/* Midnight Groove Cue Booth — physical mastering room
   Palette: tobacco brown, studio cream, brushed aluminum, black vinyl,
   VU amber, transport red, muted 1970s avocado. No blue/cyan SaaS. */

:root {
  --tobacco: #4a3424;
  --tobacco-deep: #2e2118;
  --cream: #f0e6d2;
  --cream-dim: #e2d4b8;
  --aluminum: #b8b3a8;
  --aluminum-bright: #d4cfc4;
  --vinyl: #141210;
  --vinyl-groove: #1c1916;
  --amber: #c9882a;
  --amber-hot: #e0a040;
  --transport: #9c2b22;
  --transport-hot: #c43a2e;
  --avocado: #5c6b3c;
  --avocado-mute: #6e7a4e;
  --ink: #1a1410;
  --muted: rgba(26, 20, 16, 0.68);
  --line: rgba(42, 32, 24, 0.28);
  --desk: #3a2c22;
  --panel: #efe4ce;
  --focus: #8a5a22;
  --ok: #3d5c36;
  --warn-bg: #f2d9c0;
  --radius: 4px;
  --font: "IBM Plex Sans", "Avenir Next", "Segoe UI", system-ui, sans-serif;
  --mono: "IBM Plex Mono", "SF Mono", "Menlo", "Consolas", monospace;
}

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

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--tobacco-deep);
  color: var(--ink);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.45;
}

.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  background: var(--cream);
  color: var(--ink);
  padding: 8px 12px;
  z-index: 100;
}
.skip-link:focus {
  left: 8px;
  top: 8px;
}

.mono {
  font-family: var(--mono);
  font-size: 12px;
  word-break: break-all;
}

button, select, input, textarea {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  border: 1px solid rgba(26, 20, 16, 0.35);
  background: var(--aluminum);
  color: var(--ink);
  border-radius: var(--radius);
  padding: 7px 11px;
  transition: background 120ms ease, border-color 120ms ease;
}
button:hover { background: var(--aluminum-bright); }
button:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}
button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-transport {
  background: var(--transport);
  border-color: #6e1c16;
  color: #f8ebe4;
  font-weight: 600;
}
.btn-transport:hover { background: var(--transport-hot); }

.btn-warn {
  background: var(--amber);
  border-color: #8a5a18;
  color: var(--ink);
  font-weight: 600;
}
.btn-warn:hover { background: var(--amber-hot); }

.btn-metal {
  background: linear-gradient(180deg, var(--aluminum-bright), var(--aluminum));
  border-color: #8a8478;
}

.btn-ghost {
  background: transparent;
  border-color: var(--line);
}

/* ---- Room shell ---- */
.studio-room {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto auto 1fr auto;
  background:
    radial-gradient(ellipse 80% 50% at 50% 0%, rgba(240, 230, 210, 0.08), transparent 60%),
    repeating-linear-gradient(
      90deg,
      transparent,
      transparent 47px,
      rgba(0, 0, 0, 0.04) 48px
    ),
    var(--tobacco-deep);
}

.status-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 12px 18px;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  background: var(--desk);
  color: var(--cream);
  border-bottom: 2px solid #1a120c;
}

.strip-brand {
  display: flex;
  gap: 10px;
  align-items: center;
  min-width: 200px;
}
.strip-platter {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background:
    radial-gradient(circle at 50% 50%, var(--cream-dim) 0 4px, var(--vinyl) 5px 100%);
  border: 1px solid #0a0806;
  box-shadow: inset 0 0 0 6px #1a1612;
}
.strip-name {
  margin: 0;
  font-size: 13px;
  font-weight: 650;
  letter-spacing: 0.02em;
}
.strip-booth {
  margin: 2px 0 0;
  font-size: 11px;
  color: rgba(240, 230, 210, 0.7);
}

.strip-meters {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 16px;
  margin: 0;
}
.strip-meters > div {
  display: grid;
  gap: 2px;
  min-width: 72px;
}
.strip-meters dt {
  margin: 0;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: rgba(240, 230, 210, 0.55);
}
.strip-meters dd {
  margin: 0;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--amber-hot);
}

/* Mobile nav — cassette field recorder pages */
.recorder-nav {
  display: none;
  gap: 0;
  background: #2a2018;
  border-bottom: 1px solid #120c08;
}
.recorder-nav button {
  flex: 1;
  border: none;
  border-radius: 0;
  background: transparent;
  color: rgba(240, 230, 210, 0.65);
  padding: 10px 4px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-bottom: 2px solid transparent;
}
.recorder-nav button[aria-selected="true"] {
  color: var(--cream);
  border-bottom-color: var(--amber);
  background: rgba(201, 136, 42, 0.08);
}

