/* ================================================================
   AWFST — Main Stylesheet
   ================================================================ */

/* ── Reset & Base ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  /* ── Brand palette ── */
  --brand-teal:     #4899a1;
  --brand-amber:    #eca938;
  --brand-coral:    #e2685c;
  --brand-sage:     #89a385;
  --brand-navy:     #1d365a;
  --brand-cream:    #f4ecdd;

  /* ── Dark theme (default) ── */
  --bg:           #000000;
  --bg-surface:   #0d0d0d;
  --bg-card:      #141414;
  --bg-card-hover:#1e1e1e;
  --accent:       #eca938;
  --accent-dim:   #c4881e;
  --accent2:      #4899a1;
  --accent3:      #e2685c;
  --text:         #f4ecdd;
  --text-muted:   #8fb4ba;
  --text-dim:     #4d7a80;
  --border:       rgba(72,153,161,0.18);
  --header-bg:    rgba(0,0,0,0.95);
  --radius:       14px;
  --radius-sm:    8px;
  --shadow:       0 4px 32px rgba(0,0,0,0.5);
  --font-body:    'Nunito', sans-serif;
  --font-story:   'Lora', serif;
  --transition:   0.2s ease;
}

[data-theme="light"] {
  --bg:           #f4ecdd;
  --bg-surface:   #ede3ce;
  --bg-card:      #fdf7ed;
  --bg-card-hover:#fff3e0;
  --accent:       #c47c18;
  --accent-dim:   #9e6212;
  --accent2:      #3a7d85;
  --accent3:      #c44d42;
  --text:         #1d365a;
  --text-muted:   #3d5f70;
  --text-dim:     #7a9aaa;
  --border:       rgba(29,54,90,0.14);
  --header-bg:    rgba(244,236,221,0.93);
  --shadow:       0 4px 32px rgba(29,54,90,0.12);
}

html { font-size: 16px; scroll-behavior: smooth; }

body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.6;
  transition: background-color 0.3s ease, color 0.3s ease;
}

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 99px; }

/* ── Typography ── */
h1, h2, h3, h4 { line-height: 1.2; }

/* ================================================================
   HEADER
   ================================================================ */
.site-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--header-bg);
  backdrop-filter: blur(12px);
  /* gradient bottom strip replaces plain border */
  border-bottom: none;
}
.site-header::after {
  content: '';
  position: absolute;
  bottom: 0; left: 0; right: 0;
  height: 3px;
  background: linear-gradient(90deg,
    var(--brand-teal)  0%,
    var(--brand-amber) 33%,
    var(--brand-coral) 66%,
    var(--brand-sage)  100%);
}

.header-inner {
  max-width: 900px;
  margin: 0 auto;
  padding: 4px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

/* Header center banner — shrinks between logo and nav, never overlaps */
.header-center {
  flex: 1;
  display: flex;
  justify-content: center;
  align-items: center;
  min-width: 0;
  overflow: hidden;
  padding: 0 8px;
}
.header-center-img {
  max-height: 38px;
  width: auto;
  max-width: 100%;
  object-fit: contain;
  display: block;
}

.logo {
  display: flex;
  align-items: center;
  text-decoration: none;
}
.logo-img {
  height: 48px;
  width: auto;
  display: block;
}

/* ================================================================
   BUTTONS
   ================================================================ */
/* Ensure [hidden] always wins over display rules */
[hidden] { display: none !important; }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 20px;
  border: none;
  border-radius: var(--radius-sm);
  font-family: var(--font-body);
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
}
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

