/* Level Up — design system and app shell.
   Tokens are docs/brand.md verbatim, one set per mode. Dark is the default so
   an unstamped document is the theme that has always shipped; the inline
   script in index.html <head> stamps :root[data-theme] before first paint
   (stored choice → OS preference → local clock; see docs/build-ftue2.md 2b).
   The accent pair flips with the mode: on dark the accent is the lighter
   #E0308A and its labels are NEAR-BLACK; on light it is the darker #B01C74
   and its labels are white. Same hue family, measured both ways — the token
   pair is what components use so no surface re-decides it.
   Coral belongs to the logo alone. Plum decorates; it never carries text. */

/* ---------------------------------------------------------------- fonts */

@font-face { font-family: 'Bricolage'; src: url('/fonts/bricolage-600.woff2') format('woff2'); font-weight: 600; font-display: swap; }
@font-face { font-family: 'Bricolage'; src: url('/fonts/bricolage-700.woff2') format('woff2'); font-weight: 700; font-display: swap; }
@font-face { font-family: 'Instrument'; src: url('/fonts/instrument-400.woff2') format('woff2'); font-weight: 400; font-display: swap; }
@font-face { font-family: 'Instrument'; src: url('/fonts/instrument-500.woff2') format('woff2'); font-weight: 500; font-display: swap; }
@font-face { font-family: 'Instrument'; src: url('/fonts/instrument-600.woff2') format('woff2'); font-weight: 600; font-display: swap; }
@font-face { font-family: 'SplineMono'; src: url('/fonts/splinemono-400.woff2') format('woff2'); font-weight: 400; font-display: swap; }
@font-face { font-family: 'SplineMono'; src: url('/fonts/splinemono-500.woff2') format('woff2'); font-weight: 500; font-display: swap; }

/* ---------------------------------------------------------------- tokens */

:root {
  --canvas: #0D0D0F;
  --surface: #1C1C1F;
  --raised: #232326;
  --line: #2E2E33;
  --text: #FFFFFF;
  --muted: #8E8E93;
  --accent: #E0308A;
  --accent-on: #0D0D0F;      /* labels ON accent fills — near-black on dark's lighter pink */
  --accent-text: #EC4A9C;    /* magenta that passes on dark */
  --accent-tint: rgba(224, 48, 138, .12);
  --plum: #8E2C6E;           /* decoration only, never text */

  /* Derived accent inks: hairline borders and soft glows in the accent hue.
     Two strengths each, so a surface never invents its own alpha. */
  --accent-line: rgba(224, 48, 138, .5);       /* error borders, event chips */
  --accent-line-soft: rgba(224, 48, 138, .35); /* selected chips and controls */
  --accent-glow: rgba(224, 48, 138, .5);       /* glow shadows around accent marks */
  --accent-glow-dim: rgba(224, 48, 138, .25);  /* the faint end of a glow */

  /* Glass: translucent surfaces over content (tab bar, map chrome, feed rail).
     Canvas-tinted in dark, paper-tinted in light. */
  --glass-nav: rgba(13, 13, 15, .97);
  --glass-veil: rgba(13, 13, 15, .72);         /* hint pills, attribution */
  --glass-bar: rgba(13, 13, 15, .82);          /* the time instrument */
  --glass-panel: rgba(28, 28, 31, .96);        /* floating cards and panels */
  --glass-btn: rgba(28, 28, 31, .88);          /* floating round controls */
  --glass-raised: rgba(35, 35, 38, .72);       /* feed action buttons */
  --glass-raised-hov: rgba(46, 46, 51, .85);

  /* Foreground at reduced weight, over the canvas (feed cards, rails).
     White-based on dark, ink-based on light — never behind media, which
     keeps its own scrim and its own literal white. */
  --text-hi: rgba(255, 255, 255, .88);
  --text-mid: rgba(255, 255, 255, .62);
  --faint: rgba(255, 255, 255, .32);
  --faint-mid: rgba(255, 255, 255, .5);
  --faint-strong: rgba(255, 255, 255, .7);

  --meter-off: #4A4A52;      /* an unfilled meter slot — a step above --line */

  /* Immersive chat type-and-glow. In flight the words read as light (dim
     fill, strong halo); landed they resolve to full type with a residual.
     Both scopes REQUIRED — a white halo on a light page is invisible at
     best, so the light values are a design decision, not an inversion. */
  --imm-type: rgba(255, 255, 255, .96);
  --imm-type-dim: rgba(255, 255, 255, .30);
  --imm-glow-strong: 0 0 14px rgba(255, 255, 255, .55), 0 0 38px rgba(255, 255, 255, .22);
  --imm-glow-soft: 0 0 10px rgba(255, 255, 255, .16);

  --display: 'Bricolage', system-ui, sans-serif;
  --body: 'Instrument', system-ui, sans-serif;
  --mono: 'SplineMono', ui-monospace, monospace;

  --r-s: 10px;
  --r-m: 16px;
  --r-l: 22px;
  --r-pill: 999px;

  --nav-w: 216px;      /* desktop rail */
  --nav-h: 60px;       /* phone tab bar */

  /* THE reading measure, app-wide. `.col`, the chat column and the interview
     column all consume this one declaration — it lived on `.chat` first and
     the interview surface never saw it, which is how two chat surfaces
     shipped at two widths on the same day (punchlist 2026-08-08). Declared
     exactly once; test/measure.test.js fails the suite on a second
     declaration anywhere in src/web. A surface that wants a narrower line
     is a named variant of this token, never a second number in its own file. */
  --measure: 720px;

  --t: 150ms cubic-bezier(.2, .7, .3, 1);
  --shadow-1: 0 1px 2px rgba(0,0,0,.5), 0 6px 24px rgba(0,0,0,.35);
  --shadow-2: 0 2px 6px rgba(0,0,0,.55), 0 16px 48px rgba(0,0,0,.45);
}

