:root {
    --mobile-bottom-nav-height: 96px;
    --mobile-bottom-clearance: calc(var(--mobile-bottom-nav-height) + env(safe-area-inset-bottom, 0px) + 28px);
}

@media (max-width: 900px) and (max-height: 900px) {
    :root {
        --mobile-bottom-nav-height: 84px;
    }
}

.ios-home-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 16px;
    padding-top: env(safe-area-inset-top, 0px);
    height: calc(54px + env(safe-area-inset-top, 0px));
    background: transparent;
    position: sticky;
    top: 0;
    z-index: 50;
    border-bottom: none;
}

.ios-home-header .logo {
    font-size: 1.35rem;
    margin: 0;
    color: var(--accent);
    font-family: var(--font-serif);
    font-weight: 600;
    letter-spacing: -0.01em;
}

.ios-home-header .settings-inline-pill {
    background: rgba(255,255,255,0.7);
    border: 1px solid rgba(0,0,0,0.05);
    border-radius: 50%;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    box-shadow: 0 2px 8px rgba(0,0,0,0.03);
}

[data-theme="dark"] .ios-home-header .settings-inline-pill {
    background: rgba(0,0,0,0.5);
    border: 1px solid rgba(255,255,255,0.1);
}

.ios-tab-wrapper {
    padding-bottom: 160px;
    height: 100vh;
    overflow-y: auto;
    overflow-x: hidden;
    background: linear-gradient(180deg, #F8F4EA 0%, var(--bg-body) 100vh);
}

[data-theme="dark"] .ios-tab-wrapper {
    background: linear-gradient(180deg, #1A1A1A 0%, var(--bg-body) 100vh);
}

.ios-tab-pane {
    display: none !important;
    min-height: 100%;
    animation: fadeTab 0.2s ease;
    padding-bottom: 8px;
}

.ios-tab-pane.active {
    display: block !important;
}

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

.bottom-tab-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 72px;
    min-height: var(--mobile-bottom-nav-height);
    background: rgba(252, 247, 239, 0.88) !important;
    backdrop-filter: blur(20px) saturate(1.2) !important;
    -webkit-backdrop-filter: blur(20px) saturate(1.2) !important;
    border-top: 1px solid rgba(168, 132, 83, 0.14) !important;
    display: flex;
    justify-content: space-around;
    align-items: flex-start;
    padding-top: 6px !important;
    padding-bottom: env(safe-area-inset-bottom, 20px);
    z-index: 1000;
    box-shadow: 0 -8px 24px rgba(55, 40, 24, 0.07) !important;
    transition: transform 0.35s cubic-bezier(0.25, 0.8, 0.25, 1);
}

[data-theme="dark"] .bottom-tab-bar {
    background: rgba(18, 22, 20, 0.88) !important;
    border-top: 1px solid rgba(152, 178, 143, 0.14) !important;
    box-shadow: 0 -8px 24px rgba(0, 0, 0, 0.24) !important;
}

[data-theme="black"] .bottom-tab-bar {
    background: rgba(6, 8, 10, 0.92) !important;
    border-top: 1px solid rgba(200, 171, 124, 0.12) !important;
    box-shadow: 0 -8px 28px rgba(0, 0, 0, 0.36) !important;
}

.tab-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex: 1;
    height: 100%;
    min-height: 56px;
    background: none;
    border: none;
    color: var(--text-muted) !important;
    font-family: var(--font-sans);
    cursor: pointer;
    transition: color 0.2s ease, transform 0.15s ease;
    position: relative;
    z-index: 1;
    gap: 3px;
    padding: 0 4px;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

.tab-item:active {
    transform: scale(0.94);
}

.tab-item.active {
    color: var(--accent-dark) !important;
}

[data-theme="dark"] .tab-item.active,
[data-theme="black"] .tab-item.active {
    color: var(--accent-light) !important;
}

.tab-icon {
    width: 22px !important;
    height: 22px !important;
    margin-bottom: 2px !important;
    stroke-width: 2px;
    transition: stroke-width 0.2s ease;
}

.tab-item.active .tab-icon {
    stroke-width: 2.4px !important;
}

.tab-label {
    font-size: 0.58rem !important;
    font-weight: 600 !important;
    letter-spacing: 0.04em;
    font-family: var(--font-ui, var(--font-sans));
}

.tab-item.active::before {
    content: '';
    display: block;
    width: 4px;
    height: 4px;
    border-radius: 50%;
    background: var(--accent-dark);
    margin: 0 auto 4px;
    order: -1;
    animation: tabDotPop 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
}

[data-theme="dark"] .tab-item.active::before,
[data-theme="black"] .tab-item.active::before {
    background: var(--accent-light);
}

@keyframes tabDotPop {
    from { transform: scale(0); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}

#sidebar {
    position: static;
    transform: none;
    width: 100%;
    height: auto;
    border-right: none;
    background: transparent;
    z-index: 1;
}

#content {
    margin-left: 0;
    padding-top: 0;
}

#menuToggle {
    display: none !important;
}

.welcome {
    margin: 0 auto;
    border-radius: 0;
    padding-top: 12px;
}

.welcome-inner {
    background: var(--bg-card);
    border-radius: 32px 32px 0 0;
    min-height: calc(100vh - 80px);
    padding-top: 24px;
    box-shadow: 0 -4px 24px rgba(0,0,0,0.02);
    margin: 0 8px;
}

@media (min-width: 768px) {
    .welcome-inner {
        margin: 0 auto;
        max-width: 600px;
    }
}

@media (min-width: 900px) {
    html {
        /* Warm amber-dark background for the desktop surround — better than raw black */
        background: radial-gradient(ellipse at 50% 0%, #2a1f0e 0%, #0e0a06 100%);
        background-attachment: fixed;
    }
    .ios-tab-wrapper {
        max-width: 430px;
        margin: 0 auto;
        min-height: 100vh;
        box-shadow: 0 0 80px rgba(196, 154, 42, 0.08), 0 0 0 1px rgba(168, 132, 83, 0.08);
    }
    /* Re-center fixed tab bar within the 430px shell */
    .bottom-tab-bar {
        max-width: 430px;
        left: 50%;
        transform: translateX(-50%);
    }
    /* Constrain fixed overlays to the 430px shell */
    .ios-verse-action-bar,
    .audio-mini-player,
    .autoscroll-bar {
        left: 50% !important;
        right: auto !important;
        transform: translateX(-50%);
        width: min(406px, calc(100vw - 24px));
    }
    /* Immersive mode — hide bottom tab bar on scroll down in reader */
    body.immersive-mode .bottom-tab-bar {
        transform: translateX(-50%) translateY(100%);
    }
}

/* === FIX: Autoscroll bar must ONLY appear when reader is active === */
/* When user is NOT on read tab, or reader is closed, hide the bar regardless */
body:not(.tab-read-active) .autoscroll-bar,
body.reader-closed .autoscroll-bar {
    display: none !important;
    pointer-events: none !important;
}
