/* ═══════════════════════════════════════════════════
   StoryWeaver — Styles v2.0
   Modern layout, retro flavour
   Mobile-first responsive design
   ═══════════════════════════════════════════════════ */

:root {
  --bg-dark: #0d0b08;
  --bg-surface: #1a1710;
  --bg-card: #1e1b14;
  --bg-card-hover: #2a2618;
  --bg-input: #13110d;
  --bg-page: #f4e8c1;
  --bg-page-dark: #e8d5a3;
  --accent: #c62828;
  --accent-light: #ef5350;
  --accent-dim: #8b1a1a;
  --gold: #d4a843;
  --gold-light: #f0d080;
  --gold-dim: #8a7030;
  --text-light: #ede4d3;
  --text-dim: #9a8e78;
  --text-muted: #6a6050;
  --text-dark: #2c1810;
  --green: #2e7d32;
  --blue: #1565c0;
  --red: #c62828;
  --orange: #e65100;
  --purple: #6a1b9a;
  --font-title: 'Special Elite', 'Courier New', monospace;
  --font-story: 'Merriweather', Georgia, serif;
  --font-ui: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-horror: 'Creepster', cursive;
  --radius: 8px;
  --radius-lg: 14px;
  --transition: 0.25s ease;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
}

*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; overflow: hidden; -webkit-tap-highlight-color: transparent; }
body {
  background: var(--bg-dark);
  color: var(--text-light);
  font-family: var(--font-ui);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

#app { height: 100%; position: relative; }

/* ─── Screens ─────────────────────────────────────── */
.screen {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  opacity: 0; pointer-events: none;
  transition: opacity 0.4s ease;
  overflow: hidden;
}
.screen.active { opacity: 1; pointer-events: all; }

.screen-scroll {
  height: 100%;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  scroll-behavior: smooth;
  padding: var(--safe-top) 0 var(--safe-bottom);
}

/* ─── Title Screen ────────────────────────────────── */
.title-header {
  text-align: center;
  padding: 60px 24px 24px;
}
.retro-badge {
  display: inline-block;
  background: var(--accent);
  color: #fff;
  font-family: var(--font-title);
  font-size: 0.65rem;
  letter-spacing: 0.3em;
  padding: 5px 18px;
  margin-bottom: 16px;
  text-transform: uppercase;
  border-radius: 2px;
}
.title {
  font-family: var(--font-title);
  font-size: clamp(2.4rem, 8vw, 4rem);
  font-weight: 900;
  color: var(--text-light);
  text-shadow: 2px 2px 0 rgba(0,0,0,0.4);
  letter-spacing: 0.06em;
  line-height: 1.1;
  margin-bottom: 6px;
}
.title-accent { color: var(--accent); }
.subtitle {
  font-family: var(--font-title);
  font-size: clamp(0.85rem, 2.5vw, 1.1rem);
  color: var(--text-dim);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  margin-bottom: 4px;
}
.tagline {
  font-family: var(--font-story);
  font-style: italic;
  color: var(--text-muted);
  font-size: 0.9rem;
  margin-bottom: 0;
}

/* ─── Story Cards ─────────────────────────────────── */
.story-cards {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 24px 20px;
  max-width: 600px;
  margin: 0 auto;
}
.story-card {
  background: #ffffff;
  border: 1px solid rgba(0,0,0,0.08);
  border-left: 4px solid transparent;
  color: var(--text-dark);
  padding: 20px;
  cursor: pointer;
  border-radius: var(--radius);
  transition: all var(--transition);
  position: relative;
  -webkit-tap-highlight-color: transparent;
}
.story-card.genre-fantasy { border-left-color: var(--gold); }
.story-card.genre-survival { border-left-color: var(--blue); }
.story-card.genre-horror { border-left-color: var(--accent); }
.story-card:hover, .story-card:active {
  background: #f8f8f8;
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(0,0,0,0.25);
}
.story-card-genre {
  font-family: var(--font-title);
  font-size: 0.6rem;
  letter-spacing: 0.25em;
  text-transform: uppercase;
  margin-bottom: 6px;
  opacity: 1;
}
.genre-fantasy .story-card-genre { color: var(--gold-dim); }
.genre-survival .story-card-genre { color: var(--blue); }
.genre-horror .story-card-genre { color: var(--accent); }
.story-card-title {
  font-family: var(--font-story);
  font-size: 1.1rem;
  font-weight: 700;
  margin-bottom: 6px;
  line-height: 1.3;
  color: var(--text-dark);
}
.story-card-desc {
  font-size: 0.82rem;
  line-height: 1.55;
  opacity: 0.65;
  margin-bottom: 10px;
  color: #4a4035;
}
.story-card-prompt {
  font-family: var(--font-title);
  font-size: 0.65rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  opacity: 0.3;
  text-align: right;
  color: #4a4035;
}

.title-footer {
  text-align: center;
  padding: 16px 24px 40px;
  border-top: 1px solid rgba(255,255,255,0.06);
  margin: 0 20px;
  max-width: 600px;
  margin-left: auto;
  margin-right: auto;
}
.warning-text {
  font-family: var(--font-title);
  font-size: 0.7rem;
  color: var(--accent);
  letter-spacing: 0.04em;
}
.patience-text {
  font-family: var(--font-story);
  font-size: 0.75rem;
  color: var(--text-muted);
  font-style: italic;
  margin-top: 8px;
}

/* ─── Buttons ─────────────────────────────────────── */
.btn {
  font-family: var(--font-ui);
  font-size: 0.95rem;
  font-weight: 500;
  padding: 12px 28px;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  transition: all var(--transition);
  letter-spacing: 0.02em;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
.btn-primary {
  background: var(--accent);
  color: #fff;
  font-family: var(--font-title);
  letter-spacing: 0.08em;
}
.btn-primary:hover {
  background: var(--accent-light);
  transform: translateY(-1px);
  box-shadow: 0 4px 16px rgba(198,40,40,0.3);
}
.btn-primary:active { transform: scale(0.98); }
.btn-glow { box-shadow: 0 0 20px rgba(198,40,40,0.15); }
.btn-secondary {
  background: var(--bg-surface);
  color: var(--text-light);
  border: 1px solid rgba(255,255,255,0.1);
}
.btn-secondary:hover {
  background: var(--bg-card-hover);
  border-color: rgba(255,255,255,0.2);
}
.btn-icon {
  background: none;
  border: 1px solid rgba(255,255,255,0.12);
  color: var(--text-light);
  padding: 6px 10px;
  font-size: 1.1rem;
  border-radius: var(--radius);
  cursor: pointer;
  min-width: 38px;
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.btn-icon:hover { border-color: var(--gold-dim); background: rgba(255,255,255,0.04); }
.btn:disabled { opacity: 0.35; cursor: not-allowed; transform: none !important; }
.btn-back {
  background: none;
  border: none;
  color: var(--text-muted);
  font-family: var(--font-title);
  font-size: 0.85rem;
  cursor: pointer;
  padding: 8px 12px;
  margin-bottom: 8px;
  min-height: 44px;
}
.btn-back:hover { color: var(--accent); }

/* ─── Setup Screen ────────────────────────────────── */
.setup-container {
  max-width: 600px;
  margin: 0 auto;
  padding: 20px 20px 40px;
}
.setup-container h2 {
  font-family: var(--font-title);
  font-size: 1.6rem;
  color: var(--accent);
  text-align: center;
  margin-bottom: 4px;
  letter-spacing: 0.05em;
}
.setup-intro {
  text-align: center;
  color: var(--text-muted);
  margin-bottom: 28px;
  font-family: var(--font-story);
  font-style: italic;
  font-size: 0.9rem;
}
.setup-section { margin-bottom: 22px; }
.setup-section label {
  display: block;
  font-family: var(--font-title);
  font-size: 0.72rem;
  color: var(--gold);
  text-transform: uppercase;
  letter-spacing: 0.14em;
  margin-bottom: 8px;
  padding-left: 2px;
}
.option-list { display: flex; flex-direction: column; gap: 6px; }
.option-btn {
  background: var(--bg-card);
  border: 1px solid rgba(255,255,255,0.08);
  color: var(--text-light);
  padding: 14px 16px;
  border-radius: var(--radius);
  cursor: pointer;
  text-align: left;
  font-family: var(--font-story);
  font-size: 0.85rem;
  transition: all var(--transition);
  line-height: 1.4;
  min-height: 48px;
  -webkit-tap-highlight-color: transparent;
}
.option-btn:hover { background: var(--bg-card-hover); border-color: rgba(255,255,255,0.15); }
.option-btn.selected {
  background: rgba(198,40,40,0.12);
  border-color: var(--accent);
  color: var(--accent-light);
  font-weight: 600;
}
/* ─── Setup Audio Toggle ──────────────────────────── */
.setup-audio-toggle {
  max-width: 480px;
  margin: 28px auto 0;
}
.audio-toggle-label {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--bg-card);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: var(--radius);
  padding: 16px 18px;
  cursor: pointer;
  transition: all var(--transition);
  -webkit-tap-highlight-color: transparent;
}
.audio-toggle-label:hover {
  background: var(--bg-card-hover);
  border-color: rgba(255,255,255,0.15);
}
.audio-toggle-icon { font-size: 1.5rem; flex-shrink: 0; }
.audio-toggle-text {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.audio-toggle-text strong {
  font-family: var(--font-ui);
  font-size: 0.95rem;
  color: var(--text-light);
  font-weight: 600;
}
.audio-toggle-hint {
  font-family: var(--font-story);
  font-size: 0.78rem;
  color: var(--text-muted);
  font-style: italic;
}
.audio-toggle-checkbox { display: none; }
.audio-toggle-switch {
  width: 44px;
  height: 24px;
  background: rgba(255,255,255,0.12);
  border-radius: 12px;
  position: relative;
  flex-shrink: 0;
  transition: background var(--transition);
}
.audio-toggle-switch::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 20px;
  height: 20px;
  background: var(--text-dim);
  border-radius: 50%;
  transition: all var(--transition);
}
.audio-toggle-checkbox:checked + .audio-toggle-switch {
  background: var(--accent);
}
.audio-toggle-checkbox:checked + .audio-toggle-switch::after {
  left: 22px;
  background: #fff;
}

.setup-actions {
  display: flex;
  gap: 12px;
  justify-content: center;
  margin-top: 32px;
  padding-bottom: 16px;
}

/* ─── Narration Banner ────────────────────────────── */
.narration-banner {
  background: linear-gradient(90deg, rgba(198,40,40,0.12), rgba(212,168,67,0.10));
  border-bottom: 1px solid rgba(255,255,255,0.06);
  padding: 8px 16px;
  transition: all 0.3s ease;
  overflow: hidden;
}
.narration-banner-inner {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  max-width: 640px;
  margin: 0 auto;
}
.narration-banner-inner span:not(.eq-bar) {
  font-family: var(--font-story);
  font-size: 0.82rem;
  color: var(--text-dim);
  font-style: italic;
}
.narration-banner.is-loading .narration-banner-inner span:not(.eq-bar) {
  color: var(--gold);
}
.narration-banner.is-playing .narration-banner-inner span:not(.eq-bar) {
  color: var(--gold-light);
}
.narration-eq {
  display: flex;
  align-items: flex-end;
  gap: 2px;
  height: 16px;
}
.eq-bar {
  display: block;
  width: 3px;
  background: var(--gold);
  border-radius: 1px;
  animation: eq-idle 1.2s ease-in-out infinite;
}
.eq-bar:nth-child(1) { height: 6px; animation-delay: 0s; }
.eq-bar:nth-child(2) { height: 10px; animation-delay: 0.15s; }
.eq-bar:nth-child(3) { height: 4px; animation-delay: 0.3s; }
@keyframes eq-idle {
  0%, 100% { transform: scaleY(0.5); opacity: 0.4; }
  50% { transform: scaleY(1); opacity: 0.6; }
}
.narration-banner.is-loading .eq-bar {
  animation: eq-loading 0.6s ease-in-out infinite;
}
@keyframes eq-loading {
  0%, 100% { transform: scaleY(0.3); }
  50% { transform: scaleY(1.2); }
}
.narration-banner.is-playing .eq-bar {
  background: var(--gold-light);
  animation: eq-playing 0.45s ease-in-out infinite;
}
.narration-banner.is-playing .eq-bar:nth-child(1) { animation-delay: 0s; }
.narration-banner.is-playing .eq-bar:nth-child(2) { animation-delay: 0.12s; }
.narration-banner.is-playing .eq-bar:nth-child(3) { animation-delay: 0.24s; }
@keyframes eq-playing {
  0%, 100% { transform: scaleY(0.4); }
  50% { transform: scaleY(1.4); }
}
.narration-banner.is-paused .eq-bar {
  animation: none;
  transform: scaleY(0.5);
  opacity: 0.3;
}

/* ─── Story Screen ────────────────────────────────── */
.story-container {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  background: var(--bg-dark);
}
.story-status {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px;
  background: var(--bg-surface);
  border-bottom: 1px solid rgba(255,255,255,0.06);
  font-family: var(--font-title);
  min-height: 48px;
  gap: 8px;
}
.status-left { display: flex; align-items: center; gap: 14px; }
.status-right { display: flex; align-items: center; gap: 5px; flex-shrink: 0; }
.status-item { display: flex; align-items: center; gap: 4px; }
.status-label {
  font-size: 0.6rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.status-value {
  font-size: 0.85rem;
  color: var(--gold);
  font-weight: 600;
}
.status-tension-wrap { display: none; }
.tension-bar {
  width: 60px;
  height: 5px;
  background: rgba(255,255,255,0.06);
  border-radius: 3px;
  overflow: hidden;
}
.tension-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--green), var(--orange), var(--red));
  border-radius: 3px;
  transition: width 1s ease;
}

