/* ============================================================
   INSIDE THE ECHO — 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, mechanical motion = tan, runaway = danger red.
   ============================================================ */

@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;
  --motion: #d8c9a6;
  --danger: #b3402e;
  --danger-bright: #e0684f;
  --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 1fr auto;
  height: 100vh;
  max-width: 1560px;
  margin: 0 auto;
  padding: 0 20px 16px;
  gap: 14px;
}

/* ---- masthead ---- */
.masthead { padding: 22px 6px 0; display: flex; align-items: flex-end; justify-content: space-between; gap: 24px; flex-wrap: wrap; }
.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); max-width: 62ch; margin-top: 8px; }
.capabilities {
  font-family: var(--font-data); font-size: 12px; color: var(--ink-faint);
  display: flex; gap: 14px; flex-wrap: wrap; padding-bottom: 6px;
}
.capabilities span::before { content: '▸ '; color: var(--brass); }

/* ---- main row ---- */
.main { display: grid; grid-template-columns: minmax(0, 1fr) 330px; 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.dragging-head { cursor: ew-resize; }
#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); }
/* arrival pass: labels introduce themselves one at a time */
.callout.arriving { animation: arrive 0.6s ease-out both; }
@keyframes arrive {
  from { opacity: 0; transform: translateY(-50%) translateX(var(--arrive-dx, -8px)); }
  to { opacity: 1; transform: translateY(-50%); }
}

/* 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); }

#hint {
  position: absolute; left: 50%; bottom: 46px; 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; }

/* the caption line: one cause-and-effect sentence, spoken by the stage */
#caption {
  position: absolute; left: 50%; top: 44px; transform: translateX(-50%);
  max-width: min(88%, 70ch); text-align: center;
  font-family: var(--font-body); font-size: 13.5px; color: var(--stage-text);
  background: rgba(19, 17, 9, 0.72); border: 1px solid rgba(236, 229, 212, 0.2);
  padding: 7px 16px; border-radius: var(--rad-pill); pointer-events: none;
  z-index: 4; transition: opacity 0.4s;
}
#caption[hidden] { display: none; }
#caption.danger { border-color: var(--danger-bright); color: #f4c9bd; }

.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: 10px; flex-wrap: wrap; justify-content: flex-end; max-width: 60%;
}
.status span { background: rgba(19, 17, 9, 0.5); padding: 3px 8px; border-radius: 6px; }
.status .status-big { color: var(--sound); font-size: 13px; font-weight: 500; }
.status .is-danger { color: var(--danger-bright); }

/* part card */
#partCard {
  position: absolute; left: 14px; bottom: 14px; z-index: 4; max-width: 400px;
  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; }
.panel {
  background: var(--paper-raised); border: 1px solid var(--paper-line);
  border-radius: var(--rad-md); padding: 14px 16px; box-shadow: var(--shadow-2);
  flex: none;
}
.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;
}

/* control rows: label · slider · mono readout */
.ctl { display: grid; grid-template-columns: 82px 1fr 64px; align-items: center; gap: 8px; margin-bottom: 10px; }
.ctl[hidden] { display: none; }
.ctl label { font-family: var(--font-data); font-size: 11.5px; color: var(--ink-soft); }
.ctl input[type="range"] { width: 100%; accent-color: var(--brass); }
.ctl.is-danger input[type="range"] { accent-color: var(--danger); }
.ctl-read { font-family: var(--font-data); font-size: 11.5px; color: var(--ink); text-align: right; }
.ctl.is-danger .ctl-read { color: var(--danger); font-weight: 500; }
.ctl-chip { margin: 2px 0 8px; }
.ctl-chip[hidden] { display: none; }
.ctl.revealing, .ctl-chip.revealing { animation: ctl-in 0.45s ease-out both; }
@keyframes ctl-in { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

#scope { width: 100%; height: 80px; 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: flex; flex-direction: column; gap: 6px; font-size: 12.5px; color: var(--ink-soft); }
#legend li { display: flex; gap: 8px; align-items: center; }
.swatch { width: 11px; height: 11px; border-radius: 3px; flex: none; }
.swatch-signal { background: var(--signal); }
.swatch-sound { background: var(--sound); }
.swatch-motion { background: var(--motion); }
.swatch-danger { background: var(--danger-bright); }
.fineprint { font-size: 11.5px; color: var(--ink-faint); margin-top: 10px; 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; }
.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); }
.stabgroup { display: flex; gap: 6px; }
.stabgroup[data-ghost="1"] { opacity: 0.45; pointer-events: none; }

#fireBtn {
  font-family: var(--font-data); font-size: 13px; font-weight: 500; letter-spacing: 0.14em;
  color: var(--stage-lo); background: var(--brass-bright);
  padding: 9px 22px; border-radius: var(--rad-pill);
  box-shadow: 0 3px 14px rgba(200, 150, 60, 0.35);
  transition: transform 0.08s ease-out, filter 0.15s;
}
#fireBtn:hover { filter: brightness(1.06); }
#fireBtn:active, #fireBtn.pressed { transform: scale(0.94); }
#fireBtn.pulse { animation: fire-pulse 1.6s ease-in-out infinite; }
@keyframes fire-pulse {
  0%, 100% { box-shadow: 0 3px 14px rgba(200, 150, 60, 0.35); }
  50% { box-shadow: 0 3px 26px rgba(200, 150, 60, 0.75); }
}

.layerpills, .viewpills, .modepills {
  position: relative; display: flex; gap: 4px; background: var(--paper-sunken);
  border-radius: var(--rad-pill); padding: 3px;
}
.modepills[hidden] { display: none; }
.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);
}
.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);
}
.layerpills button, .viewpills button, .modepills button {
  position: relative; z-index: 1;
  font-family: var(--font-data); font-size: 12px; padding: 6px 13px; border-radius: var(--rad-pill);
  color: var(--ink-soft);
}
.layerpills button[aria-pressed="true"], .viewpills button[aria-pressed="true"], .modepills button[aria-pressed="true"] { color: var(--ink); }

/* ---- responsive ---- */
@media (max-height: 780px) {
  #stage { min-height: 400px; }
  .capabilities { display: none; }
  .masthead .lede { max-width: 96ch; }
}
@media (max-width: 1080px) {
  .main { grid-template-columns: 1fr; }
  #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; animation: none !important; }
}
