/* kaypy.site
 *
 * Light by default. A dark variant exists for anyone whose system asks for
 * one, but light is the base theme rather than an afterthought bolted to a
 * media query.
 *
 * Colours come from the logo: the snake's green and the wordmark's blue.
 *
 * THE GREEN HAS TO BE TWO GREENS. --green is used as a TEXT colour (nav,
 * links on hover, strings in code). The logo's green, #8fd95e, is 1.9:1 on
 * white — invisible. So each theme sets its own text-safe green, and the
 * bright logo green lives in --green-fill, which is only ever a background
 * with --green-ink on top of it. Using one variable for both is how green
 * links ended up unreadable on the light theme before.
 *
 * No web fonts. A teaching site should render instantly on a school laptop
 * over a school network, and a font that arrives late moves the text under
 * the reader's eye.
 */

:root {
  --bg: #ffffff;
  --bg-soft: #f4f8fb;
  --bg-code: #f6f8fa;
  --line: #d9e2ea;

  --fg: #1a2430;
  --fg-dim: #56636f;

  --green: #3d7d24;        /* text-safe on white */
  --blue: #2b62aa;         /* the wordmark */
  --blue-soft: #2b62aa;

  /* The logo's own green, as a solid fill with dark ink on it. Identical in
     both themes on purpose: it is the one place the brand colour appears at
     full strength, and white-on-deep-green measured 3.35:1, which fails.
     This is 10.4:1 and it reads as the same button on either theme. */
  --green-fill: #8fd95e;
  --green-ink: #12181f;

  --radius: 10px;
  --measure: 46rem;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1b222c;
    --bg-soft: #232c38;
    --bg-code: #151b24;
    --line: #36424f;

    --fg: #eef3f8;
    --fg-dim: #a9b6c4;

    --green: #8fd95e;
    --blue: #4a86d4;
    --blue-soft: #9cc4f0;
  }
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; scroll-padding-top: 5rem; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 16px/1.65 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}

.skip {
  position: absolute; left: -9999px;
  background: var(--blue); color: #fff; padding: .6rem 1rem; z-index: 10;
}
.skip:focus { left: 1rem; top: 1rem; }

/* ------------------------------------------------------------ header -- */

.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 1.25rem;
  padding: .7rem clamp(1rem, 4vw, 2rem);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}

.brand {
  display: flex; align-items: center; gap: .55rem;
  color: inherit; text-decoration: none; font-weight: 700;
}
.brand img { display: block; }
.brand-name { font-size: 1.15rem; letter-spacing: -.01em; color: var(--blue-soft); }

.top-nav { display: flex; gap: .25rem; flex: 1; flex-wrap: wrap; }
.top-nav a {
  color: var(--fg-dim); text-decoration: none;
  padding: .35rem .7rem; border-radius: 7px; font-size: .95rem;
}
.top-nav a:hover { color: var(--fg); background: var(--bg-soft); }
.top-nav a.current { color: var(--green); background: var(--bg-soft); font-weight: 600; }

.gh { color: var(--fg-dim); text-decoration: none; font-size: .9rem; white-space: nowrap; }
.gh:hover { color: var(--fg); }

/* On a phone the header is already carrying a wrapping six-item nav, and
   two more links at the end push the whole thing onto a third row. Both are
   in the footer of every page, so the header can let them go. */
@media (max-width: 40rem) {
  .top .gh { display: none; }
}

/* -------------------------------------------------------------- main -- */

main {
  max-width: 78rem; margin: 0 auto;
  padding: 2.5rem clamp(1rem, 4vw, 2rem) 4rem;
}
main.with-toc { display: grid; grid-template-columns: 1fr 14rem; gap: 3rem; }
main.with-toc .prose { grid-row: 1; grid-column: 1; }
main.with-toc .toc  { grid-row: 1; grid-column: 2; }

.prose { max-width: var(--measure); min-width: 0; }