/* ─── Narrative Area ──────────────────────────────── */
.narrative-area {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 28px 20px;
  background: var(--bg-dark);
}
.narrative-text {
  font-family: var(--font-story);
  font-size: 1.05rem;
  line-height: 1.85;
  color: var(--text-light);
  max-width: 640px;
  margin: 0 auto;
}
.narrative-text p {
  margin-bottom: 1.2em;
  opacity: 0;
  animation: fade-in-up 0.6s ease forwards;
  text-indent: 1.5em;
}
.narrative-text p:first-child { text-indent: 0; }
.narrative-text p:nth-child(1) { animation-delay: 0s; }
.narrative-text p:nth-child(2) { animation-delay: 0.12s; }
.narrative-text p:nth-child(3) { animation-delay: 0.24s; }
.narrative-text p:nth-child(4) { animation-delay: 0.36s; }
.narrative-text p:nth-child(5) { animation-delay: 0.48s; }
.narrative-text p:nth-child(6) { animation-delay: 0.6s; }
.narrative-text p:nth-child(7) { animation-delay: 0.72s; }
.narrative-text p:nth-child(8) { animation-delay: 0.84s; }

@keyframes fade-in-up {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}
.segment-divider {
  text-align: center;
  padding: 20px 0;
  color: var(--text-muted);
  font-family: var(--font-title);
  font-size: 0.75rem;
  letter-spacing: 0.5em;
  opacity: 0.3;
}
.page-number {
  text-align: center;
  font-family: var(--font-title);
  font-size: 0.7rem;
  color: var(--text-muted);
  padding: 6px 0 18px;
  letter-spacing: 0.1em;
  opacity: 0.5;
}

