:root {
  --bg: #0c0c0f;
  --bg-glow: radial-gradient(ellipse 900px 500px at 50% -10%, rgba(224, 168, 62, 0.10), transparent 60%);
  --bg-glow-2: radial-gradient(ellipse 640px 480px at 88% 32%, rgba(224, 168, 62, 0.018), transparent 65%);
  /* Faint fractal-noise grain — same generator as the read-along paper
     texture, tuned way down for a dark ground so it reads as material,
     not visible static. */
  --grain: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='140' height='140'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix type='matrix' values='0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.018 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  /* Curtain-fold texture for the margins outside the content column —
     decorative only, kept clear of the app itself. */
  --curtain: repeating-linear-gradient(100deg, rgba(224, 168, 62, 0.09) 0px, rgba(224, 168, 62, 0.09) 3px, transparent 3px, transparent 26px);
  /* Loose scattered script pages tucked into the same margin strip as the
     curtain pleats — faint outline + a few text-line strokes per page,
     tiled vertically so the margin doesn't read as empty once the pleats
     alone stop being enough. */
  --curtain-pages: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='420' viewBox='0 0 160 420'%3E%3Cg fill='none' stroke='%23e0a83e'%3E%3Cg transform='rotate(-7 50 85)' stroke-opacity='0.16'%3E%3Crect x='18' y='38' width='66' height='92' rx='3'/%3E%3Cline x1='28' y1='58' x2='74' y2='58' stroke-opacity='0.11'/%3E%3Cline x1='28' y1='70' x2='74' y2='70' stroke-opacity='0.11'/%3E%3Cline x1='28' y1='82' x2='68' y2='82' stroke-opacity='0.11'/%3E%3Cline x1='28' y1='94' x2='74' y2='94' stroke-opacity='0.11'/%3E%3Cline x1='28' y1='106' x2='60' y2='106' stroke-opacity='0.11'/%3E%3C/g%3E%3Cg transform='rotate(9 100 300)' stroke-opacity='0.14'%3E%3Crect x='68' y='250' width='62' height='88' rx='3'/%3E%3Cline x1='78' y1='270' x2='122' y2='270' stroke-opacity='0.09'/%3E%3Cline x1='78' y1='282' x2='122' y2='282' stroke-opacity='0.09'/%3E%3Cline x1='78' y1='294' x2='116' y2='294' stroke-opacity='0.09'/%3E%3Cline x1='78' y1='306' x2='122' y2='306' stroke-opacity='0.09'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
  --panel: #16151a;
  --panel-alt: #1c1b21;
  --panel-border: #2b2933;
  --panel-border-soft: #221f28;
  --text: #f2eee6;
  --text-dim: #9a94a6;
  --text-faint: #6b6577;
  --accent: #e0a83e;
  --accent-strong: #f2c15c;
  --accent-dim: #362a15;
  --accent-ink: #1c1305;
  --error: #ef6461;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow-card: 0 1px 0 rgba(255, 255, 255, 0.03) inset, 0 12px 28px rgba(0, 0, 0, 0.35);
  --shadow-pop: 0 16px 40px rgba(0, 0, 0, 0.5);
  --font-display: Georgia, "Iowan Old Style", "Palatino Linotype", serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  background-color: var(--bg);
  background-image: var(--bg-glow), var(--bg-glow-2), var(--grain);
  background-attachment: fixed;
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

/* Soft curtain-fold pleats in the margins either side of the app column —
   fixed to the viewport, never under the content itself, and hidden below
   the width where they'd start crowding it. */
body::before,
body::after {
  content: "";
  position: fixed;
  top: 0;
  bottom: 0;
  width: 160px;
  background-image: var(--curtain), var(--curtain-pages);
  background-repeat: repeat, repeat-y;
  opacity: 0.8;
  pointer-events: none;
  z-index: -1;
}

body::before { left: 0; }
body::after { right: 0; transform: scaleX(-1); }

@media (max-width: 1180px) {
  body::before,
  body::after {
    display: none;
  }
}

.app {
  max-width: 720px;
  margin: 0 auto;
  padding: 3rem 1.5rem 4rem;
  transition: max-width 0.25s ease;
}

/* Widened while Read Along is open, since the script itself benefits from
   more horizontal room than the upload/character panels need — every other
   panel is hidden whenever this is active, so nothing else is affected. */
.app.app-wide {
  max-width: 1040px;
}

/* --- Header / brand --- */

.app-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding-bottom: 1.6rem;
  margin-bottom: 2.25rem;
  border-bottom: 1px solid var(--panel-border-soft);
}

.brand {
  display: flex;
  align-items: center;
  gap: 1.1rem;
}

.brand-mark-wrap {
  position: relative;
  flex: none;
  display: flex;
}

.brand-mark {
  flex: none;
  filter: drop-shadow(0 0 8px rgba(224, 168, 62, 0.2));
}