.btn-primary {
  background: linear-gradient(135deg, var(--accent), #d4902a);
  color: #1a1000;
}
.btn-primary:hover:not(:disabled) { filter: brightness(1.12); transform: translateY(-1px); }

.btn-secondary {
  background: var(--bg-card);
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-secondary:hover:not(:disabled) { background: var(--bg-card-hover); }

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  padding: 8px 14px;
}
.btn-ghost:hover { color: var(--text); background: var(--border); }

.btn-generate {
  width: 100%;
  padding: 16px;
  font-size: 1.1rem;
  justify-content: center;
  border-radius: var(--radius);
  letter-spacing: 0.3px;
}

/* ================================================================
   PAGES
   ================================================================ */
.page { display: none; }
.page.active { display: block; }

/* ================================================================
   HOMEPAGE
   ================================================================ */
main { max-width: 900px; margin: 0 auto; padding: 48px 24px 80px; }
/* Compact layout when reader is open */
main:has(#readerPage.active) { max-width: 900px; padding-top: 8px; padding-bottom: 8px; }

/* ── Stories drawer (fixed overlay, slides from right) ──────────────────── */
.stories-drawer {
  position: fixed;
  top: 0; right: 0;
  width: 300px;
  height: 100%;
  background: var(--bg-card);
  border-left: 1px solid var(--border);
  box-shadow: -4px 0 24px rgba(0,0,0,0.35);
  z-index: 400;
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform 0.28s cubic-bezier(0.4,0,0.2,1);
  will-change: transform;
}
.stories-drawer.open {
  transform: translateX(0);
}
.drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  backdrop-filter: blur(3px);
  z-index: 399;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.28s ease;
}
.drawer-backdrop.open {
  opacity: 1;
  pointer-events: auto;
}
.drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.drawer-title {
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 1.1px;
  color: var(--text-muted);
}
.drawer-close {
  padding: 4px 8px !important;
  font-size: 0.85rem;
}
.drawer-list {
  flex: 1;
  overflow-y: auto;
}
.sidebar-empty {
  text-align: center;
  padding: 36px 16px;
  color: var(--brand-sage);
  font-size: 0.85rem;
  line-height: 1.6;
}
.sidebar-empty .empty-icon { font-size: 1.8rem; display: block; margin-bottom: 8px; }
.sidebar-story {
  display: flex;
  flex-direction: column;
  gap: 0;
  padding: 0;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background var(--transition);
  overflow: hidden;
}
.sidebar-story:last-child { border-bottom: none; }
.sidebar-story:hover { background: var(--bg-card-hover); }
.sidebar-story-thumb {
  width: 100%; height: 140px;
  flex-shrink: 0;
  background: var(--bg-surface);
  display: flex; align-items: center; justify-content: center;
  font-size: 2.4rem;
  position: relative;
}
.sidebar-story-thumb.placeholder {
  background: linear-gradient(135deg, var(--brand-navy) 0%, #0e1f30 100%);
}
.sidebar-story-thumb img { width: 100%; height: 100%; object-fit: cover; }
.sidebar-story-info {
  padding: 10px 12px 12px;
  position: relative;
}
.sidebar-story-title {
  font-weight: 700;
  font-size: 0.88rem;
  line-height: 1.3;
  margin-bottom: 4px;
}
.sidebar-story-synopsis {
  font-size: 0.76rem;
  color: var(--text-muted);
  line-height: 1.45;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
  margin-bottom: 6px;
}
.sidebar-story-meta { font-size: 0.68rem; color: var(--text-dim); }
.btn-sidebar-delete {
  position: absolute;
  top: 8px; right: 8px;
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 0.75rem;
  padding: 0;
  line-height: 1;
  opacity: 0;
  transition: opacity var(--transition), color var(--transition);
}
.sidebar-story:hover .btn-sidebar-delete { opacity: 1; }
.btn-sidebar-delete:hover { color: var(--brand-coral) !important; }
.sidebar-story--pending { pointer-events: none; opacity: 0.75; }
.sidebar-spinner {
  width: 20px; height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--accent2);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.hero { text-align: center; margin-bottom: 40px; }
.hero-img {
  max-width: 100%;
  height: auto;
  display: block;
  margin: 0 auto 12px;
}
.hero-title {
  font-size: clamp(1.8rem, 4vw, 2.8rem);
  font-weight: 800;
  margin-bottom: 12px;
  background: linear-gradient(135deg,
    var(--brand-coral)  0%,
    var(--brand-amber)  33%,
    var(--brand-sage)   66%,
    var(--brand-teal)   100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.hero-subtitle { color: var(--accent2); opacity: 0.85; font-size: 1.05rem; }

/* Creator card */
.creator-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-top: 3px solid var(--brand-navy);
  border-radius: var(--radius);
  padding: 32px;
  display: flex;
  flex-direction: column;
  gap: 28px;
  box-shadow: var(--shadow);
}

.input-group { display: flex; flex-direction: column; gap: 1px; }
.input-label { font-weight: 700; font-size: 0.9rem; text-transform: uppercase; letter-spacing: 1px; color: var(--accent2); }

/* Slider */
.slider-row { display: flex; align-items: center; gap: 14px; }
.slider-min, .slider-max { font-size: 0.85rem; color: var(--text-dim); white-space: nowrap; }
.slider {
  flex: 1;
  -webkit-appearance: none;
  height: 6px;
  border-radius: 99px;
  background: linear-gradient(to right, var(--brand-sage) 0%, var(--brand-sage) var(--fill, 44%), var(--bg) var(--fill, 44%));
  outline: none;
  cursor: pointer;
}
.slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 22px; height: 22px;
  border-radius: 50%;
  background: var(--brand-sage);
  border: 3px solid var(--bg-card);
  box-shadow: 0 0 0 2px var(--brand-sage);
  transition: transform 0.15s;
}
.slider::-webkit-slider-thumb:hover { transform: scale(1.2); }
.slider-value-display { text-align: center; }
.slider-value-display span {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  padding: 4px 16px;
  border-radius: 99px;
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--brand-sage);
}
/* Big inline slider value — amber/yellow */
.slider-bigval {
  display: inline-flex;
  align-items: baseline;
  gap: 3px;
  font-size: 1.6rem;
  font-weight: 800;
  color: var(--brand-amber);
  min-width: 52px;
  line-height: 1;
  white-space: nowrap;
}
.slider-bigval-unit {
  font-size: 0.72rem;
  font-weight: 600;
  opacity: 0.75;
}

/* Textarea */
.story-textarea {
  width: 100%;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 1rem;
  padding: 14px 16px;
  resize: vertical;
  outline: none;
  transition: border-color var(--transition);
}
.story-textarea:focus { border-color: var(--accent2); }
.story-textarea::placeholder { color: var(--text-dim); }

.char-count { text-align: right; font-size: 0.8rem; color: var(--brand-sage); margin-top: -14px; }

/* ── Library ── */
.library-section { margin-top: 64px; }
.section-title {
  font-size: 1.3rem;
  font-weight: 800;
  margin-bottom: 24px;
  color: var(--text);
  padding-left: 14px;
  border-left: 3px solid var(--accent2);
}

.story-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 20px;
}

.empty-state {
  grid-column: 1 / -1;
  text-align: center;
  padding: 60px 20px;
  color: var(--brand-sage);
}
.empty-icon { font-size: 2.5rem; display: block; margin-bottom: 12px; color: var(--brand-teal); }

/* Story card */
.story-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  transition: all var(--transition);
  display: flex;
  flex-direction: column;
}
.story-card:hover { transform: translateY(-3px); border-color: var(--accent2); box-shadow: 0 8px 32px rgba(72,153,161,0.2); }

