/* ============================================================
   INSIDE THE GROOVE — design tokens + chrome
   "Bench manual" system, continuous with the explorer series:
   warm linen paper chrome, deep charcoal reserved for the stage.
   Series semantic constants: electrical signal = green, acoustic
   programme = amber. Stored modulation (violet) carried over from
   the tape machine's recorded flux — the groove stores the same
   programme, in shape instead of magnetism.
   ============================================================ */

@font-face { font-family: 'Fraunces'; src: url('../fonts/fraunces-latin-400-normal.woff2') format('woff2'); font-weight: 400; font-display: swap; }
@font-face { font-family: 'Fraunces'; src: url('../fonts/fraunces-latin-600-normal.woff2') format('woff2'); font-weight: 600; font-display: swap; }
@font-face { font-family: 'Fraunces'; src: url('../fonts/fraunces-latin-700-normal.woff2') format('woff2'); font-weight: 700; font-display: swap; }
@font-face { font-family: 'IBM Plex Sans'; src: url('../fonts/ibm-plex-sans-latin-400-normal.woff2') format('woff2'); font-weight: 400; font-display: swap; }
@font-face { font-family: 'IBM Plex Sans'; src: url('../fonts/ibm-plex-sans-latin-500-normal.woff2') format('woff2'); font-weight: 500; font-display: swap; }
@font-face { font-family: 'IBM Plex Sans'; src: url('../fonts/ibm-plex-sans-latin-600-normal.woff2') format('woff2'); font-weight: 600; font-display: swap; }
@font-face { font-family: 'IBM Plex Mono'; src: url('../fonts/ibm-plex-mono-latin-400-normal.woff2') format('woff2'); font-weight: 400; font-display: swap; }
@font-face { font-family: 'IBM Plex Mono'; src: url('../fonts/ibm-plex-mono-latin-500-normal.woff2') format('woff2'); font-weight: 500; font-display: swap; }

:root {
  --paper: #f1ede4;
  --paper-raised: #f8f5ee;
  --paper-sunken: #e7e2d6;
  --paper-line: #d5cebe;
  --paper-line-strong: #b9b09b;
  --ink: #26231c;
  --ink-soft: #57503f;
  --ink-faint: #7d7460;
  --stage-hi: #24211b;
  --stage-lo: #131109;
  --stage-text: #ece5d4;
  --stage-text-soft: #b3ab97;
  --brass: #8a5a1d;
  --brass-bright: #c8963c;
  --signal: #43b581;
  --sound: #e0a458;
  --stored: #9b85dd;
  --motion: #d8c9a6;
  --danger: #b3402e;
  --font-display: 'Fraunces', 'Iowan Old Style', georgia, serif;
  --font-body: 'IBM Plex Sans', -apple-system, 'Segoe UI', sans-serif;
  --font-data: 'IBM Plex Mono', ui-monospace, 'SF Mono', monospace;
  --rad-md: 8px;
  --rad-lg: 14px;
  --rad-pill: 999px;
  --shadow-2: 0 2px 8px rgba(38, 35, 28, 0.1), 0 1px 2px rgba(38, 35, 28, 0.06);
  --shadow-3: 0 12px 32px rgba(38, 35, 28, 0.16), 0 2px 8px rgba(38, 35, 28, 0.08);
  --shadow-stage-inset: inset 0 1px 12px rgba(0, 0, 0, 0.55);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.55;
  overflow-x: hidden;
}
button { font: inherit; color: inherit; background: none; border: none; cursor: pointer; }
:focus-visible { outline: 2px solid var(--brass); outline-offset: 2px; border-radius: 4px; }

.app {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  height: 100vh;
  height: 100dvh;
  max-width: 1560px;
  margin: 0 auto;
  padding: 0 20px 16px;
  gap: 14px;
}

/* ---- masthead ---- */
/* Title sets its own width; the lede and capabilities take every pixel that is
   left, so both run out to the same right edge as the rail below them. */
