/* =====================================================
   Cinematic Player V3 — Optimized CSS
   ===================================================== */

:root {
    --md-player-primary: var(--md-player-timeline, #e50914);
    --md-player-primary-rgb: var(--md-player-timeline-rgb, 229, 9, 20);
    --md-player-text: var(--md-player-icon, #ffffff);
    --md-player-font: 'Inter', system-ui, -apple-system, sans-serif;
    /* HUD gradient — injected from admin settings */
    --md-hud-start-rgb: var(--md-hud-gs-rgb, 0, 0, 0);
    --md-hud-end-rgb: var(--md-hud-ge-rgb, 0, 0, 0);
}

/* === Container === */
#md-player-container {
    position: relative;
    width: 100%;
    aspect-ratio: 16 / 9;
    background: #000;
    overflow: hidden;
    font-family: var(--md-player-font);
    color: #fff;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    z-index: 10;
}

/* === JW Engine === */
#md-jw-engine { position: absolute; inset: 0; width: 100% !important; height: 100% !important; z-index: 1; }

/* === Overlay — BUG FIX: must cover JW engine === */
#md-player-overlay {
    position: absolute;
    inset: 0;
    z-index: 5;
    cursor: pointer;
}

/* Remove all corner accents */
#md-player-container::before, #md-player-container::after,
#md-player-overlay::before, #md-player-overlay::after { display: none; }

/* === Theater Mode === */
#md-theater-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.92);
    z-index: 999998;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.4s ease, visibility 0.4s ease;
    pointer-events: auto;
}
body.md-theater-active #md-theater-overlay { opacity: 1; visibility: visible; }
body.md-theater-active #md-player-container { z-index: 999999; position: relative; }
body.md-theater-active #box-player,
body.md-theater-active .video-box,
body.md-theater-active .player-wrapper { z-index: 999999 !important; position: relative !important; }
body.md-theater-active header,
body.md-theater-active .header,
body.md-theater-active #header,
body.md-theater-active .navbar,
body.md-theater-active .top-nav,
body.md-theater-active .breadcrumb,
body.md-theater-active .footer,
body.md-theater-active footer { display: none !important; }

/* === Top Info Bar === */
#md-top-bar {
    position: absolute;
    top: 0; left: 0;
    width: 100%;
    padding: 20px 24px 50px;
    box-sizing: border-box;
    background: linear-gradient(to bottom, rgba(var(--md-hud-start-rgb),0.85) 0%, rgba(var(--md-hud-end-rgb),0.4) 60%, transparent 100%);
    z-index: 20;
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    opacity: 0;
    transform: translateY(-8px);
    transition: opacity 0.3s ease, transform 0.3s ease;
    pointer-events: none;
    will-change: opacity, transform;
}
#md-player-container.hud-visible #md-top-bar { opacity: 1; transform: translateY(0); }

.md-top-info { display: flex; align-items: center; gap: 8px; flex: 1; min-width: 0; margin-right: 12px; }
.md-top-title { font-size: 13px; font-weight: 700; color: rgba(255,255,255,0.92); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 60%; text-shadow: 0 1px 6px rgba(0,0,0,0.8); }
.md-top-sep { color: rgba(255,255,255,0.35); font-size: 13px; flex-shrink: 0; }
.md-top-episode { font-size: 12px; font-weight: 500; color: rgba(255,255,255,0.6); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 200px; }
.md-top-badge { display: none; }

/* === HUD (Bottom Controls) === */
#md-cinematic-hud {
    position: absolute;
    bottom: 0; left: 0;
    width: 100%;
    padding: 20px 24px;
    box-sizing: border-box;
    background: linear-gradient(to top, rgba(var(--md-hud-start-rgb),0.95) 0%, rgba(var(--md-hud-end-rgb),0.55) 55%, transparent 100%);
    z-index: 20;
    opacity: 0;
    transform: translateY(10px);
    transition: opacity 0.3s ease, transform 0.3s ease;
    pointer-events: none;
    will-change: opacity, transform;
}
#md-cinematic-hud.visible { opacity: 1; transform: translateY(0); pointer-events: auto; }