.app-header h1 {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 2.15rem;
  letter-spacing: 0.01em;
  background: linear-gradient(135deg, var(--text) 20%, var(--accent-strong) 120%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.subtitle {
  margin: 0.2rem 0 0;
  color: var(--text-dim);
  font-size: 0.92rem;
}

.project-banner {
  align-items: center;
  gap: 0.6rem;
  padding: 0.55rem 0.9rem;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 999px;
  box-shadow: var(--shadow-card);
  animation: pop-in 0.25s ease;
}

.project-banner:not([hidden]) {
  display: flex;
}

.project-banner-icon {
  flex: none;
  color: var(--accent);
}

.project-banner-title {
  font-size: 0.85rem;
  font-weight: 600;
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.project-banner-meta {
  font-size: 0.7rem;
  color: var(--text-faint);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

/* :not([hidden]) again, for the same reason as .modal-overlay and
   #sign-in-btn above — an unconditional `display: flex` here would beat the
   UA's `[hidden]{display:none}` and show the widget's empty mount point
   even while signed out. */
.user-button-slot:not([hidden]) {
  display: flex;
  align-items: center;
}

/* Same issue as .modal-overlay above: .btn's unconditional `display:
   inline-flex` has the same specificity as the UA's `[hidden]{display:none}`
   and loads after it, so it wins and keeps the button visible even when
   hidden — hide it explicitly instead. */
#sign-in-btn[hidden],
#billing-btn[hidden] {
  display: none;
}

.btn-sm {
  padding: 0.5rem 0.9rem;
  font-size: 0.8rem;
  margin-left: 0;
}

/* --- Panels --- */

.panel {
  background: linear-gradient(180deg, var(--panel-alt), var(--panel));
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  padding: 1.75rem;
  margin-bottom: 1.25rem;
  box-shadow: var(--shadow-card);
  animation: rise-in 0.32s cubic-bezier(0.22, 1, 0.36, 1);
}

.panel.panel-leaving {
  animation: none;
  opacity: 0;
  transform: translateY(-6px);
  transition: opacity 0.16s ease, transform 0.16s ease;
  pointer-events: none;
}

@keyframes rise-in {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes pop-in {
  from { opacity: 0; transform: scale(0.92); }
  to { opacity: 1; transform: scale(1); }
}

.panel h2 {
  margin: 0 0 1.1rem;
  font-size: 1.05rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  letter-spacing: 0.01em;
}

.panel-icon-badge {
  flex: none;
  width: 2.1rem;
  height: 2.1rem;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(224, 168, 62, 0.045);
  border: 1px solid rgba(224, 168, 62, 0.1);
}

.panel-icon {
  flex: none;
  width: 18px;
  height: 18px;
  color: var(--accent);
}

.panel-icon.spin {
  animation: spin 1.4s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.hint {
  color: var(--text-dim);
  font-size: 0.88rem;
  margin-top: -0.4rem;
  margin-bottom: 1rem;
}

.hint-cost:not(:empty) {
  display: inline-block;
  margin: -0.15rem 0 1rem;
  padding: 0.4rem 0.7rem;
  font-size: 0.8rem;
  color: var(--accent-strong);
  background: var(--accent-dim);
  border: 1px solid rgba(224, 168, 62, 0.35);
  border-radius: var(--radius-sm);
}

/* --- Dropzone --- */

.dropzone {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
  text-align: center;
  border: 1.5px dashed var(--panel-border);
  border-radius: var(--radius);
  padding: 3.1rem 1rem;
  margin: 0.25rem 0 1.25rem;
  cursor: pointer;
  color: var(--text-dim);
  background: rgba(255, 255, 255, 0.012);
  overflow: hidden;
  transition: border-color 0.18s ease, color 0.18s ease, background 0.18s ease;
}

.dropzone::before {
  content: "";
  position: absolute;
  top: 8%;
  left: 50%;
  width: 220px;
  height: 140px;
  transform: translateX(-50%);
  background: radial-gradient(ellipse, rgba(224, 168, 62, 0.06), transparent 70%);
  opacity: 0.4;
  transition: opacity 0.18s ease;
  pointer-events: none;
}

.dropzone:hover::before,
.dropzone.dragover::before {
  opacity: 1;
}

.dropzone-icon,
.dropzone span {
  position: relative;
}

.dropzone-icon {
  color: var(--text-faint);
  transition: color 0.18s ease, transform 0.18s ease;
}

.dropzone:hover,
.dropzone.dragover {
  border-color: var(--accent);
  color: var(--text);
  background: rgba(224, 168, 62, 0.05);
}

.dropzone:hover .dropzone-icon,
.dropzone.dragover .dropzone-icon {
  color: var(--accent);
  transform: translateY(-2px);
}

/* --- Buttons --- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  border: none;
  border-radius: var(--radius-sm);
  padding: 0.7rem 1.35rem;
  font-size: 0.92rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  text-align: center;
  transition: transform 0.12s ease, box-shadow 0.12s ease, filter 0.12s ease;
}

.btn-primary {
  background: linear-gradient(135deg, var(--accent-strong), var(--accent));
  color: var(--accent-ink);
  box-shadow: 0 6px 18px rgba(224, 168, 62, 0.25);
}

.btn-primary:hover:not(:disabled) {
  filter: brightness(1.06);
  transform: translateY(-1px);
  box-shadow: 0 8px 22px rgba(224, 168, 62, 0.32);
}

.btn-primary:active:not(:disabled) {
  transform: translateY(0);
}

.btn-primary:disabled {
  background: var(--accent-dim);
  color: var(--text-faint);
  box-shadow: none;
  cursor: not-allowed;
}

.btn-secondary {
  background: transparent;
  border: 1px solid var(--panel-border);
  color: var(--text);
  margin-left: 0.75rem;
}

.btn-secondary:hover {
  border-color: var(--text-dim);
}

.error {
  color: var(--error);
  margin-top: 0.85rem;
  font-size: 0.88rem;
}

/* --- Progress --- */

.progress {
  background: var(--accent-dim);
  border-radius: 999px;
  height: 8px;
  overflow: hidden;
  margin: 0.25rem 0 0.6rem;
}

.progress-bar {
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--accent), var(--accent-strong));
  background-size: 200% 100%;
  box-shadow: 0 0 10px rgba(224, 168, 62, 0.5);
  animation: shimmer 1.6s linear infinite;
  transition: width 0.3s ease;
}

@keyframes shimmer {
  0% { background-position: 0% 0; }
  100% { background-position: -200% 0; }
}

.status-message {
  color: var(--text-dim);
  font-size: 0.9rem;
  margin: 0;
}

/* --- Character list --- */

.character-list {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  margin: 0 0 1.5rem;
}

.character-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.7rem 0.95rem;
  background: var(--bg);
  border: 1px solid var(--panel-border-soft);
  border-radius: var(--radius-sm);
  position: relative;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.character-row:hover {
  border-color: var(--panel-border);
  background: #101013;
}

.character-left {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  min-width: 0;
}

.char-avatar {
  flex: none;
  width: 2rem;
  height: 2rem;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 0.9rem;
  color: rgba(255, 255, 255, 0.95);
  text-shadow: 0 1px 1px rgba(0, 0, 0, 0.25);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.35), 0 0 0 1px rgba(255, 255, 255, 0.08) inset;
}

.character-name {
  font-weight: 600;
  letter-spacing: 0.01em;
}

.character-meta {
  color: var(--text-faint);
  font-size: 0.78rem;
  margin-top: 0.1rem;
}

.character-voice {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.voice-name {
  font-size: 0.85rem;
  color: var(--text-dim);
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.link-btn {
  background: none;
  border: none;
  color: var(--accent);
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 600;
  padding: 0;
}

.link-btn:hover {
  color: var(--accent-strong);
}

/* --- Preview buttons --- */

.preview-btn {
  flex: none;
  width: 27px;
  height: 27px;
  border-radius: 50%;
  border: 1px solid var(--panel-border);
  background: var(--panel);
  color: var(--text);
  cursor: pointer;
  font-size: 0.68rem;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  padding-left: 1px;
  transition: border-color 0.15s ease, color 0.15s ease, background 0.15s ease, transform 0.1s ease;
}

.preview-btn:hover:not(:disabled) {
  border-color: var(--accent);
  color: var(--accent);
  transform: scale(1.06);
}

.preview-btn.playing {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
  padding-left: 0;
  animation: pulse-ring 1.4s ease-out infinite;
}

@keyframes pulse-ring {
  0% { box-shadow: 0 0 0 0 rgba(224, 168, 62, 0.45); }
  70% { box-shadow: 0 0 0 7px rgba(224, 168, 62, 0); }
  100% { box-shadow: 0 0 0 0 rgba(224, 168, 62, 0); }
}

.preview-btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

/* --- Voice picker --- */

.voice-picker {
  position: absolute;
  top: 100%;
  right: 0;
  z-index: 10;
  width: 290px;
  background: var(--panel-alt);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  padding: 0.75rem;
  margin-top: 0.4rem;
  box-shadow: var(--shadow-pop);
  animation: pop-in 0.15s ease;
}

.voice-picker input {
  width: 100%;
  padding: 0.55rem 0.65rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--panel-border);
  background: var(--bg);
  color: var(--text);
  font-size: 0.9rem;
  margin-bottom: 0.55rem;
}

.voice-picker input:focus {
  outline: none;
  border-color: var(--accent);
}

.voice-filters {
  display: flex;
  gap: 0.4rem;
  margin-bottom: 0.55rem;
}

.voice-filters select {
  flex: 1;
  min-width: 0;
  padding: 0.4rem 0.5rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--panel-border);
  background: var(--bg);
  color: var(--text-dim);
  font-size: 0.78rem;
}

.voice-filters select:focus {
  outline: none;
  border-color: var(--accent);
}

.voice-results {
  max-height: 220px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.voice-results::-webkit-scrollbar {
  width: 6px;
}

.voice-results::-webkit-scrollbar-thumb {
  background: var(--panel-border);
  border-radius: 999px;
}

.voice-result-row {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.voice-result {
  flex: 1;
  min-width: 0;
  text-align: left;
  padding: 0.5rem 0.6rem;
  border-radius: var(--radius-sm);
  border: none;
  background: var(--bg);
  color: var(--text);
  cursor: pointer;
  font-size: 0.85rem;
  transition: background 0.12s ease;
}

.voice-result:hover {
  background: var(--accent-dim);
}

.voice-result-name {
  font-weight: 600;
}

.voice-result-desc {
  color: var(--text-faint);
  font-size: 0.74rem;
  margin-top: 0.1rem;
}

/* --- Player --- */

.player-card {
  position: relative;
  background: linear-gradient(165deg, #141319, var(--bg) 65%);
  border: 1px solid var(--panel-border-soft);
  border-radius: var(--radius-sm);
  padding: 1.1rem 1rem 1rem;
  overflow: hidden;
}

.player-card::after {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--accent) 35%, var(--accent-strong) 50%, var(--accent) 65%, transparent);
  opacity: 0.2;
}

.player-card > * {
  position: relative;
}

.playback-speed {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-top: 0.7rem;
  font-size: 0.78rem;
  color: var(--text-faint);
}

.speed-options {
  display: flex;
  gap: 0.3rem;
}

.speed-btn {
  padding: 0.3rem 0.55rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--panel-border);
  background: transparent;
  color: var(--text-dim);
  font-size: 0.76rem;
  cursor: pointer;
  transition: background 0.12s ease, color 0.12s ease, border-color 0.12s ease;
}

.speed-btn:hover {
  border-color: var(--text-dim);
  color: var(--text);
}

.speed-btn.active {
  background: var(--accent-dim);
  border-color: var(--accent);
  color: var(--accent-strong);
}

#player {
  display: none;
}

.custom-player {
  display: flex;
  align-items: center;
  gap: 0.7rem;
}

.play-pause-btn {
  flex: none;
  width: 2.7rem;
  height: 2.7rem;
  border-radius: 50%;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--accent-strong), var(--accent));
  color: var(--accent-ink);
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(224, 168, 62, 0.3);
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}

