:root {
  --bg-deep: #0b0d13;
  --bg-surface: #131722;
  --bg-card: #191f2e;
  --bg-elevated: #22293d;
  --border-subtle: rgba(255, 255, 255, 0.08);
  --border-gold: rgba(245, 196, 105, 0.35);
  --text-main: #f4f6fb;
  --text-muted: #98a2b8;
  --gold: #f5c469;
  --gold-strong: #e8a838;
  --rose: #f43f5e;
  --cyan: #38bdf8;
  --emerald: #10b981;
  --radius-lg: 18px;
  --radius-md: 12px;
  --shadow-lg: 0 20px 45px rgba(0, 0, 0, 0.45);
}

*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: 'Plus Jakarta Sans', system-ui, sans-serif;
  background: radial-gradient(circle at top right, #1b162c 0%, var(--bg-deep) 55%);
  color: var(--text-main);
  min-height: 100vh;
  line-height: 1.55;
}

h1, h2, h3, .brand-name {
  font-family: 'Cinzel', Georgia, serif;
  letter-spacing: 0.02em;
}

.hidden {
  display: none !important;
}

.muted {
  color: var(--text-muted);
  font-size: 0.92rem;
}

/* Top Navigation */
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  background: rgba(11, 13, 19, 0.88);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border-subtle);
}

.topbar-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 12px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
}

.brand-logo {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--gold), var(--rose));
  color: #0b0d13;
  font-weight: 800;
  display: grid;
  place-items: center;
}

.brand-name {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text-main);
}

.nav-links {
  display: flex;
  gap: 6px;
}

.nav-btn {
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-muted);
  padding: 8px 14px;
  border-radius: 10px;
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  transition: 0.2s;
}

.nav-btn:hover,
.nav-btn.active {
  color: var(--text-main);
  background: var(--bg-elevated);
  border-color: var(--border-subtle);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.pill-btn,
.icon-btn {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  color: var(--text-main);
  padding: 7px 12px;
  border-radius: 999px;
  font-weight: 600;
  font-size: 0.86rem;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  cursor: pointer;
  transition: transform 0.15s, border-color 0.2s, background 0.2s;
}

.pill-btn > span {
  display: inline-flex;
  align-items: center;
  line-height: 1;
}

.pill-btn .pill-icon {
  transform: translateY(-1px);
  font-size: 1.05em;
}

.gem-pill {
  border-color: rgba(56, 189, 248, 0.35);
}

.gem-pill > span:last-child {
  transform: translateY(-2px);
}

.gem-pill:hover {
  border-color: var(--gold);
  background: rgba(245, 196, 105, 0.14);
  transform: translateY(-1px);
}

.key-pill {
  border-color: rgba(245, 196, 105, 0.45);
  background: rgba(245, 196, 105, 0.08);
  cursor: default;
}

.account-pill:hover,
.streak-pill:hover,
.icon-btn:hover {
  border-color: var(--gold);
}

/* Custom Language Switcher */
.lang-dropdown-wrap {
  position: relative;
}

.lang-pill {
  border-color: rgba(148, 163, 184, 0.35);
  background: rgba(255, 255, 255, 0.04);
}

.lang-pill:hover {
  border-color: var(--gold);
  background: rgba(245, 196, 105, 0.12);
}

.lang-menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  min-width: 155px;
  background: #131724;
  border: 1px solid var(--border-gold);
  border-radius: 12px;
  padding: 6px;
  box-shadow: 0 14px 32px rgba(0, 0, 0, 0.65);
  z-index: 999;
  display: grid;
  gap: 3px;
}

[dir="rtl"] .lang-menu {
  right: auto;
  left: 0;
}

.lang-option {
  background: transparent;
  border: none;
  color: var(--text-main);
  padding: 9px 12px;
  border-radius: 8px;
  text-align: left;
  font-size: 0.9rem;
  font-family: inherit;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: background 0.15s, color 0.15s;
}

[dir="rtl"] .lang-option {
  text-align: right;
}

.lang-option:hover,
.lang-option.active {
  background: rgba(245, 196, 105, 0.16);
  color: var(--gold);
  font-weight: 600;
}

/* Main Views */
.main-wrap {
  max-width: 1200px;
  margin: 0 auto;
  padding: 28px 20px 60px;
}

.view {
  display: none;
  animation: fadeIn 0.25s ease;
}

.view.active {
  display: block;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Buttons & Badges */
.btn-primary {
  background: linear-gradient(135deg, var(--gold), var(--gold-strong));
  color: #12100c;
  border: none;
  padding: 11px 20px;
  border-radius: 12px;
  font-weight: 700;
  font-size: 0.92rem;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.2s;
}

.btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 8px 20px rgba(245, 196, 105, 0.28);
}

.btn-secondary {
  background: var(--bg-elevated);
  color: var(--text-main);
  border: 1px solid var(--border-subtle);
  padding: 11px 18px;
  border-radius: 12px;
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
}

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

.btn-danger {
  background: rgba(244, 63, 94, 0.14);
  color: #fda4af;
  border: 1px solid rgba(244, 63, 94, 0.35);
  padding: 10px 16px;
  border-radius: 12px;
  font-weight: 600;
  cursor: pointer;
}

.full-width {
  width: 100%;
}

