/* ============================================
   STORY FORGE — Layout
   ============================================ */

/* ---- APP SHELL ---- */
#app-shell {
  position: relative;
  min-height: 100vh;
  z-index: var(--z-base);
}

#app {
  min-height: calc(100vh - 64px);
  padding-top: 64px; /* navbar height */
}

/* ---- AURORA BACKGROUND ---- */
.aurora-bg {
  position: fixed;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  z-index: 0;
}

.aurora {
  position: absolute;
  border-radius: 50%;
  filter: blur(80px);
  opacity: 0.15;
  animation: auroraFloat linear infinite;
}

.aurora-1 {
  width: 600px;
  height: 600px;
  background: radial-gradient(circle, #7c3aed, transparent 70%);
  top: -200px;
  left: -100px;
  animation-duration: 25s;
}

.aurora-2 {
  width: 500px;
  height: 500px;
  background: radial-gradient(circle, #a855f7, transparent 70%);
  top: 20%;
  right: -150px;
  animation-duration: 30s;
  animation-delay: -10s;
}

.aurora-3 {
  width: 400px;
  height: 400px;
  background: radial-gradient(circle, #6366f1, transparent 70%);
  bottom: 10%;
  left: 30%;
  animation-duration: 20s;
  animation-delay: -5s;
}

/* Particles canvas */
#particles-canvas {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
}

/* ---- NAVBAR ---- */
.navbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 64px;
  z-index: var(--z-sticky);
  background: rgba(8, 8, 16, 0.9);
  backdrop-filter: blur(24px) saturate(180%);
  -webkit-backdrop-filter: blur(24px) saturate(180%);
  border-bottom: 1px solid rgba(124, 58, 237, 0.15);
  box-shadow: 0 1px 0 rgba(255,255,255,0.03), 0 4px 24px rgba(0,0,0,0.3);
  display: flex;
  align-items: center;
  padding: 0 var(--space-6);
  gap: var(--space-5);
}

.navbar-brand {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  text-decoration: none;
  flex-shrink: 0;
}

.navbar-logo {
  width: 32px;
  height: 32px;
  background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
}

.navbar-name {
  font-family: var(--font-serif);
  font-size: var(--text-xl);
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.02em;
}

.navbar-nav {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  flex: 1;
  justify-content: center;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: 8px 14px;
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--text-dim);
  text-decoration: none;
  transition: all var(--transition-fast);
  white-space: nowrap;
}
.nav-link:hover {
  color: var(--text-primary);
  background: var(--bg-glass);
}
.nav-link.active {
  color: var(--text-accent);
  background: rgba(124, 58, 237, 0.1);
}

.navbar-actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-shrink: 0;
}

.navbar-icon-btn {
  position: relative;
  background: var(--bg-glass);
  border: 1px solid var(--border-glass);
  border-radius: var(--radius-md);
  color: var(--text-dim);
  width: 38px;
  height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all var(--transition-fast);
}
.navbar-icon-btn:hover {
  color: var(--text-primary);
  background: var(--bg-glass-md);
  border-color: var(--border-medium);
}
.navbar-icon-btn.has-notifications::after {
  content: attr(data-count);
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: 18px;
  height: 18px;
  background: var(--accent-primary);
  border-radius: var(--radius-full);
  font-size: 10px;
  font-weight: 700;
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
  border: 2px solid var(--bg-deep);
}

/* ---- NOTIFICATIONS DROPDOWN ---- */
.notifications-dropdown {
  position: fixed;
  top: 70px;
  right: var(--space-6);
  width: 360px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-glass);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-modal);
  backdrop-filter: blur(20px);
  z-index: var(--z-dropdown);
  overflow: hidden;
  animation: dropdownSlideIn 0.2s ease;
}

.notifications-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-4) var(--space-5);
  border-bottom: 1px solid var(--border-subtle);
}
.notifications-title {
  font-weight: 600;
  font-size: var(--text-sm);
  color: var(--text-primary);
}
.notifications-list { max-height: 360px; overflow-y: auto; }
.notifications-empty {
  padding: var(--space-7) var(--space-5);
  text-align: center;
  color: var(--text-dim);
  font-size: var(--text-sm);
}

/* ---- SEARCH OVERLAY ---- */
.search-overlay {
  position: fixed;
  top: 64px;
  left: 0;
  right: 0;
  background: rgba(8, 8, 16, 0.95);
  backdrop-filter: blur(20px);
  z-index: var(--z-overlay);
  padding: var(--space-5);
  border-bottom: 1px solid var(--border-subtle);
  animation: slideDown 0.2s ease;
}

.search-input-wrapper {
  max-width: 640px;
  margin: 0 auto;
  position: relative;
}

.search-input {
  width: 100%;
  padding: 14px 48px 14px 48px;
  background: var(--bg-surface);
  border: 1px solid var(--border-medium);
  border-radius: var(--radius-lg);
  color: var(--text-primary);
  font-size: var(--text-base);
  font-family: var(--font-sans);
  transition: all var(--transition-fast);
}
.search-input:focus {
  outline: none;
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 3px var(--accent-glow-sm);
}

.search-icon {
  position: absolute;
  left: 16px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-dim);
  pointer-events: none;
}

.search-close {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
}

.search-results {
  max-width: 640px;
  margin: var(--space-4) auto 0;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  max-height: 360px;
  overflow-y: auto;
}

.search-result-item {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  padding: var(--space-3) var(--space-4);
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all var(--transition-fast);
  text-decoration: none;
}
.search-result-item:hover {
  border-color: var(--border-medium);
  background: var(--bg-elevated);
}

.search-result-cover {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-sm);
  flex-shrink: 0;
}

