/* ==========================================================================
   4th Addiction — stylesheet
   1.  Design tokens
   2.  Reset & base
   3.  Background layers
   4.  Layout
   5.  Card & profile
   6.  Buttons / controls
   7.  Player dock
   8.  Visualizer & progress
   9.  Volume
   10. Playlist
   11. Animations
   12. Responsive
   13. Motion & accessibility preferences
   ========================================================================== */

/* 1. Design tokens ======================================================== */

:root {
    /* palette */
    --bg: #050507;
    --bg-2: #0a0a10;
    --accent: #8b5cf6;
    --accent-2: #22d3ee;

    /* text */
    --text: #f4f4f7;
    --text-muted: rgb(244 244 247 / 58%);
    --text-faint: rgb(244 244 247 / 34%);

    /* surfaces */
    --surface: rgb(255 255 255 / 4%);
    --surface-hover: rgb(255 255 255 / 8%);
    --surface-solid: rgb(9 9 13 / 78%);
    --border: rgb(255 255 255 / 9%);
    --border-strong: rgb(255 255 255 / 18%);

    /* shape */
    --radius-sm: 8px;
    --radius-md: 14px;
    --radius-lg: 22px;
    --radius-pill: 999px;

    /* elevation */
    --shadow-card: 0 24px 60px -20px rgb(0 0 0 / 80%), 0 2px 8px rgb(0 0 0 / 40%);
    --shadow-dock: 0 28px 70px -18px rgb(0 0 0 / 90%);
    --glow-accent: 0 0 24px -4px rgb(139 92 246 / 45%);

    /* motion */
    --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
    --ease-spring: cubic-bezier(0.34, 1.4, 0.64, 1);
    --dur-fast: 160ms;
    --dur: 280ms;
    --dur-slow: 620ms;

    /* runtime values written by JS */
    --level: 0;      /* 0–1 audio amplitude   */
    --progress: 0%;  /* playback position     */
    --volume: 75%;   /* volume slider fill    */
}

/* 2. Reset & base ========================================================= */

*,
*::before,
*::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    -webkit-text-size-adjust: 100%;
}

body {
    min-height: 100vh;
    min-height: 100dvh;
    background: var(--bg);
    color: var(--text);
    font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
    font-size: 16px;
    line-height: 1.5;
    letter-spacing: -0.011em;
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
    overflow-x: hidden;
}

img,
svg,
canvas {
    display: block;
    max-width: 100%;
}

button,
input {
    font: inherit;
    color: inherit;
}

:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 3px;
    border-radius: var(--radius-sm);
}

::selection {
    background: rgb(139 92 246 / 40%);
}

/* 3. Background layers ==================================================== */

.backdrop {
    position: fixed;
    inset: 0;
    z-index: -1;
    pointer-events: none;
    overflow: hidden;
    background: radial-gradient(120% 90% at 50% 0%, var(--bg-2), var(--bg) 60%);
}

/* Slow-drifting colour clouds */
.backdrop__aurora {
    position: absolute;
    inset: -25%;
    background:
        radial-gradient(38% 32% at 22% 28%, rgb(139 92 246 / 22%), transparent 65%),
        radial-gradient(34% 30% at 78% 62%, rgb(34 211 238 / 14%), transparent 65%),
        radial-gradient(30% 40% at 52% 88%, rgb(236 72 153 / 10%), transparent 65%);
    filter: blur(40px);
    animation: aurora-drift 26s var(--ease-out) infinite alternate;
    will-change: transform;
}

.backdrop__particles {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
}

/* Film grain — inline SVG noise, no extra request */
.backdrop__grain {
    position: absolute;
    inset: -50%;
    opacity: 0.035;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='140' height='140'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='3'/%3E%3C/filter%3E%3Crect width='140' height='140' filter='url(%23n)'/%3E%3C/svg%3E");
    animation: grain-shift 8s steps(6) infinite;
}

.backdrop__vignette {
    position: absolute;
    inset: 0;
    background: radial-gradient(115% 85% at 50% 42%, transparent 45%, rgb(0 0 0 / 72%) 100%);
}

/* 4. Layout =============================================================== */

.page {
    display: grid;
    place-items: center;
    min-height: 100vh;
    min-height: 100dvh;
    padding: 48px 20px 260px;
}

/* 5. Card & profile ======================================================= */

.card {
    position: relative;
    width: min(400px, 100%);
    padding: 44px 36px 36px;
    background: linear-gradient(160deg, rgb(255 255 255 / 7%), rgb(255 255 255 / 2.5%));
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-card);
    backdrop-filter: blur(22px) saturate(140%);
    -webkit-backdrop-filter: blur(22px) saturate(140%);
    text-align: center;
    overflow: hidden;
}