.badge-gold {
  display: inline-block;
  background: rgba(245, 196, 105, 0.14);
  color: var(--gold);
  border: 1px solid var(--border-gold);
  padding: 4px 12px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.promo-chip {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.promo-delete-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  min-width: 20px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.7rem;
  font-weight: 700;
  line-height: 1;
  border-radius: 50%;
  cursor: pointer;
  opacity: 0.6;
  transition: all 0.15s ease;
  flex-shrink: 0;
}

.promo-delete-btn:hover {
  background: rgba(255, 68, 68, 0.18);
  color: #ff4444;
  opacity: 1;
}

.promo-delete-btn:active {
  transform: scale(0.92);
}

/* Touch-friendly sizing for mobile */
@media (max-width: 480px) {
  .promo-delete-btn {
    width: 28px;
    height: 28px;
    min-width: 28px;
    font-size: 0.8rem;
  }
}

/* Hero Banner & Profile Card */
.hero-banner {
  background: linear-gradient(135deg, rgba(28, 33, 52, 0.9), rgba(19, 23, 34, 0.95));
  border: 1px solid var(--border-gold);
  border-radius: var(--radius-lg);
  padding: 32px;
  display: grid;
  grid-template-columns: 1.5fr 0.8fr;
  gap: 24px;
  align-items: center;
  margin-bottom: 34px;
  box-shadow: var(--shadow-lg);
}

.hero-text h1 {
  font-size: clamp(1.7rem, 3vw, 2.4rem);
  margin: 12px 0;
  line-height: 1.2;
}

.hero-text p {
  color: var(--text-muted);
  margin-bottom: 20px;
  max-width: 560px;
}

.hero-cta-row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.hero-preview-card {
  background: var(--bg-deep);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 18px;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 10px;
}

#hero-avatar-svg {
  width: 96px;
  height: 96px;
  margin: 0 auto 6px;
  border-radius: 50%;
  background: radial-gradient(circle at 50% 30%, rgba(56, 189, 248, 0.22), rgba(15, 23, 42, 0.9) 72%);
  border: 2px solid rgba(56, 189, 248, 0.35);
  box-shadow: 0 0 24px rgba(56, 189, 248, 0.18), inset 0 0 12px rgba(255, 255, 255, 0.06);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  transition: transform 0.25s ease, box-shadow 0.25s ease;
}

#hero-avatar-svg:hover {
  transform: translateY(-2px) scale(1.03);
  box-shadow: 0 0 30px rgba(56, 189, 248, 0.3), inset 0 0 14px rgba(255, 255, 255, 0.1);
}

#hero-avatar-svg svg {
  width: 86%;
  height: 86%;
  transform: translateY(6px);
}

#hero-char-name {
  font-size: 1.2rem;
  font-weight: 700;
  letter-spacing: 0.01em;
  color: #f8fafc;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

#hero-char-trait {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.hero-trait-badge {
  font-size: 0.78rem;
  font-weight: 600;
  color: #fbbf24;
  background: rgba(251, 191, 36, 0.12);
  border: 1px solid rgba(251, 191, 36, 0.3);
  padding: 4px 10px;
  border-radius: 999px;
}

.hero-stat-pill {
  font-size: 0.8rem;
  font-weight: 600;
  color: #e2e8f0;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  padding: 4px 10px;
  border-radius: 999px;
}

.avatar-frame-sm { width: 110px; height: 125px; }
.avatar-frame-md { width: 140px; height: 160px; margin: 0 auto 12px; }
.avatar-frame-lg { width: 220px; height: 250px; margin: 0 auto; }

/* Books Grid */
.section-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 16px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.filter-pills {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.filter-chip {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  color: var(--text-muted);
  padding: 7px 14px;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
}

.filter-chip.active,
.filter-chip:hover {
  background: rgba(245, 196, 105, 0.16);
  border-color: var(--gold);
  color: var(--gold);
}

.books-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(310px, 1fr));
  gap: 22px;
}

.book-card {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: transform 0.2s, border-color 0.2s;
}

.book-card:hover {
  transform: translateY(-4px);
  border-color: var(--border-gold);
}