/* ---- Floor layout: asymmetric studio furniture ---- */
.booth-floor {
  display: grid;
  grid-template-columns: minmax(220px, 0.85fr) minmax(360px, 1.4fr) minmax(240px, 0.95fr);
  grid-template-rows: auto auto;
  gap: 12px;
  padding: 12px;
  align-items: start;
}

.zone {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.25) inset;
}

.zone-head {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: baseline;
  margin-bottom: 8px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 6px;
}
.zone-head h2, .zone-head h3, .scope-strip h3, .cabinet h3 {
  margin: 0;
  font-size: 14px;
  font-weight: 650;
}
.zone-tag {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--avocado);
  font-weight: 700;
}
.zone-note {
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 12.5px;
}

.decks-zone { grid-column: 1; grid-row: 1 / span 2; }
.platter-zone { grid-column: 2; grid-row: 1 / span 2; }
.lathe-zone { grid-column: 3; grid-row: 1; }
.math-zone { grid-column: 3; grid-row: 2; }
.archive-zone {
  display: none;
}

/* ---- Reel decks ---- */
.reel-stack {
  display: grid;
  gap: 10px;
}
.reel-deck {
  background: #e8dcc4;
  border: 1px solid rgba(42, 32, 24, 0.22);
  border-radius: var(--radius);
  padding: 10px;
}
.reel-deck header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}
.reel-deck h3 {
  margin: 0;
  font-size: 13px;
}
.reel-cursor {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--avocado);
}
.reel-faces {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 48px;
  margin-bottom: 8px;
  background: #d8c9a8;
  border: 1px solid var(--line);
}
.reel-spool {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background:
    radial-gradient(circle at 50% 50%, #2a241c 0 5px, #6a5a44 6px 10px, #2a241c 11px 14px, #8a7a5c 15px);
  border: 1px solid #1a1410;
}
.reel-tape {
  flex: 1;
  height: 4px;
  background: #2a241c;
  max-width: 48px;
}
.reel-meta {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin: 0 0 8px;
  font-size: 12px;
}
.reel-meta dt { color: var(--muted); margin: 0; }
.reel-meta dd { margin: 0; font-family: var(--mono); }
.reel-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.reel-actions button { flex: 1 1 auto; font-size: 12px; padding: 6px 8px; }

.bin-row {
  display: grid;
  gap: 8px;
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px dashed var(--line);
}
.field {
  display: grid;
  gap: 4px;
}
.field > span {
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.field select,
.field input,
.field textarea {
  width: 100%;
  border: 1px solid rgba(42, 32, 24, 0.3);
  background: #f7f0e0;
  border-radius: var(--radius);
  padding: 7px 8px;
}
.field textarea { resize: vertical; min-height: 56px; }
.field input:focus,
.field select:focus,
.field textarea:focus {
  outline: 2px solid var(--focus);
  outline-offset: 1px;
}

/* ---- Turntable (must read as vinyl, not Arrival circle) ---- */
.platter-stage {
  display: grid;
  grid-template-columns: 1fr 120px;
  gap: 10px;
  align-items: start;
}

.platter-well {
  position: relative;
  aspect-ratio: 1;
  max-width: 420px;
  margin: 0 auto;
  background: #3a3028;
  border: 3px solid #1a1410;
  border-radius: 2px;
  box-shadow:
    inset 0 0 0 8px #4a3e34,
    inset 0 0 40px rgba(0, 0, 0, 0.35);
  /* rectangular plinth under circular platter — asymmetric furniture cue */
}

.platter-mat {
  position: absolute;
  inset: 10% 8% 18% 8%;
  background: #2a241e;
  border-radius: 2px;
}

.platter-disc {
  position: absolute;
  left: 50%;
  top: 46%;
  transform: translate(-50%, -50%);
  width: min(78%, 300px);
  aspect-ratio: 1;
  border-radius: 50%;
  background:
    repeating-radial-gradient(
      circle at 50% 50%,
      var(--vinyl) 0 1px,
      var(--vinyl-groove) 1px 2px
    );
  border: 2px solid #0a0806;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.45);
}

.groove-ring {
  position: absolute;
  inset: 12%;
  border-radius: 50%;
  border: 2px solid transparent;
  pointer-events: none;
}
.groove-ring.has-match {
  border-color: var(--amber);
  box-shadow: 0 0 0 1px rgba(201, 136, 42, 0.4);
}

.platter-label {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 34%;
  aspect-ratio: 1;
  border-radius: 50%;
  background: #c4a060;
  border: 1px solid #6a4a20;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  font-weight: 700;
  color: #2a1c0c;
  letter-spacing: 0.06em;
}
.platter-side {
  font-size: 8px;
  font-weight: 500;
  opacity: 0.8;
}
.platter-spindle {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--aluminum-bright);
  border: 1px solid #4a4438;
  z-index: 2;
}

.tonearm {
  position: absolute;
  right: 12%;
  top: 18%;
  width: 42%;
  height: 4px;
  background: var(--aluminum);
  transform-origin: 100% 50%;
  transform: rotate(-28deg);
  border-radius: 2px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}
.tonearm::after {
  content: "";
  position: absolute;
  left: -6px;
  top: -4px;
  width: 12px;
  height: 12px;
  background: #2a241c;
  border-radius: 2px;
}

.sleeve-rail {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 360px;
  overflow: auto;
  padding-right: 2px;
}
.sleeve {
  background: #f4ead4;
  border: 1px solid rgba(42, 32, 24, 0.3);
  border-left: 4px solid var(--avocado-mute);
  padding: 6px 8px;
  font-size: 11px;
  cursor: pointer;
  text-align: left;
  border-radius: 0 2px 2px 0;
}
.sleeve:hover, .sleeve:focus-visible {
  background: #fff6e4;
}
.sleeve.is-selected {
  border-left-color: var(--transport);
  background: #fff0d8;
}
.sleeve.is-match {
  border-left-color: var(--amber);
  box-shadow: inset 0 0 0 1px rgba(201, 136, 42, 0.45);
}
.sleeve .sleeve-id {
  font-weight: 700;
  display: block;
}
.sleeve .sleeve-r {
  font-family: var(--mono);
  font-size: 10px;
  color: var(--muted);
  display: block;
  margin-top: 2px;
}

.groove-timeline {
  margin-top: 12px;
  border-top: 1px solid var(--line);
  padding-top: 8px;
}
.timeline-head {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--muted);
  margin-bottom: 6px;
}
.timeline-track {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  min-height: 28px;
  background: #e0d4bc;
  border: 1px solid var(--line);
  padding: 4px;
}
.timeline-track li {
  font-family: var(--mono);
  font-size: 10px;
  padding: 3px 6px;
  background: var(--cream);
  border: 1px solid var(--line);
}
.timeline-track li.match {
  background: #f5d9a0;
  border-color: var(--amber);
  font-weight: 700;
}