.story-card-image {
  width: 100%;
  aspect-ratio: 16/9;
  object-fit: cover;
  background: var(--bg-surface);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2.5rem;
}
.story-card-image img { width: 100%; height: 100%; object-fit: cover; }
.story-card-image.placeholder { background: linear-gradient(135deg, var(--brand-navy) 0%, #0e1f30 55%, rgba(72,153,161,0.12) 100%); }

.story-card-body { padding: 16px; flex: 1; display: flex; flex-direction: column; gap: 8px; }
.story-card-title { font-weight: 800; font-size: 1rem; line-height: 1.3; }
.story-card-synopsis { font-size: 0.85rem; color: var(--text-muted); line-height: 1.5; flex: 1; }
.story-card-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.78rem;
  color: var(--accent2);
  opacity: 0.8;
  margin-top: 8px;
}

.story-card-actions {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 8px;
}
.story-card-actions .btn { flex: 1; justify-content: center; padding: 8px; font-size: 0.85rem; }
.btn-delete {
  background: transparent !important;
  color: var(--brand-coral) !important;
  border: 1px solid rgba(226,104,92,0.3) !important;
}
.btn-delete:hover:not(:disabled) {
  background: rgba(226,104,92,0.14) !important;
  border-color: var(--brand-coral) !important;
}
/* Hide loading sub-text when empty */
.loading-sub:empty { display: none; }

/* ================================================================
   READER
   ================================================================ */
.reader-top {
  text-align: center;
  padding: 0 24px 4px;
}
.reader-title { font-size: 1.6rem; font-weight: 800; margin-bottom: 1px; }
.reader-progress { display: block; font-size: 0.85rem; font-weight: 700; color: var(--brand-sage); margin-bottom: 3px; }
.page-indicator { display: none; }

/* Story page */
.story-page { display: none; }
.story-page.active { display: block; animation: fadeIn 0.4s ease; }

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

/* Story text overlaid on bottom of image */
.story-text-section {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  padding: 56px 20px 18px;
  background: linear-gradient(to bottom, transparent, rgba(0,0,0,0.65) 35%, rgba(0,0,0,0.88));
  color: #fff;
  font-family: var(--font-story);
  font-size: calc(clamp(0.82rem, 2.6vw, 1rem) * var(--text-scale, 1));
  line-height: 1.6;
  z-index: 2;
}
.story-text-section p { margin-bottom: 0.55em; }
.story-text-section p:last-child { margin-bottom: 0; }

/* Full-width page image — portrait 3:4, text overlaid at bottom */
.page-image-wrap {
  position: relative;
  width: 100%;
  max-width: 520px;
  margin: 0 auto;
  line-height: 0;
}
.page-image-wrap.hidden { display: none; }
/* When user hides the image: collapse to text-only block */
.page-image-wrap.image-hidden .image-loading-slot,
.page-image-wrap.image-hidden .image-single { display: none !important; }
.page-image-wrap.image-hidden { line-height: normal; background: var(--bg-surface); border-radius: var(--radius-sm); }
.page-image-wrap.image-hidden .story-text-section {
  position: static;
  background: none;
  color: var(--text);
  padding: 16px 20px;
  font-size: 1.05rem;
  text-shadow: none;
}

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

/* Controls row beneath the image */
.image-controls-row {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  max-width: 520px;
  margin: 4px auto 12px;
  padding: 0 4px;
  opacity: 0.35;
  transition: opacity 0.2s;
}
.image-controls-row:hover { opacity: 1; }
.image-controls-row .btn { font-size: 0.78rem; padding: 4px 10px; }

/* 3-column reader layout: side-nav | content | side-nav */
.reader-layout {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
}
#readerBody {
  flex: 0 1 520px;
  min-width: 0;
}
.btn-nav-side {
  flex-shrink: 0;
  width: 70px;
  min-height: 150px;
  padding: 16px 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  white-space: normal;
}
.btn-nav-side:hover:not(:disabled) { background: rgba(255,255,255,0.06); color: var(--text); }
.btn-nav-side:disabled { opacity: 0.25; cursor: default; }
.btn-nav-side .nav-icon { font-size: 1.5rem; }
.btn-nav-side .nav-label { font-size: 0.65rem; text-transform: uppercase; letter-spacing: 0.06em; text-align: center; line-height: 1.4; }
#prevPageBtn .nav-icon { color: var(--brand-teal); }
#nextPageBtn .nav-icon { color: var(--brand-amber); }
/* Constrain controls / tray / ref-panel to match the story body width */
.reader-audio-tray,
.reader-controls-bar,
.ref-sheet-panel {
  max-width: 520px;
  margin-left: auto;
  margin-right: auto;
  width: 100%;
}
#readerBody.landscape ~ .reader-audio-tray,
#readerBody.landscape ~ .reader-controls-bar,
#readerBody.landscape ~ .ref-sheet-panel { max-width: 860px; }

/* Reader bottom: back + cast centered */
.reader-bottom {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 8px 24px 20px;
}

/* ── Reader presentation controls ── */
.reader-controls-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 20px;
  padding: 6px 24px 2px;
  flex-wrap: wrap;
}
.reader-ctrl-group {
  display: flex;
  align-items: center;
  gap: 8px;
}
.reader-ctrl-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-muted);
  white-space: nowrap;
}
.reader-ctrl-slider {
  width: 100px;
  accent-color: var(--brand-teal);
  cursor: pointer;
}
.reader-ctrl-val {
  font-size: 0.75rem;
  color: var(--text-muted);
  min-width: 36px;
  text-align: right;
}
.reader-ctrl-sep {
  width: 1px;
  height: 22px;
  background: var(--border);
  flex-shrink: 0;
}
.reader-ctrl-toggle {
  display: flex;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}
.reader-ctrl-opt {
  padding: 4px 11px;
  font-size: 0.75rem;
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.reader-ctrl-opt.active {
  background: var(--brand-teal);
  color: #fff;
}
.reader-ctrl-opt:not(.active):hover {
  background: rgba(255,255,255,0.06);
  color: var(--text);
}

/* Text below image mode */
#readerBody.text-below .page-image-wrap {
  line-height: normal;
}
#readerBody.text-below .story-text-section {
  position: static;
  background: var(--bg-surface);
  color: var(--text);
  padding: 14px 20px 10px;
  text-shadow: none;
  border-radius: 0 0 var(--radius-sm) var(--radius-sm);
}
/* Override light-theme gradient text-shadow bleed */
[data-theme="light"] #readerBody.text-below .story-text-section {
  background: rgba(0,0,0,0.04);
}

/* ── Reference Sheet Panel ── */
.ref-sheet-panel {
  margin: 4px auto 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}
.ref-sheet-toggle {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 14px;
  background: var(--bg-surface);
  border: none;
  color: var(--text-muted);
  font-family: var(--font-body);
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  cursor: pointer;
  text-align: left;
  transition: background var(--transition), color var(--transition);
}
.ref-sheet-toggle:hover { background: var(--bg-card-hover); color: var(--text); }
.ref-sheet-toggle-arrow { font-size: 0.65rem; }
.ref-sheet-toggle-hint {
  margin-left: auto;
  font-size: 0.72rem;
  font-weight: 400;
  opacity: 0.6;
  text-transform: none;
  letter-spacing: 0;
}
.ref-sheet-body { display: none; padding: 16px; background: var(--bg-card); text-align: center; }
.ref-sheet-body.open { display: block; }
.ref-sheet-meta {
  width: 100%; max-width: 760px; margin: 0 auto;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 6px 16px;
  text-align: left;
}
.ref-sheet-meta-item { font-size: 0.75rem; color: var(--text); line-height: 1.45; }
.ref-sheet-meta-item strong {
  display: block; font-size: 0.65rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.7px; color: var(--text-muted); margin-bottom: 2px;
}
.ref-sheet-meta-item span { color: var(--text); }


   ================================================================ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(6px);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  animation: fadeIn 0.2s ease;
}
.modal-overlay[hidden] { display: none; }

.modal {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: 100%;
  max-width: 520px;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: var(--shadow);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px 0;
}
.modal-header h3 { font-size: 1.2rem; font-weight: 800; }
.modal-body { padding: 24px; display: flex; flex-direction: column; gap: 28px; }
.modal-footer { padding: 0 24px 24px; }

.settings-group { display: flex; flex-direction: column; gap: 14px; }
.settings-group h4 { font-size: 0.9rem; text-transform: uppercase; letter-spacing: 1px; color: var(--text-muted); font-weight: 700; }
.settings-row { display: flex; flex-direction: column; gap: 6px; }
.settings-row label { font-size: 0.85rem; color: var(--text-muted); }

select, .settings-row input {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 0.95rem;
  padding: 10px 14px;
  outline: none;
  width: 100%;
  transition: border-color var(--transition);
}
select:focus, .settings-row input:focus { border-color: var(--accent2); }
select option { background: var(--bg-card); }

