/* app.css — styles for index.html (the rehearsal app) */

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg); color: var(--text);
  font-family: var(--font-sans); min-height: 100vh; line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--cta); text-decoration: none; }
a:hover { text-decoration: underline; }

.layout {
  display: grid;
  grid-template-columns: 280px 1fr;
  min-height: 100vh;
}

/* Sidebar */
.sidebar {
  background: var(--bg-elev); border-right: 1px solid var(--border);
  padding: 24px 20px; overflow-y: auto;
}
/* The mobile-only "Scripts" drawer affordances are hidden on desktop, where
   the sidebar is a permanent column. They're switched on in the ≤720px
   media query below. */
.scripts-menu-btn,
.sidebar-close { display: none; }
.sidebar-backdrop { display: none; }
.sidebar h2 {
  font-family: var(--font-serif); font-size: 18px; font-weight: 500;
  margin: 0 0 16px;
}
.lib-item {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: 3px; padding: 12px 14px; margin-bottom: 8px;
  cursor: pointer; transition: border-color 0.15s;
  position: relative;
}
.lib-item:hover { border-color: var(--accent); }
.lib-item.selected {
  border-color: var(--accent);
  background: var(--accent-dim);
  /* left accent bar so the current script reads at a glance */
  box-shadow: inset 3px 0 0 0 var(--accent);
}
.lib-item.selected .lib-title { color: var(--accent); }
.lib-item .lib-title {
  font-family: var(--font-serif); font-weight: 500; font-size: 14px;
  margin-bottom: 4px;
}
.lib-item .lib-meta {
  font-size: 11px; color: var(--text-muted);
  font-family: var(--font-mono);
}
.lib-item .lib-delete {
  position: absolute; top: 8px; right: 8px;
  background: none; border: none; color: var(--text-muted);
  cursor: pointer; font-size: 14px; padding: 2px 6px;
  border-radius: 2px;
}
.lib-item .lib-delete:hover { color: var(--danger); background: rgba(214, 125, 111, 0.1); }
.lib-empty {
  color: var(--text-muted); font-size: 13px;
  padding: 12px 0; text-align: center;
}
.lib-count {
  font-size: 11px; color: var(--text-muted);
  font-family: var(--font-mono); margin-top: 12px;
}

/* Pre-parsed starter scripts — rendered below the user's saved list. */
.preset-lib {
  margin-top: 20px; padding-top: 16px;
  border-top: 1px solid var(--border);
}
.preset-lib-head {
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--text-muted); font-family: var(--font-mono);
  margin-bottom: 10px;
}
/* Starters share .lib-item styling but never show a delete button. */
.lib-item.preset-item .lib-meta { font-style: italic; }

/* Settings — gear button pinned below the scripts, and its modal fields. */
.settings-btn {
  display: flex; align-items: center; gap: 8px;
  width: 100%; justify-content: center;
  margin-top: 20px; padding: 9px 12px;
  font-size: 13px;
}
.settings-btn .gear { font-size: 15px; line-height: 1; }
.settings-field { margin-bottom: 20px; }
.settings-field label {
  display: block; font-size: 13px; font-weight: 500; margin-bottom: 2px;
}
.settings-field .settings-hint {
  font-size: 12px; color: var(--text-muted); margin: 0 0 8px;
}
.settings-field select { width: 100%; }

/* Main column */
.main { padding: 32px 40px 120px; max-width: 900px; }
header.app-head {
  display: flex; align-items: baseline; justify-content: space-between;
  border-bottom: 1px solid var(--border);
  padding-bottom: 16px; margin-bottom: 28px;
}
header.app-head h1 {
  margin: 0; font-family: var(--font-serif); font-weight: 500;
  font-size: 24px; letter-spacing: 0.01em;
}
header.app-head h1 .accent { color: var(--accent); }
.head-right {
  display: flex; align-items: center; gap: 16px;
  font-size: 13px; color: var(--text-muted);
}
.head-right a { color: var(--text-muted); }
.head-right a:hover { color: var(--text); }

/* Profile link + Sign out button share this class so they render at
   identical height. Matching padding alone isn't enough: <a> inherits the
   body's line-height while a bare <button> falls back to the browser's
   own UA line-height, so the two drift apart by a few px unless height is
   pinned explicitly here (same fix as the voice-picker/sample buttons). */
