/* ============================================
   MATERIAL VIEWER STYLES
   Supports: TXT, Images, Audio
   ============================================ */

/* ---------- OVERLAY ---------- */
.material-viewer-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: 10000;
    background: var(--bg-primary);
    opacity: 0;
    visibility: hidden;
    transform: scale(0.95);
    transition: opacity 0.3s ease, transform 0.3s ease, visibility 0.3s ease;
    overflow: hidden;
    will-change: transform, opacity;
}

.material-viewer-overlay.active {
    opacity: 1;
    visibility: visible;
    transform: scale(1);
}



/* Content wrapper */
.material-viewer-content {
    position: relative;
    z-index: 1;
    height: 100%;
    display: flex;
    flex-direction: column;
    background: linear-gradient(to bottom,
            transparent 0%,
            var(--bg-primary) 30%,
            var(--bg-primary) 100%);
}

/* ---------- TOP BAR ---------- */
.material-viewer-top-bar {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: calc(var(--safe-top) + 8px) 16px 8px 16px;
    flex-shrink: 0;
    z-index: 2;
}

.material-viewer-back-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: transparent;
    border: none;
    cursor: pointer;
    transition: background-color var(--transition-fast);
    flex-shrink: 0;
}

.material-viewer-back-btn:hover {
    background-color: var(--bg-hover);
}

.material-viewer-back-btn .material-icons-round {
    font-size: 2rem;    color: var(--text-primary);
    pointer-events: none;
}

.material-viewer-title {
    flex: 1;
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.material-viewer-download-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: .4rem;
    background: transparent;
    cursor: pointer;
    color: var(--text-secondary);
    transition: all var(--transition-fast);
    flex-shrink: 0;
}

.material-viewer-download-btn .material-icons-round {
    font-size: 1.75rem;    pointer-events: none;
}

/* ---------- VIEWER AREA ---------- */
.material-viewer-area {
    flex: 1;
    overflow: hidden;
    position: relative;
    min-height: 0;
}

/* ---------- IMAGE VIEWER ---------- */
.material-viewer-image {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: auto;
    padding: 16px;
}

.material-image-display {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
}

/* ---------- TXT VIEWER ---------- */
.material-viewer-txt {
    width: 100%;
    height: 100%;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 24px;
}

@media (min-width: 900px) {
    .material-viewer-txt * {
        font-size: 3.75rem;
    }
}

.material-viewer-txt * {
    font-size: 1.25rem;
}

@media (min-width: 900px) {
    .material-viewer-txt * {
        font-size: 1.55rem;
    }
}

.material-txt-content {
    margin: 0 auto;
    color: var(--text-primary);
    line-height: 1.7;
    font-size: 0.95rem;
    max-width: 900px;
}

/* TXT formatting styles */
.material-txt-content h1 {
    font-size: 1.8rem;
    font-weight: 700;
    margin-bottom: 16px;
    color: var(--text-primary);
    text-align: center;
    margin-top: 2rem;
}

.material-txt-content h2 {
    font-size: 1.4rem;
    font-weight: 700;
    margin-bottom: 12px;
    color: var(--text-primary);
    border-bottom: 2px solid var(--divider-color);
    padding-bottom: 8px;
    margin-top: 2.5rem;
}

.material-txt-content h3 {
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 8px;
    color: var(--text-primary);
    margin-top: 2.5rem;
}

.material-txt-content p {
    margin-bottom: 16px;
    color: var(--text-primary);
}

.material-txt-content strong {
    color: var(--text-primary);
    font-weight: 700;
}

.material-txt-content em {
    font-style: italic;
    color: var(--accent-color);
}

.material-txt-content ul,
.material-txt-content ol {
    margin-bottom: 16px;
    padding-left: 24px;
}

.material-txt-content li {
    margin-bottom: 6px;
    color: var(--text-primary);
}

.material-txt-content hr {
    border: none;
    border-top: 2px solid var(--divider-color);
    margin: 24px 0;
}

.material-txt-content blockquote {
    border-left: 4px solid var(--accent-color);
    padding-left: 16px;
    margin: 16px 0;
    font-style: italic;
    color: var(--text-secondary);
}

.material-txt-content img {
    max-width: 100%;
    height: auto;
    border-radius: 8px;
    margin: 16px 0;
    display: block;
}

/* ---------- AUDIO VIEWER ---------- */
.material-viewer-audio {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    padding: 24px;
    text-align: center;
}

.material-audio-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100px;
    height: 100px;
    border-radius: .4rem;
    background: var(--accent-light);
    margin-bottom: 8px;
}