.cost-note {
  font-size: 0.88rem;
  color: var(--brand-sage);
  background: var(--bg-surface);
  border-left: 3px solid var(--brand-sage);
  border-radius: var(--radius-sm);
  padding: 12px;
  line-height: 1.6;
}

/* Loading overlay */
.loading-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 48px 36px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  min-width: 280px;
}
.loading-spinner {
  width: 52px; height: 52px;
  border: 4px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-title { font-size: 1.15rem; font-weight: 800; }
.loading-sub { font-size: 0.9rem; color: var(--text-muted); }

/* Lightbox */
.lightbox-inner {
  position: relative;
  max-width: 90vw;
  max-height: 90vh;
}
.lightbox-close {
  position: absolute;
  top: -40px;
  right: 0;
  z-index: 1;
  font-size: 1.2rem;
}
.lightbox-img {
  max-width: 100%;
  max-height: 85vh;
  object-fit: contain;
  border-radius: var(--radius);
  display: block;
}

/* ================================================================
   CAST BUTTON — highlight when connected
   ================================================================ */
.btn-cast.connected { color: var(--accent); }
.btn-print { margin-left: 6px; }

/* ================================================================
   TOAST NOTIFICATIONS
   ================================================================ */
#toastContainer {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 999;
  display: flex;
  flex-direction: column;
  gap: 10px;
  pointer-events: none;
}
.toast {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-left: 4px solid var(--accent);
  border-radius: var(--radius-sm);
  padding: 12px 18px;
  font-size: 0.9rem;
  font-weight: 600;
  box-shadow: var(--shadow);
  animation: slideIn 0.3s ease, fadeOut 0.4s ease 3.6s forwards;
  pointer-events: all;
}
.toast.error { border-left-color: var(--accent3); }
@keyframes slideIn { from { transform: translateX(120%); } to { transform: translateX(0); } }
@keyframes fadeOut { to { opacity: 0; transform: translateX(40px); } }

/* ================================================================
   THEME TOGGLE, AUTH CHIP & LOGIN
   ================================================================ */
.header-nav { display: flex; align-items: center; gap: 6px; }
.btn-theme   { font-size: 1.1rem; padding: 8px 10px; }
.btn-stories { font-size: 1.1rem; padding: 8px 10px; }
.btn-heart   { font-size: 1.1rem; padding: 8px 10px; color: #e2685c; }

.auth-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 12px 5px 6px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 99px;
  cursor: pointer;
  transition: all var(--transition);
}
.auth-chip:hover { border-color: var(--accent2); }

/* Unified sign-in / account header button */
.btn-account {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 5px 14px;
  background: var(--bg-card);
  border: 1.5px solid var(--border);
  border-radius: 99px;
  cursor: pointer;
  font-family: var(--font-body);
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-muted);
  transition: all var(--transition);
  white-space: nowrap;
}
.btn-account:hover {
  border-color: var(--accent2);
  color: var(--text);
}
.btn-account[data-state="signed-in"] {
  background: rgba(72,153,161,0.12);
  border-color: var(--accent2);
  color: var(--accent2);
  padding: 5px 12px 5px 5px;
}
.hdr-initial {
  width: 24px; height: 24px;
  border-radius: 50%;
  background: var(--accent2);
  color: #fff;
  font-size: 0.72rem;
  font-weight: 800;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.hdr-name {
  max-width: 100px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.auth-initial {
  width: 26px; height: 26px;
  border-radius: 50%;
  background: var(--accent2);
  color: var(--bg);
  font-size: 0.75rem;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.auth-email {
  font-size: 0.82rem;
  color: var(--text-muted);
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Auth required notice inside creator card */
.auth-required-notice {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 24px 20px;
  background: var(--bg-surface);
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
  text-align: center;
}
.auth-required-notice[hidden] { display: none; }
.auth-required-notice p { color: var(--text-muted); font-size: 0.9rem; display: flex; align-items: center; gap: 6px; justify-content: center; }
.auth-required-notice .notice-icon { color: var(--accent); font-size: 1.1rem; flex-shrink: 0; }

/* Login modal */
.login-divider {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--text-dim);
  font-size: 0.82rem;
}
.login-divider::before, .login-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}
.btn-google {
  width: 100%;
  justify-content: center;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  color: var(--text);
  gap: 10px;
}
.btn-google:hover { background: var(--bg-card-hover); }

.login-error {
  border-left: 3px solid var(--accent3) !important;
  color: var(--accent3) !important;
}
.login-error[hidden] { display: none; }

/* Approval note below register button */
.approval-note {
  font-size: 0.8rem;
  color: var(--text-dim);
  text-align: center;
  line-height: 1.5;
}

/* Approval status badge (settings + auth chip area) */
.approval-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 12px;
  border-radius: 99px;
  font-size: 0.8rem;
  font-weight: 700;
}
.approval-approved {
  background: rgba(72,153,161,0.15);
  color: var(--accent2);
  border: 1px solid rgba(72,153,161,0.25);
}
.approval-pending {
  background: rgba(236,169,56,0.12);
  color: var(--accent);
  border: 1px solid rgba(236,169,56,0.25);
}

/* Pending approval notice — amber accent instead of teal */
.pending-notice {
  border-color: rgba(236,169,56,0.4) !important;
  border-style: solid !important;
}
.pending-notice .notice-icon { color: var(--accent); }
.pending-notice p strong { color: var(--text); }

/* Settings group separators */
.settings-group + .settings-group {
  border-top: 1px solid var(--border);
  padding-top: 24px;
}

/* Light mode scrollbar */
[data-theme="light"] ::-webkit-scrollbar-track { background: var(--bg-surface); }
[data-theme="light"] ::-webkit-scrollbar-thumb { background: rgba(29,54,90,0.2); }

/* ================================================================
   RESPONSIVE
   ================================================================ */
@media (max-width: 600px) {
  main { padding: 32px 16px 60px; }
  .creator-card { padding: 20px 16px; }
  .panel-with-dice { position: relative; }
  .panel-dice-btn { position: absolute; left: 0; top: 0; min-width: 44px; padding-left: 10px; padding-right: 10px; }
  .panel-with-dice > .story-settings-panel { width: 100%; }
  .panel-with-dice .settings-panel-toggle { padding-left: 52px; }
  .reader-top { padding: 0 12px 4px; }
  .image-grid { grid-template-columns: repeat(2, 1fr); }
  /* Stack side nav below content on small screens */
  .reader-layout { flex-wrap: wrap; }
  #readerBody { order: -1; width: 100%; }
  .btn-nav-side {
    flex: 1;
    min-height: 44px;
    flex-direction: row;
    padding: 10px 16px;
    gap: 8px;
    width: auto;
  }
  .btn-nav-side .nav-label { font-size: 0.8rem; text-transform: none; letter-spacing: 0; }
  .btn-nav-side .nav-icon { font-size: 1.1rem; }
}

/* ================================================================
   STORY SETTINGS PANEL
   ================================================================ */

.story-settings-panel {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-surface);
  overflow: hidden;
  margin-bottom: 4px;
}