.head-right .head-action {
  display: inline-flex; align-items: center; justify-content: center;
  height: 30px; box-sizing: border-box;
  font-family: var(--font-sans); font-size: 12px; line-height: 1;
  padding: 0 12px; border-radius: 3px;
  border: 1px solid var(--border-strong);
  background: transparent; color: var(--text-muted);
  letter-spacing: 0.02em; transition: all 0.15s ease; cursor: pointer;
}
.head-right .head-action:hover {
  background: var(--bg-elev); border-color: var(--accent); color: var(--text);
}

h2 {
  font-family: var(--font-serif); font-weight: 500;
  font-size: 18px; margin: 0 0 12px;
}

/* Loaded-script title, shown at the top of the parts card above "Pick your
   part", with the turn/character counts to its right (see .script-title-row
   below). Larger and serif so the selected script reads as the heading. */
.script-title {
  font-family: var(--font-serif); font-weight: 500;
  font-size: 24px; color: var(--text); margin: 0;
}
/* Wrapper for the title + counts pair. The divider (border/padding/margin)
   lives here rather than on .script-title itself, since that h2 is hidden
   for unsaved scripts (renderScriptTitle) — keeping the divider on the
   always-present wrapper means the counts still get a clean baseline to
   sit on even before a script has a title. Wraps to its own line below the
   title on narrow screens; margin-left: auto on the counts (inline in
   index.html) keeps them right-justified whether or not that happens. */
.script-title-row {
  display: flex; align-items: baseline; justify-content: space-between;
  flex-wrap: wrap; gap: 4px 16px;
  padding-bottom: 12px; margin-bottom: 12px;
  border-bottom: 1px solid var(--border);
}

.card {
  background: var(--bg-elev); border: 1px solid var(--border);
  border-radius: 4px; padding: 20px; margin-bottom: 16px;
}
.hidden { display: none !important; }

/* Buttons — scoped away from Clerk's cl-* elements */
button:not([class*="cl-"]) {
  font-family: var(--font-sans); font-size: 14px;
  padding: 10px 18px; border-radius: 3px;
  border: 1px solid var(--border-strong);
  background: var(--bg-card); color: var(--text);
  cursor: pointer; transition: all 0.15s ease;
  letter-spacing: 0.02em;
}
button:not([class*="cl-"]):hover:not(:disabled) {
  background: var(--bg-elev); border-color: var(--accent);
}
button:not([class*="cl-"]):disabled { opacity: 0.4; cursor: not-allowed; }
button.primary {
  background: var(--cta); color: var(--cta-text);
  border-color: var(--cta); font-weight: 600;
}
button.primary:hover:not(:disabled) { background: var(--cta-hover); border-color: var(--cta-hover); opacity: 1; }
button.danger { color: var(--danger); border-color: rgba(214, 125, 111, 0.4); }
button.danger:hover:not(:disabled) { background: rgba(214, 125, 111, 0.1); }
button.ghost { background: transparent; }

/* Inputs */
textarea:not([class*="cl-"]),
select:not([class*="cl-"]),
input[type=text]:not([class*="cl-"]) {
  font-family: var(--font-mono); font-size: 13px; line-height: 1.6;
  background: var(--bg); color: var(--text);
  border: 1px solid var(--border-strong); border-radius: 3px;
  padding: 10px 12px; width: 100%;
}
textarea:not([class*="cl-"]):focus,
select:not([class*="cl-"]):focus,
input:not([class*="cl-"]):focus {
  outline: none; border-color: var(--accent);
}
textarea:not([class*="cl-"]) { min-height: 240px; resize: vertical; }
label:not([class*="cl-"]) {
  display: block; font-size: 12px; color: var(--text-muted);
  margin-bottom: 6px; letter-spacing: 0.08em; text-transform: uppercase;
}

/* Setup */
.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; }

/* Per-script AI voice picker — a custom listbox (button + popover), not a
   native <select>, so voice rows can carry a descriptor + speaker-preview
   button (see settings.js). Capped to ~1/3 of the row so it doesn't dwarf
   its "AI voice" label. */
.voice-picker { position: relative; width: 33%; min-width: 160px; flex: 0 1 33%; }
/* Explicit height (not just padding) — <button> line-height defaults vary
   by browser, so pinning both this and .voice-sample-btn to the same
   height/box-sizing is what actually keeps them lined up, not matching
   padding alone. */
