/* ========================================
   1. GLOBAL RESET & BASE STYLES
   ======================================== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}
body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    -webkit-user-select: none;
    user-select: none;
    background: #f5f5f7;
    color: #000;
    line-height: 1.5;
}

/* ========================================
   2. HOME SCREEN – VOLUME GRID
   ======================================== */
#home {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 20px;
    padding: 20px;
    padding-bottom: 80px;
}
.volume {
    background: white;
    border-radius: 16px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
    overflow: hidden;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s ease;
    transform: translateY(0);
}
.volume:hover {
    transform: translateY(-4px);
    box-shadow: 0 8px 20px rgba(0,0,0,0.15);
}
.volume img {
    width: 100%;
    height: 180px;
    object-fit: cover;
    border-radius: 16px 16px 0 0;
}
.volume p {
    margin: 12px 0 16px;
    font-weight: 600;
    font-size: 15px;
    color: #1d1d1f;
}

/* ========================================
   3. VIEWER – FULLSCREEN PDF MODE
   ======================================== */
#viewer {
    display: none;
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: white;
    z-index: 100;
    flex-direction: column;
}

/* ========================================
   4. NAV BAR – FIXED FLEX & FULL TAPPABLE BUTTONS
   ======================================== */
#nav-bar {
    position: fixed;
    top: 0; left: 0; right: 0;
    height: 44px;
    background: linear-gradient(to bottom, #f9f9f9, #f0f0f0);
    border-bottom: 1px solid #d2d2d2;
    display: flex;
    align-items: stretch;
    justify-content: space-between;
    padding: 0;
    z-index: 110;
    font-size: 17px;
}

#back, #menu-toggle {
    color: #007aff;
    font-weight: 600;
    cursor: pointer;
    padding: 0 16px;
    margin: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 70px;
    flex: 0 0 auto;
    border-radius: 0;
    transition: background 0.2s ease;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}
#back:hover, #menu-toggle:hover,
#back:active, #menu-toggle:active {
    background: rgba(0,122,255,0.12);
}

#nav-title {
    font-weight: 600;
    color: #1d1d1f;
    flex: 1;
    text-align: center;
    padding: 0 20px;
    display: flex;
    align-items: center;
    justify-content: center;
}

#page-info {
    font-size: 14px;
    color: #8e8e93;
    font-weight: 500;
    padding: 0 16px;
    display: flex;
    align-items: center;
}

/* ========================================
   5. DROPDOWN MENU – SECTION + ITEMS
   ======================================== */
#dropdown-menu {
    position: absolute;
    top: 44px; left: 0; right: 0;
    max-height: 0;
    overflow: hidden;
    background: black;
    box-shadow: 0 8px 24px rgba(0,0,0,0.18);
    border-radius: 0 0 16px 16px;
    transition: max-height 0.35s ease;
    z-index: 105;
}
#dropdown-menu.open {
    max-height: calc(100vh - 114px);
    overflow-y: auto;
}
#menu-content {
    padding: 0;
}

/* ——— SECTION TITLE – PRETTY ROUNDED BOX + SHADOW + 16PX GAP ——— */
.type {
    display: block !important;
    background: #000 !important;
    color: #fff !important;
    font-size: 18px !important;
    font-weight: 900 !important;
    text-transform: uppercase !important;
    letter-spacing: 1.2px !important;
    padding: 16px 20px !important;
    margin: 24px 16px 16px 16px !important;   /* ← 16px GAP BELOW */
    border-radius: 16px !important;           /* ← GORGEOUS ROUNDED CORNERS */
    box-shadow: 
        0 6px 16px rgba(0,0,0,0.25),
        0 2px 6px rgba(0,0,0,0.15) !important; /* ← LAYERED ELEGANT SHADOW */
    position: relative !important;
    overflow: hidden !important;
    z-index: 1 !important;
    backdrop-filter: blur(4px) !important;
}
.type::before {
    content: '';
    position: absolute !important;
    top: 0; left: 0; right: 0; bottom: 0;
    background: linear-gradient(135deg, rgba(255,255,255,0.18) 0%, transparent 70%) !important;
    border-radius: 16px !important;
    pointer-events: none !important;
    z-index: -1 !important;
}
#menu-content > ul > li:first-child .type {
    margin-top: 18px !important;
}

/* ——— FIRST KEY – START AFTER 16PX GAP ——— */
.key:first-of-type {
    margin-top: 16px !important;
}

