/* =========================================
   RESET & BASE
   ========================================= */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    transition: background-color 0.3s ease, color 0.3s ease, border-color 0.3s ease, transform 0.2s ease, box-shadow 0.3s ease, opacity 0.2s ease;
}

body {
    font-family: 'Roboto', sans-serif;
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px;
    overflow-x: hidden;
    position: relative;
    background-color: var(--bg-color);
    color: var(--text-color);
}

/* =========================================
   SYSTÈME DE THÈMES (Identique au Portail)
   ========================================= */
:root {
    /* Variables de base */
    --bg-color: #121212;
    --text-color: #e0e0e0;
    --card-bg: #1e1e1e;
    --card-border: 1px solid #333;
    --accent-color: #bb86fc;
    --font-main: 'Roboto', sans-serif;
    --font-title: 'Roboto', sans-serif;
    --scanline-display: none;
    --overlay-display: none;
    --border-radius: 12px;

    /* Variables Spécifiques Player */
    --range-track: rgba(255, 255, 255, 0.1);
    --visualizer-bg: rgba(0, 0, 0, 0.2);
    --playlist-hover: rgba(255, 255, 255, 0.05);
    --section-border: 1px solid rgba(128, 128, 128, 0.1);
}

/* THEME: LIGHT */
[data-theme="light"] {
    --bg-color: #f0f2f5;
    --text-color: #1a1a1a;
    --card-bg: #ffffff;
    --card-border: 1px solid #e1e4e8;
    --accent-color: #007bff;
    --range-track: #e1e4e8;
    --visualizer-bg: #f8f9fa;
    --playlist-hover: rgba(0, 0, 0, 0.05);
    --section-border: 1px solid #e1e4e8;
}

/* THEME: DARK */
[data-theme="dark"] {
    --bg-color: #121212;
    --text-color: #e0e0e0;
    --card-bg: #1e1e1e;
    --card-border: 1px solid #333;
    --accent-color: #bb86fc;
}

/* THEME: ALIEN ISOLATION */
[data-theme="alien"] {
    --bg-color: #020a05;
    --text-color: #00ff41;
    --card-bg: #001a0d;
    --card-border: 1px solid #00ff41;
    --accent-color: #00ff41;
    --font-main: 'Share Tech Mono', monospace;
    --font-title: 'Share Tech Mono', monospace;
    --scanline-display: block;
    --border-radius: 2px;
    --range-track: #003311;
    --visualizer-bg: #001005;
    --playlist-hover: rgba(0, 255, 65, 0.1);
    --section-border: 1px solid #00ff41;
}

/* THEME: SCP FOUNDATION */
[data-theme="scp"] {
    --bg-color: #000000;
    --text-color: #e0e0e0;
    --card-bg: #0a0a0a;
    --card-border: 1px solid #444;
    --accent-color: #ff3333;
    --font-main: 'Share Tech Mono', monospace;
    --font-title: 'Special Elite', monospace;
    --border-radius: 0px;
    --visualizer-bg: #050505;
    --section-border: 1px solid #333;
}

