/* Colors ----------------------------------------------------------------- */

:root {
  color-scheme: light;
  --bg: #faf9f6;
  --surface: #ffffff;
  --sunken: #f2f0ea;
  --text: #1b1d22;
  --muted: #5a5e68;
  --line: #e2dfd7;
  --accent: #b83e0a;
  --accent-soft: #fbe9dd;
  --on-accent: #ffffff;
  --mono: ui-monospace, "Cascadia Code", "JetBrains Mono", Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #101216;
    --surface: #16191f;
    --sunken: #1b1f26;
    --text: #e7e8eb;
    --muted: #a2a6b0;
    --line: #2b2f38;
    --accent: #ff9d5c;
    --accent-soft: #33241b;
    --on-accent: #1a1209;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #101216;
  --surface: #16191f;
  --sunken: #1b1f26;
  --text: #e7e8eb;
  --muted: #a2a6b0;
  --line: #2b2f38;
  --accent: #ff9d5c;
  --accent-soft: #33241b;
  --on-accent: #1a1209;
}

/* Base ------------------------------------------------------------------- */

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; scroll-padding-top: 5rem; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 400 1.0625rem/1.65 var(--sans);
}

a { color: var(--accent); text-underline-offset: 0.18em; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

h1, h2, h3 { line-height: 1.2; letter-spacing: -0.015em; }
h1 { margin: 0 0 0.6rem; font-size: clamp(2rem, 5vw, 2.6rem); font-weight: 700; }
h2 { margin: 2.6rem 0 0.7rem; font-size: 1.5rem; font-weight: 650; }
h3 { margin: 2rem 0 0.5rem; font-size: 1.15rem; font-weight: 650; }

h2 .anchor, h3 .anchor { color: inherit; text-decoration: none; }
h2 .anchor:hover::after, h3 .anchor:hover::after { content: " #"; color: var(--muted); }

p, ul, ol { margin: 0 0 1rem; }
ul, ol { padding-left: 1.4rem; }
li { margin-bottom: 0.35rem; }

code {
  padding: 0.1em 0.32em;
  border-radius: 4px;
  background: var(--sunken);
  font: 0.88em var(--mono);
  overflow-wrap: anywhere;
}

/* Page frame ------------------------------------------------------------- */

.top {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.65rem 1rem;
  border-bottom: 1px solid var(--line);
  background: var(--bg);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  color: var(--text);
  font: 600 1rem var(--mono);
  letter-spacing: -0.02em;
  text-decoration: none;
}
.brand img { border-radius: 4px; }

.theme {
  display: grid;
  place-items: center;
  width: 2.5rem;
  height: 2.5rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}
.theme:hover { color: var(--text); }

.shell { display: block; max-width: 72rem; margin: 0 auto; padding: 0 1rem; }

main { min-width: 0; max-width: 46rem; padding: 1.5rem 0 3rem; }

.foot {
  padding: 1.5rem 1rem 2.5rem;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.9rem;
  text-align: center;
}
.foot p { margin: 0; }

/* Navigation ------------------------------------------------------------- */

.side { padding-top: 0.75rem; }
.side summary { cursor: pointer; color: var(--muted); font-size: 0.95rem; }
.side h2 {
  margin: 1rem 0 0.3rem;
  color: var(--muted);
  font: 600 0.75rem var(--mono);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.side ul { margin: 0; padding: 0; list-style: none; }
.side li { margin: 0; }
.side a {
  display: block;
  padding: 0.35rem 0.6rem;
  border-radius: 6px;
  color: var(--text);
  font-size: 0.95rem;
  text-decoration: none;
}
.side a:hover { background: var(--sunken); }
.side a[aria-current="page"] { background: var(--accent-soft); color: var(--accent); font-weight: 600; }

@media (min-width: 900px) {
  .top { padding: 0.65rem 1.5rem; }
  .shell { display: grid; grid-template-columns: 13.5rem minmax(0, 1fr); gap: 3rem; padding: 0 1.5rem; }
  .side {
    position: sticky;
    top: 3.8rem;
    align-self: start;
    max-height: calc(100vh - 3.8rem);
    padding: 1rem 0.5rem 1.5rem 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    scrollbar-width: thin;
    scrollbar-color: var(--line) transparent;
  }
  .side summary { display: none; }
  main { padding-top: 2.2rem; }
}

/* SDL version switch ----------------------------------------------------- */

.sdl-switch {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem;
  margin-bottom: 1.4rem;
  font-size: 0.9rem;
}
.sdl-switch-label { margin-right: 0.3rem; color: var(--muted); }
.sdl-switch a { margin-left: 0.4rem; }
.sdl-switch button {
  min-height: 2.25rem;
  padding: 0 0.8rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font: 600 0.88rem var(--mono);
  cursor: pointer;
}
.sdl-switch button[aria-pressed="true"] {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--on-accent);
}

html:not(.js) .sdl-switch { display: none; }

/* Only the chosen SDL version shows. Without the script, both versions show. */
html.js[data-sdl="sdl3"] [data-only="sdl2"],
html.js[data-sdl="sdl2"] [data-only="sdl3"] { display: none; }

/* Code ------------------------------------------------------------------- */

.code {
  margin: 0 0 1.25rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  overflow: hidden;
}
.code-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 2.25rem;
  padding: 0.15rem 0.4rem 0.15rem 0.85rem;
  border-bottom: 1px solid var(--line);
  background: var(--sunken);
}
.code-title { color: var(--muted); font: 0.82rem var(--mono); }
.copy {
  min-height: 2rem;
  padding: 0 0.6rem;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font: 0.8rem var(--sans);
  cursor: pointer;
}
.copy:hover { background: var(--line); color: var(--text); }

