/* lore — the tape. Token-driven (room lineage): no color, font, or radius is
   hard-coded below — everything reads the 8 custom properties + radius that
   theme.js writes. Skins change tokens, never layout. Mobile first; the shell
   owns all scrolling. */

:root {
  --sans: -apple-system, system-ui, 'Helvetica Neue', sans-serif;
  --mono: 'JetBrains Mono', ui-monospace, monospace;
  /* track colors: the house seat palette's first four, machine-dimmed via
     opacity in the canvas, never re-invented per skin */
  --t0: #ff6a2b;
  --t1: #00e653;
  --t2: #4dc4ff;
  --t3: #ff8fb3;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--tx);
  font-family: var(--sans);
  overscroll-behavior: none;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}

button {
  touch-action: manipulation;
}

.machine {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: 560px;
  margin: 0 auto;
  background: var(--bg);
  padding-top: env(safe-area-inset-top);
}

/* ---------- header ---------- */

.header {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 52px;
  padding: 0 8px 0 14px;
  border-bottom: 1px solid var(--ln);
  flex: none;
}

.wordmark {
  font-weight: 800;
  font-size: 16px;
  letter-spacing: -0.01em;
  text-transform: lowercase;
  color: var(--tx);
}

.reelTitle {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--dim);
  text-align: left;
  background: none;
  border: none;
  padding: 10px 0;
  cursor: pointer;
}

.statusDot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--dim);
  opacity: 0.5;
  flex: none;
}

.statusDot.connected {
  background: var(--ac);
  opacity: 1;
}

.headerBtn {
  width: 44px;
  height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  color: var(--dim);
  font-size: 18px;
  cursor: pointer;
  padding: 0;
  flex: none;
}

.notice {
  font-family: var(--mono);
  font-size: 10.5px;
  color: var(--dim);
  padding: 4px 14px;
  flex: none;
  min-height: 0;
}

.notice:empty {
  display: none;
}

.notice.warn {
  color: var(--ac);
}

/* ---------- the lcd ---------- */

.lcd {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  background: var(--sf);
  border-bottom: 1px solid var(--ln);
  padding: 10px 16px calc(10px);
  flex: none;
  font-family: var(--mono);
  color: var(--ac);
}

.counter {
  font-size: 34px;
  font-weight: 500;
  letter-spacing: 0.03em;
  font-variant-numeric: tabular-nums;
}

.counter .tenths {
  font-size: 20px;
  opacity: 0.75;
}

.lcdRight {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
  font-size: 10.5px;
}

.speedReadout {
  font-variant-numeric: tabular-nums;
}

.lcdMode {
  color: var(--dim);
  text-transform: lowercase;
  letter-spacing: 0.08em;
}

.lcdMode.rec {
  color: var(--ac);
  animation: recBlink 1s steps(1) infinite;
}

@keyframes recBlink {
  50% {
    opacity: 0.25;
  }
}

/* ---------- the tape ---------- */

.tapeWrap {
  flex: 1;
  min-height: 120px;
  position: relative;
  overflow: hidden;
  /* the canvas owns every gesture on it */
  touch-action: none;
}

#tape {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

.memoryBadge {
  position: absolute;
  top: 8px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--sf);
  border: 1px solid var(--ac);
  border-radius: var(--radius);
  color: var(--ac);
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.08em;
  padding: 4px 10px;
  pointer-events: none;
}

/* ---------- tracks ---------- */

.trackRow {
  display: flex;
  gap: 8px;
  padding: 10px 14px 4px;
  flex: none;
  align-items: center;
}

.trackBtn {
  flex: 1;
  min-height: 44px;
  border: 1px solid var(--ln);
  border-radius: var(--radius);
  background: var(--sf);
  color: var(--tx);
  font-family: var(--mono);
  font-size: 12px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  transition: all 0.1s;
}

.trackBtn:active {
  transform: translateY(1px);
}

.trackBtn .swatch {
  width: 8px;
  height: 8px;
  border-radius: 2px;
  flex: none;
}

.trackBtn[aria-pressed='true'] {
  border-color: var(--ac);
  color: var(--ac);
}

.gainRow {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 14px 0;
  flex: none;
  font-family: var(--mono);
  font-size: 10px;
  color: var(--dim);
}

.gainRow input[type='range'] {
  flex: 1;
  accent-color: var(--ac);
  min-height: 28px;
}

