/* glowcap site, a warm, two-column documentation surface. The palette is
   pulled from the hero art: cream paper, cocoa ink, an amber accent, and a
   teal that plays against it. */

:root {
  --code-bg: #f5e6ce;
  /* The one shadow, for the one thing that floats: the skip link, when it
     lands over the page. Cards, buttons, and listings carry none. A raised
     surface is said by its tone and its hairline, and a well by its darker
     ground; a shadow on top of either was a second signal for one fact, and
     ten of them on the front door made a grid of floating tiles. The colour
     is the ink's in light and plain darkness in the dark theme, because a
     shadow cast in cream ink is a halo, not a lift. */
  --shadow: 0 1px 2px var(--shadow-near), 0 10px 26px var(--shadow-far);
  --shadow-near: color-mix(in srgb, var(--ink) 6%, transparent);
  --shadow-far: color-mix(in srgb, var(--ink) 8%, transparent);
  --sidebar-w: 16rem;
  --content-max: 60rem;
  /* The header's side inset, shared by the brand row and the controls the
     narrow layout pins to its corner, and the icon button size the theme
     switch and the application link beside it share. */
  --header-inset: clamp(1rem, 4vw, 2.5rem);
  --icon-button-size: 36px;
  /* Core palette, type, mark, and product ink/radius/cover come from
     ui/tokens.css, linked first. */
  /* The diagrams override these two, so they need a light-theme identity of
     their own; otherwise every use carries a core colour as a literal fallback
     and the palette is restated in two more places. */
  --dia-accent-deep: var(--accent-deep);
  --dia-teal-deep: var(--teal-deep);
  /* Syntax colours, as tokens so the dark theme can lift them off the paper
     palette instead of restating every rule. Each one clears 4.5:1 against
     `--code-bg`, the bar for text this size: a fenced listing sets at roughly
     twelve pixels, which is body text and not large text. */
  --syn-keyword: #98499f;
  --syn-call: var(--teal-deep);
  --syn-string: #476225;
  --syn-number: #985313;
  --syn-comment: #736046;
  --syn-punct: #726249;
}

/* "Syrup": the same warmth taken down to a dark roast, and the palette the
   rooms app already ships, so the two surfaces read as one product. Only the
   tokens move; not one rule below is restated for the dark theme.

   Syrup is the default face, so one selector carries the whole dark theme: a
   root nobody has stamped and a root stamped `dark` are the same page, and
   `data-theme="light"` is the only thing that turns it off. Written as two
   arms it was two copies of one list, and they drift.

   The whole dark theme rides the `@supports` guard on `light-dark()`: a
   browser without the function keeps the light palette, so it must not get
   dark diagram tokens or a dark `color-scheme` either. The toggle retires on
   those browsers further down, beside its own rules. */
@supports (color: light-dark(#000, #fff)) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    /* Dark-only, and they stay unfolded rather than moving into `light-dark()`.
       Each is undefined in the light theme on purpose: the diagram SVGs name
       them as `var(--dia-…, #literal)`, and several distinct pale tints share
       one token, so giving the token a single light value would flatten three
       different colours into one and change the light artwork. */
    --dia-card: #33281b;
    --dia-danger: #e07a5f;
    --dia-danger-fill: #33221d;
    --dia-danger-rule: #5c3a31;
    --dia-green: #7fbf8c;
    --dia-muted: #9c8b70;
    --dia-warm-fill: #2a2016;
    --dia-warm-rule: #4a3b26;
    --dia-warm-stroke: #7a663f;
    --dia-cool-fill: #1d2e2e;
    --dia-cool-strong: #27403f;
  }
}

* {
  box-sizing: border-box;
}

html {
  font-family: var(--font-sans);
  line-height: 1.65;
  /* Plex ships its own kerning and ligature tables; ask for them explicitly so
     pairs like "ff" and "Ty" set the way the type designer drew them. */
  font-kerning: normal;
  font-variant-ligatures: common-ligatures;
  -webkit-font-smoothing: antialiased;
  color: var(--ink);
  background: var(--page-bg);
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  /* A flex column so a short page still drops its footer to the bottom edge
     instead of leaving a ragged band of empty paper mid-page. */
  display: flex;
  flex-direction: column;
  background: none;
}

