:root {
    --bg-app: #1c1c20;
    --bg-panel: #26262b;
    --bg-element: #303037;
    --bg-hover: #3a3a42;
    --border: #3d3d45;

    --text-main: #fafafa;
    --text-muted: #a1a1aa;

    --accent: #6366f1;
    /* Indigo */
    --accent-hover: #4f46e5;
    --danger: #ef4444;
    --success: #22c55e;

    --font-family: 'Inter', system-ui, -apple-system, sans-serif;

    --gap: 16px;
    --radius: 8px;
    --radius-sm: 4px;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body,
html {
    height: 100%;
}

body {
    background-color: var(--bg-app);
    color: var(--text-main);
    font-family: var(--font-family);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* --- Header --- */
#top-header {
    height: 60px;
    background-color: var(--bg-app);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    flex: none;
}

.logo-container {
    display: flex;
    align-items: center;
    gap: 12px;
}

.logo {
    height: 32px;
    width: auto;
}

.title {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text-main);
    letter-spacing: -0.02em;
}

.subtitle {
    font-weight: 400;
    color: var(--text-muted);
    font-size: 0.9rem;
}

/* --- App Layout --- */
#app {
    display: flex;
    flex: 1;
    overflow: hidden;
    padding: var(--gap);
    gap: var(--gap);
}

/* --- Left Panel (Playlist) --- */
#left-panel {
    width: 540px;
    background-color: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    display: flex;
    flex-direction: column;
    min-width: 380px;
    overflow: hidden;
}

#left-header {
    padding: 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--border);
    background-color: var(--bg-element);
}

.section-title {
    font-size: 0.85rem;
    font-weight: 600;
    text-transform: uppercase;
    color: var(--text-muted);
    letter-spacing: 0.05em;
}

.playlist-actions {
    display: flex;
    gap: 8px;
}

.icon-btn {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-muted);
    border-radius: var(--radius-sm);
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
}

.icon-btn:hover {
    background: var(--bg-hover);
    color: var(--text-main);
    border-color: var(--text-muted);
}

#drop-hint {
    padding: 32px;
    text-align: center;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border);
    background-color: rgba(255, 255, 255, 0.02);
    display: none;
    /* Controlled by JS typically, but flex when visible */
    flex-direction: column;
    align-items: center;
    gap: 12px;
}

#left-panel.dragover {
    box-shadow: inset 0 0 0 2px var(--success), inset 0 0 20px rgba(34, 197, 94, 0.5);
    border-color: var(--success);
}

#left-panel.dragover #drop-hint {
    display: flex;
}

#queue {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 8px;
    min-height: 0;
    /* Important for firefox/flex scrolling */
}

/* Queue Items (Styled like "BLOCS" buttons) */
.queue-item {
    background-color: var(--bg-element);
    border: 1px solid var(--border);
    border-left: 4px solid var(--accent);
    /* Accent color indicator */
    border-radius: var(--radius-sm);
    padding: 10px 12px;
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: grab;
    transition: transform 0.1s, background-color 0.2s;
}

.queue-item:hover {
    background-color: var(--bg-hover);
}

.queue-item.dragging {
    opacity: 0.5;
    background-color: var(--bg-element);
}

.qi-info {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 1px;
}

.file-name {
    display: block;
    max-width: 100%;
    font-size: 0.9rem;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.folder-pick {
    display: block;
    max-width: 100%;
    font-size: 0.74rem;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.queue-folder .folder-pick {
    color: #86efac;
}

.mix-item-btn {
    background: var(--accent);
    color: #fff;
    border: none;
    cursor: pointer;
    padding: 4px 9px;
    border-radius: var(--radius-sm);
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.05em;
    transition: background-color 0.2s;
}

.mix-item-btn:hover {
    background: var(--accent-hover);
}

.dup-item-btn {
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px 6px;
    border-radius: 4px;
    color: var(--text-muted);
    font-size: 1.05rem;
    line-height: 1;
    opacity: 0.6;
    transition: opacity 0.2s;
}

.dup-item-btn:hover {
    opacity: 1;
    color: var(--text-main);
    background-color: rgba(255, 255, 255, 0.1);
}

.reconnect-btn {
    background: rgba(245, 158, 11, 0.18);
    border: 1px solid #f59e0b;
    color: #f59e0b;
    cursor: pointer;
    padding: 3px 8px;
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    transition: background-color 0.2s;
}

.reconnect-btn:hover {
    background: rgba(245, 158, 11, 0.32);
}

.duration {
    font-size: 0.8rem;
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
}

.play-item-btn,
.delete-btn {
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0.6;
    transition: opacity 0.2s;
}

.play-item-btn {
    color: var(--text-main);
    font-size: 0.9rem;
}

.delete-btn {
    color: var(--danger);
    font-size: 1rem;
}

.play-item-btn:hover,
.delete-btn:hover {
    opacity: 1;
    background-color: rgba(255, 255, 255, 0.1);
}

/* --- Right Panel (Main) --- */
#right-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: var(--gap);
    min-width: 0;
}

/* Header Bar inside Right Panel (Top Controls) */
#header-bar {
    background-color: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 16px;
    min-height: 70px;
}

