/* ─── Reset ──────────────────────────────────────────── */

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

/* ─── Tokens ─────────────────────────────────────────── */

/* Shared values come from tokens.css; rules from design-system.md at the
   repo root. Only docs-specific values are defined here. */

:root {
  /* each tab owns one hue */
  --accent: var(--fg);

  --topbar-h: 60px;
  --sidebar-h: 48px;
}

.tab-explore { --accent: var(--blue); }
.tab-build   { --accent: var(--red); }

html {
  scroll-padding-top: calc(var(--topbar-h) + 16px);
}

body {
  font-family: var(--sans);
  font-size: var(--text-md);
  line-height: var(--lead-body);
  color: var(--fg);
  background: var(--bg);
}

a { color: inherit; }

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

code, kbd, pre {
  font-family: var(--mono);
  font-variant-ligatures: none;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* ─── Top bar ────────────────────────────────────────── */

.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: 28px;
  padding-inline: 24px;
  background: var(--bg);
  border-bottom: 1px solid var(--fg);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  font-size: var(--text-sm);
  font-weight: 700;
  letter-spacing: var(--track-caps);
  text-transform: uppercase;
  white-space: nowrap;
}

.brand b { font-weight: 400; }

.tabs {
  display: flex;
  align-self: stretch;
  gap: 24px;
}

.tab {
  display: flex;
  align-items: center;
  font-size: var(--text-2xs);
  font-weight: 500;
  letter-spacing: var(--track-caps);
  text-transform: uppercase;
  text-decoration: none;
  color: var(--fg-2);
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  padding-top: 2px;
  transition:
    color var(--dur-hover) var(--ease),
    border-color var(--dur-hover) var(--ease),
    transform var(--dur-press) var(--ease);
}

.tab:hover,
.tab.is-on { color: var(--fg); }
.tab:active { transform: var(--press); }

.tab-explore:hover,
.tab-explore.is-on { border-bottom-color: var(--blue); }
.tab-build:hover,
.tab-build.is-on   { border-bottom-color: var(--red); }

.search {
  position: relative;
  margin-left: auto;
  display: flex;
  align-items: center;
}

.search input {
  width: 240px;
  font: 400 var(--text-sm) var(--sans);
  color: var(--fg);
  background: var(--panel);
  border: 1px solid var(--rule);
  padding: 7px 34px 7px 12px;
  border-radius: 0;
  appearance: none;
}

.search input:focus {
  outline: none;
  border-color: var(--fg);
}

.search kbd {
  position: absolute;
  right: 10px;
  font-size: var(--text-2xs);
  color: var(--muted);
  pointer-events: none;
}

.search-results {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  width: min(440px, calc(100vw - 32px));
  max-height: 70vh;
  overflow-y: auto;
  list-style: none;
  background: var(--panel);
  border: 1px solid var(--fg);
}

.search-results a {
  display: block;
  padding: 10px 14px;
  text-decoration: none;
  border-bottom: 1px solid var(--rule);
}

.search-results a:hover,
.search-results a[aria-selected="true"] { background: var(--tint); }

.search-results .r-title { display: block; font-weight: 600; font-size: var(--text-sm); }
.search-results .r-path  { display: block; font: 400 var(--text-2xs) var(--mono); color: var(--muted); }
.search-results .r-empty { padding: 12px 14px; color: var(--muted); font-size: var(--text-sm); }

.site-link {
  font-size: var(--text-xs);
  font-weight: 600;
  letter-spacing: var(--track-caps);
  text-transform: uppercase;
  text-decoration: none;
  white-space: nowrap;
}

/* ─── Landing ────────────────────────────────────────── */

.land {
  max-width: 1080px;
  margin: 0 auto;
  padding: 64px 24px 96px;
}

.land-head { margin-bottom: 36px; }

.land-head h1,
.land > h1 {
  font-size: var(--text-display);
  font-weight: 700;
  line-height: 1;
  letter-spacing: var(--track-tight);
}

.land-head p {
  margin-top: 12px;
  max-width: 52ch;
  font-size: var(--text-md);
  color: var(--muted);
}

.doors {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 16px;
}

.door {
  display: flex;
  flex-direction: column;
  gap: 18px;
  min-height: 330px;
  padding: 28px 28px 24px;
  color: #FFFFFF;
}

.door-explore { background: var(--blue); }
.door-build   { background: var(--red); }

.door h2 {
  font-size: var(--text-2xl);
  font-weight: 700;
  line-height: 1;
  letter-spacing: var(--track-mark);
  text-transform: uppercase;
}

.door p { max-width: 34ch; }