.settings-panel-toggle {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: transparent;
  border: none;
  color: var(--brand-coral);
  font-family: var(--font-body);
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.9px;
  padding: 11px 14px;
  cursor: pointer;
  transition: color var(--transition);
}
.settings-panel-toggle:hover { color: var(--accent3); }
.toggle-icon { font-size: 0.75rem; line-height: 1; }

/* Dice button floats in left margin — panels span full width as if dice doesn't exist */
.panel-with-dice {
  position: relative;
  margin-bottom: 4px;
}
.panel-with-dice > .story-settings-panel {
  width: 100%;
  margin-bottom: 0;
}
.panel-with-dice .settings-panel-toggle {
  padding-left: 52px;
}
.panel-dice-btn {
  position: absolute;
  left: 0;
  top: 0;
  min-width: 44px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 11px 10px;
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
  color: var(--text-muted);
  transition: background var(--transition), color var(--transition);
}
.panel-dice-btn:hover {
  background: rgba(255,255,255,0.08);
  color: var(--text);
}

.settings-panel-body {
  padding: 8px 16px 16px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  border-top: 1px solid var(--border);
}

/* Story vitals: left 65% col (length+age+pages stacked) + right 35% preview */
.story-vitals-layout {
  display: flex;
  gap: 16px;
  align-items: center;
}
.vitals-settings-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.vitals-settings-col .input-group {
  margin-bottom: 10px;
}
.vitals-settings-col .input-group:last-child {
  margin-bottom: 0;
}
.vitals-preview-col {
  flex: 0 0 35%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  min-width: 80px;
}
.vitals-pp-page {
  width: 90px !important;
  height: 120px !important;
  flex-shrink: 0;
  transform: scale(1.4);
  transform-origin: top center;
  margin-bottom: 48px;
}
.vitals-pp-page.landscape {
  width: 120px !important;
  height: 68px !important;
  margin-bottom: 34px;
}
.vitals-preview-col .pp-meta {
  margin-top: 0;
  text-align: center;
}
@media (max-width: 540px) {
  .story-vitals-layout { flex-direction: column; align-items: stretch; }
  .vitals-preview-col {
    flex: unset;
    flex-direction: column;
    align-items: center;
    gap: 6px;
  }
  .vitals-pp-page { flex: 0 0 auto; width: 58px !important; height: 82px !important; min-height: unset; transform: none; margin-bottom: 0; }
  .vitals-pp-page.landscape { width: 70px !important; height: 40px !important; margin-bottom: 0; }
}

/* Dual-range age slider */
.age-dual-slider {
  position: relative;
  flex: 1;
  height: 28px;
}
.age-slider-track {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  left: 0;
  right: 0;
  height: 6px;
  background: var(--bg);
  border-radius: 3px;
  pointer-events: none;
}
.age-slider-fill {
  position: absolute;
  height: 100%;
  background: var(--brand-sage);
  border-radius: 3px;
}
.age-range-input {
  position: absolute;
  width: 100%;
  height: 100%;
  top: 0;
  left: 0;
  margin: 0;
  pointer-events: none;
  -webkit-appearance: none;
  appearance: none;
  background: transparent;
}
.age-range-input::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  pointer-events: all;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--brand-sage);
  border: 3px solid var(--bg-card);
  box-shadow: 0 0 0 2px var(--brand-sage);
  cursor: pointer;
  transition: transform 0.15s;
}
.age-range-input::-webkit-slider-thumb:hover { transform: scale(1.2); }
.age-range-input::-moz-range-thumb {
  pointer-events: all;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--brand-sage);
  border: 3px solid var(--bg-card);
  cursor: pointer;
}
.age-range-input::-webkit-slider-runnable-track { background: transparent; }
.age-range-input::-moz-range-track { background: transparent; height: 6px; }
#ageRangeLabel { min-width: 56px; white-space: nowrap; }

/* Label hint */
.label-hint {
  text-transform: none;
  letter-spacing: 0;
  font-weight: 500;
  font-size: 0.78rem;
  color: var(--text-dim);
  margin-left: 5px;
}

/* ================================================================
   TAGS (MOOD / COOL / CHARACTER POOL)
   ================================================================ */

.tag-pool {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.tag-btn {
  display: inline-flex;
  align-items: center;
  padding: 5px 13px;
  border-radius: 99px;
  border: 1.5px solid var(--border);
  background: var(--bg-card);
  color: var(--text-muted);
  font-family: var(--font-body);
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
  user-select: none;
}
.tag-btn:hover {
  border-color: var(--accent2);
  color: var(--accent2);
  background: rgba(72,153,161,0.08);
}
/* Mood: sage (distinct from teal hover) */
.tag-btn.selected {
  background: rgba(137,163,133,0.18);
  border-color: #89a385;
  color: #89a385;
}
/* Cool tags: amber */
#coolTagPool .tag-btn.selected {
  background: rgba(236,169,56,0.14);
  border-color: var(--accent);
  color: var(--accent);
}

/* ── Fun Tag Autocomplete ──────────────────────────────────────── */
.fun-autocomplete-wrap {
  position: relative;
}
.fun-tag-input {
  width: 100%;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 0.95rem;
  padding: 9px 14px;
  outline: none;
  transition: border-color var(--transition);
  box-sizing: border-box;
}
.fun-tag-input:focus { border-color: var(--accent); }
.fun-tag-input::placeholder { color: var(--text-dim); }
.fun-tag-dropdown {
  position: absolute;
  top: calc(100% + 4px);
  left: 0; right: 0;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  list-style: none;
  margin: 0; padding: 4px 0;
  z-index: 50;
  box-shadow: 0 6px 20px rgba(0,0,0,0.25);
  max-height: 220px;
  overflow-y: auto;
}
.fun-tag-dropdown li {
  padding: 8px 14px;
  font-size: 0.88rem;
  color: var(--text);
  cursor: pointer;
  transition: background 0.1s;
}
.fun-tag-dropdown li:hover { background: rgba(236,169,56,0.13); color: var(--accent); }
.fun-tag-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}
.fun-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px 4px 12px;
  border-radius: 99px;
  background: rgba(236,169,56,0.14);
  border: 1.5px solid var(--accent);
  color: var(--accent);
  font-size: 0.82rem;
  font-weight: 600;
}
.fun-chip-remove {
  background: none;
  border: none;
  color: var(--accent);
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  padding: 0;
  opacity: 0.7;
  transition: opacity 0.15s;
}
.fun-chip-remove:hover { opacity: 1; }