/* Scope / worksheet */
.scope-strip {
  margin-top: 12px;
  background: #1e1a16;
  color: var(--cream-dim);
  border: 1px solid #0c0a08;
  padding: 8px 10px;
  border-radius: var(--radius);
}
.scope-strip header {
  display: flex;
  gap: 8px;
  align-items: baseline;
  margin-bottom: 6px;
}
.scope-strip h3 { color: var(--cream); font-size: 12px; }
.scope-strip .zone-tag { color: var(--amber); }
#scope-canvas {
  width: 100%;
  height: 72px;
  display: block;
  background: #0e0c0a;
  border: 1px solid #2a241c;
  margin-bottom: 8px;
}
.worksheet {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px 10px;
  margin: 0;
  font-size: 11px;
}
.worksheet > div { display: grid; grid-template-columns: 56px 1fr; gap: 4px; }
.worksheet > div.full { grid-column: 1 / -1; }
.worksheet dt { margin: 0; color: rgba(240, 230, 210, 0.55); }
.worksheet dd { margin: 0; color: var(--amber-hot); }

/* Lathe + cabinet */
.lathe-body {
  height: 72px;
  margin-bottom: 8px;
  background: #d4c8b0;
  border: 1px solid var(--line);
  position: relative;
  overflow: hidden;
}
.lathe-bed {
  position: absolute;
  left: 8%;
  right: 8%;
  bottom: 18px;
  height: 10px;
  background: var(--aluminum);
  border: 1px solid #6a6458;
}
.lathe-blank {
  position: absolute;
  left: 22%;
  bottom: 28px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: #e8e0d0;
  border: 2px solid #8a7a60;
}
.lathe-arm {
  position: absolute;
  right: 18%;
  top: 12px;
  width: 40%;
  height: 5px;
  background: #5a5044;
  transform: rotate(12deg);
}

