/* SPIN LAB — broadcast slow-mo replay aesthetic.
   Fraunces (editorial serif display) · Schibsted Grotesk (body) · IBM Plex Mono (data) */

:root {
  --bg: #0a0d12;
  --panel: rgba(13, 17, 24, 0.84);
  --panel-border: rgba(240, 234, 216, 0.09);
  --ink: #ece7da;
  --ink-dim: #98a0ae;
  --ink-faint: #5d6573;
  --top: #ff6b35;
  --back: #00b4d8;
  --flat: #9aa3b2;
  --good: #2dd4a7;
  --bad: #ff5d5d;
  --warn: #ffb454;
  --serif: "Fraunces", serif;
  --sans: "Schibsted Grotesk", sans-serif;
  --mono: "IBM Plex Mono", monospace;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
}

#c { position: fixed; inset: 0; z-index: 0; }

#ui {
  position: fixed;
  inset: 0;
  z-index: 10;
  pointer-events: none;
}

/* ---------- top bar ---------- */

#topbar {
  position: absolute;
  top: 0; left: 0; right: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 22px;
  background: linear-gradient(180deg, rgba(10, 13, 18, 0.9), rgba(10, 13, 18, 0));
}

.brand {
  font-family: var(--mono);
  font-weight: 500;
  font-size: 15px;
  letter-spacing: 0.14em;
}

.brand span { color: var(--top); }

.brand em {
  display: block;
  font-family: var(--serif);
  font-style: italic;
  font-weight: 300;
  font-size: 12px;
  letter-spacing: 0.01em;
  color: var(--ink-dim);
  margin-top: 2px;
}

.playback {
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: 9px;
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-dim);
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 999px;
  padding: 7px 14px;
  backdrop-filter: blur(14px);
}

.playback input {
  width: 90px;
  accent-color: var(--top);
}

#speedVal { min-width: 42px; text-align: right; color: var(--ink); }

/* ---------- story panel ---------- */

#story {
  pointer-events: auto;
  position: absolute;
  top: 72px;
  left: 20px;
  bottom: 178px;
  width: min(390px, calc(100vw - 40px));
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 16px;
  backdrop-filter: blur(18px);
  overflow: hidden;
  transition: transform 0.35s cubic-bezier(.2,.9,.25,1), opacity 0.3s;
}

.story-scroll {
  height: 100%;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 22px 24px 24px;
  scrollbar-width: thin;
  scrollbar-color: rgba(236,231,218,0.18) transparent;
}

#storyToggle {
  pointer-events: auto;
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 2;
  width: 28px; height: 28px;
  border-radius: 8px;
  border: 1px solid var(--panel-border);
  background: rgba(236,231,218,0.05);
  color: var(--ink-dim);
  cursor: pointer;
  font-size: 14px;
  display: none;
}

.chapnum {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.35em;
  color: var(--top);
}

.chapnum::after {
  content: " / 06";
  color: var(--ink-faint);
}

#chapTitle {
  font-family: var(--serif);
  font-weight: 420;
  font-size: 44px;
  line-height: 1.02;
  letter-spacing: -0.015em;
  margin: 8px 0 12px;
}

.kicker {
  font-family: var(--serif);
  font-style: italic;
  font-weight: 340;
  font-size: 16.5px;
  line-height: 1.45;
  color: var(--ink);
  border-left: 2px solid var(--top);
  padding-left: 12px;
  margin-bottom: 14px;
}

#chapBody p {
  font-size: 13.5px;
  line-height: 1.62;
  color: var(--ink-dim);
  margin-bottom: 11px;
}

#chapBody strong { color: var(--ink); font-weight: 600; }
#chapBody em { color: var(--ink); }

.chip {
  display: inline-block;
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 500;
  padding: 1px 7px 2px;
  border-radius: 5px;
  white-space: nowrap;
}

.chip.ts { background: rgba(255,107,53,0.16); color: var(--top); }
.chip.bs { background: rgba(0,180,216,0.16); color: var(--back); }
.chip.ns { background: rgba(154,163,178,0.16); color: var(--flat); }