/* Character available: coral when selected */
.char-available.selected {
  background: rgba(226,104,92,0.13);
  border-color: var(--accent3);
  color: var(--accent3);
}

/* Selected ordered characters */
.selected-chars {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-top: 8px;
}
.char-selected-tag {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px 4px 4px;
  border-radius: 99px;
  background: rgba(226,104,92,0.12);
  border: 1.5px solid var(--accent3);
  color: var(--accent3);
  font-size: 0.8rem;
  font-weight: 700;
}
.char-rank {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--accent3);
  color: #fff;
  font-size: 0.68rem;
  font-weight: 800;
  flex-shrink: 0;
  margin-right: 2px;
}
.char-remove {
  background: none;
  border: none;
  color: var(--accent3);
  cursor: pointer;
  font-size: 0.68rem;
  line-height: 1;
  padding: 0;
  opacity: 0.65;
  margin-left: 3px;
}
.char-remove:hover { opacity: 1; }

/* ================================================================
   GENERATE ACTIONS ROW
   ================================================================ */

.generate-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.generate-idea-row {
  display: flex;
  justify-content: flex-end;
}
.generate-btn-row {
  display: flex;
  justify-content: stretch;
}
.generate-btn-row .btn-generate {
  flex: 1;
}
.btn-randomize {
  background: var(--bg-surface);
  color: var(--text-muted);
  border: 1.5px solid var(--border);
  font-size: 0.88rem;
  padding: 12px 16px;
  white-space: nowrap;
  flex-shrink: 0;
  border-radius: var(--radius-sm);
}
.btn-randomize:hover {
  color: var(--accent);
  border-color: var(--accent);
  background: rgba(236,169,56,0.08);
}
.settings-surprise-row {
  display: flex;
  justify-content: flex-end;
  padding-top: 2px;
}
/* Art style picker */
.style-picker { display: flex; flex-wrap: wrap; gap: 6px; }
.style-opt {
  padding: 6px 13px;
  font-size: 0.8rem;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
  white-space: nowrap;
}
.style-opt:hover:not(.active) { background: rgba(255,255,255,0.06); color: var(--text); }
.style-opt.active { background: var(--brand-sage); color: #fff; font-weight: 700; border-color: var(--brand-sage); }

/* Image orientation toggle */
.orient-toggle {
  display: flex;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  width: fit-content;
}
.orient-opt {
  padding: 5px 18px;
  font-size: 0.82rem;
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  white-space: nowrap;
  line-height: 1.2;
}
.orient-opt + .orient-opt { border-left: 1px solid var(--border); }
.orient-opt[data-value="portrait"].active  { background: transparent; color: var(--text); font-weight: 700; box-shadow: inset 0 0 0 3px var(--brand-amber); }
.orient-opt[data-value="landscape"].active { background: transparent; color: var(--text); font-weight: 700; box-shadow: inset 0 0 0 3px var(--brand-amber); }
.orient-hint { font-size: 0.8rem; color: var(--text-muted); margin: 4px 0 0; }

.quality-toggle {
  display: flex;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  width: fit-content;
}
.quality-opt {
  padding: 7px 18px;
  font-size: 0.82rem;
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  white-space: nowrap;
}
.quality-opt + .quality-opt { border-left: 1px solid var(--border); }
.quality-opt.active { background: var(--accent2); color: #fff; font-weight: 700; }
.quality-price { font-size: 0.7rem; opacity: 0.75; margin-left: 3px; }
/* Pages slider + live preview */
.pages-auto-pill {
  display: inline-block;
  margin-left: 8px;
  padding: 1px 8px;
  border-radius: 10px;
  border: 1px solid var(--accent2);
  background: transparent;
  color: var(--accent2);
  font-size: 0.65rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
  vertical-align: middle;
}
.pages-auto-pill.active { background: var(--brand-amber); color: #fff; border-color: var(--brand-amber); }
.pages-control-row { display: flex; gap: 14px; align-items: flex-start; }
.pages-slider-col  { flex: 1; min-width: 0; }
.pages-slider-row  { display: flex; align-items: center; gap: 8px; }
.pages-count-display {
  font-size: 1.6rem;
  font-weight: 800;
  color: var(--brand-amber);
  min-width: 32px;
  text-align: center;
  line-height: 1;
}
.pages-slider   { flex: 1; }
.pages-max-label { font-size: 0.7rem; color: var(--text-muted); opacity: 0.6; white-space: nowrap; }
.pp-meta { margin-top: 6px; font-size: 0.73rem; color: var(--text-muted); line-height: 1.5; }
/* Miniature page mockup */
.pages-preview { flex-shrink: 0; }
.pp-page {
  width: 58px;
  height: 82px;
  background: rgba(255,255,255,0.06);
  border: 1px solid var(--border);
  border-radius: 3px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.pp-img-block {
  width: 100%;
  flex: 0 0 40%;
  background: rgba(255,255,255,0.1);
  border-bottom: 1px solid rgba(255,255,255,0.08);
}
.pp-text-area {
  flex: 1;
  padding: 3px 4px;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  gap: 2.5px;
  overflow: hidden;
}
.pp-line { height: 2.5px; background: rgba(255,255,255,0.22); border-radius: 1px; }

/* ── Custom image upload ──────────────────────────────────────────── */
.upload-disclaimer {
  font-size: 0.72rem;
  color: var(--text-muted);
  opacity: 0.8;
  margin: 2px 0 8px;
  line-height: 1.4;
}
.upload-drop-zone {
  display: flex;
  align-items: center;
  gap: 10px;
  border: 1.5px dashed var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  background: rgba(0,0,0,0.08);
}
.upload-drop-zone:hover,
.upload-drop-zone.drag-over {
  border-color: var(--accent2);
  background: rgba(72,153,161,0.08);
}
.upload-icon { font-size: 1.2rem; flex-shrink: 0; }
.upload-prompt { font-size: 0.8rem; color: var(--text-muted); }
.upload-browse-btn {
  background: none;
  border: none;
  color: var(--accent2);
  font-size: 0.8rem;
  cursor: pointer;
  padding: 0;
  text-decoration: underline;
  text-decoration-style: dotted;
}
.upload-browse-btn:hover { color: var(--accent); }

/* image cards list */
.custom-img-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 8px;
}
.custom-img-card {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  background: rgba(0,0,0,0.15);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
}
.custom-img-thumb {
  width: 52px;
  height: 52px;
  object-fit: cover;
  border-radius: 4px;
  flex-shrink: 0;
  border: 1px solid var(--border);
}
.custom-img-body {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.custom-img-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}
.custom-img-name-label {
  font-size: 0.72rem;
  color: var(--text-muted);
  opacity: 0.7;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 140px;
}
.custom-img-remove {
  background: none;
  border: none;
  color: var(--accent3);
  cursor: pointer;
  font-size: 0.9rem;
  padding: 0 2px;
  line-height: 1;
  flex-shrink: 0;
}
.custom-img-remove:hover { opacity: 0.7; }
.custom-img-desc {
  width: 100%;
  background: rgba(0,0,0,0.25);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
  font-size: 0.78rem;
  padding: 5px 8px;
  outline: none;
  box-sizing: border-box;
}
.custom-img-desc:focus { border-color: var(--accent2); }
.custom-img-desc::placeholder { color: var(--text-muted); opacity: 0.6; }
.custom-img-influence {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 0.73rem;
  color: var(--text-muted);
}
.influence-slider {
  flex: 1;
  height: 3px;
  accent-color: var(--accent2);
  cursor: pointer;
}
.influence-val {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--accent2);
  min-width: 18px;
  text-align: right;
}

/* Visual guide spans full grid width */
.ref-sheet-meta-full { grid-column: 1 / -1; }
.ref-sheet-meta-full span { white-space: pre-wrap; }

/* ================================================================
   COVER PAGE
   ================================================================ */
.story-page.cover-page {
  position: relative;
  width: 100%;
  line-height: 0;
}
.cover-image-wrap {
  position: relative;
  width: 100%;
}
.cover-image-wrap img {
  width: 100%;
  display: block;
  aspect-ratio: 3 / 4;
  object-fit: cover;
}
#readerBody.landscape .cover-image-wrap img { aspect-ratio: 16 / 9; }
#readerBody.landscape .cover-skeleton { aspect-ratio: 16 / 9; }

.cover-skeleton {
  width: 100%;
  aspect-ratio: 3 / 4;
  background: linear-gradient(
    90deg,
    var(--bg-surface) 25%,
    var(--bg-card-hover, rgba(255,255,255,0.06)) 50%,
    var(--bg-surface) 75%
  );
  background-size: 200% 100%;
  animation: shimmer 1.6s infinite;
}

.cover-title-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 24px;
  background: linear-gradient(
    to bottom,
    rgba(0,0,0,0.15) 0%,
    transparent 35%,
    transparent 50%,
    rgba(0,0,0,0.55) 75%,
    rgba(0,0,0,0.80) 100%
  );
}
.cover-title-text {
  color: #fff;
  font-size: clamp(1.6rem, 6vw, 3.2rem);
  line-height: 1.15;
  text-shadow: 0 2px 12px rgba(0,0,0,0.6), 0 0 40px rgba(0,0,0,0.4);
  letter-spacing: 0.02em;
}

/* ================================================================
   BACK COVER PAGE
   ================================================================ */
.story-page.back-cover-page {
  display: none;
  background: radial-gradient(ellipse at center top, #1a1040 0%, #0a0518 60%, #000 100%);
  min-height: 400px;
  padding: 0;
}
#readerBody.landscape .story-page.back-cover-page { min-height: 540px; }
.story-page.back-cover-page.active { display: flex; flex-direction: column; align-items: center; justify-content: center; }

.back-cover-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 28px;
  padding: 48px 32px;
  text-align: center;
}
.back-cover-thanks {
  font-size: clamp(1rem, 3.5vw, 1.5rem);
  color: rgba(255,255,255,0.88);
  font-family: var(--font-story);
  font-style: italic;
  line-height: 1.5;
  max-width: 380px;
}
.back-cover-brand {
  font-size: clamp(0.7rem, 2vw, 0.85rem);
  text-transform: uppercase;
  letter-spacing: 0.15em;
  color: rgba(255,255,255,0.4);
  margin-top: -16px;
}
.back-cover-logo {
  max-width: min(260px, 60%);
  opacity: 0.92;
  filter: brightness(1.1);
}
.back-cover-stars {
  font-size: 1.4rem;
  letter-spacing: 0.3em;
  opacity: 0.5;
}

/* ================================================================
   PAGE-TURN SPARKLE TRANSITION
   ================================================================ */
@keyframes sparkle-out {
  0%   { transform: translate(0,0) scale(1) rotate(0deg); opacity: 1; }
  100% { transform: translate(var(--sx), var(--sy)) scale(0) rotate(var(--sr,180deg)); opacity: 0; }
}
.sparkle-particle {
  position: fixed;
  pointer-events: none;
  z-index: 9999;
  animation: sparkle-out 0.65s ease-out forwards;
  border-radius: 50%;
}

/* Page enter animations — applied via class on #readerBody */
@keyframes pageFlipInRight {
  from { opacity: 0; transform: perspective(1100px) rotateY(22deg) translateX(18px) scale(0.97); }
  to   { opacity: 1; transform: perspective(1100px) rotateY(0deg)  translateX(0)    scale(1); }
}
@keyframes pageFlipInLeft {
  from { opacity: 0; transform: perspective(1100px) rotateY(-22deg) translateX(-18px) scale(0.97); }
  to   { opacity: 1; transform: perspective(1100px) rotateY(0deg)   translateX(0)     scale(1); }
}
#readerBody.flip-forward  .story-page.active { animation: pageFlipInRight 0.38s cubic-bezier(0.22,1,0.36,1) both; }
#readerBody.flip-backward .story-page.active { animation: pageFlipInLeft  0.38s cubic-bezier(0.22,1,0.36,1) both; }

/* Cost estimator */
.cost-estimator {
  background: rgba(0,0,0,0.18);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 4px;
}
.cost-est-title {
  font-size: 0.67rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  opacity: 0.6;
  margin-bottom: 8px;
}
.cost-est-row { display: flex; justify-content: space-between; align-items: center; padding: 2px 0; }
.cost-est-row span:last-child { font-weight: 600; color: var(--text); font-variant-numeric: tabular-nums; }
.cost-est-sep { border-top: 1px solid var(--border); margin: 6px 0 4px; }
.cost-est-total span:last-child { color: var(--brand-amber); font-weight: 700; }
.cost-est-regen { margin-top: 2px; opacity: 0.75; }
.cost-est-regen span:last-child { color: var(--brand-sage); }
.btn-generate.btn-primary { flex: 1; justify-content: center; padding: 14px; }

/* ================================================================
   AUDIO SETTINGS PANEL
   ================================================================ */

.audio-settings-note {
  font-size: 0.78rem;
  color: var(--text-muted);
  background: rgba(255,255,255,0.04);
  border-left: 3px solid var(--brand-teal);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  padding: 8px 12px;
  line-height: 1.5;
  margin-bottom: 4px;
}
.audio-settings-note strong { color: var(--text); }
.audio-settings-note code { font-size: 0.82em; background: rgba(255,255,255,0.08); padding: 1px 4px; border-radius: 3px; }

.label-badge {
  display: inline-block;
  font-size: 0.6rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: 2px 6px;
  border-radius: 99px;
  background: rgba(126,211,180,0.18);
  color: var(--brand-teal);
  vertical-align: middle;
  margin-left: 6px;
}

/* Each audio option row */
.audio-opt-row {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border);
}
.audio-opt-row:last-child { border-bottom: none; padding-bottom: 0; }