/* ─── Response Area ───────────────────────────────── */
.response-area {
  padding: 12px 16px calc(12px + var(--safe-bottom));
  background: var(--bg-surface);
  border-top: 1px solid rgba(255,255,255,0.06);
}
.response-area.pulse { animation: pulse-border 2s ease; }
@keyframes pulse-border {
  0% { border-top-color: rgba(255,255,255,0.06); }
  30% { border-top-color: var(--accent); }
  100% { border-top-color: rgba(255,255,255,0.06); }
}
.suggestions-label {
  font-family: var(--font-title);
  font-size: 0.65rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.15em;
  margin-bottom: 8px;
  max-width: 640px;
  margin-left: auto;
  margin-right: auto;
}
.suggestions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 12px;
  max-width: 640px;
  margin-left: auto;
  margin-right: auto;
}
.suggestion-btn {
  background: var(--bg-card);
  border: 1px solid rgba(255,255,255,0.08);
  color: var(--text-light);
  padding: 14px 16px;
  border-radius: var(--radius);
  cursor: pointer;
  font-family: var(--font-story);
  font-size: 0.88rem;
  transition: all var(--transition);
  line-height: 1.35;
  text-align: left;
  min-height: 48px;
  -webkit-tap-highlight-color: transparent;
}
.suggestion-btn::before { content: '▸ '; color: var(--accent); font-weight: bold; }
.suggestion-btn:hover, .suggestion-btn:active {
  background: rgba(198,40,40,0.12);
  border-color: var(--accent-dim);
  color: #fff;
}

