/*
 * View — brand tokens. "A window from another point of view."
 *
 * THIS IS THE ONLY FILE ALLOWED TO CONTAIN RAW HEX. Components (styles.css) and
 * app code reference these semantic custom properties via var(), never a literal
 * colour — enforced by tests/unit/brand-nohex.test.ts. New colours are added
 * HERE with a recorded WCAG contrast ratio, asserted by
 * tests/unit/brand-tokens.test.ts — the numbers are load-bearing, not decoration.
 * (Croft brand-token discipline, per croft-pwa docs/DESIGN.md.)
 *
 * View expresses two weathers through the shared Croft semantic token roles.
 * The poetic palette names from the brand plan map onto the roles as noted; the
 * mapping is also logged in docs/CONVENTIONS.md.
 *
 *   LIGHT "morning air"           DARK "comforting storm"
 *   --sky   #F6F9FB → --bg        --storm #12181F → --bg
 *   --haze  #E3ECF2 → --surface   --cloud #1D2733 → --surface
 *   --water #9FBAC9 → --border    --rain  #55677A → --border
 *   --pine  #2E4B47 → --ink       --mist  #C9D4DC → --ink
 *   --dawn  #C97B3D → --accent    --lamp  #E8B36B → --accent
 *
 * The two accents are siblings — dawn light / lamp light — so the brand holds
 * across modes. Ratios below are the ACTUAL computed values.
 *
 * Type: Fraunces (display) + Inter (body/UI), self-hostable; system fallbacks.
 */

:root {
  /* --- Light theme (default): "morning air" — pale, airy, early daylight --- */
  --bg: #f6f9fb;          /* --sky: page background — pale morning white-blue */
  --surface: #e3ecf2;     /* --haze: cards, raised surfaces */
  --ink: #2e4b47;         /* --pine: primary/body text        (bg 8.97:1) */
  --ink-muted: #4e6b72;   /* slate — captions, mono machine facts (bg 5.41:1) */
  --accent: #c97b3d;      /* --dawn: primary action fill (first-light amber) */
  --accent-ink: #131f1b;  /* deep pine ink on --accent        (5.15:1) */
  --active: #2e5d53;      /* deep teal-pine — active/current fill */
  --active-ink: #f6f9fb;  /* sky ink on --active              (7.08:1) */
  --link: #8f511f;        /* darkened dawn amber — body-text links (bg 5.90:1, on surface 5.22:1) */
  --danger: #a23520;      /* terracotta rust — warning/destructive (not a 2nd accent) */
  --danger-ink: #f6f9fb;  /* sky ink on --danger              (6.48:1) */
  --border: #9fbac9;      /* --water: hairline dividers, quiet UI — decorative */
  --focus: #b4632c;       /* focus ring — dawn amber, deepened (bg 4.17:1) */
  --code-bg: #e3ecf2;     /* --haze: inline/code block background */

  /* --- Type roles --- */
  --font-display: 'Fraunces', Georgia, 'Times New Roman', serif;
  --font-body: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --font-mono: ui-monospace, 'SF Mono', 'Cascadia Code', Menlo, Consolas, monospace;

  /* Type scale (fixed ramp — new sizes join the ramp, never ad-hoc) */
  --t-stamp: 0.75rem;
  --t-caption: 0.8125rem;
  --t-body: 1rem;
  --t-lead: 1.125rem;
  --t-h3: 1.25rem;
  --t-h2: 1.5rem;
  --t-h1: 2rem;
  --t-wordmark: 1.5rem;

  /* Spacing (4px base) + radii + stroke */
  --s-1: 0.25rem;
  --s-2: 0.5rem;
  --s-3: 0.75rem;
  --s-4: 1rem;
  --s-5: 1.5rem;
  --s-6: 2rem;
  --s-7: 3rem;
  --r-s: 4px;
  --r-m: 8px;
  --r-l: 14px;
  --r-pill: 999px;
  --stroke: 1.5px;

  /* The window signature (Phase 3.4): a thin inset frame reading as glass. In
   * light mode the frame is a cool water hairline; the warm cast arrives in dark. */
  --window-frame: #cdd9e2;   /* frame edge — cool, quiet */
  --window-sill: #b9c9d4;    /* the sill line at the bottom edge */

  /* PWA manifest theme mirrors --bg; kept in sync by src/theme.ts */
  --theme-color: #f6f9fb;
}

