/* =============================================================================
   MyMusic — assets/css/app.css
   UI/UX soignée : thème sombre profond, verre dépoli, fond dynamique flouté
   d'après la pochette, superpositions de lecture, égaliseur animé.
   Optimisée mobile & voiture (gros boutons, contrastes), accessible.
   ========================================================================== */

:root {
    --bg:            #08080b;
    --bg-2:          #0d0d12;
    --bg-elev:       #14141b;
    --bg-elev-2:     #1c1c26;
    --card:          #121218;
    --card-hover:    #1b1b24;
    --text:          #f5f5f8;
    --text-dim:      #a2a2b2;
    --text-faint:    #6a6a78;

    --accent:        #7c6cff;
    --accent-2:      #a78bff;
    --accent-3:      #4f8bff;
    --grad:          linear-gradient(135deg, #a78bff 0%, #7c6cff 45%, #4f8bff 100%);
    --grad-soft:     linear-gradient(135deg, rgba(167,139,255,.22), rgba(79,139,255,.10));

    --danger:        #ff5a72;
    --warn:          #ffb454;
    --ok:            #37d9a0;
    --border:        #24242f;
    --border-soft:   rgba(255,255,255,.06);

    --radius:        18px;
    --radius-sm:     12px;
    --shadow:        0 12px 40px rgba(0,0,0,.5);
    --shadow-glow:   0 10px 40px rgba(124,108,255,.35);

    --miniplayer-h:  74px;
    --safe-bottom:   env(safe-area-inset-bottom, 0px);
    --safe-top:      env(safe-area-inset-top, 0px);
    --tap:           48px;

    --ease:          cubic-bezier(.2, .8, .2, 1);
}

* { box-sizing: border-box; }

html, body {
    margin: 0; padding: 0;
    background: var(--bg);
    color: var(--text);
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
    overscroll-behavior-y: none;
}
body {
    min-height: 100vh; min-height: 100dvh;
    background:
        radial-gradient(900px 500px at 15% -10%, rgba(124,108,255,.16), transparent 60%),
        radial-gradient(800px 500px at 110% 0%, rgba(79,139,255,.12), transparent 55%),
        var(--bg);
    background-attachment: fixed;
}

button { font-family: inherit; cursor: pointer; color: inherit; }
img { display: block; }
.hidden { display: none !important; }
[hidden] { display: none !important; }
.sr-only {
    position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
    overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
::selection { background: rgba(124,108,255,.35); }

/* Barres de défilement discrètes */
* { scrollbar-width: thin; scrollbar-color: #2a2a36 transparent; }
*::-webkit-scrollbar { width: 8px; height: 8px; }
*::-webkit-scrollbar-thumb { background: #2a2a36; border-radius: 8px; }

/* ---------- Boutons ---------- */
.icon-btn {
    display: inline-flex; align-items: center; justify-content: center;
    min-width: var(--tap); min-height: var(--tap);
    background: transparent; border: none; color: var(--text);
    font-size: 1.3rem; border-radius: 14px; line-height: 1;
    transition: background .16s var(--ease), transform .12s var(--ease), color .16s;
    text-decoration: none; -webkit-tap-highlight-color: transparent;
}
.icon-btn:hover { background: rgba(255,255,255,.07); }
.icon-btn:active { transform: scale(.9); }
.icon-btn:focus-visible { outline: 2px solid var(--accent-2); outline-offset: 2px; }
.icon-btn-lg { font-size: 1.6rem; }

.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    min-height: var(--tap); padding: 0 22px; border-radius: 999px;
    border: 1px solid var(--border); background: var(--bg-elev-2);
    color: var(--text); font-size: 1rem; font-weight: 600;
    transition: background .16s var(--ease), transform .12s var(--ease), box-shadow .2s;
    -webkit-tap-highlight-color: transparent;
}
.btn:hover { background: #23232f; }
.btn:active { transform: scale(.97); }
.btn-primary { background-image: var(--grad); border: none; color: #fff; box-shadow: var(--shadow-glow); }
.btn-primary:hover { filter: brightness(1.06); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-ghost { background: transparent; }
.btn-block { width: 100%; }
.btn-small { min-height: 40px; padding: 0 16px; font-size: .9rem; }

/* ---------- Champs / alertes ---------- */
.alert { padding: 12px 14px; border-radius: var(--radius-sm); font-size: .92rem; margin-bottom: 14px; line-height: 1.5; }
.alert-error { background: rgba(255,90,114,.12); color: #ffb3c0; border: 1px solid rgba(255,90,114,.35); }
.alert-warn  { background: rgba(255,180,84,.10); color: #ffd8a3; border: 1px solid rgba(255,180,84,.30); }

.field { display: block; margin-bottom: 16px; text-align: left; }
.field-label { display: block; font-size: .82rem; color: var(--text-dim); margin-bottom: 7px; font-weight: 500; }
.field input, .form-input, select {
    width: 100%; min-height: var(--tap); padding: 11px 14px;
    background: var(--bg-elev); border: 1px solid var(--border);
    border-radius: var(--radius-sm); color: var(--text); font-size: 1rem;
    transition: border-color .16s, box-shadow .16s, background .16s;
}
.field input:focus, .form-input:focus, select:focus {
    outline: none; border-color: var(--accent); background: var(--bg-elev-2);
    box-shadow: 0 0 0 4px rgba(124,108,255,.18);
}
code { background: var(--bg-elev-2); padding: 2px 7px; border-radius: 6px; font-size: .9em; }

/* =============================================================================
   Authentification
   ========================================================================== */
.auth-body {
    display: flex; align-items: center; justify-content: center;
    padding: 24px; min-height: 100dvh;
}
.auth-card {
    width: 100%; max-width: 400px; text-align: center;
    background: linear-gradient(180deg, rgba(28,28,38,.9), rgba(18,18,24,.92));
    border: 1px solid var(--border-soft);
    border-radius: 26px; padding: 40px 28px; box-shadow: var(--shadow);
    backdrop-filter: blur(20px);
    animation: pop .4s var(--ease);
}
@keyframes pop { from { opacity: 0; transform: translateY(14px) scale(.98); } to { opacity: 1; transform: none; } }
.auth-logo {
    width: 76px; height: 76px; margin: 0 auto 6px; border-radius: 22px;
    display: flex; align-items: center; justify-content: center; font-size: 2.4rem;
    background-image: var(--grad); box-shadow: var(--shadow-glow);
}
.auth-title { margin: 12px 0 2px; font-size: 1.8rem; letter-spacing: -.02em; }
.auth-subtitle { margin: 0 0 24px; color: var(--text-dim); }

/* =============================================================================
   En-tête
   ========================================================================== */
.app-header {
    position: sticky; top: 0; z-index: 30;
    padding: calc(12px + var(--safe-top)) 16px 12px;
    background: linear-gradient(180deg, rgba(8,8,11,.92), rgba(8,8,11,.72));
    backdrop-filter: saturate(160%) blur(18px);
    border-bottom: 1px solid var(--border-soft);
}
.app-header-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.app-logo {
    margin: 0; font-size: 1.25rem; font-weight: 700; letter-spacing: -.01em;
    display: flex; align-items: center; gap: 9px;
}
.app-logo span {
    background-image: var(--grad);
    -webkit-background-clip: text; background-clip: text; color: transparent;
}
.app-header-actions { display: flex; gap: 2px; }

.app-toolbar { display: flex; gap: 10px; margin-top: 12px; }
.search-wrap { position: relative; flex: 1; display: flex; align-items: center; }
.search-icon { position: absolute; left: 14px; font-size: .95rem; opacity: .6; pointer-events: none; }
#search {
    width: 100%; min-height: var(--tap); padding: 8px 40px 8px 40px;
    background: var(--bg-elev); border: 1px solid var(--border);
    border-radius: 999px; color: var(--text); font-size: 1rem;
    transition: border-color .16s, box-shadow .16s, background .16s;
}
#search::placeholder { color: var(--text-faint); }
#search:focus { outline: none; border-color: var(--accent); background: var(--bg-elev-2); box-shadow: 0 0 0 4px rgba(124,108,255,.16); }
.search-clear { position: absolute; right: 5px; min-width: 40px; min-height: 40px; }
.sort-wrap select {
    min-height: var(--tap); border-radius: 999px; padding: 8px 34px 8px 16px;
    appearance: none; -webkit-appearance: none; cursor: pointer;
    background:
        var(--bg-elev)
        url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23a2a2b2' stroke-width='3'><path d='M6 9l6 6 6-6'/></svg>")
        no-repeat right 12px center;
}

/* Bannières */
.banner { padding: 10px 14px; text-align: center; font-size: .9rem; }
.banner-offline { background: rgba(255,180,84,.14); color: #ffd8a3; }

.ios-hint {
    position: relative; margin: 12px 16px; padding: 16px 42px 16px 16px;
    background: var(--grad-soft); border: 1px solid rgba(167,139,255,.25);
    border-radius: var(--radius); font-size: .92rem; line-height: 1.5;
}
.ios-hint p { margin: 0 0 6px; }
.ios-hint-close { position: absolute; top: 6px; right: 6px; }

/* =============================================================================
   Bibliothèque
   ========================================================================== */
.app-main { padding: 14px 12px calc(var(--miniplayer-h) + 30px + var(--safe-bottom)); }

.section-head { display: flex; align-items: baseline; justify-content: space-between; padding: 4px 6px 12px; }
.section-title { margin: 0; font-size: 1.35rem; font-weight: 700; letter-spacing: -.02em; }
.section-count { color: var(--text-faint); font-size: .85rem; font-variant-numeric: tabular-nums; }

.library-status { color: var(--text-dim); padding: 40px 10px; text-align: center; display: flex; align-items: center; justify-content: center; gap: 10px; }
.spinner {
    width: 18px; height: 18px; border-radius: 50%;
    border: 2px solid rgba(255,255,255,.2); border-top-color: var(--accent-2);
    animation: spin .8s linear infinite; display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

.track-list { list-style: none; margin: 0; padding: 0; }
.track-item {
    display: flex; align-items: center; gap: 13px;
    padding: 9px 10px; border-radius: var(--radius-sm);
    transition: background .14s var(--ease);
}
.track-item:hover { background: var(--card-hover); }
.track-item.is-playing { background: var(--grad-soft); box-shadow: inset 0 0 0 1px rgba(167,139,255,.2); }
.track-item.is-playing .track-title { color: var(--accent-2); }

/* Pochette + superposition de lecture */
.track-cover-wrap {
    position: relative; width: 56px; height: 56px; flex: 0 0 auto;
    border-radius: 12px; overflow: hidden; cursor: pointer;
    background: var(--bg-elev-2); box-shadow: 0 4px 12px rgba(0,0,0,.3);
}
.track-cover { width: 100%; height: 100%; object-fit: cover; }
.track-cover-overlay {
    position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
    background: rgba(0,0,0,.5); opacity: 0; transition: opacity .18s var(--ease);
}
.track-cover-wrap:hover .track-cover-overlay,
.track-cover-wrap:focus-visible .track-cover-overlay { opacity: 1; }
.track-cover-wrap:focus-visible { outline: 2px solid var(--accent-2); outline-offset: 2px; }
.track-play-icon { color: #fff; font-size: 1.05rem; margin-left: 2px; }
.track-item.is-playing .track-cover-overlay { opacity: 1; background: rgba(0,0,0,.42); }
.track-item.is-playing .track-play-icon { display: none; }

/* Égaliseur animé (morceau en cours) */
.eq { display: none; align-items: flex-end; gap: 2px; height: 16px; }
.track-item.is-playing .eq { display: flex; }
.eq i {
    width: 3px; height: 40%; background: #fff; border-radius: 2px;
    animation: eq .9s ease-in-out infinite;
}
.eq i:nth-child(2) { animation-delay: .25s; }
.eq i:nth-child(3) { animation-delay: .5s; }
.eq i:nth-child(4) { animation-delay: .15s; }
@keyframes eq { 0%, 100% { height: 25%; } 50% { height: 100%; } }

.track-main {
    flex: 1 1 auto; min-width: 0;
    display: flex; flex-direction: column; gap: 3px;
    border: none; background: none; text-align: left; padding: 6px 0;
    cursor: pointer;
}
.track-title { font-size: 1rem; font-weight: 600; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.track-sub { font-size: .84rem; color: var(--text-dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.track-duration { color: var(--text-faint); font-size: .82rem; flex: 0 0 auto; margin-left: 2px; font-variant-numeric: tabular-nums; }
.track-actions { display: flex; gap: 0; flex: 0 0 auto; }
.track-actions .icon-btn { min-width: 42px; min-height: 42px; font-size: 1.1rem; }
.track-fav.is-fav { color: var(--danger); }
.track-dl.is-cached { color: var(--ok); }

/* =============================================================================
   File d'attente
   ========================================================================== */
.scrim { position: fixed; inset: 0; background: rgba(0,0,0,.55); z-index: 45; backdrop-filter: blur(3px); animation: fade .2s var(--ease); }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

.queue-panel {
    position: fixed; top: 0; right: 0; z-index: 50;
    width: min(430px, 92vw); height: 100dvh;
    background: linear-gradient(180deg, var(--bg-2), var(--bg));
    border-left: 1px solid var(--border-soft); box-shadow: var(--shadow);
    transform: translateX(100%); transition: transform .28s var(--ease);
    display: flex; flex-direction: column; padding-bottom: var(--safe-bottom);
}
.queue-panel.open { transform: translateX(0); }
.queue-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: calc(16px + var(--safe-top)) 16px 14px; border-bottom: 1px solid var(--border-soft);
}
.queue-header h2 { margin: 0; font-size: 1.2rem; font-weight: 700; }
.queue-list { list-style: none; margin: 0; padding: 8px; overflow-y: auto; flex: 1; }
.queue-row { display: flex; align-items: center; gap: 11px; padding: 8px; border-radius: var(--radius-sm); transition: background .14s; }
.queue-row:hover { background: var(--card-hover); }
.queue-row.is-current { background: var(--grad-soft); }
.queue-row .track-cover { width: 44px; height: 44px; border-radius: 9px; }
.queue-row .icon-btn { min-width: 38px; min-height: 38px; font-size: .95rem; }
.queue-grab { cursor: grab; color: var(--text-faint); font-size: 1.2rem; touch-action: none; }
.queue-row.dragging { opacity: .5; }

/* =============================================================================
   Lecteur réduit (verre dépoli)
   ========================================================================== */
.mini-player {
    position: fixed; left: 8px; right: 8px;
    bottom: calc(8px + var(--safe-bottom)); z-index: 40;
    height: var(--miniplayer-h); padding: 0 6px 0 8px;
    display: flex; align-items: center; gap: 8px;
    background: rgba(22,22,30,.78);
    border: 1px solid var(--border-soft); border-radius: 18px;
    box-shadow: 0 10px 34px rgba(0,0,0,.5);
    backdrop-filter: saturate(160%) blur(22px);
    overflow: hidden;
    animation: riseIn .3s var(--ease);
}
@keyframes riseIn { from { opacity: 0; transform: translateY(16px); } to { opacity: 1; transform: none; } }
.mini-progress { position: absolute; top: 0; left: 0; right: 0; height: 3px; background: rgba(255,255,255,.08); }
.mini-progress-fill { height: 100%; width: 0; background-image: var(--grad); transition: width .25s linear; }
.mini-open { flex: 1 1 auto; min-width: 0; display: flex; align-items: center; gap: 11px; background: none; border: none; text-align: left; padding: 6px; }
.mini-cover { width: 50px; height: 50px; border-radius: 11px; object-fit: cover; background: var(--bg-elev-2); flex: 0 0 auto; box-shadow: 0 4px 12px rgba(0,0,0,.35); }
.mini-meta { min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.mini-title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mini-artist { font-size: .82rem; color: var(--text-dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mini-controls { display: flex; align-items: center; gap: 0; flex: 0 0 auto; }

/* =============================================================================
   Lecteur plein écran
   ========================================================================== */
.full-player {
    position: fixed; inset: 0; z-index: 60; isolation: isolate;
    background: var(--bg);
    display: flex; flex-direction: column;
    padding: calc(12px + var(--safe-top)) 24px calc(28px + var(--safe-bottom));
    animation: slideUp .32s var(--ease);
    overflow: hidden;
}
@keyframes slideUp { from { transform: translateY(100%); } to { transform: translateY(0); } }

/* Fond dynamique flouté d'après la pochette */
.full-bg {
    position: absolute; inset: 0; z-index: 0;
    background-size: cover; background-position: center;
    filter: blur(50px) saturate(1.6) brightness(.5);
    transform: scale(1.35);
}
.full-player::after {
    content: ''; position: absolute; inset: 0; z-index: 1; pointer-events: none;
    background: linear-gradient(180deg, rgba(8,8,11,.3) 0%, rgba(8,8,11,.72) 55%, var(--bg) 100%);
}
.full-player > *:not(.full-bg) { position: relative; z-index: 2; }

.full-topbar { display: flex; align-items: center; justify-content: space-between; }
.full-topbar-label { font-size: .72rem; letter-spacing: .14em; text-transform: uppercase; color: var(--text-dim); }

.full-cover-wrap { flex: 1 1 auto; display: flex; align-items: center; justify-content: center; padding: 26px 0; min-height: 0; }
.full-cover {
    width: min(74vw, 350px); aspect-ratio: 1; max-height: 44vh;
    border-radius: 24px; object-fit: cover; background: var(--bg-elev-2);
    box-shadow: 0 30px 70px rgba(0,0,0,.6), 0 0 0 1px rgba(255,255,255,.05);
    animation: coverIn .5s var(--ease);
}
@keyframes coverIn { from { opacity: 0; transform: scale(.94); } to { opacity: 1; transform: none; } }

.full-meta { text-align: center; margin-bottom: 6px; }
.full-title { margin: 0 0 5px; font-size: 1.55rem; line-height: 1.2; letter-spacing: -.02em; }
.full-artist { margin: 0; color: var(--text-dim); font-size: 1.05rem; }
.full-album { margin: 4px 0 0; color: var(--text-faint); font-size: .88rem; }

.full-progress { margin: 16px 0 6px; }
.time-row { display: flex; justify-content: space-between; font-size: .78rem; color: var(--text-dim); margin-top: 6px; font-variant-numeric: tabular-nums; }

/* Curseurs (progression / volume) */
input[type="range"] {
    width: 100%; -webkit-appearance: none; appearance: none;
    height: 6px; border-radius: 999px; background: rgba(255,255,255,.14);
    cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none; appearance: none;
    width: 16px; height: 16px; border-radius: 50%; background: #fff;
    box-shadow: 0 2px 8px rgba(0,0,0,.4), 0 0 0 4px rgba(255,255,255,.12);
    transition: transform .12s var(--ease);
}
input[type="range"]:active::-webkit-slider-thumb { transform: scale(1.25); }
input[type="range"]::-moz-range-thumb { width: 16px; height: 16px; border-radius: 50%; background: #fff; border: none; box-shadow: 0 2px 8px rgba(0,0,0,.4); }
input[type="range"]:focus-visible { outline: 2px solid var(--accent-2); outline-offset: 5px; }

.full-controls { display: flex; align-items: center; justify-content: space-between; gap: 6px; margin: 20px 0 14px; }
.ctrl-main { font-size: 1.9rem; }
.ctrl-secondary { font-size: 1.25rem; color: var(--text-dim); }
.ctrl-secondary.active { color: var(--accent-2); text-shadow: 0 0 16px rgba(167,139,255,.6); }
.ctrl-play {
    width: 78px; height: 78px; border-radius: 50%; flex: 0 0 auto;
    background-image: var(--grad); color: #fff; font-size: 2rem;
    display: inline-flex; align-items: center; justify-content: center; border: none;
    box-shadow: var(--shadow-glow); transition: transform .12s var(--ease), filter .16s;
}
.ctrl-play:hover { filter: brightness(1.08); }
.ctrl-play:active { transform: scale(.93); }

.full-bottom { display: flex; align-items: center; justify-content: space-between; gap: 14px; }
.ctrl-fav.is-fav { color: var(--danger); text-shadow: 0 0 16px rgba(255,90,114,.5); }
.volume-wrap { display: flex; align-items: center; gap: 10px; flex: 1; max-width: 220px; color: var(--text-dim); }
.volume-wrap.unavailable { display: none; }

/* =============================================================================
   Modale / toasts
   ========================================================================== */
.modal { position: fixed; inset: 0; z-index: 70; display: flex; align-items: flex-end; justify-content: center; background: rgba(0,0,0,.6); backdrop-filter: blur(3px); }
.modal-card {
    width: 100%; max-width: 470px;
    background: linear-gradient(180deg, var(--bg-elev), var(--bg-2));
    border-top-left-radius: 24px; border-top-right-radius: 24px;
    border: 1px solid var(--border-soft); border-bottom: none;
    padding: 22px 22px calc(26px + var(--safe-bottom)); animation: slideUp .28s var(--ease);
}
.modal-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.modal-header h2 { margin: 0; font-size: 1.2rem; font-weight: 700; }
.modal-text { color: var(--text); margin: 4px 0 8px; }
.modal-hint { color: var(--text-dim); font-size: .88rem; margin: 0 0 18px; line-height: 1.5; }

.toast {
    position: fixed; left: 50%; transform: translateX(-50%);
    bottom: calc(var(--miniplayer-h) + 30px + var(--safe-bottom)); z-index: 90;
    background: rgba(28,28,38,.95); color: var(--text);
    padding: 12px 20px; border-radius: 999px; border: 1px solid var(--border-soft);
    box-shadow: var(--shadow); font-size: .92rem; max-width: 90vw; text-align: center;
    backdrop-filter: blur(12px); animation: toastIn .25s var(--ease);
}
@keyframes toastIn { from { opacity: 0; transform: translate(-50%, 12px); } to { opacity: 1; transform: translate(-50%, 0); } }

/* =============================================================================
   Écrans larges (ordinateur)
   ========================================================================== */
@media (min-width: 900px) {
    .app-main { max-width: 920px; margin: 0 auto; }
    .app-header { padding-left: max(16px, calc((100% - 920px) / 2)); padding-right: max(16px, calc((100% - 920px) / 2)); }
    .mini-player { left: 50%; right: auto; transform: translateX(-50%); width: min(880px, 96vw); }
    @keyframes riseIn { from { opacity: 0; transform: translate(-50%, 16px); } to { opacity: 1; transform: translateX(-50%); } }
    .full-player { max-width: 520px; margin: 0 auto; border-radius: 28px; inset: 28px auto 28px 50%; transform: translateX(-50%); height: auto; box-shadow: var(--shadow); }
    @keyframes slideUp { from { transform: translate(-50%, 100%); } to { transform: translate(-50%, 0); } }
    .track-cover-wrap { width: 60px; height: 60px; }
}

/* =============================================================================
   Préférences système
   ========================================================================== */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: .001ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: .001ms !important;
    }
    .eq i { height: 60% !important; }
}