/* Sheen along the top edge */
.card::before {
    content: '';
    position: absolute;
    inset-inline: 12%;
    top: 0;
    height: 1px;
    background: linear-gradient(90deg, transparent, rgb(255 255 255 / 55%), transparent);
}

.profile {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
}

/* Avatar with beat-reactive halo ----------------------------------------- */

.avatar {
    position: relative;
    display: grid;
    place-items: center;
    width: 128px;
    height: 128px;
    margin-bottom: 6px;
}

.avatar__ring,
.avatar__glow {
    position: absolute;
    inset: 0;
    border-radius: 50%;
}

.avatar__ring {
    background: conic-gradient(from 0deg,
        transparent 0deg 90deg,
        var(--accent) 170deg,
        var(--accent-2) 220deg,
        transparent 300deg 360deg);
    filter: blur(7px);
    opacity: calc(0.3 + var(--level) * 0.55);
    animation: spin 7s linear infinite;
    transition: opacity 120ms linear;
}

.avatar__glow {
    box-shadow: 0 0 0 1px rgb(255 255 255 / 12%),
                0 0 calc(18px + var(--level) * 44px) rgb(139 92 246 / 45%);
    transform: scale(calc(1 + var(--level) * 0.07));
    transition: transform 120ms var(--ease-out), box-shadow 120ms linear;
}

.avatar__img {
    position: relative;
    width: 112px;
    height: 112px;
    border-radius: 50%;
    object-fit: cover;
    border: 1px solid rgb(255 255 255 / 22%);
    background: var(--bg-2);
}

/* Plays once when the live Discord avatar replaces the fallback image. */
.avatar__img.is-fresh {
    animation: avatar-in 520ms var(--ease-out);
}

/* Discord presence dot — only shown when the API reports a status. */
.avatar__status {
    position: absolute;
    right: 10px;
    bottom: 10px;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #80848e;
    border: 3px solid #0b0b11;
    box-shadow: 0 0 12px -2px currentColor;
    animation: reveal-up 400ms var(--ease-out) both;
}

.avatar__status[data-status='online'] { background: #23a55a; color: #23a55a; }
.avatar__status[data-status='idle']   { background: #f0b232; color: #f0b232; }
.avatar__status[data-status='dnd']    { background: #f23f43; color: #f23f43; }
.avatar__status[data-status='offline'] { background: #80848e; color: transparent; }

/* Text ------------------------------------------------------------------- */

.profile__name {
    font-size: 2rem;
    font-weight: 700;
    line-height: 1.1;
    background: linear-gradient(180deg, #fff, rgb(255 255 255 / 62%));
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}

.profile__handle {
    font-family: 'JetBrains Mono', ui-monospace, monospace;
    font-size: 0.82rem;
    color: var(--text-muted);
    letter-spacing: 0.02em;
}

.profile__stats {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-top: 4px;
    font-size: 0.75rem;
    color: var(--text-faint);
}

.stat b {
    color: var(--text);
    font-weight: 600;
}

.stat--live {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.stat__sep {
    width: 3px;
    height: 3px;
    border-radius: 50%;
    background: var(--text-faint);
}

.pulse {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--text-faint);
    transition: background var(--dur) var(--ease-out), box-shadow var(--dur) var(--ease-out);
}

body.is-playing .pulse {
    background: var(--accent-2);
    box-shadow: 0 0 0 0 rgb(34 211 238 / 60%);
    animation: pulse-ring 1.9s var(--ease-out) infinite;
}

/* 6. Buttons & controls =================================================== */

.btn {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    margin-top: 18px;
    padding: 10px 20px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-pill);
    background: var(--surface);
    color: var(--text-muted);
    font-size: 0.83rem;
    font-weight: 500;
    text-decoration: none;
    overflow: hidden;
    transition: color var(--dur) var(--ease-out),
                border-color var(--dur) var(--ease-out),
                transform var(--dur) var(--ease-spring),
                box-shadow var(--dur) var(--ease-out);
}

/* Light sweep on hover */
.btn::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(110deg, transparent 30%, rgb(255 255 255 / 16%) 50%, transparent 70%);
    transform: translateX(-120%);
    transition: transform var(--dur-slow) var(--ease-out);
}

.btn:hover {
    color: var(--text);
    border-color: rgb(139 92 246 / 55%);
    transform: translateY(-2px);
    box-shadow: var(--glow-accent);
}

.btn:hover::after {
    transform: translateX(120%);
}

.btn:active {
    transform: translateY(0) scale(0.98);
}

.btn svg {
    width: 16px;
    height: 16px;
    fill: currentColor;
    flex-shrink: 0;
}

/* Player transport buttons ----------------------------------------------- */

.ctrl {
    display: grid;
    place-items: center;
    width: 34px;
    height: 34px;
    border: none;
    border-radius: 50%;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    transition: color var(--dur-fast) var(--ease-out),
                background var(--dur-fast) var(--ease-out),
                transform var(--dur-fast) var(--ease-spring);
}

.ctrl svg {
    width: 18px;
    height: 18px;
    fill: currentColor;
}

.ctrl:hover {
    color: var(--text);
    background: var(--surface-hover);
    transform: scale(1.08);
}

.ctrl:active {
    transform: scale(0.94);
}

.ctrl--sm {
    width: 26px;
    height: 26px;
}

.ctrl--sm svg {
    width: 14px;
    height: 14px;
}

.ctrl--play {
    position: relative;
    width: 46px;
    height: 46px;
    color: var(--text);
    background: linear-gradient(150deg, rgb(255 255 255 / 16%), rgb(255 255 255 / 6%));
    border: 1px solid var(--border-strong);
}

.ctrl--play svg {
    width: 20px;
    height: 20px;
}

.ctrl--play:hover {
    background: linear-gradient(150deg, rgb(139 92 246 / 42%), rgb(34 211 238 / 22%));
    border-color: rgb(139 92 246 / 60%);
    box-shadow: var(--glow-accent);
}

/* Play / pause icon crossfade */
.ctrl__icon {
    position: absolute;
    transition: opacity var(--dur-fast) var(--ease-out),
                transform var(--dur) var(--ease-spring);
}

.ctrl__icon--pause,
.ctrl__icon--muted {
    opacity: 0;
    transform: scale(0.6);
}

body.is-playing .ctrl__icon--play {
    opacity: 0;
    transform: scale(0.6);
}

body.is-playing .ctrl__icon--pause {
    opacity: 1;
    transform: scale(1);
}

#muteBtn {
    position: relative;
}

#muteBtn.is-muted .ctrl__icon--vol {
    opacity: 0;
    transform: scale(0.6);
}

#muteBtn.is-muted .ctrl__icon--muted {
    opacity: 1;
    transform: scale(1);
}