.book-cover {
  height: 155px;
  padding: 18px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.book-body {
  padding: 20px;
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 16px;
}

.book-body h3 {
  font-size: 1.25rem;
  margin-bottom: 6px;
}

/* Chapter Hub */
.book-hub-banner {
  background: linear-gradient(135deg, #1b1320 0%, #121622 100%);
  border: 1px solid var(--border-gold);
  border-radius: var(--radius-lg);
  padding: 26px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 20px;
  flex-wrap: wrap;
  margin-bottom: 24px;
}

.hub-progress-box {
  background: var(--bg-deep);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 16px 22px;
  text-align: center;
}

.chapters-list {
  display: grid;
  gap: 14px;
}

.chapter-row {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 18px 22px;
  display: flex;
  flex-wrap: nowrap;
  justify-content: space-between;
  align-items: center;
  gap: 20px;
  transition: border-color 0.2s, transform 0.15s;
}

.chapter-row:hover {
  border-color: var(--border-gold);
  transform: translateY(-2px);
}

.chapter-row.unlocked {
  border-left: 4px solid var(--gold);
}

.chapter-row.completed {
  border-left: 4px solid var(--emerald);
}

.chapter-row.prereq-locked {
  opacity: 0.6;
}

.chapter-info {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 16px;
}

.chapter-num {
  font-family: 'Cinzel', Georgia, serif;
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--gold);
  flex-shrink: 0;
}

.chapter-action {
  flex-shrink: 0;
}

/* Character Creator */
.creator-grid {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 24px;
}

.creator-stage,
.creator-controls,
.panel-box {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 22px;
}

.creator-stage {
  text-align: center;
  height: fit-content;
}

.portrait-backdrop {
  background: radial-gradient(circle, #28314b 0%, #111521 80%);
  border-radius: var(--radius-md);
  padding: 16px;
  margin-bottom: 14px;
}

.control-group {
  margin-bottom: 18px;
}

.control-group label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.input-field {
  width: 100%;
  background: var(--bg-deep);
  border: 1px solid var(--border-subtle);
  color: var(--text-main);
  padding: 11px 14px;
  border-radius: 10px;
  font-size: 0.95rem;
}

.input-field:focus {
  outline: none;
  border-color: var(--gold);
}

.gender-toggle {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.gender-btn {
  background: var(--bg-deep);
  border: 1px solid var(--border-subtle);
  color: var(--text-muted);
  padding: 10px;
  border-radius: 10px;
  font-weight: 700;
  cursor: pointer;
}

.gender-btn.active {
  border-color: var(--gold);
  color: var(--gold);
  background: rgba(245, 196, 105, 0.12);
}

.swatch-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.swatch-btn {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
}

.swatch-btn.active {
  border-color: var(--gold);
  transform: scale(1.12);
}

.option-grid,
.trait-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(145px, 1fr));
  gap: 10px;
}

.choice-pill {
  background: var(--bg-deep);
  border: 1px solid var(--border-subtle);
  color: var(--text-main);
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 0.86rem;
  font-weight: 600;
  text-align: left;
  cursor: pointer;
}

.choice-pill.active {
  border-color: var(--gold);
  background: rgba(245, 196, 105, 0.12);
  color: var(--gold);
}

/* Story Reader & Visual Novel Dialogue */
.reader-shell {
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-gold);
  padding: 20px;
  min-height: 540px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  background: linear-gradient(180deg, #171c2c 0%, #0d1018 100%);
  box-shadow: var(--shadow-lg);
}

.reader-hud {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.hud-btn {
  background: rgba(11, 13, 19, 0.75);
  border: 1px solid var(--border-subtle);
  color: var(--text-main);
  padding: 7px 12px;
  border-radius: 9px;
  font-size: 0.84rem;
  font-weight: 600;
  cursor: pointer;
}

.hud-btn.active {
  border-color: var(--gold);
  color: var(--gold);
}

.progress-bar-wrap,
.chapter-progress-wrap,
.reader-progress-wrap,
#reader-progress-bar,
#chapter-progress-bar {
  display: none !important;
}

.hud-title {
  display: block;
  font-size: 0.82rem;
  color: var(--gold);
  font-weight: 700;
  margin-bottom: 5px;
  text-align: center;
}

.relationship-bar {
  display: flex;
  gap: 10px;
  justify-content: center;
  margin: 10px 0;
  flex-wrap: wrap;
}

.rel-badge {
  background: rgba(11, 13, 19, 0.72);
  border: 1px solid var(--border-subtle);
  padding: 4px 12px;
  border-radius: 999px;
  font-size: 0.8rem;
}

.speaker-portraits {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  padding: 0 24px;
  min-height: 155px;
}

.stage-char {
  width: 135px;
  height: 150px;
  transition: transform 0.25s, opacity 0.25s;
}

.stage-char.dimmed {
  opacity: 0.45;
  transform: scale(0.94);
}

.dialogue-card,
.dialogue-box,
#dialogue-box {
  background: rgba(15, 19, 29, 0.94);
  border: 1px solid var(--border-gold);
  border-radius: var(--radius-md);
  padding: 20px 24px;
  cursor: pointer;
  margin-top: -8px;
  display: flex;
  flex-direction: column;
}

.speaker-tag {
  display: inline-block;
  background: var(--gold);
  color: #110f0a;
  font-weight: 800;
  font-size: 0.8rem;
  padding: 3px 10px;
  border-radius: 6px;
  margin-bottom: 10px;
}

.dialogue-text {
  font-size: 1.05rem;
  min-height: 54px;
}

/* Player ({name}) -> Left Side */
.align-left {
  align-items: flex-start;
  text-align: left;
  border-left: 3px solid var(--cyan) !important;
  margin-right: auto;
}

.align-left #speaker-name-tag {
  align-self: flex-start;
  background: rgba(56, 189, 248, 0.16);
  color: #7dd3fc;
  border: 1px solid rgba(56, 189, 248, 0.35);
}

/* Narrator -> Center */
.align-center {
  align-items: center;
  text-align: center;
  margin-left: auto;
  margin-right: auto;
}

.align-center #speaker-name-tag {
  align-self: center;
  background: rgba(255, 255, 255, 0.06);
  color: #cbd5e1;
}

.align-center #dialogue-text {
  font-style: italic;
  color: #e2e8f0;
}

/* Other Characters (Caleb, Maya, Toby, etc.) -> Right Side */
.align-right {
  align-items: flex-end;
  text-align: right;
  border-right: 3px solid var(--rose) !important;
  margin-left: auto;
}

.align-right #speaker-name-tag {
  align-self: flex-end;
  background: rgba(244, 63, 94, 0.16);
  color: #fda4af;
  border: 1px solid rgba(244, 63, 94, 0.35);
}

/* Important Story Locations in Crimson Red */
.place-highlight {
  color: #f87171;
  font-weight: 700;
  text-shadow: 0 0 10px rgba(239, 68, 68, 0.35);
}

