:root {
    --bg: #050505;
    --foreground: #ffffff;
    --card: #0c0c0c;
    --border: #1a1a1a;
    --primary: #d4af37; 
    --gold: #d4af37;
    --gold-glow: rgba(212, 175, 55, 0.5);
    --muted: #666666;
    --font-main: 'Inter', system-ui, -apple-system, sans-serif;
    --font-serif: 'Georgia', serif;
    --header-h: 70px;
    --drawer-w: 420px;
}

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

html {
    overflow-x: hidden;        /* single scroll-container; sticky + fixed children work correctly */
    overscroll-behavior: none; /* suppress rubber-band in all directions */
    -webkit-text-size-adjust: 100%; /* prevent iOS font inflation */
}

body {
    overflow-x: hidden;
    overscroll-behavior-x: none;
    max-width: 100vw;
    width: 100%;
    font-family: var(--font-main);
    background-color: var(--bg);
    color: var(--foreground);
    line-height: 1.6;
}

/* --- Header --- */
header {
    background: rgba(0, 0, 0, 0.92);
    backdrop-filter: blur(18px);
    -webkit-backdrop-filter: blur(18px);
    height: var(--header-h);
    padding: 0 1.5rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 9000;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    overflow: hidden;
    transition: opacity 0.4s ease, transform 0.4s ease;
}

/* Floating overlay: fade + slide up when hidden */
header.header-hidden {
    opacity: 0;
    transform: translateY(-100%);
    pointer-events: none;
}

.header-left { min-width: 0; flex-shrink: 1; }
.brand-logo-img {
    height: 32px;
    width: auto;
    display: block;
    object-fit: contain;
    max-width: 160px;
}
#brand-logo-link { display: flex; align-items: center; text-decoration: none; }

header h1 {
    font-size: 1.3rem;
    font-weight: 800;
    letter-spacing: -0.5px;
    color: var(--foreground);
    cursor: pointer;
    text-transform: lowercase;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}


header h1::first-letter { color: var(--gold); font-size: 1.5rem; }

.version-tag {
    font-size: 0.6rem;
    font-family: monospace;
    background: #1a1a1a;
    color: var(--gold);
    padding: 2px 6px;
    border-radius: 4px;
    text-transform: uppercase;
    font-weight: normal;
    letter-spacing: 1px;
}

.header-center { flex: 2; min-width: 0; display: flex; justify-content: center; align-items: center; gap: 1.5rem; overflow: hidden; }

/* --- Reader Progress Indicator --- */
#progress-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    min-width: 200px;
}

.progress-info {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 1.5px;
}

.progress-chapter {
    color: var(--gold);
    font-weight: 700;
}

.progress-divider {
    color: #333;
}

.progress-chunk {
    color: var(--muted);
    font-weight: 400;
}

.progress-bar-track {
    width: 100%;
    height: 3px;
    background: #1a1a1a;
    border-radius: 3px;
    overflow: hidden;
    position: relative;
}

.progress-bar-fill {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, var(--gold), #f0d060);
    border-radius: 3px;
    transition: width 0.8s cubic-bezier(0.25, 1, 0.5, 1);
    box-shadow: 0 0 8px var(--gold-glow);
}

/* ─── Bottom Narrator Bar ─────────────────────────────────────────── */
#narrator-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    max-width: 100%;
    overflow: hidden;
    z-index: 4998;
    background: rgba(5, 5, 5, 0.97);
    border-top: 1px solid var(--border);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    padding: 0.5rem 1.5rem;
    box-sizing: border-box;
}

#narrator-bar-inner {
    display: flex;
    align-items: center;
    gap: 1rem;
    max-width: 900px;
    margin: 0 auto;
    width: 100%;
    overflow: hidden;
}

#narrator-track-info {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-width: 0;
    overflow: hidden;
}

.narrator-chapter {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    color: var(--gold);
    font-weight: 700;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.narrator-passage {
    font-size: 0.65rem;
    color: var(--muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

#audio-player {
    flex: 1 1 auto;
    min-width: 0;
    max-width: 420px;
    width: 100%;
    height: 32px;
    filter: invert(1) hue-rotate(180deg) brightness(1.2) contrast(1.2);
}

.header-right { flex: 1; min-width: 0; display: flex; justify-content: flex-end; align-items: center; gap: 0.5rem; }

.nav-hidden { display: none !important; }

/* Nav controls — always visible flex row */
#nav-controls {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
.narrator-bar-hidden { transform: translateY(100%); pointer-events: none; }

/* --- Hero Section --- */
.hero {
    padding: 8rem 2rem 5rem;
    text-align: center;
    max-width: 1000px;
    margin: 0 auto;
}

.hero h2 {
    font-size: 4.5rem;
    font-weight: 900;
    margin-bottom: 1.5rem;
    background: linear-gradient(135deg, #fff 30%, var(--gold) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    letter-spacing: -3px;
    line-height: 1;
}

.hero p {
    font-size: 1.3rem;
    color: var(--muted);
    max-width: 650px;
    margin: 0 auto 3rem;
    font-weight: 400;
}


/* --- Gallery View --- */
.gallery-container {
    padding: 4rem 2rem;
    max-width: 1400px;
    margin: 0 auto;
}
.gallery-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 3rem;
}
.gallery-grid-full {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 2rem;
}
.gallery-item {
    background: #0c0c0c;
    border: 1px solid var(--border);
    border-radius: 1rem;
    padding: 1rem;
    transition: 0.3s;
}
.gallery-item:hover {
    border-color: var(--gold);
    transform: translateY(-5px);
}
.gallery-item img {
    width: 100%;
    aspect-ratio: 16/9;
    object-fit: cover;
    border-radius: 0.5rem;
    margin-bottom: 1rem;
}
.gallery-item-title {
    font-size: 1rem;
    color: #fff;
    margin-bottom: 0.5rem;
}

.view-title { 
    font-size: 0.7rem; 
    text-transform: uppercase; 
    letter-spacing: 4px; 
    color: var(--gold);
    text-align: center;
    margin-bottom: 3rem;
    opacity: 0.6;
}

.book-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
    gap: 2rem;
    max-width: 1400px;
    margin: 0 auto 10rem;
    padding: 0 2rem;
}

.book-card {
    background: var(--card);
    border: 1px solid var(--border);
    padding: 2.5rem;
    border-radius: 1.5rem;
    transition: all 0.5s cubic-bezier(0.2, 1, 0.3, 1);
    display: flex;
    flex-direction: column;
    position: relative;
}

.book-card:hover {
    transform: translateY(-12px);
    border-color: var(--gold);
    box-shadow: 0 30px 60px rgba(0,0,0,0.6), 0 0 20px rgba(212, 175, 55, 0.1);
}

.book-card h3 {
    font-size: 1.6rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
    color: var(--foreground);
}

.book-card .author {
    color: var(--gold);
    font-size: 0.85rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 1.5rem;
}

.book-card .synopsis {
    font-size: 0.95rem;
    color: #888;
    margin-bottom: 2.5rem;
    line-height: 1.7;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.book-card button {
    margin-top: auto;
    background: var(--foreground);
    color: #000;
    border: none;
    padding: 1.2rem;
    border-radius: 0.8rem;
    font-weight: 800;
    font-size: 0.9rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    cursor: pointer;
    transition: 0.3s;
}

.book-card button:hover { background: var(--gold); transform: scale(1.02); }

/* ── Book card indicators ─────────────────────────────────────────── */

/* Corner badge cluster — top-right, inside the card, below the card border */
.book-card-badges {
    position: absolute;
    top: 1.2rem;
    right: 1.2rem;
    display: flex;
    align-items: center;
    gap: 0.55rem;
}

/* Narration complete dot — vivid green */
.narration-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #22c55e;
    box-shadow: 0 0 6px rgba(34, 197, 94, 0.7);
    flex-shrink: 0;
}

/* Vision count chip — washed-out, secondary */
.vision-count-chip {
    display: flex;
    align-items: center;
    gap: 0.3rem;
    font-size: 0.72rem;
    font-weight: 600;
    color: rgba(255,255,255,0.28);
    letter-spacing: 0.5px;
    line-height: 1;
}
.vision-count-chip i {
    font-size: 0.68rem;
    opacity: 0.7;
}

/* ── Featured Works header row + legend ──────────────────────────── */
.view-title-row {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 3rem;
}
.view-title-row .view-title {
    margin-bottom: 0;
}
.narration-legend {
    display: flex;
    align-items: center;
    gap: 0.45rem;
}
.narration-legend .legend-dot {
    width: 8px;
    height: 8px;
}
.legend-label {
    font-size: 0.65rem;
    text-transform: uppercase;
    letter-spacing: 2.5px;
    color: rgba(255,255,255,0.3);
}

/* --- Reader --- */
#view-reader { padding: 0; background: #000; overflow-x: hidden; width: 100%; max-width: 100%; height: 100%; }
#text-container { max-width: 800px; margin: 0 auto; padding: 2rem 1.25rem 12rem; overflow-x: hidden; box-sizing: border-box; width: 100%; }
#text-content { display: flex; flex-direction: column; gap: 4rem; }

.passage {
    border: none;
    background: transparent;
    opacity: 0.45;
    transition: opacity 0.6s ease;
}

.passage.active { opacity: 1; }

.passage.playing { border-left: 3px solid var(--gold); padding-left: 1rem; }
.passage.playing .passage-play-btn { color: var(--gold); }

.passage-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
    border-bottom: 1px solid #111;
    padding-bottom: 0.8rem;
}