/* 7. Player dock ========================================================== */

.player {
    position: fixed;
    bottom: 20px;
    left: 50%;
    z-index: 100;
    display: flex;
    gap: 20px;
    width: min(660px, calc(100vw - 28px));
    padding: 18px 22px;
    background: var(--surface-solid);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-dock);
    backdrop-filter: blur(26px) saturate(150%);
    -webkit-backdrop-filter: blur(26px) saturate(150%);
    transform: translateX(-50%);
}

.player::before {
    content: '';
    position: absolute;
    inset-inline: 15%;
    top: 0;
    height: 1px;
    background: linear-gradient(90deg, transparent, rgb(255 255 255 / 40%), transparent);
}

.player__main {
    display: flex;
    flex: 1;
    flex-direction: column;
    min-width: 0;
}

.player__side {
    flex-shrink: 0;
    width: 190px;
    padding-left: 18px;
    border-left: 1px solid var(--border);
}

.player__eyebrow {
    font-size: 0.62rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.16em;
    color: var(--text-faint);
}

.player__eyebrow--side {
    margin-bottom: 8px;
}

.player__meta {
    margin-bottom: 12px;
}

.player__title {
    font-size: 1.02rem;
    font-weight: 600;
    line-height: 1.35;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.player__sub {
    font-size: 0.7rem;
    color: var(--text-faint);
}

/* Title swap animation */
.player__title.is-swapping {
    animation: title-swap 420ms var(--ease-out);
}

.player__times {
    display: flex;
    justify-content: space-between;
    margin-top: 6px;
    font-family: 'JetBrains Mono', ui-monospace, monospace;
    font-size: 0.65rem;
    color: var(--text-faint);
    font-variant-numeric: tabular-nums;
}

/* 8. Visualizer & progress ================================================ */

.visualizer {
    width: 100%;
    height: 42px;
    margin-bottom: 10px;
    opacity: 0.55;
    transition: opacity var(--dur-slow) var(--ease-out);
}

body.is-playing .visualizer {
    opacity: 1;
}

.progress {
    --thumb: 11px;
    padding-block: 7px;
    cursor: pointer;
    touch-action: none;
}

.progress__track {
    position: relative;
    height: 4px;
    background: rgb(255 255 255 / 10%);
    border-radius: var(--radius-pill);
    transition: height var(--dur-fast) var(--ease-out);
}

.progress__fill {
    position: absolute;
    inset: 0 auto 0 0;
    width: var(--progress);
    background: linear-gradient(90deg, var(--accent), var(--accent-2));
    border-radius: inherit;
    box-shadow: 0 0 12px -2px rgb(139 92 246 / 70%);
}

.progress__thumb {
    position: absolute;
    top: 50%;
    left: var(--progress);
    width: var(--thumb);
    height: var(--thumb);
    background: #fff;
    border-radius: 50%;
    box-shadow: 0 0 0 4px rgb(139 92 246 / 25%);
    transform: translate(-50%, -50%) scale(0);
    transition: transform var(--dur-fast) var(--ease-spring);
}

.progress:hover .progress__track,
.progress:focus-visible .progress__track,
.progress.is-scrubbing .progress__track {
    height: 6px;
}

.progress:hover .progress__thumb,
.progress:focus-visible .progress__thumb,
.progress.is-scrubbing .progress__thumb {
    transform: translate(-50%, -50%) scale(1);
}

/* 9. Volume =============================================================== */

.controls {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 14px;
    margin-top: 10px;
}

.volume {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    margin-top: 10px;
}

.volume__slider {
    -webkit-appearance: none;
    appearance: none;
    width: 104px;
    height: 4px;
    border-radius: var(--radius-pill);
    background: linear-gradient(90deg,
        rgb(255 255 255 / 65%) var(--volume),
        rgb(255 255 255 / 10%) var(--volume));
    cursor: pointer;
    outline: none;
}

.volume__slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 11px;
    height: 11px;
    border: none;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 0 0 0 rgb(255 255 255 / 22%);
    transition: box-shadow var(--dur-fast) var(--ease-out);
}