.toc {
  position: sticky; top: 5rem; align-self: start;
  font-size: .875rem; max-height: calc(100vh - 7rem); overflow-y: auto;
}
.toc-head {
  margin: 0 0 .5rem; color: var(--fg-dim);
  text-transform: uppercase; letter-spacing: .08em; font-size: .72rem;
}
.toc a {
  display: block; padding: .18rem 0 .18rem .75rem;
  border-left: 2px solid var(--line);
  color: var(--fg-dim); text-decoration: none;
}
.toc a:hover { color: var(--green); border-left-color: var(--green); }
.toc a.d3 { padding-left: 1.5rem; font-size: .84rem; }

@media (max-width: 62rem) {
  main.with-toc { grid-template-columns: 1fr; }
  .toc { display: none; }
}

/* ------------------------------------------------------------- prose -- */

.prose h1 {
  font-size: clamp(1.9rem, 4vw, 2.5rem); line-height: 1.15;
  margin: 0 0 1rem; letter-spacing: -.02em;
}
.prose h2 {
  font-size: 1.5rem; margin: 3rem 0 .9rem; letter-spacing: -.01em;
  padding-bottom: .4rem; border-bottom: 1px solid var(--line);
}
.prose h3 { font-size: 1.15rem; margin: 2.2rem 0 .7rem; }
.prose h4 { font-size: 1rem; margin: 1.6rem 0 .5rem; color: var(--fg-dim); }

.prose p, .prose li { color: var(--fg); }
.prose a { color: var(--blue-soft); text-decoration-thickness: 1px; }
.prose a:hover { color: var(--green); }

.prose blockquote {
  margin: 1.4rem 0; padding: .9rem 1.2rem;
  border-left: 3px solid var(--green);
  background: var(--bg-soft); border-radius: 0 var(--radius) var(--radius) 0;
}
.prose blockquote p:last-child { margin-bottom: 0; }

.prose table {
  width: 100%; border-collapse: collapse; margin: 1.4rem 0;
  font-size: .93rem; display: block; overflow-x: auto;
}
.prose th, .prose td {
  text-align: left; padding: .55rem .8rem;
  border-bottom: 1px solid var(--line); vertical-align: top;
}
.prose th { color: var(--fg-dim); font-weight: 600; font-size: .85rem; }
.prose tbody tr:hover { background: var(--bg-soft); }

.prose img { max-width: 100%; height: auto; }
.prose hr { border: 0; border-top: 1px solid var(--line); margin: 3rem 0; }

/* -------------------------------------------------------------- code -- */

.prose code {
  font: .9em/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  background: var(--bg-soft); padding: .12em .38em; border-radius: 5px;
  border: 1px solid var(--line);
}

.prose pre, .hl {
  background: var(--bg-code); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 1rem 1.1rem;
  overflow-x: auto; margin: 1.3rem 0;
}
.prose pre code, .hl code {
  background: none; border: 0; padding: 0; font-size: .875rem; line-height: 1.6;
}