.search-result-info { flex: 1; min-width: 0; }
.search-result-title {
  font-family: var(--font-serif);
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.search-result-meta {
  font-size: var(--text-xs);
  color: var(--text-dim);
  margin-top: 2px;
}

/* ---- PAGE CONTAINER ---- */
.page-container {
  max-width: 1280px;
  margin: 0 auto;
  padding: var(--space-7) var(--space-6);
  position: relative;
  z-index: var(--z-base);
}

.page-container-sm {
  max-width: 680px;
}

.page-container-md {
  max-width: 900px;
}

/* ---- HERO SECTION ---- */
.hero {
  text-align: center;
  padding: var(--space-9) var(--space-6) var(--space-8);
  position: relative;
  z-index: var(--z-base);
  overflow: hidden;
}
.hero::before {
  content: '';
  position: absolute;
  top: -50%;
  left: 50%;
  transform: translateX(-50%);
  width: 900px;
  height: 900px;
  background: radial-gradient(circle, rgba(124,58,237,0.07) 0%, transparent 65%);
  pointer-events: none;
  z-index: 0;
}
.hero > * { position: relative; z-index: 1; }

.hero-badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  background: rgba(124, 58, 237, 0.1);
  border: 1px solid var(--border-medium);
  border-radius: var(--radius-full);
  padding: 7px 18px;
  font-size: var(--text-xs);
  color: var(--text-accent);
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  margin-bottom: var(--space-5);
  animation: fadeInDown 0.5s ease both;
}

.hero-title {
  font-family: var(--font-serif);
  font-size: clamp(2.5rem, 6vw, var(--text-6xl));
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.1;
  margin-bottom: var(--space-5);
  letter-spacing: -0.02em;
  animation: fadeInUp 0.5s ease 0.1s both;
}

.hero-title .gradient-text {
  background: linear-gradient(135deg, var(--accent-secondary), #e879f9, #38bdf8, var(--accent-secondary));
  background-size: 300% auto;
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  animation: gradientShift 5s linear infinite;
}

.hero-subtitle {
  font-size: var(--text-lg);
  color: var(--text-secondary);
  max-width: 520px;
  margin: 0 auto var(--space-7);
  line-height: 1.75;
  animation: fadeInUp 0.5s ease 0.2s both;
}

.hero-actions {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-4);
  flex-wrap: wrap;
  animation: fadeInUp 0.5s ease 0.3s both;
}

/* ---- HOME STATS ROW ---- */
.home-stats-row {
  display: flex;
  gap: var(--space-3);
  flex-wrap: wrap;
  margin-bottom: var(--space-5);
}
.home-stat-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: var(--space-3) var(--space-5);
  display: flex;
  align-items: center;
  gap: var(--space-3);
  text-decoration: none;
  transition: all var(--transition-fast);
  position: relative;
  overflow: hidden;
}
.home-stat-card--link:hover {
  border-color: var(--stat-color, var(--accent-primary));
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(0,0,0,0.2);
}
.home-stat-emoji {
  font-size: 1.4rem;
  line-height: 1;
}
.home-stat-label {
  font-size: var(--text-xs);
  color: var(--text-dim);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.home-stat-val {
  font-weight: 700;
  color: var(--text-primary);
  font-size: var(--text-2xl);
  line-height: 1.1;
  font-family: var(--font-serif);
}

/* ---- STORIES GRID ---- */
.stories-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: var(--space-5);
}

/* ---- FILTER BAR ---- */
.filter-bar {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  flex-wrap: wrap;
  padding: var(--space-4) 0;
}

.filter-scroll {
  display: flex;
  gap: var(--space-2);
  overflow-x: auto;
  scrollbar-width: none;
  -ms-overflow-style: none;
  flex: 1;
  padding-bottom: 2px;
}
.filter-scroll::-webkit-scrollbar { display: none; }

.filter-chip {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: 6px 14px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-full);
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--text-dim);
  cursor: pointer;
  transition: all var(--transition-fast);
  white-space: nowrap;
  font-family: var(--font-sans);
}
.filter-chip:hover {
  color: var(--text-secondary);
  border-color: var(--border-medium);
  background: var(--bg-elevated);
}
.filter-chip.active {
  background: var(--accent-primary);
  border-color: var(--accent-primary);
  color: white;
  box-shadow: 0 2px 8px var(--accent-glow-sm);
}

/* ---- AUTH PAGES ---- */
.auth-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-5);
  position: relative;
  z-index: var(--z-base);
}

.auth-card {
  width: 100%;
  max-width: 440px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-glass);
  border-radius: var(--radius-xl);
  padding: var(--space-7);
  box-shadow: var(--shadow-modal), 0 0 80px rgba(124,58,237,0.08);
  position: relative;
  overflow: hidden;
}
.auth-card::before {
  content: '';
  position: absolute;
  top: -60px;
  left: 50%;
  transform: translateX(-50%);
  width: 300px;
  height: 300px;
  background: radial-gradient(circle, rgba(124,58,237,0.1) 0%, transparent 70%);
  pointer-events: none;
  z-index: 0;
}
.auth-card > * { position: relative; z-index: 1; }

.auth-logo {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-3);
  margin-bottom: var(--space-6);
  text-align: center;
}