/* Light mode. Stamped by the inline <head> script before first paint; never
   by a timer or a media-query listener, so the theme cannot change under
   someone mid-sentence. The surfaces get brighter, the accent gets DARKER —
   #B01C74, 6.43:1 under white labels — because the lighter pink that passes
   on near-black fails on white. Every colour-carrying token above must be
   re-stated here (test/theme.test.js holds the two sets to the same names).
   Shadows soften: the dark set's near-opaque black reads as soot on white. */
:root[data-theme="light"] {
  --canvas: #FFFFFF;
  --surface: #F4F4F6;
  --raised: #EAEAEE;
  --line: #D8D8DE;
  --text: #16161A;
  --muted: #5C5C66;
  --accent: #B01C74;
  --accent-on: #FFFFFF;      /* the pair flips: white labels on the darker pink */
  --accent-text: #B01C74;
  --accent-tint: rgba(176, 28, 116, .10);
  --plum: #8E2C6E;           /* still decoration only — 7.68:1 on white as ornament */

  --accent-line: rgba(176, 28, 116, .5);
  --accent-line-soft: rgba(176, 28, 116, .35);
  --accent-glow: rgba(176, 28, 116, .3);
  --accent-glow-dim: rgba(176, 28, 116, .15);

  --glass-nav: rgba(255, 255, 255, .97);
  --glass-veil: rgba(255, 255, 255, .9);
  --glass-bar: rgba(255, 255, 255, .9);
  --glass-panel: rgba(250, 250, 251, .96);
  --glass-btn: rgba(255, 255, 255, .88);
  --glass-raised: rgba(244, 244, 246, .8);
  --glass-raised-hov: rgba(228, 228, 233, .92);

  --text-hi: rgba(22, 22, 26, .92);
  --text-mid: #5C5C66;
  --faint: rgba(22, 22, 26, .35);
  --faint-mid: rgba(22, 22, 26, .55);
  --faint-strong: rgba(22, 22, 26, .75);

  /* Immersive type-and-glow, light: near-black type, and the halo goes
     WARM (accent-toned), tighter and weaker — white light on a white page
     is invisible, and a grey halo reads as a smudge. */
  --imm-type: rgba(22, 22, 26, .95);
  --imm-type-dim: rgba(22, 22, 26, .32);
  --imm-glow-strong: 0 0 8px rgba(176, 28, 116, .26), 0 0 20px rgba(176, 28, 116, .10);
  --imm-glow-soft: 0 0 4px rgba(176, 28, 116, .07);

  --meter-off: #B6B6C0;

  --shadow-1: 0 1px 2px rgba(22, 22, 26, .08), 0 6px 24px rgba(22, 22, 26, .10);
  --shadow-2: 0 2px 6px rgba(22, 22, 26, .10), 0 16px 48px rgba(22, 22, 26, .16);
}

/* ---------------------------------------------------------------- reset */

*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--canvas);
  color: var(--text);
  font: 400 15px/1.5 var(--body);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}
h1, h2, h3 { font-family: var(--display); margin: 0; letter-spacing: -.01em; }
h1 { font-size: 28px; font-weight: 700; }
h2 { font-size: 19px; font-weight: 600; }
h3 { font-size: 16px; font-weight: 600; }
p { margin: 0; }
a { color: var(--accent-text); text-decoration: none; }
a:hover { text-decoration: underline; }
button { font: inherit; }
img, video { max-width: 100%; display: block; }
::selection { background: var(--accent-tint); }

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