.passage-label {
    font-family: monospace;
    font-size: 0.75rem;
    color: var(--gold);
    text-transform: uppercase;
    letter-spacing: 2px;
}

.passage-chapter {
    color: var(--gold);
    font-weight: 600;
    letter-spacing: 1.5px;
}

.passage-sep {
    color: #444;
    letter-spacing: 0;
    font-weight: 400;
}

.passage-hash {
    color: #555;
    font-weight: 400;
    letter-spacing: 1px;
}

.passage-play-btn {
    background: transparent;
    border: none;
    color: #444;
    font-size: 1.4rem;
    cursor: pointer;
    transition: 0.3s;
}

.passage-play-btn:hover { color: var(--gold); transform: scale(1.2); }

.passage-body p {
    overflow-wrap: break-word;
    word-break: break-word;
    font-family: var(--font-serif);
    font-size: 1.15rem;
    line-height: 1.9;
    color: #ccc;
}

/* --- Gallery Vault & Favor Icons --- */
.gallery-vault {
    background: #000;
    border: 1px solid var(--border);
    border-radius: 1rem;
    padding: 1.5rem;
    margin-top: 1rem;
    position: relative;
}

.gallery-nav-rune {
    background: #111;
    border: 1px solid var(--gold);
    color: var(--gold);
    padding: 1rem;
    text-align: center;
    border-radius: 0.5rem;
    cursor: pointer;
    margin-bottom: 1rem;
    text-transform: uppercase;
    letter-spacing: 2px;
    font-size: 0.8rem;
    transition: 0.3s;
}

.gallery-nav-rune:hover {
    background: var(--gold);
    color: #000;
}

.gallery-reveal-badge {
    display: inline-block;
    background: var(--gold);
    color: #000;
    font-size: 0.7rem;
    font-weight: 700;
    border-radius: 999px;
    padding: 0.1em 0.55em;
    margin-left: 0.5rem;
    vertical-align: middle;
    line-height: 1.4;
    letter-spacing: 0;
}

.gallery-nav-rune:hover .gallery-reveal-badge {
    background: #000;
    color: var(--gold);
}

.gallery-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1rem;
}

.gallery-item {
    background: #1a1a1a;
    border-radius: 0.5rem;
    padding: 0.5rem;
    cursor: pointer;
    border: 1px solid var(--border);
}

.gallery-item img {
    width: 100%;
    height: auto;
    border-radius: 0.2rem;
}

.favor-icon {
    font-size: 1.2rem;
    color: var(--muted);
    cursor: pointer;
    transition: 0.2s;
    margin-left: 0.5rem;
}

.favor-icon:hover, .favor-icon.active {
    color: var(--gold);
    transform: scale(1.2);
}

/* --- Drawer --- */
.drawer {
    position: fixed;
    top: var(--header-h);
    right: 0; 
    width: var(--drawer-w);
    height: calc(100vh - var(--header-h));
    background: #080808;
    border-left: 1px solid var(--border);
    transform: translateX(100%); 
    transition: transform 0.6s cubic-bezier(0.19, 1, 0.22, 1);
    z-index: 6000;
    display: flex;
    flex-direction: column;
    box-shadow: -20px 0 50px rgba(0,0,0,0.8);
    visibility: hidden;
}

.drawer.open { 
    transform: translateX(0); 
    visibility: visible;
}

.drawer-header {
    padding: 1.5rem 2rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #000;
}

.drawer-header h3 { color: var(--gold); font-size: 0.9rem; text-transform: uppercase; letter-spacing: 2px; }

.drawer-close-icon {
    background: none; border: none; color: #666; font-size: 2rem; cursor: pointer;
}
.drawer-close-icon:hover { color: var(--gold); }

.drawer-content { padding: 0; overflow-y: auto; flex-grow: 1; }

.panel-divider { border: none; border-bottom: 1px solid var(--border); margin: 0; }

/* Living Lore Sections (Drawers) */
.lore-section { border-bottom: 1px solid var(--border); }

.section-trigger {
    width: 100%;
    padding: 1.2rem 2rem;
    background: transparent;
    border: none;
    color: #fff;
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    transition: 0.2s;
}

