/* ===== Thème ===== */
:root {
    --bg: #f4f4f4;
    --card: #ffffff;
    --line: #dcdcdc;
    --text: #1d1d1f;
    --muted: #6b6b70;
    --hover: #efefef;
    --active: #e6eefc;
    --accent: #4285f4;
    --accent-ink: #ffffff;
    --track: #dddddd;
    --radius: 18px;
    --shadow: 0 1px 2px rgba(0,0,0,.05), 0 6px 24px rgba(0,0,0,.06);
    color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
    :root {
        --bg: #121214;
        --card: #1c1c1f;
        --line: #2e2e33;
        --text: #ececf0;
        --muted: #9a9aa3;
        --hover: #26262b;
        --active: #1f2d47;
        --accent: #6ea0ff;
        --accent-ink: #0b1220;
        --track: #34343a;
        --shadow: 0 1px 2px rgba(0,0,0,.4);
    }
}

*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
    margin: 0;
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; }
svg { width: 1em; height: 1em; fill: currentColor; }

/* ===== Mise en page : le player reste en place, seule la playlist défile ===== */
.app {
    height: 100vh;
    height: 100dvh;
    max-width: 1100px;
    margin: 0 auto;
    padding: 16px;
    padding-top: max(16px, env(safe-area-inset-top));
    padding-bottom: max(16px, env(safe-area-inset-bottom));
    display: grid;
    grid-template-rows: auto minmax(0, 1fr);
    gap: 12px;
}