.auth-logo-icon {
  width: 60px;
  height: 60px;
  background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2rem;
  box-shadow: 0 8px 32px var(--accent-glow), inset 0 1px 0 rgba(255,255,255,0.15);
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

/* Avatar pick buttons (register) */
.avatar-pick-btn {
  width: 38px;
  height: 38px;
  padding: 0;
  background: var(--bg-surface);
  border: 2px solid transparent;
  border-radius: var(--radius-md);
  font-size: 1.3rem;
  cursor: pointer;
  transition: all var(--transition-fast);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.avatar-pick-btn:hover {
  border-color: var(--border-medium);
  background: var(--bg-glass-md);
  transform: scale(1.1);
}
.avatar-pick-btn.active {
  border-color: var(--accent-primary);
  background: rgba(124,58,237,0.15);
  box-shadow: 0 0 12px rgba(124,58,237,0.3);
  transform: scale(1.1);
}

/* ---- BOOK LAYOUT ---- */
.book-layout {
  min-height: calc(100vh - 64px);
  position: relative;
  z-index: var(--z-base);
}

/* ── BOOK COVER PAGE ── */
.book-cover-page {
  max-width: 720px;
  margin: 0 auto;
  padding: var(--space-6) var(--space-5) var(--space-10);
  position: relative;
}
.book-back-btn {
  margin-bottom: var(--space-5);
  display: inline-flex;
  gap: var(--space-2);
}
.book-cover-art {
  width: 100%;
  height: 380px;
  border-radius: var(--radius-xl);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
  box-shadow: 0 24px 80px rgba(0,0,0,0.6), 0 0 0 1px var(--border-subtle);
  margin-bottom: var(--space-7);
}
.book-cover-shine {
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, rgba(255,255,255,0.08) 0%, transparent 50%, rgba(0,0,0,0.3) 100%);
  pointer-events: none;
}
.book-cover-emoji {
  font-size: 8rem;
  filter: drop-shadow(0 12px 32px rgba(0,0,0,0.6));
  animation: float 5s ease-in-out infinite;
  position: relative;
  z-index: 1;
}
.book-cover-genre {
  position: absolute;
  bottom: var(--space-5);
  left: 50%;
  transform: translateX(-50%);
  font-size: var(--text-xs);
  font-weight: 700;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: rgba(255,255,255,0.7);
  background: rgba(0,0,0,0.4);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  padding: 5px 16px;
  border-radius: var(--radius-full);
  border: 1px solid rgba(255,255,255,0.15);
}
.book-cover-info {
  padding: 0 var(--space-2);
}
.book-title {
  font-family: var(--font-serif);
  font-size: clamp(2rem, 5vw, 3.2rem);
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.15;
  letter-spacing: -0.02em;
  margin-bottom: var(--space-3);
}
.book-author {
  font-family: var(--font-serif);
  font-size: var(--text-lg);
  color: var(--text-dim);
  font-style: italic;
  margin-bottom: var(--space-5);
}
.book-meta-row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  margin-bottom: var(--space-5);
}
.book-meta-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: var(--text-xs);
  color: var(--text-dim);
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  padding: 4px 12px;
  border-radius: var(--radius-full);
}
.book-details-row {
  display: flex;
  gap: var(--space-6);
  flex-wrap: wrap;
  padding: var(--space-4) var(--space-5);
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  margin-bottom: var(--space-5);
}
.book-detail {
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.book-detail-label {
  font-size: var(--text-xs);
  font-weight: 700;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.book-detail-val {
  font-size: var(--text-sm);
  color: var(--text-secondary);
}
.book-cover-actions {
  display: flex;
  gap: var(--space-3);
  flex-wrap: wrap;
  margin-bottom: var(--space-7);
}

/* Book TOC on cover */
.book-toc {
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  overflow: hidden;
}
.book-toc-title {
  font-size: var(--text-xs);
  font-weight: 700;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  padding: var(--space-4) var(--space-5) var(--space-3);
  border-bottom: 1px solid var(--border-subtle);
}
.book-toc-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  width: 100%;
  padding: var(--space-3) var(--space-5);
  background: none;
  border: none;
  border-bottom: 1px solid var(--border-subtle);
  cursor: pointer;
  text-align: left;
  transition: background var(--transition-fast);
}
.book-toc-item:last-child { border-bottom: none; }
.book-toc-item:hover { background: var(--bg-elevated); }
.book-toc-num {
  font-size: var(--text-xs);
  font-weight: 700;
  color: var(--text-dim);
  min-width: 44px;
  flex-shrink: 0;
}
.book-toc-label {
  font-size: var(--text-sm);
  color: var(--text-secondary);
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.book-toc-words {
  font-size: var(--text-xs);
  color: var(--text-dim);
  flex-shrink: 0;
}
.book-toc-add { background: rgba(124,58,237,0.05); }
.book-toc-add:hover { background: rgba(124,58,237,0.12); }

/* ── BOOK READING VIEW ── */
.book-reading-view {
  flex-direction: column;
  min-height: calc(100vh - 64px);
  position: relative;
}

/* Top bar */
.book-topbar {
  position: sticky;
  top: 64px;
  z-index: var(--z-sticky);
  background: rgba(13,13,26,0.9);
  -webkit-backdrop-filter: blur(16px);
  backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--space-5);
  height: 52px;
  gap: var(--space-3);
}
.book-topbar-btn {
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  padding: var(--space-2);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color var(--transition-fast), background var(--transition-fast);
  font-size: var(--text-base);
  line-height: 1;
  min-width: 32px;
  height: 32px;
}
.book-topbar-btn:hover, .book-topbar-btn.active { color: var(--text-primary); background: var(--bg-glass-md); }
.book-topbar-title {
  flex: 1;
  font-size: var(--text-sm);
  color: var(--text-dim);
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-family: var(--font-serif);
  font-style: italic;
}

/* Settings panel */
.book-settings-panel {
  position: sticky;
  top: 116px;
  z-index: calc(var(--z-sticky) - 1);
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border-subtle);
  padding: var(--space-3) var(--space-5);
  box-shadow: 0 4px 20px rgba(0,0,0,0.3);
}
.book-settings-inner {
  max-width: 860px;
  margin: 0 auto;
  display: flex;
  gap: var(--space-4) var(--space-6);
  flex-wrap: wrap;
  align-items: center;
}
.book-settings-row {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}
.book-settings-label {
  font-size: 10px;
  color: var(--text-dim);
  font-weight: 700;
  white-space: nowrap;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  min-width: 52px;
}
.book-font-btns {
  display: flex;
  gap: 3px;
}
.book-font-btn, .book-width-btn, .book-lh-btn, .book-ff-btn, .book-theme-btn {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  color: var(--text-dim);
  cursor: pointer;
  padding: 4px 10px;
  border-radius: var(--radius-sm);
  font-family: var(--font-sans);
  transition: all var(--transition-fast);
  font-size: var(--text-xs);
  line-height: 1.4;
}
.book-font-btn { font-family: var(--font-serif); }
.book-font-btn:hover, .book-width-btn:hover,
.book-lh-btn:hover, .book-ff-btn:hover, .book-theme-btn:hover {
  color: var(--text-primary);
  border-color: var(--border-medium);
  background: var(--bg-glass-md);
}
.book-font-btn.active, .book-width-btn.active,
.book-lh-btn.active, .book-ff-btn.active {
  background: var(--accent-primary);
  border-color: var(--accent-primary);
  color: #fff;
}
.book-theme-btn.active {
  outline: 2px solid var(--accent-primary);
  outline-offset: 2px;
}