.material-audio-icon .material-icons-round {
    font-size: 3.5rem;    color: var(--accent-color);
}

.material-audio-title {
    font-size: 1.8rem;
    font-weight: 700;
    color: var(--text-primary);
    margin: 0;
}

@media (max-width: 710px) {
    .material-audio-title {
    font-size: 1.2rem;
}
}

.material-audio-subtitle {
    font-size: 1.1rem;
    color: var(--text-tertiary);
}

.material-audio-player {
    width: 100%;
    max-width: 400px;
    margin-top: 8px;
}

.material-audio-player::-webkit-media-controls-panel {
    background: var(--bg-elevated);
}

.material-audio-player::-webkit-media-controls-play-button {
    background: var(--accent-color);
    border-radius: 50%;
}

/* ---------- LOADING ---------- */
.material-viewer-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    padding: 48px;
    color: var(--text-secondary);
}

.material-viewer-loading .material-icons-round {
    font-size: 3.5rem;    color: var(--accent-color);
    animation: pulse 1.5s ease infinite;
}

/* ---------- ERROR ---------- */
.material-viewer-error {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    padding: 48px;
    color: var(--text-secondary);
    text-align: center;
}

.material-viewer-error .material-icons-round {
    font-size: 3.5rem;    color: #f44336;
}

/* ---------- BOTTOM INFO BAR ---------- */
.material-viewer-info-bar {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    border-top: 1px solid var(--divider-color);
    flex-shrink: 0;
    background: var(--bg-primary);
}

.material-viewer-info-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    min-width: 40px;
    border-radius: 8px;
    background: var(--bg-elevated);
}

.material-viewer-info-icon .material-icons-round {
    font-size: 1.875rem;    color: var(--text-secondary);
}

.material-viewer-info-text {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.material-viewer-info-title {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.material-viewer-info-meta {
    font-size: 0.7rem;
    color: var(--text-tertiary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.material-viewer-download-large-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 10px 16px;
    background: var(--accent-color);
    border: none;
    border-radius: 20px;
    cursor: pointer;
    color: #ffffff;
    font-size: 0.8rem;
    font-weight: 600;
    font-family: 'Poppins', sans-serif;
    transition: all var(--transition-fast);
    flex-shrink: 0;
}

.material-viewer-download-large-btn:hover {
    background: var(--accent-hover);
    transform: scale(1.03);
}

.material-viewer-download-large-btn .material-icons-round {
    font-size: 1.625rem;    pointer-events: none;
}

/* ---------- DESKTOP ---------- */
@media (min-width: 711px) {
    .material-viewer-area {
        margin: 0 auto;
        width: 100%;
    }

    .material-viewer-info-bar {
        max-width: 900px;
        margin: 0 auto;
        width: 100%;
        border-left: 1px solid var(--divider-color);
        border-right: 1px solid var(--divider-color);
    }

    .material-viewer-top-bar {
        margin: 0 auto;
        width: 100%;
    }
}

/* ---------- MOBILE ---------- */
@media (max-width: 710px) {
    .material-viewer-txt {
        padding: 16px;
    }

    .material-txt-content h1 {
        font-size: 1.4rem;
    }

    .material-txt-content h2 {
        font-size: 1.15rem;
    }

    .material-audio-icon {
        width: 72px;
        height: 72px;
    }

    .material-audio-icon .material-icons-round {
        font-size: 2.75rem;    }

    .material-viewer-info-bar {
        padding: 10px 12px;
        padding-bottom: var(--safe-bottom);
    }
}

/* ---------- TOAST ---------- */
.material-toast {
    position: fixed;
    bottom: 32px;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 24px;
    background: #4caf50;
    color: #ffffff;
    border-radius: 24px;
    font-family: 'Poppins', sans-serif;
    font-size: 0.85rem;
    font-weight: 600;
    z-index: 10005;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
    opacity: 0;
    transition: opacity 0.3s ease, transform 0.3s ease;
    pointer-events: none;
}

.material-toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

.material-toast .material-icons-round {
    font-size: 1.625rem;}

/* ---------- CUSTOM AUDIO PLAYER ---------- */
.material-custom-audio-player {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    max-width: 400px;
    padding: 12px 16px;
    background: var(--bg-elevated);
    border: 1px solid var(--border-color);
    border-radius: 24px;
    margin-top: 8px;
}

.material-audio-play-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    min-width: 44px;
    border-radius: 50%;
    background: var(--accent-color);
    border: none;
    cursor: pointer;
    color: #ffffff;
    transition: all var(--transition-fast);
}

.material-audio-play-btn:hover {
    background: var(--accent-hover);
    transform: scale(1.05);
}

.material-audio-play-btn:active {
    transform: scale(0.95);
}

.material-audio-play-btn .material-icons-round {
    font-size: 2rem;    pointer-events: none;
}

.material-audio-progress {
    flex: 1;
    height: 6px;
    background: var(--bg-hover);
    border-radius: 3px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
}

.material-audio-progress-fill {
    height: 100%;
    background: var(--accent-color);
    border-radius: 3px;
    width: 0%;
    transition: width 0.1s linear;
}

.material-audio-time {
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--text-secondary);
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.material-audio-volume-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    min-width: 36px;
    border-radius: 50%;
    background: transparent;
    border: none;
    cursor: pointer;
    color: var(--text-secondary);
    transition: all var(--transition-fast);
}

.material-audio-volume-btn:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.material-audio-volume-btn .material-icons-round {
    font-size: 1.75rem;    pointer-events: none;
}

/* Mobile */
@media (max-width: 710px) {
    .material-custom-audio-player {
        gap: 8px;
        padding: 10px 12px;
        max-width: 100%;
    }

    .material-audio-play-btn {
        width: 38px;
        height: 38px;
        min-width: 38px;
    }

    .material-audio-play-btn .material-icons-round {
        font-size: 1.75rem;    }

    .material-audio-time {
        font-size: 0.65rem;
    }
}


/* ============================================================
   SPOTIFY-AUDIO — synchronized lyrics player for audio materials.
   Appended after existing audio classes; nothing removed. Old
   classes remain in the file for backwards safety.
   ============================================================ */

#materialAudioViewer {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    justify-content: flex-start;
    padding: 0;
    gap: 0;
    text-align: left;
    height: 100%;
    width: 100%;
    overflow: hidden;
}