/* The ground is a property of the window here exactly as in Rooms: the crown
   holds the top of what a reader sees and the floor sits under the fold, on
   every screenful of a long article rather than only at its end. A ground
   painted on the scrolling document would show most readers nothing but paper.
   The `html` backstop keeps overscroll rubber-banding on the same picture. */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  background: var(--page-bg);
}

.shell {
  flex: 1 0 auto;
}

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

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

a:hover {
  text-decoration: underline;
}

/* One ring for everything a key can reach. A control keeps its own corners. */
:focus-visible {
  outline: 2px solid var(--teal);
  outline-offset: 2px;
}

/* A link draws no box, so its ring gets corners unless a class draws one. */
:where(a):focus-visible {
  border-radius: var(--radius-chip);
}

.skip-link {
  position: absolute;
  left: -999px;
}

.skip-link:focus {
  left: 1rem;
  top: 0.5rem;
  z-index: 10;
  background: var(--paper-raised);
  padding: 0.4rem 0.8rem;
  border-radius: var(--radius-control);
  box-shadow: var(--shadow);
}

/* ── Header ──────────────────────────────────────────────────────────────── */

.site-header {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: calc(0.7rem + var(--accent-line)) var(--header-inset) 0.7rem;
  background: color-mix(in srgb, var(--paper-raised) 70%, transparent);
  backdrop-filter: blur(var(--frost));
  -webkit-backdrop-filter: blur(var(--frost));
  border-bottom: 1px solid var(--rule);
}

/* The brand hairline rides with the sticky header, the way rooms' topbar
   carries it — a stripe on the body would scroll away. Same 3px, same oklch
   blend of accent into teal. */
.site-header::before {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: var(--accent-line);
  background: linear-gradient(90deg in oklch, var(--accent) 0%, var(--teal) 100%);
}

/* How far through the page you are, drawn along the bottom edge of the header
   that is already stuck to the top of the screen. Some of these pages are long,
   and a reader deciding whether to keep going deserves to know how much is
   left. It reuses the brand gradient rather than introducing a new colour, and
   it rides the scroll itself: no script, no scroll listener.

   Browsers without scroll-driven animation, and readers who ask for less
   motion, simply keep the header's plain bottom border. */
@supports (animation-timeline: scroll()) {
  @media (prefers-reduced-motion: no-preference) {
    .site-header::after {
      content: "";
      position: absolute;
      left: 0;
      right: 0;
      bottom: -1px;
      height: 2px;
      background: linear-gradient(90deg in oklch, var(--accent) 0%, var(--teal) 100%);
      /* Revealed with a clip rather than scaled: scaling squeezes the whole
         gradient into whatever is shown, so the leading edge would read teal at
         every scroll position. Clipping leaves the gradient anchored to the
         page, so the colour at a given point on the bar means something. */
      clip-path: inset(0 100% 0 0);
      animation: read-progress linear both;
      animation-timeline: scroll(root block);
    }
  }
}

@keyframes read-progress {
  to {
    clip-path: inset(0 0 0 0);
  }
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--ink);
}

.brand:hover {
  text-decoration: none;
}

/* The glowcap mark from ui/mark.css, the still artwork the tab icon also
   shows. Size is this header's; the drawing and its hover bloom are the shared
   sheet's. No shader here: at this size almost nothing that makes the shader
   worth drawing survives, and the chrome is furniture. */
.brand .icon-mark {
  width: 22px;
  height: 22px;
}

/* The hero's shader takes the still artwork's place once this browser has
   drawn one: the same box at the same size, so nothing around it moves, and
   the drawing stands down. A browser with no device never earns the class and
   keeps the drawing. `.mark-live` starts hidden here rather than in the shared
   sheet, because rooms shows its own without ever earning this class. */
.hero-mark .mark-live {
  display: none;
  position: relative;
  flex: none;
}

.mark-shaded > .mark-live {
  display: block;
}

.mark-shaded > .icon-mark {
  display: none;
}

/* Where the script runs, the still waits for the verdict rather than
   showing first: a drawing that flashes and is then replaced by the shader
   spoils the arrival the shader exists for. `.mark-still` is the verdict
   that no device could be had, and only then does the drawing show. A page
   without the script never stamps `js` on the root and keeps the drawing
   from the first paint, and the box keeps its size either way. */
html.js .hero-mark:not(.mark-shaded):not(.mark-still) > .icon-mark {
  visibility: hidden;
}