/* TOC side drawer */
.book-toc-drawer {
  position: fixed;
  top: 116px;
  right: 0;
  bottom: 0;
  width: min(320px, 85vw);
  background: var(--bg-elevated);
  border-left: 1px solid var(--border-subtle);
  z-index: var(--z-dropdown);
  overflow-y: auto;
  box-shadow: -8px 0 32px rgba(0,0,0,0.4);
}
.book-toc-drawer-inner {
  padding: var(--space-5);
}
.book-toc-drawer-item {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  width: 100%;
  padding: var(--space-3) var(--space-3);
  background: none;
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
  text-align: left;
  transition: background var(--transition-fast);
  margin-bottom: 2px;
}
.book-toc-drawer-item:hover { background: var(--bg-glass-md); }
.book-toc-drawer-item.active { background: rgba(124,58,237,0.12); }
.book-toc-drawer-item.active .book-toc-num { color: var(--accent-primary); }
.book-toc-drawer-item .book-toc-label { color: var(--text-primary); font-size: var(--text-sm); font-weight: 500; }
.book-toc-drawer-item .book-toc-words { color: var(--text-dim); font-size: var(--text-xs); margin-top: 2px; }
.book-toc-drawer-item .book-toc-num { padding-top: 2px; }

/* Content area */
.book-content-area {
  --book-max-width: 680px;
  flex: 1;
  display: flex;
  justify-content: center;
  padding: var(--space-8) var(--space-5);
}
.book-content {
  width: 100%;
  max-width: var(--book-max-width);
}

/* Chapter heading */
.book-chapter-label {
  font-size: var(--text-xs);
  font-weight: 700;
  color: var(--accent-primary);
  text-transform: uppercase;
  letter-spacing: 0.2em;
  text-align: center;
  margin-bottom: var(--space-3);
  opacity: 0.8;
}
.book-chapter-title {
  font-family: var(--font-serif);
  font-size: clamp(1.6rem, 4vw, 2.4rem);
  font-weight: 700;
  color: var(--text-primary);
  text-align: center;
  line-height: 1.2;
  margin-bottom: var(--space-4);
  letter-spacing: -0.01em;
}
.book-chapter-ornament {
  text-align: center;
  color: var(--text-dim);
  font-size: var(--text-xs);
  letter-spacing: 0.8em;
  margin-bottom: var(--space-8);
  opacity: 0.4;
}

/* Chapter transition animation */
.chapter-transition {
  animation: fadeIn 0.35s ease both;
}

/* ── TTS HIGHLIGHTING ── */
.sentence {
  transition: background-color 0.3s ease, color 0.3s ease;
  border-radius: 4px;
}
.sentence.tts-active {
  background-color: var(--accent-primary-dim, rgba(124, 58, 237, 0.15));
  color: var(--text-primary);
  box-shadow: 0 0 0 2px var(--accent-primary-dim, rgba(124, 58, 237, 0.15));
}

/* ── TYPOGRAPHY ENHANCEMENTS ── */
.story-content p:first-child::first-letter {
  float: left;
  font-size: 3.5rem;
  line-height: 0.8;
  margin: 0.1em 0.1em 0 0;
  font-family: var(--font-serif);
  font-weight: 700;
  color: var(--accent-primary);
}

.story-content p.dialogue {
  position: relative;
  padding-left: var(--space-2);
}

.story-content p.thought {
  font-style: italic;
  color: var(--text-dim);
  border-left: 3px solid var(--accent-secondary-dim, rgba(56, 189, 248, 0.2));
  padding-left: var(--space-4);
  margin-left: var(--space-2);
}

/* Story content in book */
.book-story-content {
  font-size: 1.125rem;
  line-height: 1.95;
}

/* Bottom nav */
.book-nav-bar {
  position: sticky;
  bottom: 0;
  background: rgba(13,13,26,0.92);
  -webkit-backdrop-filter: blur(16px);
  backdrop-filter: blur(16px);
  border-top: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-3) var(--space-5);
  height: 56px;
}
.book-nav-btn {
  background: none;
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  cursor: pointer;
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  display: flex;
  align-items: center;
  gap: var(--space-2);
  transition: all var(--transition-fast);
  font-family: var(--font-sans);
}
.book-nav-btn:hover {
  color: var(--text-primary);
  border-color: var(--border-medium);
  background: var(--bg-glass-md);
}
.book-nav-center {
  flex: 1;
  text-align: center;
}

/* Chapter gen panel */
.book-gen-panel {
  max-width: 720px;
  margin: 0 auto;
  padding: var(--space-6) var(--space-5) var(--space-10);
}

/* Streaming cursor */
.streaming-cursor::after {
  content: '▋';
  animation: blink 0.8s step-end infinite;
  color: var(--accent-secondary);
  font-weight: normal;
}

/* Chapter gen components */
.chapter-gen-container {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-xl);
  padding: var(--space-5) var(--space-6);
}
.chapter-gen-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-4);
  flex-wrap: wrap;
  gap: var(--space-3);
}
.chapter-gen-output {
  font-family: var(--font-serif);
  font-size: var(--text-base);
  line-height: 2;
  color: var(--text-primary);
  white-space: pre-wrap;
  padding: var(--space-4) 0;
  border-top: 1px solid var(--border-subtle);
}

/* Chapter config form */
.chapter-gen-config {
  display: flex;
  flex-direction: column;
  gap: 0;
}
.chapter-gen-config-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding-bottom: var(--space-5);
  border-bottom: 1px solid var(--border-subtle);
  margin-bottom: var(--space-5);
  color: var(--accent-secondary);
}
.chapter-gen-config-body {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  margin-bottom: var(--space-5);
}
.chapter-gen-config-footer {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding-top: var(--space-5);
  border-top: 1px solid var(--border-subtle);
  flex-wrap: wrap;
}

/* ── Responsive ── */
@media (max-width: 640px) {
  .book-cover-art { height: 260px; }
  .book-cover-emoji { font-size: 5rem; }
  .book-title { font-size: 1.8rem; }
  .book-content-area { padding: var(--space-5) var(--space-4); }
  .book-toc-drawer { top: 64px; }
}
/* Scrollbar in reader */
.book-reading-view::-webkit-scrollbar { display: none; }

/* ---- GENERATOR PAGE ---- */
.generator-page {
  max-width: 800px;
  margin: 0 auto;
  padding: var(--space-7) var(--space-6);
  position: relative;
  z-index: var(--z-base);
}

/* Header */
.generator-header {
  text-align: center;
  margin-bottom: var(--space-8);
}
.generator-title {
  font-family: var(--font-serif);
  font-size: clamp(2rem, 5vw, 3rem);
  color: var(--text-primary);
  letter-spacing: -0.02em;
  margin-bottom: var(--space-3);
  line-height: 1.1;
}
.generator-subtitle {
  color: var(--text-secondary);
  max-width: 480px;
  margin: 0 auto var(--space-5);
  font-size: var(--text-base);
  line-height: 1.7;
}