.ma-header {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 20px 24px 12px;
    text-align: center;
    flex-shrink: 0;
}

.ma-artwork {
    width: 128px;
    height: 128px;
    border-radius: 20px;
    background: var(--accent-light);
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 6px;
    box-shadow: 0 8px 32px rgba(244, 67, 54, 0.15);
}

.ma-artwork .material-icons-round {
    font-size: 3.5rem;
    color: var(--accent-color);
}

.ma-title {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text-primary);
    margin: 0;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.ma-subtitle {
    font-size: 0.85rem;
    color: var(--text-tertiary);
    margin: 0;
}

.ma-transcript {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    -ms-overflow-style: none;
    mask-image: linear-gradient(to bottom, transparent 0%, black 12%, black 88%, transparent 100%);
    -webkit-mask-image: linear-gradient(to bottom, transparent 0%, black 12%, black 88%, transparent 100%);
}

.ma-transcript::-webkit-scrollbar { display: none; }

.ma-transcript-inner {
    padding: 32px 20px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    align-items: stretch;
}

.ma-transcript-empty {
    padding: 40px 20px;
    text-align: center;
    color: var(--text-tertiary);
    font-size: 0.9rem;
    font-style: italic;
    line-height: 1.5;
}

.ma-transcript-line {
    font-size: 2.3rem;
    line-height: 1.5;
    color: var(--text-tertiary);
    padding: 8px 12px;
    border-radius: 8px;
    text-align: center;
    cursor: pointer;
    transition: color 0.2s ease, background-color 0.2s ease, transform 0.2s ease, opacity 0.2s ease;
    opacity: 0.45;
    user-select: none;
    -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent;
}

.ma-transcript-line:hover {
    opacity: 0.7;
    color: var(--text-secondary);
}

.ma-transcript-line.nearby {
    opacity: 0.7;
    color: var(--text-secondary);
}

.ma-transcript-line.active {
    color: var(--text-primary);
    font-size: 2.3rem;
    opacity: 1;
    transform: scale(1.02);
}

.ma-controls {
    flex-shrink: 0;
    padding: 10px 20px calc(14px + var(--safe-bottom));
    background: var(--bg-primary);
    border-top: 1px solid var(--divider-color);
}

.ma-progress {
    width: 100%;
    height: 5px;
    background: var(--bg-hover);
    border-radius: 3px;
    cursor: pointer;
    position: relative;
    margin-bottom: 10px;
    touch-action: none;
}

.ma-progress::before {
    content: '';
    position: absolute;
    top: -8px; bottom: -8px; left: 0; right: 0;
}