/* ——— MENU ITEMS – FULL WIDTH ——— */
.key {
    display: block;
    width: 100%;
    background: #f8f8f8;
    color: #1d1d1f;
    font-size: 16px;
    font-weight: 500;
    padding: 15px 20px;
    margin: 0;
    border: none;
    border-bottom: 1px solid #e5e5e5;
    text-align: left;
    cursor: pointer;
    transition: background 0.2s ease;
}
.key:first-of-type {
    margin-top: 16px !important;
}
.key:hover, .key:active {
    background: #ebebeb !important;
}
.key:last-child {
    border-bottom: none;
}
.key[style*="opacity"] {
    font-style: italic;
    color: #666;
    background: #f0f0f0;
}

/* ========================================
   6. PDF CANVAS – CENTERED & DARK BACKGROUND
   ======================================== */
#pdf-container {
    position: absolute;
    top: 44px; left: 0; bottom: 70px; right: 0;
    overflow: auto;
    padding: 16px;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    -webkit-overflow-scrolling: touch;
    background: #1c1c1e !important;
    z-index: 0;
}

#pdf-container::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background: 
        radial-gradient(circle at 20% 80%, rgba(255,255,255,0.03) 0%, transparent 50%),
        radial-gradient(circle at 80% 20%, rgba(255,255,255,0.02) 0%, transparent 50%);
    pointer-events: none;
    z-index: 0;
}

#pdf-canvas {
    position: relative;
    z-index: 1;
    max-width: 100%;
    height: auto;
    border-radius: 12px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.15);
    background: white;
}

/* ========================================
   7. NAV FOOTER – ARROW BUTTONS
   ======================================== */
#nav-footer {
    position: fixed;
    bottom: 0; left: 0; right: 0;
    height: 70px;
    background: linear-gradient(to bottom, #f2f2f2, #e8e8e8);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 90px;
    z-index: 110;
    pointer-events: none;
}
.nav-arrow {
    width: 54px;
    height: 54px;
    border-radius: 50%;
    background: rgba(255,255,255,0.85);
    backdrop-filter: blur(12px);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0;
    cursor: pointer;
    transition: all 0.25s ease;
    opacity: 0.7;
    color: #007aff;
    pointer-events: auto;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}
.nav-arrow:hover, .nav-arrow:active {
    opacity: 1;
    transform: scale(1.12);
    background: rgba(255,255,255,0.95);
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
}
.nav-arrow::before {
    font-size: 30px;
    font-weight: bold;
}
#prev-arrow::before  { content: "←"; }
#next-arrow::before  { content: "→"; }

/* ========================================
   8. DARK MODE – SYSTEM PREFERENCE
   ======================================== */
@media (prefers-color-scheme: dark) {
    body {
        background: #000;
        color: #f0f0f0;
    }

    .volume {
        background: #1c1c1e;
        box-shadow: 0 4px 12px rgba(0,0,0,0.4);
    }
    .volume p { color: #f0f0f0; }

    #nav-bar {
        background: linear-gradient(to bottom, #1c1c1e, #111113);
        border-bottom-color: #333;
    }
    #nav-title, #back, #menu-toggle { color: #ffffff; }

    #back:hover, #menu-toggle:hover,
    #back:active, #menu-toggle:active {
        background: rgba(10, 132, 255, 0.2) !important;
    }

    /* DARK MODE: BOXED TITLE */
    .type {
        background: #000;
        color: #fff;
        box-shadow: 0 6px 16px rgba(0,0,0,0.6);
        margin: 24px 16px 16px 16px !important;
        border: 1px solid rgba(255,255,255,0.1);
    }
    .type::before {
        background: linear-gradient(135deg, rgba(255,255,255,0.25) 0%, transparent 60%);
    }
    #menu-content > ul > li:first-child .type {
        margin-top: 18px !important;
    }

    .key {
        background: #1c1c1e;
        color: #f0f0f0;
        border-bottom-color: #333;
        margin: 0 16px;
    }
    .key:hover, .key:active {
        background: #2a2a2c !important;
    }
    .key[style*="opacity"] {
        color: #999;
        background: #181818;
    }
    .key:last-child {
        margin-bottom: 18px;
    }

    #pdf-canvas { filter: brightness(0.98); }
    #pdf-container {
        background: #000 !important;
    }
    #pdf-container::before {
        background: 
            radial-gradient(circle at 20% 80%, rgba(255,255,255,0.05) 0%, transparent 50%),
            radial-gradient(circle at 80% 20%, rgba(255,255,255,0.04) 0%, transparent 50%);
    }

    #nav-footer {
        background: linear-gradient(to bottom, #1c1c1e, #111113);
    }
    .nav-arrow {
        background: rgba(30,30,30,0.85);
        color: #0a84ff;
    }
    .nav-arrow:hover {
        background: rgba(40,40,40,0.95);
    }
}

/* ========================================
   9. RESPONSIVE TWEAKS
   ======================================== */
@media (max-width: 380px) {
    #nav-footer { gap: 70px; }
    .nav-arrow { width: 50px; height: 50px; }
    .nav-arrow::before { font-size: 26px; }
}