.door ul {
  list-style: none;
  margin-top: auto;
  border-top: 1px solid rgba(255, 255, 255, 0.35);
}

.door li { border-bottom: 1px solid rgba(255, 255, 255, 0.35); }

.door li a {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
  font-weight: 500;
  text-decoration: underline;
  text-decoration-color: transparent;
  text-underline-offset: 3px;
  transition: text-decoration-color var(--dur-hover) var(--ease);
}

.door li a:hover { text-decoration-color: currentColor; }

.door em {
  font-style: normal;
  font-size: var(--text-2xs);
  font-weight: 700;
  letter-spacing: var(--track-caps);
  text-transform: uppercase;
  opacity: 0.75;
  margin-left: 6px;
}

.ref-strip {
  display: grid;
  grid-template-columns: minmax(0, 220px) 1fr;
  gap: 24px;
  margin-top: 40px;
  padding-top: 18px;
  border-top: 1px solid var(--fg);
}

.ref-strip h2 {
  font-size: var(--text-xs);
  letter-spacing: var(--track-caps);
  text-transform: uppercase;
}

.ref-strip h2 a {
  text-decoration: none;
  transition: color var(--dur-hover) var(--ease);
}

.ref-strip h2 a:hover { color: var(--fg-2); }

.ref-strip p {
  margin-top: 6px;
  font-size: var(--text-sm);
  color: var(--muted);
}

.ref-strip p code { font-size: var(--text-xs); }

.chips {
  display: flex;
  flex-wrap: wrap;
  align-content: start;
  gap: 8px;
}

.chips a {
  font: 500 var(--text-sm) var(--mono);
  text-decoration: none;
  background: var(--panel);
  border: 1px solid var(--rule);
  padding: 6px 10px;
}

.chips a {
  transition:
    border-color var(--dur-hover) var(--ease),
    transform var(--dur-press) var(--ease);
}

.chips a:hover { border-color: var(--fg); }
.chips a:active { transform: var(--press); }

/* ─── Doc layout ─────────────────────────────────────── */

.doc {
  display: grid;
  grid-template-columns: 230px minmax(0, 1fr) 200px;
  gap: 48px;
  max-width: 1280px;
  margin: 0 auto;
  padding: 40px 24px 96px;
}

.side,
.toc {
  position: sticky;
  top: calc(var(--topbar-h) + 24px);
  align-self: start;
  max-height: calc(100vh - var(--topbar-h) - 48px);
  overflow-y: auto;
}

.side {
  font-size: var(--text-sm);
  margin-left: -8px;
  padding-left: 8px;
}

.side .group { margin-bottom: 22px; }

.side-toggle { display: none; }

.side .group > b,
.toc > b {
  display: block;
  margin-bottom: 6px;
  font-size: var(--text-2xs);
  letter-spacing: var(--track-caps);
  text-transform: uppercase;
}

.side a {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-left: -8px;
  padding: 4px 8px;
  color: var(--fg-2);
  text-decoration: none;
  transition:
    background var(--dur-hover) var(--ease),
    color var(--dur-hover) var(--ease);
}

.side a:hover { color: var(--fg); background: var(--tint); }

.side a.is-active {
  background: var(--accent);
  color: #FFFFFF;
  font-weight: 600;
}

.side a code { font-size: var(--text-xs); }
.side a.is-active code { color: inherit; }

.tag-planned {
  flex: none;
  padding: 1px 5px;
  font-size: var(--text-2xs);
  font-weight: 700;
  letter-spacing: var(--track-caps);
  text-transform: uppercase;
  color: var(--muted);
  background-image: repeating-linear-gradient(135deg, var(--rule) 0 2px, transparent 2px 5px);
}

