:root {
  --bg: #0b0b0c;
  --panel: #17171a;
  --line: #2a2a30;
  --fg: #f4f4f5;
  --muted: #9a9aa3;
  --accent: #ffd23f;
  --live: #ff4d4d;
  --font-size: 56px;
  --focus: 28%;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
body { overflow-x: clip; }
/* Stop mobile browsers from enlarging text on their own, so sizes match the slider. */
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }

[hidden] { display: none !important; }

button {
  font: inherit;
  color: inherit;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 14px;
  cursor: pointer;
  touch-action: manipulation;
}
button.primary {
  background: var(--accent);
  color: #111;
  border: 0;
  font-weight: 700;
  font-size: 1.1rem;
  padding: 14px;
}

/* ---------- Editor ---------- */
#editor {
  max-width: 820px;
  margin: 0 auto;
  min-height: 100dvh;
  padding: max(16px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 14px;
}
#editor h1 { margin: 8px 0 4px; font-size: 1.6rem; }
.muted { color: var(--muted); margin: 0; }
.warn { color: var(--accent); margin: 0; font-size: .9rem; }

.speeches { display: flex; gap: 8px; }
.speeches select {
  flex: 1;
  min-width: 0;
  font: inherit; color: var(--fg); background: var(--panel);
  border: 1px solid var(--line); border-radius: 10px; padding: 10px;
}
.speeches button { white-space: nowrap; }
#title {
  font: inherit; font-size: 1.05rem; font-weight: 600;
  color: var(--fg); background: var(--panel);
  border: 1px solid var(--line); border-radius: 10px; padding: 10px 14px;
}

#script {
  flex: 1;
  min-height: 40dvh;
  width: 100%;
  resize: vertical;
  background: var(--panel);
  color: var(--fg);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px;
  font: 1.05rem/1.5 inherit;
  font-family: inherit;
}

.settings {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 12px;
  align-items: end;
}
.settings label { display: flex; flex-direction: column; gap: 6px; font-size: .9rem; color: var(--muted); }
.settings label.check { flex-direction: row; align-items: center; gap: 8px; }
.settings select {
  font: inherit; color: var(--fg); background: var(--panel);
  border: 1px solid var(--line); border-radius: 8px; padding: 8px;
}
.settings input[type=range] { accent-color: var(--accent); }

/* Preview overlay shown while changing text size: same width, padding and type as the prompter,
   so line breaks match. Fixed to the top so the finger on the slider never covers it. */
#preview {
  position: fixed;
  left: 0; right: 0; top: 0;
  z-index: 10;
  background: #000;
  border-bottom: 1px solid var(--line);
  padding: max(14px, env(safe-area-inset-top)) max(5vw, 16px) 14px;
  max-height: min(calc(var(--font-size) * 1.35 * 3 + 28px), 60vh);
  overflow: hidden;
  opacity: 0;
  visibility: hidden;
  transition: opacity .2s, visibility .2s;
  pointer-events: none;
}
#preview.show { opacity: 1; visibility: visible; }
#preview::after {
  content: "";
  position: absolute;
  left: 0; right: 0; bottom: 0;
  height: calc(var(--font-size) * .9);
  background: linear-gradient(rgba(0,0,0,0), #000);
  pointer-events: none;
}
#preview.mirror #previewText { transform: scaleX(-1); }
#previewText {
  max-width: 1200px;
  margin: 0 auto;
  font-size: var(--font-size);
  line-height: 1.35;
  font-weight: 600;
  word-wrap: break-word;
}
#previewText .current { color: var(--accent); }
#previewText.placeholder { color: var(--muted); }

/* ---------- Prompter ---------- */
#prompter {
  position: fixed;
  inset: 0;
  overflow: hidden;
  background: #000;
}
#stage {
  position: absolute;
  inset: 0;
  padding: 0 max(5vw, 16px);
}
#prompter.mirror #stage { transform: scaleX(-1); }
#stage { touch-action: none; overscroll-behavior: none; cursor: grab; }
#text.dragging { transition: none; }
#text.dragging .w { transition: none; }

#text {
  max-width: 1200px;
  margin: 0 auto;
  font-size: var(--font-size);
  line-height: 1.35;
  font-weight: 600;
  white-space: normal;
  word-wrap: break-word;
  transition: transform .45s ease-out;
  will-change: transform;
  padding-bottom: 100vh;
}
#text .w { transition: color .25s, opacity .25s; border-radius: .15em; }
#text .w.spoken { opacity: .18; }
#text .w.current { color: var(--accent); }
#text p { margin: 0 0 .6em; }

/* Fade out what's already been said above the reading line */
#fade {
  position: absolute;
  left: 0; right: 0; top: 0;
  height: calc(var(--focus) - 2%);
  background: linear-gradient(#000 35%, rgba(0,0,0,0));
  pointer-events: none;
}
#marker {
  position: absolute;
  left: 6px;
  top: var(--focus);
  width: 0; height: 0;
  border-top: 12px solid transparent;
  border-bottom: 12px solid transparent;
  border-left: 16px solid var(--accent);
  transform: translateY(4px);
  opacity: .8;
  pointer-events: none;
}

#clock {
  position: absolute;
  top: max(10px, env(safe-area-inset-top));
  right: 14px;
  padding: 4px 10px;
  border-radius: 8px;
  background: rgba(20,20,24,.85);
  color: var(--muted);
  font: 600 1.1rem/1.2 ui-monospace, "SF Mono", Consolas, monospace;
  font-variant-numeric: tabular-nums;
  pointer-events: none;
}
#clock.running { color: var(--fg); }

#controls {
  position: absolute;
  left: 50%;
  bottom: max(12px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  display: flex;
  gap: 6px;
  padding: 6px;
  background: rgba(20,20,24,.85);
  border: 1px solid var(--line);
  border-radius: 14px;
  backdrop-filter: blur(8px);
  transition: opacity .3s;
  max-width: calc(100vw - 16px);
  overflow-x: auto;
}
#controls button { min-width: 44px; padding: 8px 10px; background: transparent; border-color: transparent; }
#controls button:hover { background: var(--panel); }
#mic.live { background: var(--live); border-color: var(--live); }
#mic.waiting { border-color: var(--live); animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: .35; } }
#prompter.idle #controls, #prompter.idle #heard { opacity: 0; }

#heard {
  position: absolute;
  left: 50%;
  bottom: calc(max(12px, env(safe-area-inset-bottom)) + 64px);
  transform: translateX(-50%);
  max-width: calc(100vw - 32px);
  white-space: nowrap;
  overflow: hidden;
  color: var(--muted);
  font-size: .85rem;
  transition: opacity .3s;
  pointer-events: none;
}