@media (prefers-reduced-motion: reduce) {
  /* iteration-count 1 is load-bearing: a .01ms INFINITE animation (typing
     dots, the climb rung, skeleton shimmer) never stops — it samples a new
     phase every frame and STROBES, which is worse for the people this
     media query exists for than the motion it replaces (review-animations,
     2026-08-09). One instant pass, then stillness. */
  *, *::before, *::after {
    transition-duration: .01ms !important;
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
  }
}

/* ------------------------------------------------------------- the rung */
/* The signature: the brand chevron re-cut in UI magenta. Nav active state,
   ladder rungs, slider handles, pending shimmer — one mark, one meaning:
   a step upward. Coral stays on the logo. */

.rung {
  display: inline-block;
  width: 14px; height: 14px;
  flex: none;
  background: currentColor;
  clip-path: polygon(50% 0%, 100% 44%, 78% 44%, 78% 100%, 22% 100%, 22% 44%, 0% 44%);
}
.rung--sm { width: 10px; height: 10px; }

/* --------------------------------------------------------------- layout */

#app {
  min-height: 100dvh;
  display: grid;
  grid-template-columns: var(--nav-w) 1fr;
}
#app.chrome-hidden { grid-template-columns: 1fr; }
#app.chrome-hidden .nav { display: none; }

main#view { min-width: 0; position: relative; }

/* Full-bleed surfaces (map, feed) opt in: the view fills the viewport and
   the rail floats above it. */
main#view.bleed { height: 100dvh; overflow: hidden; }

/* Column surfaces get a disciplined measure — THE measure, from :root. */
.col {
  max-width: var(--measure);
  margin: 0 auto;
  padding: 32px 24px 96px;
}
.col--wide { max-width: 960px; }

/* ------------------------------------------------------------------ nav */

.nav {
  position: sticky; top: 0;
  height: 100dvh;
  display: flex; flex-direction: column;
  gap: 4px;
  padding: 20px 12px;
  border-right: 1px solid var(--line);
  background: var(--canvas);
  z-index: 60;
}
.nav .wordmark {
  font-family: var(--display); font-weight: 700; font-size: 19px;
  color: var(--text);
  display: flex; align-items: center; gap: 9px;
  padding: 8px 12px 20px;
}
.nav .wordmark:hover { text-decoration: none; }
/* The one place coral exists in the interface: the logo mark itself — and it
   is now the asset rather than a CSS approximation of it. Sized by height with
   width auto, so the 699:915 ratio comes from the file and cannot drift; the
   width/height attributes in the markup carry that ratio before it loads, so
   nothing reflows. The source is 96px tall for a 22px slot — 2× and then some,
   because the extrusion is what softens first on a retina screen. */
.nav .wordmark .mark {
  height: 28px; width: auto; flex: none;
}

.nav a.item {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 12px;
  border-radius: var(--r-m);
  color: var(--muted);
  font-weight: 500;
  transition: background var(--t), color var(--t);
}
.nav a.item:hover { color: var(--text); background: var(--surface); text-decoration: none; }
.nav a.item[aria-current="page"] { color: var(--accent-text); background: var(--accent-tint); }
.nav a.item .rung { color: transparent; transition: color var(--t); }
.nav a.item[aria-current="page"] .rung { color: var(--accent-text); }
.nav a.item svg { width: 21px; height: 21px; flex: none; }

.nav .foot { margin-top: auto; padding: 8px 12px; color: var(--muted); font-size: 12.5px; }

/* Phone: bottom tab bar. */
@media (max-width: 760px) {
  #app { grid-template-columns: 1fr; }
  .nav {
    position: fixed; inset: auto 0 0 0;
    height: var(--nav-h);
    flex-direction: row; align-items: stretch;
    padding: 0 8px calc(env(safe-area-inset-bottom, 0px));
    border-right: 0; border-top: 1px solid var(--line);
    /* Glass on a childless ::before layer: the compositor silently drops
       backdrop-filter once the filtered element has painted descendants
       (diagnosed by the quests builder with headless probes). Ink raised to
       .97 so residue stays illegible wherever blur is unavailable. */
    background: transparent;
  }
  .nav::before {
    content: '';
    position: absolute;
    inset: 0;
    z-index: -1;
    background: var(--glass-nav);
    backdrop-filter: blur(18px);
    -webkit-backdrop-filter: blur(18px);
  }
  .nav .wordmark, .nav .foot { display: none; }
  .nav a.item { flex: 1; flex-direction: column; justify-content: center; gap: 3px; font-size: 10.5px; padding: 6px 4px; border-radius: var(--r-s); }
  .nav a.item[aria-current="page"] { background: transparent; }
  /* On phone the active state is colour alone: the rung chevron stays a
     desktop-rail mark. In column flow it wrapped below the label and clipped
     at the viewport edge (filed by the map and profile builders). */
  .nav a.item .rung { display: none; }
  .col { padding: 24px 16px calc(var(--nav-h) + 40px); }
  main#view.bleed { height: 100dvh; }
}