/* Pixelberry "Choices"-Style Speech Bubble Pop & Tap Indicator */
@keyframes choicesBubblePop {
  0% {
    opacity: 0;
    transform: translateY(12px) scale(0.94);
  }
  70% {
    opacity: 1;
    transform: translateY(-2px) scale(1.01);
  }
  100% {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.choices-bubble-pop {
  animation: choicesBubblePop 0.25s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

@keyframes choicesCaretBounce {
  0%, 100% { transform: translateY(0); opacity: 0.65; }
  50% { transform: translateY(3px); opacity: 1; }
}

#tap-continue-hint {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 8px;
  font-size: 0.78rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #94a3b8;
  animation: choicesCaretBounce 1.2s ease-in-out infinite;
}

#tap-continue-hint::after {
  content: '▾';
  font-size: 1rem;
  color: #fbbf24;
}

.timed-bar {
  height: 6px;
  background: rgba(244, 63, 94, 0.25);
  border-radius: 999px;
  overflow: hidden;
  margin-top: 12px;
}

.timed-fill {
  height: 100%;
  background: var(--rose);
  width: 100%;
}

.choices-container {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}

.story-choice-btn {
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  color: var(--text-main);
  padding: 13px 16px;
  border-radius: 12px;
  text-align: left;
  font-weight: 600;
  font-size: 0.94rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  transition: 0.18s;
}

.story-choice-btn:hover {
  border-color: var(--gold);
  background: #2a334d;
}

.story-choice-btn.premium {
  border-color: rgba(56, 189, 248, 0.5);
  background: linear-gradient(90deg, rgba(56, 189, 248, 0.14), var(--bg-elevated));
}

.story-choice-btn.trait-locked {
  border-color: rgba(245, 196, 105, 0.5);
}

/* Chapter Recap Overlay */
.recap-card {
  background: rgba(13, 16, 25, 0.96);
  border: 1px solid var(--border-gold);
  border-radius: var(--radius-lg);
  padding: 30px;
  max-width: 640px;
  margin: 28px auto;
  text-align: center;
  box-shadow: var(--shadow-lg);
}

.recap-body {
  color: var(--text-main);
  font-size: 1.02rem;
  line-height: 1.7;
  margin: 16px 0 24px;
  background: rgba(255, 255, 255, 0.03);
  padding: 18px;
  border-radius: 12px;
  border-left: 3px solid var(--gold);
  text-align: left;
}

/* Ending & Stats */
.ending-card,
.auth-card {
  max-width: 680px;
  margin: 0 auto;
  background: var(--bg-card);
  border: 1px solid var(--border-gold);
  border-radius: var(--radius-lg);
  padding: 32px;
  text-align: center;
}

.ending-rewards {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin: 22px 0;
}

.reward-box {
  background: var(--bg-deep);
  border: 1px solid var(--border-subtle);
  border-radius: 12px;
  padding: 14px;
}

.reward-box span {
  display: block;
  font-size: 0.82rem;
  color: var(--text-muted);
}

.reward-box strong {
  font-size: 1.25rem;
  color: var(--gold);
}

.ending-choices-section {
  text-align: left;
  margin-top: 24px;
}

.stat-row-card {
  background: var(--bg-deep);
  border: 1px solid var(--border-subtle);
  border-radius: 12px;
  padding: 14px 16px;
  margin-top: 12px;
}

.stat-bar-track {
  height: 8px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 999px;
  overflow: hidden;
  margin: 8px 0 4px;
}

.stat-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--gold), var(--rose));
}

.ending-actions {
  display: flex;
  gap: 12px;
  justify-content: center;
  margin-top: 24px;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(185px, 1fr));
  gap: 14px;
  margin-bottom: 22px;
}

.kpi-card {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 18px;
}

.kpi-card span {
  font-size: 0.82rem;
  color: var(--text-muted);
}

.kpi-card strong {
  display: block;
  font-size: 1.5rem;
  color: var(--gold);
  margin-top: 4px;
}

.stats-tabs,
.admin-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.achieved-panel {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 22px;
}

/* Auth & Profile */
.auth-card {
  max-width: 460px;
  text-align: left;
}

.auth-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 20px;
}

.auth-tab {
  background: var(--bg-deep);
  border: 1px solid var(--border-subtle);
  color: var(--text-muted);
  padding: 10px;
  border-radius: 10px;
  font-weight: 700;
  cursor: pointer;
}

.auth-tab.active {
  border-color: var(--gold);
  color: var(--gold);
}

.guest-divider {
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--border-subtle);
  text-align: center;
}

.link-btn {
  background: none;
  border: none;
  color: var(--gold);
  font-weight: 700;
  cursor: pointer;
  font-size: 0.92rem;
}

.guest-warning {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 6px;
}

.profile-grid {
  display: grid;
  grid-template-columns: 300px 1fr;
  gap: 22px;
}

.profile-card {
  background: var(--bg-card);
  border: 1px solid var(--border-gold);
  border-radius: var(--radius-lg);
  padding: 24px;
  text-align: center;
  height: fit-content;
}

.profile-metrics {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin: 18px 0;
  background: var(--bg-deep);
  padding: 12px;
  border-radius: 12px;
}

.profile-metrics strong {
  display: block;
  color: var(--gold);
  font-size: 1.15rem;
}

.profile-metrics span {
  font-size: 0.78rem;
  color: var(--text-muted);
}

.profile-actions {
  display: grid;
  gap: 10px;
}

.profile-right-col {
  display: grid;
  gap: 20px;
}

.achievements-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 12px;
  margin-top: 14px;
}

.ach-card {
  background: var(--bg-deep);
  border: 1px solid var(--border-subtle);
  border-radius: 12px;
  padding: 14px;
  opacity: 0.52;
}

.ach-card.unlocked {
  opacity: 1;
  border-color: var(--border-gold);
}

.form-row-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.form-feedback {
  font-size: 0.86rem;
  margin-bottom: 10px;
  min-height: 20px;
}

/* Admin Tables & Modals */
.table-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