.system-info {
    display: flex;
    flex-direction: column;
}

.system-info .label {
    font-size: 0.7rem;
    color: var(--text-muted);
    font-weight: 600;
    margin-bottom: 2px;
}

#clock {
    font-family: 'Inter', monospace;
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-main);
    font-variant-numeric: tabular-nums;
}

.main-controls {
    display: flex;
    gap: 8px;
    align-items: center;
}

.control-btn {
    height: 40px;
    padding: 0 16px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background-color: var(--bg-element);
    color: var(--text-main);
    font-weight: 600;
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    transition: all 0.2s;
}

.control-btn:hover {
    background-color: var(--bg-hover);
    border-color: var(--text-muted);
}

.control-btn .icon {
    font-size: 1.1em;
}

.stop-btn:hover {
    background-color: rgba(239, 68, 68, 0.15);
    border-color: var(--danger);
    color: var(--danger);
}

.play-btn {
    background-color: var(--text-main);
    color: var(--bg-app);
    border-color: var(--text-main);
}

.play-btn:hover {
    background-color: #ddd;
}

.active {
    /* Auto Next Active State */
    border-color: var(--accent);
    background-color: rgba(99, 102, 241, 0.15);
    color: var(--accent);
}

/* Volume */
.volume-control {
    display: flex;
    align-items: center;
    gap: 8px;
}

.vol-icon {
    font-size: 1.2rem;
    color: var(--text-muted);
}

#volume {
    appearance: none;
    width: 100px;
    height: 4px;
    background: var(--bg-element);
    border-radius: 2px;
}

#volume::-webkit-slider-thumb {
    appearance: none;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--text-main);
    cursor: pointer;
}

/* Player Container (Big Box) */
.player-container {
    background-color: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    min-height: 180px;
    position: relative;
    flex: 1;
    /* Grow to fill space */
    max-height: 220px;
    /* Constrain height — le décompte d'intro est en sur-impression, donc
       il n'agrandit pas le contenu */
    overflow: hidden;
}

#visualizer {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 0;
    opacity: 0.3;
    pointer-events: none;
}

#now-playing {
    width: 100%;
    text-align: center;
    margin-bottom: 20px;
    position: relative;
    z-index: 1;
}

.track-info {
    margin-bottom: 16px;
}

#now-label {
    color: var(--accent);
    font-size: 0.9rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    margin-bottom: 12px;
}

#now-title {
    font-size: 2.5rem;
    font-weight: 800;
    color: var(--text-main);
    line-height: 1.2;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
}

.time-display {
    color: var(--text-muted);
    font-family: monospace;
    font-size: 1.1rem;
    margin-top: 8px;
}

#progress {
    width: 100%;
    height: 48px;
    /* Taller for waveform */
    flex: none;
    /* Ne pas rétrécir dans le conteneur flex (sinon écrasé à ~1px) */
    min-height: 48px;
    background-color: var(--bg-element);
    border-radius: 4px;
    overflow: hidden;
    cursor: pointer;
    position: relative;
    transition: height 0.2s;
}

#progress:hover {
    height: 48px;
    /* Keep height consistent or expand */
}

/* #progress-bar {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, var(--accent), #818cf8);
    transition: width 0.1s linear;
} */

#waveform {
    width: 100%;
    height: 100%;
    display: block;
}

/* Up Next Bar */
#up-next {
    background-color: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px 20px;
    font-size: 0.95rem;
    color: var(--text-muted);
}

