/* ============================================================
   CENTRAL BLOG STYLES (v4.0 - FINAL UI)
   ============================================================ */

/* ROOT VARIABLES */
:root {
    --bg-color: #1e1e1e;
    --hover-color: #2a2d2e;
    --border-color: #333;
    --text-color: #e0e0e0;
    --folder-color: #f1d592;
    --line-color: #444;
    --accent-color: cyan;
}

/* BANNER STYLE */
.fm-banner {
    display: block;
    margin: 0 auto 20px auto;
    border-radius: 12px;
    box-shadow: 0 10px 25px rgba(0,0,0,0.4);
    border: 1px solid var(--border-color);
    max-width: 100%;
}

.file-manager {
    font-family: 'Segoe UI', sans-serif;
    background: var(--bg-color);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    max-width: 800px;
    margin: 0 auto 40px auto;
    color: var(--text-color);
    box-shadow: 0 10px 30px rgba(0,0,0,0.5);
    overflow: hidden;
    user-select: none;
}

/* HEADER & PATH */
.fm-header {
    background: #252526;
    padding: 10px 15px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 0.9rem;
    flex-wrap: wrap; /* Added for tags */
}

.fm-left-controls {
    display: flex;
    align-items: center;
    flex: 1;
    gap: 15px;
    overflow: hidden;
}