/* -------------------------------------------------------------- buttons */
/* Every control has: a pressed state on the same tick (:active), and a
   pending state (aria-busy) that reads as alive. Nothing may read as dead. */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 20px;
  border: 0; border-radius: var(--r-pill);
  background: var(--accent);
  color: var(--accent-on);           /* the measured pair: near-black on dark's pink, white on light's */
  font-weight: 600; font-size: 14.5px;
  cursor: pointer;
  transition: transform var(--t), filter var(--t), background var(--t);
  position: relative;
}
.btn:hover { filter: brightness(1.08); }
.btn:active { transform: scale(.97); filter: brightness(.92); }
.btn:disabled { opacity: .45; cursor: default; transform: none; }

.btn--quiet {
  background: var(--raised);
  color: var(--text);
}
.btn--quiet:hover { filter: brightness(1.15); }
.btn--ghost {
  background: transparent;
  color: var(--accent-text);
  box-shadow: inset 0 0 0 1px var(--line);
}
.btn--ghost:hover { background: var(--accent-tint); filter: none; }
.btn--sm { padding: 7px 14px; font-size: 13.5px; }

/* Pending: the rung climbs. Set aria-busy="true" on the same tick as the
   click; the label dims and the mark animates. */
.btn[aria-busy="true"] { pointer-events: none; color: transparent; }
.btn[aria-busy="true"]::after {
  content: '';
  position: absolute; inset: 0; margin: auto;
  width: 13px; height: 13px;
  background: var(--accent-on);
  clip-path: polygon(50% 0%, 100% 44%, 78% 44%, 78% 100%, 22% 100%, 22% 44%, 0% 44%);
  animation: climb .7s ease-in-out infinite;
}
.btn--quiet[aria-busy="true"]::after, .btn--ghost[aria-busy="true"]::after { background: var(--accent-text); }
@keyframes climb {
  0%, 100% { transform: translateY(3px); opacity: .6; }
  50% { transform: translateY(-3px); opacity: 1; }
}

/* ---------------------------------------------------------------- cards */

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-l);
  padding: 20px;
}
.card--raised { background: var(--raised); }
.card--flush { padding: 0; overflow: hidden; }

/* ----------------------------------------------------------------- rows */

.row { display: flex; align-items: center; gap: 12px; }
.spread { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.stack { display: flex; flex-direction: column; gap: 12px; }

/* A row sits flat on the canvas and is drawn by a 1px inset stroke — the same
   construction as .btn--ghost. Before this it had no resting state at all, so
   its bounds only appeared on hover. Hover lifts the stroke; the FILL is
   reserved for press and selection, which is what keeps the two readable as
   different things. Selected borrows --accent-line-soft rather than minting a
   fourth alpha in the accent hue: see the derived-inks note in :root. */
.listrow {
  display: flex; align-items: center; gap: 14px;
  padding: 14px 16px;
  border-radius: var(--r-m);
  transition: box-shadow var(--t), background var(--t);
  cursor: pointer;
  background: var(--canvas);
  box-shadow: inset 0 0 0 1px var(--raised);
}
.listrow + .listrow { margin-top: 6px; }
.listrow:hover { background: var(--canvas); box-shadow: inset 0 0 0 1px var(--line); }
.listrow:active { background: var(--surface); box-shadow: inset 0 0 0 1px var(--line); }
.listrow.selected { background: var(--accent-tint); box-shadow: inset 0 0 0 1px var(--accent-line-soft); }

/* ---------------------------------------------------------------- chips */

.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 12px;
  border-radius: var(--r-pill);
  background: var(--raised);
  color: var(--muted);
  font-size: 12.5px; font-weight: 500;
  border: 1px solid transparent;
  transition: all var(--t);
}
.chip--on { background: var(--accent-tint); color: var(--accent-text); border-color: var(--accent-line-soft); }
.chip--tag::before { content: '#'; opacity: .6; }

.pill {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 10px;
  border-radius: var(--r-pill);
  background: var(--accent-tint);
  color: var(--accent-text);
  font-size: 11.5px; font-weight: 600;
  letter-spacing: .02em;
}
.pill--grey { background: var(--raised); color: var(--muted); }