[data-theme='dark'] {
  /* "storm, but comforting" — dark and weatherly, warm-inside-while-it-rains. */
  --bg: #12181f;          /* --storm: deep blue-slate, not black */
  --surface: #1d2733;     /* --cloud: surfaces */
  --ink: #c9d4dc;         /* --mist: primary/body text        (bg 11.85:1) */
  --ink-muted: #8b9cab;   /* muted mist — captions, mono facts (bg 6.33:1) */
  --accent: #e8b36b;      /* --lamp: lamplight amber — the comfort */
  --accent-ink: #12181f;  /* storm ink on --accent            (9.43:1) */
  --active: #6fb08c;      /* lamplit sea-green — active/current fill */
  --active-ink: #12181f;  /* storm ink on --active            (7.03:1) */
  --link: #e8b36b;        /* --lamp: lamplight amber links    (bg 9.43:1) */
  --danger: #e4795b;      /* rust, lightened for dark */
  --danger-ink: #12181f;  /* storm ink on --danger            (6.11:1) */
  --border: #55677a;      /* --rain: hairline dividers, quiet UI — decorative */
  --focus: #e8b36b;       /* focus ring — lamp amber          (bg 9.43:1) */
  --code-bg: #1d2733;     /* --cloud */

  /* The window warms slightly toward --lamp in the dark (Phase 3.4). */
  --window-frame: #3a4655;   /* frame edge — warm rainy slate */
  --window-sill: #4a3c2e;    /* sill line — a hint of lamplight below the glass */

  --theme-color: #12181f;
}

/*
 * View — components. TOKEN-ONLY: no raw hex lives here (enforced by
 * tests/unit/brand-nohex.test.ts). Every colour is a var() from tokens.css.
 * Mobile-first, single column; tabs move to a bottom bar on phones (thumb reach).
 */

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

html {
  color-scheme: light dark;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: var(--t-body);
  line-height: 1.55;
  -webkit-text-size-adjust: 100%;
}

/* --- Type --- */
h1,
h2,
h3 {
  font-family: var(--font-display);
  line-height: 1.15;
  margin: 0 0 var(--s-3);
}
h1 {
  font-size: var(--t-h1);
}
h2 {
  font-size: var(--t-h2);
}
h3 {
  font-size: var(--t-h3);
}
p {
  margin: 0 0 var(--s-4);
}
a {
  color: var(--link);
  text-underline-offset: 2px;
}
code,
kbd,
samp {
  font-family: var(--font-mono);
  font-size: 0.9em;
  background: var(--code-bg);
  padding: 0.1em 0.35em;
  border-radius: var(--r-s);
}
pre {
  font-family: var(--font-mono);
  background: var(--code-bg);
  padding: var(--s-4);
  border-radius: var(--r-m);
  overflow: auto;
}
pre code {
  background: none;
  padding: 0;
}

/* Machine facts (build stamp, status) render in mono muted — "if software
 * produced the value, it's mono". */
.mono {
  font-family: var(--font-mono);
  color: var(--ink-muted);
  font-size: var(--t-stamp);
}

/* --- Focus: visible everywhere, one ring --- */
:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
  border-radius: var(--r-s);
}

/* --- App shell --- */
.topbar {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  padding: var(--s-3) var(--s-4);
  border-bottom: var(--stroke) solid var(--border);
  background: var(--surface);
}
.wordmark {
  font-family: var(--font-display);
  font-size: var(--t-wordmark);
  font-weight: 600;
  letter-spacing: 0.01em;
  color: var(--ink);
  text-decoration: none;
  margin-right: auto;
}
.topbar-action {
  background: none;
  border: var(--stroke) solid var(--border);
  color: var(--ink);
  border-radius: var(--r-pill);
  padding: var(--s-1) var(--s-3);
  font: inherit;
  cursor: pointer;
  min-height: 40px;
}

main {
  max-width: 52rem;
  margin: 0 auto;
  padding: var(--s-5) var(--s-4) var(--s-7);
}

.panel {
  background: var(--surface);
  border: var(--stroke) solid var(--border);
  border-radius: var(--r-l);
  padding: var(--s-5);
  margin-bottom: var(--s-5);
}

/* --- Tabs: top on wide screens, bottom bar on phones --- */
.tabs {
  display: flex;
  gap: var(--s-2);
  padding: var(--s-2) var(--s-4);
  border-bottom: var(--stroke) solid var(--border);
  overflow-x: auto;
}
.tab {
  padding: var(--s-2) var(--s-3);
  border-radius: var(--r-pill);
  color: var(--ink-muted);
  text-decoration: none;
  white-space: nowrap;
  min-height: 40px;
  display: inline-flex;
  align-items: center;
}
.tab[aria-current='page'] {
  background: var(--active);
  color: var(--active-ink);
}