/* ---------- transport ---------- */

.transport {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 14px;
  flex: none;
}

.tBtn {
  flex: 1;
  min-width: 0;
  height: 56px;
  border: 1px solid var(--ln);
  border-radius: var(--radius);
  background: var(--sf);
  color: var(--tx);
  font-size: 18px;
  cursor: pointer;
  transition: all 0.1s;
  box-shadow: 0 2px 3px rgba(0, 0, 0, 0.25);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.tBtn:active,
.tBtn[aria-pressed='true'] {
  transform: translateY(1px);
  box-shadow: 0 1px 1px rgba(0, 0, 0, 0.25);
}

.tBtn[aria-pressed='true'] {
  border-color: var(--ac);
  color: var(--ac);
}

.tBtn:disabled {
  opacity: 0.4;
  cursor: default;
}

.tBtn .led {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--ln);
  flex: none;
}

.tBtn.recBtn .led.on {
  background: var(--ac);
  box-shadow: 0 0 8px var(--ac);
  animation: recBlink 1s steps(1) infinite;
}

/* the speed knob — a rotary, 270° sweep, vertical drag */

.knobWrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  flex: none;
  width: 72px;
}

.knob {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  border: 1px solid var(--ln);
  background: var(--sf);
  position: relative;
  cursor: ns-resize;
  touch-action: none;
  box-shadow: 0 2px 3px rgba(0, 0, 0, 0.25);
}

.knob .pointerLine {
  position: absolute;
  left: 50%;
  top: 5px;
  width: 2px;
  height: 16px;
  margin-left: -1px;
  background: var(--ac);
  border-radius: 1px;
  transform-origin: 1px 25px;
}

.knobLabel {
  font-family: var(--mono);
  font-size: 9.5px;
  letter-spacing: 0.08em;
  color: var(--dim);
  text-transform: lowercase;
}

/* ---------- actions row ---------- */

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 0 14px calc(12px + env(safe-area-inset-bottom));
  flex: none;
}

.aBtn {
  flex: 1;
  min-height: 40px;
  background: none;
  border: 1px solid var(--ln);
  border-radius: var(--radius);
  color: var(--dim);
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: 0.06em;
  text-transform: lowercase;
  padding: 8px 10px;
  cursor: pointer;
  white-space: nowrap;
}

.aBtn:active {
  transform: translateY(1px);
}

.aBtn[aria-pressed='true'] {
  border-color: var(--ac);
  color: var(--ac);
}

/* ---------- sheets ---------- */

.sheetBackdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  z-index: 30;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  animation: sheetFade 150ms ease-out;
}