/* Pygments, in the logo's palette rather than a stock theme. Light first. */
.hl .k, .hl .kn, .hl .kd { color: #a02aa0; }           /* keyword */
.hl .nf, .hl .fm        { color: var(--blue); }        /* function */
.hl .s, .hl .s1, .hl .s2, .hl .sd { color: #2f6b1c; }  /* string */
.hl .mi, .hl .mf        { color: #a35400; }            /* number */
.hl .c, .hl .c1, .hl .cm { color: var(--fg-dim); font-style: italic; }
.hl .nd                 { color: #a35400; }            /* decorator */
.hl .bp, .hl .nb        { color: #167a7a; }            /* builtin */
.hl .o, .hl .p          { color: var(--fg-dim); }

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .hl .k,
  :root:not([data-theme="light"]) .hl .kn,
  :root:not([data-theme="light"]) .hl .kd { color: #d98bd1; }
  :root:not([data-theme="light"]) .hl .s,
  :root:not([data-theme="light"]) .hl .s1,
  :root:not([data-theme="light"]) .hl .s2,
  :root:not([data-theme="light"]) .hl .sd { color: #8fd95e; }
  :root:not([data-theme="light"]) .hl .mi,
  :root:not([data-theme="light"]) .hl .mf,
  :root:not([data-theme="light"]) .hl .nd { color: #e8a760; }
  :root:not([data-theme="light"]) .hl .bp,
  :root:not([data-theme="light"]) .hl .nb { color: #6fc5c5; }
}

/* ------------------------------------------------------------ footer -- */

.foot {
  border-top: 1px solid var(--line);
  padding: 2rem clamp(1rem, 4vw, 2rem) 3rem;
  max-width: 78rem; margin: 0 auto;
  font-size: .88rem; color: var(--fg-dim);
}
.foot p { max-width: var(--measure); }
.foot a { color: var(--blue-soft); }
.foot .dim { font-size: .82rem; }

/* -------------------------------------------------------------- home -- */

.hero { text-align: center; padding: 1rem 0 2.5rem; }
.hero img { max-width: min(300px, 65vw); height: auto; }
.hero h1 {
  font-size: clamp(2rem, 6vw, 3rem); margin: 1rem 0 .5rem; letter-spacing: -.02em;
}
.hero .lede {
  font-size: clamp(1.05rem, 2.5vw, 1.3rem); color: var(--fg-dim);
  max-width: 38rem; margin: 0 auto 1.8rem;
}

.hero h1 { margin-bottom: 1.6rem; }

.cta { display: flex; gap: .8rem; justify-content: center; flex-wrap: wrap; }
.cta a {
  padding: .7rem 1.4rem; border-radius: 8px; text-decoration: none;
  font-weight: 600; border: 1px solid var(--line);
}
/* The fill and the ink are both theme variables, so neither theme has to
   make a light-on-light or dark-on-dark compromise. */
.cta .primary {
  background: var(--green-fill); color: var(--green-ink);
  border-color: transparent;
}
.cta .primary:hover { filter: brightness(1.12); }
.cta .secondary { color: var(--fg); background: var(--bg-soft); }
.cta .secondary:hover { border-color: var(--green); color: var(--green); }

.cards {
  display: grid; gap: 1.1rem; margin: 3rem 0;
  grid-template-columns: repeat(auto-fit, minmax(15rem, 1fr));
}
.card {
  background: var(--bg-soft); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 1.2rem;
}
.card h3 { margin: 0 0 .4rem; font-size: 1.05rem; }
.card p { margin: 0; color: var(--fg-dim); font-size: .92rem; }
.card a { color: var(--green); text-decoration: none; font-weight: 600; }

.split {
  display: grid; gap: 2rem; align-items: center; margin: 3rem 0;
  grid-template-columns: 1fr 1fr;
}
@media (max-width: 52rem) { .split { grid-template-columns: 1fr; } }

/* The wordmark is text, not part of the image. The logo it came from baked it
   in as dark navy, which vanishes on a dark page and cannot be restyled,
   selected or translated. As text it takes the theme's colours like
   everything else. */
.wordmark {
  font-size: clamp(2.6rem, 8vw, 4rem);
  font-weight: 800; letter-spacing: -.045em; line-height: 1;
  color: var(--blue-soft); margin: .4rem 0 .2rem;
}
.hero h1 { font-size: clamp(1.5rem, 4vw, 2.1rem); color: var(--fg); }

/* ------------------------------------------------ lesson solutions -- */

/* The lesson pages hide worked solutions behind <details>. Unstyled, a
   disclosure triangle next to the word "Solution" reads as a broken link
   rather than a thing to press, and students do not press it. */
.prose details {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg-soft);
  padding: .3rem 1rem;
  margin: 1.4rem 0;
}
.prose details[open] { padding-bottom: .6rem; }
.prose summary {
  cursor: pointer;
  font-weight: 600;
  color: var(--green);
  padding: .6rem 0;
  list-style: none;
}
.prose summary::-webkit-details-marker { display: none; }
.prose summary::before {
  content: "▸";
  display: inline-block;
  width: 1.1em;
  transition: transform .15s ease;
}
.prose details[open] summary::before { transform: rotate(90deg); }
.prose summary:hover { color: var(--fg); }
