/* Teleprompter — dark studio UI, so the screen doesn't light up a set. */

:root {
  --bg: #0e0f12;
  --panel: #16181d;
  --panel-2: #1d2027;
  --line: #2a2e37;
  --ink: #e9ebf0;
  --muted: #9aa1ae;
  --accent: #ffcc33;
  --accent-ink: #1a1400;
  --danger: #ff5a5f;
  --ok: #3ddc84;
  --radius: 8px;
  color-scheme: dark;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }
dialog { margin: auto; }

html, body { height: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.45 Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}
input, button, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent); }

.spacer { flex: 1 1 auto; }
.row { display: flex; gap: 8px; align-items: end; }
.row.wrap { flex-wrap: wrap; }
.grow { flex: 1 1 0; }
.hint { color: var(--muted); font-size: 12.5px; }
.hint.center { text-align: center; }
.error { color: var(--danger); }

/* ---------- controls ---------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 34px; padding: 6px 12px;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--radius);
  white-space: nowrap;
}
.btn:hover { border-color: #3c4250; }
.btn.small { min-height: 30px; padding: 4px 10px; font-size: 13px; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
.btn.danger { color: var(--danger); }
.btn.live { border-color: var(--ok); color: var(--ok); }
.btn:disabled { opacity: .45; cursor: default; }
select.btn { appearance: none; padding-right: 12px; }
.file-btn { cursor: pointer; }

.icon-btn {
  background: none; border: 0; padding: 6px; border-radius: 6px; color: var(--muted);
  min-width: 32px; min-height: 32px;
}
.icon-btn:hover { background: var(--panel-2); color: var(--ink); }

.field { display: flex; flex-direction: column; gap: 4px; font-size: 12.5px; color: var(--muted); margin: 10px 0 0; }
.field output { color: var(--ink); font-variant-numeric: tabular-nums; margin-left: auto; position: absolute; right: 0; top: 0; }
.field { position: relative; }
.field input:not([type=range]):not([type=color]), .field select {
  width: 100%; padding: 7px 9px; background: var(--bg); border: 1px solid var(--line); border-radius: 6px; color: var(--ink);
}
.field input[type=color] { width: 100%; height: 32px; border: 1px solid var(--line); border-radius: 6px; background: var(--bg); padding: 2px; }
input[type=range] { width: 100%; accent-color: var(--accent); }
.check { display: flex; gap: 8px; align-items: center; margin: 8px 0 0; font-size: 13px; }
.check input { accent-color: var(--accent); width: 16px; height: 16px; }

/* ---------- layout ---------- */

.topbar {
  height: 56px; display: flex; align-items: center; gap: 8px; padding: 0 14px;
  border-bottom: 1px solid var(--line); background: var(--panel);
}
.brand { font-weight: 700; letter-spacing: .02em; color: var(--accent); white-space: nowrap; }
.title-input {
  min-width: 0; flex: 0 1 360px; background: transparent; border: 1px solid transparent; border-radius: 6px;
  padding: 6px 8px; font-weight: 600; font-size: 15px;
}
.title-input:hover, .title-input:focus { border-color: var(--line); background: var(--bg); outline: none; }
.sync-status { color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 260px; }
.sync-status.ok { color: var(--ok); }
.sync-status.error { color: var(--danger); }
.sync-status.warn { color: var(--accent); }

.workspace {
  display: grid; grid-template-columns: 260px minmax(0, 1fr) 300px; grid-template-rows: minmax(0, 1fr);
  height: calc(100% - 56px);
}

.library, .settings { background: var(--panel); overflow-y: auto; }
.library { border-right: 1px solid var(--line); display: flex; flex-direction: column; padding: 12px; gap: 10px; }
.settings { border-left: 1px solid var(--line); padding: 4px 14px 24px; }

.library-head { display: flex; gap: 8px; }
.library-head input { flex: 1 1 auto; min-width: 0; padding: 7px 9px; background: var(--bg); border: 1px solid var(--line); border-radius: 6px; }
.library-actions { display: flex; gap: 6px; flex-wrap: wrap; }