.masthead {
  padding: 18px 6px 0;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: end;
  column-gap: 36px;
  row-gap: 8px;
}
.mast-say { min-width: 0; }
.masthead .eyebrow {
  font-family: var(--font-data); font-size: 11px; letter-spacing: 0.14em;
  text-transform: uppercase; color: var(--ink-faint); margin-bottom: 6px;
}
.masthead h1 { font-family: var(--font-display); font-weight: 700; font-size: clamp(28px, 3.4vw, 40px); line-height: 1.05; }
.masthead .lede { color: var(--ink-soft); margin: 0; text-wrap: pretty; }
.capabilities {
  font-family: var(--font-data); font-size: 12px; color: var(--ink-faint);
  display: flex; gap: 14px; flex-wrap: wrap; margin-top: 8px; padding-bottom: 4px;
}
.capabilities span::before { content: '▸ '; color: var(--brass); }

/* ---- main row ---- */
.main { display: grid; grid-template-columns: minmax(0, 1fr) 350px; gap: 14px; min-height: 0; }

/* ---- stage ---- */
#stage {
  position: relative; border-radius: var(--rad-lg); overflow: hidden;
  background: linear-gradient(180deg, var(--stage-hi), var(--stage-lo));
  box-shadow: var(--shadow-stage-inset), var(--shadow-2);
  min-height: 520px;
}
#gl { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; cursor: grab; }
#gl.grabbing { cursor: grabbing; }
#gl.scratching { cursor: ew-resize; }
#gl.press { cursor: pointer; }
#leaders { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
#leaders .leader { stroke: rgba(236, 229, 212, 0.42); stroke-width: 1; fill: none; }
#leaders .leader-dot { fill: rgba(236, 229, 212, 0.7); stroke: none; }
#leaders .leader-selected { stroke: var(--brass-bright); fill: var(--brass-bright); opacity: 1; }

.callout {
  position: absolute; transform: translateY(-50%);
  font-family: var(--font-data); font-size: 11.5px; letter-spacing: 0.04em;
  color: var(--stage-text); background: rgba(19, 17, 9, 0.55);
  border: 1px solid rgba(236, 229, 212, 0.22);
  padding: 4px 9px; border-radius: var(--rad-pill);
  transition: opacity 0.25s, border-color 0.2s;
  backdrop-filter: blur(3px);
  white-space: nowrap;
}
.callout:hover { border-color: rgba(236, 229, 212, 0.55); }
.callout.is-selected { border-color: var(--brass-bright); color: var(--brass-bright); }

/* stage overlays */
.stage-veil {
  position: absolute; inset: 0; display: grid; place-items: center;
  background: linear-gradient(180deg, rgba(36, 33, 27, 0.55), rgba(19, 17, 9, 0.75));
  z-index: 5; text-align: center; color: var(--stage-text); padding: 24px;
}
.stage-veil[hidden] { display: none; }
.veil-inner .veil-title { font-family: var(--font-display); font-weight: 600; font-size: 26px; margin-bottom: 8px; }
.veil-inner p { color: var(--stage-text-soft); max-width: 46ch; margin: 0 auto 18px; }
.begin-btn {
  font-family: var(--font-data); font-size: 14px; letter-spacing: 0.12em; text-transform: uppercase;
  color: var(--stage-lo); background: var(--brass-bright);
  padding: 12px 34px; border-radius: var(--rad-pill);
  box-shadow: 0 4px 18px rgba(200, 150, 60, 0.35);
}
.begin-btn:hover { filter: brightness(1.06); }
#cutting { font-family: var(--font-data); color: var(--stage-text-soft); letter-spacing: 0.06em; }

#hint {
  position: absolute; left: 50%; bottom: 14px; transform: translateX(-50%);
  font-family: var(--font-data); font-size: 11.5px; color: var(--stage-text-soft);
  background: rgba(19, 17, 9, 0.6); border: 1px solid rgba(236, 229, 212, 0.16);
  padding: 6px 14px; border-radius: var(--rad-pill); pointer-events: none;
  transition: opacity 0.6s; z-index: 4; white-space: nowrap;
}
#hint.hide { opacity: 0; }

.status {
  position: absolute; top: 12px; right: 14px; z-index: 4;
  font-family: var(--font-data); font-size: 11.5px; color: var(--stage-text-soft);
  display: flex; gap: 14px;
}
.status span { background: rgba(19, 17, 9, 0.5); padding: 3px 8px; border-radius: 6px; }