.player,
.list {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

/* ===== Player ===== */
.player {
    padding: 16px;
    display: grid;
    gap: 12px;
}
.player-title {
    margin: 0;
    font-size: 1rem;
    font-weight: 700;
    text-align: center;
    letter-spacing: .02em;
}

.now { display: flex; gap: 14px; align-items: center; min-width: 0; }
.now-cover {
    width: 72px; height: 72px; flex: none;
    border-radius: 12px; overflow: hidden;
    background: var(--hover);
    display: grid; place-items: center;
    color: var(--muted);
}
.now-cover img { width: 100%; height: 100%; object-fit: cover; display: block; }
.now-cover .ph { width: 40%; height: 40%; }
.now-meta { min-width: 0; }
.now-title { font-weight: 700; font-size: 1.1rem; line-height: 1.25; }
.now-artist { color: var(--text); margin-top: 2px; }
.now-album { color: var(--muted); font-style: italic; font-size: .9rem; }
.now-title, .now-artist, .now-album { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Barres de position et de volume */
input[type=range] {
    --p: 0%;
    -webkit-appearance: none; appearance: none;
    width: 100%; height: 18px; margin: 0;
    background: transparent; cursor: pointer;
}
input[type=range]::-webkit-slider-runnable-track {
    height: 6px; border-radius: 3px;
    background: linear-gradient(var(--accent), var(--accent)) 0 / var(--p) 100% no-repeat, var(--track);
}
input[type=range]::-moz-range-track { height: 6px; border-radius: 3px; background: var(--track); }
input[type=range]::-moz-range-progress { height: 6px; border-radius: 3px; background: var(--accent); }
input[type=range]::-webkit-slider-thumb {
    -webkit-appearance: none; width: 14px; height: 14px; margin-top: -4px;
    border-radius: 50%; background: var(--accent); border: 0;
    transition: transform .15s;
}
input[type=range]::-moz-range-thumb { width: 14px; height: 14px; border-radius: 50%; background: var(--accent); border: 0; }
input[type=range]:hover::-webkit-slider-thumb { transform: scale(1.25); }
input[type=range]:focus-visible { outline: 2px solid var(--accent); outline-offset: 4px; border-radius: 4px; }

.times {
    display: flex; justify-content: space-between;
    font-size: .8rem; color: var(--muted);
    font-variant-numeric: tabular-nums;
    margin-top: 2px;
}

.controls { display: flex; justify-content: center; align-items: center; gap: 10px; }
.btn {
    position: relative;
    width: 44px; height: 44px;
    display: grid; place-items: center;
    border: 0; border-radius: 50%;
    background: transparent; cursor: pointer;
    font-size: 22px;
    transition: background .15s, color .15s, transform .1s;
}
.btn:hover { background: var(--hover); }
.btn:active { transform: scale(.94); }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn-sm { font-size: 18px; color: var(--muted); }
.btn-play { width: 56px; height: 56px; background: var(--accent); color: var(--accent-ink); font-size: 26px; }
.btn-play:hover { background: var(--accent); filter: brightness(1.08); }
.btn[aria-pressed=true], .btn[data-mode=all], .btn[data-mode=one] { color: var(--accent); }
.btn .badge {
    display: none;
    position: absolute; top: 6px; right: 5px;
    font-size: 9px; font-weight: 700; line-height: 1;
    background: var(--accent); color: var(--accent-ink);
    border-radius: 6px; padding: 2px 3px;
}
.btn[data-mode=one] .badge { display: block; }

.volume { display: flex; align-items: center; gap: 6px; max-width: 220px; width: 100%; justify-self: center; }
/* Le volume n'est pas pilotable sur iOS/Android : on le masque sur les écrans tactiles */
@media (pointer: coarse) { .volume { display: none; } }

/* ===== Playlist ===== */
.list {
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.list-head {
    display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
    padding: 12px;
    border-bottom: 1px solid var(--line);
}
.search {
    flex: 1 1 220px;
    display: flex; align-items: center; gap: 8px;
    background: var(--hover);
    border-radius: 12px;
    padding: 0 12px;
    color: var(--muted);
}
.search input {
    flex: 1; min-width: 0;
    border: 0; background: transparent; color: var(--text);
    font: inherit; padding: 10px 0; outline: none;
}
.search:focus-within { outline: 2px solid var(--accent); }
.list-info { font-size: .85rem; color: var(--muted); white-space: nowrap; }

.playlist {
    list-style: none;
    margin: 0;
    padding: 8px;
    overflow-y: auto;
    overscroll-behavior: contain;
    flex: 1;
    scroll-padding: 8px;
}
.track + .track { margin-top: 4px; }
.track[hidden] { display: none; }
.track-btn {
    width: 100%;
    display: flex; align-items: center; gap: 12px;
    padding: 8px;
    border: 0; border-radius: 14px;
    background: transparent;
    text-align: left; cursor: pointer;
    transition: background .15s;
}
.track-btn:hover { background: var(--hover); }
.track-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.track.active .track-btn { background: var(--active); }
.track.active strong { color: var(--accent); }
.track.error { opacity: .45; }

.track-cover {
    position: relative;
    width: 56px; height: 56px; flex: none;
    border-radius: 10px; overflow: hidden;
    background: var(--hover);
    display: grid; place-items: center;
    color: var(--muted);
}
.track-cover img { width: 100%; height: 100%; object-fit: cover; display: block; }
.track-cover .ph { width: 45%; height: 45%; }

.track-info { flex: 1; min-width: 0; display: grid; gap: 2px; }
.track-info strong, .track-info small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.track-info strong { font-weight: 600; }
.track-info small { color: var(--muted); font-size: .85rem; }
.track-dur { color: var(--muted); font-size: .85rem; font-variant-numeric: tabular-nums; }

/* Indicateur « en cours de lecture » */
.eq {
    position: absolute; inset: 0;
    display: none; align-items: flex-end; justify-content: center; gap: 3px;
    padding-bottom: 14px;
    background: rgba(0,0,0,.45);
}
.eq i { width: 4px; height: 8px; background: #fff; border-radius: 2px; animation: eq 1s ease-in-out infinite; }
.eq i:nth-child(2) { animation-delay: -.35s; }
.eq i:nth-child(3) { animation-delay: -.7s; }
.track.active .eq { display: flex; }
body:not(.is-playing) .eq i { animation-play-state: paused; }
@keyframes eq { 0%,100% { height: 6px; } 50% { height: 24px; } }

.empty { text-align: center; color: var(--muted); padding: 24px; margin: 0; }

/* ===== Mobile ===== */
@media (max-width: 600px) {
    .app { padding: 10px; gap: 10px; }
    .player { padding: 12px; gap: 8px; }
    .player-title { font-size: .9rem; }
    .now-cover { width: 60px; height: 60px; }
    .now-title { font-size: 1rem; }
    .track-cover { width: 46px; height: 46px; }
    .track-btn { gap: 10px; padding: 6px; }
    .list-head { padding: 8px; }
    .search { flex-basis: 0; }
    .list-info { font-size: .8rem; }
}

/* ===== Grand écran / paysage : player à gauche, playlist à droite ===== */
@media (min-width: 900px), (orientation: landscape) and (max-height: 560px) and (min-width: 600px) {
    .app {
        grid-template-columns: minmax(300px, 380px) minmax(0, 1fr);
        grid-template-rows: minmax(0, 1fr);
    }
    .player { align-content: start; overflow-y: auto; }
}
@media (min-width: 900px) {
    .player { padding: 24px; gap: 16px; }
    .now { flex-direction: column; text-align: center; }
    .now-cover { width: 100%; height: auto; aspect-ratio: 1; border-radius: 14px; }
    .now-meta { width: 100%; }
    .now-title { font-size: 1.25rem; white-space: normal; }
}

@media (prefers-reduced-motion: reduce) {
    .eq i { animation: none; height: 14px; }
    * { transition: none !important; }
}