.next-label {
    font-weight: 600;
    color: var(--text-main);
    margin-right: 8px;
}

/* History */
#history {
    background-color: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    flex: 1;
    /* Fill available space */
    min-height: 0;
    /* Allow scrolling */
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

#history h3 {
    margin-bottom: 10px;
}

#history-list {
    list-style: none;
    font-size: 0.85rem;
    color: var(--text-muted);
}

#history-list li {
    padding: 4px 0;
    border-bottom: 1px solid var(--border);
}

#history-list li:last-child {
    border-bottom: none;
}

/* ── Audio Output Selector ───────────────────────────────── */
.header-controls {
    display: flex;
    align-items: center;
    gap: 18px;
}

.output-group {
    display: flex;
    align-items: center;
    gap: 7px;
}

.out-label {
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--text-muted);
    white-space: nowrap;
}

.audio-output-btn {
    height: 36px;
    padding: 0 14px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background-color: var(--bg-element);
    color: var(--text-muted);
    font-family: var(--font-family);
    font-size: 0.8rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
    max-width: 220px;
    overflow: hidden;
    text-overflow: ellipsis;
}

.audio-output-btn:hover {
    background-color: var(--bg-hover);
    color: var(--text-main);
    border-color: var(--text-muted);
}

.audio-output-panel {
    position: fixed;
    z-index: 9999;
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.6);
    min-width: 260px;
    max-width: 360px;
    padding: 6px 0;
    font-family: var(--font-family);
    font-size: 0.85rem;
}

.aop-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 14px;
    cursor: pointer;
    color: var(--text-main);
    transition: background 0.15s;
}

.aop-item:hover {
    background: var(--bg-hover);
}

.aop-active {
    color: var(--accent);
}

.aop-check {
    width: 16px;
    font-size: 0.85rem;
    flex-shrink: 0;
    text-align: center;
}

.aop-label {
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.aop-sep {
    height: 1px;
    background: var(--border);
    margin: 4px 0;
}

.aop-msg {
    padding: 8px 14px;
    color: var(--text-muted);
    font-size: 0.8rem;
}

.aop-unlock {
    color: var(--text-muted);
    font-size: 0.82rem;
}

/* --- Sauvegarde / chargement playlist --- */
#playlist-io {
    display: flex;
    gap: 8px;
    padding: 10px 12px;
    border-top: 1px solid var(--border);
    background-color: var(--bg-element);
    flex: none;
}

.pl-io-btn {
    flex: 1;
    height: 34px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background-color: var(--bg-panel);
    color: var(--text-main);
    font-family: var(--font-family);
    font-size: 0.82rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.pl-io-btn:hover {
    background-color: var(--bg-hover);
    border-color: var(--text-muted);
}

/* --- Emplacement à recharger (playlist chargée) --- */
.queue-missing {
    border-left-color: #f59e0b;
    opacity: 0.85;
}

.queue-missing .file-name {
    color: var(--text-muted);
}

.missing-note {
    color: #f59e0b !important;
}

/* --- Dossier dans la playlist --- */
.queue-folder {
    border-left-color: var(--success);
}

.queue-folder .file-name {
    color: var(--success);
}

/* --- Piste URL (M3U / PLS) --- */
.queue-url-track {
    border-left-color: #38bdf8;
}

.queue-url-track .file-name {
    color: #38bdf8;
}

/* --- Décompte d'intro --- */
#intro-countdown {
    position: absolute;
    top: 14px;
    right: 18px;
    z-index: 2;
    padding: 6px 18px;
    border-radius: 999px;
    background-color: rgba(34, 197, 94, 0.15);
    border: 1px solid var(--success);
    color: var(--success);
    font-weight: 700;
    font-size: 1.6rem;
    font-variant-numeric: tabular-nums;
    letter-spacing: 0.03em;
}

#intro-countdown[hidden] {
    display: none;
}

#intro-countdown.blink {
    background-color: rgba(239, 68, 68, 0.18);
    border-color: var(--danger);
    color: var(--danger);
    animation: introBlink 0.6s steps(2, start) infinite;
}

@keyframes introBlink {
    50% { opacity: 0.25; }
}

/* --- Éditeur de mix (modale) --- */
#mix-editor-overlay {
    position: fixed;
    inset: 0;
    z-index: 10000;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