/* part card */
#partCard {
  position: absolute; left: 14px; bottom: 14px; z-index: 4; max-width: 420px;
  background: var(--paper-raised); border-radius: var(--rad-md);
  box-shadow: var(--shadow-3); padding: 14px 16px;
}
#partCard h3 { font-family: var(--font-display); font-weight: 600; font-size: 18px; margin-bottom: 4px; }
#partRole { color: var(--ink); font-weight: 500; margin-bottom: 6px; }
#partDetail { color: var(--ink-soft); font-size: 13.5px; }
#partExam {
  margin-top: 8px; font-family: var(--font-data); font-size: 11.5px;
  color: var(--brass); border-top: 1px solid var(--paper-line); padding-top: 8px;
}

/* ---- rail ---- */
.rail {
  display: flex; flex-direction: column; gap: 12px;
  min-width: 0; min-height: 0; overflow-y: auto;
  scrollbar-gutter: stable; padding-right: 2px;
}
.panel {
  background: var(--paper-raised); border: 1px solid var(--paper-line);
  border-radius: var(--rad-md); padding: 14px 16px; box-shadow: var(--shadow-2);
}
.panel h2 {
  font-family: var(--font-data); font-size: 11px; letter-spacing: 0.14em;
  text-transform: uppercase; color: var(--ink-faint); margin-bottom: 10px; font-weight: 500;
}

.lesson-item {
  display: flex; flex-direction: column; align-items: flex-start; width: 100%;
  text-align: left; padding: 6px 10px; border-radius: var(--rad-md); line-height: 1.25;
  border: 1px solid transparent;
}
.lesson-item:hover { background: var(--paper); border-color: var(--paper-line); }
.lesson-item span {
  font-family: var(--font-data); font-size: 9.5px; letter-spacing: 0.09em;
  text-transform: uppercase; color: var(--brass); line-height: 1.6;
}
.lesson-item { font-family: var(--font-display); font-weight: 600; font-size: 15.5px; }

#lessonPanel[hidden] { display: none; }
#lessonEyebrow { font-family: var(--font-data); font-size: 10.5px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--brass); }
#lessonTitle { font-family: var(--font-display); font-weight: 600; font-size: 19px; margin: 2px 0 8px; }
#lessonCopy { color: var(--ink-soft); font-size: 13.8px; min-height: 104px; }
#lessonSource { font-family: var(--font-data); font-size: 10.5px; color: var(--ink-faint); margin-top: 8px; }
.lesson-nav { display: flex; align-items: center; gap: 8px; margin-top: 10px; }
.lesson-nav button {
  font-family: var(--font-data); font-size: 12px; padding: 5px 12px;
  border: 1px solid var(--paper-line-strong); border-radius: var(--rad-pill);
}
.lesson-nav button:hover { background: var(--paper-sunken); }
#lessonPos { font-family: var(--font-data); font-size: 11px; color: var(--ink-faint); margin-left: auto; }
#lessonRange { width: 100%; margin-top: 10px; accent-color: var(--brass); }
#lessonClose { margin-left: auto; color: var(--ink-faint); font-size: 18px; line-height: 1; }
.lesson-head { display: flex; align-items: flex-start; }

#scope { width: 100%; height: 92px; display: block; border-radius: 6px;
  background: linear-gradient(180deg, var(--stage-hi), var(--stage-lo));
  box-shadow: var(--shadow-stage-inset); }