.search-sm {
  max-width: 240px;
}

.table-responsive {
  overflow-x: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.data-table th,
.data-table td {
  padding: 12px 10px;
  border-bottom: 1px solid var(--border-subtle);
  text-align: left;
}

.data-table th {
  color: var(--text-muted);
  font-size: 0.8rem;
  text-transform: uppercase;
}

.promo-chips-list {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 14px;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(5, 7, 12, 0.78);
  backdrop-filter: blur(6px);
  z-index: 80;
  display: grid;
  place-items: center;
  padding: 20px;
}

.modal-box {
  background: var(--bg-card);
  border: 1px solid var(--border-gold);
  border-radius: var(--radius-lg);
  padding: 24px;
  width: 100%;
  max-width: 480px;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
}

.log-scroll {
  max-height: 320px;
  overflow-y: auto;
  display: grid;
  gap: 10px;
}

.log-item {
  background: var(--bg-deep);
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 0.88rem;
}

.streak-days-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
  margin: 16px 0;
}

.streak-day {
  background: var(--bg-deep);
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  padding: 8px 4px;
  text-align: center;
  font-size: 0.76rem;
}

.streak-day.claimed {
  border-color: var(--gold);
  color: var(--gold);
}

.promo-redeem-box {
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid var(--border-subtle);
}

#toast-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 100;
  display: grid;
  gap: 8px;
}

.toast {
  background: var(--bg-elevated);
  border: 1px solid var(--gold);
  color: var(--text-main);
  padding: 11px 16px;
  border-radius: 12px;
  font-size: 0.88rem;
  font-weight: 600;
  box-shadow: var(--shadow-lg);
}

@media (max-width: 820px) {
  .hero-banner,
  .creator-grid,
  .profile-grid,
  .form-row-2 {
    grid-template-columns: 1fr;
  }

  .chapter-row {
    flex-wrap: wrap;
  }
}
.pw-wrap {
  position: relative;
  width: 100%;
  margin-bottom: 14px;
}
.pw-wrap input {
  margin-bottom: 0;
  padding-right: 42px;
}
.pw-toggle {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  width: auto;
  padding: 4px 6px;
  background: transparent;
  color: #94a3b8;
  font-size: 0.95rem;
  line-height: 1;
}
.pw-toggle:hover {
  background: transparent;
  color: #fbbf24;
}


/* Phase 3A V2 — cinematic ILID Chapter 1 composition */
.reader-shell.ilid-cinematic {
  min-height: 540px;
  justify-content: flex-start;
  gap: 8px;
}
.ilid-cinematic .relationship-bar { margin: 4px 0; min-height: 26px; }
.ilid-cinematic .speaker-portraits {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  justify-items: center;
  align-items: end;
  padding: 0 5%;
  min-height: 0;
  height: clamp(300px, 52vh, 440px);
}
.ilid-cinematic .stage-char {
  width: 100%;
  max-width: 340px;
  height: 100%;
  min-width: 0;
  transform-origin: bottom center;
}
.ilid-cinematic .stage-char > svg { display: block; width: 100%; height: 100%; }
.ilid-cinematic .stage-char.dimmed { opacity: .78; transform: none; }
.ilid-cinematic .dialogue-card {
  position: relative;
  z-index: 1;
  width: 100%;
  box-sizing: border-box;
  margin-top: -2px;
  padding: 12px 20px;
  background: rgba(15, 19, 29, .91);
}
.ilid-cinematic .speaker-tag { margin-bottom: 5px; }
.ilid-cinematic .dialogue-text { min-height: 0; margin: 0; line-height: 1.55; }
.ilid-cinematic #tap-continue-hint { margin-top: 5px; }
@media (max-width: 600px) {
  .reader-shell.ilid-cinematic { padding: 10px; min-height: 0; }
  .ilid-cinematic .speaker-portraits { padding: 0; height: clamp(210px, 42vh, 310px); }
  .ilid-cinematic .dialogue-card { padding: 12px; }
  .ilid-cinematic .dialogue-text { font-size: .98rem; }
}
@media (prefers-reduced-motion: reduce) {
  .ilid-cinematic .stage-char { transition: none; }
}

