/* ===== Tokens ===== */
:root {
    --bg: #1a1714;
    --surface: #221d18;
    --surface-2: #2b241d;
    --surface-3: #342c23;
    --border: #3c332a;
    --text: #f2ead9;
    --text-muted: #a89c86;
    --text-faint: #756a5a;
    --accent: #e8a33d;
    --accent-strong: #f4b95a;
    --accent-soft: rgba(232, 163, 61, 0.14);
    --coral: #d9634a;
    --radius-sm: 8px;
    --radius-md: 14px;
    --radius-lg: 22px;
    --font-display: Georgia, "Iowan Old Style", "Palatino Linotype", serif;
    --font-body: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    --font-mono: ui-monospace, "SF Mono", "Cascadia Code", Menlo, Consolas, monospace;
    --player-h: 86px;
    --topbar-h: 76px;
    --player-offset: 24px;
}
:root {
    --player-offset: 24px;
}

#library {
    padding-bottom: calc(var(--player-offset) + env(safe-area-inset-bottom));
}

* {
    box-sizing: border-box;
}

/* The `hidden` attribute must always win over any component's own `display` rule.
   Without this, classes like .ios-hint / .player-bar that set `display: flex`
   unconditionally will override the browser's default [hidden]{display:none},
   since author-origin CSS always beats user-agent CSS regardless of specificity. */
[hidden] {
    display: none !important;
}

html,
body {
    height: 100%;
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font-body);
    -webkit-tap-highlight-color: transparent;
}
body {
    overscroll-behavior-y: none;
}
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.001ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.001ms !important;
    }
}

button {
    font-family: inherit;
}
input {
    font-family: inherit;
    color: inherit;
}

#app {
    min-height: 100%;
}

/* ===== Reel motif (signature element) ===== */
.reel-spin {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    border: 3px solid var(--accent);
    position: relative;
    flex: none;
    background:
        radial-gradient(circle at center, var(--surface-2) 0 32%, transparent 33%),
        conic-gradient(
            from 0deg,
            var(--surface-3) 0 8%,
            transparent 8% 25%,
            var(--surface-3) 25% 33%,
            transparent 33% 50%,
            var(--surface-3) 50% 58%,
            transparent 58% 75%,
            var(--surface-3) 75% 83%,
            transparent 83% 100%
        );
    animation: spin 3.2s linear infinite;
    animation-play-state: paused;
}
.reel-spin .reel-hub {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 9px;
    height: 9px;
    background: var(--accent);
    border-radius: 50%;
    transform: translate(-50%, -50%);
}
.reel-spin.spinning {
    animation-play-state: running;
}
.reel-spin.big {
    width: 88px;
    height: 88px;
    border-width: 6px;
    margin: 0 auto 20px;
}
.reel-spin.big .reel-hub {
    width: 20px;
    height: 20px;
}
@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* ===== Icons ===== */
.icon {
    width: 18px;
    height: 18px;
    stroke: currentColor;
    fill: none;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
    flex: none;
}
.search-wrap .icon {
    stroke: var(--text-faint);
}

/* ===== Buttons ===== */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 9px 14px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--surface-2);
    color: var(--text);
    font-size: 13.5px;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    transition:
        background 0.15s,
        border-color 0.15s,
        transform 0.1s;
}
.btn:hover {
    background: var(--surface-3);
}
.btn:active {
    transform: scale(0.97);
}
.btn.primary {
    background: var(--accent);
    border-color: var(--accent);
    color: #201607;
}
.btn.primary:hover {
    background: var(--accent-strong);
}
.btn.ghost .icon {
    stroke: var(--text-muted);
}
.btn.small {
    padding: 6px 10px;
    font-size: 12.5px;
}
.btn:focus-visible,
.ctl:focus-visible,
input:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