.voice-picker-btn {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  width: 100%; height: 38px; box-sizing: border-box;
  font-family: var(--font-mono); font-size: 13px; line-height: 1;
  background: var(--bg); color: var(--text);
  border: 1px solid var(--border-strong); border-radius: 3px;
  padding: 0 12px; cursor: pointer; text-align: left;
}
.voice-picker-btn:hover { border-color: var(--accent); }
.voice-picker-btn span:first-child {
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.voice-picker-caret { color: var(--text-muted); font-size: 11px; flex-shrink: 0; }
.voice-picker-list {
  position: absolute; top: calc(100% + 4px); left: 0; right: 0; z-index: 20;
  max-height: 280px; overflow-y: auto;
  background: var(--bg-card); border: 1px solid var(--border-strong);
  border-radius: 3px; box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
}
.voice-option {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 8px 10px; font-size: 13px; cursor: pointer;
}
.voice-option:hover { background: var(--bg-elev); }
.voice-option.selected { background: var(--accent-dim); color: var(--accent); }
.voice-option-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* Standalone speaker-preview button, to the RIGHT of the voice dropdown
   (not inside it) — pick a voice from the list, then press this to hear a
   sample of whatever's currently selected. Square, and pinned to the same
   38px height as .voice-picker-btn so the pair reads as one control.
   Disabled (see settings.js updateSampleButton) when the selection has no
   known sample, e.g. Auto, Random, or a non-OpenAI voice. */
.voice-sample-btn {
  flex-shrink: 0; cursor: pointer;
  width: 38px; height: 38px; box-sizing: border-box;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; line-height: 1; padding: 0; border-radius: 3px;
  background: var(--bg); color: var(--text);
  border: 1px solid var(--border-strong);
}
.voice-sample-btn:hover:not(:disabled) { border-color: var(--accent); background: var(--accent-dim); }
.voice-sample-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.parts-list { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.part-chip {
  padding: 6px 14px; border: 1px solid var(--border-strong);
  border-radius: 999px; background: var(--bg-card); cursor: pointer;
  font-size: 13px;
}
.part-chip:hover { border-color: var(--accent); }
.part-chip.selected {
  background: var(--accent); color: #1a1208;
  border-color: var(--accent); font-weight: 600;
}
.meta-row {
  display: flex; gap: 24px; margin-top: 12px; flex-wrap: wrap;
  color: var(--text-muted); font-size: 13px;
}
.meta-row strong { color: var(--text); font-weight: 500; }

/* Running */
.running-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 20px;
}
.run-controls { display: flex; gap: 8px; flex-wrap: wrap; }
.run-controls button { padding: 6px 14px; font-size: 12px; }

/* Skip-to-line picker */
.jump-list { display: flex; flex-direction: column; gap: 4px; }
.jump-row {
  display: flex; gap: 10px; align-items: baseline; width: 100%;
  padding: 8px 10px; text-align: left; cursor: pointer;
  border: 1px solid var(--border-strong); border-radius: 4px;
  background: var(--bg-card); color: var(--text); font-size: 13px;
}
.jump-row:hover { border-color: var(--accent); background: var(--bg-elev); }
.jump-row.current { border-color: var(--accent); background: var(--accent-dim); }
.jump-row .jr-num { font-family: var(--font-mono); color: var(--text-muted); min-width: 28px; flex: 0 0 auto; }
.jump-row .jr-char { font-weight: 600; min-width: 90px; flex: 0 0 auto; }
.jump-row.mine .jr-char { color: var(--accent); }
.jump-row .jr-text { color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.speaker-tag {
  font-family: var(--font-mono); font-size: 11px;
  text-transform: uppercase; letter-spacing: 0.15em;
  padding: 4px 10px; border-radius: 2px;
}
.speaker-tag.ai { background: var(--bg-card); color: var(--info); border: 1px solid rgba(127, 183, 201, 0.3); }
.speaker-tag.me { background: var(--accent-dim); color: var(--accent); border: 1px solid var(--accent); }

.line {
  font-family: var(--font-serif); font-size: 22px; line-height: 1.5;
  padding: 24px 28px; background: var(--bg-card);
  border-left: 3px solid var(--border); border-radius: 3px;
  margin-bottom: 16px; min-height: 80px;
}
.line.me { border-left-color: var(--accent); }
.line.ai { border-left-color: var(--info); }
.line .char-name {
  display: block; font-family: var(--font-sans); font-size: 11px;
  text-transform: uppercase; letter-spacing: 0.12em;
  color: var(--text-muted); margin-bottom: 10px; font-weight: 600;
}

.mic-status {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 16px; background: var(--bg-card);
  border-radius: 3px; margin-bottom: 12px;
  font-size: 13px; color: var(--text-muted);
  font-family: var(--font-mono);
}
.mic-dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--text-muted); transition: all 0.2s;
}
.mic-dot.live { background: var(--danger); animation: pulse 1.4s infinite; }
.mic-dot.speaking { background: var(--success); animation: none; }
@keyframes pulse {
  0%   { box-shadow: 0 0 0 0 rgba(214, 125, 111, 0.5); }
  70%  { box-shadow: 0 0 0 10px rgba(214, 125, 111, 0); }
  100% { box-shadow: 0 0 0 0 rgba(214, 125, 111, 0); }
}
/* Spinner shown in the voice loader while TTS audio is being prepared. */
.voice-spinner {
  display: inline-block; width: 14px; height: 14px; flex: none;
  border: 2px solid var(--border-strong);
  border-top-color: var(--text-muted);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  .voice-spinner { animation-duration: 1.6s; }
}
.level-bar { flex: 1; height: 3px; background: var(--bg); border-radius: 2px; overflow: hidden; max-width: 200px; }
.level-bar-fill { height: 100%; background: var(--success); width: 0%; transition: width 0.05s linear; }
.preview {
  font-family: var(--font-serif); font-style: italic;
  font-size: 15px; color: var(--text-muted);
  padding: 10px 14px; background: transparent;
  border-left: 2px solid var(--border); margin: 12px 0;
  min-height: 24px;
}