.section-trigger:hover { background: #111; }
.section-trigger h4 { 
    font-size: 0.75rem; 
    text-transform: uppercase; 
    letter-spacing: 2px; 
    color: var(--gold); 
    margin: 0;
    display: flex;
    align-items: center;
    gap: 0.6rem;
}
.section-trigger h4 i { font-size: 0.8rem; opacity: 0.7; }
.section-trigger > i { transition: transform 0.3s; color: #444; }

.lore-section.open .section-trigger > i { transform: rotate(180deg); color: var(--gold); }

.section-content {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.5s ease-out, padding 0.3s;
    background: #050505;
    padding: 0 2rem;
}

.lore-section.open .section-content {
    max-height: 2000px;
    padding: 1.5rem 2rem;
}

.context-box { color: #888; font-size: 0.95rem; line-height: 1.8; }
.chip-container { display: flex; flex-wrap: wrap; gap: 0.6rem; }

.persona-chip {
    background: #111;
    border: 1px solid var(--border);
    color: #ccc;
    padding: 0.4rem 1rem;
    border-radius: 2rem;
    font-size: 0.85rem;
    cursor: pointer;
    transition: 0.2s;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.persona-chip:hover { border-color: var(--gold); color: #fff; background: #1a1a1a; }
.persona-chip.active { background: var(--gold); color: #000; font-weight: 700; border-color: var(--gold); }

.persona-chip .chip-state {
    font-size: 0.65rem;
    color: var(--muted);
    max-width: 120px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.persona-chip.active .chip-state { color: rgba(0,0,0,0.6); }
/* Ghost chips — mentioned but not physically present in scene */
.persona-chip--ghost {
    opacity: 0.5;
    border-style: dashed;
    color: #888;
    font-style: italic;
}
.persona-chip--ghost:hover {
    opacity: 0.8;
    border-color: var(--gold);
    border-style: dashed;
    color: #ccc;
}
.persona-chip--ghost.active {
    opacity: 1;
    background: #2a2a1a;
    color: var(--gold);
    border-color: var(--gold);
    border-style: dashed;
}

/* Divider between present and mentioned chips */
.chip-divider {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin: 0.4rem 0 0.2rem;
    color: #444;
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
}
.chip-divider::before, .chip-divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: #2a2a2a;
}



/* --- Lore List (Glossary) --- */
.lore-list {
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
}

.lore-entry {
    background: #0a0a0a;
    border: 1px solid var(--border);
    border-radius: 0.6rem;
    padding: 0.8rem 1rem;
    transition: 0.2s;
}

.lore-entry:hover {
    border-color: #333;
}

.lore-term {
    color: var(--gold);
    font-size: 0.8rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 0.3rem;
}

.lore-definition {
    color: #888;
    font-size: 0.85rem;
    line-height: 1.6;
}

/* --- Interaction Styling --- */
.char-link {
    color: var(--gold);
    text-decoration: none;
    border-bottom: 1px dashed var(--gold);
    cursor: pointer;
    font-weight: 600;
    transition: 0.2s;
    position: relative;
}

.char-link:hover { color: #fff; border-bottom-style: solid; background: rgba(212, 175, 55, 0.1); }

/* Popup Reminders (Tooltips) */
.char-link::after {
    content: attr(data-name);
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%) translateY(-10px);
    background: var(--gold);
    color: #000;
    padding: 4px 10px;
    border-radius: 4px;
    font-size: 0.7rem;
    font-weight: 800;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: 0.2s;
    z-index: 100;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.char-link:hover::after { opacity: 1; transform: translateX(-50%) translateY(-5px); }

/* Interrogation (Chat) */
.interrogation { border-bottom: none; }
.interrogation-header { margin-bottom: 1.5rem; }
.interrogation-header h4 { font-size: 1.1rem; color: #fff; margin-bottom: 0.4rem; text-transform: none; letter-spacing: 0; }
.persona-state-tag { font-size: 0.7rem; color: var(--muted); text-transform: uppercase; letter-spacing: 1px; }
.persona-state-tag span { color: var(--gold); font-weight: 700; }

.chat-log { height: 300px; overflow-y: auto; margin-bottom: 1.5rem; display: flex; flex-direction: column; gap: 1rem; padding-right: 0.5rem; }
.msg { padding: 0.8rem 1.2rem; border-radius: 1rem; font-size: 0.95rem; max-width: 85%; line-height: 1.5; }
.msg.user { align-self: flex-end; background: #111; color: #fff; border-bottom-right-radius: 0.2rem; border: 1px solid #222; }
.msg.bot { align-self: flex-start; background: #000; color: #ccc; border: 1px solid var(--border); border-bottom-left-radius: 0.2rem; }
.chat-replay-btn { background: transparent; border: none; color: var(--gold); cursor: pointer; font-size: 0.85rem; padding: 0 0.3rem; opacity: 0.7; vertical-align: middle; transition: opacity 0.2s; }
.chat-replay-btn:hover { opacity: 1; }
#track-progress-btn { position: relative; }
#track-progress-btn:not(.active) { color: #444; }
#track-progress-btn:not(.active)::after { content: ''; position: absolute; top: 50%; left: 50%; width: 60%; height: 2px; background: #666; transform: translate(-50%, -50%) rotate(-45deg); pointer-events: none; }
.chat-replay-btn:hover { opacity: 1; }
.msg.sys { align-self: center; font-size: 0.75rem; color: var(--muted); font-style: italic; background: transparent; padding: 0; }

.chat-input-wrap { display: flex; gap: 0.5rem; background: #000; border: 1px solid var(--border); padding: 0.4rem; border-radius: 0.8rem; }
#chat-input { flex-grow: 1; background: transparent; border: none; color: #fff; padding: 0.6rem 0.8rem; font-family: var(--font-main); font-size: 0.9rem; }
#chat-input:focus { outline: none; }
#chat-send { background: var(--gold); border: none; width: 40px; height: 40px; border-radius: 0.6rem; cursor: pointer; transition: 0.2s; }
#chat-send:hover { transform: scale(1.05); filter: brightness(1.1); }

.icon-btn {
    background: transparent; border: none; color: #666;
    font-size: 1.3rem; cursor: pointer; padding: 0.5rem;
    transition: 0.3s;
    position: relative;
}

.icon-btn:hover { color: var(--foreground); }
.icon-btn.active { color: var(--gold); filter: drop-shadow(0 0 8px var(--gold-glow)); }

.badge {
    position: absolute; top: 0; right: 0; background: #a33b3b;
    color: #fff; font-size: 0.6rem; min-width: 16px; height: 16px;
    display: flex; align-items: center; justify-content: center;
    border-radius: 50%;
}

.view { display: none; }
.view.active { display: block; }

/* Auth View */
.auth-container {
    max-width: 450px; margin: 15vh auto;
    padding: 4rem; background: var(--card);
    border: 1px solid var(--border); border-radius: 2rem;
    box-shadow: 0 40px 100px rgba(0,0,0,0.8);
}

.primary-btn {
    width: 100%; background: var(--foreground); color: #000; border: none;
    padding: 1.2rem; border-radius: 0.8rem; font-weight: 800;
    cursor: pointer; text-transform: uppercase; letter-spacing: 1px;
}

/* Scene context styling */
.scene-field {
    margin-bottom: 0.6rem;
}

.scene-field-label {
    color: var(--gold);
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
    display: block;
    margin-bottom: 0.2rem;
}

.scene-field-value {
    color: #aaa;
    font-size: 0.9rem;
    line-height: 1.6;
}



/* ========== Drawer Footer ========== */
.drawer-footer {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 0.5rem;
    padding: 1rem 1rem 1.25rem;
    border-top: 1px solid var(--border);
    margin-top: auto;
}

.drawer-footer-btn {
    background: none;
    border: none;
    color: var(--muted);
    cursor: pointer;
    padding: 0.5rem;
    border-radius: 6px;
    font-size: 1.1rem;
    transition: color 0.2s, background 0.2s;
    line-height: 1;
}
.drawer-footer-btn:hover { color: var(--gold); background: rgba(255,255,255,0.05); }
.drawer-footer-btn.active { color: var(--gold); }

@media (max-width: 900px) {
    .hero h2 { font-size: 3rem; }
    .book-grid { grid-template-columns: 1fr; }
    :root { --drawer-w: 100vw; }
    .drawer { width: 100vw; }
    #audio-player { width: 150px; }
    #progress-container { min-width: 120px; }
    .progress-info { font-size: 0.6rem; }
}

/* ─── Mobile Waffle Menu ─────────────────────────────────────────── */
@media (max-width: 768px) {
    /* Show the waffle toggle button on mobile */
    /* When toggled open */
    /* Each icon button gets a full-width tap target in the dropdown */
    /* Brand shortening on mobile */

    /* Narrator bar: full width, comfortable height on mobile */
    #narrator-bar { padding: 0.5rem 0.75rem; overflow: hidden; }
    #narrator-bar-inner { gap: 0.5rem; overflow: hidden; }
    #audio-player { max-width: calc(100vw - 2rem); width: 100%; flex: 1 1 0; min-width: 0; }
    #narrator-track-info { display: none; }   /* hide track info on mobile, save space */

    /* Hide progress text on very small screens */
    #progress-container { display: none !important; }
}

/* Waffle toggle is hidden on desktop */
@media (min-width: 769px) {
    }

/* --- Profile View --- */
.profile-container {
    max-width: 800px;
    margin: 10vh auto;
    padding: 4rem;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 2rem;
}

.profile-container h2 {
    font-size: 2.5rem;
    margin-bottom: 2.5rem;
    color: var(--gold);
}

.profile-layout {
    display: flex;
    gap: 4rem;
    align-items: flex-start;
}

.profile-pic-section {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.5rem;
}

#profile-pic-preview {
    width: 200px;
    height: 200px;
    border-radius: 50%;
    object-fit: cover;
    border: 4px solid var(--border);
    background: #111;
}

.profile-info-section {
    flex: 2;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.form-group label {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 2px;
    color: var(--muted);
}

.profile-info-section input, .profile-info-section textarea {
    background: #111;
    border: 1px solid var(--border);
    border-radius: 0.8rem;
    padding: 1rem;
    color: #fff;
    font-family: var(--font-main);
    font-size: 1rem;
}

.profile-info-section textarea {
    min-height: 120px;
    resize: vertical;
}

.secondary-btn {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--foreground);
    padding: 0.8rem 2rem;
    border-radius: 0.8rem;
    cursor: pointer;
    transition: 0.3s;
    font-weight: 600;
}
.secondary-btn:hover {
    border-color: var(--gold);
    color: var(--gold);
}

.auth-alt {
    text-align: center;
    margin-top: 1rem;
    font-size: 0.85rem;
    color: var(--muted);
}
.auth-alt a {
    color: var(--gold);
    text-decoration: none;
    font-weight: 600;
}
.auth-alt a:hover { text-decoration: underline; }

.error-msg {
    color: #e74c3c;
    font-size: 0.85rem;
    margin-top: 1rem;
    text-align: center;
}

.status-msg {
    font-size: 0.85rem;
    color: var(--gold);
    margin-top: 0.5rem;
    text-align: center;
}

.verify-hint {
    color: var(--muted);
    font-size: 0.9rem;
    margin-bottom: 1.5rem;
    text-align: center;
}

.auth-container input {
    width: 100%;
    background: #111;
    border: 1px solid var(--border);
    border-radius: 0.8rem;
    padding: 1rem;
    color: #fff;
    font-family: var(--font-main);
    font-size: 1rem;
    margin-bottom: 1rem;
}

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

.loader {
    text-align: center;
    color: var(--muted);
    font-size: 0.9rem;
    padding: 4rem;
    grid-column: 1 / -1;
}

/* Inline count badge for drawer section headers */
.count-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--gold);
    color: #000;
    font-size: 0.65rem;
    font-weight: 700;
    min-width: 1.4em;
    height: 1.4em;
    padding: 0 0.4em;
    border-radius: 1em;
    margin-left: 0.5em;
    vertical-align: middle;
}

/* ============================================
   VOICE AUDITION PANEL (Temporary)
   ============================================ */
.voice-audition {
    max-width: 1000px;
    margin: 0 auto;
    padding: 0 2rem 4rem;
}

.voice-audition-inner {
    background: linear-gradient(145deg, #0a0a0a 0%, #0f0f0f 100%);
    border: 1px solid var(--border);
    border-radius: 1.5rem;
    padding: 3rem;
    position: relative;
    overflow: hidden;
}

.voice-audition-inner::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 2px;
    background: linear-gradient(90deg, transparent, var(--gold), transparent);
}

.voice-audition-inner h3 {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--foreground);
    margin-bottom: 0.5rem;
    display: flex;
    align-items: center;
    gap: 0.7rem;
}

.voice-audition-inner h3 i {
    color: var(--gold);
    font-size: 1.2rem;
}

.voice-audition-desc {
    color: var(--muted);
    font-size: 0.9rem;
    margin-bottom: 2rem;
    line-height: 1.6;
}

.voice-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1.2rem;
}

@media (max-width: 768px) {
    .voice-grid {
        grid-template-columns: 1fr;
    }
}

.voice-card {
    background: #000;
    border: 1px solid #1a1a1a;
    border-radius: 1rem;
    padding: 1.5rem;
    transition: all 0.3s ease;
    position: relative;
}

.voice-card:hover {
    border-color: #333;
    background: #060606;
}

.voice-card.playing {
    border-color: var(--gold);
    box-shadow: 0 0 30px rgba(212, 175, 55, 0.08);
}

.voice-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.8rem;
}

.voice-name {
    font-size: 1.2rem;
    font-weight: 800;
    color: #fff;
}

.voice-engine {
    font-size: 0.65rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    padding: 0.25rem 0.7rem;
    border-radius: 2rem;
}

.voice-engine.generative {
    background: rgba(212, 175, 55, 0.15);
    color: var(--gold);
    border: 1px solid rgba(212, 175, 55, 0.3);
}

.voice-engine.neural {
    background: rgba(100, 200, 255, 0.1);
    color: #64c8ff;
    border: 1px solid rgba(100, 200, 255, 0.2);
}

.voice-desc {
    color: #888;
    font-size: 0.82rem;
    line-height: 1.6;
    margin-bottom: 1rem;
}

.voice-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.2rem;
    font-size: 0.72rem;
    color: var(--muted);
}

.voice-meta i {
    margin-right: 0.3rem;
    opacity: 0.7;
}

.voice-cost {
    color: var(--gold);
    font-weight: 600;
}

.voice-player {
    display: flex;
    align-items: center;
    gap: 0.8rem;
    background: #0a0a0a;
    border: 1px solid #1a1a1a;
    border-radius: 0.6rem;
    padding: 0.6rem 0.8rem;
}

.voice-play-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: 2px solid var(--gold);
    background: transparent;
    color: var(--gold);
    font-size: 0.85rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    flex-shrink: 0;
}

.voice-play-btn:hover {
    background: var(--gold);
    color: #000;
    transform: scale(1.05);
}

.voice-card.playing .voice-play-btn {
    background: var(--gold);
    color: #000;
}

.voice-waveform {
    flex: 1;
    height: 4px;
    background: #1a1a1a;
    border-radius: 4px;
    overflow: hidden;
    position: relative;
}

.wave-progress {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, var(--gold), #f0d060);
    border-radius: 4px;
    transition: width 0.1s linear;
    box-shadow: 0 0 6px var(--gold-glow);
}

.voice-time {
    font-family: monospace;
    font-size: 0.7rem;
    color: var(--muted);
    min-width: 2.5rem;
    text-align: right;
}

/* ── Table of Contents Overlay ───────────────────────────────────────────── */
.toc-overlay {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 500;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(4px);
    align-items: flex-start;
    justify-content: center;
    padding-top: 5rem;
}

.toc-overlay.open {
    display: flex;
}

.toc-panel {
    background: #0a0a0a;
    border: 1px solid var(--border);
    border-radius: 1.2rem;
    width: min(480px, 90vw);
    max-height: 70vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: 0 20px 60px rgba(0,0,0,0.8);
}

.toc-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1.2rem 1.5rem;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.toc-header h3 {
    font-size: 0.9rem;
    font-weight: 700;
    color: var(--foreground);
    text-transform: uppercase;
    letter-spacing: 1.5px;
    margin: 0;
}

.toc-list {
    overflow-y: auto;
    padding: 0.5rem 0;
    flex: 1;
}

/* Each row = dot + vertical spine line + label */
.toc-row {
    display: grid;
    grid-template-columns: 2.5rem 2px 1fr;
    grid-template-rows: auto 1fr;
    min-height: 3rem;
    cursor: default;
    padding-right: 1.2rem;
    transition: background 0.15s;
}

.toc-row.past,
.toc-row.current {
    cursor: pointer;
}

.toc-row.past:hover   { background: rgba(255,255,255,0.025); }
.toc-row.current:hover { background: rgba(212,175,55,0.06); }

/* The dot — centred in the left column, aligned to top of row */
.toc-dot {
    grid-column: 1;
    grid-row: 1;
    justify-self: center;
    align-self: start;
    margin-top: 0.85rem;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    border: 2px solid #333;
    background: #111;
    transition: all 0.2s;
    position: relative;
    z-index: 1;
}

.toc-dot.dot-past {
    border-color: #555;
    background: #333;
}

.toc-dot.dot-current {
    border-color: var(--gold);
    background: var(--gold);
    box-shadow: 0 0 8px rgba(212,175,55,0.5);
    animation: pulse-dot 2s ease-in-out infinite;
}

@keyframes pulse-dot {
    0%, 100% { box-shadow: 0 0 8px rgba(212,175,55,0.5); }
    50%       { box-shadow: 0 0 16px rgba(212,175,55,0.9); }
}

/* The vertical spine line — connects dots */
.toc-spine-line {
    grid-column: 2;
    grid-row: 1 / 3;
    width: 2px;
    background: #1e1e1e;
    margin-top: 0;
    justify-self: center;
}

.toc-spine-line.last {
    background: transparent;
}

/* Spine colour reflects read state */
.toc-row.past   .toc-spine-line { background: #333; }
.toc-row.current .toc-spine-line { background: linear-gradient(to bottom, var(--gold), #333); }

/* Label area */
.toc-label {
    grid-column: 3;
    grid-row: 1;
    padding: 0.7rem 0 0.7rem 0.8rem;
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
}

.toc-ch-num {
    font-size: 0.7rem;
    font-family: monospace;
    color: var(--muted);
    opacity: 0.6;
    letter-spacing: 0.5px;
}

.toc-ch-title {
    font-size: 0.82rem;
    color: var(--muted);
    line-height: 1.4;
    transition: color 0.15s;
}

.toc-row.past   .toc-ch-title { color: #666; }
.toc-row.past:hover .toc-ch-title { color: var(--foreground); }

.toc-row.current .toc-ch-num  { color: var(--gold); opacity: 1; }
.toc-row.current .toc-ch-title { color: var(--gold); font-weight: 600; }

/* Future chapters — intentionally dim, title hidden */
.toc-row.future .toc-ch-num  { color: #333; }
.toc-row.future .toc-ch-title { display: none; }
.toc-row.future .toc-dot      { border-color: #222; background: #111; }

/* ══════════════════════════════════════════════════════════════════
   BYOK Keys Section (Profile Page)
══════════════════════════════════════════════════════════════════ */
.byok-section {
    margin-top: 0;
}
.byok-section h3 {
    font-size: 1rem;
    color: var(--gold);
    margin-bottom: 0.5rem;
}
.byok-hint {
    font-size: 0.82rem;
    color: var(--muted);
    margin-bottom: 1rem;
    line-height: 1.5;
}
.byok-hint a {
    color: var(--gold);
    text-decoration: none;
}
.byok-hint a:hover {
    text-decoration: underline;
}
.key-input-row {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}
.key-input-row input {
    flex: 1;
    min-width: 0;
}
.key-current-display {
    font-size: 0.78rem;
    color: var(--muted);
    margin-top: 0.3rem;
    font-family: monospace;
    letter-spacing: 0.05em;
}
.quota-info {
    font-size: 0.82rem;
    color: var(--muted);
    margin-bottom: 0.75rem;
    padding: 0.4rem 0.6rem;
    background: rgba(255,255,255,0.03);
    border-left: 2px solid var(--gold);
    border-radius: 2px;
}
.label-hint {
    font-size: 0.75rem;
    color: var(--muted);
    font-weight: 400;
}

/* ══════════════════════════════════════════════════════════════════
   Vision Generate Modal
══════════════════════════════════════════════════════════════════ */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.96);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 1rem;
    box-sizing: border-box;
}
.modal-panel {
    background: #0d0d0d;
    border: 1px solid #333;
    border-radius: 12px;
    width: 100%;
    max-width: 480px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 20px 60px rgba(0,0,0,0.6);
}
.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1.25rem 1.5rem 1rem;
    border-bottom: 1px solid #222;
}
.modal-header h3 {
    font-size: 1rem;
    color: var(--gold);
    margin: 0;
}
.modal-body {
    padding: 1.25rem 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}
.vision-result {
    padding: 1.25rem 1.5rem;
    border-top: 1px solid #222;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
}
.vision-result img {
    width: 100%;
    max-width: 320px;
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.5);
}

/* ══════════════════════════════════════════════════════════════════
   Gallery Enhancements
══════════════════════════════════════════════════════════════════ */
.gallery-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 0.75rem;
    padding: 1rem 1.5rem;
}
.gallery-header h2 {
    margin: 0;
}
.gallery-header-actions {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    flex-wrap: wrap;
}
.gallery-item-meta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.25rem 0.5rem 0.5rem;
    font-size: 0.75rem;
}
.gallery-item-book {
    color: var(--muted);
    font-style: italic;
}
.gallery-vote-wrap {
    display: flex;
    align-items: center;
    gap: 0.3rem;
}
.vote-count {
    font-size: 0.75rem;
    color: var(--muted);
    min-width: 1.2em;
    text-align: left;
}
.favor-icon.active {
    color: #e05;
}
.gallery-empty {
    text-align: center;
    color: var(--muted);
    padding: 2rem;
    font-style: italic;
}


/* ══════════════════════════════════════════════════════════════════
   SPLIT LAYOUT — Two-panel reader experience (v68)
══════════════════════════════════════════════════════════════════ */

/* ------------------------------------------------------------------
   Variables for panel sizing
------------------------------------------------------------------ */
:root {
    --left-w: 22%;          /* default left panel width */
    --divider-w: 4px;       /* divider bar width */
    --narrator-h: 60px;     /* narrator bar height */
}

/* ------------------------------------------------------------------
   Fullscreen views container — library, auth, profile, gallery
   Sits under the header, above narrator bar
------------------------------------------------------------------ */
#fullscreen-views {
    display: block;
    padding-top: var(--header-h);
    min-height: calc(100vh - var(--header-h) - var(--narrator-h));
}

#fullscreen-views .view { display: none; }
#fullscreen-views .view.active { display: block; }

/* ------------------------------------------------------------------
   Split layout container
   Hidden by default — JS shows it when entering the reader
------------------------------------------------------------------ */
#split-layout {
    position: fixed;
    top: var(--header-h);
    left: 0;
    right: 0;
    bottom: var(--narrator-h);
    display: flex;
    flex-direction: row;
    overflow: hidden;
    z-index: 100;
}

/* ------------------------------------------------------------------
   LEFT PANEL — Living Lore
------------------------------------------------------------------ */
#panel-left {
    width: var(--left-w);
    min-width: 0;
    flex-shrink: 0;
    background: #080808;
    border-right: 3px solid #ffffff22;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: width 0.35s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    z-index: 10;
}