.play-pause-btn:hover {
  transform: scale(1.05);
  box-shadow: 0 6px 18px rgba(224, 168, 62, 0.4);
}

.nav-step-btn {
  flex: none;
  width: 2rem;
  height: 2rem;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: var(--text-faint);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.12s ease, background 0.12s ease;
}

.nav-step-btn:hover:not(:disabled) {
  color: var(--text);
  background: rgba(255, 255, 255, 0.06);
}

.nav-step-btn:disabled {
  opacity: 0.35;
  cursor: default;
}

.play-pause-icon.is-play {
  margin-left: 2px; /* optically center the triangle */
}

/* Some browsers don't reliably apply the UA [hidden]{display:none} rule to
   inline <svg> children — spell it out so only one glyph per toggle ever renders. */
.mute-btn svg[hidden] {
  display: none;
}

.player-time {
  flex: none;
  font-variant-numeric: tabular-nums;
  font-size: 0.78rem;
  color: var(--text-faint);
  min-width: 2.2em;
}

#player-current-time {
  text-align: right;
}

.player-seek {
  flex: 1;
  min-width: 0;
  -webkit-appearance: none;
  appearance: none;
  height: 4px;
  border-radius: 999px;
  background: var(--accent-dim);
  cursor: pointer;
}

.player-seek::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: var(--accent-strong);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.4);
  margin-top: -4.5px;
}