/* Banners */
.banner {
  padding: 12px 16px; border-radius: 3px; font-size: 13px;
  margin-bottom: 16px; display: flex; align-items: center; justify-content: space-between;
}
.banner.warn  { background: var(--accent-dim); border: 1px solid var(--accent); color: var(--accent); }
.banner.info  { background: var(--bg-card); border: 1px solid var(--info); color: var(--info); }
.banner.error { background: rgba(214, 125, 111, 0.1); border: 1px solid var(--danger); color: var(--danger); }
.banner a { color: inherit; text-decoration: underline; }

/* Multi-line errors (e.g. the parse-format help) need a single column that
   wraps, not the centered flex row used for short one-line banners. */
#parseError {
  display: block;
  line-height: 1.5;
  text-align: left;
}
#parseError p { margin: 0 0 8px; }
#parseError p:last-child { margin-bottom: 0; }
#parseError ul { margin: 0 0 8px; padding-left: 20px; }
#parseError li { margin: 2px 0; }
#parseError code {
  display: inline-block;
  max-width: 100%;
  white-space: normal;
  overflow-wrap: anywhere;
  word-break: break-word;
}
.banner-close {
  background: none; border: none; color: inherit; cursor: pointer;
  padding: 2px 6px; font-size: 16px;
}

.progress-row {
  display: flex; gap: 16px; align-items: center; flex-wrap: wrap;
  margin-bottom: 16px; color: var(--text-muted); font-size: 12px;
  font-family: var(--font-mono);
}
.progress-bar { flex: 1; height: 4px; background: var(--bg-card); border-radius: 2px; overflow: hidden; min-width: 200px; }
.progress-bar-fill { height: 100%; background: var(--accent); width: 0%; transition: width 0.3s; }

/* Done / results */
.results-hero {
  text-align: center; padding: 32px 0;
  border-bottom: 1px solid var(--border); margin-bottom: 24px;
}
.results-hero .big {
  font-family: var(--font-serif); font-size: 64px; color: var(--accent);
  line-height: 1;
}
.results-hero .label {
  font-size: 14px; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: 0.1em; margin-top: 8px;
}
.stats-row { display: flex; gap: 32px; justify-content: center; margin-top: 16px; }
.stat .stat-num { font-family: var(--font-serif); font-size: 24px; }
.stat .stat-label { font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.1em; }

.line-review {
  background: var(--bg-elev); border: 1px solid var(--border);
  border-radius: 3px; padding: 16px 20px; margin-bottom: 12px;
}
.line-review-head {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 10px; font-size: 12px; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: 0.1em;
}
.line-review-score.good { color: var(--success); }
.line-review-score.mid  { color: var(--accent); }
.line-review-score.bad  { color: var(--danger); }
.line-review-expected { font-family: var(--font-serif); font-size: 16px; line-height: 1.6; }
.line-review-expected .word { padding: 1px 2px; border-radius: 2px; }
.line-review-expected .word.hit  { color: var(--text); }
.line-review-expected .word.miss { color: var(--danger); text-decoration: line-through; opacity: 0.7; }
.line-review-expected .word.sub  { color: var(--accent); border-bottom: 1px dashed var(--accent); }
.line-review-actual { font-family: var(--font-mono); font-size: 12px; color: var(--text-muted); margin-top: 6px; font-style: italic; }
.skipped-badge {
  display: inline-block; font-size: 10px; padding: 2px 8px;
  background: var(--bg-card); color: var(--text-muted);
  border-radius: 999px; letter-spacing: 0.1em;
}
.ondevice-badge {
  display: inline-block; font-size: 10px; padding: 2px 6px;
  background: var(--bg-card); color: var(--info);
  border: 1px solid rgba(127, 183, 201, 0.4);
  border-radius: 2px; letter-spacing: 0.1em; margin-left: 6px;
}

