/* ============ Prompta — styles ============
   App chrome is always dark ("studio booth" feel).
   Prompter themes are [data-ptheme] overrides scoped to the overlay. */

:root {
  --bg: #0E0E13;
  --bg-raised: #17171F;
  --line: #26262F;
  --text: #F0EFF4;
  --text-dim: #9C9AA8;
  --accent: #7C5CFF;
  --accent-soft: #2A2140;
  --danger: #FF5C7A;

  /* prompter theme tokens (studio defaults) */
  --p-bg: #0B0B0F;
  --p-text: #F2F1F6;
  --p-read: #56546A;
  --p-guide: #7C5CFF;
  --p-font: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --p-weight: 600;
  --p-glow: none;
  --p-live-bg: rgba(124, 92, 255, .18);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
body { min-height: 100dvh; }

/* ---------- top bar ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px clamp(16px, 4vw, 32px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark { width: 30px; height: 30px; border-radius: 8px; }
.brand-name { font-size: 1.15rem; font-weight: 700; letter-spacing: .01em; }

/* ---------- buttons ---------- */
.btn {
  font: inherit; cursor: pointer; border: 1px solid var(--line);
  background: var(--bg-raised); color: var(--text);
  padding: 10px 16px; border-radius: 10px;
  transition: background .15s ease, border-color .15s ease;
  touch-action: manipulation;
}
.btn:hover { border-color: var(--accent); }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn-primary:hover { filter: brightness(1.1); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--text-dim); }
.btn-ghost:hover { color: var(--text); border-color: transparent; }

/* ---------- views ---------- */
.view { padding: clamp(16px, 4vw, 32px); max-width: 900px; margin: 0 auto; }
.view-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  margin-bottom: 20px; flex-wrap: wrap;
}
.view-head h1 { font-size: 1.5rem; margin: 0; }

