/* ══════════════════════════════════════════════════════════════════
   DIM LANTERN — mobile overhaul (<= 768px)
   Additive stylesheet. Loads AFTER style.css.
   All rules gated on @media (max-width: 768px) to leave desktop intact.
   ══════════════════════════════════════════════════════════════════ */

@media (max-width: 768px) {

/* ── Tokens ───────────────────────────────────────────────────── */
:root {
    --dl-bg:        #050505;
    --dl-bg-raised: #0c0c0c;
    --dl-border:    #1a1a1a;
    --dl-border-2:  #242424;
    --dl-fg:        #e8e4d9;
    --dl-fg-dim:    #8a8374;
    --dl-muted:     #555044;
    --dl-gold:      #d4af37;
    --dl-gold-soft: rgba(212, 175, 55, 0.18);
    --dl-serif:     'Georgia', 'Iowan Old Style', 'Charter', serif;

    /* bottom nav height + iOS safe-area */
    --dl-nav-h: 64px;
    --dl-nav-total: calc(var(--dl-nav-h) + env(safe-area-inset-bottom, 0px));
}

/* ── Global ───────────────────────────────────────────────────── */
body {
    font-size: 16px;
    /* reserve space for bottom nav whenever it's visible */
    padding-bottom: var(--dl-nav-total);
}

/* Header — compact, single row, no icon crowding */
header {
    height: 56px;
    padding: 0 1rem;
}
.brand-logo-img { height: 24px; max-width: 130px; }
#nav-controls { gap: 0.25rem; }
.icon-btn {
    width: 40px;
    height: 40px;
    font-size: 0.95rem;
}
/* hide progress bar from header on mobile — moved to reader */
#progress-container { display: none !important; }

/* ── Bottom nav — injected by mobile.js ───────────────────────── */
#dl-bottom-nav {
    position: fixed;
    left: 0; right: 0; bottom: 0;
    height: var(--dl-nav-total);
    padding-bottom: env(safe-area-inset-bottom, 0px);
    background: rgba(5,5,5,0.94);
    backdrop-filter: blur(18px);
    -webkit-backdrop-filter: blur(18px);
    border-top: 1px solid var(--dl-border);
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    z-index: 5000;
    /* Sits below the narrator bar (z 4998) by default; re-elevated when narrator is hidden */
}
#dl-bottom-nav .dl-nav-btn {
    background: transparent;
    border: 0;
    color: var(--dl-fg-dim);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    font-family: inherit;
    font-size: 0.62rem;
    letter-spacing: 1.2px;
    text-transform: uppercase;
    padding: 0;
    cursor: pointer;
    transition: color 0.2s ease;
    position: relative;
}
#dl-bottom-nav .dl-nav-btn i { font-size: 1.15rem; }
#dl-bottom-nav .dl-nav-btn[aria-current="true"] { color: var(--dl-gold); }
#dl-bottom-nav .dl-nav-btn[aria-current="true"]::before {
    content: '';
    position: absolute;
    top: 0; left: 50%;
    width: 20px; height: 2px;
    background: var(--dl-gold);
    transform: translateX(-50%);
    box-shadow: 0 0 8px var(--dl-gold);
}

/* Narrator bar sits ABOVE the nav (stacks) — 48px compact */
#narrator-bar {
    bottom: var(--dl-nav-total);
    padding: 0.4rem 0.75rem;
    padding-bottom: 0.4rem;
}
#narrator-bar-inner { gap: 0.5rem; }
.narrator-chapter { font-size: 0.6rem; }
.narrator-passage { font-size: 0.55rem; }
#audio-player { height: 28px; max-width: none; }

/* ══════════════════════════════════════════════════════════════════
   LIBRARY
   ══════════════════════════════════════════════════════════════════ */
#view-library { padding-bottom: calc(var(--dl-nav-total) + 1rem); }

.hero {
    padding: 2.5rem 1.25rem 2rem;
}
.hero h2 {
    font-family: var(--dl-serif);
    font-weight: 400;
    font-style: italic;
    font-size: 2.4rem;
    letter-spacing: -1px;
    line-height: 1.05;
    margin-bottom: 0.75rem;
}
.hero p {
    font-size: 0.95rem;
    line-height: 1.5;
    padding: 0 0.5rem;
    margin-bottom: 0;
}

