/* ============================================
   MENU TOGGLE BUTTON
   ============================================ */
#menu-toggle {
    position: absolute;
    top: 15px;
    left: 50%;
    transform: translateX(-50%);
    width: 40px;
    height: 40px;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid #444;
    border-radius: 50%;
    cursor: pointer;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.3s, transform 0.3s;
    font-size: 20px;
    color: #aaa;
}

#menu-toggle:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: translateX(-50%) scale(1.1);
}

#menu-toggle.active {
    background: rgba(0, 170, 255, 0.2);
    border-color: #0af;
    color: #0af;
}

/* ============================================
   DRAG AREA (Top 20px for mobile gesture)
   ============================================ */
#drag-area {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 20px;
    z-index: 99;
    cursor: ns-resize;
}

/* ============================================
   TOOLBAR CONTAINER
   ============================================ */
#toolbar {
    position: absolute;
    top: 65px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 10px;
    z-index: 100;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease, transform 0.3s ease;
    background: rgba(0, 0, 0, 0.8);
    padding: 10px 16px;
    border-radius: 25px;
    backdrop-filter: blur(8px);
    border: 1px solid #333;
    box-shadow: 0 4px 15px rgba(0,0,0,0.5);
}

#toolbar.visible {
    opacity: 1;
    visibility: visible;
    transform: translateX(-50%) translateY(0);
}

/* ============================================
   TOOL BUTTONS
   ============================================ */
.tool-btn {
    /* background: transparent; */
    border: 1px solid #555;
    color: #ccc;
    padding: 8px 14px;
    cursor: pointer;
    border-radius: 20px;
    font-size: 14px;
    transition: all 0.3s;
    font-family: 'Courier New', Courier, monospace;
    white-space: nowrap;
}

.tool-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: #888;
    color: #fff;
}

.tool-btn.active {
    background: #0af;
    color: #000;
    border-color: #0af;
    font-weight: bold;
}

/* ============================================
   NAVIGATION MODAL
   ============================================ */
#nav-modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    z-index: 9999;
    justify-content: center;
    align-items: center;
    backdrop-filter: blur(5px);
}

.nav-content {
    background: #111;
    padding: 20px;
    border-radius: 8px;
    border: 1px solid #444;
    max-width: 400px;
    width: 90%;
    max-height: 80vh;
    /* overflow-y: auto;
    position: relative;
    box-shadow: 0 10px 30px rgba(0,0,0,0.8);
    display: flex;
    flex-direction: column; */
    /* Flexbox to separate header from scrollable list */
    display: flex;
    flex-direction: column;
    position: relative;
    box-shadow: 0 10px 30px rgba(0,0,0,0.8);
}

.nav-content h3 {
    text-align: center;
    color: var(--text-primary);
    /* margin-top: 0;
    border-bottom: 1px solid var(--border);
    padding-bottom: 10px;
    position: sticky;
    top: 0;
    background: var(--bg-secondary);
    z-index: 10; */
    margin: 0 0 10px 0; /* Remove top margin to eliminate gap */
    padding-bottom: 10px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0; /* Prevent shrinking */
    position: relative; /* Ensure it stays in flow */
    z-index: 10;
}

.nav-item {
    padding: 12px 15px;
    border-bottom: 1px solid #333;
    cursor: pointer;
    display: flex;
    align-items: center;
    transition: background 0.2s;
    color: var(--text-primary);
}

.nav-item:hover {
    background: var(--bg-tertiary);
}

.nav-item.bookmarked {
    color: #0af;
    font-weight: bold;
}

.nav-item.current-page {
    background: rgba(0, 170, 255, 0.15);
    border-left: 4px solid var(--accent);
    font-weight: bold;
}

.close-nav {
    position: absolute;
    top: 10px;
    right: 15px;
    cursor: pointer;
    font-size: 24px;
    color: #888;
    line-height: 1;
    /* z-index: 10; */
    z-index: 20; /* Above the header text */
    transition: color 0.2s;
}

.close-nav:hover {
    color: #fff;
}


/* The list takes up remaining space and scrolls */
#nav-list {
    flex-grow: 1;
    overflow-y: auto;
    overflow-x: hidden;
    margin-top: 0; /* Remove any top margin that caused the gap */
    padding-top: 0;
}

/* Custom scrollbar for the list */
#nav-list::-webkit-scrollbar {
    width: 8px;
}

#nav-list::-webkit-scrollbar-track {
    background: #111;
}

#nav-list::-webkit-scrollbar-thumb {
    background: #444;
    border-radius: 4px;
}

#nav-list::-webkit-scrollbar-thumb:hover {
    background: #666;
}

/* Custom scrollbar for modal */
.nav-content::-webkit-scrollbar {
    width: 8px;
}

.nav-content::-webkit-scrollbar-track {
    background: #111;
}

.nav-content::-webkit-scrollbar-thumb {
    background: #444;
    border-radius: 4px;
}

.nav-content::-webkit-scrollbar-thumb:hover {
    background: #666;
}

/* ============================================
   TTS CONTROLS
   ============================================ */
#tts-controls {
    display: none;
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.9);
    padding: 12px 16px;
    border-radius: 30px;
    border: 1px solid #555;
    backdrop-filter: blur(10px);
    z-index: 2147483647;
    gap: 12px;
    align-items: center;
    box-shadow: 0 8px 25px rgba(0,0,0,0.6);
    white-space: nowrap;
    max-width: 95%;
}

#tts-controls.active {
    display: flex;
    animation: slideUp 0.3s ease-out;
}