/* library */
.script-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 14px; }
.script-card {
  text-align: left; font: inherit; color: var(--text); cursor: pointer;
  background: var(--bg-raised); border: 1px solid var(--line); border-radius: 14px;
  padding: 16px; display: flex; flex-direction: column; gap: 8px;
  transition: border-color .15s ease, transform .15s ease;
}
.script-card:hover { border-color: var(--accent); transform: translateY(-2px); }
.script-card h3 { margin: 0; font-size: 1.05rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.script-card p { margin: 0; color: var(--text-dim); font-size: .85rem;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.script-card .card-meta { color: var(--text-dim); font-size: .75rem; margin-top: auto; }
.card-actions { display: flex; gap: 8px; }
.card-actions .btn { padding: 6px 10px; font-size: .8rem; }
.empty-note { color: var(--text-dim); text-align: center; margin-top: 48px; }

/* editor */
.editor-title {
  width: 100%; font: inherit; font-size: 1.3rem; font-weight: 700;
  background: transparent; border: none; border-bottom: 1px solid var(--line);
  color: var(--text); padding: 10px 2px; margin-bottom: 14px;
}
.editor-title:focus { outline: none; border-bottom-color: var(--accent); }
.editor-body {
  width: 100%; min-height: 50dvh; resize: vertical;
  font: inherit; font-size: 1.05rem; line-height: 1.7;
  background: var(--bg-raised); color: var(--text);
  border: 1px solid var(--line); border-radius: 14px; padding: 16px;
}
.editor-body:focus { outline: none; border-color: var(--accent); }
.editor-meta { color: var(--text-dim); font-size: .85rem; }

/* help */
.help-copy { line-height: 1.7; color: var(--text); max-width: 65ch; }
.help-copy h2 { font-size: 1.05rem; margin: 24px 0 6px; color: var(--accent); }
.help-copy p { margin: 0 0 10px; color: var(--text-dim); }
.help-copy strong { color: var(--text); }

/* ---------- prompter overlay ---------- */
.prompter {
  position: fixed; inset: 0; z-index: 50;
  background: var(--p-bg); color: var(--p-text);
  display: flex; flex-direction: column;
  font-family: var(--p-font);
}

.matrix-rain { position: absolute; inset: 0; pointer-events: none; opacity: 0; }
.prompter[data-ptheme="matrix"] .matrix-rain { opacity: .28; }

.prompter-top {
  position: relative; z-index: 3;
  display: flex; align-items: center; gap: 12px;
  padding: max(10px, env(safe-area-inset-top)) 14px 10px;
}
.prompter-top .btn-ghost { color: var(--p-text); opacity: .6; }
.prompter-top .btn-ghost:hover { opacity: 1; }
.prompter-progress { flex: 1; height: 4px; border-radius: 2px; background: rgba(128,128,128,.25); overflow: hidden; }
.prompter-progress-fill { height: 100%; width: 0%; background: var(--p-guide); transition: width .3s linear; }
.prompter-clock { font-variant-numeric: tabular-nums; opacity: .7; font-size: .9rem; }

.prompter-scroll {
  position: relative; z-index: 2; flex: 1;
  overflow-y: auto; overscroll-behavior: contain;
  scrollbar-width: none;
}
.prompter-scroll::-webkit-scrollbar { display: none; }

.prompter-text {
  padding: 45dvh clamp(16px, var(--p-margin, 6vw), 20vw) 60dvh;
  font-size: var(--p-fontsize, 42px);
  font-weight: var(--p-weight);
  line-height: 1.55;
  text-shadow: var(--p-glow);
}
.prompter-text p { margin: 0 0 1.2em; }

/* sentence spotlight — three layers of focus, voice mode only:
   past = read and released · live = being spoken · rest = readable ahead */
.prompter-text .s {
  border-radius: .25em;
  padding: .04em .12em;
  margin: 0 -.12em;
  transition: opacity .18s ease-out, background-color .18s ease-out, color .18s ease-out;
  -webkit-box-decoration-break: clone;
  box-decoration-break: clone;
}
.prompter[data-mode="voice"] .prompter-text .s { opacity: .78; }
.prompter[data-mode="voice"] .prompter-text .s.past { opacity: .32; }
.prompter[data-mode="voice"] .prompter-text .s.live {
  opacity: 1;
  background-color: var(--p-live-bg);
  color: var(--p-live-fg, inherit);
  text-shadow: var(--p-live-glow, var(--p-glow));
}
.prompter.mirrored .prompter-scroll { transform: scaleX(-1); }

.guide-line {
  position: absolute; z-index: 1; left: 0; right: 0; top: 38dvh; height: 0;
  border-top: 2px solid var(--p-guide); opacity: .28; pointer-events: none;
}

.prompter-countdown {
  position: absolute; inset: 0; z-index: 6;
  display: flex; align-items: center; justify-content: center;
  background: var(--p-bg);
}
.prompter-countdown span { font-size: 20vmin; font-weight: 800; color: var(--p-guide); }

.prompter-paused, .voice-status {
  position: absolute; z-index: 4; left: 50%; transform: translateX(-50%);
  background: rgba(0,0,0,.65); color: #fff; backdrop-filter: blur(6px);
  padding: 8px 18px; border-radius: 999px; font-size: .9rem; white-space: nowrap;
}
.prompter-paused { top: 16dvh; }
.voice-status { bottom: 110px; }

.prompter-bottom {
  position: relative; z-index: 3;
  display: flex; align-items: center; justify-content: center; gap: 14px;
  padding: 10px 14px max(14px, env(safe-area-inset-bottom));
  flex-wrap: wrap;
}
.mode-seg { display: flex; border: 1px solid rgba(128,128,128,.35); border-radius: 999px; overflow: hidden; }
.seg {
  font: inherit; font-size: .85rem; cursor: pointer;
  background: transparent; color: var(--p-text); opacity: .55;
  border: none; padding: 8px 16px;
}
.seg.active { opacity: 1; background: var(--p-guide); color: var(--p-bg); font-weight: 700; }
.btn-play {
  font: inherit; font-size: 1.3rem; cursor: pointer;
  width: 58px; height: 58px; border-radius: 50%;
  border: none; background: var(--p-guide); color: var(--p-bg);
  display: flex; align-items: center; justify-content: center;
}
.speed-ctl { display: flex; align-items: center; gap: 4px; }
.speed-ctl .btn { color: var(--p-text); font-size: 1.1rem; padding: 8px 12px; }
.speed-val { min-width: 2ch; text-align: center; font-variant-numeric: tabular-nums; opacity: .8; }
.prompter-bottom .btn-ghost { color: var(--p-text); font-size: 1.2rem; }

/* controls fade while playing */
.prompter.playing .prompter-top,
.prompter.playing .prompter-bottom { opacity: 0; pointer-events: none; transition: opacity .4s ease .8s; }
.prompter .prompter-top, .prompter .prompter-bottom { transition: opacity .25s ease; }

/* ---------- settings sheet ---------- */
.sheet {
  position: absolute; inset: 0; z-index: 7;
  background: rgba(0,0,0,.5); display: flex; align-items: flex-end;
}
.sheet-inner {
  width: 100%; max-height: 75dvh; overflow-y: auto;
  background: var(--bg-raised); color: var(--text);
  border-radius: 20px 20px 0 0; padding: 18px 20px max(20px, env(safe-area-inset-bottom));
}
.sheet-head { display: flex; align-items: center; justify-content: space-between; }
.sheet-head h2, .sheet-subhead { font-size: 1rem; margin: 0; }
.sheet-subhead { margin: 20px 0 10px; }
.sheet-row {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 12px 0; border-bottom: 1px solid var(--line);
}
.sheet-row span small { color: var(--text-dim); }
.sheet-row input[type="range"] { flex: 1; max-width: 55%; accent-color: var(--accent); }
.sheet-row input[type="checkbox"] { width: 22px; height: 22px; accent-color: var(--accent); }

.theme-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.theme-chip {
  font: inherit; font-size: .8rem; cursor: pointer; color: var(--text);
  background: transparent; border: 1px solid var(--line); border-radius: 12px;
  padding: 10px; display: flex; flex-direction: column; align-items: center; gap: 8px;
}
.theme-chip.active { border-color: var(--accent); background: var(--accent-soft); }
.chip-preview {
  width: 100%; border-radius: 8px; padding: 10px 0; text-align: center;
  font-size: 1.1rem; font-weight: 700;
}
.chip-studio    { background: #0B0B0F; color: #F2F1F6; }
.chip-broadcast { background: #04203C; color: #EAF4FF; }
.chip-matrix    { background: #000; color: #22FF66; font-family: "Courier New", monospace; }
.chip-noir      { background: #0A0908; color: #F4E9D4; font-family: Georgia, serif; }
.chip-synthwave { background: linear-gradient(160deg, #170032, #34005B); color: #FFB3EC; }
.chip-contrast  { background: #000; color: #FFE600; }

/* ---------- prompter themes ---------- */
.prompter[data-ptheme="broadcast"] {
  --p-bg: #04203C; --p-text: #EAF4FF; --p-read: #3E5F7E; --p-guide: #4FC3F7;
  --p-weight: 700;
  --p-live-bg: rgba(79, 195, 247, .16);
}
.prompter[data-ptheme="matrix"] {
  --p-bg: #000; --p-text: #22FF66; --p-read: #0C5A26; --p-guide: #A8FFC4;
  --p-font: "Courier New", ui-monospace, monospace; --p-weight: 700;
  --p-glow: 0 0 12px rgba(34,255,102,.45);
  --p-live-bg: rgba(34, 255, 102, .12);
  --p-live-glow: 0 0 18px rgba(34, 255, 102, .65);
}
.prompter[data-ptheme="noir"] {
  --p-bg: #0A0908; --p-text: #F4E9D4; --p-read: #6B6152; --p-guide: #C9A24B;
  --p-font: Georgia, "Times New Roman", serif; --p-weight: 500;
  --p-live-bg: rgba(201, 162, 75, .15);
}
.prompter[data-ptheme="synthwave"] {
  --p-bg: #170032; --p-text: #FFD9F5; --p-read: #6B3E7E; --p-guide: #FF7EDB;
  --p-weight: 700; --p-glow: 0 0 14px rgba(255,126,219,.5);
  --p-live-bg: rgba(255, 126, 219, .16);
  --p-live-glow: 0 0 18px rgba(255, 126, 219, .65);
}
.prompter[data-ptheme="contrast"] {
  --p-bg: #000; --p-text: #FFE600; --p-read: #5C5300; --p-guide: #FFF;
  --p-weight: 800;
  --p-live-bg: #FFE600;
  --p-live-fg: #000;
  --p-live-glow: none;
}

/* ---------- toast ---------- */
.toast {
  position: fixed; z-index: 90; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--bg-raised); border: 1px solid var(--line); color: var(--text);
  padding: 10px 20px; border-radius: 999px; font-size: .9rem;
  box-shadow: 0 8px 30px rgba(0,0,0,.5); white-space: nowrap;
}

/* phone-landscape: short screens starve the reader of upcoming lines —
   ride the current line higher and cap text height so the next words
   are always on screen. (Guide top matches anchorFrac() in prompter.js.) */
@media (orientation: landscape) and (max-height: 500px) {
  .guide-line { top: 26dvh; }
  .prompter-text {
    padding-top: 30dvh;
    padding-bottom: 70dvh;
    font-size: min(var(--p-fontsize, 42px), 8.5vh);
  }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
  .prompter[data-ptheme="matrix"] .matrix-rain { display: none; }
}