#panel-left.collapsed {
    width: 0 !important;
    border-right-width: 0;
    overflow: hidden;
}

#panel-left-inner {
    width: 100%;
    height: 100%;
    overflow-y: auto;
    overflow-x: hidden;
    display: flex;
    flex-direction: column;
    min-width: 240px; /* inner content never wraps below this */
}

/* Panel left header bar */
.panel-left-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border);
    background: #000;
    flex-shrink: 0;
    position: sticky;
    top: 0;
    z-index: 5;
}

.panel-left-title {
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 2px;
    color: var(--gold);
    display: flex;
    align-items: center;
    gap: 0.5rem;
    white-space: nowrap;
}

.panel-left-header-actions {
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

/* ------------------------------------------------------------------
   DIVIDER
------------------------------------------------------------------ */
#panel-divider {
    width: 0;             /* visually zero — the border on panel-left IS the divider */
    flex-shrink: 0;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Toggle button — floats on the divider edge */
#panel-toggle-btn {
    position: absolute;
    left: 0;
    transform: translateX(-50%);
    width: 24px;
    height: 48px;
    background: #1a1a1a;
    border: 1px solid #ffffff33;
    border-radius: 4px;
    color: #888;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.7rem;
    transition: background 0.2s, color 0.2s, left 0.35s cubic-bezier(0.4,0,0.2,1);
    z-index: 20;
}