.free-input-bar {
  display: flex;
  gap: 8px;
  align-items: center;
  max-width: 640px;
  margin: 0 auto;
}
.free-input-bar input {
  flex: 1;
  background: var(--bg-input);
  border: 1px solid rgba(255,255,255,0.1);
  color: var(--text-light);
  padding: 12px 16px;
  border-radius: var(--radius);
  font-family: var(--font-story);
  font-size: 0.95rem;
  outline: none;
  transition: border-color var(--transition);
  min-height: 48px;
}
.free-input-bar input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(198,40,40,0.15);
}
.free-input-bar input::placeholder { color: var(--text-muted); }

.btn-send {
  background: var(--accent);
  color: #fff;
  border: none;
  width: 48px;
  height: 48px;
  border-radius: var(--radius);
  font-size: 1.1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all var(--transition);
  padding: 0;
  flex-shrink: 0;
}
.btn-send:hover { background: var(--accent-light); }
.btn-send:active { transform: scale(0.95); }

.btn-voice {
  background: none;
  border: 1px solid rgba(255,255,255,0.12);
  color: var(--text-light);
  width: 48px;
  height: 48px;
  border-radius: var(--radius);
  font-size: 1.2rem;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
  flex-shrink: 0;
}
.btn-voice:hover { border-color: var(--accent); }
.btn-voice.listening {
  border-color: var(--red);
  background: rgba(198,40,40,0.15);
  animation: listening-pulse 1.5s ease-in-out infinite;
}
@keyframes listening-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(198,40,40,0.3); }
  50% { box-shadow: 0 0 0 8px rgba(198,40,40,0); }
}