.script-list { list-style: none; display: flex; flex-direction: column; gap: 2px; flex: 1 1 auto; overflow-y: auto; }
.script-list li { display: flex; align-items: center; border-radius: 6px; }
.script-list li.active { background: var(--panel-2); box-shadow: inset 3px 0 0 var(--accent); }
.script-list li:hover { background: var(--panel-2); }
.script-list li .icon-btn { opacity: 0; }
.script-list li:hover .icon-btn, .script-list li.active .icon-btn { opacity: 1; }
.script-list li.empty { color: var(--muted); padding: 8px; }
.script-open { flex: 1 1 auto; min-width: 0; background: none; border: 0; text-align: left; padding: 8px 10px; display: flex; flex-direction: column; }
.script-title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.script-meta { color: var(--muted); font-size: 12px; }

.editor-pane { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.toolbar {
  display: flex; flex-wrap: wrap; gap: 4px; align-items: center; padding: 8px 12px;
  border-bottom: 1px solid var(--line); background: var(--panel);
}
.toolbar button, .toolbar select, .color-btn {
  min-height: 30px; min-width: 32px; padding: 3px 8px; border-radius: 6px;
  background: transparent; border: 1px solid transparent; color: var(--ink);
}
.toolbar button:hover, .color-btn:hover, .toolbar select:hover { background: var(--panel-2); border-color: var(--line); }
.toolbar select { background: var(--panel-2); border-color: var(--line); max-width: 150px; }
.toolbar .sep { width: 1px; height: 20px; background: var(--line); margin: 0 4px; }
.color-btn { position: relative; display: inline-flex; align-items: center; justify-content: center; font-weight: 700; cursor: pointer; }
.color-btn input { position: absolute; inset: auto 4px 2px; width: calc(100% - 8px); height: 4px; border: 0; padding: 0; opacity: 1; cursor: pointer; }
.color-btn input::-webkit-color-swatch-wrapper { padding: 0; }
.color-btn input::-webkit-color-swatch { border: 0; }

.editor {
  flex: 1 1 auto; overflow-y: auto; padding: 28px clamp(16px, 6vw, 72px) 120px;
  font-size: 20px; line-height: 1.6; outline: none;
}
.editor p, .editor div { margin: 0 0 .8em; }
.editor h1 { font-size: 1.6em; margin: 0 0 .6em; }
.editor h2 { font-size: 1.3em; margin: 0 0 .6em; }
.editor h3 { font-size: 1.1em; margin: 0 0 .6em; }
.editor blockquote { border-left: 3px solid var(--accent); padding-left: 14px; color: var(--muted); margin: 0 0 .8em; }
.editor ul, .editor ol { margin: 0 0 .8em 1.4em; }
.editor mark { background: #5c4600; color: #ffe08a; border-radius: 3px; padding: 0 3px; }
.editor:empty::before { content: "Start writing, paste a script, or drop documents here…"; color: var(--muted); }
.editor-foot { display: flex; gap: 12px; padding: 6px 14px; border-top: 1px solid var(--line); color: var(--muted); font-size: 12px; background: var(--panel); }

.settings details { border-bottom: 1px solid var(--line); padding: 10px 0 14px; }
.settings summary { cursor: pointer; font-weight: 600; padding: 4px 0; list-style: none; display: flex; justify-content: space-between; }
.settings summary::after { content: "▾"; color: var(--muted); }
.settings details:not([open]) > summary::after { content: "▸"; }
.settings details.inner { border: 0; padding: 6px 0 0; }
.settings h4 { margin: 16px 0 4px; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.settings .hint { margin-top: 6px; }
.seg { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; }
.seg label { position: relative; text-align: center; padding: 6px 0; border: 1px solid var(--line); border-radius: 6px; cursor: pointer; font-size: 12.5px; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg label:has(input:checked) { border-color: var(--accent); color: var(--accent); }
.keys { display: grid; grid-template-columns: max-content 1fr; gap: 4px 12px; margin-top: 8px; font-size: 12.5px; }
.keys dt { font-family: ui-monospace, monospace; color: var(--accent); }
.keys dd { color: var(--muted); }

.camera-slot canvas { width: 100%; border-radius: 6px; margin-top: 12px; background: #000; display: block; }
.selfie { transform: scaleX(-1); }

.takes { list-style: none; display: flex; flex-direction: column; gap: 6px; margin-top: 6px; }
.takes li { display: grid; grid-template-columns: 1fr auto auto; gap: 2px 6px; align-items: center; padding: 6px 8px; background: var(--bg); border-radius: 6px; }
.takes li.empty { display: block; color: var(--muted); font-size: 12.5px; }
.take-name { color: var(--ink); text-decoration: none; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; grid-column: 1; }
.takes .script-meta { grid-column: 1; grid-row: 2; }
.takes .btn { grid-row: 1 / span 2; grid-column: 2; }
.takes .icon-btn { grid-row: 1 / span 2; grid-column: 3; }

/* ---------- dialogs, toast, drop ---------- */

dialog {
  background: var(--panel); color: var(--ink); border: 1px solid var(--line); border-radius: 12px;
  padding: 20px; width: min(520px, calc(100vw - 32px));
}
dialog::backdrop { background: rgba(0, 0, 0, .6); }
dialog h2 { font-size: 18px; margin-bottom: 8px; }
dialog menu { display: flex; gap: 8px; justify-content: flex-end; margin-top: 18px; }
.remote-grid { display: grid; grid-template-columns: 160px 1fr; gap: 16px; margin-top: 12px; align-items: start; }
.qr { background: #fff; border-radius: 8px; padding: 6px; aspect-ratio: 1; display: grid; place-items: center; color: #333; font-size: 12px; text-align: center; }
.qr svg { width: 100%; height: auto; display: block; }
.room { font-size: 13px; color: var(--muted); }
.room strong { color: var(--accent); font-size: 22px; letter-spacing: .08em; font-family: ui-monospace, monospace; margin-left: 6px; }
.screen-list { margin-top: 10px; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 100;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; padding: 10px 16px;
  box-shadow: 0 8px 30px rgba(0,0,0,.5); max-width: calc(100vw - 32px);
}
.toast.error { border-color: var(--danger); }
.drop-overlay {
  position: fixed; inset: 12px; z-index: 90; border: 3px dashed var(--accent); border-radius: 16px;
  background: rgba(14, 15, 18, .85); display: grid; place-items: center; font-size: 28px; font-weight: 700; color: var(--accent);
  pointer-events: none;
}

/* ---------- the prompter ---------- */

.prompter {
  position: relative; overflow: hidden; background: var(--pr-bg, #000); color: var(--pr-color, #fff);
  user-select: none; touch-action: none; height: 100%;
}
.pr-backdrop { position: absolute; inset: 0; opacity: var(--pr-cam-opacity, .4); }
.pr-backdrop canvas { width: 100%; height: 100%; object-fit: cover; display: block; }
.pr-stage { position: absolute; inset: 0; transform: var(--pr-transform, none); }
.pr-viewport { position: absolute; inset: 0; overflow: hidden; }
.pr-dim .pr-viewport {
  -webkit-mask-image: linear-gradient(to bottom, rgba(0,0,0,.25) 0, #000 calc(var(--pr-guide) - 8%), #000 calc(var(--pr-guide) + 30%), rgba(0,0,0,.35) 100%);
  mask-image: linear-gradient(to bottom, rgba(0,0,0,.25) 0, #000 calc(var(--pr-guide) - 8%), #000 calc(var(--pr-guide) + 30%), rgba(0,0,0,.35) 100%);
}
.pr-track { will-change: transform; }
.pr-content {
  padding: 0 var(--pr-margin, 8%);
  font-family: var(--pr-font); font-weight: var(--pr-weight, 500); font-size: var(--pr-size, 64px);
  line-height: var(--pr-line, 1.45); letter-spacing: var(--pr-letter, 0); text-align: var(--pr-align, left);
  overflow-wrap: break-word;
}
.pr-upper .pr-content { text-transform: uppercase; }
.pr-content > * { margin: 0 0 var(--pr-para, .9em); }
.pr-content h1 { font-size: 1.25em; }
.pr-content h2 { font-size: 1.12em; }
.pr-content h3 { font-size: 1.05em; }
.pr-content h1, .pr-content h2, .pr-content h3 { line-height: 1.2; }
.pr-content blockquote { opacity: .7; font-style: italic; }
.pr-content ul, .pr-content ol { padding-left: 1.2em; }
.pr-content mark { background: rgba(255, 204, 51, .25); color: inherit; border-radius: .12em; padding: 0 .12em; }
.pr-content hr { border: 0; border-top: 2px dashed currentColor; opacity: .3; }
.pr-empty { opacity: .5; }

.pr-guide { position: absolute; left: 0; right: 0; top: var(--pr-guide); height: 0; pointer-events: none; }
/* The line being read starts at the guide, so the band runs one line down from it. */
.pr-guide span {
  position: absolute; left: 0; right: 0; top: 0; height: calc(var(--pr-size) * var(--pr-line));
  border-top: 1px solid rgba(255, 204, 51, .25); border-bottom: 1px solid rgba(255, 204, 51, .25);
  background: rgba(255, 204, 51, .05);
}
.pr-guide::before, .pr-guide::after {
  content: ""; position: absolute; top: calc(var(--pr-size) * var(--pr-line) / 2 - 12px); border: 12px solid transparent;
}
.pr-guide::before { left: 0; border-left: 16px solid var(--accent); border-right-width: 0; }
.pr-guide::after { right: 0; border-right: 16px solid var(--accent); border-left-width: 0; }
.pr-noguide .pr-guide { display: none; }

.pr-countdown {
  position: absolute; inset: 0; display: grid; place-items: center; background: rgba(0,0,0,.55);
  font: 700 min(40vh, 40vw)/1 Inter, system-ui, sans-serif; color: var(--accent); z-index: 3;
}
.pr-countdown.pop { animation: pop .9s ease-out; }
@keyframes pop { 0% { transform: scale(1.4); opacity: 0; } 25% { opacity: 1; } 100% { transform: scale(.9); opacity: .9; } }

/* ---------- prompting view ---------- */

.prompt-view { position: fixed; inset: 0; z-index: 50; background: #000; }
.prompt-view.idle { cursor: none; }
.prompter-host { position: absolute; inset: 0; }
.rec-badge {
  position: absolute; top: 14px; right: 14px; z-index: 4; padding: 6px 12px; border-radius: 999px;
  background: rgba(255, 90, 95, .9); color: #fff; font-weight: 700; font-variant-numeric: tabular-nums;
  animation: blink 1.6s infinite;
}
@keyframes blink { 50% { opacity: .65; } }

.hud {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 5;
  background: linear-gradient(to top, rgba(0,0,0,.92), rgba(0,0,0,.6) 70%, transparent);
  padding: 22px 14px calc(12px + env(safe-area-inset-bottom));
  transition: opacity .3s, transform .3s;
}
.hud.hidden { opacity: 0; transform: translateY(20px); pointer-events: none; }
.progress { height: 6px; background: rgba(255,255,255,.15); border-radius: 3px; cursor: pointer; margin-bottom: 12px; }
.progress-fill { height: 100%; background: var(--accent); border-radius: 3px; width: 0; }
.hud-row { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; justify-content: center; }
.hud-btn {
  min-width: 44px; height: 44px; padding: 0 10px; border-radius: 10px;
  background: rgba(255,255,255,.08); border: 1px solid rgba(255,255,255,.12); color: #fff; font-size: 16px;
}
.hud-btn:hover { background: rgba(255,255,255,.16); }
.hud-btn.big { min-width: 64px; height: 52px; background: var(--accent); color: var(--accent-ink); font-size: 20px; border: 0; }
.hud-btn.on { border-color: var(--ok); color: var(--ok); }
.hud-btn.rec { color: var(--danger); }
.hud-btn.rec.on { background: var(--danger); color: #fff; }
.hud-group { display: inline-flex; align-items: center; gap: 4px; }
.hud-val { min-width: 40px; text-align: center; font-variant-numeric: tabular-nums; font-weight: 600; }
.hud-time { color: #c9cdd6; font-variant-numeric: tabular-nums; margin-left: 8px; font-size: 13px; }

/* ---------- display page ---------- */

.display-page { background: #000; overflow: hidden; }
.display-page.idle { cursor: none; }
.display-hint {
  position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); z-index: 10;
  background: rgba(20,20,24,.85); border: 1px solid var(--line); border-radius: 10px; padding: 8px 14px;
  display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 13px; color: var(--muted);
  transition: opacity .4s; pointer-events: none; text-align: center;
}
.display-hint strong { color: var(--ink); }
.display-hint.hidden { opacity: 0; }

/* ---------- remote page ---------- */

.remote-page { overscroll-behavior: none; }
.join { max-width: 380px; margin: 0 auto; padding: 48px 20px; display: flex; flex-direction: column; gap: 12px; }
.join input { font-size: 22px !important; letter-spacing: .1em; text-transform: uppercase; font-family: ui-monospace, monospace; }
.remote { max-width: 480px; margin: 0 auto; padding: 12px 16px calc(20px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 12px; }
.remote-head { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--muted); }
.dot.ok { background: var(--ok); }
.dot.wait { background: var(--accent); }
.dot.bad { background: var(--danger); }
.rec-pill { background: var(--danger); color: #fff; border-radius: 999px; padding: 2px 10px; font-weight: 700; font-size: 12px; }
.script-pick { width: 100%; padding: 10px; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; font-weight: 600; }
.remote-progress { height: 6px; background: var(--panel-2); border-radius: 3px; overflow: hidden; }
.remote-progress div { height: 100%; width: 0; background: var(--accent); }
.remote-time { display: flex; justify-content: space-between; color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.remote button { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; color: var(--ink); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; font-size: 20px; }
.remote button small { font-size: 11px; color: var(--muted); }
.remote button:active { transform: scale(.97); background: var(--panel-2); }
.remote button.on { border-color: var(--ok); color: var(--ok); }
.remote button.rec { color: var(--danger); }
.remote button.rec.on { background: var(--danger); color: #fff; }
.remote .remote-play { height: 120px; font-size: 44px; background: var(--accent); color: var(--accent-ink); border: 0; }
.remote .remote-play.on { background: var(--panel-2); color: var(--accent); border: 2px solid var(--accent); }
.remote-grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.remote-grid3 button { height: 72px; }
.remote-grid4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.remote-grid4 button { height: 64px; font-size: 18px; }
.remote-speed { display: grid; grid-template-columns: 72px 1fr 72px; gap: 10px; align-items: center; }
.remote-speed button { height: 64px; font-size: 30px; }
.remote-speed div { text-align: center; display: flex; flex-direction: column; }
.remote-speed strong { font-size: 30px; font-variant-numeric: tabular-nums; }
.remote-speed small { color: var(--muted); font-size: 11px; }
.jog {
  height: 110px; border: 1px dashed var(--line); border-radius: 14px; display: grid; place-items: center;
  color: var(--muted); touch-action: none; user-select: none;
  background: repeating-linear-gradient(to bottom, transparent 0 14px, rgba(255,255,255,.03) 14px 15px);
}
.jog.active { border-color: var(--accent); color: var(--accent); }

/* ---------- narrow screens ---------- */

.only-narrow { display: none; }

@media (max-width: 1100px) {
  .workspace { grid-template-columns: 230px minmax(0, 1fr); grid-template-rows: auto; }
  .settings { grid-column: 1 / -1; border-left: 0; border-top: 1px solid var(--line); }
  .workspace { height: auto; min-height: calc(100% - 56px); }
  .editor-pane { min-height: 70vh; }
}

@media (max-width: 760px) {
  .only-narrow { display: inline-flex; }
  .topbar { flex-wrap: wrap; height: auto; padding: 8px 12px; row-gap: 6px; }
  .topbar .brand, .topbar .spacer, .wide-only { display: none; }
  .topbar #start-prompt { margin-left: auto; }
  .title-input { order: 10; flex: 1 1 100%; }
  .sync-status { display: none; }
  .topbar .btn { padding: 4px 8px; font-size: 13px; }
  .workspace { display: block; }
  .library { position: fixed; z-index: 40; top: 0; bottom: 0; left: 0; width: min(320px, 86vw); transform: translateX(-100%); transition: transform .25s; box-shadow: 0 0 40px rgba(0,0,0,.6); }
  .show-library .library { transform: none; }
  .editor { padding: 18px 16px 60px; font-size: 18px; }
  .editor-pane { min-height: 60vh; }
  .remote-grid { grid-template-columns: 1fr; }
  .qr { max-width: 200px; }
  .hud-time { width: 100%; text-align: center; margin: 4px 0 0; }
}

@media (prefers-reduced-motion: reduce) {
  .pr-countdown.pop, .rec-badge { animation: none; }
}