/* matchup header + lesson (chapter 06) */

.matchup {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.matchup .vs { color: var(--ink-faint); }

.otag {
  font-family: var(--mono);
  font-size: 11px;
  padding: 1px 8px 2px;
  border-radius: 999px;
}

.otag.ok { background: rgba(45,212,167,0.16); color: var(--good); }
.otag.nt { background: rgba(255,93,93,0.16); color: var(--bad); }
.otag.lg { background: rgba(255,180,84,0.16); color: var(--warn); }
.otag.pu { background: rgba(255,93,93,0.18); color: var(--bad); }

.lesson { margin-top: 14px; display: grid; gap: 10px; }

.lesson-line span {
  display: block;
  font-family: var(--mono);
  font-size: 9.5px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-faint);
  margin-bottom: 2px;
}

.lesson-line p {
  font-size: 13px !important;
  color: var(--ink) !important;
  margin: 0 !important;
}

/* ---------- readout cards ---------- */

#readout { margin-top: 16px; display: grid; gap: 10px; }

.ro-card {
  background: rgba(236,231,218,0.04);
  border: 1px solid var(--panel-border);
  border-radius: 11px;
  padding: 11px 13px;
}

.ro-title {
  font-family: var(--mono);
  font-size: 9.5px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--ink-faint);
  margin-bottom: 7px;
}

.ro-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  margin-top: 5px;
}

.ro-row span {
  font-family: var(--mono);
  font-size: 10.5px;
  color: var(--ink-faint);
  flex-shrink: 0;
}

.ro-row strong {
  font-size: 12.5px;
  font-weight: 500;
  color: var(--ink);
  text-align: right;
  line-height: 1.4;
}

/* ---------- stamp ---------- */

#stamp {
  position: absolute;
  right: 7vw;
  top: 30vh;
  font-family: var(--serif);
  font-weight: 600;
  font-size: clamp(34px, 5vw, 62px);
  letter-spacing: 0.02em;
  transform: rotate(-5deg) scale(0.8);
  opacity: 0;
  transition: opacity 0.18s, transform 0.18s cubic-bezier(.2,1.6,.4,1);
  text-shadow: 0 4px 30px rgba(0,0,0,0.55);
  pointer-events: none;
  white-space: nowrap;
}

#stamp.show { opacity: 1; transform: rotate(-5deg) scale(1); }

#stamp[data-tone="good"] { color: var(--good); }
#stamp[data-tone="bad"] { color: var(--bad); }
#stamp[data-tone="warn"] { color: var(--warn); }
#stamp[data-tone="top"] { color: var(--top); }
#stamp[data-tone="back"] { color: var(--back); }
#stamp[data-tone="flat"] { color: var(--flat); }
#stamp[data-tone="info"] { color: var(--ink); }

/* ---------- hint bar ---------- */

#hint {
  position: absolute;
  left: 50%;
  bottom: 168px;
  transform: translateX(-50%) translateY(8px);
  max-width: min(620px, 90vw);
  font-size: 13px;
  line-height: 1.5;
  text-align: center;
  padding: 9px 18px;
  border-radius: 999px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  backdrop-filter: blur(14px);
  opacity: 0;
  transition: opacity 0.25s, transform 0.25s;
  pointer-events: none;
}

#hint.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#hint[data-tone="good"] { border-color: rgba(45,212,167,0.4); color: var(--good); }
#hint[data-tone="bad"] { color: var(--ink); border-color: rgba(255,93,93,0.35); }
#hint[data-tone="info"] { color: var(--ink-dim); }

/* ---------- bottom: controls dock + chapter rail ---------- */

#bottom {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 0 16px 14px;
  background: linear-gradient(0deg, rgba(10,13,18,0.92) 30%, rgba(10,13,18,0));
}

#controls {
  pointer-events: auto;
  display: flex;
  align-items: flex-end;
  gap: 18px;
  flex-wrap: wrap;
  justify-content: center;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 16px;
  padding: 12px 18px;
  backdrop-filter: blur(18px);
  max-width: min(960px, 100%);
}