.side a.is-active .tag-planned { color: #FFFFFF; }

.toc { font-size: var(--text-sm); }

.toc a {
  display: block;
  padding: 3px 0 3px 10px;
  color: var(--muted);
  text-decoration: none;
  border-left: 1px solid var(--rule);
  transition: color var(--dur-hover) var(--ease);
}

.toc a:hover { color: var(--fg); }

.toc a.sub {
  padding-left: 22px;
  font: 400 var(--text-xs) var(--mono);
}

.toc a.is-on {
  color: var(--fg);
  border-left: 2px solid var(--accent);
  padding-left: 9px;
}

.toc a.sub.is-on { padding-left: 21px; }

/* ─── Article ────────────────────────────────────────── */

.article { max-width: 72ch; }

.crumb {
  font-size: var(--text-2xs);
  font-weight: 600;
  letter-spacing: var(--track-caps);
  text-transform: uppercase;
  color: var(--accent);
}

.article h1 {
  margin: 8px 0 18px;
  font-size: var(--text-2xl);
  font-weight: 700;
  line-height: 1.1;
  text-wrap: balance;
}

.article h1 code { font-size: var(--text-2xl); font-weight: 500; }

.article h2 {
  margin: 44px 0 10px;
  font-size: var(--text-xl);
  font-weight: 700;
  line-height: 1.25;
  text-wrap: balance;
}

.article h3 {
  margin: 28px 0 6px;
  font-size: var(--text-md);
  font-weight: 700;
}

.article h4 {
  margin: 20px 0 4px;
  font-size: var(--text-sm);
  font-weight: 700;
}

.article h1 code,
.article h2 code,
.article h3 code,
.article h4 code {
  font-size: 0.92em;
  font-weight: 500;
  background: none !important;
  padding: 0 !important;
}

.article p,
.article ul,
.article ol,
.article table,
.article blockquote { margin: 12px 0; }

.article ul,
.article ol { padding-left: 22px; }

.article li + li { margin-top: 4px; }

.article a {
  text-decoration: underline;
  text-decoration-color: var(--accent);
  text-decoration-thickness: 1.5px;
  text-underline-offset: 3px;
}

.article a {
  transition: color var(--dur-hover) var(--ease);
}

.article a:hover { color: var(--accent); }

.article :not(pre) > code {
  font-size: 0.86em;
  background: var(--tint);
  padding: 1px 5px;
}

.article kbd {
  font-size: 0.86em;
  background: none;
  border: 1px solid var(--rule);
  border-radius: 0;
  padding: 0 5px;
  white-space: nowrap;
}

/* Control glyphs from Kenney's Input Prompts (kenney.nl), CC0. The source
   SVGs are solid with their labels knocked out, so an alpha mask keeps the
   label as a hole and the shape takes the theme's own colour. */
.ctrl {
  display: inline-block;
  inline-size: 1.75em;
  block-size: 1.75em;
  vertical-align: -0.35em;
  background-color: currentColor;
  -webkit-mask: var(--ctrl) center / contain no-repeat;
  mask: var(--ctrl) center / contain no-repeat;
}

.ctrl-mouse-move  { --ctrl: url("/icons/mouse_move.svg"); }
.ctrl-mouse-left  { --ctrl: url("/icons/mouse_left_outline.svg"); }
.ctrl-mouse-right { --ctrl: url("/icons/mouse_right_outline.svg"); }
.ctrl-stick-l     { --ctrl: url("/icons/index_stick_l.svg"); }
.ctrl-stick-r     { --ctrl: url("/icons/index_stick_r.svg"); }
.ctrl-stick-press { --ctrl: url("/icons/index_stick_l_press.svg"); }
.ctrl-button-a    { --ctrl: url("/icons/index_button_a.svg"); }
.ctrl-button-b    { --ctrl: url("/icons/index_button_b.svg"); }
.ctrl-trigger-l   { --ctrl: url("/icons/index_lt.svg"); }
.ctrl-trigger-r   { --ctrl: url("/icons/index_rt.svg"); }
.ctrl-grip-l      { --ctrl: url("/icons/quest_grip_left.svg"); }
.ctrl-grip-r      { --ctrl: url("/icons/quest_grip_right.svg"); }

.article strong { font-weight: 700; }

.article blockquote {
  padding-left: 14px;
  border-left: 2px solid var(--rule);
  color: var(--fg-2);
}

.article hr {
  border: 0;
  border-top: 1px solid var(--rule);
  margin: 32px 0;
}

.article img { max-width: 100%; }

/* tables */

.article table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-sm);
  display: block;
  overflow-x: auto;
}

.article th {
  text-align: left;
  font-size: var(--text-2xs);
  font-weight: 700;
  letter-spacing: var(--track-caps);
  text-transform: uppercase;
  padding: 6px 14px 6px 0;
  border-bottom: 1px solid var(--fg);
}

.article td {
  padding: 7px 14px 7px 0;
  border-bottom: 1px solid var(--rule);
  vertical-align: top;
}

/* code */

.article pre {
  margin: 14px 0;
  padding: 14px 16px;
  overflow-x: auto;
  font-size: var(--text-sm);
  line-height: 1.6;
  background: var(--tint) !important;
  border-left: 2px solid var(--fg);
}

.article pre code {
  font-size: inherit;
  background: none;
  padding: 0;
}

.file {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin: 18px 0 -10px;
  font: 500 var(--text-2xs) var(--mono);
  color: var(--muted);
}