/* ILID choice feedback: non-blocking, no numeric scores. */
.ilid-feedback { width: min(360px, calc(100vw - 40px)); background: #141820; border: 1px solid #68583e; border-radius: 12px; padding: 12px 16px; box-shadow: 0 8px 28px #0007; pointer-events: none; animation: ilid-feedback-in .25s ease-out; transition: opacity .35s; }
.ilid-feedback.leaving { opacity: 0; }
.ilid-feedback-row { display: flex; align-items: center; gap: 12px; padding: 8px 0; color: #c5a371; }
.ilid-feedback-row + .ilid-feedback-row { border-top: 1px solid #ffffff18; }
.ilid-feedback-row.positive { color: #76d5a0; }
.ilid-feedback-row.negative { color: #ff8c91; }
.ilid-feedback-icon { font-size: 25px; width: 28px; text-align: center; flex-shrink: 0; }
.ilid-feedback-row strong { display: block; color: #f1f1f4; font-size: .9rem; }
.ilid-feedback-row small { display: block; color: inherit; font-size: .8rem; margin-top: 3px; }
@keyframes ilid-feedback-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
@media (prefers-reduced-motion: reduce) { .ilid-feedback { animation: none; transition: none; } }

/* Phase 4: outdoor rainfall, non-interactive and reduced-motion safe. */
#ilid-rain-layer { position:absolute; inset:0; z-index:-1; pointer-events:none; overflow:hidden; border-radius:inherit; background-image:repeating-linear-gradient(112deg,transparent 0 34px,rgba(190,211,225,.22) 35px,transparent 36px 62px); background-size:130px 180px; animation:ilid-rain-fall .65s linear infinite; }
@keyframes ilid-rain-fall { to { background-position:-65px 180px; } }
@media(prefers-reduced-motion:reduce){#ilid-rain-layer{animation:none;}}

/* Approved V4 creature effects */
#ilid-entity-layer{position:absolute;inset:0;display:flex;justify-content:center;align-items:center;pointer-events:none;z-index:-1;animation:none!important;transform:none!important;opacity:1!important;background:none!important}#ilid-entity-layer svg{width:100%;height:100%;overflow:visible;transform-origin:50% 50%;transform:scale(1);transition:transform 2.6s cubic-bezier(.3,.05,.2,1),opacity 2s ease;animation:none!important}#ilid-entity-layer[data-mode=awakened] svg{transform:scale(1.15)}#ilid-entity-layer[data-mode=kneeling] svg{transform:translateY(8%) scale(.85,.66)}#ilid-entity-layer[data-mode=dissolving] svg{opacity:0}#ilid-entity-head{transform-origin:300px 178px;transition:transform .7s ease}#ilid-entity-layer[data-mode=tilted] #ilid-entity-head{transform:rotate(90deg)}#ilid-entity-burn,#ilid-entity-blind,#ilid-entity-rage{transition:opacity 1s ease;opacity:0}#ilid-entity-layer[data-mode=burned] #ilid-entity-burn,#ilid-entity-layer[data-mode=blind] #ilid-entity-blind{opacity:1}#ilid-entity-layer[data-mode=awakened] #ilid-entity-rage{opacity:.8}#cinematic-shade{position:absolute;inset:0;pointer-events:none;z-index:-1;background:radial-gradient(ellipse at 50% 45%,transparent 10%,#03080c 100%);opacity:.12;transition:opacity 2.6s}#reader-backdrop[data-awake=true] #cinematic-shade{opacity:.72}#ilid-entity-layer[data-mode=awakened] #ilid-entity-creature>g:first-child{animation:root-breathe 3.8s ease-in-out infinite;transform-origin:300px 440px}@keyframes root-breathe{50%{transform:scaleX(1.025)}}@media(prefers-reduced-motion:reduce){#ilid-entity-layer svg,#ilid-entity-head,#cinematic-shade{transition:none!important}#ilid-entity-creature>g{animation:none!important}}

#cinematic-fog{position:absolute;inset:0;z-index:0;pointer-events:none;overflow:hidden;opacity:.12;transition:opacity 2.6s ease}
#cinematic-fog::before,#cinematic-fog::after{content:"";position:absolute;inset:35% -20% -15%;background:radial-gradient(ellipse at 25% 65%,#a4b8b44a,transparent 55%),radial-gradient(ellipse at 75% 80%,#a4b8b438,transparent 50%);animation:mist-drift 12s ease-in-out infinite alternate}
#cinematic-fog::after{animation-direction:alternate-reverse;animation-duration:17s;opacity:.65}
#reader-backdrop[data-awake=true] #cinematic-fog{opacity:.8}
@keyframes mist-drift{from{transform:translateX(-5%)}to{transform:translateX(5%)}}
#ilid-entity-layer[data-mode=awakened]{animation:awakening-tremor .65s ease-in-out 1!important}
@keyframes awakening-tremor{0%,100%{left:0;right:0}20%,60%{left:-3px;right:3px}40%,80%{left:3px;right:-3px}}
#ilid-entity-layer[data-mode=kneeling] #ilid-entity-head{transform:rotate(13deg) translateY(8px)}
#ilid-entity-layer[data-mode=dissolving] svg{filter:blur(5px);transition:transform 2.6s ease,opacity 2.8s ease,filter 2.8s ease}
@media(prefers-reduced-motion:reduce){#cinematic-fog,#ilid-entity-layer svg{transition:none!important}#cinematic-fog::before,#cinematic-fog::after,#ilid-entity-layer[data-mode=awakened]{animation:none!important}}

.reader-shell.ilid-cinematic { overflow:hidden; }

/* Phase 4C: finale-only atmosphere, no layout changes. */
#view-ending[data-ilid-finale="broken"] .ending-card {background:linear-gradient(155deg,#252b32,#131722 75%);border-color:#84909c;}
#view-ending[data-ilid-finale="fulfilled"] .ending-card {background:radial-gradient(ellipse at top,#50452a,#131722 70%);border-color:#c9aa65;}
#view-ending[data-ilid-finale="rewritten"] .ending-card {background:radial-gradient(ellipse at top,#594034,#191f2e 75%);border-color:#e0ad80;}

/* Phase 5A: phone layouts only; desktop composition is unchanged. */
@media (max-width: 600px) {
  .topbar-inner { padding: 8px 10px; gap: 8px; }
  .topbar-actions, .nav-links { flex-wrap: wrap; gap: 5px; max-width: 100%; }
  .nav-btn, .pill-btn, .icon-btn { min-height: 44px; }
  .main-wrap { padding: 12px 8px 28px; }
  .books-grid { grid-template-columns: minmax(0,1fr); }
  .chapter-info { min-width: 0; flex-basis: 100%; overflow-wrap: anywhere; }
  .chapter-row { padding: 14px; gap: 12px; }
  .chapter-action { max-width: 100%; }
  .reader-shell.ilid-cinematic { padding: 8px; gap: 4px; border-radius: 12px; }
  .ilid-cinematic .reader-hud { gap: 6px; flex-wrap: wrap; }
  .ilid-cinematic .hud-controls { display: flex; gap: 5px; flex-wrap: wrap; }
  .ilid-cinematic .hud-btn { min-height: 44px; padding: 8px 10px; }
  .ilid-cinematic .relationship-bar:empty { display: none; }
  .ilid-cinematic .speaker-portraits { height: clamp(190px, 38svh, 300px); gap: 0; }
  .ilid-cinematic .dialogue-card { padding: 12px; min-height: 100px; }
  .ilid-cinematic .dialogue-text { font-size: 1rem; line-height: 1.55; overflow-wrap: anywhere; }
  .ilid-cinematic .choices-container { gap: 8px; margin-top: 10px; }
  .ilid-cinematic .story-choice-btn { min-height: 48px; width: 100%; padding: 12px; font-size: 1rem; line-height: 1.4; }
  .ilid-cinematic .story-choice-btn > span:first-child { min-width: 0; overflow-wrap: anywhere; }
  .ilid-cinematic .story-choice-btn .badge-gold { flex-shrink: 0; white-space: nowrap; }
  .ilid-cinematic #ilid-entity-layer { bottom: auto; height: clamp(240px, 48svh, 370px); top: 44px; }
  .ilid-cinematic .recap-card { padding: 16px; margin: 12px auto; }
  .modal-overlay { padding: 10px; }
  .modal-box { min-width: 0; max-height: 90vh; max-height: 90dvh; overflow-y: auto; padding: 16px; }
  .input-field { font-size: 16px; }
  .btn-primary, .btn-secondary, .btn-danger { min-height: 44px; }
}
@media (max-width: 600px) and (max-height: 500px) {
  .ilid-cinematic .speaker-portraits { height: 180px; }
  .ilid-cinematic #ilid-entity-layer { height: 210px; }
}

/* Homepage last-played story card only */
.hero-story-card {padding:0;gap:0;overflow:hidden;min-width:0;align-items:stretch;text-align:left;}
.hero-story-card[hidden] {display:none;}
.hero-story-cover {width:100%;aspect-ratio:16/9;background-size:cover!important;background-position:center!important;}
.hero-story-meta {padding:16px;display:flex;flex-direction:column;gap:10px;}
.hero-story-meta h3,.hero-story-meta p {margin:0;overflow-wrap:anywhere;}

/* Approved ILID cover artwork; existing card dimensions retained. */
.book-cover.ilid-cover {background-image:url("assets/covers/ilid-wide.webp") !important;background-size:cover !important;background-position:center !important;}
.book-hub-banner.ilid-hub-cover {background-image:linear-gradient(90deg,rgba(11,13,19,.94),rgba(11,13,19,.48)),url("assets/covers/ilid.webp");background-size:cover;background-position:center 48%;}

/* Phase 5A revision: phone-only alignment and flexible reader composition. */
@media (max-width:600px) {
  .topbar-inner { flex-direction:column; justify-content:center; align-items:center; gap:6px; padding:10px 8px; }
  .brand,.nav-links,.topbar-actions,.lang-dropdown-wrap { justify-content:center; align-items:center; }
  .lang-dropdown-wrap { display:flex; flex-wrap:wrap; gap:6px; max-width:100%; }
  .topbar-actions { width:100%; }
  .pill-btn { padding:7px 9px; }
  .main-wrap { padding:12px 10px 24px; }
  .hero-banner { grid-template-columns:minmax(0,1fr); padding:18px; gap:18px; margin-bottom:24px; }
  .hero-text,.hero-story-meta { text-align:center; }
  .hero-text p { margin:0 auto 16px; }
  .hero-cta-row,.filter-pills { justify-content:center; }
  .hero-story-meta { align-items:center; }
  .hero-story-meta button { width:100%; }
  #view-library .section-header { justify-content:center; align-items:center; text-align:center; gap:12px; }
  .filter-chip { min-height:44px; }
  .book-hub-banner { padding:20px 16px; justify-content:center; text-align:center; gap:16px; }
  .book-hub-banner > div { min-width:0; }
  .hub-progress-box { width:100%; }
  .chapter-row { gap:10px; }
  .chapter-action { margin-inline:auto; }
  .profile-grid { grid-template-columns:minmax(0,1fr); }
  .profile-card { text-align:center; }
  .profile-actions { justify-content:center; flex-wrap:wrap; }
  /* The sticky header becomes ordinary flow in the reader so long choices can scroll. */
  body:has(#view-reader.active) .topbar { position:relative; }
  body:has(#view-reader.active) .main-wrap { padding:8px 8px 10px; }
  #view-reader.active { min-width:0; }
  .reader-shell.ilid-cinematic { min-height:max(400px,calc(100svh - 174px)); gap:8px; padding:10px; }
  .ilid-cinematic .reader-hud { flex-shrink:0; }
  .ilid-cinematic .reader-stage:not(.hidden) { display:flex; flex-direction:column; flex:1 0 auto; min-width:0; justify-content:flex-end; }
  .ilid-cinematic .speaker-portraits { flex:1 0 auto; height:auto; min-height:clamp(180px,36svh,300px); align-items:end; }
  .ilid-cinematic .stage-char { height:clamp(180px,36svh,300px); }
  .ilid-cinematic .dialogue-card { flex-shrink:0; min-height:0; margin:0; padding:12px; }
  .ilid-cinematic .dialogue-text { line-height:1.55; }
  .ilid-cinematic .choices-container:empty { display:none; }
  .ilid-cinematic #ilid-entity-layer { top:44px; bottom:auto; height:clamp(220px,42svh,340px); }
  #ilid-selection-back { align-self:center; }
}
@media(max-width:600px) and (max-height:500px) {
  .reader-shell.ilid-cinematic { min-height:0; }
  .ilid-cinematic .speaker-portraits { min-height:180px; }
  .ilid-cinematic .stage-char { height:180px; }
}

/* Phase 5A V3: approved compact phone navigation. */
.mobile-bottom-nav { display:none; }
@media(max-width:600px) {
  .topbar-inner { position:relative; display:grid; grid-template-columns:1fr; gap:6px; padding:8px 12px 7px; }
  .topbar-inner .brand { justify-self:start; gap:7px; min-height:36px; }
  .topbar-inner .brand-logo { width:25px; height:25px; border-radius:7px; }
  .topbar-inner .brand-name { font-size:1rem; }
  .topbar-inner .nav-links { display:none; }
  .topbar-inner:has(#nav-admin-btn:not(.hidden)) .nav-links { display:flex; justify-content:center; }
  .topbar-inner .nav-links .nav-btn:not(#nav-admin-btn) { display:none; }
  .topbar-inner .topbar-actions { display:block; }
  .topbar-inner .lang-dropdown-wrap { position:static; display:flex; justify-content:center; flex-wrap:nowrap; gap:6px; }
  .topbar-inner #account-header-btn { display:none; }
  .topbar-inner #sound-toggle-btn { position:absolute; top:5px; right:10px; width:44px; height:44px; min-height:44px; padding:0; border:0; background:transparent; }
  .topbar-inner :is(.streak-pill,.key-pill,.gem-pill) { display:grid; grid-template-columns:auto auto; justify-content:center; align-content:center; column-gap:4px; row-gap:3px; width:84px; max-width:30%; min-height:39px; padding:4px 5px; border-radius:7px; font-size:12px; }
  .topbar-inner :is(.streak-pill,.key-pill,.gem-pill)>span:last-child { grid-column:1; grid-row:1; transform:none; }
  .topbar-inner :is(.streak-pill,.key-pill,.gem-pill)>span:first-child { grid-column:2; grid-row:1; }
  .topbar-inner :is(.streak-pill,.key-pill,.gem-pill)::after { grid-column:1/-1; font-size:10px; line-height:1.1; font-weight:500; text-align:center; }
  .topbar-inner .streak-pill { background:#29201e; border-color:#694332; color:#ffad76; }
  .topbar-inner .streak-pill::after { content:'Streak'; }
  .topbar-inner .key-pill { background:#28241a; border-color:#66532c; color:#efc66b; }
  .topbar-inner .key-pill::after { content:'Keys'; }
  .topbar-inner .gem-pill { background:#172734; border-color:#294c64; color:#81caff; }
  .topbar-inner .gem-pill::after { content:'Diamonds'; }
  .mobile-bottom-nav { position:fixed; bottom:0; left:0; right:0; z-index:40; display:grid; grid-template-columns:repeat(3,minmax(0,1fr)); background:#10131c; border-top:1px solid var(--border-subtle); padding:3px 8px calc(3px + env(safe-area-inset-bottom,0px)); }
  .mobile-tab { border:0; background:transparent; color:var(--text-muted); display:flex; flex-direction:column; align-items:center; justify-content:center; gap:4px; min-height:53px; font:inherit; font-size:11px; cursor:pointer; }
  .mobile-tab svg { width:21px; height:21px; }
  body:has(#view-library.active,#view-chapters.active) .mobile-library, body:has(#view-stats.active) .mobile-stats, body:has(#view-profile.active,#view-auth.active) .mobile-profile { color:var(--gold); }
  .main-wrap { padding-bottom:calc(76px + env(safe-area-inset-bottom,0px)); }
  body:has(#view-reader.active,#view-ilid-selection.active) .mobile-bottom-nav { display:none; }
  body:has(#view-reader.active) .main-wrap { padding-bottom:10px; }
  body:has(#view-reader.active) .reader-shell.ilid-cinematic { min-height:max(400px,calc(100svh - 110px)); }
}
@media(max-width:600px) and (max-height:500px) { body:has(#view-reader.active) .reader-shell.ilid-cinematic { min-height:0; } }

/* Phase 5A V4: attach mobile portraits to dialogue; keep original SVG proportions. */
@media(max-width:600px) {
  .ilid-cinematic .speaker-portraits { padding:0; column-gap:0; align-items:end; overflow:visible; }
  .ilid-cinematic .stage-char { width:100%; max-width:none; height:auto; aspect-ratio:320/440; align-self:end; }
  .ilid-cinematic .stage-char > svg { width:100%; height:100%; transform:scale(1.08); transform-origin:bottom center; }
  .ilid-cinematic .dialogue-card { margin-top:-16px; }
  .ilid-cinematic .reader-stage:not(.hidden) { gap:0; }
}

/* Phase 5A V5: mobile branding only. */
@media(max-width:600px) {
  .topbar-inner { padding-top:10px; padding-bottom:9px; }
  .topbar-inner .brand { gap:10px; min-height:40px; }
  .topbar-inner .brand-logo { width:32px; height:32px; flex-shrink:0; border-radius:9px; }
  .topbar-inner .brand-name { font-size:21px; line-height:1.2; }
  .topbar-inner #sound-toggle-btn { top:8px; }
  body:has(#view-reader.active) .reader-shell.ilid-cinematic { min-height:max(400px,calc(100svh - 118px)); }
}
@media(max-width:600px) and (max-height:500px) { body:has(#view-reader.active) .reader-shell.ilid-cinematic { min-height:0; } }