.player-seek::-webkit-slider-runnable-track {
  height: 4px;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--accent), var(--accent-dim));
}

.player-seek::-moz-range-thumb {
  width: 13px;
  height: 13px;
  border: none;
  border-radius: 50%;
  background: var(--accent-strong);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.4);
}

.player-seek::-moz-range-track {
  height: 4px;
  border-radius: 999px;
  background: var(--accent-dim);
}

.player-seek::-moz-range-progress {
  height: 4px;
  border-radius: 999px;
  background: var(--accent);
}

.mute-btn {
  flex: none;
  width: 1.9rem;
  height: 1.9rem;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: var(--text-faint);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.12s ease, background 0.12s ease;
}

.mute-btn:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.06);
}

.player-actions {
  margin-top: 1.1rem;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
}

.characters-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
}

/* Spacing here comes from the container's own gap now (needed so a wrapped
   second row of buttons doesn't stack flush against the first) — the
   default .btn-secondary margin-left would just double up on top of it. */
.player-actions .btn-secondary {
  margin-left: 0;
}

.share-panel {
  margin-top: 0.9rem;
  padding: 0.6rem 0.8rem;
  align-items: center;
  gap: 0.6rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--panel-border);
  background: var(--panel-alt);
}

/* display:flex must be conditional on not [hidden] — see the .modal-overlay
   comment above for why an unconditional rule here would defeat `hidden`. */
.share-panel:not([hidden]) {
  display: flex;
}

.share-panel-icon {
  flex: none;
  color: var(--accent);
}