#panel-toggle-btn:hover {
    background: #2a2a2a;
    color: var(--gold);
    border-color: var(--gold);
}

/* When left panel is collapsed, toggle button shifts to left edge of screen */
#split-layout.left-collapsed #panel-toggle-btn {
    left: 12px;
    transform: none;
}

/* Icon flips direction on collapse */
#split-layout.left-collapsed #panel-toggle-icon {
    transform: rotate(180deg);
}

/* ------------------------------------------------------------------
   RIGHT PANEL — Reader
------------------------------------------------------------------ */
#panel-right {
    flex: 1;
    min-width: 0;
    overflow-y: auto;
    overflow-x: hidden;
    background: #000;
    position: relative;
}

/* Override old view-reader padding — panel-right handles scroll */
#split-layout #panel-right #view-reader {
    display: block;
    height: auto;
    padding: 0;
}

/* ------------------------------------------------------------------
   Lore sections inside panel-left — reuse existing .lore-section styles
   but with slightly tighter padding
------------------------------------------------------------------ */
#panel-left-inner .section-trigger {
    padding: 0.9rem 1rem;
}

#panel-left-inner .lore-section.open .section-content {
    padding: 1rem;
}

#panel-left-inner .section-content {
    padding: 0 1rem;
}

/* ------------------------------------------------------------------
   DESKTOP — Draggable divider
   The drag handle sits on top of panel-left's right border
------------------------------------------------------------------ */
#panel-divider-drag-handle {
    position: absolute;
    top: 0;
    bottom: 0;
    right: -6px;
    width: 12px;
    cursor: col-resize;
    z-index: 30;
}

