/* Teleprompter Dennis – mobile-first styles (dark default) */

:root {
  --bg: #0b0b0d;
  --surface: #17171c;
  --surface-2: #23232a;
  --border: #2e2e36;
  --text: #f3f3f6;
  --muted: #9b9ba6;
  --primary: #3d7cff;
  --primary-text: #ffffff;
  --danger: #ff3b30;
  --ok: #30d158;
  --warn: #ffd60a;
  --err: #ff6b61;
  --radius: 16px;
  --tap: 56px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  /* text box geometry, updated by app.js */
  --tp-top: 8px;
  --tp-height: 34dvh;
  color-scheme: dark;
}

:root[data-theme="light"] {
  --bg: #f4f4f7;
  --surface: #ffffff;
  --surface-2: #ececf1;
  --border: #d9d9e0;
  --text: #15151a;
  --muted: #62626d;
  --primary: #2563eb;
  --err: #d92d20;
  color-scheme: light;
}

*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 17px;
  line-height: 1.4;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}

html, body { overscroll-behavior: none; } /* no pull-to-refresh: all screens scroll internally */
body { min-height: 100dvh; overflow: hidden; }

[hidden] { display: none !important; }

button, select, input, textarea { font: inherit; color: inherit; }

button {
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.center { text-align: center; }
.noscript { padding: 24px; }

/* ---------- Screens ---------- */

.screen {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  height: 100dvh;
  overflow: hidden;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: calc(var(--safe-t) + 10px) calc(var(--safe-r) + 16px) 10px calc(var(--safe-l) + 16px);
  min-height: calc(var(--safe-t) + 60px);
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}
.topbar h1 { font-size: 1.3rem; margin: 0; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.icon-btn {
  min-width: var(--tap); min-height: var(--tap);
  margin-left: -12px;
  border: 0; background: transparent;
  font-size: 1.5rem; border-radius: 50%;
}
.icon-btn:active { background: var(--surface-2); }

.scroll-area {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 12px calc(var(--safe-r) + 16px) 16px calc(var(--safe-l) + 16px);
}

.bottombar {
  display: flex;
  gap: 12px;
  padding: 12px calc(var(--safe-r) + 16px) calc(var(--safe-b) + 12px) calc(var(--safe-l) + 16px);
  border-top: 1px solid var(--border);
  background: var(--bg);
}
.bottombar .btn { flex: 1; }

.banner {
  margin: 12px 16px 0;
  padding: 12px 14px;
  border-radius: 12px;
  background: rgba(255, 214, 10, 0.14);
  border: 1px solid rgba(255, 214, 10, 0.4);
  font-size: 0.92rem;
}

/* ---------- Buttons ---------- */

.btn {
  min-height: var(--tap);
  padding: 0 18px;
  border-radius: 14px;
  border: 1px solid transparent;
  font-weight: 600;
  font-size: 1rem;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  white-space: nowrap;
}
.btn:active { transform: scale(0.98); filter: brightness(1.1); }
.btn:disabled { opacity: 0.45; }
.btn-primary { background: var(--primary); color: var(--primary-text); }
.btn-secondary { background: var(--surface-2); border-color: var(--border); }
.btn-ghost { background: transparent; border-color: var(--border); color: var(--muted); }
.btn-danger { background: transparent; border-color: rgba(255, 59, 48, 0.5); color: var(--err); }
.btn.small { min-height: 44px; padding: 0 16px; font-size: 0.95rem; }
.btn.wide { width: 100%; }

/* ---------- Script cards ---------- */

.cards { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 12px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 14px 12px;
}
.card.active-script { border-color: var(--primary); }
.card h2 { margin: 0 0 2px; font-size: 1.1rem; overflow-wrap: anywhere; }
.card .meta { color: var(--muted); font-size: 0.88rem; margin-bottom: 12px; }
.card .preview { color: var(--muted); font-size: 0.9rem; margin: 0 0 12px;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.card-actions { display: grid; grid-template-columns: 1fr 1fr 1fr 56px; gap: 8px; }
.card-actions .btn { padding: 0 6px; font-size: 0.92rem; }
.card-actions .btn-rec { background: var(--danger); color: #fff; }

.empty { text-align: center; color: var(--muted); padding: 48px 16px; }

/* ---------- Editor ---------- */

.editor {
  flex: 1;
  display: flex; flex-direction: column; gap: 12px;
  padding: 12px calc(var(--safe-r) + 16px) 12px calc(var(--safe-l) + 16px);
  min-height: 0;
}
.field { display: flex; flex-direction: column; gap: 6px; }
.field > span { font-size: 0.85rem; color: var(--muted); }
.field.grow { flex: 1; min-height: 0; }
.field input, .field textarea {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 1.05rem;
}
.field input { min-height: var(--tap); }
.field textarea { flex: 1; min-height: 160px; resize: none; line-height: 1.5; }
.field input:focus, .field textarea:focus, select:focus { outline: 2px solid var(--primary); outline-offset: 1px; }

/* ---------- Settings ---------- */

.settings-stage {
  position: fixed; inset: 0;
  background:
    radial-gradient(120% 70% at 50% 20%, #3a3f4a 0%, #1c1f26 55%, #0b0c10 100%);
}
:root[data-theme="light"] .settings-stage {
  background: radial-gradient(120% 70% at 50% 20%, #c9ced8 0%, #9aa1ae 60%, #6c7380 100%);
}
.lens-dot {
  position: absolute; left: 50%; top: calc(var(--safe-t) + 2px);
  width: 12px; height: 12px; margin-left: -6px;
  border-radius: 50%; background: #000; box-shadow: 0 0 0 2px #333;
}

.settings-panel {
  position: fixed; left: 0; right: 0; bottom: 0;
  max-height: 58dvh;
  display: flex; flex-direction: column;
  background: var(--surface);
  border-top-left-radius: 22px; border-top-right-radius: 22px;
  box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.45);
  z-index: 5;
}
.panel-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px calc(var(--safe-r) + 16px) 8px calc(var(--safe-l) + 16px);
  border-bottom: 1px solid var(--border);
}
.panel-head h1 { font-size: 1.15rem; margin: 0; }
.panel-body {
  overflow-y: auto; overscroll-behavior: contain;
  padding: 8px calc(var(--safe-r) + 16px) calc(var(--safe-b) + 20px) calc(var(--safe-l) + 16px);
  display: flex; flex-direction: column; gap: 4px;
}
.panel-body > .btn { margin-top: 10px; }

.slider { padding: 8px 0; }
.slider-head { display: flex; justify-content: space-between; font-size: 0.95rem; margin-bottom: 2px; }
.slider-head .val { color: var(--muted); font-variant-numeric: tabular-nums; }
.slider input[type="range"] { width: 100%; height: 40px; accent-color: var(--primary); }

.row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  min-height: var(--tap);
  padding: 6px 0;
  border-top: 1px solid var(--border);
}
.row-label { display: flex; flex-direction: column; min-width: 0; }
.row-label small { color: var(--muted); font-size: 0.8rem; }
.row select {
  min-height: 48px; max-width: 55%;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 12px;
  padding: 0 12px;
}

.seg { display: inline-flex; background: var(--surface-2); border-radius: 12px; padding: 3px; border: 1px solid var(--border); }
.seg-btn { min-height: 44px; min-width: 76px; border: 0; background: transparent; border-radius: 10px; font-weight: 600; }
.seg-btn.on { background: var(--primary); color: #fff; }

.switch {
  appearance: none; -webkit-appearance: none;
  width: 56px; height: 34px; border-radius: 17px;
  background: var(--surface-2); border: 1px solid var(--border);
  position: relative; flex: none; cursor: pointer;
  transition: background 0.15s;
}
.switch::after {
  content: ""; position: absolute; top: 3px; left: 3px;
  width: 26px; height: 26px; border-radius: 50%; background: #fff;
  transition: transform 0.15s;
}
.switch:checked { background: var(--ok); }
.switch:checked::after { transform: translateX(22px); }

.info {
  margin-top: 8px;
  padding: 12px 14px;
  border-radius: 12px;
  background: var(--surface-2);
  font-size: 0.88rem; color: var(--muted);
}
.info b { color: var(--text); }

/* ---------- Text overlay box (prompter + settings preview) ---------- */

.tp-box {
  --tp-font: 30px;
  --tp-lh: 1.35;
  --tp-width: 92%;
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
  touch-action: pan-y;
  border-radius: 18px;
  font-size: var(--tp-font);
  line-height: var(--tp-lh);
  font-weight: 500;
  scrollbar-width: none;
  z-index: 3;
}
.tp-box::-webkit-scrollbar { display: none; }
.tp-box.fixed {
  position: fixed;
  top: calc(var(--safe-t) + var(--tp-top));
  left: 50%;
  transform: translateX(-50%);
  width: var(--tp-width);
  height: var(--tp-height);
}
.tp-box.dark { background: rgba(0, 0, 0, 0.6); color: rgba(255, 255, 255, 0.86); }
.tp-box.light { background: rgba(255, 255, 255, 0.7); color: rgba(0, 0, 0, 0.82); }

.tp-content {
  position: relative;
  padding: 0.25em 0.6em 0;
  overflow-wrap: break-word;
}
.tp-content.mirrored { transform: scaleX(-1); }
.tp-content p { margin: 0 0 0.6em; }
.tp-spacer { height: var(--tp-height); }

.tp-content .w { cursor: pointer; transition: color 0.2s, background-color 0.2s; border-radius: 0.18em; }
/* Read / recognised words: green. Unread: white (dark) or black (light). */
.tp-box.dark .w.done { color: #6fe38f; }
.tp-box.light .w.done { color: #137a35; }
/* Active line: faux bold via text-shadow so the line does not reflow */
.tp-box.dark .active { color: #ffffff; text-shadow: 0.025em 0 0 currentColor, -0.01em 0 0 currentColor; }
.tp-box.light .active { color: #000000; text-shadow: 0.025em 0 0 currentColor, -0.01em 0 0 currentColor; }
.tp-box.dark .active.done { color: #8dffad; }
.tp-box.light .active.done { color: #0f6a2c; }
/* Last recognised word: yellow marker */
.tp-box .w.cur {
  background: #ffd54a; color: #111 !important; text-shadow: none;
  box-shadow: 0 0 0 0.08em #ffd54a;
}
/* Lines already read further up: a bit calmer so the eye goes to the active line */
.tp-box.dark .w.done:not(.active) { opacity: 0.75; }
.tp-box.light .w.done:not(.active) { opacity: 0.8; }

/* ---------- Prompter screen ---------- */

#screen-prompter {
  background: #000;
  overscroll-behavior: none;
}

#cam {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  object-fit: cover;
  transform: scaleX(-1); /* selfie view only; the recording is not mirrored */
  background: #000;
}
.cam-off {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  color: #666; font-size: 1rem; padding-top: 30dvh;
}

.tp-status {
  position: fixed;
  top: calc(var(--safe-t) + var(--tp-top) + var(--tp-height) + 8px);
  right: calc(var(--safe-r) + 12px);
  left: calc(var(--safe-l) + 12px);
  display: flex; justify-content: flex-end; gap: 8px;
  pointer-events: none;
  z-index: 4;
}
.chip {
  padding: 6px 12px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.6);
  color: #fff;
  font-size: 0.85rem; font-weight: 600;
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  max-width: 70vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.chip.ok { color: #9ff0b5; }
.chip.warn { color: var(--warn); }
.chip.err { color: #ffb4ae; background: rgba(120, 0, 0, 0.6); }
.chip.rec { background: rgba(255, 59, 48, 0.9); font-variant-numeric: tabular-nums; }

.tp-controls {
  position: fixed; left: 0; right: 0; bottom: 0;
  max-height: 40dvh;
  padding: 10px calc(var(--safe-r) + 10px) calc(var(--safe-b) + 14px) calc(var(--safe-l) + 10px);
  background: linear-gradient(to top, rgba(0, 0, 0, 0.7) 0%, rgba(0, 0, 0, 0.35) 70%, rgba(0, 0, 0, 0) 100%);
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  user-select: none; -webkit-user-select: none;
  touch-action: manipulation;
  z-index: 4;
}

.tp-row2 { display: flex; align-items: center; justify-content: center; gap: 16px; width: 100%; max-width: 480px; }
.tp-speed { display: flex; align-items: center; gap: 12px; }
.tp-speed[hidden] { display: none; }
.speed-val {
  min-width: 108px; text-align: center; color: #fff; font-weight: 600;
  font-variant-numeric: tabular-nums;
  background: rgba(0, 0, 0, 0.5); border-radius: 999px; padding: 6px 12px;
}
.tp-speed .ctl { font-size: 1.6rem; }

.tp-level { width: min(240px, 60vw); height: 4px; border-radius: 2px; background: rgba(255, 255, 255, 0.2); overflow: hidden; }
#tp-level-bar { height: 100%; width: 0; background: var(--ok); transition: width 0.12s linear; }

.tp-main {
  width: 100%; max-width: 480px;
  display: flex; align-items: center; justify-content: space-between; gap: 6px;
}

.ctl {
  width: var(--tap); height: var(--tap); min-width: var(--tap);
  flex: none;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: rgba(30, 30, 36, 0.72);
  color: #fff;
  display: inline-flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 0; line-height: 1;
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
}
.ctl:active { background: rgba(80, 80, 90, 0.9); }
.ctl:disabled { opacity: 0.4; }
.ctl .ico { font-size: 1.2rem; }
.ctl .lbl { font-size: 0.6rem; margin-top: 3px; opacity: 0.85; }
.ctl.on { background: rgba(61, 124, 255, 0.85); border-color: transparent; }

.big {
  width: 84px; height: 84px; flex: none;
  border-radius: 50%;
  border: 4px solid #fff;
  background: transparent;
  padding: 0;
  display: inline-flex; align-items: center; justify-content: center;
}
.big .big-ico {
  width: 64px; height: 64px; border-radius: 50%;
  background: var(--danger);
  transition: all 0.18s ease;
}
.big.recording .big-ico { width: 34px; height: 34px; border-radius: 8px; }
.big:active .big-ico { filter: brightness(1.2); }
.big:disabled { opacity: 0.4; }
/* practice mode: play / pause */
.big.practice .big-ico {
  background: transparent; border-radius: 0;
  width: 0; height: 0;
  border-style: solid; border-width: 18px 0 18px 30px;
  border-color: transparent transparent transparent #fff;
  margin-left: 8px;
}
.big.practice.running .big-ico {
  width: 30px; height: 34px; margin-left: 0;
  border: 0;
  border-left: 10px solid #fff; border-right: 10px solid #fff;
  background: transparent;
}

.tp-hint { margin: 0; color: #ddd; font-size: 0.8rem; text-align: center; max-width: 420px; text-shadow: 0 1px 2px #000; }

.countdown {
  position: fixed; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  background: rgba(0, 0, 0, 0.35);
  color: #fff;
  z-index: 10;
  user-select: none; -webkit-user-select: none;
}
.countdown span { font-size: 9rem; font-weight: 800; line-height: 1; text-shadow: 0 4px 24px rgba(0, 0, 0, 0.6); }
.countdown small { margin-top: 12px; opacity: 0.8; }

/* ---------- Sheets ---------- */

.backdrop { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.5); z-index: 20; }

.sheet {
  position: fixed; left: 0; right: 0; bottom: 0;
  z-index: 21;
  background: var(--surface);
  color: var(--text);
  border-top-left-radius: 22px; border-top-right-radius: 22px;
  padding: 18px calc(var(--safe-r) + 16px) calc(var(--safe-b) + 18px) calc(var(--safe-l) + 16px);
  box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.5);
  animation: sheet-in 0.2s ease-out;
  max-width: 640px; margin: 0 auto;
}
.sheet h2 { margin: 0 0 4px; font-size: 1.2rem; overflow-wrap: anywhere; }
.sheet p { margin: 0 0 14px; }
.sheet-actions { display: flex; flex-direction: column; gap: 10px; }
@keyframes toast-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes sheet-in { from { transform: translateY(40px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---------- Toast ---------- */

.toast {
  position: fixed;
  left: calc(var(--safe-l) + 16px);
  right: calc(var(--safe-r) + 16px);
  margin: 0 auto;
  bottom: calc(var(--safe-b) + 42dvh);
  width: fit-content; max-width: 560px;
  padding: 12px 16px;
  border-radius: 14px;
  background: rgba(20, 20, 24, 0.94);
  color: #fff;
  font-size: 0.95rem;
  text-align: center;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.4);
  z-index: 40;
  animation: toast-in 0.18s ease-out;
}
body[data-screen="list"] .toast, body[data-screen="editor"] .toast { bottom: calc(var(--safe-b) + 96px); }

@media (min-width: 700px) {
  .scroll-area, .editor { max-width: 720px; width: 100%; margin: 0 auto; }
}

/* ---------- Landscape (phone held sideways) ----------
   Text box sits on the side of the front camera, the controls form a column
   on the opposite side so the thumb of the other hand reaches them. */
@media (orientation: landscape) and (max-height: 600px) {
  :root { --land-ctl-w: 216px; }
  body.landscape .tp-box.fixed {
    top: calc(var(--safe-t) + var(--tp-top));
    left: calc(var(--safe-l) + 10px);
    transform: none;
    width: calc(100% - var(--land-ctl-w) - var(--safe-l) - var(--safe-r) - 20px);
    height: min(calc(var(--tp-height) * 1.7), calc(100dvh - var(--tp-top) - var(--safe-t) - 44px));
  }
  body.landscape.lens-right .tp-box.fixed {
    left: auto;
    right: calc(var(--safe-r) + 10px);
  }
  body.landscape .tp-controls {
    top: 0; bottom: 0; left: auto; right: 0;
    width: calc(var(--land-ctl-w) + var(--safe-r));
    max-height: none;
    padding: calc(var(--safe-t) + 8px) calc(var(--safe-r) + 8px) calc(var(--safe-b) + 8px) 8px;
    justify-content: center;
    gap: 8px;
    background: linear-gradient(to left, rgba(0, 0, 0, 0.7) 0%, rgba(0, 0, 0, 0.35) 75%, rgba(0, 0, 0, 0) 100%);
  }
  body.landscape.lens-right .tp-controls {
    right: auto; left: 0;
    width: calc(var(--land-ctl-w) + var(--safe-l));
    padding: calc(var(--safe-t) + 8px) 8px calc(var(--safe-b) + 8px) calc(var(--safe-l) + 8px);
    background: linear-gradient(to right, rgba(0, 0, 0, 0.7) 0%, rgba(0, 0, 0, 0.35) 75%, rgba(0, 0, 0, 0) 100%);
  }
  body.landscape .tp-main {
    display: grid;
    grid-template-columns: repeat(3, var(--tap));
    justify-content: center;
    gap: 8px;
  }
  body.landscape .tp-main .big { grid-column: 1 / -1; justify-self: center; order: -1; }
  body.landscape .tp-main [hidden] { display: none; }
  body.landscape .tp-row2 { flex-direction: column; gap: 8px; }
  body.landscape .speed-val { min-width: 72px; padding: 6px 8px; font-size: 0.85rem; }
  body.landscape .tp-speed { gap: 6px; }
  body.landscape .tp-hint { font-size: 0.7rem; }
  /* status chips below the text box, on the text side */
  body.landscape .tp-status {
    top: auto; bottom: calc(var(--safe-b) + 10px);
    left: calc(var(--safe-l) + 12px); right: calc(var(--land-ctl-w) + var(--safe-r) + 12px);
    justify-content: flex-start;
  }
  body.landscape.lens-right .tp-status {
    left: calc(var(--land-ctl-w) + var(--safe-l) + 12px); right: calc(var(--safe-r) + 12px);
    justify-content: flex-end;
  }
  body.landscape .toast { bottom: calc(var(--safe-b) + 16px); }
  body.landscape .countdown span { font-size: 6rem; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