.ma-progress-fill {
    height: 100%;
    background: var(--accent-color);
    border-radius: 3px;
    width: 0%;
    transition: width 0.1s linear;
    position: relative;
}

.ma-progress-fill::after {
    content: '';
    position: absolute;
    right: -5px;
    top: 50%;
    transform: translateY(-50%);
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--accent-color);
    box-shadow: 0 0 8px rgba(244, 67, 54, 0.6);
    opacity: 0;
    transition: opacity 0.15s ease;
}

.ma-progress:hover .ma-progress-fill::after,
.ma-progress:active .ma-progress-fill::after {
    opacity: 1;
}

.ma-controls-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.ma-time {
    font-size: 1rem;
    font-weight: 500;
    color: var(--text-secondary);
    font-variant-numeric: tabular-nums;
    min-width: 42px;
    text-align: center;
}

.ma-controls-buttons {
    display: flex;
    align-items: center;
    gap: 14px;
    flex: 1;
    justify-content: center;
}

.ma-play-btn {
    width: 52px;
    height: 52px;
    border-radius: 50%;
    background: var(--accent-color);
    color: #fff;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.15s ease, background-color 0.15s ease;
}

.ma-play-btn:hover  { background: var(--accent-hover);}

.ma-play-btn .material-icons-round {
    font-size: 2rem;
    pointer-events: none;
}

.ma-skip-btn {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: transparent;
    color: var(--text-secondary);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.15s ease, background-color 0.15s ease;
}

.ma-skip-btn:hover {
    color: var(--text-primary);
    background: var(--bg-hover);
}

.ma-skip-btn .material-icons-round {
    font-size: 2.1rem;
    pointer-events: none;
}

@media (max-width: 710px) {
    .ma-artwork {
        width: 96px;
        height: 96px;
        border-radius: 14px;
    }
    .ma-artwork .material-icons-round { font-size: 2.75rem; }
    .ma-header { padding: 12px 16px 8px; gap: 4px; }
    .ma-title { font-size: 1.1rem; }
    .ma-subtitle { font-size: 0.78rem; }
    .ma-transcript-line { font-size: 1.6rem; padding: 6px 10px; }
    .ma-transcript-line.active { font-size: 1.6rem; }
    .ma-controls { padding: 8px 16px calc(12px + var(--safe-bottom)); }
    .ma-play-btn { width: 52px; height: 52px; }
    .ma-play-btn .material-icons-round { font-size: 1.8rem; }
    .ma-skip-btn .material-icons-round { font-size: 2rem; }
    .ma-skip-btn { width: 50px; height: 50px; }
}


/* ============================================================
   SPOTIFY-AUDIO-BACKDROP — blurred album art behind the player.
   Thumbnail is set as background-image from JS. Hidden until
   a thumbnail is available.
   ============================================================ */
#materialAudioViewer {
    position: relative;
}

.ma-backdrop {
    position: absolute;
    inset: 0;
    background-size: cover;
    background-position: center;
    filter: blur(40px) saturate(1.5) brightness(0.55);
    opacity: 0.55;
    z-index: 0;
    pointer-events: none;
}

.ma-backdrop.hidden {
    display: none;
}

.ma-header, .ma-transcript, .ma-controls {
    position: relative;
    z-index: 1;
}

.ma-artwork {
    overflow: hidden;
    position: relative;
}

.ma-artwork-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.ma-artwork-icon {
    /* Icon shows when no thumbnail; hidden by JS when img is set */
}


/* ============================================================
   AUDIO-LIGHT-THEME — when the system is in light theme:
     1. Hide the blurred album-art backdrop. In dark theme the
        backdrop adds ambiance behind the lyrics; on white it just
        looks like a muddy dark smear with no purpose.
     2. Slightly darken the inactive transcript lines. Their
        defaults (tertiary text at 0.45 opacity on white) are too
        faint to read comfortably on a phone at arm's length.
   Dark theme behavior is unchanged.
   ============================================================ */
@media (prefers-color-scheme: light) {
    .ma-backdrop {
        display: none;
    }

    /* Inactive lines — noticeably darker but still clearly secondary */
    .ma-transcript-line {
        color: var(--text-secondary);
        opacity: 0.7;
    }

    /* Nearest neighbours — darker still, almost full-strength */
    .ma-transcript-line.nearby {
        color: var(--text-secondary);
        opacity: 0.9;
    }

    /* Active line stays at full primary — no change */
    .ma-transcript-line.active {
        color: var(--text-primary);
        opacity: 1;
    }
}