/*
 * Digeratist: The Soundtracks
 * Universal rule 2: all layout, type and spacing sizes are relative
 * (rem / em / % / vw / vh / dvh / clamp). 1–2px only for hairlines,
 * outlines and shadow offsets.
 */

:root {
    --bg: #07070f;
    --panel: rgba(18, 16, 34, 0.62);
    --panel-strong: rgba(22, 20, 40, 0.92);
    --line: rgba(255, 255, 255, 0.12);
    --text: #f1f0ff;
    --muted: rgba(241, 240, 255, 0.58);
    --accent: #ff3d9a;
    --accent-2: #3de0ff;
    --star: #ffd34d;
    --danger: #ff5a5a;
    --radius: 1.1rem;
    --gap: clamp(0.75rem, 2vw, 1.5rem);
    --ease: cubic-bezier(0.2, 0.8, 0.2, 1);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

/* Universal rule 10: no native text selection / iOS callout. */
html {
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
    -webkit-tap-highlight-color: transparent;
}
input, textarea, [contenteditable="true"] {
    -webkit-user-select: text;
    -moz-user-select: text;
    -ms-user-select: text;
    user-select: text;
    -webkit-touch-callout: default;
}

html, body { height: 100%; }
body {
    min-height: 100dvh;
    background: var(--bg);
    color: var(--text);
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    font-size: clamp(0.95rem, 0.9rem + 0.25vw, 1.05rem);
    display: flex;
    flex-direction: column;
    overflow-x: hidden;
    padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
[hidden] { display: none !important; }
button, select, input { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: none; }
a { color: var(--accent-2); }
.game-link { color: inherit; text-decoration: underline; text-decoration-color: var(--accent-2); text-underline-offset: 0.15em; }
.game-link:hover { color: var(--accent-2); }
svg { width: 1.4em; height: 1.4em; fill: currentColor; display: block; }
.muted { color: var(--muted); }
.hint { color: var(--muted); font-size: 0.85em; line-height: 1.4; }
:focus-visible { outline: 2px solid var(--accent-2); outline-offset: 2px; }

/* ── Backdrop: the current cover, blurred ──────────────────────── */
.backdrop {
    position: fixed; inset: -10%;
    z-index: -1;
    background: radial-gradient(circle at 20% 10%, #3a1450 0%, transparent 55%),
                radial-gradient(circle at 85% 90%, #0b3a4a 0%, transparent 55%), var(--bg);
    background-size: cover;
    background-position: center;
    filter: blur(3.5rem) brightness(0.42) saturate(1.35);
    transition: background-image 0.8s var(--ease);
}

/* ── Top bar ───────────────────────────────────────────────────── */
.topbar {
    display: flex; align-items: center; justify-content: space-between;
    gap: 0.75rem;
    padding: 0.75rem var(--gap);
}
.brand { display: flex; flex-direction: column; line-height: 1.05; min-width: 0; }
.brand-main {
    font-size: clamp(1.2rem, 1rem + 1.2vw, 1.75rem);
    font-weight: 800; letter-spacing: 0.04em;
    background: linear-gradient(90deg, var(--accent), var(--accent-2));
    -webkit-background-clip: text; background-clip: text; color: transparent;
}
.brand-sub { font-size: 0.8em; font-weight: 500; color: var(--muted); letter-spacing: 0.12em; text-transform: uppercase; }
.top-actions { display: flex; align-items: center; gap: 0.4rem; flex-wrap: wrap; justify-content: flex-end; }

.pill {
    display: inline-flex; align-items: center; gap: 0.4em;
    padding: 0.45em 0.9em;
    border-radius: 999em;
    border: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.07);
    text-decoration: none; color: var(--text);
    font-size: 0.9em; font-weight: 600;
    transition: background 0.2s, border-color 0.2s, transform 0.15s;
}
.pill:hover { background: rgba(255, 255, 255, 0.14); }
.pill:active { transform: scale(0.97); }
.pill.small { font-size: 0.78em; padding: 0.3em 0.75em; }
.pill.danger { border-color: rgba(255, 90, 90, 0.5); color: var(--danger); }
.pill.suno svg { width: 1.1em; height: 1.1em; }

.icon-btn {
    display: inline-grid; place-items: center;
    width: 2.6rem; height: 2.6rem;
    border-radius: 50%;
    color: var(--text);
    transition: background 0.2s, color 0.2s, transform 0.15s;
    position: relative;
}
.icon-btn:hover { background: rgba(255, 255, 255, 0.1); }
.icon-btn:active { transform: scale(0.92); }
.icon-btn.toggle { color: var(--muted); }
.icon-btn.toggle.on { color: var(--accent-2); }
.repeat-one {
    position: absolute; right: 0.3rem; bottom: 0.3rem;
    font-size: 0.6rem; font-weight: 800;
    background: var(--accent-2); color: var(--bg);
    border-radius: 999em; padding: 0 0.3em; line-height: 1.3;
}

/* ── Layout ────────────────────────────────────────────────────── */
.layout {
    flex: 1;
    display: grid;
    gap: var(--gap);
    padding: 0 var(--gap) var(--gap);
    min-height: 0;
}
.panel {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    -webkit-backdrop-filter: blur(1.25rem) saturate(1.2);
    backdrop-filter: blur(1.25rem) saturate(1.2);
    box-shadow: 0 1.5rem 3rem rgba(0, 0, 0, 0.35);
}

/* ── Now playing ───────────────────────────────────────────────── */
.now {
    display: flex; flex-direction: column; align-items: center;
    gap: 0.9rem;
    padding: clamp(1rem, 3vw, 1.75rem);
    text-align: center;
}
.cover-wrap {
    position: relative;
    width: min(100%, 22rem, 42dvh);
    aspect-ratio: 1;
    border-radius: calc(var(--radius) * 0.8);
    overflow: hidden;
    box-shadow: 0 1.25rem 3rem rgba(0, 0, 0, 0.5);
    touch-action: pan-y;
}
.cover, .cover-ph { position: absolute; inset: 0; width: 100%; height: 100%; }
.cover { object-fit: cover; }
.cover-ph {
    --hue: 280;
    display: grid; place-items: center;
    font-size: clamp(4rem, 12vw, 7rem);
    color: rgba(255, 255, 255, 0.85);
    background: linear-gradient(135deg, hsl(var(--hue) 70% 45%), hsl(calc(var(--hue) + 60) 70% 25%));
}
.new-badge {
    position: absolute; top: 0.75rem; left: 0.75rem;
    padding: 0.25em 0.7em; border-radius: 999em;
    font-size: 0.75em; font-weight: 800; letter-spacing: 0.08em; text-transform: uppercase;
    background: var(--accent); color: #fff;
    box-shadow: 0 0.25rem 1rem rgba(255, 61, 154, 0.5);
}
.np-meta { width: 100%; }
.np-title { font-size: clamp(1.25rem, 1rem + 1.2vw, 1.75rem); font-weight: 800; line-height: 1.2; overflow-wrap: anywhere; }
.np-sub { color: var(--muted); font-size: 0.88em; margin-top: 0.35rem; line-height: 1.5; }
.suno-song { font-size: 0.95em; }
.tag {
    display: inline-block; font-size: 0.7em; font-weight: 700;
    padding: 0.05em 0.45em; border-radius: 0.3em;
    border: 1px solid var(--line); color: var(--muted);
    vertical-align: middle; letter-spacing: 0.05em; text-transform: uppercase;
}

.np-rating { display: flex; flex-direction: column; align-items: center; gap: 0.25rem; }
.rating-hint { color: var(--muted); font-size: 0.8em; min-height: 1.2em; }
.rating { display: inline-flex; align-items: center; gap: 0.1em; }
.r-btn {
    line-height: 1; padding: 0.15em;
    color: rgba(255, 255, 255, 0.25);
    transition: color 0.15s, transform 0.15s;
}
.r-btn:hover { transform: scale(1.15); }
.r-star.on { color: var(--star); text-shadow: 0 0 0.6em rgba(255, 211, 77, 0.45); }
.r-never { margin-right: 0.2em; }
.r-never.on { color: var(--danger); }
.rating-lg .r-btn { font-size: 2rem; }
.rating-sm .r-btn { font-size: 1.05rem; }

.progress { display: flex; align-items: center; gap: 0.6rem; width: 100%; max-width: 30rem; }
.time { font-variant-numeric: tabular-nums; font-size: 0.8em; color: var(--muted); min-width: 2.8em; }
input[type="range"] {
    -webkit-appearance: none; appearance: none;
    flex: 1; height: 0.35rem; border-radius: 999em;
    background: rgba(255, 255, 255, 0.18);
    cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none; appearance: none;
    width: 1rem; height: 1rem; border-radius: 50%;
    background: var(--text); box-shadow: 0 0 0 0.25rem rgba(61, 224, 255, 0.25);
}
input[type="range"]::-moz-range-thumb {
    width: 1rem; height: 1rem; border-radius: 50%; border: none;
    background: var(--text);
}

.transport { display: flex; align-items: center; justify-content: center; gap: clamp(0.4rem, 2vw, 1rem); }
.transport .icon-btn svg { width: 1.6rem; height: 1.6rem; }
.play-btn {
    display: grid; place-items: center;
    width: 4.25rem; height: 4.25rem; border-radius: 50%;
    background: linear-gradient(135deg, var(--accent), #b44dff);
    color: #fff;
    box-shadow: 0 0.6rem 1.75rem rgba(255, 61, 154, 0.45);
    transition: transform 0.15s var(--ease), box-shadow 0.2s;
}
.play-btn:hover { transform: scale(1.05); }
.play-btn:active { transform: scale(0.95); }
.play-btn svg { width: 2rem; height: 2rem; }
.play-btn .i-pause, .play-btn.playing .i-play { display: none; }
.play-btn.playing .i-pause { display: block; }

.status { min-height: 1.3em; font-size: 0.88em; color: var(--accent-2); }

.library-toggle {
    margin-top: auto;
    padding: 0.7em 1.4em; border-radius: 999em;
    border: 1px solid var(--line); background: rgba(255, 255, 255, 0.07);
    font-weight: 700;
}

/* ── Library ───────────────────────────────────────────────────── */
.library {
    display: flex; flex-direction: column;
    gap: 0.75rem;
    padding: clamp(0.9rem, 2.5vw, 1.25rem);
    min-height: 0;
}
.lib-head { display: flex; align-items: center; justify-content: space-between; }
.lib-head h2 { font-size: 1.2em; font-weight: 800; }
.sheet-grip { display: none; }
.block-label { font-size: 0.78em; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: 0.1em; margin-bottom: 0.4rem; }

.segmented {
    display: grid; grid-template-columns: repeat(3, 1fr);
    padding: 0.25rem; gap: 0.25rem;
    border-radius: 0.9rem; background: rgba(0, 0, 0, 0.3);
    border: 1px solid var(--line);
}
.segmented button {
    display: flex; flex-direction: column; align-items: center; gap: 0.1rem;
    padding: 0.45rem 0.25rem; border-radius: 0.7rem;
    font-size: 0.82em; font-weight: 600; color: var(--muted);
    transition: background 0.2s, color 0.2s;
}
.segmented.auto { grid-template-columns: repeat(auto-fit, minmax(0, 1fr)); }
.segmented button { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.segmented button.on { background: rgba(255, 255, 255, 0.14); color: var(--text); }
.seg-stars { color: var(--star); letter-spacing: 0.05em; font-size: 0.95em; }
.mode-block .hint { margin-top: 0.4rem; }

.cat-block summary { cursor: pointer; font-weight: 700; padding: 0.2rem 0; }
.cat-actions { display: flex; gap: 0.4rem; margin: 0.5rem 0; }
.cat-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(13rem, 100%), 1fr)); gap: 0.25rem 0.75rem; }
.cat { display: flex; align-items: center; gap: 0.5rem; padding: 0.3rem 0; cursor: pointer; font-size: 0.92em; }
.cat-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
input[type="checkbox"] { width: 1.1rem; height: 1.1rem; accent-color: var(--accent); flex: none; }

.lib-tools { display: flex; gap: 0.5rem; }
.lib-tools input, .lib-tools select, .setting-row select {
    padding: 0.55em 0.8em; border-radius: 0.7rem;
    border: 1px solid var(--line); background: rgba(0, 0, 0, 0.35);
}
.lib-tools input { flex: 1; min-width: 0; }
select option { background: var(--panel-strong); }
.lib-count { font-size: 0.82em; color: var(--muted); }

.song-list { list-style: none; overflow-y: auto; flex: 1; min-height: 0; margin: 0 -0.4rem; padding: 0 0.4rem; overscroll-behavior: contain; }
.song {
    display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 0.7rem;
    padding: 0.45rem 0.5rem; border-radius: 0.7rem;
    cursor: pointer;
    transition: background 0.15s, opacity 0.2s;
}
.song:hover { background: rgba(255, 255, 255, 0.07); }
.song.current { background: rgba(255, 61, 154, 0.16); }
.song.current .song-title { color: #ff8cc4; }
.song.out { opacity: 0.45; }
.thumb { width: 2.75rem; height: 2.75rem; border-radius: 0.45rem; object-fit: cover; display: block; }
.thumb.ph { --hue: 280; background: linear-gradient(135deg, hsl(var(--hue) 70% 45%), hsl(calc(var(--hue) + 60) 70% 25%)); }
.song-text { min-width: 0; }
.song-title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.song-meta { font-size: 0.78em; color: var(--muted); }
.empty { padding: 1.5rem 0.5rem; color: var(--muted); text-align: center; list-style: none; }

/* ── Footer ────────────────────────────────────────────────────── */
.footer { display: flex; justify-content: center; gap: 1.25rem; padding: 0 var(--gap) 0.75rem; font-size: 0.78em; }
.footer a { color: var(--muted); text-decoration: none; }
.footer a:hover { color: var(--text); }

/* ── Overlays ──────────────────────────────────────────────────── */
.overlay {
    position: fixed; inset: 0; z-index: 50;
    display: grid; place-items: center;
    padding: var(--gap);
    background: rgba(0, 0, 0, 0.55);
    animation: fade 0.2s var(--ease);
}
.dialog {
    width: min(100%, 26rem);
    max-height: 90dvh; overflow-y: auto;
    padding: 1.25rem;
    background: var(--panel-strong);
    display: flex; flex-direction: column; gap: 0.9rem;
    animation: pop 0.25s var(--ease);
}
.dialog-head { display: flex; align-items: center; justify-content: space-between; }
.dialog-head h2 { font-size: 1.15em; }
.setting-row { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.setting-row input[type="range"] { max-width: 55%; }
.keys-hint { font-size: 0.78em; }
.version { font-size: 0.72em; text-align: center; }
.share-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 0.5rem; }
.share-grid .pill { justify-content: center; padding: 0.7em; }
.share-native { grid-column: 1 / -1; background: linear-gradient(135deg, var(--accent), #b44dff); border: none; }

.toast {
    position: fixed; left: 50%; bottom: calc(1.25rem + env(safe-area-inset-bottom)); z-index: 60;
    transform: translateX(-50%);
    max-width: min(90vw, 28rem);
    padding: 0.7em 1.2em; border-radius: 999em;
    background: var(--panel-strong); border: 1px solid var(--line);
    font-size: 0.9em; text-align: center;
    box-shadow: 0 0.75rem 2rem rgba(0, 0, 0, 0.45);
    animation: pop 0.2s var(--ease);
    cursor: default;
}

@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: translateY(0.5rem) scale(0.98); } }
.toast { animation-name: fade; }

/* ── Desktop: side by side ─────────────────────────────────────── */
@media (min-width: 56rem) {
    body { height: 100dvh; overflow: hidden; }
    .layout { grid-template-columns: minmax(0, 1fr) minmax(0, 1.1fr); }
    .now { justify-content: center; }
    .library-toggle, .close-lib { display: none; }
}

/* ── Phone / narrow: the library is a bottom sheet ─────────────── */
@media (max-width: 55.99rem) {
    .now { min-height: calc(100dvh - 7rem); justify-content: center; }
    .library {
        position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
        height: 88dvh;
        border-radius: var(--radius) var(--radius) 0 0;
        background: var(--panel-strong);
        padding-bottom: calc(1rem + env(safe-area-inset-bottom));
        transform: translateY(105%);
        transition: transform 0.35s var(--ease), visibility 0s linear 0.35s;
        visibility: hidden;
    }
    .library.open { transform: translateY(0); visibility: visible; transition: transform 0.35s var(--ease), visibility 0s; }
    body.sheet-open { overflow: hidden; }
    .sheet-grip { display: block; width: 3rem; height: 0.3rem; margin: -0.2rem auto 0; border-radius: 999em; background: rgba(255, 255, 255, 0.3); }
    .pill.suno span { display: none; }
    .pill.suno { padding: 0.55em; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation: none !important; transition: none !important; }
}