.mix-editor {
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.7);
    width: min(1100px, 96vw);
    max-height: 92vh;
    display: flex;
    flex-direction: column;
    font-family: var(--font-family);
}

.me-stage {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.me-hint {
    font-size: 0.78rem;
    color: var(--text-muted);
    line-height: 1.4;
}

#me-timeline {
    width: 100%;
    display: block;
    background: #1a1a1f;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    touch-action: none;
    user-select: none;
}

.me-scrollbar {
    position: relative;
    height: 12px;
    background: var(--bg-element);
    border: 1px solid var(--border);
    border-radius: 6px;
    cursor: pointer;
    touch-action: none;
}

.me-scrollbar.hidden {
    visibility: hidden;
}

.me-thumb {
    position: absolute;
    top: 1px;
    bottom: 1px;
    left: 0;
    width: 40px;
    background: var(--text-muted);
    border-radius: 5px;
    cursor: grab;
}

.me-thumb:hover {
    background: var(--text-main);
}

.me-thumb:active {
    cursor: grabbing;
}

.me-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 18px;
    border-bottom: 1px solid var(--border);
    background: var(--bg-element);
    border-radius: var(--radius) var(--radius) 0 0;
}

.me-title {
    font-weight: 700;
    font-size: 1rem;
}

.me-nav {
    display: flex;
    gap: 6px;
}

.me-btn:disabled {
    opacity: 0.4;
    cursor: default;
}

.me-btn:disabled:hover {
    background: var(--bg-element);
    border-color: var(--border);
}

.me-close {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.1rem;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: var(--radius-sm);
}

.me-close:hover {
    color: var(--text-main);
    background: var(--bg-hover);
}

.me-body {
    padding: 16px 18px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.me-msg,
.me-loading {
    color: var(--text-muted);
    font-size: 0.9rem;
    padding: 12px 4px;
}

.me-loading {
    display: flex;
    align-items: center;
    gap: 12px;
}

.me-spinner {
    width: 20px;
    height: 20px;
    flex: none;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: meSpin 0.8s linear infinite;
}

@keyframes meSpin {
    to { transform: rotate(360deg); }
}

.me-warn {
    color: #fbbf24;
    background: rgba(251, 191, 36, 0.12);
    border: 1px solid rgba(251, 191, 36, 0.4);
    border-radius: var(--radius-sm);
    font-size: 0.82rem;
    padding: 8px 12px;
    line-height: 1.4;
}

.me-row {
    background: var(--bg-element);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 10px 12px;
}

.me-row-disabled {
    opacity: 0.6;
}

.me-row-head {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 8px;
}

.me-role {
    font-size: 0.68rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--accent);
    background: rgba(99, 102, 241, 0.15);
    padding: 2px 8px;
    border-radius: 999px;
    flex: none;
}

.me-name {
    flex: 1;
    min-width: 0;
    font-size: 0.9rem;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.me-times {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 0.82rem;
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
    flex: none;
}

.me-times b {
    color: var(--text-main);
}

.me-canvas {
    width: 100%;
    height: 80px;
    display: block;
    background: #1a1a1f;
    border-radius: var(--radius-sm);
    touch-action: none;
}

.me-overlap {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.85rem;
    color: var(--text-muted);
    padding: 2px 4px;
}

.me-ov-input {
    width: 64px;
    height: 28px;
    background: var(--bg-element);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-main);
    text-align: right;
    padding: 0 6px;
    font-family: var(--font-family);
    font-variant-numeric: tabular-nums;
}

.me-foot {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
    padding: 14px 18px;
    border-top: 1px solid var(--border);
}

.me-stop:hover {
    background-color: rgba(239, 68, 68, 0.18);
    border-color: var(--danger);
    color: var(--danger);
}

.me-spacer {
    flex: 1;
}

.me-btn {
    height: 34px;
    padding: 0 14px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--bg-element);
    color: var(--text-main);
    font-family: var(--font-family);
    font-weight: 600;
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.2s;
}

.me-btn:hover {
    background: var(--bg-hover);
    border-color: var(--text-muted);
}

.me-row-auto {
    height: 28px;
    padding: 0 8px;
    font-size: 0.8rem;
}

.me-ok {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}

.me-ok:hover {
    background: var(--accent-hover);
    border-color: var(--accent-hover);
}