.share-link-input {
  flex: 1;
  min-width: 0;
  padding: 0.45rem 0.6rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--panel-border-soft);
  background: var(--bg);
  color: var(--text-dim);
  font-size: 0.8rem;
}

.share-link-input:focus {
  outline: none;
  border-color: var(--accent);
  color: var(--text);
}

.share-panel .btn-sm {
  margin-left: 0;
  flex: none;
  white-space: nowrap;
}

.scenes-panel {
  margin-top: 0.9rem;
  padding: 0.7rem 0.8rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--panel-border);
  background: var(--panel-alt);
}

.scenes-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
  margin-bottom: 0.5rem;
}

.scenes-panel-title {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.scenes-list {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  max-height: 260px;
  overflow-y: auto;
}

.scene-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.45rem 0.6rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--panel-border-soft);
  background: var(--bg);
}

.scene-row-info {
  flex: 1;
  min-width: 0;
}

.scene-row-heading {
  font-size: 0.85rem;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.scene-row-meta {
  font-size: 0.72rem;
  color: var(--text-dim);
  margin-top: 0.1rem;
}

.scene-row .btn-sm {
  margin-left: 0;
  flex: none;
}

.scene-row-pending {
  font-size: 0.72rem;
  color: var(--text-dim);
  font-style: italic;
  flex: none;
}

.scenes-empty {
  font-size: 0.82rem;
  color: var(--text-dim);
  padding: 0.4rem 0;
}

.self-tape-hint {
  font-size: 0.78rem;
  margin: 0 0 0.5rem;
}

.self-tape-item {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.self-tape-timing {
  flex-direction: column;
  gap: 0.55rem;
  padding: 0.6rem 0.7rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--panel-border-soft);
  background: var(--panel-alt);
}

.self-tape-timing:not([hidden]) {
  display: flex;
}

.self-tape-pad-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.self-tape-pad-row label {
  font-size: 0.78rem;
  color: var(--text-dim);
  flex: none;
}

.self-tape-pad-row input[type="range"] {
  flex: 1;
  accent-color: var(--accent);
}

.self-tape-pad-value {
  font-size: 0.78rem;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  flex: none;
  min-width: 3.2em;
  text-align: right;
}

.self-tape-lines-toggle {
  align-self: flex-start;
  background: none;
  border: none;
  padding: 0;
  color: var(--accent);
  font-size: 0.76rem;
  cursor: pointer;
  text-decoration: underline;
}

.self-tape-lines {
  flex-direction: column;
  gap: 0.3rem;
  max-height: 220px;
  overflow-y: auto;
  padding-right: 0.2rem;
}

.self-tape-lines:not([hidden]) {
  display: flex;
}

.self-tape-line-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.self-tape-line-text {
  flex: 1;
  min-width: 0;
  font-size: 0.76rem;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.self-tape-line-pad {
  flex: none;
  width: 4.2em;
  padding: 0.25rem 0.4rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--panel-border);
  background: var(--bg);
  color: var(--text);
  font-size: 0.76rem;
  font-variant-numeric: tabular-nums;
}

.self-tape-line-pad:focus {
  outline: none;
  border-color: var(--accent);
}

.self-tape-line-pad.is-custom {
  border-color: var(--accent);
  color: var(--accent);
}

.self-tape-line-reset,
.self-tape-line-preview {
  flex: none;
  width: 1.6em;
  height: 1.6em;
  padding: 0;
  border-radius: var(--radius-sm);
  border: 1px solid var(--panel-border);
  background: var(--bg);
  color: var(--text-dim);
  font-size: 0.78rem;
  line-height: 1;
  cursor: pointer;
}

.self-tape-line-reset:hover,
.self-tape-line-preview:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.now-playing-banner {
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
  margin-top: 0.6rem;
  padding: 0.5rem 0.7rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--accent, var(--panel-border));
  background: var(--panel-alt);
  font-size: 0.82rem;
  color: var(--text);
}

.now-playing-banner:not([hidden]) {
  display: flex;
}

.now-playing-banner .btn-sm {
  flex: none;
}

.readalong-slot {
  margin-top: 1.5rem;
}

.readalong-status .status-message {
  margin: 0;
}

.readalong-toolbar {
  gap: 0.5rem;
  margin-bottom: 0.6rem;
  flex-wrap: wrap;
}

.readalong-toolbar:not([hidden]) {
  display: flex;
}

.scene-jump-select {
  flex: none;
  max-width: 40%;
  padding: 0.5rem 0.6rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--panel-border);
  background: var(--panel-alt);
  color: var(--text-dim);
  font-size: 0.78rem;
}

.transcript-search {
  flex: 1;
  min-width: 140px;
  padding: 0.5rem 0.7rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--panel-border);
  background: var(--panel-alt);
  color: var(--text);
  font-size: 0.82rem;
}

.scene-jump-select:focus,
.transcript-search:focus {
  outline: none;
  border-color: var(--accent);
}

.notes-summary {
  flex: none;
  padding: 0.4rem 0.7rem;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(224, 168, 62, 0.35);
  background: rgba(224, 168, 62, 0.1);
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.12s ease, border-color 0.12s ease;
}