.volume__slider:hover::-webkit-slider-thumb,
.volume__slider:focus-visible::-webkit-slider-thumb {
    box-shadow: 0 0 0 5px rgb(139 92 246 / 30%);
}

.volume__slider::-moz-range-thumb {
    width: 11px;
    height: 11px;
    border: none;
    border-radius: 50%;
    background: #fff;
}

/* 10. Playlist ============================================================ */

.playlist {
    display: flex;
    flex-direction: column;
    gap: 2px;
    max-height: 158px;
    overflow-y: auto;
    list-style: none;
    scrollbar-width: thin;
    scrollbar-color: rgb(255 255 255 / 18%) transparent;
    overscroll-behavior: contain;
}

.playlist::-webkit-scrollbar {
    width: 4px;
}

.playlist::-webkit-scrollbar-thumb {
    background: rgb(255 255 255 / 16%);
    border-radius: var(--radius-pill);
}

.playlist__item {
    position: relative;
    display: flex;
    align-items: center;
    gap: 9px;
    width: 100%;
    padding: 7px 10px;
    border: none;
    border-radius: var(--radius-sm);
    background: transparent;
    text-align: left;
    cursor: pointer;
    transition: background var(--dur-fast) var(--ease-out),
                transform var(--dur-fast) var(--ease-out);
}

.playlist__item:hover {
    background: var(--surface-hover);
    transform: translateX(2px);
}

.playlist__item.is-active {
    background: linear-gradient(90deg, rgb(139 92 246 / 22%), rgb(255 255 255 / 4%));
}

/* Accent marker on the active row */
.playlist__item.is-active::before {
    content: '';
    position: absolute;
    left: 0;
    top: 20%;
    bottom: 20%;
    width: 2px;
    border-radius: var(--radius-pill);
    background: linear-gradient(var(--accent), var(--accent-2));
}

.playlist__num {
    flex-shrink: 0;
    width: 14px;
    font-family: 'JetBrains Mono', ui-monospace, monospace;
    font-size: 0.68rem;
    color: var(--text-faint);
    font-variant-numeric: tabular-nums;
}

.playlist__name {
    flex: 1;
    min-width: 0;
    font-size: 0.79rem;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    transition: color var(--dur-fast) var(--ease-out);
}

.playlist__item.is-active .playlist__name {
    color: var(--text);
    font-weight: 500;
}

.playlist__item.is-active .playlist__num {
    display: none;
}

/* Mini equalizer shown on the active row */
.eq {
    display: none;
    align-items: flex-end;
    gap: 2px;
    flex-shrink: 0;
    width: 14px;
    height: 11px;
}

.playlist__item.is-active .eq {
    display: flex;
}

.eq i {
    flex: 1;
    height: 30%;
    border-radius: 1px;
    background: var(--accent-2);
    animation: eq-bounce 900ms var(--ease-out) infinite alternate;
    animation-play-state: paused;
}

