:root {
  color-scheme: dark;
  --bg: #0b0d10;
  --surface: #14171c;
  --surface-2: #1b1f26;
  --border: #262b34;
  --text: #e9edf2;
  --muted: #8a93a0;
  --read: #4f5764;
  --accent: #ffd166;
  --accent-ink: #1a1405;
  --hint: #7cc4ff;
  --emphasis: #ff8f6b;
  --danger: #ff6b6b;
  --live: #3ddc84;
  --radius: 12px;
  --font: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;

  /* prompter, set from JS */
  --pr-font: 64px;
  --pr-line: 1.35;
  --pr-margin: 8%;
  --pr-reading: 30%;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

body {
  overflow: hidden;
}

[hidden] {
  display: none !important;
}

.view {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
}

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 16px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-2);
  color: var(--text);
  font: 500 15px/1 var(--font);
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
  transition:
    background 0.15s,
    border-color 0.15s,
    color 0.15s;
}
.btn:hover {
  background: #232832;
}
.btn:focus-visible,
.seg:focus-visible,
.play-big:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.btn.small {
  min-height: 36px;
  padding: 0 12px;
  font-size: 14px;
}
.btn.ghost {
  background: transparent;
  border-color: transparent;
}
.btn.ghost:hover {
  background: var(--surface-2);
}
.btn.icon-only {
  width: 44px;
  padding: 0;
}
.btn.primary {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: var(--accent);
  font-weight: 650;
}
.btn.primary:hover {
  background: #ffdb85;
}
.btn.danger:hover {
  color: var(--danger);
}
.btn.toggle[aria-pressed='true'] {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: var(--accent);
}
.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.icon {
  width: 20px;
  height: 20px;
  flex: none;
}

/* ---------- Editor ---------- */

.topbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px max(16px, env(safe-area-inset-right)) 10px max(16px, env(safe-area-inset-left));
  padding-top: max(10px, env(safe-area-inset-top));
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 18px;
}
.brand .icon {
  color: var(--accent);
  width: 24px;
  height: 24px;
}
.spacer {
  flex: 1;
}

.editor-body {
  flex: 1;
  display: flex;
  min-height: 0;
}

.sidebar {
  width: 280px;
  flex: none;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
  background: var(--surface);
  min-height: 0;
}
.sidebar-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  padding: 14px 12px 8px 16px;
}
.sidebar-head h2 {
  flex: 1;
  margin: 0;
  font-size: 13px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.script-list {
  list-style: none;
  margin: 0;
  padding: 4px 8px 16px;
  overflow-y: auto;
  flex: 1;
}
.script-list li {
  margin: 2px 0;
}
.script-list button {
  width: 100%;
  display: block;
  text-align: left;
  padding: 10px 12px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--text);
  font: inherit;
  cursor: pointer;
}
.script-list button:hover {
  background: var(--surface-2);
}
.script-list button[aria-current='true'] {
  background: var(--surface-2);
  box-shadow: inset 3px 0 0 var(--accent);
}
.script-list .s-title {
  display: block;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.script-list .s-meta {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin-top: 3px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.editor-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  padding: 12px max(16px, env(safe-area-inset-right)) 0 20px;
}
.editor-toolbar {
  display: flex;
  align-items: center;
  gap: 4px;
}
.title-input {
  flex: 1;
  min-width: 0;
  height: 48px;
  padding: 0 4px;
  border: 0;
  border-bottom: 1px solid transparent;
  background: transparent;
  color: var(--text);
  font: 700 24px/1.2 var(--font);
}
.title-input:focus {
  outline: none;
  border-bottom-color: var(--border);
}

.script-text {
  flex: 1;
  width: 100%;
  margin-top: 8px;
  padding: 16px;
  resize: none;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font: 18px/1.6 var(--font);
  tab-size: 2;
}
.script-text:focus {
  outline: none;
  border-color: #3a414d;
}
.script-text::placeholder {
  color: var(--muted);
}

.editor-footer {
  display: flex;
  gap: 16px;
  justify-content: space-between;
  padding: 10px 2px max(12px, env(safe-area-inset-bottom));
  font-size: 13px;
  color: var(--muted);
}
.hint-help {
  color: var(--hint);
}
.stats {
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

@media (max-width: 760px) {
  .editor-body {
    flex-direction: column;
  }
  .sidebar {
    width: auto;
    max-height: 34vh;
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }
  .editor-main {
    padding-left: 16px;
  }
  .editor-footer {
    flex-direction: column;
    gap: 4px;
  }
  .btn-label-optional {
    display: none;
  }
  .topbar .btn {
    padding: 0 12px;
  }
}

/* ---------- Dialog ---------- */

.dialog {
  width: min(520px, calc(100vw - 32px));
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--surface);
  color: var(--text);
}
.dialog::backdrop {
  background: rgb(0 0 0 / 0.6);
}
.dialog form {
  padding: 8px 20px 20px;
}
.dialog-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.dialog h2 {
  margin: 0;
  font-size: 20px;
}
.dialog h3 {
  margin: 20px 0 4px;
  font-size: 14px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 16px;
  font-size: 14px;
  color: var(--muted);
}
.field select {
  height: 44px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-2);
  color: var(--text);
  font: 16px var(--font);
}
.note {
  margin: 12px 0 0;
  font-size: 14px;
  line-height: 1.5;
  color: var(--muted);
}
.repo-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 44px; /* touch target */
  color: var(--accent);
  font-weight: 600;
  text-decoration: none;
}
.repo-link:hover {
  text-decoration: underline;
}