.input-hint {
  text-align: center;
  font-family: var(--font-title);
  font-size: 0.6rem;
  color: var(--text-muted);
  margin-top: 6px;
  letter-spacing: 0.04em;
  opacity: 0.6;
}

/* ─── Speed Control ───────────────────────────────── */
.speed-control { display: flex; align-items: center; gap: 3px; margin-right: 4px; }
.speed-label {
  font-size: 0.55rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-right: 2px;
  display: none;
}
.speed-value {
  font-size: 0.75rem;
  color: var(--gold);
  font-weight: 600;
  min-width: 30px;
  text-align: center;
}
.btn-speed {
  background: var(--bg-card);
  border: 1px solid rgba(255,255,255,0.1);
  color: var(--text-light);
  width: 28px;
  height: 28px;
  border-radius: var(--radius);
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
  line-height: 1;
}
.btn-speed:hover { border-color: var(--accent); color: var(--accent); }

/* ─── Decision Timer ──────────────────────────────── */
.timer-bar {
  position: relative;
  height: 4px;
  background: rgba(255,255,255,0.06);
  border-radius: 2px;
  overflow: visible;
  margin-bottom: 12px;
  max-width: 640px;
  margin-left: auto;
  margin-right: auto;
}
.timer-fill {
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, var(--red), var(--orange), var(--green));
  border-radius: 2px;
  transition: width 1s linear;
}
.timer-text {
  position: absolute;
  right: 0;
  top: -18px;
  font-family: var(--font-title);
  font-size: 0.65rem;
  color: var(--accent);
  font-weight: 600;
}
.timer-bar.urgent .timer-fill {
  background: var(--red);
  animation: timer-flash 0.5s ease-in-out infinite;
}
.timer-bar.paused .timer-fill { opacity: 0.4; }
.timer-bar.paused .timer-text::after { content: ' PAUSED'; }
@keyframes timer-flash {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

/* ─── Timer Toggle ────────────────────────────────── */
.btn-icon.timer-off { opacity: 0.35; }

/* ─── Modals ──────────────────────────────────────── */
.modal {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  z-index: 200;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.modal-backdrop {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.75);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}
.modal-content {
  position: relative;
  width: 100%;
  max-width: 500px;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  z-index: 1;
  background: var(--bg-surface);
  border: 1px solid rgba(255,255,255,0.08);
  border-bottom: none;
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  padding-bottom: var(--safe-bottom);
}
.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 18px 20px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
}
.modal-header h3 {
  font-family: var(--font-title);
  font-size: 1.1rem;
  color: var(--gold);
}
.modal-header .btn-icon { color: var(--text-dim); }
.modal-body {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 16px 20px;
}
.modal-footer {
  padding: 12px 20px;
  border-top: 1px solid rgba(255,255,255,0.06);
}
.rewind-hint {
  font-family: var(--font-story);
  font-style: italic;
  font-size: 0.78rem;
  color: var(--text-muted);
  text-align: center;
}