/* --- Buttons --- */
.btn {
  font: inherit;
  cursor: pointer;
  border-radius: var(--r-m);
  padding: var(--s-2) var(--s-4);
  min-height: 44px;
  border: var(--stroke) solid transparent;
}
.btn-primary {
  background: var(--accent);
  color: var(--accent-ink);
}
.btn-secondary {
  background: transparent;
  border-color: var(--border);
  color: var(--ink);
}
.btn-danger {
  background: var(--danger);
  color: var(--danger-ink);
}

/* =====================================================================
 * The window — View's one deliberate signature (Phase 3.4).
 * A thin inset frame with a soft inner shadow and a sill line at the bottom
 * edge, so a scene reads as *through* glass, not pasted on the page. A few px,
 * no skeuomorphism. In dark mode the frame + sill warm toward lamplight
 * (--window-* tokens re-tune per theme).
 * ===================================================================== */
.stage {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  background: var(--surface);
  border: var(--stroke) solid var(--window-frame);
  border-bottom-width: 3px;
  border-bottom-color: var(--window-sill);
  border-radius: var(--r-l);
  overflow: hidden;
  /* soft inner shadow = the glass */
  box-shadow: inset 0 1px 10px rgb(0 0 0 / 0.14), inset 0 0 0 var(--stroke) var(--window-frame);
}
.stage-media {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
}
.stage-media video,
.stage-media iframe {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
  object-fit: cover;
  display: block;
}
/* Poster placeholder drawn in-brand (no network) — a calm horizon through glass. */
.stage-poster {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: linear-gradient(180deg, var(--surface) 0%, var(--bg) 62%, var(--surface) 100%);
  color: var(--ink-muted);
}
.stage-poster::after {
  /* the horizon line */
  content: '';
  position: absolute;
  left: 8%;
  right: 8%;
  top: 62%;
  height: var(--stroke);
  background: var(--window-sill);
  opacity: 0.7;
}
.stage-play {
  position: relative;
  z-index: 2;
}
/* Crossfade layer for scene changes; reduced-motion collapses it (global rule). */
.stage-media {
  opacity: 1;
  transition: opacity 480ms ease;
}
.stage-media.is-fading {
  opacity: 0;
}

/* Credit chip — every scene renders its credit + link (constraint C2). */
.credit {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: var(--s-2);
  margin-top: var(--s-3);
  font-size: var(--t-caption);
  color: var(--ink-muted);
}
.credit .credit-license {
  font-family: var(--font-mono);
  font-size: var(--t-stamp);
  border: var(--stroke) solid var(--border);
  border-radius: var(--r-pill);
  padding: 0 var(--s-2);
}

/* Shelf navigation — Live · Parks · Mine */
.shelf-nav {
  display: flex;
  gap: var(--s-2);
  margin: var(--s-4) 0;
  flex-wrap: wrap;
}
.shelf-btn {
  font: inherit;
  cursor: pointer;
  min-height: 40px;
  padding: var(--s-1) var(--s-4);
  border-radius: var(--r-pill);
  border: var(--stroke) solid var(--border);
  background: transparent;
  color: var(--ink);
}
.shelf-btn[aria-pressed='true'] {
  background: var(--active);
  color: var(--active-ink);
  border-color: var(--active);
}

/* Scene rail — the thumbnails under the stage for the current shelf */
.rail {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(9rem, 1fr));
  gap: var(--s-3);
  margin-top: var(--s-4);
  list-style: none;
  padding: 0;
}
.rail-item {
  margin: 0;
}
.scene-card {
  display: block;
  width: 100%;
  text-align: left;
  cursor: pointer;
  font: inherit;
  color: var(--ink);
  background: var(--surface);
  border: var(--stroke) solid var(--border);
  border-radius: var(--r-m);
  padding: 0;
  overflow: hidden;
}
.scene-card[aria-current='true'] {
  border-color: var(--accent);
  outline: var(--stroke) solid var(--accent);
}
/* Rail thumbnails are quiet: a plain glass wash, no horizon line. The horizon is
 * the signature reserved for the big stage — repeating it on every thumbnail was
 * the one decoration removed in the Phase 3.7 critique pass. */