.view-title-row {
    padding: 0 1.25rem;
    margin: 1.5rem 0 1rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.view-title {
    font-family: var(--dl-serif);
    font-weight: 400;
    font-style: italic;
    font-size: 1.05rem;
    color: var(--dl-fg-dim);
    text-transform: none;
    letter-spacing: 0;
}
.narration-legend { font-size: 0.6rem; }

/* Book grid — 2-up thumbnail-forward */
.book-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1rem;
    padding: 0 1.25rem;
}
.book-card {
    background: transparent;
    border: 0;
    padding: 0;
    border-radius: 0;
    cursor: pointer;
}
.book-card .book-cover,
.book-card img {
    width: 100%;
    aspect-ratio: 2 / 3;
    object-fit: cover;
    border-radius: 4px;
    box-shadow:
        0 1px 0 rgba(255,255,255,0.04) inset,
        0 8px 24px rgba(0,0,0,0.6),
        0 0 0 1px var(--dl-border);
    background: linear-gradient(135deg, #1a1612, #0a0807);
}
.book-card h3, .book-card .book-title {
    font-family: var(--dl-serif);
    font-size: 0.92rem;
    font-weight: 500;
    margin-top: 0.6rem;
    line-height: 1.25;
    color: var(--dl-fg);
}
.book-card .book-author, .book-card .author {
    font-size: 0.72rem;
    color: var(--dl-fg-dim);
    margin-top: 0.15rem;
    font-style: italic;
}
.book-card .badge, .book-card .narration-badge {
    font-size: 0.55rem;
}

/* Beta banner — compact */
.beta-banner { margin: 0.75rem 1rem 0; padding: 1rem 2.25rem 1rem 0.9rem; }
.beta-banner-title { font-size: 0.95rem; }
.beta-banner-sub { font-size: 0.8rem; }
.beta-banner-features { grid-template-columns: 1fr; gap: 0.4rem; }

/* ══════════════════════════════════════════════════════════════════
   READER — split-layout collapses to single-pane
   ══════════════════════════════════════════════════════════════════ */
#split-layout {
    display: flex !important;   /* was flex, but may be "none" when inactive */
    flex-direction: column;
}
#split-layout[style*="display: none"],
#split-layout[style*="display:none"] { display: none !important; }

/* Hide left lore panel + divider on mobile — replaced by bottom sheet */
#panel-left, #panel-divider { display: none !important; }

#panel-right {
    width: 100%;
    padding-bottom: calc(var(--dl-nav-total) + 64px); /* nav + narrator */
}

#text-container {
    padding: 5rem 1.5rem 2rem;  /* room under header */
    max-width: 100%;
}
#text-content {
    font-family: var(--dl-serif);
    font-size: 1.125rem;
    line-height: 1.75;
    color: var(--dl-fg);
    letter-spacing: 0.01em;
}
#text-content p {
    margin: 0 0 1.35em;
    text-wrap: pretty;
}
#text-content .chapter-heading,
#text-content h2, #text-content h3 {
    font-family: var(--dl-serif);
    font-weight: 400;
    font-style: italic;
    font-size: 1.4rem;
    color: var(--dl-fg-dim);
    margin: 2.5rem 0 1.5rem;
    text-align: center;
    letter-spacing: 0.04em;
}

/* character-chip hits inline */
#text-content .char-mention,
#text-content a.persona-link {
    color: var(--dl-gold);
    text-decoration: none;
    border-bottom: 1px dotted var(--dl-gold-soft);
    padding-bottom: 1px;
}

/* ── Reader rail: thin progress + Lore pill anchored bottom ───── */
#dl-reader-rail {
    position: fixed;
    left: 0; right: 0;
    bottom: calc(var(--dl-nav-total) + 52px);  /* above narrator */
    pointer-events: none;
    z-index: 4997;
    display: flex;
    justify-content: center;
    padding: 0 1rem;
}
#dl-lore-handle {
    pointer-events: auto;
    background: rgba(10,10,10,0.92);
    border: 1px solid var(--dl-border-2);
    color: var(--dl-fg);
    font-family: var(--dl-serif);
    font-style: italic;
    font-size: 0.82rem;
    padding: 0.5rem 1.1rem;
    border-radius: 999px;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    backdrop-filter: blur(12px);
    box-shadow: 0 4px 16px rgba(0,0,0,0.5);
    cursor: pointer;
}
#dl-lore-handle .dl-lore-count {
    font-style: normal;
    color: var(--dl-gold);
    background: var(--dl-gold-soft);
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 0.7rem;
    font-family: var(--dl-serif);
}

/* In-header progress line (under brand) */
#dl-reader-progress {
    position: fixed;
    top: 56px;
    left: 0; right: 0;
    height: 2px;
    background: var(--dl-border);
    z-index: 8999;
}
#dl-reader-progress > span {
    display: block;
    height: 100%;
    background: linear-gradient(90deg, var(--dl-gold), #f0d060);
    width: 0%;
    transition: width 0.8s cubic-bezier(0.25, 1, 0.5, 1);
    box-shadow: 0 0 6px var(--dl-gold-soft);
}