/* ─── Chapter Entries ─────────────────────────────── */
.chapter-entry {
  padding: 12px 0;
  border-bottom: 1px solid rgba(255,255,255,0.04);
}
.chapter-entry:last-child { border-bottom: none; }
.chapter-entry-header {
  font-family: var(--font-title);
  font-size: 0.72rem;
  color: var(--gold);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  margin-bottom: 4px;
}
.chapter-entry-text {
  font-family: var(--font-story);
  font-size: 0.85rem;
  color: var(--text-dim);
  line-height: 1.5;
  margin-bottom: 6px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.chapter-choice-btn {
  display: inline-block;
  background: rgba(198,40,40,0.1);
  border: 1px solid var(--accent-dim);
  color: var(--accent-light);
  padding: 6px 14px;
  border-radius: var(--radius);
  cursor: pointer;
  font-family: var(--font-title);
  font-size: 0.7rem;
  letter-spacing: 0.05em;
  min-height: 36px;
}
.chapter-choice-btn:hover { background: var(--accent); color: #fff; }
.chapter-choice-label {
  font-family: var(--font-story);
  font-style: italic;
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-bottom: 4px;
}

/* ─── Death Screen ────────────────────────────────── */
#screen-death {
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(ellipse at center, #1a0808 0%, #0a0404 70%);
}
.death-container {
  text-align: center;
  padding: 40px 28px;
  max-width: 420px;
  width: 90%;
}
.death-icon {
  font-size: 4rem;
  margin-bottom: 16px;
  animation: death-pulse 2s ease-in-out infinite;
}
@keyframes death-pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.6; transform: scale(1.05); }
}
.death-title {
  font-family: var(--font-title);
  font-size: clamp(1.6rem, 5vw, 2.2rem);
  color: var(--accent);
  letter-spacing: 0.15em;
  margin-bottom: 16px;
}
.death-text {
  font-family: var(--font-story);
  font-style: italic;
  font-size: 0.95rem;
  color: #aa8888;
  margin-bottom: 24px;
  line-height: 1.6;
}
.death-page {
  font-family: var(--font-title);
  font-size: 0.85rem;
  color: var(--accent-dim);
  letter-spacing: 0.3em;
  margin-bottom: 28px;
  opacity: 0.5;
}
.death-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: center;
}
.death-actions .btn { min-width: 260px; max-width: 100%; }

/* ─── Story Complete Screen ───────────────────────── */
#screen-complete {
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(ellipse at center, #1a1608 0%, var(--bg-dark) 70%);
}
.complete-container {
  text-align: center;
  padding: 40px 28px;
  max-width: 420px;
  width: 90%;
}
.complete-icon {
  font-size: 4rem;
  margin-bottom: 16px;
  animation: complete-glow 3s ease-in-out infinite;
}
@keyframes complete-glow {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.7; transform: scale(1.05); }
}
.complete-title {
  font-family: var(--font-title);
  font-size: clamp(1.6rem, 5vw, 2.2rem);
  color: var(--gold);
  letter-spacing: 0.2em;
  margin-bottom: 16px;
}
.complete-text {
  font-family: var(--font-story);
  font-style: italic;
  font-size: 0.95rem;
  color: var(--text-dim);
  margin-bottom: 16px;
  line-height: 1.6;
}
.complete-stats {
  font-family: var(--font-title);
  font-size: 0.78rem;
  color: var(--text-muted);
  letter-spacing: 0.05em;
  margin-bottom: 28px;
}
.complete-stat-sep { margin: 0 8px; opacity: 0.3; }
.complete-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: center;
}
.complete-actions .btn { min-width: 260px; max-width: 100%; }