/* === Timeline === */
.md-timeline-container {
    position: relative;
    height: 20px;
    margin-bottom: 10px;
    cursor: pointer;
    display: flex;
    align-items: center;
}
/* Timeline tooltip */
.md-timeline-tooltip {
    position: absolute;
    bottom: calc(100% + 8px);
    transform: translateX(-50%);
    background: rgba(0,0,0,0.85);
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    padding: 3px 8px;
    border-radius: 4px;
    white-space: nowrap;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.15s ease;
    z-index: 30;
    font-variant-numeric: tabular-nums;
}
.md-timeline-tooltip.visible { opacity: 1; }
.md-timeline-rail {
    position: relative;
    width: 100%;
    height: 4px;
    background: rgba(255,255,255,0.2);
    border-radius: 4px;
    transition: height 0.2s ease;
}
.md-timeline-container:hover .md-timeline-rail { height: 6px; }
.md-timeline-buffer { position: absolute; inset: 0; background: rgba(255,255,255,0.2); border-radius: 4px; width: 0; transition: width 0.3s linear; }
.md-timeline-progress {
    position: absolute;
    top: 0; left: 0;
    height: 100%;
    width: 0;
    background: var(--md-player-primary);
    border-radius: 4px;
    box-shadow: 0 0 10px rgba(var(--md-player-primary-rgb), 0.5);
}
.md-timeline-handle {
    position: absolute;
    top: 50%; left: 0;
    width: 12px; height: 12px;
    background: #fff;
    border-radius: 50%;
    transform: translate(-50%, -50%) scale(0);
    transition: transform 0.2s ease;
    box-shadow: 0 2px 6px rgba(0,0,0,0.5);
    pointer-events: none;
    will-change: transform, left;
}
.md-timeline-container:hover .md-timeline-handle { transform: translate(-50%, -50%) scale(1); }

/* === Control Bar === */
.md-control-bar { display: flex; align-items: center; justify-content: space-between; gap: 4px; }
.md-controls-left { display: flex; align-items: center; gap: 4px; flex: 1; min-width: 0; }
.md-controls-right { display: flex; align-items: center; gap: 2px; flex-shrink: 0; }