.code pre {
  margin: 0;
  padding: 0.85rem 1rem;
  overflow-x: auto;
  background: transparent !important;
  font: 0.86rem/1.6 var(--mono);
  tab-size: 4;
}
.code code { padding: 0; background: none; font: inherit; overflow-wrap: normal; }

.shiki span { color: var(--shiki-light); }

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .shiki span { color: var(--shiki-dark); }
}
:root[data-theme="dark"] .shiki span { color: var(--shiki-dark); }

/* Tabs ------------------------------------------------------------------- */

.tabs { margin-bottom: 1.25rem; }
.tablist {
  display: flex;
  gap: 0.25rem;
  margin-bottom: 1rem;
  border-bottom: 1px solid var(--line);
  overflow-x: auto;
}
.tablist button {
  min-height: 2.5rem;
  padding: 0 0.9rem;
  border: 0;
  border-bottom: 2px solid transparent;
  background: transparent;
  color: var(--muted);
  font: 500 0.95rem var(--sans);
  white-space: nowrap;
  cursor: pointer;
}
.tablist button[aria-selected="true"] { border-bottom-color: var(--accent); color: var(--text); }

.tab-label { margin: 1.2rem 0 0.4rem; font-weight: 650; }
html.js .tab-label { display: none; }
html:not(.js) .tablist { display: none; }

/* Boxes ------------------------------------------------------------------ */

.box {
  margin: 1.75rem 0;
  padding: 1rem 1.15rem 0.35rem;
  border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  border-radius: 8px;
  background: var(--surface);
}
.box-title { margin-bottom: 0.5rem; font-weight: 650; }