/* Ollama status badge */
.gen-ollama-badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: 6px 14px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-full);
  font-size: var(--text-xs);
  color: var(--text-dim);
  margin-bottom: var(--space-5);
  transition: all var(--transition-base);
}
.gen-ollama-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-dim);
  flex-shrink: 0;
}
.gen-ollama-text code {
  font-family: var(--font-mono, monospace);
  font-size: 0.9em;
  background: rgba(255,255,255,0.07);
  padding: 1px 5px;
  border-radius: 3px;
}

/* Card base */
.gen-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-xl);
  padding: var(--space-5) var(--space-6);
  margin-bottom: var(--space-4);
  transition: border-color var(--transition-fast);
}
.gen-card:focus-within { border-color: var(--border-medium); }

/* Section header (label + current selection) */
.gen-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-4);
}
.gen-section-label {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-xs);
  font-weight: 700;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.gen-section-selected {
  font-size: var(--text-xs);
  color: var(--text-accent);
  font-weight: 600;
}

/* ── Genre grid ── */
.gen-genre-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: var(--space-3);
}
.gen-genre-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-4) var(--space-2);
  background: var(--bg-elevated);
  border: 2px solid transparent;
  border-radius: var(--radius-lg);
  cursor: pointer;
  transition: all var(--transition-fast);
  font-family: var(--font-sans);
  position: relative;
  overflow: hidden;
}
.gen-genre-btn::before {
  content: '';
  position: absolute;
  inset: 0;
  background: var(--genre-color, var(--accent-primary));
  opacity: 0;
  transition: opacity var(--transition-fast);
}
.gen-genre-btn:hover::before { opacity: 0.07; }
.gen-genre-btn.active::before { opacity: 0.14; }
.gen-genre-btn:hover {
  border-color: var(--genre-color, var(--accent-primary));
  transform: translateY(-2px);
  box-shadow: 0 4px 16px rgba(0,0,0,0.25);
}
.gen-genre-btn.active {
  border-color: var(--genre-color, var(--accent-primary));
  box-shadow: 0 0 0 1px var(--genre-color, var(--accent-primary)), 0 6px 20px rgba(0,0,0,0.3);
}
.gen-genre-emoji {
  font-size: 1.9rem;
  line-height: 1;
  position: relative;
  z-index: 1;
  transition: transform var(--transition-fast);
}
.gen-genre-btn:hover .gen-genre-emoji,
.gen-genre-btn.active .gen-genre-emoji { transform: scale(1.2) rotate(-3deg); }
.gen-genre-label {
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--text-dim);
  position: relative;
  z-index: 1;
  white-space: normal;
  text-align: center;
  line-height: 1.25;
  transition: color var(--transition-fast);
}
.gen-genre-btn:hover .gen-genre-label { color: var(--text-secondary); }
.gen-genre-btn.active .gen-genre-label { color: var(--text-primary); }

/* ── Mood grid ── */
.gen-mood-grid {
  display: flex;
  gap: var(--space-2);
  flex-wrap: wrap;
}
.gen-mood-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 15px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-full);
  cursor: pointer;
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--text-dim);
  transition: all var(--transition-fast);
  white-space: nowrap;
}
.gen-mood-emoji { font-size: 1rem; line-height: 1; }
.gen-mood-btn:hover {
  color: var(--text-primary);
  border-color: var(--border-medium);
  background: var(--bg-glass-md);
  transform: translateY(-1px);
}
.gen-mood-btn.active {
  background: rgba(124,58,237,0.14);
  border-color: var(--accent-primary);
  color: var(--text-accent);
  box-shadow: 0 0 14px rgba(124,58,237,0.22), inset 0 1px 0 rgba(168,85,247,0.15);
}

/* ── Length grid ── */
.gen-length-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--space-3);
}
.gen-length-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: var(--space-4) var(--space-3);
  background: var(--bg-elevated);
  border: 2px solid transparent;
  border-radius: var(--radius-lg);
  cursor: pointer;
  font-family: var(--font-sans);
  transition: all var(--transition-fast);
  text-align: center;
}
.gen-length-btn:hover {
  border-color: var(--border-medium);
  background: var(--bg-glass-md);
  transform: translateY(-2px);
  box-shadow: 0 4px 16px rgba(0,0,0,0.25);
}
.gen-length-btn.active {
  border-color: var(--accent-primary);
  background: rgba(124,58,237,0.1);
  box-shadow: 0 0 0 1px var(--accent-primary), 0 6px 20px rgba(124,58,237,0.18);
}
.gen-length-icon {
  font-size: 1.5rem;
  line-height: 1;
  margin-bottom: 2px;
  transition: transform var(--transition-fast);
}
.gen-length-btn:hover .gen-length-icon,
.gen-length-btn.active .gen-length-icon { transform: scale(1.15); }
.gen-length-label {
  font-size: var(--text-sm);
  font-weight: 700;
  color: var(--text-secondary);
  transition: color var(--transition-fast);
}
.gen-length-btn.active .gen-length-label { color: var(--text-accent); }
.gen-length-desc {
  font-size: var(--text-xs);
  color: var(--text-dim);
}
.gen-length-time {
  font-size: 10px;
  color: var(--text-dim);
  opacity: 0.6;
  margin-top: 1px;
}

/* ── Details section ── */
.gen-details-section { padding: var(--space-4) var(--space-6); }
.gen-details-toggle {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  width: 100%;
  background: transparent;
  border: none;
  cursor: pointer;
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--text-secondary);
  padding: 0;
  transition: color var(--transition-fast);
}
.gen-details-toggle:hover { color: var(--text-primary); }
.gen-details-arrow {
  margin-left: auto;
  transition: transform var(--transition-fast);
  font-size: var(--text-sm);
  color: var(--text-dim);
}
.gen-details-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--accent-primary);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
}
.gen-details-panel {
  max-height: 0;
  opacity: 0;
  overflow: hidden;
  transition: max-height 0.35s ease, opacity 0.3s ease, padding-top 0.3s ease;
  padding-top: 0;
}
.gen-details-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-4);
}