/* ===== Topbar ===== */
#topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    gap: 18px;
    padding: 14px 22px;
    min-height: var(--topbar-h);
    background: rgba(26, 23, 20, 0.92);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--border);
}
.brand {
    display: flex;
    align-items: center;
    gap: 12px;
    flex: none;
}
.brand-text h1 {
    font-family: var(--font-display);
    font-size: 21px;
    margin: 0;
    letter-spacing: 0.3px;
    font-weight: 700;
}
.brand-text p {
    margin: 0;
    font-size: 11.5px;
    color: var(--text-faint);
    font-family: var(--font-mono);
}
.search-wrap {
    flex: 1 1 auto;
    max-width: 420px;
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 9px 16px;
}
.search-wrap input {
    border: none;
    background: transparent;
    outline: none;
    color: var(--text);
    font-size: 14px;
    width: 100%;
}
.search-wrap input::placeholder {
    color: var(--text-faint);
}
.topbar-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-left: auto;
    flex: none;
}

.ios-hint {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    background: var(--accent-soft);
    border-bottom: 1px solid var(--border);
    color: var(--text);
    font-size: 13px;
    padding: 10px 22px;
}
.ios-hint button {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 15px;
}

/* ===== Library ===== */
#library {
    padding: 22px;
    padding-bottom: calc(var(--player-offset) + env(safe-area-inset-bottom));
    max-width: 980px;
    margin: 0 auto;
}

.empty-state {
    text-align: center;
    padding: 64px 20px;
    color: var(--text-muted);
}
.empty-state h2 {
    font-family: var(--font-display);
    font-size: 22px;
    color: var(--text);
    margin: 0 0 8px;
}
.empty-state p {
    max-width: 420px;
    margin: 0 auto;
    font-size: 14px;
    line-height: 1.6;
}
.empty-actions {
    display: flex;
    gap: 10px;
    justify-content: center;
    margin-top: 22px;
}

.folder-group {
    margin-bottom: 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    overflow: hidden;
    background: var(--surface);
}
.folder-header {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 13px 16px;
    background: var(--surface-2);
    border: none;
    color: var(--text);
    cursor: pointer;
    text-align: left;
    font-size: 14.5px;
    font-weight: 600;
}
.folder-header .chev {
    transition: transform 0.18s;
    color: var(--text-faint);
    flex: none;
}
.folder-header[aria-expanded="false"] .chev {
    transform: rotate(-90deg);
}
.folder-name {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.folder-count {
    font-family: var(--font-mono);
    font-size: 11.5px;
    color: var(--text-faint);
    flex: none;
}

.song-list {
    list-style: none;
    margin: 0;
    padding: 4px 0;
}
.song-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 16px;
    cursor: pointer;
    border-top: 1px solid var(--border);
    transition: background 0.12s;
}
.song-row:first-child {
    border-top: none;
}
.song-row:hover {
    background: var(--surface-2);
}
.song-row.active {
    background: var(--accent-soft);
}
.song-row.active .song-name {
    color: var(--accent-strong);
}

.song-play-icon {
    width: 26px;
    height: 26px;
    flex: none;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: var(--surface-3);
    color: var(--text-muted);
    border: none;
    cursor: pointer;
}
.song-row.active .song-play-icon {
    background: var(--accent);
    color: #201607;
}
.song-play-icon svg {
    width: 12px;
    height: 12px;
}

.song-name {
    flex: 1;
    font-size: 14px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.song-duration {
    font-family: var(--font-mono);
    font-size: 12px;
    color: var(--text-faint);
    flex: none;
}
.song-delete {
    flex: none;
    background: none;
    border: none;
    color: var(--text-faint);
    cursor: pointer;
    padding: 6px;
    border-radius: 6px;
    /* Visible by default so touch devices (no hover) can always tap it */
    opacity: 0.55;
    transition:
        opacity 0.12s,
        color 0.12s,
        background 0.12s;
}
.song-delete:hover {
    color: var(--coral);
    background: rgba(217, 99, 74, 0.12);
}
.song-delete svg {
    width: 15px;
    height: 15px;
}

/* Only devices with real hover (mouse/trackpad) get the hidden-until-hover behavior */
@media (hover: hover) and (pointer: fine) {
    .song-delete {
        opacity: 0;
    }
    .song-row:hover .song-delete,
    .song-row:focus-within .song-delete {
        opacity: 1;
    }
}

/* ===== Player bar ===== */
.player-bar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 30;
    display: flex;
    align-items: center;
    gap: 20px;
    padding: 10px 22px;
    padding-bottom: calc(10px + env(safe-area-inset-bottom));
    height: var(--player-h);
    background: rgba(34, 29, 24, 0.96);
    backdrop-filter: blur(14px);
    border-top: 1px solid var(--border);
}