/* --------------------------------------------------------------- inputs */

.input, textarea.input, select.input {
  width: 100%;
  padding: 12px 14px;
  border-radius: var(--r-m);
  border: 1px solid var(--line);
  background: var(--raised);
  color: var(--text);
  font: inherit;
  transition: border-color var(--t), box-shadow var(--t);
}
.input::placeholder { color: var(--muted); }
.input:focus { outline: none; border-color: var(--accent-text); box-shadow: 0 0 0 3px var(--accent-tint); }
textarea.input { resize: vertical; min-height: 44px; }
label.lbl { display: block; font-size: 13px; font-weight: 500; color: var(--muted); margin: 14px 0 6px; }

/* ------------------------------------------------------------ stat tiles */

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 10px; }
.tile {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-m);
  padding: 14px 16px;
}
.tile .n { font-family: var(--display); font-weight: 700; font-size: 24px; }
.tile .k { color: var(--muted); font-size: 12.5px; margin-top: 2px; }

/* --------------------------------------------------------------- ladder */
/* Rungs of a ladder: the signature at content scale. */

.ladder { display: flex; flex-direction: column; gap: 0; }
.ladder .step { display: flex; gap: 14px; padding: 10px 0; }
.ladder .step .rail { display: flex; flex-direction: column; align-items: center; width: 16px; flex: none; }
.ladder .step .rail .rung { color: var(--line); }
.ladder .step.done .rail .rung { color: var(--accent-text); }
.ladder .step .rail .drop { flex: 1; width: 2px; background: var(--line); margin-top: 4px; }
.ladder .step:last-child .rail .drop { display: none; }

/* ---------------------------------------------------------------- toast */

#toast {
  position: fixed;
  left: 50%; bottom: 28px;
  transform: translateX(-50%) translateY(20px);
  background: var(--raised);
  border: 1px solid var(--line);
  color: var(--text);
  padding: 11px 18px;
  border-radius: var(--r-pill);
  box-shadow: var(--shadow-2);
  font-size: 14px;
  opacity: 0; pointer-events: none;
  transition: opacity var(--t), transform var(--t);
  z-index: 100;
  max-width: min(90vw, 480px);
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.err { border-color: var(--accent-line); }
@media (max-width: 760px) { #toast { bottom: calc(var(--nav-h) + 18px); } }

/* ------------------------------------------------------------- skeleton */

.skel {
  background: linear-gradient(100deg, var(--surface) 40%, var(--raised) 50%, var(--surface) 60%);
  background-size: 200% 100%;
  animation: skel 1.2s linear infinite;
  border-radius: var(--r-s);
  color: transparent;
}
@keyframes skel { to { background-position: -200% 0; } }

/* ------------------------------------------------------------ utilities */

.muted { color: var(--muted); }
.small { font-size: 13px; }
.mono { font-family: var(--mono); font-size: .92em; }
.center { text-align: center; }
.mt-1 { margin-top: 8px; } .mt-2 { margin-top: 16px; } .mt-3 { margin-top: 28px; }
.hidden { display: none !important; }

/* Decorative gradient — the ONLY sanctioned use of plum: a hairline that
   runs plum → magenta, for section accents and the hero edges of cards.
   Never behind text. */
.lotus-edge { height: 2px; border-radius: 2px; background: linear-gradient(90deg, var(--plum), var(--accent)); }

/* Empty states invite an action; they do not emote. */
.empty {
  border: 1px dashed var(--line);
  border-radius: var(--r-l);
  padding: 36px 24px;
  text-align: center;
  color: var(--muted);
}

/* --------------------------------------------------------- nav notices */
/* "There is something new here", per nav item. A bare dot for most surfaces
   and a count for Chat, because a conversation has a number of things in it
   and a map does not — see src/web/shell.js for the model and the rule that
   only entering a surface clears one.

   Everything here is tokens, so it themes for free. Deliberately quiet: this
   is an indicator, not a demand. No pulse, no bounce, nothing that moves. */
.nav-notice {
  margin-left: auto;
  flex: none;
  width: 7px;
  height: 7px;
  border-radius: var(--r-pill);
  background: var(--accent);
}
.nav-notice--count {
  width: auto;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  color: var(--accent-on);
  font: 500 11px/18px var(--mono);
  text-align: center;
}
@media (max-width: 760px) {
  /* On the phone tab bar the items are stacked icons, so the dot rides the
     corner of the item rather than sitting at the end of a row. */
  .nav a.item { position: relative; }
  .nav-notice { position: absolute; top: 6px; right: 12px; margin-left: 0; }
}
