:root {
  --deep: #062238;      /* pool at depth: page background */
  --water: #0b3350;     /* panels */
  --shallow: #134a6f;   /* raised controls, borders */
  --tile: #e9f3f8;      /* primary text, like pool tile grout white */
  --mist: #93b6cb;      /* secondary text */
  --buoy-red: #e5484d;  /* recording / armed */
  --buoy-yellow: #f3c744; /* the beep, current selection */

  --numerals: "Barlow Condensed", "Arial Narrow", sans-serif;
  --text: "Barlow", system-ui, sans-serif;
  --rail: 320px;
  --radius: 10px;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--deep);
  color: var(--tile);
  font: 400 15px/1.45 var(--text);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--buoy-yellow); outline-offset: 2px; }
[hidden] { display: none !important; }

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) var(--rail);
  height: 100vh;
}

/* ---------- Viewer ---------- */

.viewer {
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto auto;
  padding: 16px 0 16px 16px;
  gap: 12px;
  min-width: 0;
}

.stage {
  position: relative;
  background: #031726;
  border-radius: var(--radius);
  overflow: hidden;
  display: grid;
  place-items: center;
}
.stage video {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}
.stage:fullscreen { border-radius: 0; }

.empty { position: absolute; text-align: center; max-width: 30em; padding: 24px; }
.empty-title { font: 600 clamp(28px, 4vw, 44px)/1.1 var(--numerals); margin: 0 0 8px; }
.empty-body { color: var(--mist); margin: 0; font-size: 17px; }

.hud {
  position: absolute;
  left: 20px;
  bottom: 16px;
  text-shadow: 0 2px 12px rgba(3, 23, 38, 0.8);
  pointer-events: none;
}
.hud-time {
  font: 600 clamp(44px, 7vw, 96px)/0.95 var(--numerals);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.01em;
}
.hud-time small { font-size: 0.42em; font-weight: 500; color: var(--mist); margin-left: 0.15em; }
.hud-sub { font: 500 20px/1.2 var(--numerals); color: var(--mist); font-variant-numeric: tabular-nums; }
.hud-speed {
  position: absolute;
  top: 14px;
  right: 18px;
  font: 600 clamp(28px, 3.4vw, 44px)/1 var(--numerals);
  color: var(--buoy-yellow);
  text-shadow: 0 2px 12px rgba(3, 23, 38, 0.8);
  pointer-events: none;
}

.loading {
  position: absolute;
  top: 16px;
  left: 20px;
  background: rgba(6, 34, 56, 0.85);
  padding: 10px 14px;
  border-radius: 8px;
  min-width: 240px;
  font-weight: 500;
}
.loading-bar { height: 4px; background: var(--shallow); border-radius: 2px; margin-top: 8px; overflow: hidden; }
.loading-bar div { height: 100%; width: 0; background: var(--tile); transition: width 120ms linear; }

/* The one loud moment: a starter call readable from the blocks. */
.call {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: var(--deep);
  text-align: center;
}
.call-big {
  font: 700 min(48vh, 30vw)/0.85 var(--numerals);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
}
.call-sub { font: 600 clamp(28px, 5vw, 64px)/1.1 var(--numerals); margin-top: 0.3em; }
.call-hint { position: absolute; bottom: 18px; color: var(--mist); font-size: 14px; }
.call[data-phase="marks"] .call-big,
.call[data-phase="waiting"] .call-big { font-size: min(22vh, 12vw); line-height: 1; }
.call[data-phase="marks"] { background: var(--water); }
.call[data-phase="recording"] { background: var(--buoy-red); }
.call[data-phase="recording"] .call-hint { color: var(--tile); }
@media (prefers-reduced-motion: no-preference) {
  .call[data-phase="recording"] .call-big { animation: pulse 0.8s ease-in-out infinite alternate; }
}
@keyframes pulse { to { opacity: 0.6; } }

/* Scrub bar */
.scrub { position: relative; height: 28px; cursor: pointer; touch-action: none; }
.scrub-track {
  position: absolute; left: 0; right: 0; top: 11px; height: 6px;
  background: var(--water); border-radius: 3px; overflow: hidden;
}
.scrub-fill { height: 100%; width: 0; background: var(--mist); }
.scrub-beep {
  position: absolute; top: 4px; width: 3px; height: 20px; margin-left: -1.5px;
  background: var(--buoy-yellow); border-radius: 2px;
}
.scrub-head {
  position: absolute; top: 6px; width: 16px; height: 16px; margin-left: -8px; left: 0;
  background: var(--tile); border-radius: 50%; box-shadow: 0 0 0 3px var(--deep);
}

