:root {
  color-scheme: dark;
  --bg: #07080a;
  --chassis: #10141a;
  --glass: #0b1116;
  --text: #f4ece0;
  --muted: #8d877c;
  --spoken: #5d5a53;
  --upcoming: #d8d0c4;
  --filament: #7cf0d2;
  --rec: #ff4d1a;
  --brass: #e2a45a;
  --line: rgb(124 240 210 / 0.28);
  --font-script: "Fraunces", "Iowan Old Style", "Palatino Linotype", serif;
  --font-ui: "Oxanium", "Segoe UI", sans-serif;
  --radius-outer: 28px;
  --radius-inner: 16px;
  --script-size: 64px;
  --cue-at: 22px;
  --target-size: 24px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
}

@media (pointer: coarse) {
  :root {
    --target-size: 44px;
  }
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  -webkit-font-smoothing: antialiased;
  overflow-wrap: break-word;
  touch-action: pan-y;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  height: 100svh;
  min-height: 100svh;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  overflow: hidden;
  overscroll-behavior: none;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.grain,
.vignette {
  pointer-events: none;
  position: fixed;
  inset: 0;
  z-index: 1;
}

.grain {
  opacity: 0.18;
  mix-blend-mode: overlay;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='180' height='180' filter='url(%23n)' opacity='.55'/%3E%3C/svg%3E");
}

.vignette {
  z-index: 7;
  background: radial-gradient(120% 80% at 50% 40%, transparent 40%, rgb(0 0 0 / 0.55) 100%);
}

.eyebrow {
  margin: 0;
  color: var(--brass);
  font-size: 0.68rem;
  letter-spacing: 0.28em;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  text-wrap: balance;
}

.hud {
  position: relative;
  z-index: 3;
  display: flex;
  justify-content: space-between;
  gap: 1.5rem;
  align-items: end;
  padding: calc(1.1rem + var(--safe-top)) calc(1.6rem + var(--safe-right)) 0.6rem
    calc(1.6rem + var(--safe-left));
}

.brand {
  display: flex;
  gap: 0.85rem;
  align-items: center;
}

.brand-mark {
  width: 14px;
  height: 42px;
  border-radius: 99px;
  background: linear-gradient(180deg, var(--filament), #1b6d62);
  box-shadow: 0 0 18px rgb(124 240 210 / 0.45);
}

.brand h1 {
  font-size: 1.7rem;
  letter-spacing: 0.22em;
  font-weight: 700;
}

.hud-meters {
  display: flex;
  align-items: center;
  gap: 1.1rem;
}

.rec-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  min-height: 40px;
  padding: 0 0.9rem;
  border-radius: 999px;
  background: rgb(255 255 255 / 0.04);
  box-shadow: inset 0 0 0 1px rgb(255 255 255 / 0.06);
  font-size: 0.78rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.rec-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #6b6860;
}

.rec-pill[data-state="live"] .rec-dot {
  background: var(--rec);
  box-shadow: 0 0 12px var(--rec);
  animation: pulse 1.1s ease-in-out infinite;
}

.rec-pill[data-state="live"] {
  color: #ffd7c8;
}

.meter {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.meter-label,
.progress-readout {
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.12em;
  font-size: 0.78rem;
  color: var(--muted);
}

.meter-track {
  width: 88px;
  height: 8px;
  border-radius: 99px;
  overflow: hidden;
  background: rgb(255 255 255 / 0.08);
}

.meter-fill {
  width: 0%;
  height: 100%;
  background: linear-gradient(90deg, #1f8f78, var(--filament));
  transition-property: width;
  transition-duration: 80ms;
  transition-timing-function: linear;
}

.progress-readout .slash {
  opacity: 0.4;
  margin: 0 0.15rem;
}

main {
  position: relative;
  z-index: 2;
  display: grid;
  grid-template-rows: 1fr auto;
  min-height: 0;
  padding: 0.4rem 1.2rem 0;
}

.chassis {
  min-height: 0;
}

.bezel {
  height: 100%;
  min-height: 0;
  padding: 12px;
  border-radius: var(--radius-outer);
  background:
    linear-gradient(180deg, #1c242e, #0c1015 42%, #151015);
  box-shadow:
    0 30px 80px rgb(0 0 0 / 0.45),
    inset 0 1px 0 rgb(255 255 255 / 0.14),
    inset 0 -1px 0 rgb(0 0 0 / 0.5);
}

.stage-wrap {
  position: relative;
  height: 100%;
  min-height: 0;
  overflow: hidden;
  border-radius: var(--radius-inner);
  background:
    radial-gradient(120% 80% at 50% 0%, #18232c, var(--glass) 46%);
  box-shadow: inset 0 0 80px rgb(0 0 0 / 0.45);
}

.stage {
  height: 100%;
  overflow: auto;
  padding: 2.4rem 8vw 75dvh;
  scrollbar-width: thin;
  scrollbar-color: #2a3a42 transparent;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  touch-action: pan-y;
  mask-image: linear-gradient(to bottom, black 0 62%, transparent);
}

.stage:focus-visible {
  outline: 2px solid var(--filament);
  outline-offset: -4px;
}

.script {
  margin: 0 auto;
  max-width: 18ch;
  font-family: var(--font-script);
  font-size: var(--script-size);
  font-weight: 500;
  font-optical-sizing: auto;
  line-height: 1.28;
  letter-spacing: -0.02em;
  text-wrap: pretty;
  text-align: center;
}

.word {
  color: var(--upcoming);
  transition-property: color, text-shadow, opacity;
  transition-duration: 420ms;
  transition-timing-function: cubic-bezier(0.2, 0, 0, 1);
}

.word.is-spoken {
  color: var(--spoken);
}

.word.is-current {
  color: var(--text);
  text-shadow: 0 0 18px rgb(255 246 232 / 0.28);
  text-decoration: underline;
  text-decoration-color: var(--filament);
  text-decoration-thickness: 0.08em;
  text-underline-offset: 0.14em;
}

.cue-line {
  pointer-events: none;
  position: absolute;
  top: var(--cue-at);
  left: 0;
  right: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.cue-filament {
  flex: 1;
  height: 2px;
  background: linear-gradient(
    90deg,
    transparent,
    var(--filament) 12%,
    #fff 50%,
    var(--filament) 88%,
    transparent
  );
  box-shadow: 0 0 16px rgb(124 240 210 / 0.55);
}

.cue-notch {
  width: 18px;
  height: 18px;
  border: 2px solid var(--filament);
}

.cue-notch.left {
  border-right: 0;
  border-radius: 4px 0 0 4px;
  margin-left: 10px;
}

.cue-notch.right {
  border-left: 0;
  border-radius: 0 4px 4px 0;
  margin-right: 10px;
}

.heard-bar {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.8rem;
  align-items: baseline;
  padding: 0.7rem 0.4rem 0.2rem;
  min-height: 3.2rem;
}

.heard-kicker {
  color: var(--filament);
  letter-spacing: 0.22em;
  text-transform: uppercase;
  font-size: 0.68rem;
}

#heardText {
  margin: 0;
  color: var(--muted);
  font-size: 0.95rem;
  text-wrap: pretty;
}

.dock {
  position: relative;
  z-index: 20;
  display: flex;
  flex-wrap: wrap;
  gap: 1rem 1.5rem;
  align-items: end;
  justify-content: space-between;
  padding: 0.7rem calc(1.4rem + var(--safe-right))
    calc(1.1rem + var(--safe-bottom)) calc(1.4rem + var(--safe-left));
  background: #07080a;
}

.dock-primary,
.dock-toggles,
.dock-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  align-items: end;
}

.btn,
.icon-btn,
select,
textarea {
  font: inherit;
  color: inherit;
}

.btn {
  min-height: var(--target-size);
  padding: 0.55rem 1.05rem;
  border: 0;
  border-radius: 999px;
  cursor: pointer;
  touch-action: manipulation;
  background: rgb(255 255 255 / 0.08);
  box-shadow: inset 0 0 0 1px rgb(255 255 255 / 0.08);
  transition-property: transform, background-color, box-shadow;
  transition-duration: 140ms;
  transition-timing-function: cubic-bezier(0.2, 0, 0, 1);
}

.btn:hover {
  background: rgb(255 255 255 / 0.12);
}

.btn:active,
.icon-btn:active {
  transform: scale(0.96);
}

.btn.start {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  background: var(--filament);
  color: #06221c;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  box-shadow: 0 0 24px rgb(124 240 210 / 0.25);
}

.btn.start.is-stop {
  background: var(--rec);
  color: #fff4ee;
  box-shadow: 0 0 24px rgb(255 77 26 / 0.28);
}

.start-icon {
  width: 0;
  height: 0;
  border-top: 6px solid transparent;
  border-bottom: 6px solid transparent;
  border-left: 10px solid currentColor;
  transform: translateX(1px);
}

.btn.start.is-stop .start-icon {
  width: 9px;
  height: 9px;
  border: 0;
  background: currentColor;
  transform: none;
}

.btn.ghost {
  background: transparent;
}

.icon-btn {
  min-height: var(--target-size);
  min-width: var(--target-size);
  padding: 0.4rem 0.8rem;
  border: 0;
  border-radius: 12px;
  cursor: pointer;
  touch-action: manipulation;
  background: rgb(255 255 255 / 0.05);
  transition-property: transform, background-color;
  transition-duration: 140ms;
}

.icon-btn[aria-pressed="true"] {
  background: rgb(124 240 210 / 0.16);
  color: var(--filament);
}

.slider,
.field {
  display: grid;
  gap: 0.25rem;
  font-size: 0.7rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted);
}

.slider input,
.field select {
  accent-color: var(--filament);
}

.field select {
  min-height: var(--target-size);
  padding: 0 0.7rem;
  border: 0;
  border-radius: 12px;
  background: rgb(255 255 255 / 0.05);
}

.hint {
  margin: 0;
  color: #6d6a63;
  font-size: 0.7rem;
  letter-spacing: 0.04em;
  text-transform: none;
}

dialog {
  width: min(720px, 92vw);
  border: 0;
  border-radius: 24px;
  padding: 1.2rem 1.3rem 1.1rem;
  background: #141820;
  color: var(--text);
  box-shadow: 0 30px 80px rgb(0 0 0 / 0.45);
}

dialog::backdrop {
  background: rgb(0 0 0 / 0.62);
}

.dialog-head {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: start;
  margin-bottom: 0.9rem;
}

.editor-label {
  display: block;
  margin-bottom: 0.4rem;
  color: var(--muted);
  font-size: 0.75rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

textarea {
  width: 100%;
  resize: vertical;
  min-height: 240px;
  padding: 0.9rem 1rem;
  border: 0;
  border-radius: 16px;
  background: #0c1016;
  line-height: 1.5;
  box-shadow: inset 0 0 0 1px rgb(255 255 255 / 0.06);
}

.dialog-note {
  color: var(--muted);
  font-size: 0.85rem;
  text-wrap: pretty;
}

.dialog-actions {
  display: flex;
  justify-content: end;
  gap: 0.6rem;
}

.help-pop {
  width: min(360px, 90vw);
  padding: 1rem 1.1rem;
  border: 0;
  border-radius: 18px;
  background: #151a22;
  color: var(--text);
  box-shadow: 0 18px 50px rgb(0 0 0 / 0.4);
}

.help-pop ul {
  margin: 0.6rem 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 0.4rem;
}

kbd {
  display: inline-block;
  min-width: 1.4rem;
  padding: 0.05rem 0.35rem;
  border-radius: 6px;
  background: rgb(255 255 255 / 0.08);
  font-family: var(--font-ui);
  font-size: 0.78rem;
}

body.is-fullscreen .hud,
body.is-fullscreen .heard-bar,
body.is-fullscreen .dock-controls,
body.is-fullscreen .dock-toggles,
body.is-fullscreen .dock-primary .btn.ghost {
  display: none;
}

body.is-fullscreen main {
  padding: 0;
}

body.is-fullscreen .bezel {
  padding: 0;
  border-radius: 0;
}

body.is-fullscreen .stage-wrap {
  border-radius: 0;
}

body.is-fullscreen .dock {
  justify-content: center;
  background: transparent;
}

body.is-fullscreen .dock-primary {
  width: 100%;
  justify-content: center;
}

body.is-fullscreen .btn.start {
  min-width: 9rem;
}

@keyframes pulse {
  50% {
    opacity: 0.35;
  }
}

@media (max-width: 860px) {
  .script {
    max-width: 22ch;
  }

  .hud {
    padding: calc(0.4rem + var(--safe-top)) calc(0.7rem + var(--safe-right))
      0.2rem calc(0.7rem + var(--safe-left));
  }

  .brand-mark {
    height: 22px;
    width: 10px;
  }

  .brand h1 {
    font-size: 1rem;
    letter-spacing: 0.12em;
  }

  .eyebrow,
  .meter,
  .hint {
    display: none;
  }

  .heard-bar {
    min-height: 0;
    padding: 0.25rem 0.2rem 0.1rem;
    gap: 0.4rem;
  }

  #heardText {
    font-size: 0.75rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .dock {
    gap: 0.4rem;
    padding: 0.4rem calc(0.7rem + var(--safe-right))
      calc(0.55rem + var(--safe-bottom)) calc(0.7rem + var(--safe-left));
  }

  .dock-primary,
  .dock-toggles,
  .dock-controls {
    width: 100%;
    gap: 0.4rem;
  }

  .btn,
  .icon-btn,
  .field select {
    min-height: 40px;
    font-size: 0.82rem;
  }

  .btn.start {
    flex: 1 1 100%;
    min-height: 48px;
    justify-content: center;
  }

  .btn.ghost {
    flex: 1 1 auto;
  }

  .slider {
    flex: 1 1 9rem;
  }

  .field {
    flex: 1 1 8rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  .rec-pill[data-state="live"] .rec-dot,
  .word,
  .btn,
  .icon-btn,
  .meter-fill {
    animation: none;
    transition-duration: 0.01ms;
  }
}