.audio-opt-header {
  display: flex;
  align-items: flex-start;
  gap: 12px;
}

/* Toggle switch */
.audio-toggle-wrap {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  cursor: pointer;
  margin-top: 2px;
}
.audio-toggle-input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}
.audio-toggle-track {
  display: inline-block;
  width: 36px;
  height: 20px;
  background: var(--border);
  border-radius: 99px;
  position: relative;
  transition: background 0.2s;
  flex-shrink: 0;
}
.audio-toggle-thumb {
  position: absolute;
  top: 3px; left: 3px;
  width: 14px; height: 14px;
  background: #fff;
  border-radius: 50%;
  transition: transform 0.2s, background 0.2s;
}
.audio-toggle-input:checked + .audio-toggle-track {
  background: var(--brand-teal);
}
.audio-toggle-input:checked + .audio-toggle-track .audio-toggle-thumb {
  transform: translateX(16px);
}

.audio-opt-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.audio-opt-name {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text);
}
.audio-opt-hint {
  font-size: 0.75rem;
  color: var(--text-muted);
  line-height: 1.4;
}

/* Volume row */
.audio-opt-vol {
  display: flex;
  align-items: center;
  gap: 8px;
  padding-left: 48px;
}
.audio-vol-icon { font-size: 0.85rem; }
.audio-vol-slider {
  flex: 1;
  max-width: 140px;
  accent-color: var(--brand-teal);
  cursor: pointer;
}
.audio-vol-val {
  font-size: 0.72rem;
  color: var(--text-muted);
  min-width: 30px;
  text-align: right;
}

