:root {
  --bg: #0b0b0d; --paper: #17171a; --line: #2a2a30; --ink: #f4f4f5; --muted: #a1a1aa;
  --red: #e11d2e; --yellow: #ffd60a; --green: #3ddc97;
  --top: env(safe-area-inset-top, 0px); --bottom: env(safe-area-inset-bottom, 0px);
  --left: env(safe-area-inset-left, 0px); --right: env(safe-area-inset-right, 0px);
  color-scheme: dark;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink); overscroll-behavior: none; }
body { font: 17px/1.4 system-ui, -apple-system, sans-serif; -webkit-text-size-adjust: 100%; overflow: hidden; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; touch-action: manipulation; }
button, a, .bar, .controls { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
:focus-visible { outline: 2px solid var(--yellow); outline-offset: 2px; }

/* Pages */
#app, .page { height: 100dvh; }
.page { overflow-y: auto; padding: 0 max(16px, var(--right)) calc(var(--bottom) + 24px) max(16px, var(--left)); max-width: 760px; margin: 0 auto; }
.bar { position: sticky; top: 0; z-index: 2; display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: calc(var(--top) + 8px) 0 8px; background: var(--bg); }
.bar h2 { font-size: 17px; margin: 0; }
.bar-side { display: flex; gap: 4px; min-width: 88px; }
.bar-side.end { justify-content: flex-end; }
h1 { font-size: 34px; margin: 8px 0 16px; letter-spacing: -0.02em; }
h3 { font-size: 13px; font-weight: 600; color: var(--muted); margin: 24px 4px 8px; }
.muted, .note { color: var(--muted); font-size: 14px; }
.note { margin: 8px 4px; }
.empty { color: var(--muted); text-align: center; margin-top: 25vh; }
.hint { display: flex; gap: 10px; align-items: center; margin-top: 24px; padding: 14px 16px; border-radius: 14px; background: var(--paper); color: var(--muted); font-size: 15px; }
.icon { width: 24px; height: 24px; flex: none; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.icon-button { display: grid; place-items: center; width: 44px; height: 44px; border: 0; border-radius: 12px; background: none; }
.icon-button.label { width: auto; min-width: 52px; padding: 0 8px; font-size: 15px; font-weight: 600; }
.text-button { border: 0; background: none; padding: 10px 4px; color: var(--yellow); font-weight: 600; }
.text-button.danger { color: #ff6b76; }
.primary { display: flex; align-items: center; justify-content: center; gap: 8px; width: 100%; min-height: 52px; border: 0; border-radius: 14px; background: var(--red); color: #fff; font-weight: 600; }
.primary:disabled { opacity: 0.5; }

.list { list-style: none; margin: 0; padding: 0; border-radius: 16px; overflow: hidden; background: var(--paper); }
.list li + li { border-top: 1px solid var(--line); }
.row { display: block; padding: 14px 16px; color: inherit; text-decoration: none; }
.row:active { background: var(--line); }
.row-title { display: block; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.editor { display: flex; flex-direction: column; overflow: hidden; }
.title-input, .script-input { width: 100%; border: 0; background: none; outline: none; padding: 8px 4px; }
.title-input { font-size: 26px; font-weight: 700; }
.script-input { flex: 1; min-height: 0; resize: none; font-size: 18px; line-height: 1.5; margin-bottom: 12px; -webkit-user-select: text; user-select: text; }

/* Sheets */
.sheet { width: 100%; max-width: 640px; height: calc(100dvh - var(--top) - 24px); max-height: none; margin: auto auto 0; padding: 0; border: 0; border-radius: 20px 20px 0 0; background: var(--bg); color: var(--ink); overflow: hidden; animation: rise 0.28s cubic-bezier(0.2, 0.8, 0.2, 1); }
.sheet[open] { display: flex; flex-direction: column; }
.sheet::backdrop { background: rgb(0 0 0 / 0.6); }
.sheet .bar { padding: 8px 16px; }
.sheet-body { flex: 1; overflow-y: auto; padding: 0 max(16px, var(--right)) calc(var(--bottom) + 24px) max(16px, var(--left)); }
@keyframes rise { from { transform: translateY(100%); } }
.card { margin: 0; padding: 0; border: 0; border-radius: 16px; background: var(--paper); overflow: hidden; }
.field { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 52px; padding: 6px 16px; }
.field + .field { border-top: 1px solid var(--line); }
.field.stacked { flex-direction: column; align-items: stretch; gap: 4px; padding: 12px 16px; }
.field.stacked span { display: flex; justify-content: space-between; }
.field output { color: var(--muted); font-variant-numeric: tabular-nums; }
.field select { border: 0; background: var(--paper); color: var(--muted); text-align: right; max-width: 60%; padding: 8px 0; }
.field input[type='password'], .field .model { flex: 1; min-width: 0; border: 0; background: none; outline: none; padding: 8px 0; }
.field .model { text-align: right; color: var(--muted); font-size: 16px; }
.field input[type='range'] { width: 100%; height: 32px; accent-color: var(--red); touch-action: pan-y; }
.switch { appearance: none; flex: none; position: relative; width: 51px; height: 31px; margin: 0; border-radius: 16px; background: #3a3a41; transition: background 0.2s; }
.switch::after { content: ''; position: absolute; inset: 2px auto 2px 2px; width: 27px; border-radius: 50%; background: #fff; transition: transform 0.2s; }
.switch:checked { background: var(--red); }
.switch:checked::after { transform: translateX(20px); }
.toast { position: fixed; z-index: 50; left: 50%; top: calc(var(--top) + 12px); transform: translateX(-50%); width: max-content; max-width: calc(100vw - 32px); padding: 12px 16px; border-radius: 14px; background: #2a2a30; color: #fff; text-align: center; box-shadow: 0 8px 30px rgb(0 0 0 / 0.5); }

/* Prompter */
.prompter { position: fixed; inset: 0; overflow: hidden; background: #000; --text: #fff; --mark: var(--yellow); }
.prompter.light { background: #fff; --text: #000; --mark: #d9480f; }
.stage { position: absolute; top: 0; left: 0; display: grid; place-items: center; transform-origin: 0 0; overflow: hidden; }
.frame { position: relative; grid-area: 1 / 1; padding: max(12px, var(--top)) max(28px, var(--right)) max(12px, var(--bottom)) max(28px, var(--left)); }
/* 16:9 already leaves the notch and rounded corners outside the box. */
.wide .frame { padding: 12px 32px; }
.turned .frame { padding: 12px 32px; }
.mirror .frame { transform: scaleX(-1); }
.surface { position: relative; width: 100%; height: 100%; overflow: hidden; touch-action: none; cursor: pointer; -webkit-user-select: none; user-select: none; }
.fade .surface { -webkit-mask-image: linear-gradient(transparent, #000 10%, #000 80%, transparent); mask-image: linear-gradient(transparent, #000 10%, #000 80%, transparent); }
.lines { color: var(--text); will-change: transform; }
.line { height: 1lh; white-space: nowrap; }
.lines span { transition: opacity 0.15s; }
.cue { opacity: 0.4; font-style: italic; }
.spoken { opacity: 0.32; }
.current { color: var(--mark); }
.progress-track { position: absolute; top: 24px; bottom: 24px; right: 8px; width: 4px; border-radius: 2px; background: rgb(128 128 128 / 0.25); overflow: hidden; pointer-events: none; }
.progress { height: 100%; background: rgb(128 128 128 / 0.8); transform: scaleY(0); transform-origin: top; }
.no-progress .progress-track { display: none; }
.countdown { position: absolute; inset: 0; display: grid; place-items: center; font-size: min(30vh, 200px); font-weight: 700; color: var(--text); background: rgb(0 0 0 / 0.5); pointer-events: none; }
.light .countdown { background: rgb(255 255 255 / 0.6); }
.controls { grid-area: 1 / 1; align-self: end; z-index: 2; display: flex; align-items: center; gap: 6px; margin-bottom: calc(var(--bottom) + 12px); padding: 6px 12px; border-radius: 999px; background: rgb(32 32 36 / 0.92); color: #fff; transition: opacity 0.25s; }
.turned .controls { margin-bottom: 16px; }
.reading .controls { opacity: 0; pointer-events: none; }
.controls:focus-within { opacity: 1; pointer-events: auto; }
.mic { width: 12px; height: 12px; margin: 0 8px; border-radius: 50%; background: #52525b; }
.mic.on { background: var(--green); }
@media (prefers-reduced-motion: reduce) { .sheet { animation: none; } .lines span, .controls { transition: none; } }