/* diagrams */

.diagram {
  margin: 24px 0 8px;
  overflow-x: auto;
}

.diagram svg {
  display: block;
  width: 100%;
  min-width: 560px;
  height: auto;
}

.diagram .box {
  fill: var(--panel);
  stroke: var(--fg);
  stroke-width: 1;
}

.diagram .box.wired {
  stroke: var(--accent);
  stroke-width: 2;
}

.diagram .link {
  fill: none;
  stroke: var(--fg);
  stroke-width: 1;
}

.diagram .band {
  font: 700 var(--text-2xs) var(--sans);
  letter-spacing: var(--track-caps);
  text-transform: uppercase;
  fill: var(--muted);
}

.diagram .t {
  font: 700 var(--text-sm) var(--sans);
  fill: var(--fg);
}

.diagram .s {
  font: 400 var(--text-2xs) var(--mono);
  fill: var(--muted);
}

.diagram .head { fill: var(--fg); }

.diagram .chips rect { fill: var(--tint); }

.diagram .chips text {
  font: 400 var(--text-2xs) var(--mono);
  fill: var(--fg);
}

/* asides */

.note {
  margin: 18px 0;
  padding: 12px 16px;
  font-size: var(--text-sm);
  background: var(--panel);
  border: 1px solid var(--rule);
}

.note > b,
.planned > b {
  display: inline-block;
  margin-right: 10px;
  font-size: var(--text-2xs);
  letter-spacing: var(--track-caps);
  text-transform: uppercase;
}

.planned {
  margin: 18px 0;
  padding: 14px 16px;
  font-size: var(--text-sm);
  border: 1px solid var(--fg);
  background-image: repeating-linear-gradient(135deg, rgba(15, 15, 15, 0.06) 0 2px, transparent 2px 6px);
}

.planned > b {
  padding: 2px 7px;
  color: var(--bg);
  background: var(--fg);
}

/* guides: H2s become numbered steps */

.steps { counter-reset: step; }

.steps h2 {
  display: grid;
  grid-template-columns: 32px 1fr;
  align-items: center;
  gap: 14px;
  counter-increment: step;
}

.steps h2::before {
  content: counter(step);
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  font-size: var(--text-sm);
  color: var(--bg);
  background: var(--fg);
}

/* generated API reference */

.api h2 { padding-top: 14px; border-top: 1px solid var(--fg); }

.api h3,
.api h4 {
  font-family: var(--mono);
  font-weight: 500;
  padding-top: 14px;
  border-top: 1px solid var(--rule);
}

.sig {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 4px 10px;
  margin: 6px 0;
  overflow-x: auto;
}

.sig code {
  font-size: var(--text-sm);
  font-weight: 500;
  background: none !important;
  padding: 0 !important;
  white-space: pre-wrap;
}

.sig a {
  color: var(--accent);
  text-decoration: none;
}

.sig a:hover { text-decoration: underline; }

.kind {
  font-size: var(--text-2xs);
  font-weight: 700;
  letter-spacing: var(--track-caps);
  text-transform: uppercase;
  color: var(--muted);
}

.article table.fields { font-size: var(--text-sm); }
.article table.fields td:first-child { white-space: nowrap; }

/* page footer */

.meta {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 10px 24px;
  margin-top: 48px;
  padding-top: 14px;
  border-top: 1px solid var(--rule);
  font: 400 var(--text-xs) var(--mono);
  color: var(--muted);
}

.meta .pager {
  font-family: var(--sans);
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--fg);
  text-decoration: none;
}

.meta .pager:first-of-type { margin-left: auto; }
.meta .pager {
  transition:
    color var(--dur-hover) var(--ease),
    transform var(--dur-press) var(--ease);
}

.meta .pager:hover { color: var(--accent); }
.meta .pager:active { transform: var(--press); }

/* ─── Narrow screens ─────────────────────────────────── */

@media (max-width: 1100px) {
  .doc { grid-template-columns: 210px minmax(0, 1fr); }
  .toc { display: none; }
}