.now-playing {
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 0 0 220px;
    min-width: 0;
}
.track-meta {
    min-width: 0;
}
.track-title {
    font-size: 14px;
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.track-folder {
    font-size: 11.5px;
    color: var(--text-faint);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-family: var(--font-mono);
}

.player-center {
    flex: 1 1 auto;
    min-width: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
}
.transport {
    display: flex;
    align-items: center;
    gap: 6px;
}

.ctl {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    position: relative;
    transition:
        color 0.12s,
        background 0.12s;
}
.ctl:hover {
    color: var(--text);
    background: var(--surface-2);
}
.ctl[aria-pressed="true"] {
    color: var(--accent);
}
.ctl.play {
    width: 42px;
    height: 42px;
    background: var(--accent);
    color: #201607;
}
.ctl.play:hover {
    background: var(--accent-strong);
    color: #201607;
}
.ctl.play .icon {
    width: 19px;
    height: 19px;
}
.ctl.play svg {
    fill: currentColor;
}
.repeat-one-dot {
    position: absolute;
    bottom: 2px;
    right: 2px;
    font-size: 8px;
    font-family: var(--font-mono);
    font-weight: 700;
    background: var(--accent);
    color: #201607;
    border-radius: 50%;
    width: 12px;
    height: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.seek-row {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    max-width: 560px;
}
.time {
    font-family: var(--font-mono);
    font-size: 11px;
    color: var(--text-faint);
    flex: none;
    width: 36px;
    text-align: center;
}

input[type="range"] {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 4px;
    background: var(--surface-3);
    border-radius: 999px;
    outline: none;
    cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 13px;
    height: 13px;
    border-radius: 50%;
    background: var(--accent);
    border: none;
    margin-top: -4.5px;
    box-shadow: 0 0 0 3px rgba(232, 163, 61, 0.18);
}
input[type="range"]::-moz-range-thumb {
    width: 13px;
    height: 13px;
    border-radius: 50%;
    background: var(--accent);
    border: none;
    box-shadow: 0 0 0 3px rgba(232, 163, 61, 0.18);
}
input[type="range"]::-moz-range-track {
    height: 4px;
    background: var(--surface-3);
    border-radius: 999px;
}

.player-extra {
    display: flex;
    align-items: center;
    gap: 6px;
    flex: 0 0 auto;
}
.sleep-wrap {
    position: relative;
}
.sleep-label {
    position: absolute;
    top: -4px;
    right: -6px;
    font-family: var(--font-mono);
    font-size: 9px;
    background: var(--accent);
    color: #201607;
    border-radius: 999px;
    padding: 1px 4px;
    font-weight: 700;
}
.sleep-panel {
    position: absolute;
    bottom: 48px;
    right: 0;
    width: 220px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 14px;
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.4);
}
.sleep-panel-title {
    margin: 0 0 10px;
    font-size: 12.5px;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
}
.sleep-options {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
    margin-bottom: 10px;
}
.sleep-options button {
    background: var(--surface-3);
    border: 1px solid var(--border);
    color: var(--text);
    border-radius: 8px;
    padding: 8px 0;
    font-size: 12.5px;
    cursor: pointer;
}
.sleep-options button:hover {
    background: var(--accent-soft);
    border-color: var(--accent);
}
.sleep-options button.selected {
    background: var(--accent);
    color: #201607;
    border-color: var(--accent);
    font-weight: 700;
}
.sleep-end-toggle {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    color: var(--text-muted);
    margin-bottom: 10px;
    cursor: pointer;
}
.sleep-end-toggle input {
    accent-color: var(--accent);
}

.volume-wrap {
    display: none;
    align-items: center;
    gap: 8px;
}
.volume-wrap input[type="range"] {
    width: 90px;
}

.mobile-only {
    display: inline-flex;
}

.toast {
    position: fixed;
    bottom: calc(var(--player-h) + 16px);
    left: 50%;
    transform: translateX(-50%);
    background: var(--surface-3);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 10px 18px;
    border-radius: 999px;
    font-size: 13px;
    z-index: 50;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
}

/* ===== Floating upload button ===== */
.fab-upload {
    position: fixed;
    right: 20px;
    bottom: calc(var(--player-offset) + env(safe-area-inset-bottom));
    z-index: 35;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 10px;
    transition:
        bottom 0.2s ease,
        right 0.2s ease;
}
/* body.has-now-playing .fab-upload {
    bottom: calc(var(--player-offset) + 14px + env(safe-area-inset-bottom));
} */
.fab-btn {
    width: 54px;
    height: 54px;
    border-radius: 50%;
    background: var(--accent);
    color: #201607;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 10px 26px rgba(0, 0, 0, 0.4);
    transition:
        transform 0.15s,
        background 0.15s;
}
.fab-btn:hover {
    background: var(--accent-strong);
}
.fab-btn:active {
    transform: scale(0.94);
}
.fab-btn .icon {
    width: 24px;
    height: 24px;
    stroke-width: 2.4;
}
.fab-btn[aria-expanded="true"] {
    transform: rotate(45deg);
}

.fab-menu {
    display: flex;
    flex-direction: column;
    gap: 8px;
    align-items: flex-end;
}
.fab-menu-item {
    display: flex;
    align-items: center;
    gap: 10px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 10px 16px;
    border-radius: 999px;
    font-size: 13.5px;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.35);
}
.fab-menu-item:hover {
    background: var(--surface-3);
    border-color: var(--accent);
}
.fab-menu-item .icon {
    stroke: var(--accent);
}