@keyframes slideUp {
    from { transform: translateX(-50%) translateY(20px); opacity: 0; }
    to { transform: translateX(-50%) translateY(0); opacity: 1; }
}

.tts-btn {
    background: transparent;
    border: 1px solid #555;
    color: #ccc;
    padding: 6px 12px;
    border-radius: 20px;
    cursor: pointer;
    font-size: 14px;
    transition: all 0.3s;
}

.tts-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
}

.tts-btn.playing {
    background: #0af;
    color: #000;
    border-color: #0af;
    font-weight: bold;
}

/* Speed Controls Wrapper */
#speed-controls-wrapper {
    display: flex;
    flex-direction: column;
    align-items: center;
    min-width: 50px;
    justify-content: center;
}

#speed-label {
    font-size: 12px;
    color: #aaa;
    margin-bottom: 2px;
}

#speed-display {
    font-size: 11px;
    color: #0af;
    font-weight: bold;
    margin-bottom: 4px;
}

/* Speed Range Slider - Robust Reset */
#speed-range {
    -webkit-appearance: none;
    appearance: none;
    width: 80px;
    height: 6px;
    background: #444;
    border-radius: 3px;
    outline: none;
    padding: 0;
    margin: 0;
    flex-shrink: 0;
}

/* Track styles for Webkit (Chrome, Safari, Edge) */
#speed-range::-webkit-slider-runnable-track {
    width: 100%;
    height: 6px;
    background: #444;
    border-radius: 3px;
}

/* Thumb styles for Webkit */
#speed-range::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 14px;
    height: 14px;
    background: #0af;
    border-radius: 50%;
    cursor: pointer;
    margin-top: -4px;
}

/* Track styles for Firefox */
#speed-range::-moz-range-track {
    width: 100%;
    height: 6px;
    background: #444;
    border-radius: 3px;
}

/* Thumb styles for Firefox */
#speed-range::-moz-range-thumb {
    width: 14px;
    height: 14px;
    background: #0af;
    border-radius: 50%;
    cursor: pointer;
    border: none;
}

#voice-select {
    background: #222;
    color: #ddd;
    border: 1px solid #444;
    border-radius: 15px;
    padding: 4px 8px;
    font-size: 12px;
    max-width: 150px;
}

/* ============================================
   THEME-SPECIFIC SPEED CONTROL COLORS
   ============================================ */
body.light-mode #speed-label {
    color: #333;
}

body.light-mode #speed-display {
    color: #0066cc;
}

body.light-mode #speed-range {
    background: #ccc;
}

body.light-mode #speed-range::-webkit-slider-thumb {
    background: #0066cc;
}

body.light-mode #speed-range::-moz-range-thumb {
    background: #0066cc;
}

body.sepia-mode #speed-label {
    color: #5b4636;
}

body.sepia-mode #speed-display {
    color: #a0522d;
}

body.sepia-mode #speed-range {
    background: #c9b896;
}

body.sepia-mode #speed-range::-webkit-slider-thumb {
    background: #a0522d;
}

body.sepia-mode #speed-range::-moz-range-thumb {
    background: #a0522d;
}

/* ============================================
   BOOKMARK RIBBONS
   ============================================ */
.bookmark-ribbon {
    position: absolute;
    top: 0;
    right: 72px;
    width: 32px;
    height: 48px;
    z-index: 50;
    cursor: pointer;
    background-image: url("../images/bookmark.png");
    background-size: contain;
    background-repeat: no-repeat;
}

.nav-item .bookmark-ribbon {
    position: relative;
    top: -3px;
    right: -27px;
    width: 24px;
    height: 32px;
    z-index: 50;
    cursor: pointer;
    background-image: url("../images/bookmark.png");
    background-size: 24px 32px;
}

.bookmark-ribbon:hover {
    background-image: url("../images/remove-bookmark.png");
}

/* ============================================
   POINTER EVENTS FOR TOOLBAR
   ============================================ */
#toolbar {
    pointer-events: none;
}

#toolbar.active,
#toolbar.visible {
    pointer-events: auto;
}

/* Hide empty voice dropdown */
#voice-select:empty {
    display: none !important;
}

#voice-select option:first-child:only-child {
    display: none;
}

/* Force modal visibility when class added */
#nav-modal.show {
    display: flex !important;
}

/* ============================================
   MOBILE ADJUSTMENTS
   ============================================ */
@media (max-width: 600px) {
    #tts-controls {
        bottom: 15px;
        padding: 10px 14px;
        width: auto;
        max-width: 90%;
        flex-wrap: wrap;
        justify-content: center;
    }

    /* Stack speed controls vertically on mobile */
    #speed-controls-wrapper {
        min-width: 50px;
    }

    #speed-range {
        width: 70px;
    }

    #speed-label {
        font-size: 11px;
    }

    .tts-btn {
        padding: 8px 12px;
        font-size: 13px;
    }

    #voice-select {
        max-width: 110px;
        font-size: 12px;
        padding: 4px;
    }

    #speed-display {
        font-size: 10px;
    }

    .bookmark-ribbon {
        position: absolute;
        top: 0;
        right: 22px;
        width: 24px;
        height: 32px;
        z-index: 50;
        cursor: pointer;
        background-image: url("../images/bookmark.png");
        background-size: 24px 32px;
    }

    .bookmark-ribbon:hover {
        background-image: url("../images/remove-bookmark.png");
    }

    .nav-item .bookmark-ribbon {
        top: -15px;
        right: -27px;
        width: 12px;
        height: 16px;
        background-image: url("../images/bookmark.png");
        background-size: 12px 16px;
    }

    small {
        font-size: 3.5vw;
    }
}