/* While dragging */
body.is-dragging {
    cursor: col-resize !important;
    user-select: none;
}

body.is-dragging * {
    pointer-events: none;
}
body.is-dragging #panel-divider-drag-handle {
    pointer-events: all;
}

/* ------------------------------------------------------------------
   MOBILE — left panel slides over the right panel
   Default: left panel fully hidden off-screen left
------------------------------------------------------------------ */
@media (max-width: 768px) {
    :root {
        --left-w: 85vw;
    }

    #split-layout {
        overflow: visible; /* allow left panel to slide over */
    }

    #panel-left {
        position: absolute;
        top: 0;
        left: 0;
        bottom: 0;
        width: var(--left-w) !important;
        transform: translateX(-100%);
        transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
        border-right: 3px solid #ffffffaa;
        box-shadow: 4px 0 24px rgba(0,0,0,0.7);
        z-index: 50;
    }

    /* Open state on mobile — slide in */
    #panel-left.mobile-open {
        transform: translateX(0);
    }

    /* Collapsed class has no effect on mobile (transform takes over) */
    #panel-left.collapsed {
        width: var(--left-w) !important;
        border-right-width: 3px;
        overflow: hidden;
    }

    /* Right panel always full width on mobile */
    #panel-right {
        width: 100%;
        flex: 1;
    }

    /* Toggle button: sits at top-left of right panel on mobile */
    #panel-divider {
        display: none; /* hidden on mobile — toggle is in header area */
    }

    /* Mobile: show a dedicated lore toggle button in the header nav */
    #lore-panel-btn { display: flex !important; }

    /* Backdrop overlay when lore panel is open on mobile */
    #panel-left-backdrop {
        display: none;
        position: absolute;
        inset: 0;
        background: rgba(0,0,0,0.5);
        z-index: 40;
    }
    #panel-left-backdrop.visible { display: block; }
}

@media (min-width: 769px) {
    #lore-panel-btn { display: none !important; }
    #panel-left-backdrop { display: none !important; }
}

/* ------------------------------------------------------------------
   Narrator bar height sync
   The bar height is fixed at --narrator-h; everything above it
   is already accounted for in the split-layout bottom offset.
------------------------------------------------------------------ */
#narrator-bar {
    height: var(--narrator-h);
}

#narrator-bar-inner {
    height: 100%;
}

/* ------------------------------------------------------------------
   Char count badge in panel header
------------------------------------------------------------------ */
#char-count-badge {
    font-size: 0.65rem;
    background: var(--gold);
    color: #000;
    border-radius: 1em;
    padding: 0 0.4em;
    min-width: 1.4em;
    height: 1.4em;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
}


/* ══════════════════════════════════════════════════════════════════
   VISION WIZARD MODAL (v69)
══════════════════════════════════════════════════════════════════ */

.vision-wizard {
    max-width: 560px;
    width: 100%;
}

/* Step indicator in modal header */
.wizard-steps {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex: 1;
    min-width: 0;
}

.wstep {
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    color: #444;
    transition: color 0.2s;
    white-space: nowrap;
}

.wstep.active {
    color: var(--gold);
}

.wstep-arrow {
    font-size: 0.55rem;
    color: #333;
    flex-shrink: 0;
}

/* Wizard step panels */
.wizard-step {
    display: none;
    padding: 1.25rem 1.5rem 1.5rem;
    flex-direction: column;
    gap: 0.9rem;
}

.wizard-step.active {
    display: flex;
}

/* Scene context box in step 1 */
.wizard-scene-box {
    background: #080808;
    border: 1px solid #1e1e1e;
    border-left: 3px solid var(--gold);
    border-radius: 6px;
    padding: 0.8rem 1rem;
    font-size: 0.85rem;
    color: #aaa;
    line-height: 1.7;
}

.wizard-label {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 2px;
    color: var(--muted);
    font-weight: 700;
    margin-bottom: -0.4rem;
}

.wizard-hint {
    font-size: 0.78rem;
    color: #555;
    line-height: 1.5;
}

/* Character chips in step 1 */
.vision-chips {
    gap: 0.5rem;
    flex-wrap: wrap;
    min-height: 2.5rem;
}

.vision-char-chip {
    background: #111;
    border: 1px solid #2a2a2a;
    color: #bbb;
    padding: 0.45rem 1rem;
    border-radius: 2rem;
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.2s;
    user-select: none;
}

.vision-char-chip:hover {
    border-color: var(--gold);
    color: #fff;
}

.vision-char-chip.active {
    background: var(--gold);
    color: #000;
    border-color: var(--gold);
    font-weight: 700;
}

/* Prompt textarea in step 2 */
#vision-prompt {
    width: 100%;
    background: #080808;
    border: 1px solid #222;
    border-radius: 8px;
    color: #ccc;
    padding: 0.9rem;
    font-family: var(--font-serif);
    font-size: 0.9rem;
    line-height: 1.7;
    resize: vertical;
    min-height: 160px;
}

#vision-prompt:focus {
    outline: none;
    border-color: var(--gold);
}

/* Prompt building spinner */
.wizard-loading {
    text-align: center;
    color: var(--gold);
    font-size: 0.85rem;
    padding: 0.5rem;
    letter-spacing: 1px;
}

/* Button row for back/next */
.wizard-btn-row {
    display: flex;
    gap: 0.75rem;
    align-items: center;
    justify-content: flex-end;
}

.wizard-next-btn {
    width: 100%;
    margin-top: 0.5rem;
}

/* Step 3 — result */
.vision-result-frame {
    width: 100%;
    border-radius: 8px;
    overflow: hidden;
    border: 1px solid #222;
    background: #000;
    max-height: 55vh;
    display: flex;
    align-items: center;
    justify-content: center;
}

.vision-result-frame img {
    width: 100%;
    height: auto;
    max-height: 55vh;
    object-fit: contain;
    display: block;
}

.wizard-quota-note {
    font-size: 0.72rem;
    color: #555;
    text-align: center;
    margin-top: -0.4rem;
}

/* ══════════════════════════════════════════════════════════════════
   VISION WIZARD — Step 2 Prompt Blocks
══════════════════════════════════════════════════════════════════ */

/* Scrollable block list — keeps modal at fixed height */
.prompt-blocks-list {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    max-height: 42vh;
    overflow-y: auto;
    overflow-x: hidden;
    padding-right: 2px;
    scrollbar-width: thin;
    scrollbar-color: #2a2a2a transparent;
}