.fm-traffic-lights { display: flex; gap: 8px; flex-shrink: 0; }
.light { width: 12px; height: 12px; border-radius: 50%; }
.red { background: #ff5f56; }
.yellow { background: #ffbd2e; }
.green { background: #27c93f; }

.fm-path {
    background: #181818;
    padding: 4px 10px;
    border-radius: 4px;
    border: 1px solid #333;
    color: #888;
    font-family: monospace;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
}

/* Adjustments when ZIP button is hidden */
.fm-header.no-zip-btn {
    padding-right: 15px;
}
.fm-header.no-zip-btn .fm-path {
    margin-right: 0;
    flex: 1;
}

/* BUTTONS & ICONS */
.zip-btn {
    background: var(--accent-color);
    color: black;
    border: none;
    padding: 5px 12px;
    border-radius: 4px;
    font-size: 0.85rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: all 0.2s ease;
    margin-left: 10px;
    white-space: nowrap;
    text-decoration: none;
    font-weight: 600;
}
.zip-btn:hover { opacity: 0.8; transform: translateY(-1px); }
.zip-btn:disabled { opacity: 0.5; cursor: not-allowed; background: #666; color: #ddd; }

.fm-body { padding: 10px; }
.fm-row {
    display: flex; align-items: center; padding: 8px 10px;
    border-radius: 4px; cursor: pointer; transition: background 0.1s;
    border-bottom: 1px solid rgba(255,255,255,0.02);
}
.fm-row:hover { background: var(--hover-color); }

.indent-1 { margin-left: 20px; border-left: 1px solid var(--line-color); }
.indent-2 { margin-left: 40px; border-left: 1px solid var(--line-color); }
.indent-3 { margin-left: 60px; border-left: 1px solid var(--line-color); }

.fm-icon { margin-right: 12px; width: 20px; text-align: center; font-size: 1.1rem; }
.folder-icon { color: var(--folder-color); }
.pdf-icon { color: #ff6b6b; } .audio-icon { color: #4facfe; }
.html-icon { color: #e44d26; } .zip-icon { color: #f093fb; }
.txt-icon { color: #b2bec3; } .video-icon { color: #9b59b6; }

.fm-name { flex: 1; font-size: 0.95rem; }
.fm-size { color: #666; font-size: 0.8rem; margin-left: 10px; }
.fm-status { color: #666; font-size: 1rem; width: 20px; text-align: right; }

.caret { margin-right: 8px; font-size: 0.7rem; transition: transform 0.2s; color: #888; }
.caret.open { transform: rotate(90deg); }
.folder-contents { display: none; animation: slideDown 0.2s ease-out; }
.folder-contents.show { display: block; }
@keyframes slideDown { from { opacity: 0; transform: translateY(-5px); } to { opacity: 1; transform: translateY(0); } }

/* Action Icons */
.fm-action-icon {
    margin-left: 10px;
    cursor: pointer;
    color: #888;
    transition: color 0.2s, transform 0.2s;
    padding: 5px;
}
.fm-action-icon:hover { color: var(--accent-color); transform: scale(1.1); }
.play-btn { color: #4facfe; }
.play-btn:hover { color: #fff; text-shadow: 0 0 8px #4facfe; }
.view-icon { margin-left: 8px; margin-right: 4px; cursor: pointer; color: #ff6b6b; transition: all 0.2s ease; font-size: 0.9rem; }
.view-icon:hover { color: #fff; text-shadow: 0 0 8px #ff3333; transform: scale(1.1); }

/* ============================================================
   FINAL UI CSS (v6.1 - Layout Stability Fix)
   ============================================================ */

/* 1. DESKTOP BASE STYLES */
#audio-player-bar.audio-bar {
    position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
    width: 95vw !important; max-width: 900px !important;
    background: rgba(15, 15, 15, 0.95); 
    backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
    border: 1px solid rgba(255, 255, 255, 0.1); border-top: 1px solid cyan;
    border-radius: 16px; display: flex; align-items: center; justify-content: space-between;
    gap: 15px; padding: 10px 20px;
    box-shadow: 0 20px 50px rgba(0,0,0,0.6); z-index: 2147483647;
    box-sizing: border-box; height: 90px;
    transition: bottom 0.5s cubic-bezier(0.2, 0.8, 0.2, 1);
}
#audio-player-bar.hidden { bottom: -150px; }

/* VISIBILITY HELPERS - THE FIX */
.mobile-only { display: none !important; }
.desktop-only { display: flex !important; }
button.desktop-only { display: flex !important; } /* Force buttons to show */

/* SECTIONS */
.audio-left-section {
    display: flex; align-items: center; gap: 15px;
    width: 260px; min-width: 260px; flex-shrink: 0; overflow: hidden;
}
.cyan-glow-icon { color: cyan; font-size: 1.4rem; flex-shrink: 0; }
#audio-title {
    font-size: 0.9rem; color: #fff; font-weight: 500;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: block;
}

/* CENTER CONTROLS */
.custom-audio-wrapper {
    flex: 1; display: flex; flex-direction: column;
    justify-content: center; gap: 6px; min-width: 300px; 
}
.custom-controls-row {
    display: grid; grid-template-columns: 1fr auto 1fr;
    align-items: center; width: 100%; 
}

/* Cells */
.speed-container { justify-self: start; position: relative; }
.speed-menu {
    display: none; position: absolute; bottom: 40px; left: 0;
    background: #1a1a1a; border: 1px solid #333; border-radius: 6px;
    padding: 5px 0; width: 80px; z-index: 10000;
}
.speed-menu.show { display: block; }
.speed-item { padding: 8px; font-size: 0.8rem; color: #fff; text-align: center; cursor: pointer; }
.speed-item:hover { background: #333; color: cyan; }
.speed-item.active { color: cyan; font-weight: bold; }

.main-transport { 
    justify-self: center; display: flex; align-items: center; gap: 15px; position: relative; 
}

#speed-btn {
    padding-left: 0;
    padding-right: 0;
}

#shuffle-btn { 
    position: absolute; right: 100%; margin-right: 20px; top: 50%; transform: translateY(-50%);
    background: transparent; border: none; color: #666; font-size: 1rem; cursor: pointer; padding: 5px;
}
#shuffle-btn:hover { color: cyan; }

.extras-wrapper { justify-self: end; width: 10px; }

/* Buttons & Sliders */
.control-btn {
    background: transparent; border: 1px solid rgba(255,255,255,0.1);
    color: #ccc; cursor: pointer; display: flex; align-items: center; justify-content: center;
}
.control-btn:hover { border-color: cyan; color: cyan; }
.control-btn.text-btn { width: 40px; height: 28px; border-radius: 4px; font-size: 0.8rem; font-weight: bold; color: #fff; }
.control-btn.small { width: 32px; height: 32px; border-radius: 8px; }
.control-btn.main-play {
    width: 42px; height: 42px; border-radius: 50%; border: 2px solid cyan; color: cyan;
}
.control-btn.main-play:hover { background: cyan; color: #000; }

.progress-container { display: flex; align-items: center; gap: 10px; width: 100%; }
.time-text { font-family: 'Segoe UI', sans-serif; font-size: 0.85rem; color: #ccc; font-variant-numeric: tabular-nums; letter-spacing: 0.5px; font-weight: 600; min-width: 45px; text-align: center; }
input[type=range] { -webkit-appearance: none; background: transparent; cursor: pointer; accent-color: cyan; }
#seek-slider { flex: 1; height: 4px; background: rgba(255,255,255,0.1); border-radius: 2px; }
#seek-slider::-webkit-slider-thumb { -webkit-appearance: none; width: 12px; height: 12px; background: cyan; border-radius: 50%; margin-top: -2px; box-shadow: 0 0 10px cyan; }

/* RIGHT SECTION */
.audio-right-section { 
    display: flex; align-items: center; justify-content: flex-end; gap: 15px;
    width: 260px; min-width: 260px; flex-shrink: 0;
}
.controls-stack { display: flex; flex-direction: column; align-items: flex-end; justify-content: center; gap: 4px; }
.volume-container { display: flex; align-items: center; gap: 8px; }
#volume-slider { width: 70px; height: 4px; background: rgba(255,255,255,0.1); border-radius: 2px; }
.autoplay-wrapper { display: flex; align-items: center; gap: 8px; margin-right: 2px; }
.auto-text { font-size: 0.7rem; font-weight: bold; color: #888; letter-spacing: 1px; }
.switch { position: relative; display: inline-block; width: 28px; height: 14px; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider { position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0; background-color: #333; transition: .4s; border-radius: 34px; border: 1px solid #555; }
.slider:before { position: absolute; content: ""; height: 8px; width: 8px; left: 2px; bottom: 2px; background-color: white; transition: .4s; border-radius: 50%; }
input:checked + .slider { background-color: rgba(0, 255, 255, 0.2); border-color: cyan; }
input:checked + .slider:before { transform: translateX(14px); background-color: cyan; }
.vertical-divider { width: 1px; height: 35px; background: rgba(255,255,255,0.1); margin: 0 5px; }

/* Close Buttons */
.close-audio { background: none; border: none; color: #666; font-size: 1.2rem; cursor: pointer; padding: 5px; }
.close-audio:hover { color: #ff5f56; }

/* ============================================================
   2. MOBILE OVERRIDES (Max Width 768px)
   ============================================================ */
@media screen and (max-width: 768px) {
    .desktop-only { display: none !important; }
    .mobile-only { display: flex !important; }

    /* LAYOUT RESET */
    #audio-player-bar.audio-bar {
        bottom: 0; width: 100% !important; left: 0 !important;
        height: auto; padding: 50px 20px 20px 20px;
        flex-direction: column; 
        border-radius: 16px 16px 0 0;
        border-left: none; border-right: none;
        gap: 20px;
        transition: transform 0.4s cubic-bezier(0.2, 0.8, 0.2, 1);
        transform: translateY(0);
    }

    #audio-player-bar.hidden { 
        bottom: 0; /* Keep anchored to bottom */
        transform: translateY(100%); /* Slide completely out of view */
        pointer-events: none; /* Prevent accidental clicks */
    }

    /* TITLE */
    .audio-left-section { position: absolute; top: 15px; left: 0; width: 100%; justify-content: center; padding: 0 60px; box-sizing: border-box; }
    #audio-title { font-size: 1rem; color: cyan; font-weight: bold; }

    /* MOBILE CLOSE BUTTON */
    .close-audio.mobile-only {
        position: absolute; top: 10px; right: 15px;
        z-index: 20; font-size: 1.4rem; padding: 10px;
    }

    /* CONTROLS ROW */
    .custom-controls-row {
        display: flex; justify-content: space-between; align-items: center;
        width: 100%; gap: 10px; margin-bottom: 10px;
    }
    .custom-audio-wrapper { min-width: 0; width: 100%; }
    .main-transport { gap: 20px; margin: 0 10px; }

    /* RESET SHUFFLE (Mobile) */
    #shuffle-btn { position: static; transform: none; margin: 0; }

    /* MOBILE BUTTONS */
    #mobile-auto-btn, #mobile-transcript-btn, #mobile-speed-btn {
        border: none; 
        color: #ccc; 
        font-size: 0.9rem;
        width: 34px; 
        height: 34px;
        border-radius: 10px;
        display: flex; 
        align-items: center; 
        justify-content: center;
        background: transparent;
        font-weight: 700; 
        padding: 0;
    }

    /* Add this RIGHT AFTER the mobile buttons block */
#mobile-speed-btn {
    width: 50px !important;  /* Wide enough for "1.75x" */
    min-width: 50px !important;
    white-space: nowrap;     /* Prevents text from breaking lines */
}

    /* MOBILE SPEED MENU POSITIONING */
#mobile-speed-menu {
    bottom: 100%; /* Sits directly on top of the button */
    left: 50%;
    transform: translateX(-50%); /* Centers it horizontally */
    margin-bottom: 10px; /* Adds a little gap */
    width: 70px; /* Slightly narrower than desktop for mobile screens */
    background: rgba(20, 20, 20, 0.95); /* Dark background */
    backdrop-filter: blur(10px);
}
}

/* ============================================================
   TRANSCRIPT UI (NEW)
   ============================================================ */
.transcript-overlay {
    position: fixed;
    bottom: 120px; /* Above the audio player */
    right: 20px;
    width: 350px;
    height: 500px;
    background: rgba(20, 20, 20, 0.95);
    backdrop-filter: blur(15px);
    -webkit-backdrop-filter: blur(15px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-top: 1px solid var(--accent-color);
    border-radius: 12px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.5);
    z-index: 2147483640;
    display: flex;
    flex-direction: column;
    transition: transform 0.3s ease, opacity 0.3s ease;
    transform-origin: bottom right;
}

.transcript-overlay.hidden {
    transform: scale(0.9);
    opacity: 0;
    pointer-events: none;
}

.transcript-header {
    padding: 12px 15px;
    background: rgba(255, 255, 255, 0.03);
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-weight: 600;
    font-size: 0.9rem;
    color: #fff;
}

.transcript-header button {
    background: none; border: none; color: #888; cursor: pointer; font-size: 1rem;
}
.transcript-header button:hover { color: #fff; }

.transcript-body {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    font-family: 'Segoe UI', sans-serif;
    font-size: 1.05rem;
    line-height: 1.6;
    color: #ccc;
    scroll-behavior: smooth;
}

/* WORD HIGHLIGHTING */
.t-word {
    padding: 2px 0;
    border-radius: 3px;
    transition: background 0.1s, color 0.1s;
    cursor: pointer;
}

.t-word:hover {
    color: #fff;
}

.t-word.active-word {
    background: rgba(0, 255, 255, 0.2);
    color: #00ffff;
    font-weight: bold;
    box-shadow: 0 0 10px rgba(0, 255, 255, 0.1);
}

.transcript-placeholder {
    text-align: center; color: #666; font-style: italic; margin-top: 50%;
}

/* MOBILE ADAPTATION */
@media (max-width: 768px) {
    /* FIX: Force the transcript container to stop ABOVE the player */
    #transcript-overlay {
        height: calc(100% - 140px) !important; /* Leaves 280px of space at the bottom */
        bottom: auto !important; /* Ensure it doesn't stretch */
        top: 0 !important;
    }

    /* Remove the previous padding attempt if it's there */
    .transcript-body {
        padding-bottom: 20px !important; 
    }
}

/* =========================================
   TITLE SCROLLING ANIMATION
   ========================================= */

.track-info {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    position: relative;
    text-align: center;
    font-family: 'Segoe UI', sans-serif;
}

#audio-title {
    display: inline-block;
    white-space: nowrap;
    font-size: 0.9rem;
    color: #fff;
    font-weight: 500;
}

#audio-title.scroll-me {
    animation: scroll-text 8s linear infinite;
}

@keyframes scroll-text {
    0% { transform: translateX(0); }
    100% { transform: translateX(-50%); }
}

/* ============================================================
   CATEGORY TAGS & RELATED MATERIALS
   ============================================================ */
.category-tags-container {
    flex-basis: 100%;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid var(--border-color);
}
.category-tag-btn {
    background: #333;
    color: #ccc;
    border: 1px solid #444;
    padding: 4px 12px;
    border-radius: 12px;
    font-size: 0.8rem;
    cursor: pointer;
    transition: all 0.2s ease;
}
.category-tag-btn:hover {
    border-color: var(--accent-color);
    color: var(--accent-color);
}
.category-tag-btn.active {
    background: rgba(0, 255, 255, 0.1);
    color: var(--accent-color);
    border-color: var(--accent-color);
    font-weight: bold;
}

.related-materials-section {
    max-width: 800px;
    margin: 0 auto 40px auto;
    background: var(--bg-color);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 20px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.5);
}
.related-section-title {
    color: var(--text-color);
    font-size: 1.2rem;
    margin-bottom: 15px;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 10px;
}
.related-materials-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 15px;
}
.related-material-card {
    display: block;
    text-decoration: none;
    background: #252526;
    border-radius: 6px;
    overflow: hidden;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    border: 1px solid transparent;
    position: relative; /* Needed for spinner positioning */
}
.related-material-card.loading::after {
    content: "";
    position: absolute;
    top: 50%; left: 50%;
    width: 30px; height: 30px;
    margin: -15px 0 0 -15px;
    border: 3px solid rgba(0, 255, 255, 0.2);
    border-top-color: var(--accent-color);
    border-radius: 50%;
    animation: related-spin 1s linear infinite;
    z-index: 2;
}
@keyframes related-spin { to { transform: rotate(360deg); } }
.related-material-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 5px 15px rgba(0,0,0,0.4);
    border: 1px solid var(--accent-color);
}
.related-material-card img {
    width: 100%;
    aspect-ratio: 2 / 3; /* Forces a consistent book-cover shape */
    object-fit: cover; /* Fills the area completely without empty space */
    display: block;
}
.related-material-title {
    padding: 8px;
    font-size: 0.85rem;
    color: var(--text-color);
    text-align: center;
    word-wrap: break-word; /* Allows full name to display */
    white-space: normal;
}
.related-expand-btn {
    grid-column: 1 / -1; /* Spans full width of grid */
    background: #333;
    color: var(--accent-color);
    border: 1px solid #444;
    padding: 10px;
    border-radius: 6px;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.2s ease;
    margin-top: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}
.related-expand-btn:hover {
    background: rgba(0, 255, 255, 0.1);
    border-color: var(--accent-color);
}