.notes-summary:hover {
  background: rgba(224, 168, 62, 0.18);
  border-color: var(--accent);
}

.zoom-control {
  flex: none;
  display: flex;
  gap: 0.3rem;
}

.zoom-btn {
  width: 2rem;
  height: 2rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--panel-border);
  background: var(--panel-alt);
  color: var(--text-dim);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.12s ease, color 0.12s ease, border-color 0.12s ease;
}

.zoom-btn:hover {
  border-color: var(--accent);
  color: var(--text);
}

/* Read-along transcript is styled as a script page — Courier, cream paper,
   industry-standard screenplay layout (centered dialogue column under an
   uppercase character cue, full-width action, right-aligned transitions) —
   rather than matching the surrounding dark UI, since the point is to look
   like the page it was generated from. */

.readalong-transcript {
  max-height: 62vh;
  overflow-y: auto;
  background-color: #f6f1e4;
  /* Faint fractal-noise grain so the page reads as paper rather than a flat
     fill — the alpha channel in the filter's color matrix keeps it subtle. */
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='140' height='140'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix type='matrix' values='0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.05 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  color: #1c1a16;
  font-family: "Courier Prime", "Courier New", Courier, monospace;
  font-size: 0.86rem;
  line-height: 1.28;
  padding: 1.75rem 2rem;
  border: 1px solid var(--panel-border-soft);
  border-radius: var(--radius-sm);
  box-shadow: 0 22px 48px rgba(0, 0, 0, 0.4), 0 2px 0 rgba(0, 0, 0, 0.06);
}

.readalong-transcript::-webkit-scrollbar {
  width: 8px;
}

.readalong-transcript::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.22);
  border-radius: 999px;
}

.ra-line {
  position: relative;
  padding: 0 4.75rem 0 0.4rem;
  border-radius: 3px;
  transition: background 0.4s ease;
}

.ra-line.ra-flash {
  background: rgba(224, 168, 62, 0.18);
}

.ra-line.ra-self-tape-cue {
  background: rgba(224, 168, 62, 0.08);
  border-left: 3px solid var(--accent);
}

.ra-cue-badge {
  text-align: center;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--accent);
  margin: 0.3rem 0 0;
}

.ra-regen-btn {
  position: absolute;
  top: 0.05rem;
  right: 0.1rem;
  width: 1.4rem;
  height: 1.4rem;
  border-radius: 50%;
  border: 1px solid rgba(0, 0, 0, 0.15);
  background: rgba(255, 255, 255, 0.6);
  color: #6b6355;
  font-size: 0.78rem;
  line-height: 1;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.12s ease, transform 0.12s ease, background 0.12s ease;
}

.ra-line:hover .ra-regen-btn {
  opacity: 1;
}

.ra-regen-btn:hover {
  background: #fff;
  transform: rotate(45deg);
  color: #1c1a16;
}

.ra-note-btn {
  position: absolute;
  top: 0.05rem;
  right: 1.65rem;
  width: 1.4rem;
  height: 1.4rem;
  border-radius: 50%;
  border: 1px solid rgba(0, 0, 0, 0.15);
  background: rgba(255, 255, 255, 0.6);
  color: #6b6355;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.12s ease, background 0.12s ease, color 0.12s ease;
}

.ra-line:hover .ra-note-btn,
.ra-note-btn.has-notes {
  opacity: 1;
}

.ra-note-btn:hover {
  background: #fff;
  color: #1c1a16;
}

.ra-note-count {
  position: absolute;
  top: -0.3rem;
  right: -0.3rem;
  min-width: 1rem;
  height: 1rem;
  padding: 0 0.15rem;
  border-radius: 999px;
  background: #c8862a;
  color: #fff;
  font-size: 0.6rem;
  font-weight: 700;
  line-height: 1rem;
  text-align: center;
}

.ra-note-panel {
  margin: 0.5rem 0 0.75rem;
  padding: 0.65rem 0.75rem;
  border-radius: 6px;
  border: 1px solid rgba(0, 0, 0, 0.12);
  background: rgba(255, 255, 255, 0.55);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
}

.ra-note-item {
  padding: 0.35rem 0;
  border-bottom: 1px solid rgba(0, 0, 0, 0.08);
}

.ra-note-item:last-of-type {
  border-bottom: none;
}

.ra-note-item-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.ra-note-author {
  font-weight: 700;
  font-size: 0.78rem;
  color: #4a4438;
}

.ra-note-delete {
  border: none;
  background: none;
  color: #a89f8c;
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  padding: 0;
}

.ra-note-delete:hover {
  color: #a63244;
}

.ra-note-text {
  margin: 0.15rem 0 0;
  font-size: 0.85rem;
  color: #33302a;
  line-height: 1.4;
  white-space: pre-wrap;
}