.errors { padding-bottom: 0.25rem; }
.error { padding: 0.9rem 0; border-top: 1px solid var(--line); }
.error-problem { margin: 0 0 0.5rem; font-weight: 600; }
.error-problem.is-message { font-weight: 400; }
.error-problem.is-message code {
  display: block;
  padding: 0.5rem 0.65rem;
  border-radius: 6px;
  line-height: 1.5;
}
.error-fix { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 0.65rem; align-items: start; }
.error-fix p { margin: 0 0 0.4rem; }
.error-fix p:last-child { margin-bottom: 0; }
.error-label {
  margin-top: 0.22rem;
  padding: 0.05rem 0.45rem;
  border-radius: 4px;
  background: var(--accent-soft);
  color: var(--accent);
  font: 600 0.72rem/1.5 var(--mono);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

/* Demo ------------------------------------------------------------------- */

.demo { margin: 0 0 1.75rem; }
.demo-frame {
  position: relative;
  aspect-ratio: 4 / 3;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #0b0d10;
  overflow: hidden;
}
.demo iframe { display: block; width: 100%; height: 100%; border: 0; }
.demo-status {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  margin: 0;
  padding: 1rem;
  background: #0b0d10;
  color: #d9dbe0;
  font-size: 0.95rem;
  text-align: center;
}
.demo-status[hidden] { display: none; }
.demo-noscript { margin: 0.5rem 0 0; color: var(--muted); font-size: 0.9rem; }

/* Lesson list ------------------------------------------------------------ */

.lesson-list { margin: 0 0 1rem; padding: 0; list-style: none; }
.lesson-list li { margin: 0; border-top: 1px solid var(--line); }
.lesson-list li:last-child { border-bottom: 1px solid var(--line); }
.lesson-list a {
  display: grid;
  grid-template-columns: 4.4rem minmax(0, 1fr);
  column-gap: 0.75rem;
  align-items: baseline;
  padding: 0.7rem 0.5rem;
  color: var(--text);
  text-decoration: none;
}
.lesson-list a:hover { background: var(--sunken); }
.lesson-number { color: var(--muted); font: 600 0.95rem var(--mono); }
.lesson-tag {
  justify-self: start;
  padding: 0.05rem 0.4rem;
  border-radius: 4px;
  background: var(--accent-soft);
  color: var(--accent);
  font: 600 0.68rem/1.6 var(--mono);
  letter-spacing: 0.03em;
  text-transform: uppercase;
}
.lesson-name { font-weight: 600; }
.lesson-text { grid-column: 2; color: var(--muted); font-size: 0.95rem; line-height: 1.45; }

/* Reference -------------------------------------------------------------- */

.api-crumbs { margin-bottom: 0.4rem; color: var(--muted); font-size: 0.9rem; }
h1.api-title { font-family: var(--mono); font-size: clamp(1.4rem, 5vw, 2.1rem); overflow-wrap: anywhere; }
.api-kind { margin-top: -0.3rem; color: var(--muted); font-size: 0.9rem; }
.api-source { color: var(--muted); font-size: 0.93rem; }
.api-link { text-decoration-color: var(--line); }
.api-see { display: flex; flex-wrap: wrap; gap: 0.3rem 0.9rem; padding: 0; list-style: none; }
.api-see li { margin: 0; }
.api-search {
  width: 100%;
  min-height: 2.75rem;
  padding: 0 0.8rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
}
.api-list { margin: 0 0 1rem; padding: 0; list-style: none; }
.api-list li { margin: 0; border-top: 1px solid var(--line); }
.api-list li[hidden], .api-group[hidden] { display: none; }
.api-list a { display: block; padding: 0.55rem 0.4rem; color: var(--text); text-decoration: none; }
.api-list a:hover { background: var(--sunken); }
.api-list code { padding: 0; background: none; font-weight: 600; }
.api-list span { display: block; color: var(--muted); font-size: 0.93rem; line-height: 1.4; }

/* Download --------------------------------------------------------------- */

.download {
  margin: 2rem 0 0;
  padding: 1rem 1.15rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}
.download p { margin-bottom: 0.4rem; }
.download a { font-weight: 600; }

/* Tables ----------------------------------------------------------------- */

main table { width: 100%; margin: 0 0 1.25rem; border-collapse: collapse; font-size: 0.95rem; }
main th, main td { padding: 0.45rem 0.6rem; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
main th { color: var(--muted); font-weight: 600; }

/* Figures --------------------------------------------------------------- */

.figure { margin: 0 0 1.5rem; }
.figure svg { display: block; width: 100%; height: auto; }
.figure text { fill: var(--text); font-family: var(--mono); }
.figure figcaption { margin-top: 0.4rem; color: var(--muted); font-size: 0.9rem; }

/* Next and previous links ------------------------------------------------ */

.pager {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
  margin-top: 3rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--line);
}
.pager a {
  display: block;
  padding: 0.6rem 0.9rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  font-weight: 600;
  text-decoration: none;
}
.pager a:hover { border-color: var(--accent); }
.pager a span { display: block; color: var(--muted); font-size: 0.8rem; font-weight: 400; }
.pager .next { grid-column: 2; text-align: right; }

/* Home ------------------------------------------------------------------- */

.home .side { display: none; }
.home .shell { display: block; max-width: 62rem; }
.home main { max-width: none; padding-top: clamp(2rem, 6vw, 4.5rem); }
.home h1 { font-size: clamp(2.4rem, 7vw, 3.8rem); }

.lead { max-width: 36rem; color: var(--muted); font-size: 1.2rem; line-height: 1.5; }

.actions p { display: flex; flex-wrap: wrap; gap: 0.6rem; margin: 1.5rem 0 2.5rem; }
.actions a {
  display: inline-flex;
  align-items: center;
  min-height: 2.75rem;
  padding: 0 1.1rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  font-weight: 600;
  text-decoration: none;
}
.actions a:first-child { border-color: var(--accent); background: var(--accent); color: var(--on-accent); }

.home .demo { max-width: 40rem; }

.home-list { display: grid; gap: 1.5rem; margin-top: 2.5rem; }
.home-list h2 { margin-top: 0; font-size: 1.15rem; }
.home-list p { color: var(--muted); }

@media (min-width: 700px) {
  .home-list { grid-template-columns: repeat(3, 1fr); }
}