/* Voice selector */
.audio-opt-voice {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  padding-left: 48px;
}
.audio-voice-label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  white-space: nowrap;
}
.audio-voice-select {
  flex: 1;
  min-width: 0;
  max-width: 300px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 0.8rem;
  padding: 4px 8px;
}
.audio-voice-custom {
  flex: 1;
  min-width: 160px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 0.8rem;
  padding: 4px 8px;
}
.audio-voice-browse {
  font-size: 0.72rem;
  color: var(--brand-teal);
  text-decoration: none;
  white-space: nowrap;
}
.audio-voice-browse:hover { text-decoration: underline; }

/* ── Reader Audio Tray ── */
.reader-audio-tray {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 20px;
  padding: 6px 24px 2px;
  flex-wrap: wrap;
}
.audio-tray-chan {
  display: flex;
  align-items: center;
  gap: 8px;
}
.audio-tray-btn {
  display: flex;
  align-items: center;
  gap: 5px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 4px 10px;
  font-size: 0.78rem;
  color: var(--text-muted);
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
  white-space: nowrap;
}
.audio-tray-btn:hover { background: rgba(255,255,255,0.06); color: var(--text); }
.audio-tray-btn.playing {
  border-color: var(--brand-teal);
  color: var(--brand-teal);
}
.audio-tray-icon { font-size: 0.9rem; }
.audio-tray-status {
  font-size: 0.6rem;
  opacity: 0.6;
}
.audio-tray-btn.loading .audio-tray-status { animation: spin 1s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }

.audio-tray-vol {
  width: 70px;
  accent-color: var(--brand-teal);
  cursor: pointer;
}

/* ================================================================
   SINGLE PAGE ILLUSTRATION
   ================================================================ */

.image-single img.page-illustration {
  width: 100%;
  display: block;
  cursor: zoom-in;
  aspect-ratio: 3 / 4;
  object-fit: cover;
}

.image-skeleton-single {
  width: 100%;
  aspect-ratio: 3 / 4;
  background: linear-gradient(
    90deg,
    var(--bg-surface) 25%,
    var(--bg-card-hover, rgba(255,255,255,0.06)) 50%,
    var(--bg-surface) 75%
  );
  background-size: 200% 100%;
  animation: shimmer 1.6s infinite;
}

/* ================================================================
   LANDSCAPE (TV / WIDESCREEN) MODE
   ================================================================ */
#readerBody.landscape { flex: 0 1 860px; }
#readerBody.landscape .page-image-wrap { max-width: none; }
#readerBody.landscape .image-controls-row { max-width: none; }
#readerBody.landscape .image-skeleton-single { aspect-ratio: 16 / 9; }
#readerBody.landscape .image-single img.page-illustration { aspect-ratio: 16 / 9; }
#readerBody.landscape .story-text-section { padding: 28px 20px 14px; }

/* ================================================================
   PRINT / EXPORT PDF
   ================================================================ */
@media print {
  @page { margin: 0.5in; }
  body { background: #fff !important; color: #000 !important; }
  header,
  .library-section,
  .reader-top .reader-progress,
  .reader-layout > .btn-nav-side,
  .reader-bottom,
  .image-controls-row,
  .loading-overlay,
  .modal-overlay,
  .toast-container,
  #toastContainer,
  .page-indicator { display: none !important; }
  #homePage { display: none !important; }
  #readerPage { display: block !important; padding: 0 !important; }
  .reader-top { text-align: center; padding-bottom: 12pt; }
  .reader-layout { display: block !important; }
  #readerBody {
    max-width: 100% !important;
    width: 100% !important;
    flex: none !important;
  }
  .story-page {
    display: block !important;
    break-after: page;
    page-break-after: always;
  }
  .story-page:last-child {
    break-after: avoid;
    page-break-after: avoid;
  }
  .page-image-wrap { max-width: 100% !important; border-radius: 0 !important; }
  .image-skeleton-single { display: none !important; }
  .image-single { display: block !important; }
  .image-single img.page-illustration {
    width: 100% !important;
    height: auto !important;
    aspect-ratio: auto !important;
    object-fit: contain !important;
    display: block !important;
  }
  .story-text-section {
    position: static !important;
    background: transparent !important;
    color: #000 !important;
    text-shadow: none !important;
    padding: 8pt 4pt !important;
    font-size: 11pt !important;
  }
}