.cabinet {
  margin-top: 8px;
  background: #e6d8bc;
  border: 1px solid rgba(42, 32, 24, 0.28);
  padding: 10px;
}
.cabinet header {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 10px;
  align-items: center;
  margin-bottom: 8px;
}
.lock-lamp {
  margin-left: auto;
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  background: var(--transport);
  color: #f8ebe4;
  border-radius: 2px;
}
.cabinet[data-locked="false"] .lock-lamp {
  background: var(--ok);
}
.cabinet-actions {
  display: grid;
  gap: 8px;
}
.sig-pair {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.challenge-box {
  margin: 10px 0 0;
  padding: 8px;
  background: #1e1a16;
  color: var(--cream-dim);
  border: 1px solid #0c0a08;
  font-size: 11px;
  white-space: pre-wrap;
  max-height: 140px;
  overflow: auto;
}

/* Math board */
.matrix-board {
  background: #3a4a30;
  color: #e4ecd4;
  border: 1px solid #2a3420;
  padding: 10px;
  border-radius: var(--radius);
}
.matrix-eq {
  margin: 0 0 10px;
  font-size: 11px;
  line-height: 1.55;
  color: #d4e0b8;
  white-space: pre-wrap;
}
.compare-grid {
  display: grid;
  gap: 8px;
  margin-bottom: 8px;
}
.matrix-board .field > span { color: rgba(228, 236, 212, 0.7); }
.matrix-board select {
  background: #2a3424;
  color: #e4ecd4;
  border-color: #4a5a38;
}
.compare-out {
  margin: 0;
  padding: 8px;
  background: #24301c;
  border: 1px solid #1a2414;
  font-size: 11px;
  white-space: pre-wrap;
  min-height: 64px;
}

.archive-out {
  margin-top: 10px;
  padding: 10px;
  background: #1e1a16;
  color: var(--cream);
  border: 1px solid #0c0a08;
  white-space: pre-wrap;
  min-height: 80px;
}

/* Mixing desk footer */
.mix-desk {
  display: grid;
  grid-template-columns: auto auto 1fr;
  gap: 12px 16px;
  align-items: center;
  padding: 8px 14px 10px;
  background: var(--desk);
  border-top: 3px solid #1a120c;
  color: var(--cream);
}
.fader-bank {
  display: flex;
  gap: 6px;
  align-items: flex-end;
  height: 36px;
}
.fader {
  width: 8px;
  height: 22px;
  background: #2a241c;
  border: 1px solid #0c0a08;
  position: relative;
}
.fader::after {
  content: "";
  position: absolute;
  left: -2px;
  right: -2px;
  height: 6px;
  top: 40%;
  background: var(--aluminum);
}
.fader.tall { height: 30px; }

.vu-meters {
  display: flex;
  gap: 4px;
  align-items: flex-end;
  height: 28px;
}
.vu {
  width: 10px;
  height: 60%;
  background: linear-gradient(180deg, var(--transport) 0%, var(--amber) 55%, var(--avocado) 100%);
  opacity: 0.75;
  border: 1px solid #0c0a08;
}
.vu.hot { height: 100%; opacity: 1; }

.transport {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.desk-live {
  grid-column: 1 / -1;
  margin: 0;
  font-size: 12px;
  color: rgba(240, 230, 210, 0.78);
  font-family: var(--mono);
  border-top: 1px solid rgba(240, 230, 210, 0.12);
  padding-top: 6px;
}

/* State lamp on room */
.studio-room[data-state="repeated_r_detected"] .groove-ring {
  border-color: var(--amber);
}
.studio-room[data-state="master_cabinet_unlocked"] #lock-lamp,
.studio-room[data-state="final_flag"] #lock-lamp,
.studio-room[data-state="forged_command_accepted"] #lock-lamp {
  background: var(--ok);
}
.studio-room[data-state="forged_command_rejected"] #lock-lamp,
.studio-room[data-state="replay_rejected"] #lock-lamp {
  background: #6a2018;
}

/* ---- Mobile: cassette field recorder ---- */
@media (max-width: 900px) {
  .recorder-nav {
    display: flex;
  }
  .booth-floor {
    display: block;
    padding: 8px;
  }
  .work-area {
    display: none;
  }
  .work-area.is-active {
    display: block;
  }
  .archive-zone.is-active {
    display: block;
  }
  .platter-stage {
    grid-template-columns: 1fr;
  }
  .sleeve-rail {
    flex-direction: row;
    max-height: none;
    overflow-x: auto;
  }
  .sleeve {
    min-width: 140px;
  }
  .mix-desk {
    grid-template-columns: 1fr;
    position: sticky;
    bottom: 0;
    z-index: 20;
  }
  .fader-bank, .vu-meters {
    display: none;
  }
  .transport {
    width: 100%;
  }
  .transport button {
    flex: 1 1 40%;
  }
}

@media (prefers-reduced-motion: reduce) {
  button { transition: none; }
  .vu { transition: none; }
}

@media (prefers-contrast: more) {
  :root {
    --muted: rgba(26, 20, 16, 0.85);
    --line: rgba(26, 20, 16, 0.5);
  }
  .status-strip, .mix-desk {
    border-color: #000;
  }
}