/* ── Visibility row ── */
.gen-visibility-row {
  display: flex;
  align-items: center;
  padding: var(--space-3) var(--space-5);
}
.gen-visibility-label {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  cursor: pointer;
  flex: 1;
}
.gen-visibility-chk { display: none; }
.gen-visibility-track {
  width: 40px;
  height: 22px;
  border-radius: var(--radius-full);
  background: var(--border-medium);
  position: relative;
  flex-shrink: 0;
  transition: background var(--transition-fast);
}
.gen-visibility-track::after {
  content: '';
  position: absolute;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  top: 3px;
  left: 3px;
  transition: transform var(--transition-fast);
}
.gen-visibility-chk:checked + .gen-visibility-track { background: var(--accent-primary); }
.gen-visibility-chk:checked + .gen-visibility-track::after { transform: translateX(18px); }
.gen-visibility-title {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: var(--space-1);
}
.gen-visibility-sub {
  font-size: var(--text-xs);
  color: var(--text-dim);
  margin-top: 2px;
}

/* ── Submit card ── */
.gen-submit-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-medium);
  border-radius: var(--radius-xl);
  padding: var(--space-4) var(--space-5);
  display: flex;
  align-items: center;
  gap: var(--space-4);
  box-shadow: 0 8px 40px rgba(0,0,0,0.3), inset 0 1px 0 rgba(255,255,255,0.04);
  margin-top: var(--space-2);
  position: relative;
  overflow: hidden;
}
.gen-submit-card::before {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse at 20% 50%, rgba(124,58,237,0.06) 0%, transparent 65%);
  pointer-events: none;
}
.gen-submit-cover {
  width: 76px;
  height: 76px;
  border-radius: var(--radius-lg);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background var(--transition-slow);
  box-shadow: 0 4px 20px rgba(0,0,0,0.45);
}
.gen-submit-cover-emoji {
  font-size: 2.6rem;
  filter: drop-shadow(0 3px 10px rgba(0,0,0,0.5));
  transition: transform var(--transition-fast);
}
.gen-submit-card:hover .gen-submit-cover-emoji { transform: scale(1.1) rotate(-5deg); }
.gen-submit-info { flex: 1; min-width: 0; }
.gen-submit-tags {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  margin-bottom: var(--space-2);
}
.gen-submit-tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 9px;
  background: rgba(124,58,237,0.1);
  border: 1px solid rgba(124,58,237,0.2);
  border-radius: var(--radius-full);
  font-size: var(--text-xs);
  color: var(--text-secondary);
  font-weight: 500;
}
.gen-submit-hint {
  font-size: var(--text-xs);
  color: var(--text-dim);
}
.gen-submit-btn {
  flex-shrink: 0;
  white-space: nowrap;
  animation: glowPulse 3s ease-in-out infinite;
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
}

/* Random idea button */
.gen-random-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-full);
  cursor: pointer;
  font-family: var(--font-sans);
  font-size: var(--text-xs);
  color: var(--text-dim);
  transition: all var(--transition-fast);
  white-space: nowrap;
}
.gen-random-btn:hover {
  color: var(--text-accent);
  border-color: var(--accent-primary);
  background: rgba(124,58,237,0.08);
  transform: translateY(-1px);
}
.gen-random-btn:active { transform: translateY(0) scale(0.97); }

/* Extra detail info in submit preview */
.gen-submit-extra { margin-bottom: var(--space-2); }
.gen-submit-extra-text {
  font-size: var(--text-xs);
  color: var(--text-secondary);
}

/* ── Streaming view ── */
.gen-stream-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-3) var(--space-5);
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-xl) var(--radius-xl) 0 0;
  flex-wrap: wrap;
  gap: var(--space-3);
}
.gen-stream-meta {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}
.gen-stream-controls {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.gen-status-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--accent-primary);
  animation: pulse 1.2s ease-in-out infinite;
  flex-shrink: 0;
  box-shadow: 0 0 8px var(--accent-primary);
  transition: background var(--transition-fast);
}
.gen-status-dot.done  { background: var(--accent-teal); box-shadow: 0 0 8px var(--accent-teal); animation: none; }
.gen-status-dot.error { background: var(--accent-rose); box-shadow: 0 0 8px var(--accent-rose); animation: none; }

.gen-status-text {
  font-size: var(--text-sm);
  color: var(--text-secondary);
  font-weight: 500;
}

.gen-word-badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-full);
  font-size: var(--text-xs);
  color: var(--text-dim);
  font-weight: 600;
}

/* Passes indicator */
.gen-passes {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}
.gen-pass-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--border-medium);
  border: 1px solid var(--border-subtle);
  transition: all var(--transition-fast);
}
.gen-pass-dot.active {
  background: var(--accent-primary);
  box-shadow: 0 0 6px var(--accent-primary);
  animation: pulse 1s infinite;
}
.gen-pass-dot.done {
  background: var(--accent-teal);
  border-color: var(--accent-teal);
  animation: none;
}

.gen-cancel-btn { color: var(--text-dim); }
.gen-cancel-btn:hover { color: var(--accent-rose); }

/* Progress */
.gen-progress-wrap {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-5);
  background: var(--bg-surface);
  border-left: 1px solid var(--border-subtle);
  border-right: 1px solid var(--border-subtle);
}
.gen-progress-track {
  flex: 1;
  height: 4px;
  background: var(--border-subtle);
  border-radius: var(--radius-full);
  overflow: hidden;
}
.gen-progress-fill {
  height: 100%;
  width: 5%;
  background: linear-gradient(90deg, var(--accent-primary), var(--accent-secondary), var(--accent-primary));
  background-size: 200% auto;
  border-radius: var(--radius-full);
  transition: width 0.6s ease;
  animation: gradientShift 2s linear infinite;
  box-shadow: 0 0 8px var(--accent-glow-sm);
}
.gen-progress-fill.complete {
  background: var(--accent-teal);
  animation: none;
  box-shadow: 0 0 10px var(--accent-teal);
}
.gen-progress-pct {
  font-size: 11px;
  color: var(--text-dim);
  font-weight: 600;
  min-width: 32px;
  text-align: right;
}

/* Story render area */
.gen-stream-body {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-top: none;
  border-radius: 0 0 var(--radius-xl) var(--radius-xl);
  padding: var(--space-7) var(--space-8);
  min-height: 360px;
  box-shadow: 0 8px 40px rgba(0,0,0,0.25);
  margin-bottom: var(--space-4);
}