.ctl { display: flex; flex-direction: column; gap: 6px; min-width: 120px; }

.ctl label {
  font-family: var(--mono);
  font-size: 9.5px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ink-faint);
  display: flex;
  justify-content: space-between;
  gap: 10px;
}

.ctl output {
  color: var(--ink);
  text-transform: none;
  letter-spacing: 0;
  font-size: 10.5px;
}

.ctl input[type="range"] {
  width: 150px;
  accent-color: var(--top);
}

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

.seg button {
  font-family: var(--mono);
  font-size: 11px;
  padding: 6px 11px;
  border-radius: 8px;
  border: 1px solid var(--panel-border);
  background: rgba(236,231,218,0.04);
  color: var(--ink-dim);
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}

.seg button:hover { color: var(--ink); border-color: rgba(236,231,218,0.25); }

.seg button.on {
  color: var(--seg-color);
  border-color: var(--seg-color);
  background: color-mix(in srgb, var(--seg-color) 13%, transparent);
}

.act {
  font-family: var(--sans);
  font-weight: 600;
  font-size: 13px;
  padding: 10px 18px;
  border-radius: 11px;
  border: 1px solid var(--panel-border);
  background: rgba(236,231,218,0.06);
  color: var(--ink);
  cursor: pointer;
  transition: all 0.15s;
  align-self: center;
}

.act:hover { background: rgba(236,231,218,0.12); }

.act.primary {
  background: var(--top);
  border-color: var(--top);
  color: #14060097;
  color: #1c0c04;
  box-shadow: 0 4px 22px rgba(255,107,53,0.35);
}

.act.primary:hover { filter: brightness(1.08); }

/* matrix grid (chapter 06) */

.matrix-grid {
  display: grid;
  grid-template-columns: 56px repeat(6, minmax(64px, 1fr));
  grid-auto-rows: auto;
  gap: 4px;
  align-items: stretch;
}

.mhead {
  font-family: var(--mono);
  font-size: 9px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-faint);
  display: flex;
  align-items: center;
  justify-content: center;
}

.mhead.row { justify-content: flex-end; padding-right: 8px; }
.mhead.corner { font-size: 8px; }

.mcell {
  border-radius: 9px;
  border: 2px solid transparent;
  padding: 6px 6px;
  min-height: 46px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  transition: transform 0.15s, border-color 0.15s;
  background: rgba(236,231,218,0.04);
}

.mcell:hover { transform: scale(1.05); }
.mcell.sel { border-color: var(--top); box-shadow: 0 0 18px rgba(255,107,53,0.22); }

.mcell i { font-style: normal; font-size: 13px; }
.mcell span {
  font-family: var(--mono);
  font-size: 8.5px;
  line-height: 1.25;
  text-align: center;
}

.mcell.ok { background: rgba(45,212,167,0.09); }
.mcell.ok i, .mcell.ok span { color: var(--good); }
.mcell.nt { background: rgba(255,93,93,0.09); }
.mcell.nt i, .mcell.nt span { color: var(--bad); }
.mcell.lg { background: rgba(255,180,84,0.09); }
.mcell.lg i, .mcell.lg span { color: var(--warn); }

/* lands on the table, loses the point: smashed next ball */
.mcell.pu { background: rgba(255,93,93,0.12); border-style: dashed; border-color: rgba(255,93,93,0.35); }
.mcell.pu i, .mcell.pu span { color: var(--bad); }

/* chapter rail */

#rail {
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: 8px;
}

#chapList { display: flex; gap: 4px; }

#chapList button {
  display: flex;
  align-items: baseline;
  gap: 6px;
  font-family: var(--mono);
  font-size: 10.5px;
  padding: 7px 12px;
  border-radius: 999px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--ink-faint);
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}

#chapList button i { font-style: normal; font-size: 9px; opacity: 0.7; }

#chapList button:hover { color: var(--ink); }