.legal-links {
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 8px 16px max(12px, env(safe-area-inset-bottom));
  font-size: 13px;
  color: var(--muted);
}
.legal-links a,
.legal-links-inline a {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  color: var(--muted);
  text-decoration: none;
}
.legal-links a:hover,
.legal-links-inline a:hover {
  color: var(--text);
  text-decoration: underline;
}
.repo-link .icon {
  width: 16px;
  height: 16px;
}

/* ---------- Prompter ---------- */

#prompter {
  background: #000;
}

.viewport {
  position: absolute;
  inset: 0;
  overflow: hidden;
  touch-action: none;
  cursor: default;
}

.stage {
  position: absolute;
  inset: 0;
  overflow: hidden;
}
.stage.mirror-h {
  transform: scaleX(-1);
}
.stage.mirror-v {
  transform: scaleY(-1);
}
.stage.mirror-h.mirror-v {
  transform: scale(-1, -1);
}

.reading-line {
  position: absolute;
  left: 0;
  right: 0;
  top: var(--pr-reading);
  height: calc(var(--pr-font) * var(--pr-line));
  transform: translateY(-50%);
  background: linear-gradient(
    90deg,
    rgb(255 209 102 / 0.1),
    rgb(255 209 102 / 0.03) 40%,
    rgb(255 209 102 / 0.03) 60%,
    rgb(255 209 102 / 0.1)
  );
  border-top: 1px solid rgb(255 209 102 / 0.18);
  border-bottom: 1px solid rgb(255 209 102 / 0.18);
  pointer-events: none;
}
.reading-line::before,
.reading-line::after {
  content: '';
  position: absolute;
  top: 50%;
  width: 0;
  height: 0;
  border: 12px solid transparent;
  transform: translateY(-50%);
}
.reading-line::before {
  left: 0;
  border-left-color: var(--accent);
}
.reading-line::after {
  right: 0;
  border-right-color: var(--accent);
}

.prompter-text {
  position: absolute;
  top: 0;
  left: var(--pr-margin);
  right: var(--pr-margin);
  padding-bottom: 100vh;
  font: 600 var(--pr-font)/var(--pr-line) var(--font);
  color: var(--text);
  overflow-wrap: break-word;
  will-change: transform;
  user-select: none;
  -webkit-user-select: none;
}
.prompter-text p {
  margin: 0 0 calc(var(--pr-font) * var(--pr-line) * 0.6);
}
.prompter-text .w {
  transition: color 0.2s;
}
.prompter-text .w.read {
  color: var(--read);
}
.prompter-text .w.cur {
  color: var(--accent);
}
.prompter-text.auto .w.cur {
  color: inherit;
}
.prompter-text .w.em {
  font-weight: 800;
  text-decoration: underline;
  text-decoration-color: var(--emphasis);
  text-decoration-thickness: 0.07em;
  text-underline-offset: 0.14em;
}
.prompter-text .w.em.read {
  text-decoration-color: var(--read);
}
.prompter-text .hint {
  display: inline-block;
  margin: 0 0.15em;
  padding: 0.08em 0.45em;
  border: 1px solid rgb(124 196 255 / 0.35);
  border-radius: 0.35em;
  background: rgb(124 196 255 / 0.08);
  color: var(--hint);
  font-size: 0.55em;
  font-style: italic;
  font-weight: 500;
  line-height: 1.3;
  vertical-align: 0.2em;
}
.prompter-text .hint.read {
  opacity: 0.4;
}
.prompter-text .punct.read {
  color: var(--read);
}

/* inside the (mirrorable) stage, so it reads correctly on teleprompter glass */
.timer {
  position: absolute;
  top: 12px;
  right: max(16px, env(safe-area-inset-right));
  padding: 4px 10px;
  border-radius: 8px;
  background: rgb(0 0 0 / 0.6);
  color: rgb(233 237 242 / 0.8);
  font: 600 20px/1.2 var(--font);
  font-variant-numeric: tabular-nums;
  pointer-events: none;
  transition: opacity 0.25s;
}
#prompter.controls-visible .timer {
  opacity: 0;
}

.countdown {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgb(0 0 0 / 0.55);
  color: var(--accent);
  font: 800 min(42vh, 320px)/1 var(--font);
  font-variant-numeric: tabular-nums;
  pointer-events: none;
}
.countdown.tick {
  animation: countdown-tick 1s ease-out;
}
@keyframes countdown-tick {
  from {
    transform: scale(1.35);
    opacity: 0;
  }
  25% {
    transform: scale(1);
    opacity: 1;
  }
  to {
    transform: scale(0.92);
    opacity: 0.85;
  }
}