.streaming-title {
  font-family: var(--font-serif);
  font-size: clamp(1.5rem, 4vw, 2.4rem);
  color: var(--text-primary);
  margin-bottom: var(--space-6);
  line-height: 1.2;
  letter-spacing: -0.01em;
}

/* Paragraph appear animation during streaming */
#streaming-content p {
  animation: paraAppear 0.3s ease both;
}

/* Post-generation actions panel */
.gen-actions-panel {
  background: var(--bg-surface);
  border: 1px solid var(--border-medium);
  border-radius: var(--radius-xl);
  padding: var(--space-5) var(--space-6);
  animation: fadeInUp 0.5s ease both;
  box-shadow: 0 8px 40px rgba(0,0,0,0.25);
}
.gen-actions-stats {
  display: flex;
  gap: var(--space-6);
  justify-content: center;
  margin-bottom: var(--space-5);
  padding-bottom: var(--space-4);
  border-bottom: 1px solid var(--border-subtle);
}
.gen-stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}
.gen-stat-val {
  font-size: var(--text-lg);
  font-weight: 700;
  color: var(--text-primary);
}
.gen-stat-lbl {
  font-size: var(--text-xs);
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.gen-actions-title-row {
  margin-bottom: var(--space-3);
}
.gen-actions-title-label {
  display: block;
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: var(--space-2);
}
.gen-actions-title-input {
  font-family: var(--font-serif);
  font-size: var(--text-lg);
  font-weight: 600;
}
.gen-actions-visibility-row {
  margin-bottom: var(--space-4);
  padding-bottom: var(--space-4);
  border-bottom: 1px solid var(--border-subtle);
}
.gen-visibility-label--compact {
  gap: var(--space-3);
}
.gen-visibility-label--compact .gen-visibility-title {
  font-size: var(--text-sm);
}
.gen-actions-row {
  display: flex;
  gap: var(--space-3);
  flex-wrap: wrap;
  justify-content: center;
}

.generator-form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-4);
}

/* Responsive */
@media (max-width: 640px) {
  .generator-page { padding: var(--space-5) var(--space-4); }
  .gen-card { padding: var(--space-4); }
  .gen-genre-grid { grid-template-columns: repeat(4, 1fr); gap: var(--space-2); }
  .gen-genre-btn { padding: var(--space-3) var(--space-1); }
  .gen-genre-emoji { font-size: 1.4rem; }
  .gen-genre-label { font-size: 9px; }
  .gen-length-grid { grid-template-columns: repeat(2, 1fr); }
  .gen-details-grid { grid-template-columns: 1fr; }
  .gen-submit-card { flex-wrap: wrap; }
  .gen-submit-btn { width: 100%; justify-content: center; }
  .gen-stream-body { padding: var(--space-5) var(--space-4); }
  .gen-actions-stats { gap: var(--space-4); }
  .gen-actions-row { flex-direction: column; }
  .gen-actions-row .btn { width: 100%; justify-content: center; }
}

/* ---- PROFILE PAGE ---- */
.profile-page {
  max-width: 900px;
  margin: 0 auto;
  padding: var(--space-7) var(--space-6);
  position: relative;
  z-index: var(--z-base);
}

.profile-header {
  display: flex;
  align-items: center;
  gap: var(--space-6);
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-xl);
  padding: var(--space-7);
  margin-bottom: var(--space-6);
}

.profile-stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--space-4);
  margin-bottom: var(--space-6);
}

.profile-section {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-xl);
  padding: var(--space-6);
  margin-bottom: var(--space-5);
}

.profile-section-title {
  font-family: var(--font-serif);
  font-size: var(--text-xl);
  color: var(--text-primary);
  margin-bottom: var(--space-5);
  padding-bottom: var(--space-4);
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

/* Profile header tweaks */
.profile-avatar-wrap {
  position: relative;
  flex-shrink: 0;
}
.profile-avatar {
  font-size: 2.5rem;
  cursor: pointer;
  transition: transform var(--transition-fast), box-shadow var(--transition-fast);
}
.profile-avatar:hover { transform: scale(1.05); box-shadow: 0 0 20px var(--accent-glow); }
.profile-avatar-edit {
  position: absolute;
  bottom: -2px;
  right: -2px;
  width: 22px;
  height: 22px;
  background: var(--accent-primary);
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  pointer-events: none;
  border: 2px solid var(--bg-surface);
}
.profile-username {
  font-family: var(--font-serif);
  font-size: var(--text-3xl);
  color: var(--text-primary);
  line-height: 1.1;
}
.profile-bio {
  color: var(--text-secondary);
  font-size: var(--text-sm);
  line-height: 1.65;
  max-width: 480px;
}
.profile-logout { color: var(--text-dim); align-self: flex-start; }
.profile-bio-input {
  resize: vertical;
  min-height: 80px;
}
.stat-card-bar {
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  border-radius: var(--radius-xl) var(--radius-xl) 0 0;
}
.gradient-stat {
  background: linear-gradient(135deg, var(--accent-secondary), var(--accent-primary));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

/* Profile activity grid */
.profile-activity-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-5);
}
@media (max-width: 640px) {
  .profile-activity-grid { grid-template-columns: 1fr; }
}