#legend { list-style: none; display: grid; grid-template-columns: 1fr 1fr; gap: 9px 14px; font-size: 12.5px; color: var(--ink-soft); }
#legend li { display: grid; grid-template-columns: 11px minmax(0, 1fr); gap: 8px; align-items: start; }
#legend b { display: block; font-weight: 500; font-size: 12px; color: var(--ink); }
.legend-desc { display: block; font-size: 11px; line-height: 1.35; color: var(--ink-faint); }
.swatch { width: 11px; height: 11px; border-radius: 3px; flex: none; margin-top: 3px; }
.swatch-stored { background: var(--stored); }
.swatch-signal { background: var(--signal); }
.swatch-sound { background: var(--sound); }
.swatch-motion { background: var(--motion); }
.notes { margin-top: 12px; border-top: 1px solid var(--paper-line); padding-top: 8px; }
.notes summary {
  cursor: pointer; font-family: var(--font-data); font-size: 10.5px;
  letter-spacing: 0.1em; text-transform: uppercase; color: var(--ink-faint);
}
.notes summary::marker { color: var(--brass); }
.fineprint { font-size: 11.5px; color: var(--ink-faint); margin-top: 8px; line-height: 1.5; }
.fineprint + .fineprint { margin-top: 4px; }

#examToggle {
  width: 100%; text-align: left; font-family: var(--font-data); font-size: 11px;
  letter-spacing: 0.14em; text-transform: uppercase; color: var(--ink-faint); font-weight: 500;
}
#examToggle::after { content: ' ⇄'; color: var(--brass); }
#examDrawer[hidden] { display: none; }
#examDrawer { margin-top: 10px; }
.exam-note { font-size: 11.5px; color: var(--ink-faint); margin-bottom: 8px; }
#examList details { border-top: 1px solid var(--paper-line); padding: 7px 0; }
#examList summary { cursor: pointer; font-size: 13px; color: var(--ink); font-weight: 500; }
#examList details p { font-size: 12.5px; color: var(--ink-soft); padding: 6px 0 2px 14px; }

/* ---- transport ---- */
.transport {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  background: var(--paper-raised); border: 1px solid var(--paper-line);
  border-radius: var(--rad-md); box-shadow: var(--shadow-2); padding: 10px 14px;
}
.transport .grow { flex: 1; }
#playBtn {
  font-family: var(--font-data); font-size: 13px; letter-spacing: 0.08em;
  background: var(--ink); color: var(--paper); padding: 8px 20px; border-radius: var(--rad-pill);
}
#playBtn:hover { background: #3a352a; }
.chip {
  font-family: var(--font-data); font-size: 12px; padding: 6px 14px;
  border: 1px solid var(--paper-line-strong); border-radius: var(--rad-pill);
  color: var(--ink-soft); transition: background 0.15s, color 0.15s;
}
.chip[aria-pressed="true"] { background: var(--brass); border-color: var(--brass); color: var(--paper-raised); }
.chip:hover:not([aria-pressed="true"]) { background: var(--paper-sunken); }
#pitchRead { font-family: var(--font-data); font-size: 11.5px; color: var(--ink-faint); }
.viewpills { position: relative; display: flex; gap: 4px; background: var(--paper-sunken); border-radius: var(--rad-pill); padding: 3px; }
.pill-thumb {
  position: absolute; top: 3px; bottom: 3px; left: 0; width: 0;
  background: var(--paper-raised); border-radius: var(--rad-pill); box-shadow: var(--shadow-2);
}
.viewpills.pill-ready .pill-thumb {
  transition: left 0.5s cubic-bezier(0.34, 1.56, 0.64, 1), width 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.viewpills button {
  position: relative; z-index: 1;
  font-family: var(--font-data); font-size: 12px; padding: 6px 15px; border-radius: var(--rad-pill);
  color: var(--ink-soft);
}
.viewpills button[aria-pressed="true"] { color: var(--ink); }

/* ---- short windows: the machine keeps the room ---- */
@media (max-height: 780px) {
  .masthead { padding-top: 12px; }
  .masthead h1 { font-size: 30px; }
  .capabilities { display: none; }
  #stage { min-height: 400px; }
  .panel { padding: 11px 13px; }
  #scope { height: 72px; }
  #lessonCopy { min-height: 88px; }
}

/* ---- responsive ---- */
@media (max-width: 1080px) {
  .app { height: auto; min-height: 100vh; }
  .masthead { grid-template-columns: 1fr; }
  .main { grid-template-columns: 1fr; }
  .rail { overflow-y: visible; }
  #stage { min-height: 440px; }
}
@media (max-width: 560px) {
  .app { padding: 0 10px 10px; }
  #stage { min-height: 360px; }
  #partCard { max-width: calc(100% - 28px); }
  .status { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