.ra-note-form {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

.ra-note-input {
  flex: 1;
  min-width: 0;
  padding: 0.4rem 0.6rem;
  border-radius: 6px;
  border: 1px solid rgba(0, 0, 0, 0.15);
  background: #fff;
  color: #1c1a16;
  font-size: 0.82rem;
}

.ra-note-input:focus {
  outline: none;
  border-color: #c8862a;
}

.ra-note-add-btn {
  flex: none;
  padding: 0.4rem 0.75rem;
  border-radius: 6px;
  border: 1px solid #c8862a;
  background: #c8862a;
  color: #fff;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}

.ra-note-add-btn:hover {
  filter: brightness(1.05);
}

.ra-note-add-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.ra-takes-btn {
  position: absolute;
  top: 0.05rem;
  right: 3.2rem;
  width: 1.4rem;
  height: 1.4rem;
  border-radius: 50%;
  border: 1px solid rgba(0, 0, 0, 0.15);
  background: rgba(255, 255, 255, 0.6);
  color: #6b6355;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.12s ease, background 0.12s ease, color 0.12s ease;
}

.ra-line:hover .ra-takes-btn,
.ra-takes-btn.has-takes {
  opacity: 1;
}

.ra-takes-btn:hover {
  background: #fff;
  color: #1c1a16;
}

.ra-takes-count {
  position: absolute;
  top: -0.3rem;
  right: -0.3rem;
  min-width: 1rem;
  height: 1rem;
  padding: 0 0.15rem;
  border-radius: 999px;
  background: #4a7a8c;
  color: #fff;
  font-size: 0.6rem;
  font-weight: 700;
  line-height: 1rem;
  text-align: center;
}

.ra-takes-panel {
  margin: 0.5rem 0 0.75rem;
  padding: 0.65rem 0.75rem;
  border-radius: 6px;
  border: 1px solid rgba(0, 0, 0, 0.12);
  background: rgba(255, 255, 255, 0.55);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
}

.ra-takes-loading,
.ra-takes-empty {
  font-size: 0.82rem;
  color: #6b6355;
  padding: 0.2rem 0;
}

.ra-takes-list {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.ra-take-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.3rem 0;
  border-bottom: 1px solid rgba(0, 0, 0, 0.08);
}

.ra-take-item:last-of-type {
  border-bottom: none;
}

.ra-take-play {
  flex: none;
  width: 1.6rem;
  height: 1.6rem;
  border-radius: 50%;
  border: 1px solid rgba(0, 0, 0, 0.18);
  background: #fff;
  color: #1c1a16;
  font-size: 0.7rem;
  cursor: pointer;
}

.ra-take-play.playing {
  background: #c8862a;
  color: #fff;
  border-color: #c8862a;
}

.ra-take-label {
  flex: 1;
  min-width: 0;
  font-size: 0.82rem;
  color: #33302a;
}

.ra-take-active-badge {
  flex: none;
  font-size: 0.72rem;
  font-weight: 700;
  color: #2f7a4a;
}

.ra-take-use-btn {
  flex: none;
  padding: 0.3rem 0.6rem;
  border-radius: 6px;
  border: 1px solid #c8862a;
  background: transparent;
  color: #8a5e1e;
  font-size: 0.76rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}

.ra-take-use-btn:hover:not(:disabled) {
  background: #c8862a;
  color: #fff;
}

.ra-take-use-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.ra-take-delete {
  flex: none;
  border: none;
  background: none;
  color: #a89f8c;
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  padding: 0 0.15rem;
}

.ra-take-delete:hover {
  color: #a63244;
}

.ra-take-export-btn {
  display: block;
  margin-top: 0.6rem;
  width: 100%;
  padding: 0.4rem 0.75rem;
  border-radius: 6px;
  border: 1px solid rgba(0, 0, 0, 0.18);
  background: transparent;
  color: #4a4438;
  font-size: 0.78rem;
  font-weight: 600;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
}

.ra-take-export-btn:hover {
  border-color: #8a5e1e;
  color: #8a5e1e;
}

.ra-take-gen-btn {
  margin-top: 0.6rem;
  width: 100%;
  padding: 0.45rem 0.75rem;
  border-radius: 6px;
  border: 1px solid #c8862a;
  background: #c8862a;
  color: #fff;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
}

.ra-take-gen-btn:hover:not(:disabled) {
  filter: brightness(1.05);
}

.ra-take-gen-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.ra-word {
  cursor: pointer;
  border-radius: 3px;
  transition: background 0.1s ease;
}

.ra-word:hover {
  background: rgba(0, 0, 0, 0.08);
}

/* The highlight is applied to every word sharing the current wrapped visual
   row (see computeWordRows in app.js), not the whole paragraph — adjacent
   highlighted spans read as one continuous marked line since each span's
   own trailing space is included in its highlighted background. */
.ra-word.active {
  background: #ffd54a;
  box-shadow: 0 0 0 2px rgba(255, 213, 74, 0.35);
}

/* Vertical rhythm matches real screenplay format: one blank line's worth of
   space before a new element (scene heading, action beat, character cue,
   transition), and none between elements that continue one another — a
   character cue sits flush against its own dialogue, and if the same speech
   was split across multiple dialogue_list entries (e.g. a mid-line
   parenthetical), those entries now touch with zero margin so line-height
   alone spaces them, reading as one continuous paragraph instead of
   separate, oddly-gapped blocks. */

.ra-scene-heading .ra-block-text {
  font-weight: 700;
  text-transform: uppercase;
  margin: 1.15rem 0 0;
}

.ra-action .ra-block-text {
  margin: 1.15rem 0 0;
}

.ra-transition .ra-block-text {
  text-align: right;
  text-transform: uppercase;
  font-weight: 700;
  margin: 1.15rem 0 0;
}

.ra-character-name {
  text-align: center;
  text-transform: uppercase;
  font-weight: 700;
  margin: 1.15rem 0 0;
}

.ra-dialogue-text {
  width: 62%;
  min-width: 190px;
  margin: 0 auto;
  text-align: left;
}

/* .ra-dialogue-text's own margin is already 0 (see above), so dialogue text
   naturally sits flush under its cue with no extra rule needed. Only the
   very first element on the page needs its top margin zeroed. */
.readalong-transcript > .ra-line:first-child > :first-child {
  margin-top: 0;
}

/* --- My Scripts modal --- */

.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.55);
  animation: rise-in 0.15s ease;
}

