/* Teleprompter JCP — mobile-first, dark, sober */
:root {
  --bg: #000;
  --surface: #101418;
  --surface-2: #1a2027;
  --text: #f2f5f7;
  --muted: #8b98a5;
  --accent: #22d3ee;
  --danger: #ef4444;
  --font-size: 32px;       /* prompter font size (JS-controlled) */
  --margin: 8%;            /* prompter side margin (JS-controlled) */
  --linepos: 45dvh;        /* reading line offset from top (JS-controlled, dvh) */
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, system-ui, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior: none;
}

.view { min-height: 100dvh; display: flex; flex-direction: column; }

/* ── App bar ── */
.appbar {
  display: flex; align-items: center; gap: 12px;
  padding: calc(10px + var(--safe-top)) 16px 10px;
  background: var(--surface);
  position: sticky; top: 0; z-index: 5;
}
.appbar h1, .appbar h2 { font-size: 18px; margin: 0; flex: 1; font-weight: 600; }
.accent { color: var(--accent); }

/* ── Buttons ── */
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; }
.icon-btn {
  min-width: 44px; min-height: 44px; border-radius: 10px;
  background: var(--surface-2); font-size: 17px;
}
.btn-primary {
  background: var(--accent); color: #00252b; font-weight: 700;
  border-radius: 12px; padding: 10px 18px; min-height: 44px;
}
.btn-big { width: 100%; font-size: 18px; padding: 16px; }
.btn-ghost {
  background: var(--surface-2); border-radius: 12px;
  padding: 10px 16px; min-height: 44px; color: var(--text);
}
.btn-ghost.small { padding: 8px 12px; font-size: 14px; }
.btn-danger { background: #2a1214; color: var(--danger); border-radius: 12px; padding: 12px; min-height: 44px; width: 100%; }

/* ── Library ── */
.content { padding: 16px; display: flex; flex-direction: column; gap: 14px; flex: 1; padding-bottom: calc(24px + var(--safe-bottom)); }
.script-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.script-list li {
  background: var(--surface); border-radius: 14px; padding: 14px;
  display: flex; align-items: center; gap: 10px;
}
.script-list .meta { flex: 1; min-width: 0; }
.script-list .meta .title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.script-list .meta .sub { color: var(--muted); font-size: 13px; margin-top: 2px; }
.script-list .play { background: var(--accent); color: #00252b; border-radius: 50%; width: 48px; height: 48px; font-size: 20px; flex: none; }
.empty-hint { color: var(--muted); text-align: center; margin-top: 40px; line-height: 1.6; }
.hint { color: var(--muted); font-size: 13px; line-height: 1.5; }
.stats { color: var(--muted); font-size: 14px; }

/* ── Editor ── */
#editor-title {
  background: var(--surface); border: 0; border-radius: 12px;
  color: var(--text); padding: 14px; font-size: 17px; width: 100%;
}
#editor-text {
  background: var(--surface); border: 0; border-radius: 12px;
  color: var(--text); padding: 14px; font-size: 16px; line-height: 1.6;
  width: 100%; min-height: 45dvh; resize: vertical;
}

/* ── Settings ── */
.settings-form label { display: flex; flex-direction: column; gap: 8px; font-size: 15px; }
.settings-form label.row { flex-direction: row; align-items: center; justify-content: space-between; }
.settings-form input[type="range"] { width: 100%; accent-color: var(--accent); }
.settings-form output { color: var(--accent); font-weight: 600; }

/* ── Prompter ── */
.prompter { position: fixed; inset: 0; background: var(--bg); overflow: hidden; touch-action: none; }
#cam-preview {
  position: absolute; inset: 0; width: 100%; height: 100%;
  object-fit: cover; transform: scaleX(-1); /* mirror selfie preview */
}
#prompter-dim { position: absolute; inset: 0; background: rgba(0,0,0,.45); pointer-events: none; }
.prompter.no-cam #prompter-dim { background: transparent; }

#prompter-scroll { position: absolute; inset: 0; overflow: hidden; }
#prompter-content {
  padding: 0 var(--margin);
  padding-top: var(--linepos);
  padding-bottom: 80dvh;
  will-change: transform;
}
#prompter-content p.sentence {
  font-size: var(--font-size); line-height: 1.45; font-weight: 600;
  margin: 0 0 .6em; color: rgba(242,245,247,.55);
  text-shadow: 0 1px 4px rgba(0,0,0,.8);
}
#prompter-content p.sentence.active { color: var(--text); }
#prompter-content p.sentence.done { color: rgba(242,245,247,.28); }
#prompter-content span.w.heard { color: var(--accent); }

