:root {
  --bg: #0b0b0c;
  --ink: #f5f3ee;
  --soft: #a7a39b;
  --accent: #ff5b1f;
  --font-size: 40px;
  --band: var(--band-user, 45dvh);
  --target: 44px;
  color-scheme: dark;
  font-family: "Inter Tight", "SF Pro Text", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink); overscroll-behavior: none; }
body { -webkit-tap-highlight-color: transparent; touch-action: manipulation; user-select: none; -webkit-user-select: none; }
button, select, input, textarea { font: inherit; color: inherit; }

#stage { position: fixed; inset: 0; overflow: hidden; background: #000; }
/* the camera only feeds the canvas; the canvas is both the preview and what gets recorded */
#cam { position: absolute; width: 2px; height: 2px; opacity: 0; pointer-events: none; }
#view { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; background: #000; }

#camera-off { position: absolute; inset: 0; display: grid; place-content: center; gap: 16px; text-align: center; color: var(--soft); }
#camera-off[hidden] { display: none; }

/* ---------- script band ---------- */
#prompter {
  position: absolute; inset: 0 0 auto 0; height: calc(var(--band) + env(safe-area-inset-top, 0px));
  padding-top: env(safe-area-inset-top, 0px);
  background: linear-gradient(to bottom, rgb(0 0 0 / 0.82) 0%, rgb(0 0 0 / 0.72) 70%, rgb(0 0 0 / 0) 100%);
  cursor: grab; touch-action: none;
}
#scroller {
  position: relative; height: 100%; overflow: hidden;
  mask-image: linear-gradient(to bottom, transparent 0, #000 12%, #000 78%, transparent 100%);
}
#script-text {
  position: absolute; left: 0; right: 0; top: 0;
  margin-inline: auto; max-width: 30ch; width: calc(100% - 2 * max(20px, env(safe-area-inset-left, 0px)));
  font-size: var(--font-size); line-height: 1.32; font-weight: 600; letter-spacing: -0.01em;
  text-wrap: pretty; will-change: transform;
}
#script-text p { margin: 0 0 0.35em; }
#script-text p.gap { height: 0.9em; margin: 0; }
#script-text.flip { scale: -1 1; }
#reading-line {
  position: absolute; left: 10px; top: calc(env(safe-area-inset-top, 0px) + var(--read-y, 22%));
  width: 0; height: 0; border-block: 9px solid transparent; border-left: 13px solid var(--accent);
  pointer-events: none;
}

#speedbox {
  position: absolute; right: max(12px, env(safe-area-inset-right, 0px));
  top: calc(var(--band) + env(safe-area-inset-top, 0px) + 6px);
  display: flex; align-items: center; gap: 6px;
}

/* ---------- HUD ---------- */
#hud {
  position: absolute; left: max(16px, env(safe-area-inset-left, 0px)); bottom: calc(112px + env(safe-area-inset-bottom, 0px));
  display: flex; align-items: center; gap: 10px; font-variant-numeric: tabular-nums; font-weight: 600;
  text-shadow: 0 1px 3px rgb(0 0 0 / 0.7);
}
#rec-dot { width: 12px; height: 12px; border-radius: 50%; background: var(--accent); animation: blink 1s steps(2, start) infinite; }
#rec-dot[hidden] { display: none; }
#est { color: var(--soft); font-weight: 500; }
@keyframes blink { to { visibility: hidden; } }

#countdown {
  position: absolute; inset: 0; display: grid; place-items: center; pointer-events: none;
  font-size: min(40vw, 260px); font-weight: 700; color: rgb(255 255 255 / 0.92); text-shadow: 0 6px 30px rgb(0 0 0 / 0.5);
}
#countdown[hidden] { display: none; }

/* ---------- controls ---------- */
#controls {
  position: absolute; left: 0; right: 0; bottom: 0;
  display: flex; align-items: center; justify-content: center; gap: 14px;
  padding: 14px max(14px, env(safe-area-inset-right, 0px)) max(18px, env(safe-area-inset-bottom, 0px)) max(14px, env(safe-area-inset-left, 0px));
  background: linear-gradient(to top, rgb(0 0 0 / 0.55), transparent);
}
#speed { min-width: 3ch; text-align: center; font-weight: 700; font-variant-numeric: tabular-nums; text-shadow: 0 1px 3px rgb(0 0 0 / 0.7); }
#speed::after { content: " wpm"; font-weight: 500; color: var(--soft); font-size: 0.8em; }