.review-line {
  border-left: 3px solid var(--border); padding: 10px 14px;
  margin-bottom: 10px; border-radius: 0 3px 3px 0;
}
.review-line.my-part { border-left-color: var(--accent); }
.review-line-char {
  font-family: var(--font-mono); font-size: 11px; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: 0.1em; margin-bottom: 5px;
}
.review-line.my-part .review-line-char { color: var(--accent); }
.review-line-text { font-family: var(--font-serif); font-size: 16px; line-height: 1.55; }

/* Voice prep overlay */
.overlay {
  position: fixed; inset: 0; background: rgba(15, 13, 11, 0.92);
  display: flex; align-items: center; justify-content: center; z-index: 100;
}
[data-theme="light"] .overlay { background: rgba(250, 248, 245, 0.92); }
.overlay-inner { text-align: center; max-width: 400px; padding: 32px; }
.overlay-bar { height: 4px; background: var(--bg-card); border-radius: 2px; overflow: hidden; margin: 16px 0 8px; }
.overlay-bar-fill { height: 100%; background: var(--accent); width: 0%; transition: width 0.3s; }

/* Pre-roll 3·2·1 countdown — a small, non-blocking badge centered over the
   running view. It deliberately does NOT use .overlay (which dims the whole
   screen and would hide the script). pointer-events:none so it never blocks. */
.countdown-overlay {
  position: fixed; inset: 0; z-index: 100;
  display: flex; align-items: center; justify-content: center;
  background: transparent; pointer-events: none;
}
.countdown-num {
  font-family: var(--font-mono);
  font-size: 56px; font-weight: 800; line-height: 1;
  color: var(--accent);
  width: 96px; height: 96px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 50%;
  background: var(--bg-card);
  border: 2px solid var(--accent);
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.45);
  animation: countdownPop 0.8s ease-out;
}
@keyframes countdownPop {
  0%   { transform: scale(0.5); opacity: 0; }
  30%  { transform: scale(1.1); opacity: 1; }
  100% { transform: scale(1);   opacity: 0.92; }
}
@media (max-width: 720px) {
  .countdown-num { font-size: 44px; width: 76px; height: 76px; }
}

@media (max-width: 720px) {
  .layout { grid-template-columns: 1fr; }

  /* Show the header toggle + the drawer's own close button. */
  .scripts-menu-btn { display: inline-block; padding: 6px 12px; font-size: 12px; }
  .sidebar-close { display: inline-block; }

  /* The sidebar becomes an off-canvas drawer that slides in from the left,
     so the script list no longer eats vertical space above the rehearsal UI. */
  .sidebar {
    position: fixed; top: 0; left: 0; bottom: 0;
    width: min(84vw, 320px); max-height: none;
    border-right: 1px solid var(--border); border-bottom: none;
    z-index: 60;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    box-shadow: 2px 0 16px rgba(0, 0, 0, 0.25);
  }
  .sidebar.open { transform: translateX(0); }

  /* Dim backdrop — always rendered at this width so it can fade via opacity;
     only catches taps while the drawer is open. */
  .sidebar-backdrop {
    display: block;
    position: fixed; inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 50;
    opacity: 0; pointer-events: none;
    transition: opacity 0.25s ease;
  }
  .sidebar-backdrop.open { opacity: 1; pointer-events: auto; }

  /* The app header packs the ☰ Scripts button + brand on the left and the
     session count + Profile + Sign out on the right — too much for one phone-
     width row, which is what forced the page to scroll sideways. Let it wrap
     and trim the brand + side padding so everything fits within the screen. */
  .main { padding: 20px 16px 100px; }
  header.app-head { flex-wrap: wrap; gap: 8px 12px; align-items: center; }
  header.app-head h1 { font-size: 20px; }
  .head-right { gap: 12px; font-size: 12px; }
}

@media (prefers-reduced-motion: reduce) {
  .sidebar { transition: none; }
  .sidebar-backdrop { transition: none; }
}

/* Desktop: shrink the rehearsal-control dropdowns so they don't stretch full width */
@media (min-width: 721px) {
  #speedSel, #micSensitivitySel, #vadTimeoutSel {
    width: 33%;
  }
}