.scene-thumb {
  aspect-ratio: 16 / 9;
  background: linear-gradient(180deg, var(--surface) 0%, var(--bg) 70%, var(--surface) 100%);
  position: relative;
}
.scene-meta {
  padding: var(--s-2) var(--s-3) var(--s-3);
}
.scene-title {
  display: block;
  font-weight: 600;
}
.scene-sub {
  display: block;
  font-size: var(--t-caption);
  color: var(--ink-muted);
  margin-top: var(--s-1);
}
.scene-arrow {
  font-size: var(--t-caption);
  color: var(--link);
}

/* Empty shelf — an invitation, never a blank box. */
.empty {
  border: var(--stroke) dashed var(--border);
  border-radius: var(--r-l);
  padding: var(--s-6);
  text-align: center;
  color: var(--ink-muted);
}

/* --- Footer: license line (left) + About/Croft (right) --- */
.build-stamp {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-3);
  flex-wrap: wrap;
  padding: var(--s-4);
  border-top: var(--stroke) solid var(--border);
}
.footer-license {
  font-size: var(--t-caption);
  color: var(--ink-muted);
}
.footer-license a {
  color: var(--link);
}
.footer-right {
  display: inline-flex;
  gap: var(--s-3);
  align-items: baseline;
}
.croft-attr {
  font-family: var(--font-display);
  font-size: var(--t-caption);
  color: var(--ink-muted);
  text-decoration: none;
}
.croft-attr:hover {
  color: var(--link);
}

/* --- Update toast ("ask, don't ambush") --- */
.update-toast {
  position: fixed;
  left: 50%;
  bottom: var(--s-4);
  transform: translateX(-50%);
  z-index: 40;
  display: flex;
  align-items: center;
  gap: var(--s-3);
  max-width: calc(100vw - var(--s-5));
  padding: var(--s-2) var(--s-3);
  background: var(--surface);
  color: var(--ink);
  border: var(--stroke) solid var(--border);
  border-radius: var(--r-l);
  box-shadow: 0 6px 20px rgb(0 0 0 / 0.18);
}
.update-toast .btn {
  min-height: 36px;
  padding: var(--s-1) var(--s-3);
}

/* --- Metrics list --- */
.measure-list {
  list-style: none;
  margin: 0;
  padding: 0;
}
.measure-list li {
  padding: var(--s-2) 0;
  border-bottom: var(--stroke) solid var(--border);
  overflow-wrap: anywhere;
}
.measure-list li:last-child {
  border-bottom: none;
}

/* --- Legend (about page licensing) --- */
.legend {
  list-style: none;
  margin: 0;
  padding: 0;
}
.legend li {
  padding: var(--s-3) 0;
  border-bottom: var(--stroke) solid var(--border);
}
.legend li:last-child {
  border-bottom: none;
}
.legend .legend-shelf {
  font-family: var(--font-mono);
  font-size: var(--t-stamp);
  border: var(--stroke) solid var(--border);
  border-radius: var(--r-pill);
  padding: 0 var(--s-2);
  margin-right: var(--s-2);
}

/* =====================================================================
 * Kiosk mode — full-viewport stage, chrome hidden, a minimal overlay that
 * fades after idle.
 * ===================================================================== */
.kiosk .stage {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  aspect-ratio: auto;
  border: 0;
  border-radius: 0;
  box-shadow: none;
}
.kiosk-overlay {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  gap: var(--s-3);
  flex-wrap: wrap;
  padding: var(--s-4);
  color: var(--active-ink);
  background: linear-gradient(0deg, rgb(0 0 0 / 0.55), rgb(0 0 0 / 0));
  opacity: 1;
  transition: opacity 600ms ease;
}
.kiosk-overlay.is-hidden {
  opacity: 0;
  pointer-events: none;
}
.kiosk-overlay .kiosk-title {
  font-family: var(--font-display);
  font-size: var(--t-h3);
}
.kiosk-overlay .credit {
  margin: 0;
  color: inherit;
}

@media (max-width: 40rem) {
  main {
    padding: var(--s-4) var(--s-3) var(--s-7);
  }
  .tabs {
    position: sticky;
    bottom: 0;
    top: auto;
    border-top: var(--stroke) solid var(--border);
    border-bottom: none;
    background: var(--surface);
    justify-content: space-around;
  }
  .update-toast {
    bottom: calc(var(--s-7) + var(--s-3));
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    transition-duration: 0.001ms !important;
  }
}