.progress {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: rgb(255 255 255 / 0.06);
  pointer-events: none;
}
#progress-bar {
  height: 100%;
  width: 0;
  background: var(--accent);
  transition: width 0.3s;
}

/* ---------- Overlay ---------- */

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  pointer-events: none;
  opacity: 1;
  transition: opacity 0.25s;
}
.overlay.hidden {
  opacity: 0;
}
.overlay.hidden * {
  pointer-events: none !important;
}

.ov-top,
.ov-bottom {
  pointer-events: auto;
}

.ov-top {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: max(12px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) 28px
    max(16px, env(safe-area-inset-left));
  background: linear-gradient(rgb(0 0 0 / 0.9), rgb(0 0 0 / 0.65) 70%, transparent);
}
.pr-title {
  flex: 1;
  min-width: 0;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--muted);
}

.status {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  color: var(--muted);
  white-space: nowrap;
}
.status .dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--read);
}
.status.live .dot {
  background: var(--live);
  box-shadow: 0 0 0 0 rgb(61 220 132 / 0.6);
  animation: pulse 1.6s infinite;
}
.status.live {
  color: var(--text);
}
@keyframes pulse {
  to {
    box-shadow: 0 0 0 10px rgb(61 220 132 / 0);
  }
}

.segmented {
  display: flex;
  padding: 3px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: rgb(20 23 28 / 0.9);
}
.seg {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 38px;
  padding: 0 14px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--muted);
  font: 500 15px var(--font);
  cursor: pointer;
}
.seg[aria-checked='true'] {
  background: var(--surface-2);
  color: var(--text);
  box-shadow: inset 0 0 0 1px var(--border);
}
.seg:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.play-big {
  pointer-events: auto;
  align-self: center;
  display: grid;
  place-items: center;
  width: 96px;
  height: 96px;
  border: 0;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-ink);
  box-shadow: 0 10px 40px rgb(0 0 0 / 0.6);
  cursor: pointer;
}
.play-big .icon {
  width: 44px;
  height: 44px;
}
.overlay.has-resume .play-big {
  display: none;
}

.resume-card {
  pointer-events: auto;
  align-self: center;
  width: min(560px, calc(100vw - 32px));
  padding: 18px 20px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: rgb(20 23 28 / 0.96);
  box-shadow: 0 10px 40px rgb(0 0 0 / 0.6);
}
.resume-card p {
  margin: 0 0 14px;
  font-size: 17px;
  line-height: 1.5;
  color: var(--muted);
}
.resume-card q {
  color: var(--text);
  font-weight: 600;
}
.resume-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  flex-wrap: wrap;
}
.play-big.running {
  background: rgb(27 31 38 / 0.92);
  color: var(--text);
  box-shadow:
    0 0 0 1px var(--border),
    0 10px 40px rgb(0 0 0 / 0.6);
}

.ov-bottom {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px 24px;
  padding: 28px max(16px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom))
    max(16px, env(safe-area-inset-left));
  background: linear-gradient(transparent, rgb(0 0 0 / 0.65) 30%, rgb(0 0 0 / 0.92));
}
.ctl {
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1 1 140px;
  font-size: 13px;
  color: var(--muted);
}
.ctl-buttons {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

input[type='range'] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 32px;
  background: transparent;
  cursor: pointer;
}
input[type='range']::-webkit-slider-runnable-track {
  height: 4px;
  border-radius: 2px;
  background: #333a45;
}
input[type='range']::-moz-range-track {
  height: 4px;
  border-radius: 2px;
  background: #333a45;
}
input[type='range']::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 22px;
  height: 22px;
  margin-top: -9px;
  border-radius: 50%;
  background: var(--accent);
  border: 0;
}
input[type='range']::-moz-range-thumb {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--accent);
  border: 0;
}

@media (max-width: 760px) {
  .ov-top {
    flex-wrap: wrap;
  }
  .pr-title {
    order: 1;
    flex-basis: 100%;
  }
  .seg span {
    display: none;
  }
  .ov-bottom {
    gap: 4px 16px;
  }
}

/* ---------- Update button ---------- */

.update-btn {
  border-color: var(--live);
  color: var(--live);
}
.update-btn:hover {
  background: rgb(61 220 132 / 0.12);
}

/* ---------- Done button (touch keyboards) ---------- */

.done-btn {
  position: fixed;
  top: 0;
  right: max(16px, env(safe-area-inset-right));
  z-index: 20;
  box-shadow: 0 6px 24px rgb(0 0 0 / 0.55);
}

/* ---------- Toast ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: max(24px, env(safe-area-inset-bottom));
  z-index: 10;
  max-width: calc(100vw - 32px);
  padding: 12px 18px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface-2);
  color: var(--text);
  font-size: 15px;
  box-shadow: 0 10px 30px rgb(0 0 0 / 0.5);
  transform: translate(-50%, 20px);
  opacity: 0;
  pointer-events: none;
  transition:
    opacity 0.2s,
    transform 0.2s;
}
.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition: none !important;
    animation: none !important;
  }
}