#reading-line {
  position: absolute; left: 8px; top: var(--linepos); width: 14px; height: 3px;
  background: var(--accent); border-radius: 2px; pointer-events: none; opacity: .9;
}

#prompter-topbar {
  position: absolute; top: 0; left: 0; right: 0; z-index: 6;
  display: flex; align-items: center; gap: 8px;
  padding: calc(8px + var(--safe-top)) 10px 8px;
}
#prompter-topbar .grp { display: flex; gap: 6px; align-items: center; }
#prompter-topbar .icon-btn { background: rgba(26,32,39,.8); }
.pill {
  background: rgba(26,32,39,.85); border-radius: 999px; padding: 6px 12px;
  font-size: 13px; color: var(--muted); white-space: nowrap;
}
.pill.ok { color: var(--accent); }
.pill.warn { color: #fbbf24; }
.pill.rec { color: var(--danger); font-weight: 700; }

#tap-layer { position: absolute; inset: 0; z-index: 4; }

#prompter-bottombar {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 6;
  display: flex; flex-direction: column; gap: 10px; align-items: center;
  padding: 10px 14px calc(14px + var(--safe-bottom));
  background: linear-gradient(transparent, rgba(0,0,0,.75));
}
.mode-chips { display: flex; gap: 8px; }
.chip {
  border-radius: 999px; padding: 8px 16px; min-height: 40px;
  background: rgba(26,32,39,.85); color: var(--muted); font-size: 13px; font-weight: 700;
}
.chip.selected { background: var(--accent); color: #00252b; }
.chip[disabled] { opacity: .4; }
.actions { display: flex; align-items: center; gap: 14px; }
.btn-rec {
  width: 64px; height: 64px; border-radius: 50%;
  background: var(--danger); color: #fff; font-size: 26px;
  border: 4px solid rgba(255,255,255,.85);
}
.btn-rec.recording { background: #7f1d1d; animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 10px rgba(239,68,68,.25); } }

/* ── Overlays ── */
.overlay {
  position: absolute; inset: 0; z-index: 20;
  display: flex; align-items: center; justify-content: center;
  background: rgba(0,0,0,.75);
}
#countdown-num { font-size: 120px; font-weight: 800; color: var(--accent); }
.card-overlay .card {
  background: var(--surface); border-radius: 18px; padding: 22px;
  max-width: 340px; margin: 20px; display: flex; flex-direction: column; gap: 12px;
}
.card h3 { margin: 0; }
.card ol { margin: 0; padding-left: 20px; line-height: 1.6; font-size: 15px; }

.overlay.guide { background: rgba(0,0,0,.35); flex-direction: column; justify-content: space-between; padding: 0; }
.lens-dot {
  margin-top: calc(10px + var(--safe-top));
  background: rgba(16,20,24,.9); border: 2px dashed var(--accent);
  border-radius: 999px; padding: 10px 16px; font-size: 14px;
}
.safe-zone {
  width: 100%; height: 33dvh; border-top: 2px dashed var(--danger);
  background: rgba(239,68,68,.12); color: #fca5a5;
  display: flex; align-items: flex-start; justify-content: center;
  padding-top: 8px; font-size: 13px;
}
.overlay.guide .btn-primary { position: absolute; bottom: calc(20px + var(--safe-bottom)); left: 50%; transform: translateX(-50%); }

/* ── Takes ── */
.take-actions { display: flex; gap: 8px; flex: none; }
.take-actions button { min-width: 44px; min-height: 44px; border-radius: 10px; background: var(--surface-2); }

/* ── Toast ── */
#toast {
  position: fixed; bottom: calc(24px + var(--safe-bottom)); left: 50%; transform: translateX(-50%);
  background: var(--surface-2); color: var(--text); border-radius: 12px;
  padding: 12px 18px; z-index: 50; font-size: 14px; max-width: 86vw; text-align: center;
}

/* Desktop: keep it phone-shaped */
@media (min-width: 700px) {
  body:not(:has(.prompter:not([hidden]))) .view { max-width: 430px; margin: 0 auto; border-left: 1px solid #1c232b; border-right: 1px solid #1c232b; }
}