/* ─── Loading Overlay ─────────────────────────────── */
.loading-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(10,8,4,0.9);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}
.loading-content { text-align: center; }
.loading-spinner {
  width: 32px;
  height: 32px;
  margin: 0 auto 16px;
  border: 2px solid rgba(255,255,255,0.08);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-content p {
  font-family: var(--font-story);
  font-style: italic;
  color: var(--text-dim);
  font-size: 0.95rem;
}

/* ─── Text Highlighting ───────────────────────────── */
.word { transition: color 0.15s ease; }
.word-spoken { color: var(--text-muted); }
.word-active { color: var(--gold-light); text-shadow: 0 0 6px rgba(240,208,128,0.2); }

/* ─── Narration Loading ───────────────────────────── */
.narration-loading {
  display: flex;
  align-items: center;
  gap: 10px;
  justify-content: center;
  padding: 12px;
  margin-top: 16px;
  font-family: var(--font-story);
  font-style: italic;
  color: var(--text-dim);
  font-size: 0.82rem;
}
.narration-loading-spinner {
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255,255,255,0.06);
  border-top-color: var(--gold);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

/* ─── Ending Continue Button ──────────────────────── */
.btn-ending-continue {
  display: block;
  margin: 24px auto 16px;
  padding: 16px 44px;
  background: var(--accent);
  color: var(--text-light);
  border: none;
  border-radius: var(--radius);
  font-family: var(--font-title);
  font-size: 1rem;
  letter-spacing: 0.06em;
  cursor: pointer;
  transition: all 0.3s ease;
  animation: pulse-glow 2s ease-in-out infinite;
  min-height: 52px;
}
.btn-ending-continue:hover {
  background: var(--accent-light);
  transform: scale(1.03);
}
@keyframes pulse-glow {
  0%, 100% { box-shadow: 0 0 8px rgba(198, 40, 40, 0.3); }
  50% { box-shadow: 0 0 24px rgba(198, 40, 40, 0.6); }
}

/* ─── Narration Upsell Modal ──────────────────────── */
.upsell-body {
  text-align: center;
  padding: 8px 0;
}
.upsell-body p {
  color: var(--text-light);
  margin: 8px 0;
  font-family: var(--font-story);
  font-size: 0.9rem;
  line-height: 1.6;
}
.upsell-option {
  background: var(--bg-card);
  border: 1px solid var(--gold-dim);
  border-radius: var(--radius);
  padding: 18px;
  margin: 18px 0;
}
.upsell-option h4 {
  color: var(--text-light);
  margin: 0 0 8px;
  font-family: var(--font-title);
  font-size: 1rem;
}
.upsell-hint {
  font-size: 0.82rem !important;
  color: var(--text-dim) !important;
}
.upsell-hint a {
  color: var(--accent-light);
  text-decoration: underline;
}
.upsell-key-input {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}
.tts-key-input {
  flex: 1;
  padding: 10px 14px;
  border: 1px solid var(--gold-dim);
  border-radius: var(--radius);
  background: var(--bg-input);
  color: var(--text-light);
  font-family: var(--font-ui);
  font-size: 0.88rem;
  min-height: 44px;
}
.tts-key-input:focus {
  outline: none;
  border-color: var(--gold);
}
.upsell-divider {
  color: var(--text-muted);
  margin: 18px 0;
  font-family: var(--font-title);
  font-size: 0.85rem;
  opacity: 0.5;
}
.btn-full {
  width: 100%;
  justify-content: center;
}

/* ─── Utilities ───────────────────────────────────── */
.hidden { display: none !important; }

/* ─── Scrollbars ──────────────────────────────────── */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 2px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.2); }

/* ═══════════════════════════════════════════════════
   Desktop & Tablet Enhancements
   ═══════════════════════════════════════════════════ */