/* clear "liquid glass": brightens what's behind, lit rim, no heavy frost */
.glass {
  position: relative; display: inline-grid; place-items: center;
  min-width: var(--target); min-height: var(--target); padding: 0 14px;
  border: 0; border-radius: 999px; color: #fff;
  background: linear-gradient(160deg, rgb(255 255 255 / 0.22), rgb(255 255 255 / 0.06) 55%, rgb(255 255 255 / 0.12));
  backdrop-filter: blur(2px) saturate(1.8) brightness(1.18);
  -webkit-backdrop-filter: blur(2px) saturate(1.8) brightness(1.18);
  box-shadow: inset 0 1px 0 rgb(255 255 255 / 0.55), inset 0 -1px 0 rgb(255 255 255 / 0.12),
              inset 0 0 0 1px rgb(255 255 255 / 0.18), 0 6px 18px rgb(0 0 0 / 0.28);
}
.glass.icon { width: var(--target); padding: 0; }
.glass.wide { padding: 0 22px; font-weight: 600; }
.glass:active { scale: 0.94; }
.glass svg, .ghost svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.glass .i-play { fill: currentColor; stroke: none; }
#play .i-pause, #play.playing .i-play { display: none; }
#play.playing .i-pause { display: block; }

#record {
  width: 72px; height: 72px; border-radius: 50%; border: 4px solid #fff; background: transparent; padding: 0;
  display: grid; place-items: center; margin-inline: 6px;
}
#record span { width: 54px; height: 54px; border-radius: 50%; background: var(--accent); transition: all 160ms ease; }
#record.on span { width: 28px; height: 28px; border-radius: 7px; }
#record:disabled { opacity: 0.4; }

/* ---------- sheets ---------- */
dialog {
  width: min(680px, 100% - 24px); max-height: min(92dvh, 900px); padding: 0; border: 0; border-radius: 22px;
  background: #151517; color: var(--ink); box-shadow: 0 30px 80px rgb(0 0 0 / 0.6), inset 0 0 0 1px rgb(255 255 255 / 0.08);
}
dialog::backdrop { background: rgb(0 0 0 / 0.55); }
.sheet { display: flex; flex-direction: column; gap: 14px; padding: 22px; user-select: text; -webkit-user-select: text; }
.sheet h2 { margin: 0; font-size: 1.5rem; letter-spacing: -0.02em; }
textarea {
  min-height: 46dvh; resize: vertical; padding: 14px; border-radius: 14px; border: 1px solid rgb(255 255 255 / 0.12);
  background: #0e0e10; line-height: 1.5; font-size: 16px;
}
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.spacer { flex: 1; }
.ghost, .primary {
  display: inline-flex; align-items: center; justify-content: center; min-height: var(--target); padding: 0 18px;
  border-radius: 12px; border: 1px solid rgb(255 255 255 / 0.16); background: transparent; color: var(--ink);
  font-weight: 600; text-decoration: none; cursor: pointer;
}
.primary { background: var(--ink); color: #111; border-color: transparent; }
.file { position: relative; overflow: hidden; }
.file input { position: absolute; inset: 0; opacity: 0; }
.field { display: grid; grid-template-columns: 1fr minmax(120px, 1.4fr) 3.5ch; align-items: center; gap: 12px; min-height: var(--target); }
.field select { grid-column: 2 / 4; min-height: 40px; border-radius: 10px; background: #0e0e10; border: 1px solid rgb(255 255 255 / 0.14); padding: 0 10px; }
.field output { text-align: right; color: var(--soft); font-variant-numeric: tabular-nums; }
input[type="range"] { accent-color: var(--accent); width: 100%; }
.check { display: flex; align-items: center; gap: 12px; min-height: var(--target); }
.check input { width: 22px; height: 22px; accent-color: var(--accent); }
.note { margin: 0; color: var(--soft); font-size: 0.9rem; line-height: 1.45; }
#review { width: 100%; max-height: 52dvh; border-radius: 14px; background: #000; }

@media (orientation: landscape) and (max-height: 520px) {
  :root { --band: max(var(--band-user, 45dvh), 62dvh); }
  #controls { padding-top: 6px; gap: 8px; }
  #record { width: 60px; height: 60px; }
  #record span { width: 44px; height: 44px; }
  #hud { bottom: calc(84px + env(safe-area-inset-bottom, 0px)); }
}

@media (prefers-reduced-motion: reduce) {
  #rec-dot { animation: none; }
  #record span { transition: none; }
}