/* `display: flex` has to be conditional on not being [hidden] — an
   unconditional `display: flex` on this class has the same specificity as
   the browser's built-in `[hidden] { display: none }` rule, and since this
   stylesheet loads after the UA one, it would win and keep the modal visible
   (and unclosable) even with the hidden attribute set. */
.modal-overlay:not([hidden]) {
  display: flex;
}

.modal-card {
  width: min(420px, 90vw);
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  background: linear-gradient(180deg, var(--panel-alt), var(--panel));
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-pop);
  animation: pop-in 0.18s ease;
}

/* The default 420px modal width (sized for the simple "My Scripts" list) is
   too narrow for three side-by-side pricing cards — they'd overflow the
   card's edge. Billing needs its own wider cap. */
#billing-modal .modal-card {
  width: min(640px, 92vw);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.1rem 1.25rem 0.85rem;
  border-bottom: 1px solid var(--panel-border-soft);
}

.modal-header h3 {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
}

.modal-close {
  border: none;
  background: transparent;
  color: var(--text-faint);
  font-size: 1.3rem;
  line-height: 1;
  cursor: pointer;
  padding: 0.15rem 0.4rem;
}

.modal-close:hover {
  color: var(--text);
}

.history-list {
  overflow-y: auto;
  padding: 0.6rem;
}

.history-item {
  display: block;
  width: 100%;
  text-align: left;
  padding: 0.7rem 0.8rem;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text);
  cursor: pointer;
  transition: background 0.12s ease;
}

.history-item:hover {
  background: var(--panel-border-soft);
}

.history-item-title {
  font-weight: 600;
  font-size: 0.92rem;
}

.history-item-meta {
  color: var(--text-faint);
  font-size: 0.76rem;
  margin-top: 0.15rem;
}

.history-empty {
  padding: 1.5rem;
  text-align: center;
  color: var(--text-faint);
  font-size: 0.88rem;
}

.billing-content {
  padding: 1.1rem;
}

.billing-intro {
  color: var(--text-dim);
  font-size: 0.88rem;
  margin: 0 0 0.9rem;
}

.billing-plans {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.7rem;
}

.billing-plan {
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-sm);
  padding: 0.9rem 0.8rem;
  text-align: center;
}

.billing-plan-name {
  font-weight: 600;
  font-size: 0.9rem;
}

.billing-plan-price {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--accent);
  margin: 0.3rem 0;
}

.billing-plan-price span {
  font-size: 0.7rem;
  font-weight: 500;
  color: var(--text-faint);
}

.billing-plan-quota {
  color: var(--text-dim);
  font-size: 0.78rem;
  margin-bottom: 0.7rem;
}

.billing-current-plan {
  font-size: 1.1rem;
  font-weight: 700;
}

.billing-current-meta {
  color: var(--text-dim);
  font-size: 0.82rem;
  margin-top: 0.2rem;
}

.billing-current-usage {
  margin-top: 0.7rem;
  font-size: 0.88rem;
}

.billing-overage-note {
  color: var(--text-faint);
  font-size: 0.78rem;
  margin: 0.5rem 0 1rem;
}

.billing-legal-note {
  color: var(--text-faint);
  font-size: 0.74rem;
  text-align: center;
  margin: 1rem 0 0;
}

.billing-legal-note a {
  color: var(--text-dim);
}

/* --- Responsive --- */

@media (max-width: 480px) {
  .app { padding: 2rem 1rem 3rem; }
  .panel { padding: 1.25rem; }
  .project-banner-title { max-width: 140px; }
  .readalong-transcript { padding: 1.25rem 1rem; }
  .ra-dialogue-text { width: 90%; }
  .readalong-toolbar { flex-direction: column; }
  .scene-jump-select { max-width: 100%; }
  .billing-plans { grid-template-columns: 1fr; }
}