/* Mini stats */
.profile-mini-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-3);
}
.profile-mini-stat {
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: var(--space-4);
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.profile-mini-val {
  font-size: var(--text-2xl);
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1;
}
.profile-mini-label {
  font-size: var(--text-xs);
  color: var(--text-dim);
  line-height: 1.4;
}

/* Genre bars */
.profile-genres {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}
.profile-genres-title {
  font-size: var(--text-xs);
  font-weight: 700;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: var(--space-1);
}
.profile-genre-bar {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}
.profile-genre-label {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: var(--text-sm);
  color: var(--text-secondary);
  min-width: 90px;
}
.profile-genre-track {
  flex: 1;
  height: 6px;
  background: var(--bg-elevated);
  border-radius: var(--radius-full);
  overflow: hidden;
}
.profile-genre-fill {
  height: 100%;
  border-radius: var(--radius-full);
  transition: width 0.6s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.profile-genre-count {
  font-size: var(--text-xs);
  color: var(--text-dim);
  min-width: 16px;
  text-align: right;
}

/* Notification toggles */
.profile-notif-row {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  padding: var(--space-3) var(--space-4);
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: border-color var(--transition-fast);
  position: relative;
}
.profile-notif-row:hover { border-color: var(--border-medium); }
.profile-notif-row > div { flex: 1; }
.profile-notif-label {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 2px;
}
.profile-notif-desc {
  font-size: var(--text-xs);
  color: var(--text-dim);
  line-height: 1.4;
}
.profile-toggle {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}
.profile-toggle-track {
  width: 40px;
  height: 22px;
  border-radius: var(--radius-full);
  background: var(--bg-surface);
  border: 1px solid var(--border-medium);
  flex-shrink: 0;
  position: relative;
  transition: background var(--transition-base), border-color var(--transition-base);
  cursor: pointer;
}
.profile-toggle-track::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  border-radius: var(--radius-full);
  background: var(--text-dim);
  transition: transform var(--transition-base), background var(--transition-base);
}
.profile-toggle:checked + .profile-toggle-track {
  background: var(--accent-primary);
  border-color: var(--accent-primary);
}
.profile-toggle:checked + .profile-toggle-track::after {
  transform: translateX(18px);
  background: #fff;
}

/* Danger zone */
.profile-danger-zone {
  border-color: rgba(244, 63, 94, 0.2);
  background: rgba(244, 63, 94, 0.03);
}

/* Book accessibility additions */
.book-align-btn, .book-para-btn, .book-focus-btn {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  color: var(--text-dim);
  cursor: pointer;
  padding: 4px 10px;
  border-radius: var(--radius-sm);
  font-family: var(--font-sans);
  transition: all var(--transition-fast);
  font-size: var(--text-xs);
  line-height: 1.4;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.book-align-btn:hover, .book-para-btn:hover, .book-focus-btn:hover {
  color: var(--text-primary);
  border-color: var(--border-medium);
  background: var(--bg-glass-md);
}
.book-align-btn.active, .book-para-btn.active {
  background: var(--accent-primary);
  border-color: var(--accent-primary);
  color: #fff;
}
.book-focus-btn.active {
  background: var(--accent-primary);
  border-color: var(--accent-primary);
  color: #fff;
  box-shadow: 0 0 12px rgba(124,58,237,0.45);
}

/* Focus mode — immersive reading: chrome slides away, cursor triggers reveal */
.book-layout { --focus-transition: 0.45s cubic-bezier(0.4, 0, 0.2, 1); }

.book-topbar   { transition: transform var(--focus-transition), opacity var(--focus-transition); }
.book-nav-bar  { transition: transform var(--focus-transition), opacity var(--focus-transition); }
.book-content-area { transition: padding var(--focus-transition); }

.focus-mode .book-topbar {
  transform: translateY(-110%);
  opacity: 0;
  pointer-events: none;
}
.focus-mode .book-nav-bar {
  transform: translateY(110%);
  opacity: 0;
  pointer-events: none;
}
.focus-mode .book-content-area {
  padding-top: 6rem;
  padding-bottom: 6rem;
  box-shadow: inset 0 0 80px rgba(0,0,0,0.25);
}

/* Chrome is revealed by JS mouse tracking near top/bottom edges */

/* ---- PAGE HEADER ---- */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-6);
  flex-wrap: wrap;
  gap: var(--space-4);
}

.page-title {
  font-family: var(--font-serif);
  font-size: var(--text-3xl);
  color: var(--text-primary);
}

/* ---- MOBILE MENU ---- */
.mobile-menu-btn {
  display: none;
  background: var(--bg-glass);
  border: 1px solid var(--border-glass);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  width: 38px;
  height: 38px;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

/* ============================================
   RESPONSIVE
   ============================================ */
@media (max-width: 768px) {
  .navbar-nav { display: none; }
  .mobile-menu-btn { display: flex; }

  .hero { padding: var(--space-7) var(--space-4) var(--space-6); }
  .hero-title { font-size: 2rem; }
  .hero-subtitle { font-size: var(--text-base); }

  .stories-grid { grid-template-columns: 1fr; }

  .generator-form-grid { grid-template-columns: 1fr; }

  .reader-page { padding: var(--space-5) var(--space-4); }
  .reader-cover { height: 200px; font-size: 4rem; }

  .profile-header { flex-direction: column; text-align: center; }
  .profile-bio { max-width: 100%; }
  .profile-username { font-size: var(--text-2xl); }
  .profile-stats-grid { grid-template-columns: repeat(2, 1fr); gap: var(--space-3); }
  .profile-mini-stats { grid-template-columns: 1fr; }

  .page-container { padding: var(--space-5) var(--space-4); }

  .auth-card { padding: var(--space-6) var(--space-5); }

  .toast-container {
    bottom: var(--space-4);
    right: var(--space-4);
    left: var(--space-4);
  }
  .toast { min-width: unset; max-width: 100%; }

  .notifications-dropdown {
    right: var(--space-4);
    left: var(--space-4);
    width: auto;
  }

  .modal { border-radius: var(--radius-lg); }
}

@media (max-width: 480px) {
  .navbar { padding: 0 var(--space-4); }
  .stories-grid { gap: var(--space-4); }
  .filter-bar { gap: var(--space-2); }
}

/* ---- EXTRAS & POLISH ---- */

/* Stat cards clickable via <a> */
a.stat-card {
  text-decoration: none;
  cursor: pointer;
  transition: all var(--transition-base);
}
a.stat-card:hover {
  border-color: var(--border-medium);
  background: var(--bg-elevated);
  transform: translateY(-3px);
  box-shadow: 0 8px 24px rgba(0,0,0,0.3);
}

/* Hero divider dots */
.hero-divider {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-3);
  margin: var(--space-6) 0 var(--space-5);
}
.hero-divider span {
  width: 4px;
  height: 4px;
  background: var(--border-medium);
  border-radius: 50%;
}
.hero-divider span:nth-child(2) {
  background: var(--accent-primary);
  width: 6px;
  height: 6px;
}

/* Filter bar separator */
.filter-sep {
  width: 1px;
  height: 20px;
  background: var(--border-subtle);
  flex-shrink: 0;
}

/* Scrollbar in reader */
.reader-page::-webkit-scrollbar { display: none; }

/* Better focus for form inputs */
.form-input:focus-visible,
.form-textarea:focus-visible {
  outline: none;
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 3px var(--accent-glow-sm);
}

/* Inline word count badge */
.word-count-badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  font-size: var(--text-xs);
  color: var(--text-dim);
  background: var(--bg-glass);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-full);
  padding: 2px 8px;
}