#chapList button.on {
  color: var(--ink);
  border-color: var(--panel-border);
  background: var(--panel);
}

#chapList button.on i { color: var(--top); opacity: 1; }

.navarrow {
  width: 30px; height: 30px;
  border-radius: 50%;
  border: 1px solid var(--panel-border);
  background: var(--panel);
  color: var(--ink-dim);
  cursor: pointer;
  font-size: 13px;
  transition: all 0.15s;
}

.navarrow:hover { color: var(--ink); border-color: rgba(236,231,218,0.3); }

/* ---------- floating ball label ---------- */

#ballLabel {
  position: fixed;
  z-index: 20;
  pointer-events: none;
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 500;
  padding: 3px 10px;
  border-radius: 6px;
  background: rgba(10,13,18,0.72);
  border: 1px solid var(--panel-border);
  white-space: nowrap;
  transform: translate(-50%, -100%);
  opacity: 0;
  transition: opacity 0.2s;
}

/* ---------- responsive ---------- */

@media (max-width: 900px) {
  #story {
    top: auto;
    bottom: calc(100% - 100dvh + 188px);
    bottom: 188px;
    left: 12px;
    right: 12px;
    width: auto;
    max-height: 32vh;
  }

  #storyToggle { display: block; }

  #story.collapsed .story-scroll { display: none; }
  #story.collapsed { background: transparent; border-color: transparent; backdrop-filter: none; }

  #chapTitle { font-size: 28px; }
  .kicker { font-size: 14px; }
  .story-scroll { padding: 16px 18px 18px; }

  #chapList button span { display: none; }
  #chapList button { padding: 7px 9px; }

  .playback label { display: none; }
  .playback input { width: 64px; }

  #bottom {
    gap: 8px;
    padding: 0 8px;
    padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px));
  }

  #controls {
    gap: 8px 14px;
    padding: 9px 12px;
    max-width: 100%;
    border-radius: 13px;
  }

  .ctl { min-width: 0; }
  .ctl input[type="range"] { width: 104px; }
  .seg button { padding: 6px 9px; font-size: 10px; }
  .act { padding: 9px 14px; font-size: 12px; }

  /* The hint moves to the top on small screens so it never fights the dock */
  #hint {
    bottom: auto;
    top: 64px;
    max-width: calc(100vw - 24px);
    font-size: 12px;
  }
  #hint.show { transform: translateX(-50%) translateY(0); }

  #stamp { right: 4vw; top: 16vh; font-size: clamp(26px, 8vw, 44px); }

  /* 3x6 matrix scrolls horizontally inside the dock */
  .matrix-grid {
    grid-template-columns: 46px repeat(6, 64px);
    overflow-x: auto;
    max-width: calc(100vw - 60px);
    padding-bottom: 4px;
    -webkit-overflow-scrolling: touch;
  }
  .mcell { min-height: 40px; padding: 4px 3px; }
  .mcell span { font-size: 7.5px; }
  .mhead { font-size: 8px; }
  .mhead.row { padding-right: 5px; }
}

@media (max-width: 480px) {
  .brand em { display: none; }
  .brand { font-size: 13px; }
  #topbar { padding: 10px 12px; }
  .playback { padding: 6px 10px; gap: 6px; }
  .playback input { width: 54px; }
  #speedVal { min-width: 34px; font-size: 9px; }

  #story { bottom: 178px; max-height: 30vh; }
  #chapTitle { font-size: 24px; }
  .kicker { font-size: 13px; padding-left: 10px; }
  #chapBody p { font-size: 12.5px; }

  #controls { gap: 6px 10px; padding: 8px 10px; }
  .ctl input[type="range"] { width: 92px; }
  .ctl label { font-size: 8.5px; }
  .seg { flex-wrap: wrap; }

  #rail { gap: 4px; }
  .navarrow { width: 26px; height: 26px; font-size: 11px; }
  #chapList button { padding: 6px 7px; font-size: 9.5px; }

  .matrix-grid { max-width: calc(100vw - 40px); }
}