.prompt-blocks-list::-webkit-scrollbar { width: 4px; }
.prompt-blocks-list::-webkit-scrollbar-thumb { background: #2a2a2a; border-radius: 2px; }

/* Individual block */
.prompt-block {
    border: 1px solid #1e1e1e;
    border-radius: 6px;
    overflow: hidden;
    background: #060606;
}

/* Optional block — slightly different accent */
.prompt-block-optional {
    border-color: #1a1a2e;
    background: #04040a;
}

/* Block trigger row */
.prompt-block-trigger {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.6rem 0.9rem;
    background: none;
    border: none;
    cursor: pointer;
    color: #999;
    font-size: 0.78rem;
    font-weight: 600;
    letter-spacing: 0.5px;
    text-align: left;
    transition: background 0.15s, color 0.15s;
}

.prompt-block-trigger:hover {
    background: #0d0d0d;
    color: #ccc;
}

.prompt-block-trigger > span:first-child {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Gold accent for character blocks */
.prompt-block-char .prompt-block-trigger {
    border-left: 2px solid var(--gold);
}
.prompt-block-char .prompt-block-trigger i:first-child {
    color: var(--gold);
}

/* Optional block accent */
.prompt-block-optional .prompt-block-trigger {
    border-left: 2px solid #334;
}

/* Small meta label (e.g. "synopsis", "optional") */
.prompt-block-meta {
    font-size: 0.65rem;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    color: #444;
    flex-shrink: 0;
}

/* Expand/collapse arrow */
.prompt-block-arrow {
    font-size: 0.6rem;
    color: #444;
    flex-shrink: 0;
    transition: transform 0.2s;
}

.prompt-block.open .prompt-block-arrow {
    transform: rotate(180deg);
}

/* Block body */
.prompt-block-body {
    padding: 0.1rem 0.9rem 0.8rem;
    border-top: 1px solid #111;
}

/* Editable textarea inside block */
.prompt-block-textarea {
    width: 100%;
    background: #080808;
    border: 1px solid #1c1c1c;
    border-radius: 5px;
    color: #bbb;
    padding: 0.6rem 0.75rem;
    font-family: var(--font-serif);
    font-size: 0.83rem;
    line-height: 1.6;
    resize: vertical;
    min-height: 60px;
    box-sizing: border-box;
    margin-top: 0.5rem;
}

.prompt-block-textarea:focus {
    outline: none;
    border-color: #333;
}

.prompt-block-hint {
    font-size: 0.72rem;
    color: #444;
    margin-top: 0.4rem;
    line-height: 1.4;
}


/* Locked (readonly) prompt blocks — synopsis & scene */
.prompt-block-textarea[readonly] {
    color: #666;
    cursor: default;
    resize: none;
    border-color: #111;
    background: #050505;
}
.prompt-block-textarea[readonly]:focus {
    outline: none;
    border-color: #111;
}
.prompt-block-locked .prompt-block-trigger {
    cursor: default;
}
.prompt-block-locked .prompt-block-trigger:hover {
    background: none;
    color: #999;
}
.prompt-block-locked .prompt-block-meta::before {
    content: '🔒 ';
    font-size: 0.65rem;
}

/* ── Vision refined prompt panel (step 2.5) ─────────────────── */
.prompt-refined-divider {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin: 1.25rem 0 0.75rem;
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 2px;
    color: var(--gold);
    border-top: 1px solid #1e1e1e;
    padding-top: 1.25rem;
}
.vision-refined-textarea {
    width: 100%;
    background: #0a0a0a;
    color: #e8e8e8;
    border: 1px solid #2a2a2a;
    border-radius: 6px;
    padding: 0.75rem;
    font-size: 0.85rem;
    line-height: 1.6;
    resize: vertical;
    box-sizing: border-box;
    font-family: inherit;
}
.vision-refined-textarea:focus {
    outline: none;
    border-color: var(--gold);
}

/* ══════════════════════════════════════════════════════════════════
   GALLERY PAGE (v69)
══════════════════════════════════════════════════════════════════ */

.gallery-page {
    min-height: calc(100vh - var(--header-h));
    padding-top: var(--header-h);
    background: #000;
    display: flex;
    flex-direction: column;
}

.gallery-page-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    padding: 3rem 3rem 2rem;
    border-bottom: 1px solid #111;
    gap: 1.5rem;
    flex-wrap: wrap;
}

.gallery-page-title {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.gallery-page-title i {
    color: var(--gold);
    font-size: 1.5rem;
    margin-bottom: 0.25rem;
}

.gallery-page-title h2 {
    font-size: 2.5rem;
    font-weight: 900;
    background: linear-gradient(135deg, #fff 30%, var(--gold) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    letter-spacing: -1px;
    margin: 0;
}

.gallery-page-title p {
    color: var(--muted);
    font-size: 0.9rem;
    margin: 0;
}

.gallery-page-actions {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-shrink: 0;
}

/* Masonry-style card grid */
.gallery-masonry {
    padding: 1rem 2rem 6rem;
}

/* ── Scene group header ─────────────────────────────────── */
.gallery-scene-header {
    margin: 2.5rem 0 1rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid #1e1e1e;
}

.gallery-scene-header:first-child {
    margin-top: 0.5rem;
}

.gallery-scene-title {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.5rem;
    font-family: monospace;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 1.5px;
}

.gallery-scene-ch {
    color: var(--gold);
    font-weight: 700;
    letter-spacing: 2px;
}

.gallery-scene-sep {
    color: #333;
    font-weight: 400;
}

.gallery-scene-loc,
.gallery-scene-time {
    color: #888;
    display: flex;
    align-items: center;
    gap: 0.3rem;
}

.gallery-scene-loc i,
.gallery-scene-time i {
    font-size: 0.7rem;
    color: #555;
}

.gallery-scene-atmos {
    margin-top: 0.35rem;
    font-size: 0.78rem;
    color: #555;
    font-style: italic;
    line-height: 1.4;
}

/* ── Cards row under each scene header ──────────────────── */
.gallery-masonry-row {
    columns: 4 200px;
    column-gap: 1.25rem;
    margin-bottom: 1rem;
}

.gallery-card {
    break-inside: avoid;
    margin-bottom: 1.25rem;
    background: #080808;
    border: 1px solid #141414;
    border-radius: 10px;
    overflow: hidden;
    transition: transform 0.3s ease, border-color 0.3s ease;
    cursor: default;
}

.gallery-card:hover {
    transform: translateY(-4px);
    border-color: #2a2a2a;
}

.gallery-card-img-wrap {
    position: relative;
    width: 100%;
    overflow: hidden;
}

.gallery-card-img-wrap img {
    width: 100%;
    height: auto;
    display: block;
    transition: transform 0.4s ease;
}

.gallery-card:hover .gallery-card-img-wrap img {
    transform: scale(1.03);
}

/* Overlay on hover */
.gallery-card-overlay {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: linear-gradient(transparent, rgba(0,0,0,0.85));
    padding: 1.5rem 0.75rem 0.75rem;
    opacity: 0;
    transition: opacity 0.3s ease;
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
}

.gallery-card:hover .gallery-card-overlay {
    opacity: 1;
}

.gallery-card-name {
    color: #fff;
    font-size: 0.85rem;
    font-weight: 700;
}

.gallery-card-book {
    color: var(--gold);
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.gallery-card-footer {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.5rem 0.75rem;
    border-top: 1px solid #111;
}

.gallery-card-footer .favor-icon {
    background: none;
    border: none;
    color: #444;
    font-size: 0.95rem;
    cursor: pointer;
    transition: color 0.2s, transform 0.2s;
    padding: 0.2rem;
}

.gallery-card-footer .favor-icon:hover {
    color: #e05;
    transform: scale(1.2);
}

.gallery-card-footer .favor-icon.active {
    color: #e05;
}

.gallery-card-footer .vote-count {
    font-size: 0.75rem;
    color: var(--muted);
}

/* Empty and loading states */
.gallery-loading {
    text-align: center;
    color: var(--gold);
    padding: 6rem 2rem;
    font-size: 1rem;
    letter-spacing: 2px;
    text-transform: uppercase;
    width: 100%;
}

.gallery-empty-state {
    text-align: center;
    padding: 6rem 2rem;
    color: var(--muted);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
    width: 100%;
}

.gallery-empty-state i {
    font-size: 3rem;
    opacity: 0.3;
}

.gallery-empty-state p {
    font-size: 0.95rem;
    max-width: 300px;
}

/* Mobile gallery */
@media (max-width: 768px) {
    .gallery-page-header {
        padding: 1.5rem 1.25rem 1rem;
    }
    .gallery-page-title h2 {
        font-size: 1.75rem;
    }
    .gallery-masonry {
        padding: 0.5rem 0.75rem 5rem;
    }
    .gallery-masonry-row {
        columns: 2 140px;
        column-gap: 0.75rem;
    }
    .gallery-scene-title {
        font-size: 0.72rem;
        gap: 0.35rem;
    }
    .gallery-card-overlay {
        opacity: 1; /* Always visible on mobile */
    }
}

/* ══════════════════════════════════════════════════════
   GALLERY LIGHTBOX
══════════════════════════════════════════════════════ */
.gallery-lightbox {
    position: fixed;
    inset: 0;
    z-index: 2000;
    background: rgba(0, 0, 0, 0.92);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
    box-sizing: border-box;
    -webkit-backdrop-filter: blur(6px);
    backdrop-filter: blur(6px);
}

.gallery-lb-inner {
    position: relative;
    background: #0c0c0c;
    border: 1px solid #222;
    border-radius: 14px;
    max-width: 960px;
    width: 100%;
    max-height: 90vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.gallery-lb-close {
    position: absolute;
    top: 0.75rem;
    right: 0.9rem;
    background: none;
    border: none;
    color: #888;
    font-size: 1.8rem;
    line-height: 1;
    cursor: pointer;
    z-index: 10;
    transition: color 0.2s;
}
.gallery-lb-close:hover { color: #fff; }

.gallery-lb-layout {
    display: flex;
    flex-direction: row;
    overflow: hidden;
    height: 100%;
    max-height: 90vh;
}

.gallery-lb-img-col {
    flex: 0 0 auto;
    width: 45%;
    max-height: 90vh;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #080808;
}

.gallery-lb-img-col img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.gallery-lb-info-col {
    flex: 1 1 auto;
    padding: 2.5rem 1.75rem 1.75rem;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
}

.lb-title {
    font-family: 'Playfair Display', serif;
    font-size: 1.5rem;
    color: var(--gold);
    margin: 0 0 0.1rem;
}

.lb-book {
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    color: var(--muted);
}

.lb-meta {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
    margin: 0.5rem 0;
    color: #666;
    font-size: 0.8rem;
}

.lb-meta span {
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.lb-meta i {
    color: #444;
    width: 14px;
    text-align: center;
}

.lb-prompt-section {
    margin-top: 0.75rem;
    border-top: 1px solid #1a1a1a;
    padding-top: 0.9rem;
    flex: 1;
}

.lb-prompt-label {
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    color: var(--gold);
    margin: 0 0 0.6rem;
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.lb-prompt-text {
    font-size: 0.82rem;
    color: #888;
    line-height: 1.65;
    margin: 0;
    white-space: pre-wrap;
    font-style: italic;
}

/* Mobile lightbox — stack vertically */
@media (max-width: 768px) {
    .gallery-lb-layout {
        flex-direction: column;
        max-height: 88vh;
    }
    .gallery-lb-img-col {
        width: 100%;
        max-height: 45vh;
    }
    .gallery-lb-info-col {
        padding: 1.25rem 1rem;
    }
    .lb-title {
        font-size: 1.15rem;
    }
}



/* ── Gallery: new-card highlight animation (post-publish instant feedback) ─── */
@keyframes galleryCardIn {
    from { opacity: 0; transform: translateY(-12px) scale(0.97); }
    to   { opacity: 1; transform: translateY(0)    scale(1);    }
}
.gallery-card-new {
    animation: galleryCardIn 0.5s ease both;
}
.gallery-card-highlight {
    border-color: #c8a84b !important;
    box-shadow: 0 0 18px rgba(200, 168, 75, 0.35);
    transition: border-color 0.3s ease, box-shadow 0.3s ease;
}

/* ── Gallery mode toggle ────────────────────────────────── */
.gallery-mode-toggle {
    display: flex;
    align-items: center;
    background: rgba(255,255,255,0.05);
    border: 1px solid var(--border);
    border-radius: 2rem;
    padding: 0.2rem;
    gap: 0;
}
.gallery-mode-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 0.8rem;
    padding: 0.35rem 0.85rem;
    border-radius: 2rem;
    cursor: pointer;
    transition: background 0.2s, color 0.2s;
    white-space: nowrap;
}
.gallery-mode-btn:hover { color: var(--text); }
.gallery-mode-btn.active {
    background: var(--gold);
    color: #0a0a0f;
    font-weight: 600;
}
.gallery-mode-btn i { margin-right: 0.3rem; }

/* ── Gallery spoiler modal overlay ─────────────────────── */
.gallery-spoiler-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.82);
    z-index: 10500;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
}
.gallery-spoiler-box {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 1rem;
    max-width: 420px;
    width: 100%;
    padding: 2.5rem 2rem 2rem;
    text-align: center;
    box-shadow: 0 8px 40px rgba(0,0,0,0.6);
}
.gallery-spoiler-icon {
    font-size: 2.5rem;
    color: #e55;
    margin-bottom: 1rem;
    display: block;
}
.gallery-spoiler-box h3 {
    font-size: 1.3rem;
    color: var(--text);
    margin-bottom: 1rem;
}
.gallery-spoiler-box p {
    color: var(--text-muted);
    font-size: 0.92rem;
    line-height: 1.6;
    margin-bottom: 0.75rem;
}
.gallery-spoiler-sub {
    font-style: italic;
    font-size: 0.85rem !important;
}
.gallery-spoiler-actions {
    display: flex;
    gap: 0.75rem;
    justify-content: center;
    margin-top: 1.5rem;
    flex-wrap: wrap;
}
.gallery-spoiler-banner {
    color: #e55 !important;
    font-size: 0.78rem;
    opacity: 0.85;
}
.gallery-spoiler-banner i { margin-right: 0.3rem; }

/* ══════════════════════════════════════════════════════
   BETA BANNER
══════════════════════════════════════════════════════ */
.beta-banner {
    position: relative;
    background: linear-gradient(135deg, #0d0d1a 0%, #1a0a2e 50%, #0a1a2e 100%);
    border: 1px solid rgba(139, 92, 246, 0.35);
    border-radius: 12px;
    margin: 1.5rem 1rem 0;
    padding: 1.75rem 2rem 1.75rem 1.75rem;
    box-shadow: 0 4px 32px rgba(139, 92, 246, 0.12), 0 1px 0 rgba(255,255,255,0.04) inset;
    overflow: hidden;
}
.beta-banner::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 2px;
    background: linear-gradient(90deg, #7c3aed, #2563eb, #7c3aed);
}
.beta-banner.dismissed { display: none; }

.beta-banner-close {
    position: absolute;
    top: 0.75rem; right: 0.85rem;
    background: none; border: none;
    color: rgba(255,255,255,0.35);
    font-size: 1.4rem;
    line-height: 1;
    cursor: pointer;
    padding: 0.2rem 0.4rem;
    transition: color 0.2s;
}
.beta-banner-close:hover { color: rgba(255,255,255,0.75); }

.beta-banner-inner {
    display: flex;
    gap: 1.25rem;
    align-items: flex-start;
}

.beta-pill {
    flex-shrink: 0;
    background: linear-gradient(135deg, #7c3aed, #2563eb);
    color: #fff;
    font-size: 0.65rem;
    font-weight: 800;
    letter-spacing: 0.12em;
    padding: 0.3rem 0.65rem;
    border-radius: 4px;
    margin-top: 0.15rem;
}

.beta-banner-body { flex: 1; min-width: 0; }

.beta-banner-title {
    color: #e2d9f3;
    font-size: 1.15rem;
    font-weight: 800;
    margin: 0 0 0.6rem;
    line-height: 1.3;
}

.beta-banner-sub {
    color: rgba(200,190,220,0.8);
    font-size: 0.875rem;
    line-height: 1.65;
    margin: 0 0 1rem;
}
.beta-banner-sub strong { color: #c4b5fd; }
.beta-banner-sub em { color: #93c5fd; font-style: normal; }

.beta-banner-features {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.55rem 1.5rem;
    margin-bottom: 1rem;
}

.beta-feature {
    display: flex;
    align-items: baseline;
    gap: 0.5rem;
    font-size: 0.82rem;
    color: rgba(180,170,210,0.85);
    line-height: 1.45;
}
.beta-feature i {
    color: #7c3aed;
    font-size: 0.8rem;
    flex-shrink: 0;
    margin-top: 0.1rem;
}
.beta-feature strong { color: #ddd6fe; }

.beta-banner-cta {
    font-size: 0.82rem;
    color: rgba(160,150,200,0.75);
    margin: 0;
    border-top: 1px solid rgba(139,92,246,0.2);
    padding-top: 0.75rem;
}
.beta-banner-cta strong { color: #a78bfa; }

@media (max-width: 600px) {
    .beta-banner { margin: 1rem 0.5rem 0; padding: 1.25rem 2.5rem 1.25rem 1rem; }
    .beta-banner-inner { flex-direction: column; gap: 0.75rem; }
    .beta-banner-features { grid-template-columns: 1fr; }
    .beta-banner-title { font-size: 1rem; }
}