.top-nav {
  display: flex;
  /* Centre, not the flex default of stretch: the links and the theme button are
     very different heights, and stretching makes each link a full-height box
     whose text then sits at the top, riding above the button beside it. */
  align-items: center;
  gap: 1.1rem;
  font-size: 0.95rem;
  flex-wrap: wrap;
}

.top-nav a {
  color: var(--ink-soft);
}

/* The application link: a small pill, so the one thing in the header that
   opens an app rather than a page reads as an action. */
.top-nav .top-nav-app {
  padding: 0.3rem 0.75rem;
  border: 1px solid var(--rule);
  border-radius: var(--radius-control);
  font-weight: 700;
  color: var(--accent-ink);
}

.top-nav .top-nav-app:hover {
  text-decoration: none;
  background: color-mix(in srgb, var(--accent) 10%, transparent);
}

/* The theme switch. It shows the theme you would move to, not the one you are
   in, so the icon reads as an action. Which icon that is comes straight from
   the same conditions that pick the palette, so the button cannot fall out of
   step with the page even before its script runs. */
/* A browser without `light-dark()` keeps the light palette no matter what
   the toggle stamps, so on those browsers the control retires rather than
   sit in the header doing nothing. */
@supports not (color: light-dark(#000, #fff)) {
  .theme-toggle {
    display: none;
  }
}

.theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
  width: var(--icon-button-size);
  height: var(--icon-button-size);
  padding: 0;
  cursor: pointer;
  color: var(--ink-soft);
  background: transparent;
  border: 1px solid var(--rule);
  border-radius: var(--radius-control);
  transition: color 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}

.theme-toggle:hover {
  color: var(--accent-ink);
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 10%, transparent);
}

.theme-toggle svg {
  display: block;
  width: 17px;
  height: 17px;
}

/* The face the button offers, which is the other one. Syrup is the default,
   so the sun is what an unstamped page shows, and the moon appears only once
   a reader has chosen light. The same selector that carries the theme carries
   the icon, so the two cannot disagree. */
.theme-toggle .icon-moon {
  display: none;
}

:root:not([data-theme="light"]) .theme-toggle .icon-sun {
  display: block;
}

:root[data-theme="light"] .theme-toggle .icon-moon {
  display: block;
}

:root[data-theme="light"] .theme-toggle .icon-sun {
  display: none;
}

/* ── Shell: sidebar + content ────────────────────────────────────────────── */

.shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  --shell-gap: clamp(1.25rem, 2.5vw, 2rem);
  gap: var(--shell-gap);
  /* The body is a flex column, where a centered item shrinks to its content. */
  width: 100%;
  max-width: 84rem;
  margin: 0 auto;
  padding: 0 var(--header-inset);
}

/* ── Print ───────────────────────────────────────────────────────────────────
   A printed page is the article alone: the chrome exists to move between
   pages, and paper has no pages to move between. Code listings wrap instead
   of scrolling, because a scrollbar on paper is just missing text. */
@media print {
  .site-header,
  .sidebar,
  .toc,
  .site-footer,
  .copy-btn,
  .docs-nav-toggle {
    display: none !important;
  }

  .shell {
    display: block;
    max-width: none;
    padding: 0;
  }

  pre,
  pre code {
    white-space: pre-wrap;
    overflow-wrap: anywhere;
  }
}

/* A browser without light-dark() drops the whole palette to invalid
   custom properties, so the plain declarations above carry the light
   arms and this block restores the pair where the function exists.
   Without it, the site keeps its light face everywhere. */
@supports (color: light-dark(#000, #fff)) {
  :root {
    --code-bg: light-dark(#f5e6ce, #191309);
    --shadow-near: light-dark(color-mix(in srgb, var(--ink) 6%, transparent), rgba(0, 0, 0, 0.4));
    --shadow-far: light-dark(color-mix(in srgb, var(--ink) 8%, transparent), rgba(0, 0, 0, 0.36));
    --dia-accent-deep: light-dark(var(--accent-deep), #eda04a);
    --dia-teal-deep: light-dark(var(--teal-deep), #5cc3cd);
    --syn-keyword: light-dark(#98499f, #d08ad6);
    --syn-call: light-dark(var(--teal-deep), #5cc3cd);
    --syn-string: light-dark(#476225, #a8c86a);
    --syn-number: light-dark(#985313, #e8a765);
    --syn-comment: light-dark(#736046, #8d7c60);
    --syn-punct: light-dark(#726249, #9c8b70);
  }
}