/* === HUD Buttons === */
.md-hud-btn {
    background: transparent;
    border: none;
    color: rgba(255,255,255,0.85);
    padding: 7px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    transition: background 0.18s ease, color 0.18s ease;
    flex-shrink: 0;
    touch-action: manipulation;
    min-width: 36px; min-height: 36px;
}
.md-hud-btn:hover { background: rgba(255,255,255,0.12); color: #fff; }
.md-hud-btn.active { color: var(--md-player-primary); background: rgba(var(--md-player-primary-rgb), 0.12); }
.md-hud-btn svg { width: 20px; height: 20px; fill: currentColor; display: block; }
#md-play-pause svg { width: 26px; height: 26px; }

/* === Time Display === */
.md-playback-time { font-size: 12px; font-weight: 600; color: rgba(255,255,255,0.85); white-space: nowrap; margin-left: 2px; font-variant-numeric: tabular-nums; }

/* === Volume === */
.md-volume-container { display: flex; align-items: center; position: relative; }
.md-volume-slider-wrap { width: 0; overflow: hidden; transition: width 0.3s ease; display: flex; align-items: center; }
.md-volume-container:hover .md-volume-slider-wrap { width: 80px; margin-left: 6px; }
.md-volume-slider { width: 80px; cursor: pointer; accent-color: var(--md-player-primary); height: 4px; }

/* === Center Play Button === */
#md-center-play {
    position: absolute;
    top: 50%; left: 50%;
    transform: translate(-50%, -50%) scale(0.85);
    width: 72px; height: 72px;
    background: rgba(255,255,255,0.15);
    border: 1.5px solid rgba(255,255,255,0.3);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 6;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease, transform 0.25s cubic-bezier(0.34,1.56,0.64,1), background 0.2s ease;
    cursor: pointer;
    overflow: hidden;
}
#md-center-play.visible { opacity: 1; transform: translate(-50%, -50%) scale(1); pointer-events: auto; }
#md-center-play:hover { background: rgba(255,255,255,0.22); border-color: rgba(255,255,255,0.5); }
#md-center-play::after { content: ''; position: absolute; inset: 0; border-radius: 50%; background: rgba(255,255,255,0.25); transform: scale(0); opacity: 0; transition: none; }
#md-center-play.ripple::after { animation: mdRipple 0.5s ease-out forwards; }
@keyframes mdRipple { 0% { transform: scale(0); opacity: 0.5; } 100% { transform: scale(2.5); opacity: 0; } }
.md-play-ring { display: none; }
.md-play-icon { display: flex; align-items: center; justify-content: center; position: relative; z-index: 1; }
.md-play-icon svg { width: 34px; height: 34px; fill: #fff; margin-left: 3px; }

/* === Loading Spinner === */
#md-loading-spinner { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); z-index: 7; pointer-events: none; }
.md-spinner { animation: mdSpin 1s linear infinite; }
.md-spinner .path { stroke: var(--md-player-primary); stroke-linecap: round; animation: mdDash 1.5s ease-in-out infinite; }
@keyframes mdSpin { 100% { transform: rotate(360deg); } }
@keyframes mdDash { 0% { stroke-dasharray: 1,150; stroke-dashoffset: 0; } 50% { stroke-dasharray: 90,150; stroke-dashoffset: -35; } 100% { stroke-dasharray: 90,150; stroke-dashoffset: -124; } }

/* === Tap Feedback (Mobile Double-Tap Seek) === */
.md-tap-feedback { position: absolute; top: 0; width: 25%; height: 100%; background: rgba(255,255,255,0.06); z-index: 4; pointer-events: none; opacity: 0; }
.md-tap-feedback.left { left: 0; border-radius: 0 100% 100% 0; }
.md-tap-feedback.right { right: 0; border-radius: 100% 0 0 100%; }
.md-tap-feedback.active { animation: mdTapFlash 0.6s ease-out forwards; }
@keyframes mdTapFlash { 0% { opacity: 0.5; } 100% { opacity: 0; } }

/* === Settings Panel — Compact Popup (YouTube-style) === */
.md-side-panel {
    position: absolute;
    bottom: 54px; right: 10px;
    width: 220px;
    max-height: 70%;
    background: rgba(10,10,16,0.96);
    backdrop-filter: blur(24px);
    -webkit-backdrop-filter: blur(24px);
    z-index: 200;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    border: 1px solid rgba(255,255,255,0.08);
    border-radius: 10px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.6);
    overflow-y: auto;
    scrollbar-width: none;
    opacity: 0;
    transform: translateY(8px) scale(0.96);
    pointer-events: none;
    transition: opacity 0.2s ease, transform 0.2s ease;
    will-change: opacity, transform;
}
.md-side-panel::-webkit-scrollbar { display: none; }
.md-side-panel.visible { opacity: 1; transform: translateY(0) scale(1); pointer-events: auto; }