@media (min-width: 520px) {
  .story-cards {
    gap: 14px;
    padding: 32px 28px;
  }
  .story-card { padding: 24px; }
  .title-header { padding: 80px 32px 32px; }
  .setup-container { padding: 32px 28px 48px; }
  .narrative-area { padding: 36px 32px; }
  .narrative-text { font-size: 1.1rem; }
  .response-area { padding: 14px 20px calc(14px + var(--safe-bottom)); }
  .status-tension-wrap { display: flex; }
  .speed-label { display: block; }

  /* Modal slides up from bottom on phones, centered on tablet+ */
  .modal { align-items: center; }
  .modal-content {
    max-width: 480px;
    border-radius: var(--radius-lg);
    border-bottom: 1px solid rgba(255,255,255,0.08);
  }
}

@media (min-width: 768px) {
  .story-cards {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
    max-width: 840px;
    padding: 36px 32px;
  }
  .story-card {
    border-left: none;
    border-top: 3px solid transparent;
    text-align: center;
  }
  .story-card.genre-fantasy { border-top-color: var(--gold); border-left-color: transparent; }
  .story-card.genre-survival { border-top-color: var(--blue); border-left-color: transparent; }
  .story-card.genre-horror { border-top-color: var(--accent); border-left-color: transparent; }
  .story-card-prompt { text-align: center; }

  .title-header { padding: 100px 40px 40px; }
  .title-footer { max-width: 840px; margin: 0 auto; padding: 20px 32px 48px; }

  .narrative-area { padding: 44px 48px; }
  .narrative-text { font-size: 1.15rem; line-height: 1.9; }

  .story-status { padding: 10px 24px; }
  .response-area { padding: 16px 24px; }

  .suggestions { flex-direction: row; flex-wrap: wrap; }
  .suggestion-btn { flex: 1; min-width: 200px; }
}

@media (min-width: 1024px) {
  .title-header { padding: 120px 48px 48px; }
  .narrative-area { padding: 52px 64px; }
  .narrative-text { font-size: 1.2rem; max-width: 700px; }
}

/* ─── Paywall ──────────────────────────────────────── */

.story-card-lock {
  position: absolute;
  bottom: 12px;
  right: 12px;
  background: rgba(192, 57, 43, 0.9);
  color: #fff;
  font-size: 0.7rem;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 12px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.story-card-free {
  position: absolute;
  bottom: 12px;
  right: 12px;
  background: rgba(39, 174, 96, 0.9);
  color: #fff;
  font-size: 0.7rem;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 12px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.story-card-locked {
  opacity: 0.7;
  position: relative;
}

.story-card-locked:hover {
  opacity: 0.9;
}

.story-card {
  position: relative;
}

.unlock-price {
  text-align: center;
  padding: 24px 0;
}

.unlock-price-amount {
  display: block;
  font-size: 2.2rem;
  font-weight: 700;
  color: var(--gold);
  font-family: var(--font-ui);
}

.unlock-price-label {
  display: block;
  font-size: 0.85rem;
  color: var(--text-dim);
  margin-top: 4px;
}

.btn-full {
  width: 100%;
  padding: 16px;
  font-size: 1.1rem;
}

.unlock-hint {
  text-align: center;
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 16px;
}

/* Payment success toast */
.payment-toast {
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translateX(-50%) translateY(-100px);
  background: var(--bg-card);
  border: 1px solid var(--gold);
  color: var(--text);
  padding: 16px 32px;
  border-radius: var(--radius);
  font-family: var(--font-ui);
  font-size: 1rem;
  z-index: 200;
  transition: transform 0.4s ease;
  box-shadow: 0 8px 30px rgba(0,0,0,0.5);
}

.payment-toast.show {
  transform: translateX(-50%) translateY(0);
}

.unlock-disclaimer {
  background: rgba(212, 168, 67, 0.1);
  border: 1px solid var(--gold-dim);
  border-radius: var(--radius);
  padding: 12px 16px;
  margin-top: 16px;
  font-size: 0.78rem;
  color: var(--text-dim);
  line-height: 1.5;
}

.unlock-disclaimer strong {
  color: var(--gold);
}