@keyframes sheetFade {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

.sheet {
  background: var(--bg);
  border-top: 1px solid var(--ln);
  border-radius: 14px 14px 0 0;
  padding: 16px 16px calc(16px + env(safe-area-inset-bottom));
  animation: sheetUp 180ms ease-out;
  max-width: 560px;
  margin: 0 auto;
  width: 100%;
  max-height: 82dvh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

@keyframes sheetUp {
  from {
    transform: translateY(40px);
  }
  to {
    transform: translateY(0);
  }
}

.sheetSection {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.sectionLabel {
  font-family: var(--mono);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--dim);
}

.sheetRow {
  display: flex;
  align-items: center;
  gap: 8px;
}

.sheetInput {
  flex: 1;
  min-width: 0;
  min-height: 44px;
  background: var(--sf);
  border: 1px solid var(--ln);
  border-radius: var(--radius);
  color: var(--tx);
  font-family: var(--bodyfont);
  /* ≥16px on inputs — iOS Safari auto-zooms below it */
  font-size: 16px;
  padding: 10px 14px;
  outline: none;
}

.sheetInput:focus {
  border-color: var(--ac);
}

textarea.sheetInput {
  resize: none;
  min-height: 76px;
  line-height: 1.45;
}

.sheetBtn {
  background: none;
  border: 1px solid var(--ln);
  border-radius: var(--radius);
  color: var(--tx);
  font-family: var(--mono);
  font-size: 11px;
  padding: 8px 14px;
  min-height: 40px;
  cursor: pointer;
  white-space: nowrap;
}

.sheetBtn:hover,
.sheetBtn:focus-visible {
  border-color: var(--ac);
}

.sheetBtn.primary {
  background: var(--ac);
  color: var(--acTx);
  border-color: var(--ac);
  font-weight: 700;
}

.sheetBtn.danger {
  color: var(--ac);
}

.linkText {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--dim);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
}

.caption {
  font-size: 11px;
  color: var(--dim);
  line-height: 1.5;
}

.finePrint {
  background: var(--sf);
  border-radius: var(--radius);
  padding: 12px 14px;
  font-size: 12px;
  line-height: 1.6;
  color: var(--tx);
}

.themeGrid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.themeCard {
  display: flex;
  align-items: center;
  gap: 8px;
  border: 2px solid var(--ln);
  border-radius: var(--radius);
  padding: 10px 12px;
  min-height: 44px;
  font-family: var(--mono);
  font-size: 11px;
  text-transform: lowercase;
  cursor: pointer;
  background: none;
  color: var(--tx);
}

.themeCard.active {
  border-color: var(--ac);
}

.themeDots {
  display: flex;
  gap: 4px;
}

.themeDots span {
  width: 10px;
  height: 10px;
  border-radius: 50%;
}

/* ---------- the telling (log drawer) ---------- */

.tellingList {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.logRow {
  display: flex;
  gap: 10px;
  padding: 7px 2px;
  border-bottom: 1px dashed var(--ln);
  align-items: baseline;
}

.logStamp {
  font-family: var(--mono);
  font-size: 9.5px;
  color: var(--dim);
  flex: none;
  width: 86px;
}

.logBody {
  flex: 1;
  min-width: 0;
  font-size: 12.5px;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.logBody .who {
  font-weight: 600;
  font-size: 11px;
}

.logBody .what {
  color: var(--dim);
}

.logBody .quote {
  display: block;
  color: var(--tx);
  font-family: var(--bodyfont);
}

.logRow.gone .logBody {
  opacity: 0.55;
  font-style: italic;
}

.logKind {
  font-family: var(--mono);
  font-size: 9px;
  border: 1px solid var(--ln);
  border-radius: 3px;
  padding: 0 4px;
  flex: none;
}

/* ---------- rewind bar ---------- */

.rewindBar[hidden] {
  display: none; /* author display beats the hidden attribute; make hidden win */
}

.rewindBar {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 8px 14px;
  border-top: 1px solid var(--ac);
  background: var(--sf);
  flex: none;
}

.rewindBar input[type='range'] {
  width: 100%;
  accent-color: var(--ac);
  min-height: 28px;
}

.rewindMeta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-family: var(--mono);
  font-size: 10px;
  color: var(--dim);
}

body.rewinding .transport,
body.rewinding .trackRow,
body.rewinding .gainRow,
body.rewinding .actions {
  display: none;
}

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

.toast {
  position: fixed;
  bottom: calc(18px + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  background: var(--sf);
  border: 1px solid var(--ln);
  border-radius: var(--radius);
  color: var(--tx);
  font-family: var(--mono);
  font-size: 11px;
  padding: 10px 16px;
  z-index: 40;
  max-width: 88vw;
  text-align: center;
  animation: sheetFade 150ms ease-out;
}

/* ---------- arrival ---------- */

.arrival {
  position: fixed;
  inset: 0;
  background: var(--bg);
  z-index: 50;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 32px;
  cursor: pointer;
}

.arrivalLines {
  font-family: var(--mono);
  font-size: 12.5px;
  color: var(--tx);
  line-height: 2;
}

.arrivalLine {
  animation: arrivalIn 220ms ease-out;
}

@keyframes arrivalIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

.arrivalCursor {
  display: inline-block;
  width: 8px;
  height: 14px;
  background: var(--ac);
  vertical-align: text-bottom;
  animation: blink 1.1s steps(1) infinite;
}

@keyframes blink {
  50% {
    opacity: 0;
  }
}

.arrivalSkip {
  position: absolute;
  bottom: calc(24px + env(safe-area-inset-bottom));
  left: 0;
  right: 0;
  text-align: center;
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.08em;
  color: var(--dim);
}

/* ---------- accessibility ---------- */

.visuallyHidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

:focus-visible {
  outline: 2px solid var(--ac);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  .arrivalLine,
  .arrivalCursor,
  .sheetBackdrop,
  .sheet,
  .lcdMode.rec,
  .tBtn.recBtn .led.on {
    animation: none;
  }
}