.md-panel-header { display: flex; justify-content: space-between; align-items: center; padding: 8px 10px; background: rgba(var(--md-player-primary-rgb), 0.07); border-bottom: 1px solid rgba(255,255,255,0.07); flex-shrink: 0; }
.md-panel-header h3 { margin: 0; font-size: 9px; color: var(--md-player-primary); font-weight: 700; letter-spacing: 1.5px; text-transform: uppercase; }
.md-close-panel { background: rgba(255,255,255,0.07); border: none; color: rgba(255,255,255,0.7); font-size: 14px; cursor: pointer; width: 22px; height: 22px; border-radius: 5px; display: flex; align-items: center; justify-content: center; transition: background 0.2s, color 0.2s, transform 0.2s; line-height: 1; }
.md-close-panel:hover { background: rgba(255,255,255,0.12); color: #fff; transform: rotate(90deg); }

.md-panel-body { padding: 6px 8px; flex: 1; display: flex; flex-direction: column; gap: 2px; }
.md-section-label { font-size: 7px; font-weight: 700; letter-spacing: 1.5px; color: rgba(255,255,255,0.3); text-transform: uppercase; margin: 5px 0 2px; }

.md-setting-item { display: flex; justify-content: space-between; align-items: center; padding: 5px 8px; background: rgba(255,255,255,0.03); border: 1px solid rgba(255,255,255,0.06); border-radius: 6px; font-size: 11px; color: rgba(255,255,255,0.8); margin-bottom: 2px; }
.md-setting-item:hover { background: rgba(255,255,255,0.05); }
.md-setting-item label { font-size: 11px; color: rgba(255,255,255,0.8); pointer-events: none; }

/* Switch */
.md-switch { width: 32px; height: 17px; background: rgba(255,255,255,0.1); border-radius: 9px; position: relative; cursor: pointer; transition: background 0.3s ease; flex-shrink: 0; }
.md-switch span { position: absolute; left: 2px; top: 2px; width: 13px; height: 13px; background: rgba(255,255,255,0.7); border-radius: 50%; transition: all 0.3s cubic-bezier(0.34,1.56,0.64,1); }
.md-switch.active { background: var(--md-player-primary); box-shadow: 0 0 8px rgba(var(--md-player-primary-rgb), 0.35); }
.md-switch.active span { left: 17px; background: #fff; }

/* Chips */
.md-chips { display: flex; flex-wrap: wrap; gap: 4px; padding: 4px 8px 6px; }
.md-chip { padding: 3px 7px; border-radius: 4px; font-size: 10px; font-weight: 600; color: rgba(255,255,255,0.5); background: rgba(255,255,255,0.05); border: 1px solid rgba(255,255,255,0.08); cursor: pointer; transition: all 0.18s ease; }
.md-chip:hover { color: rgba(255,255,255,0.9); background: rgba(255,255,255,0.1); }
.md-chip.active { color: var(--md-player-primary); background: rgba(var(--md-player-primary-rgb), 0.12); border-color: rgba(var(--md-player-primary-rgb), 0.4); }
.md-chips.md-quality-grid { display: grid; grid-template-columns: 1fr 1fr; }

/* Select */
.md-select { background: rgba(255,255,255,0.05); color: rgba(255,255,255,0.85); border: 1px solid rgba(255,255,255,0.1); padding: 6px 10px; border-radius: 7px; font-size: 13px; cursor: pointer; width: 100%; box-sizing: border-box; }
.md-select:focus { outline: none; border-color: var(--md-player-primary); }

/* Report Button */
.md-btn-report { width: 100%; padding: 7px 10px; background: transparent; color: rgba(255,255,255,0.6); border: 1px solid rgba(255,255,255,0.12); border-radius: 7px; cursor: pointer; font-weight: 600; font-size: 11px; display: flex; align-items: center; justify-content: center; gap: 6px; transition: all 0.2s ease; margin-top: 4px; }
.md-btn-report:hover { background: rgba(var(--md-player-primary-rgb), 0.1); color: var(--md-player-primary); border-color: rgba(var(--md-player-primary-rgb), 0.3); }

/* === Admin: Intro Info Box === */
.md-admin-intro-box {
    background: rgba(var(--md-player-primary-rgb), 0.06);
    border: 1px solid rgba(var(--md-player-primary-rgb), 0.2);
    border-radius: 7px;
    padding: 7px 9px;
    font-size: 11px;
    color: rgba(255,255,255,0.7);
    margin-bottom: 4px;
}
.md-admin-intro-box strong { color: var(--md-player-primary); display: block; margin-bottom: 2px; font-size: 9px; letter-spacing: 1px; text-transform: uppercase; }
.md-admin-intro-times { font-size: 11px; color: #fff; font-weight: 600; margin-bottom: 5px; }
.md-btn-reset-intro { background: rgba(255,255,255,0.06); border: 1px solid rgba(255,255,255,0.1); color: rgba(255,255,255,0.5); padding: 3px 8px; border-radius: 5px; cursor: pointer; font-size: 10px; font-weight: 600; transition: all 0.2s ease; }
.md-btn-reset-intro:hover { background: rgba(220,50,50,0.15); border-color: rgba(220,50,50,0.4); color: #ff6b6b; }

/* Pin Intro Button */
.md-pin-intro-btn { background: rgba(var(--md-player-primary-rgb), 0.12); border: 1px solid rgba(var(--md-player-primary-rgb), 0.35); padding: 5px 14px; border-radius: 20px; font-size: 12px; font-weight: 700; color: var(--md-player-primary); display: flex; align-items: center; gap: 6px; transition: all 0.2s ease; }
.md-pin-intro-btn:hover { background: var(--md-player-primary); color: #fff; }
.md-pin-intro-btn.pinning { background: #059669; border-color: #047857; color: #fff; animation: mdPulse 1.4s infinite; }
.md-pin-intro-btn svg { width: 16px; height: 16px; }
@keyframes mdPulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.65; } }

/* === Modal (Report) === */
.md-modal { display: none; position: absolute; inset: 0; background: rgba(0,0,0,0.75); backdrop-filter: blur(8px); z-index: 250; align-items: center; justify-content: center; padding: 16px; box-sizing: border-box; }
.md-modal-content { background: rgba(12,12,18,0.95); backdrop-filter: blur(30px); width: 100%; max-width: 380px; max-height: 100%; overflow-y: auto; padding: 24px; border-radius: 16px; border: 1px solid rgba(var(--md-player-primary-rgb), 0.2); box-shadow: 0 20px 60px rgba(0,0,0,0.8); animation: mdModalIn 0.3s cubic-bezier(0.34,1.56,0.64,1); box-sizing: border-box; }
@keyframes mdModalIn { from { transform: scale(0.92) translateY(10px); opacity: 0; } to { transform: scale(1) translateY(0); opacity: 1; } }

.md-form-group { margin-bottom: 18px; }
.md-form-group label { display: block; font-size: 10px; color: rgba(255,255,255,0.4); margin-bottom: 6px; text-transform: uppercase; letter-spacing: 1.5px; font-weight: 700; }
.md-form-group input, .md-form-group select, .md-form-group textarea { width: 100%; background: transparent; border: none; border-bottom: 1px solid rgba(255,255,255,0.15); color: #fff; padding: 8px 2px; box-sizing: border-box; font-size: 14px; transition: border-color 0.2s ease; }
.md-form-group input:focus, .md-form-group textarea:focus { border-color: var(--md-player-primary); outline: none; }
.md-form-group select { background: rgba(255,255,255,0.05); border-radius: 6px; padding: 8px; border-bottom: 1px solid rgba(255,255,255,0.15); }
.md-time-inputs { display: flex; align-items: center; gap: 10px; }
.md-time-inputs input { text-align: center; font-weight: 700; }
.md-time-inputs span { color: rgba(255,255,255,0.5); }

.md-modal-footer { display: flex; justify-content: flex-end; gap: 12px; margin-top: 24px; }
.md-modal-footer button { padding: 10px 20px; border-radius: 8px; cursor: pointer; border: none; font-weight: 700; font-size: 13px; transition: all 0.2s ease; }
#md-cancel-report { background: rgba(255,255,255,0.06); color: rgba(255,255,255,0.6); border: 1px solid rgba(255,255,255,0.1); }
#md-cancel-report:hover { color: #fff; background: rgba(255,255,255,0.1); }
#md-submit-report { background: var(--md-player-primary); color: #fff; }
#md-submit-report:hover { transform: translateY(-1px); box-shadow: 0 6px 18px rgba(var(--md-player-primary-rgb), 0.4); }

/* === Skip Intro Button === */
#md-skip-btn { position: absolute; bottom: 110px; right: 24px; background: rgba(0,0,0,0.85); border: 1px solid rgba(255,255,255,0.6); color: #fff; padding: 10px 20px; cursor: pointer; font-weight: 700; font-size: 13px; z-index: 150; border-radius: 6px; backdrop-filter: blur(10px); transition: all 0.2s ease; touch-action: manipulation; }
#md-skip-btn:hover { background: #fff; color: #000; }

/* === Auto-Next Toast === */
#md-next-toast { position: absolute; bottom: 90px; left: 20px; background: rgba(12,12,18,0.92); backdrop-filter: blur(20px); padding: 12px 16px; border-radius: 12px; font-size: 13px; z-index: 160; display: none; color: rgba(255,255,255,0.9); font-weight: 600; border-left: 3px solid var(--md-player-primary); min-width: 190px; box-shadow: 0 10px 30px rgba(0,0,0,0.6); }
#md-next-toast.visible { display: block; animation: mdSlideUp 0.3s cubic-bezier(0.34,1.56,0.64,1); }
@keyframes mdSlideUp { from { transform: translateY(14px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
#md-next-toast .md-toast-content { display: flex; align-items: center; gap: 10px; }
#md-next-toast #md-cancel-next { background: rgba(255,255,255,0.08); border: 1px solid rgba(255,255,255,0.12); color: rgba(255,255,255,0.7); padding: 4px 10px; border-radius: 6px; cursor: pointer; font-size: 12px; font-weight: 600; transition: all 0.2s ease; flex-shrink: 0; margin-left: 0; }
#md-next-toast #md-cancel-next:hover { background: rgba(255,255,255,0.14); color: #fff; }

/* =====================================================
   MOBILE RESPONSIVE
   ===================================================== */

/* === Pseudo-Fullscreen (iOS fallback) === */
#md-player-container.md-pseudo-fullscreen {
    position: fixed;
    inset: 0;
    width: 100vw;
    height: 100vh;
    z-index: 999999;
    aspect-ratio: auto;
    border-radius: 0;
}

/* Tắt glow timeline trên thiết bị cảm ứng (tốn GPU) */
@media (pointer: coarse) {
    .md-timeline-progress { box-shadow: none; }
    .md-pin-intro-btn { animation: none !important; }
}

/* Tablet (≤768px) */
@media (max-width: 768px) {
    #md-cinematic-hud { padding: 14px 16px; }
    #md-top-bar { padding: 14px 16px 40px; }
    .md-top-title { font-size: 11px; max-width: 65%; }
    .md-top-episode, .md-top-sep { display: none; }
    #md-play-pause svg { width: 24px; height: 24px; }
    .md-playback-time { font-size: 11px; }
    #md-pip-btn { display: none; }
    .md-volume-slider-wrap { display: none; }
    .md-volume-container:hover .md-volume-slider-wrap { display: none; }
    .md-pin-intro-btn span { display: none; }
}

/* Mobile (≤480px) */
@media (max-width: 480px) {
    #md-cinematic-hud { padding: 10px 12px; }
    #md-top-bar { padding: 10px 12px 36px; }
    .md-top-title { font-size: 10px; max-width: 70%; }
    #md-center-play { width: 56px; height: 56px; }
    .md-play-icon svg { width: 26px; height: 26px; }
    #md-backward, #md-forward { display: none; }
    .md-timeline-container { height: 28px; }
    .md-timeline-rail { height: 3px; }
    .md-timeline-container:hover .md-timeline-rail { height: 5px; }
    #md-skip-btn { bottom: 80px; right: 12px; padding: 7px 14px; font-size: 11px; border-radius: 4px; }
    #md-next-toast { bottom: 70px; left: 12px; right: 12px; min-width: unset; font-size: 12px; padding: 10px 14px; }
    .md-playback-time { display: none; }

    /* Control bar compact */
    .md-control-bar { gap: 2px; }
    .md-controls-left { gap: 2px; }
    .md-controls-right { gap: 0; }
    .md-hud-btn { min-width: 34px; min-height: 34px; padding: 5px; border-radius: 6px; }
    .md-hud-btn svg { width: 18px; height: 18px; }
    #md-play-pause svg { width: 22px; height: 22px; }

    /* Settings popup: full-width bottom sheet on mobile */
    .md-side-panel {
        bottom: 0; left: 0; right: 0;
        width: 100%; max-height: 55%;
        border-radius: 14px 14px 0 0;
        border-top: 1px solid rgba(255,255,255,0.08);
        transform: translateY(100%);
        opacity: 1;
    }
    .md-side-panel.visible { transform: translateY(0); }

    /* Tap feedback: larger touch zone */
    .md-tap-feedback { width: 30%; }

    /* Modal compact */
    .md-modal-content { padding: 18px; border-radius: 12px; }
    .md-modal-content h3 { font-size: 15px; }
    .md-form-group label { font-size: 9px; }
    .md-form-group input, .md-form-group select, .md-form-group textarea { font-size: 13px; }
    .md-modal-footer button { padding: 8px 16px; font-size: 12px; }
}

/* Ultra-small (≤360px) */
@media (max-width: 360px) {
    #md-center-play { width: 48px; height: 48px; }
    .md-play-icon svg { width: 22px; height: 22px; }
    .md-hud-btn { min-width: 30px; min-height: 30px; padding: 4px; }
    .md-hud-btn svg { width: 16px; height: 16px; }
    #md-play-pause svg { width: 20px; height: 20px; }
    #md-theater-btn { display: none; }
    .md-side-panel { height: 65%; }
    .md-setting-item { padding: 8px; font-size: 11px; }
    .md-setting-item label { font-size: 11px; }
    .md-chip { padding: 3px 7px; font-size: 10px; }
}

/* Fullscreen safe areas (notch/Dynamic Island) */
@media (display-mode: fullscreen) {
    #md-cinematic-hud {
        padding-left: calc(12px + env(safe-area-inset-left, 0px));
        padding-right: calc(12px + env(safe-area-inset-right, 0px));
        padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px));
    }
    #md-top-bar {
        padding-left: calc(12px + env(safe-area-inset-left, 0px));
        padding-right: calc(12px + env(safe-area-inset-right, 0px));
        padding-top: calc(10px + env(safe-area-inset-top, 0px));
    }
}

/* Landscape on mobile */
@media (max-height: 500px) and (orientation: landscape) {
    #md-cinematic-hud { padding: 6px 16px; }
    #md-top-bar { padding: 6px 16px 24px; }
    .md-top-title { font-size: 10px; }
    #md-center-play { width: 48px; height: 48px; }
    .md-play-icon svg { width: 22px; height: 22px; }
    .md-hud-btn { min-width: 30px; min-height: 30px; padding: 4px; }
    .md-timeline-container { height: 22px; }
    .md-side-panel { height: 100%; border-radius: 0; }
    #md-skip-btn { bottom: 56px; }
    #md-next-toast { bottom: 50px; }
}

/* =====================================================
   Resume Toast
   ===================================================== */
#md-resume-toast {
    position: absolute;
    bottom: 90px; right: 20px;
    background: rgba(12,12,18,0.92);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    padding: 12px 16px;
    border-radius: 12px;
    font-size: 13px;
    z-index: 160;
    display: none;
    color: rgba(255,255,255,0.9);
    font-weight: 600;
    border-left: 3px solid var(--md-player-primary);
    box-shadow: 0 10px 30px rgba(0,0,0,0.6);
    min-width: 240px;
}
#md-resume-toast.visible { display: block; animation: mdSlideUp 0.3s cubic-bezier(0.34,1.56,0.64,1); }
#md-resume-toast .md-toast-content { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.md-resume-continue, .md-resume-restart {
    padding: 4px 10px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 12px;
    font-weight: 700;
    transition: all 0.2s ease;
    flex-shrink: 0;
}
.md-resume-continue { background: var(--md-player-primary); border: none; color: #fff; }
.md-resume-continue:hover { transform: translateY(-1px); box-shadow: 0 4px 12px rgba(var(--md-player-primary-rgb),0.4); }
.md-resume-restart { background: rgba(255,255,255,0.08); border: 1px solid rgba(255,255,255,0.12); color: rgba(255,255,255,0.7); }
.md-resume-restart:hover { background: rgba(255,255,255,0.14); color: #fff; }

/* =====================================================
   Episode Progress Bar
   ===================================================== */
.md-ep-progress {
    position: absolute;
    bottom: 0; left: 0; right: 0;
    height: 3px;
    background: rgba(255,255,255,0.12);
    border-radius: 0 0 4px 4px;
    overflow: hidden;
    pointer-events: none;
}
.md-ep-progress-bar {
    height: 100%;
    background: var(--md-player-primary);
    border-radius: inherit;
    transition: width 0.3s ease;
}
.md-ep-watched { outline: 1px solid rgba(var(--md-player-primary-rgb), 0.55); }

/* =====================================================
   Sticky Mini-Player
   ===================================================== */
#md-player-container.md-mini-player {
    position: fixed !important;
    bottom: 20px; right: 20px;
    width: 300px;
    height: auto;
    aspect-ratio: 16 / 9;
    z-index: 99999;
    border-radius: 10px;
    overflow: hidden;
    box-shadow: 0 8px 40px rgba(0,0,0,0.75);
    transition: box-shadow 0.3s ease;
}
#md-mini-close {
    position: absolute;
    top: 6px; right: 6px;
    z-index: 300;
    width: 24px; height: 24px;
    border-radius: 50%;
    background: rgba(0,0,0,0.65);
    border: none;
    color: #fff;
    font-size: 14px;
    line-height: 1;
    cursor: pointer;
    display: none;
    align-items: center;
    justify-content: center;
    transition: background 0.2s ease;
}
#md-player-container.md-mini-player #md-mini-close { display: flex; }
#md-mini-close:hover { background: rgba(200,30,30,0.85); }

/* =====================================================
   Chapter Markers on Timeline (Intro boundaries)
   ===================================================== */
.md-chapter-marker {
    position: absolute;
    top: -3px; bottom: -3px;
    width: 2px;
    background: rgba(255,255,255,0.55);
    border-radius: 1px;
    pointer-events: none;
    transform: translateX(-50%);
    z-index: 5;
    transition: background 0.2s ease;
}
.md-timeline-container:hover .md-chapter-marker { background: rgba(255,255,255,0.85); }