[data-theme="scp"] body {
    background-image: repeating-linear-gradient(45deg, #111 25%, #151515 25%, #151515 50%, #111 50%, #111 75%, #151515 75%, #151515 100%);
    background-size: 10px 10px;
}

/* THEME: FNAF */
[data-theme="fnaf"] {
    --bg-color: #000;
    --text-color: #eee;
    --card-bg: rgba(10, 0, 0, 0.8);
    --card-border: 1px solid #cc0000;
    --accent-color: #cc0000;
    --font-main: "Consolas", "Courier New", monospace;
    --font-title: "Consolas", "Courier New", monospace;
    --overlay-display: block;
    --border-radius: 0px;
    --visualizer-bg: #000;
    --section-border: 1px solid #500;
    --playlist-hover: rgba(200, 0, 0, 0.2);
}

[data-theme="fnaf"] body {
    background-image: radial-gradient(circle at 80% 50%, rgba(50, 40, 30, 0.4) 0%, rgba(0, 0, 0, 1) 60%);
}

/* THEME: MINECRAFT */
[data-theme="minecraft"] {
    --bg-color: #2e2e2e;
    --text-color: #ffffff;
    --card-bg: #c6c6c6;
    --card-border: 4px solid #000;
    --accent-color: #3b8526;
    --font-main: 'Press Start 2P', cursive;
    --font-title: 'Press Start 2P', cursive;
    --border-radius: 0px;
    --range-track: #555;
    --visualizer-bg: #888;
    --section-border: 4px solid #555;
    --playlist-hover: rgba(0, 0, 0, 0.1);
}

[data-theme="minecraft"] body {
    background-color: #483116;
    background-image: url('data:image/svg+xml;utf8,%3Csvg xmlns="http://www.w3.org/2000/svg" width="64" height="64" viewBox="0 0 64 64"%3E%3Crect x="0" y="0" width="64" height="64" fill="%235c3c1e"/%3E%3Crect x="8" y="8" width="8" height="8" fill="%234a3018"/%3E%3Crect x="32" y="16" width="8" height="8" fill="%234a3018"/%3E%3Crect x="48" y="40" width="8" height="8" fill="%234a3018"/%3E%3Crect x="16" y="48" width="8" height="8" fill="%234a3018"/%3E%3C/svg%3E');
    image-rendering: pixelated;
}

/* Ajustement couleur texte Minecraft sur fond gris */
[data-theme="minecraft"] .player-container {
    color: #000;
}

[data-theme="minecraft"] .btn {
    color: #000;
}

[data-theme="minecraft"] .time-text {
    color: #333;
}

/* THEME: PORTAL 2 */
[data-theme="portal"] {
    --bg-color: #e0e0e0;
    --text-color: #333;
    --card-bg: #ffffff;
    --card-border: 1px solid #999;
    --accent-color: #f68928;
    /* Orange */
    --font-main: 'Roboto', sans-serif;
    --border-radius: 4px;
    --range-track: #ccc;
    --visualizer-bg: #eee;
    --section-border: 1px solid #ccc;
}

[data-theme="portal"] body {
    background-image: linear-gradient(90deg, transparent 95%, rgba(0, 0, 0, 0.05) 95%), linear-gradient(transparent 95%, rgba(0, 0, 0, 0.05) 95%);
    background-size: 50px 50px;
}

/* THEME: SUBNAUTICA */
[data-theme="subnautica"] {
    --bg-color: #001e36;
    --text-color: #aaddff;
    --card-bg: rgba(0, 48, 73, 0.7);
    --card-border: 1px solid #00f0ff;
    --accent-color: #00f0ff;
    --font-main: 'Share Tech Mono', monospace;
    --border-radius: 20px 0 20px 0;
    --range-track: #003355;
    --visualizer-bg: rgba(0, 20, 40, 0.5);
    --section-border: 1px solid rgba(0, 240, 255, 0.3);
    --playlist-hover: rgba(0, 240, 255, 0.1);
}

[data-theme="subnautica"] body {
    background: radial-gradient(circle at center, #003355 0%, #001e36 100%);
}

/* =========================================
   STYLES DU PLAYER
   ========================================= */

.player-container {
    background-color: var(--card-bg);
    width: 100%;
    max-width: 1000px;
    border-radius: var(--border-radius);
    border: var(--card-border);
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
    overflow: hidden;
    display: grid;
    grid-template-columns: minmax(0, 1fr) 350px;
    min-height: 600px;
    position: relative;
    z-index: 10;
}

[data-theme="subnautica"] .player-container {
    backdrop-filter: blur(5px);
    box-shadow: 0 0 15px rgba(0, 240, 255, 0.2);
}

@media (max-width: 950px) {
    .player-container {
        grid-template-columns: 1fr;
        height: auto;
        max-height: 90vh;
        overflow-y: auto;
    }

    .playlist-section {
        min-height: 300px;
        border-left: none !important;
        border-top: var(--section-border);
    }
}

.main-section {
    padding: 30px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    border-right: var(--section-border);
    min-width: 0;
    position: relative;
}

/* SELECTEUR DE THEME (Droite) & BOUTON RETOUR (Gauche) */
.top-bar-left {
    position: absolute;
    top: 20px;
    left: 20px;
    z-index: 20;
}

.top-bar-right {
    position: absolute;
    top: 20px;
    right: 20px;
    z-index: 20;
}

.theme-select-mini,
.btn-return {
    appearance: none;
    appearance: none;
    -webkit-appearance: none;
    background-color: var(--card-bg);
    color: var(--text-color);
    border: var(--card-border);
    padding: 5px 10px;
    border-radius: 4px;
    font-family: inherit;
    font-size: 0.8rem;
    cursor: pointer;
    outline: none;
    text-align: center;
    display: flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
    transition: all 0.2s;
}

.btn-return svg {
    width: 16px;
    height: 16px;
    fill: currentColor;
}

.theme-select-mini:hover,
.btn-return:hover {
    border-color: var(--accent-color);
    box-shadow: 0 0 5px var(--accent-color);
    color: var(--accent-color);
}

.theme-select-mini option {
    background-color: var(--bg-color);
    color: var(--text-color);
}

[data-theme="minecraft"] .theme-select-mini,
[data-theme="minecraft"] .btn-return {
    border-radius: 0;
    border-width: 2px;
}

.visualizer-container {
    flex-grow: 1;
    background: var(--visualizer-bg);
    border-radius: calc(var(--border-radius) / 2);
    overflow: hidden;
    position: relative;
    min-height: 200px;
    border: var(--section-border);
    margin-top: 10px;
}

canvas {
    display: block;
    width: 100%;
    height: 100%;
}

.track-info {
    text-align: center;
    margin-bottom: 5px;
    width: 100%;
    padding: 0 10px;
    margin-top: 20px;
}

.track-title {
    font-family: var(--font-title);
    font-size: 1.5rem;
    font-weight: bold;
    margin-bottom: 5px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: block;
    color: var(--accent-color);
    text-shadow: 0 0 2px rgba(0, 0, 0, 0.5);
}

.track-status {
    opacity: 0.7;
    font-size: 0.9rem;
    text-transform: uppercase;
    letter-spacing: 2px;
}

/* Progress Bar */
.progress-area {
    display: flex;
    align-items: center;
    gap: 15px;
    margin-bottom: 5px;
}

.time-text {
    font-size: 0.8rem;
    opacity: 0.7;
    min-width: 45px;
    text-align: center;
    font-variant-numeric: tabular-nums;
}

.progress-bar {
    flex-grow: 1;
    height: 6px;
    appearance: none;
    -webkit-appearance: none;
    background: var(--range-track);
    border-radius: 3px;
    outline: none;
    cursor: pointer;
}

.progress-bar::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 12px;
    height: 12px;
    background: var(--accent-color);
    border-radius: 50%;
    cursor: pointer;
    transition: transform 0.1s;
    box-shadow: 0 0 5px rgba(0, 0, 0, 0.3);
}

[data-theme="minecraft"] .progress-bar::-webkit-slider-thumb,
[data-theme="alien"] .progress-bar::-webkit-slider-thumb {
    border-radius: 0;
    width: 8px;
    height: 16px;
}

.progress-bar::-webkit-slider-thumb:hover {
    transform: scale(1.3);
}

/* Contrôles */
.controls {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 20px;
    margin-bottom: 10px;
}

.btn {
    background: none;
    border: none;
    color: inherit;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn:hover {
    color: var(--accent-color);
    transform: scale(1.1);
}

.btn-main {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: var(--accent-color);
    color: var(--bg-color);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
}

[data-theme="minecraft"] .btn-main,
[data-theme="alien"] .btn-main {
    border-radius: 0;
    border: 2px solid currentColor;
    background: transparent;
    color: var(--accent-color);
}

[data-theme="minecraft"] .btn-main:hover,
[data-theme="alien"] .btn-main:hover {
    background: var(--accent-color);
    color: var(--bg-color);
}

.btn-main:hover {
    filter: brightness(1.2);
}

.btn svg {
    width: 24px;
    height: 24px;
    fill: currentColor;
}

.btn-main svg {
    width: 32px;
    height: 32px;
}

.btn.active {
    color: var(--accent-color);
    text-shadow: 0 0 10px var(--accent-color);
}

/* Style spécifique pour le bouton d'export qui clignote quand actif */
.btn.recording {
    color: red !important;
    animation: pulseRecord 1s infinite;
}

@keyframes pulseRecord {
    0% {
        text-shadow: 0 0 0 rgba(255, 0, 0, 0.5);
    }

    50% {
        text-shadow: 0 0 10px red;
        transform: scale(1.1);
    }

    100% {
        text-shadow: 0 0 0 rgba(255, 0, 0, 0.5);
    }
}

/* Effets Rack */
.effects-rack {
    background: rgba(0, 0, 0, 0.05);
    padding: 20px;
    border-radius: var(--border-radius);
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px 30px;
    border: var(--section-border);
}

.effect-control {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.effect-label {
    font-size: 0.8rem;
    opacity: 0.8;
    display: flex;
    justify-content: space-between;
}

input[type="range"] {
    appearance: none;
    -webkit-appearance: none;
    width: 100%;
    height: 6px;
    background: var(--range-track);
    border-radius: 3px;
    outline: none;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 16px;
    height: 16px;
    background: var(--accent-color);
    border-radius: 50%;
    cursor: pointer;
    transition: background 0.2s;
    box-shadow: 0 0 2px rgba(0, 0, 0, 0.5);
}

[data-theme="minecraft"] input[type="range"]::-webkit-slider-thumb,
[data-theme="alien"] input[type="range"]::-webkit-slider-thumb {
    border-radius: 0;
}

/* Playlist */
.playlist-section {
    background: rgba(0, 0, 0, 0.02);
    display: flex;
    flex-direction: column;
    height: 100%;
    max-height: 100%;
    min-width: 0;
    border-left: var(--section-border);
}

.playlist-header {
    padding: 20px;
    border-bottom: var(--section-border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
}

.playlist-header h3 {
    font-family: var(--font-title);
    margin: 0;
}

.file-input-wrapper {
    position: relative;
    overflow: hidden;
    display: inline-block;
}

.btn-upload {
    background: var(--accent-color);
    color: var(--bg-color);
    padding: 8px 16px;
    border-radius: 4px;
    font-family: var(--font-main);
    font-weight: bold;
    font-size: 0.9rem;
    cursor: pointer;
    border: none;
    transition: opacity 0.2s;
}

[data-theme="minecraft"] .btn-upload {
    border-radius: 0;
    border: 2px solid #000;
    color: #fff;
    text-shadow: 1px 1px #000;
}

.btn-upload:hover {
    opacity: 0.9;
}

.file-input-wrapper input[type=file] {
    font-size: 100px;
    position: absolute;
    left: 0;
    top: 0;
    opacity: 0;
    cursor: pointer;
}

.playlist {
    flex-grow: 1;
    overflow-y: auto;
    padding: 10px;
}

.playlist-item {
    padding: 12px 15px;
    border-radius: 4px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 5px;
    transition: background 0.2s;
    border-left: 3px solid transparent;
    overflow: hidden;
}

.playlist-item:hover {
    background: var(--playlist-hover);
}

.playlist-item.active {
    background: var(--playlist-hover);
    border-left: 3px solid var(--accent-color);
}

.playlist-item.active .item-name {
    color: var(--accent-color);
    font-weight: bold;
}

.item-name {
    font-size: 0.9rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
    flex-grow: 1;
    margin-right: 10px;
}

.item-duration {
    font-size: 0.8rem;
    opacity: 0.6;
    flex-shrink: 0;
}

/* FX Layers (Scanlines & Static) */
.scanlines {
    display: var(--scanline-display);
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: linear-gradient(to bottom,
            rgba(255, 255, 255, 0),
            rgba(255, 255, 255, 0) 50%,
            rgba(0, 0, 0, 0.3) 50%,
            rgba(0, 0, 0, 0.3));
    background-size: 100% 6px;
    z-index: 999;
    pointer-events: none;
    animation: scroll 8s linear infinite;
}

.static-overlay {
    display: var(--overlay-display);
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-image: url('data:image/svg+xml;utf8,%3Csvg viewBox="0 0 200 200" xmlns="http://www.w3.org/2000/svg"%3E%3Cfilter id="noiseFilter"%3E%3CfeTurbulence type="fractalNoise" baseFrequency="0.9" numOctaves="3" stitchTiles="stitch"/%3E%3C/filter%3E%3Crect width="100%25" height="100%25" filter="url(%23noiseFilter)" opacity="0.1"/%3E%3C/svg%3E');
    z-index: 998;
    pointer-events: none;
    opacity: 0.15;
    mix-blend-mode: hard-light;
    animation: flicker 0.1s infinite;
}

@keyframes scroll {
    0% {
        background-position: 0 0;
    }

    100% {
        background-position: 0 100%;
    }
}

@keyframes flicker {
    0% {
        opacity: 0.1;
    }

    20% {
        opacity: 0.15;
    }

    40% {
        opacity: 0.05;
    }

    60% {
        opacity: 0.15;
    }

    80% {
        opacity: 0.1;
    }

    100% {
        opacity: 0.12;
    }
}

/* Scrollbar custom */
::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--range-track);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: #555;
}

.empty-state {
    padding: 40px;
    text-align: center;
    opacity: 0.6;
    font-style: italic;
}

/* =========================================
   KEYFRAME SYSTEM
   ========================================= */

.label-left {
    display: flex;
    align-items: center;
    gap: 8px;
}

.btn-keyframe-add {
    background: transparent;
    border: 1px solid var(--text-color);
    color: var(--text-color);
    width: 18px;
    height: 18px;
    border-radius: 50%;
    font-size: 12px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    opacity: 0.5;
    transition: all 0.2s;
}

.btn-keyframe-add:hover {
    opacity: 1;
    background: var(--accent-color);
    border-color: var(--accent-color);
    color: var(--bg-color);
}

.btn#btnAutomation.active {
    color: var(--accent-color);
    text-shadow: 0 0 10px var(--accent-color);
}

/* Updated Keyframe Positioning Logic */
.progress-wrapper {
    flex-grow: 1;
    position: relative;
    display: flex;
    align-items: center;
    height: 20px;
    margin: 0 10px;
    /* Spacing from time text */
}

.progress-bar {
    width: 100%;
    flex-grow: 1;
    margin: 0;
}

.progress-area {
    position: relative;
    flex-wrap: nowrap;
    align-items: center;
}

.keyframe-indicators {
    position: absolute;
    top: 50%;
    /* Center vertically in wrapper */
    left: 0;
    width: 100%;
    height: 0;
    /* No height, just a line for positioning */
    pointer-events: none;
    z-index: 5;
    margin: 0;
}

.keyframe-point {
    position: absolute;
    width: 10px;
    /* Slightly larger for visibility */
    height: 10px;
    background-color: var(--accent-color);
    border-radius: 0;
    /* Square/Diamond */
    top: 0;
    transform: translate(-50%, -50%) rotate(45deg);
    /* Centered on line + Rotated */
    opacity: 1;
    box-shadow: 0 0 3px rgba(0, 0, 0, 0.8);
    pointer-events: auto;
    z-index: 10;
    border: 1px solid rgba(255, 255, 255, 0.3);
}

.keyframe-point:hover {
    transform: translate(-50%, -50%) rotate(45deg) scale(1.4);
    z-index: 20;
    background-color: #fff;
    cursor: help;
}