@media (max-width: 780px) {
  /* the sticky page bar sits under the top bar */
  html { scroll-padding-top: calc(var(--topbar-h) + var(--sidebar-h) + 16px); }

  .topbar { gap: 16px; padding-inline: 16px; }
  .brand span, .site-link { display: none; }
  .tabs { gap: 18px; }

  .search { flex: 1; min-width: 0; }

  /* 16px keeps iOS from zooming the page on focus */
  .search input {
    width: 100%;
    min-width: 0;
    padding-right: 12px;
    font-size: var(--text-md);
  }

  .search kbd { display: none; }

  .search-results {
    position: fixed;
    top: var(--topbar-h);
    left: 0;
    right: 0;
    width: auto;
    max-height: calc(100dvh - var(--topbar-h));
    border-width: 0 0 1px;
  }

  .search-results a { padding: 12px 16px; }

  .doc {
    grid-template-columns: minmax(0, 1fr);
    gap: 24px;
    padding: 0 16px 72px;
  }

  .side {
    top: var(--topbar-h);
    z-index: 40;
    max-height: none;
    overflow: visible;
    margin: 0 -16px;
    padding: 0;
  }

  .side-toggle {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    height: var(--sidebar-h);
    padding: 0 16px;
    font: inherit;
    text-align: left;
    color: var(--fg);
    background: var(--bg);
    border: 0;
    border-bottom: 1px solid var(--rule);
    cursor: pointer;
  }

  .side.is-open .side-toggle { border-bottom-color: var(--fg); }

  .side-where {
    display: flex;
    align-items: baseline;
    gap: 10px;
    flex: 1;
    min-width: 0;
  }

  .side-group {
    flex: none;
    font-size: var(--text-2xs);
    font-weight: 600;
    letter-spacing: var(--track-caps);
    text-transform: uppercase;
    color: var(--accent);
  }

  .side-page {
    min-width: 0;
    overflow: hidden;
    font-weight: 600;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .side-page code { font-size: var(--text-sm); }

  .side-label {
    font-size: var(--text-2xs);
    font-weight: 600;
    letter-spacing: var(--track-caps);
    text-transform: uppercase;
    color: var(--muted);
  }

  .side-icon {
    flex: none;
    width: 8px;
    height: 8px;
    margin: 0 2px 4px;
    border-right: 1.5px solid var(--fg);
    border-bottom: 1.5px solid var(--fg);
    transform: rotate(45deg);
    transition: transform var(--dur-hover) var(--ease);
  }

  .side.is-open .side-icon { transform: translate(0, 4px) rotate(-135deg); }

  .side-nav {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    max-height: calc(100dvh - var(--topbar-h) - var(--sidebar-h) - 48px);
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 20px 16px 4px;
    background: var(--bg);
    border-bottom: 1px solid var(--fg);
    visibility: hidden;
    opacity: 0;
    transform: translateY(-6px);
    transition:
      opacity var(--dur-hover) var(--ease),
      transform var(--dur-hover) var(--ease),
      visibility 0s linear var(--dur-hover);
  }

  .side.is-open .side-nav {
    visibility: visible;
    opacity: 1;
    transform: none;
    transition:
      opacity var(--dur-hover) var(--ease),
      transform var(--dur-hover) var(--ease);
  }

  /* dims the article behind the open list; a tap on it closes the list */
  .side::before {
    content: "";
    position: fixed;
    inset: var(--topbar-h) 0 0;
    z-index: -1;
    background: rgba(15, 15, 15, 0.3);
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--dur-hover) var(--ease);
  }

  .side.is-open::before { opacity: 1; pointer-events: auto; }

  .side a { padding: 9px 8px; }

  .article { padding-top: 4px; }

  .meta .pager {
    flex: 1 1 100%;
    margin-left: 0;
    padding: 12px 0;
    border-top: 1px solid var(--rule);
  }

  .meta .pager:first-of-type { margin-left: 0; }
  .meta > .pager:first-child { padding-top: 0; border-top: 0; }
  .meta .pager-next { text-align: right; }

  .land { padding: 40px 16px 72px; }
  .ref-strip { grid-template-columns: minmax(0, 1fr); }
  .door { min-height: 0; }
}

@media (max-width: 400px) {
  .side-label { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
}

/* ─── 404 ────────────────────────────────────────────── */

.lost .land-head p code {
  font-size: 0.9em;
  background: var(--tint);
  padding: 1px 6px;
  overflow-wrap: anywhere;
}

.lost-matches { margin-bottom: 40px; }

.lost-matches h2 {
  display: block;
  margin-bottom: 8px;
  font-size: var(--text-2xs);
  font-weight: 700;
  letter-spacing: var(--track-caps);
  text-transform: uppercase;
}

.lost-matches ol {
  list-style: none;
  border-top: 1px solid var(--fg);
}

.lost-matches a {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  padding: 10px 0;
  text-decoration: none;
  border-bottom: 1px solid var(--rule);
}

.lost-matches a:hover .r-title { text-decoration: underline; }
.lost-matches .r-title { font-weight: 600; }
.lost-matches .r-path { font: 400 var(--text-xs) var(--mono); color: var(--muted); }