/* ===== Responsive ===== */
@media (min-width: 720px) {
    .volume-wrap {
        display: flex;
    }
    .mobile-only {
        display: none;
    }
}

@media (max-width: 719px) {
    #topbar {
        flex-wrap: wrap;
        gap: 10px;
        padding: 12px 14px;
    }
    .brand {
        flex: 1 1 auto;
    }
    .search-wrap {
        order: 3;
        flex: 1 1 100%;
        max-width: none;
    }
    .topbar-actions .btn span {
        display: none;
    }
    .topbar-actions .btn {
        padding: 9px 11px;
    }
    #library {
        padding: 14px;
        padding-bottom: calc(var(--player-offset) + env(safe-area-inset-bottom));
    }

    .player-bar {
        height: auto;
        flex-wrap: wrap;
        row-gap: 6px;
        padding: 8px 12px calc(2rem + env(safe-area-inset-bottom));
    }
    .now-playing {
        flex: 1 1 auto;
        order: 1;
    }
    .player-extra {
        order: 2;
    }
    .player-center {
        order: 3;
        flex: 1 1 100%;
    }
    .transport {
        width: 100%;
        justify-content: space-between;
    }
    .sleep-panel {
        right: -60px;
    }
    .fab-upload {
        right: 14px;
    }

    /* body.has-now-playing .fab-upload {
        bottom: calc(var(--player-offset) + 14px + env(safe-area-inset-bottom));
    } */

    .fab-btn {
        width: 50px;
        height: 50px;
    }

    .fab-btn .icon {
        width: 22px;
        height: 22px;
    }
}

@media (max-width: 420px) {
    .brand-text p {
        display: none;
    }
}