.eq i:nth-child(2) { animation-duration: 620ms; }
.eq i:nth-child(3) { animation-duration: 780ms; }

body.is-playing .eq i {
    animation-play-state: running;
}

/* 11. Animations ========================================================== */

@keyframes aurora-drift {
    0%   { transform: translate3d(0, 0, 0) scale(1); }
    50%  { transform: translate3d(3%, -2%, 0) scale(1.08); }
    100% { transform: translate3d(-3%, 2%, 0) scale(1.03); }
}

@keyframes grain-shift {
    0%   { transform: translate(0, 0); }
    20%  { transform: translate(-6%, 4%); }
    40%  { transform: translate(4%, -5%); }
    60%  { transform: translate(-3%, -3%); }
    80%  { transform: translate(5%, 3%); }
    100% { transform: translate(0, 0); }
}

@keyframes spin {
    to { transform: rotate(1turn); }
}

@keyframes pulse-ring {
    0%   { box-shadow: 0 0 0 0 rgb(34 211 238 / 55%); }
    70%  { box-shadow: 0 0 0 7px rgb(34 211 238 / 0%); }
    100% { box-shadow: 0 0 0 0 rgb(34 211 238 / 0%); }
}

@keyframes eq-bounce {
    from { height: 22%; opacity: 0.6; }
    to   { height: 100%; opacity: 1; }
}

@keyframes avatar-in {
    from { opacity: 0; transform: scale(0.9); filter: blur(4px); }
    to   { opacity: 1; transform: none; filter: none; }
}

@keyframes title-swap {
    from { opacity: 0; transform: translateY(6px); filter: blur(3px); }
    to   { opacity: 1; transform: none; filter: none; }
}

/* Entrance reveal */
.reveal {
    animation: reveal-up var(--dur-slow) var(--ease-out) both;
    animation-delay: var(--reveal-delay, 0ms);
}

@keyframes reveal-up {
    from { opacity: 0; transform: translateY(22px) scale(0.985); filter: blur(6px); }
    to   { opacity: 1; transform: none; filter: none; }
}

/* The dock is horizontally centred with a transform, so it needs its own
   keyframes to avoid the reveal overwriting translateX(-50%). */
.player.reveal {
    animation-name: reveal-dock;
}

@keyframes reveal-dock {
    from { opacity: 0; transform: translate(-50%, 26px); filter: blur(6px); }
    to   { opacity: 1; transform: translate(-50%, 0); filter: none; }
}

/* Staggered playlist rows, applied when the list is built */
.playlist__item {
    animation: reveal-row 420ms var(--ease-out) both;
    animation-delay: calc(320ms + var(--row-index, 0) * 55ms);
}

@keyframes reveal-row {
    from { opacity: 0; transform: translateX(-8px); }
    to   { opacity: 1; transform: none; }
}

/* 12. Responsive ========================================================== */

@media (max-width: 700px) {
    .player {
        flex-direction: column;
        bottom: 12px;
        width: calc(100vw - 20px);
        padding: 16px 18px calc(16px + env(safe-area-inset-bottom, 0px));
        gap: 14px;
    }

    .player__side {
        width: 100%;
        padding-left: 0;
        padding-top: 12px;
        border-left: none;
        border-top: 1px solid var(--border);
    }

    .playlist {
        max-height: 124px;
    }

    /* iOS / Android handle volume at the OS level */
    .volume {
        display: none;
    }

    .page {
        padding: 32px 16px 320px;
    }

    .card {
        padding: 36px 24px 28px;
    }

    .avatar {
        width: 108px;
        height: 108px;
    }

    .avatar__img {
        width: 94px;
        height: 94px;
    }

    .profile__name {
        font-size: 1.7rem;
    }
}

@media (max-width: 380px) {
    .controls {
        gap: 10px;
    }
}

/* Wider screens: a touch more breathing room */
@media (min-width: 1100px) and (min-height: 800px) {
    .card {
        padding: 52px 40px 40px;
    }
}

/* 13. Motion & accessibility preferences ================================== */

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }

    .backdrop__grain,
    .backdrop__aurora {
        animation: none;
    }

    .reveal,
    .playlist__item {
        opacity: 1;
        filter: none;
    }

    .player.reveal {
        transform: translateX(-50%);
    }
}

@media (prefers-contrast: more) {
    :root {
        --text-muted: rgb(244 244 247 / 82%);
        --text-faint: rgb(244 244 247 / 65%);
        --border: rgb(255 255 255 / 28%);
        --border-strong: rgb(255 255 255 / 45%);
    }
}