.transport { display: flex; flex-wrap: wrap; gap: 12px 20px; align-items: center; justify-content: space-between; }
.transport-group { display: flex; gap: 6px; align-items: center; }
.tbtn {
  background: var(--water);
  border: 1px solid var(--shallow);
  border-radius: 8px;
  height: 40px;
  min-width: 40px;
  padding: 0 14px;
  font-weight: 500;
}
.tbtn:hover:not(:disabled) { background: var(--shallow); }
.tbtn:disabled { opacity: 0.4; cursor: default; }
.viewer[data-empty="true"] .scrub { visibility: hidden; }
.tbtn[data-action="frame-back"], .tbtn[data-action="frame-fwd"] { font-size: 24px; line-height: 1; padding: 0 12px; }
.tbtn-play { min-width: 84px; background: var(--tile); color: var(--deep); border-color: var(--tile); font-weight: 600; }
.tbtn-play:hover:not(:disabled) { background: #fff; }
.tbtn[aria-pressed="true"] { border-color: var(--buoy-yellow); color: var(--buoy-yellow); }
.speeds .tbtn { font: 600 18px/1 var(--numerals); padding: 0 10px; min-width: 48px; }

/* ---------- Rail ---------- */

.rail {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 16px;
  overflow-y: auto;
  min-height: 0;
}
.rail > section, .keys {
  background: var(--water);
  border-radius: var(--radius);
  padding: 14px 16px;
}

.phone-line { display: flex; align-items: center; gap: 10px; font-weight: 600; font-size: 16px; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--mist); opacity: 0.5; flex: none; }
.phone[data-online="true"] .dot { background: #4cc38a; opacity: 1; }
.pair p { margin: 12px 0 6px; color: var(--mist); }
.pair-code {
  font: 700 46px/1 var(--numerals);
  letter-spacing: 0.12em;
  color: var(--buoy-yellow);
  user-select: all;
}
.readouts { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 12px; margin: 14px 0 0; }
.readouts dt { color: var(--mist); font-size: 13px; }
.readouts dd { margin: 0; font: 600 20px/1.2 var(--numerals); font-variant-numeric: tabular-nums; }
.readouts dd[data-bad="true"] { color: var(--buoy-red); }
.phone-warn { margin: 12px 0 0; color: var(--buoy-yellow); font-size: 14px; }

.start-btn {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border: 0;
  border-radius: 8px;
  padding: 14px 16px;
  background: var(--buoy-red);
  color: #fff;
  font: 700 30px/1 var(--numerals);
}
.start-btn:hover:not(:disabled) { filter: brightness(1.08); }
.start-btn:disabled { background: var(--shallow); color: var(--mist); cursor: not-allowed; }
.start-btn[data-armed="true"] { background: var(--tile); color: var(--deep); }
kbd {
  font: 500 13px/1 var(--text);
  padding: 5px 7px;
  border-radius: 5px;
  background: rgba(255, 255, 255, 0.18);
}
.start-btn[data-armed="true"] kbd { background: rgba(6, 34, 56, 0.12); }

.settings { margin-top: 12px; display: grid; gap: 4px; }
.field { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 36px; color: var(--mist); }
.field .unit { color: var(--mist); }
.field input[type="number"] {
  width: 64px;
  background: var(--deep);
  border: 1px solid var(--shallow);
  border-radius: 6px;
  padding: 5px 8px;
  text-align: right;
  color: var(--tile);
  font-variant-numeric: tabular-nums;
}
.field input[type="checkbox"] { width: 20px; height: 20px; accent-color: var(--buoy-yellow); margin: 0; }
.settings[data-beep="on"] [data-beep="off"],
.settings[data-beep="off"] [data-beep="on"] { display: none; }

.attempts { flex: 1 1 auto; min-height: 160px; display: flex; flex-direction: column; }
.attempts h2 { font: 600 22px/1.1 var(--numerals); margin: 0 0 8px; }
.attempt-list { list-style: none; margin: 0 -8px; padding: 0; overflow-y: auto; }
.attempt {
  display: grid;
  grid-template-columns: 44px 1fr auto;
  align-items: center;
  gap: 4px 10px;
  padding: 8px;
  border-radius: 8px;
  cursor: pointer;
}
.attempt:hover { background: var(--shallow); }
.attempt[aria-current="true"] { background: var(--deep); box-shadow: inset 3px 0 0 var(--buoy-yellow); }
.attempt-n { font: 700 28px/1 var(--numerals); font-variant-numeric: tabular-nums; text-align: right; }
.attempt-meta { font-size: 13px; color: var(--mist); line-height: 1.35; }
.attempt-meta strong { color: var(--tile); font-weight: 500; font-size: 14px; }
.attempt-warn { color: var(--buoy-yellow); }
.attempt-actions { display: flex; gap: 2px; opacity: 0; }
.attempt:hover .attempt-actions, .attempt:focus-within .attempt-actions { opacity: 1; }
.icon-btn {
  background: none; border: 0; color: var(--mist);
  width: 30px; height: 30px; border-radius: 6px;
  display: grid; place-items: center; text-decoration: none; font-size: 16px;
}
.icon-btn:hover { background: var(--water); color: var(--tile); }
.attempts-empty { color: var(--mist); margin: 0; padding: 0 8px; font-size: 14px; }

.keys summary { cursor: pointer; font-weight: 600; }
.keys dl { margin: 10px 0 0; display: grid; gap: 4px; }
.keys dl div { display: grid; grid-template-columns: 64px 1fr; gap: 8px; font-size: 14px; }
.keys dt { font-weight: 600; }
.keys dd { margin: 0; color: var(--mist); }
.link { background: none; border: 0; padding: 0; margin-top: 12px; color: var(--mist); text-decoration: underline; font-size: 14px; }
.link:hover { color: var(--tile); }

@media (max-width: 900px) {
  body { overflow: auto; }
  .layout { grid-template-columns: 1fr; height: auto; }
  .viewer { padding: 12px; height: 80vh; }
  .rail { padding: 0 12px 12px; }
}