/* ══════════════════════════════════════════════════════════════════
   LORE BOTTOM SHEET
   ══════════════════════════════════════════════════════════════════ */
#dl-lore-sheet {
    position: fixed;
    left: 0; right: 0; bottom: 0;
    height: 85vh;
    max-height: 85vh;
    background: #0a0a0a;
    border-top: 1px solid var(--dl-border-2);
    border-radius: 18px 18px 0 0;
    transform: translateY(100%);
    transition: transform 0.32s cubic-bezier(0.25, 1, 0.3, 1);
    z-index: 5100;
    display: flex;
    flex-direction: column;
    box-shadow: 0 -12px 48px rgba(0,0,0,0.7);
}
#dl-lore-sheet.dl-open { transform: translateY(0); }
#dl-lore-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.55);
    backdrop-filter: blur(4px);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.28s ease;
    z-index: 5099;
}
#dl-lore-backdrop.dl-open { opacity: 1; pointer-events: auto; }

#dl-lore-grip {
    display: flex;
    justify-content: center;
    padding: 10px 0 6px;
    touch-action: none;
}
#dl-lore-grip::before {
    content: '';
    width: 40px;
    height: 4px;
    border-radius: 4px;
    background: var(--dl-border-2);
}
#dl-lore-sheet-body {
    flex: 1;
    overflow-y: auto;
    padding: 0 1.1rem 2rem;
    -webkit-overflow-scrolling: touch;
}

/* Lore section inside sheet — reuse existing lore-section styling but tune spacing */
#dl-lore-sheet .lore-section {
    border-bottom: 1px solid var(--dl-border);
    padding: 0.4rem 0;
}
#dl-lore-sheet .section-trigger {
    padding: 0.8rem 0;
    font-family: var(--dl-serif);
}
#dl-lore-sheet .section-trigger h4 {
    font-size: 0.82rem;
    letter-spacing: 1.5px;
    text-transform: uppercase;
    color: var(--dl-fg-dim);
    font-weight: 600;
}
#dl-lore-sheet .section-content { padding: 0.25rem 0 1rem; }
#dl-lore-sheet .chip-container { gap: 0.4rem; }

/* Chat composer becomes sticky at bottom of sheet when interrogating */
#dl-lore-sheet .chat-input-wrap {
    position: sticky;
    bottom: 0;
    background: #0a0a0a;
    padding: 0.5rem 0 0.25rem;
    border-top: 1px solid var(--dl-border);
}

/* ══════════════════════════════════════════════════════════════════
   PROFILE + AUTH
   ══════════════════════════════════════════════════════════════════ */
#view-profile, #view-auth {
    padding: 5rem 1.25rem calc(var(--dl-nav-total) + 2rem);
}
.profile-container { padding: 0; }
.profile-layout {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}
.profile-pic-section {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.75rem;
}
#profile-pic-preview { width: 96px; height: 96px; border-radius: 50%; object-fit: cover; }
.auth-container {
    padding: 0;
    max-width: 100%;
}

/* ══════════════════════════════════════════════════════════════════
   GALLERY
   ══════════════════════════════════════════════════════════════════ */
#view-gallery { padding-bottom: calc(var(--dl-nav-total) + 1rem); }
.gallery-page { padding: 4.5rem 0.75rem 0; }
.gallery-page-header { flex-direction: column; gap: 0.75rem; padding: 0 0.5rem; }
.gallery-page-title h2 { font-size: 1.4rem; }
.gallery-page-title p { font-size: 0.82rem; }
.gallery-page-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    width: 100%;
}
.gallery-masonry {
    columns: 2;
    column-gap: 0.5rem;
    padding: 0 0.25rem;
}
.gallery-masonry > * {
    break-inside: avoid;
    margin-bottom: 0.5rem;
}

/* ══════════════════════════════════════════════════════════════════
   Vision wizard — fullscreen on mobile
   ══════════════════════════════════════════════════════════════════ */
.modal-overlay { padding: 0; }
.modal-panel.vision-wizard {
    width: 100vw;
    max-width: 100vw;
    height: 100vh;
    max-height: 100vh;
    border-radius: 0;
    padding: 1rem;
    overflow-y: auto;
}
.wizard-steps { font-size: 0.7rem; }

/* ══════════════════════════════════════════════════════════════════
   TOC overlay
   ══════════════════════════════════════════════════════════════════ */
.toc-overlay .toc-panel {
    width: 100vw;
    max-width: 100vw;
    height: 100vh;
    border-radius: 0;
}

/* ── Hide debug bar on mobile (reserve real estate) ───────────── */
#debug-tid-bar { display: none !important; }

} /* end @media */
