:root {
    --bg: #f2e9da;
    --bg-glow: radial-gradient(ellipse 1000px 560px at 50% -10%, #fff6e8 0%, transparent 60%);
    --panel: #fffaf1;
    --panel-line: rgba(60, 40, 20, 0.12);
    --wood-a: #b98a56;
    --wood-b: #7c5636;
    --vinyl: #16130f;
    --vinyl-groove: rgba(255, 255, 255, 0.05);
    --vinyl-sheen: rgba(255, 255, 255, 0.13);
    --accent: #bb6a2a;
    --accent-soft: rgba(187, 106, 42, 0.14);
    --accent-ink: #fffaf1;
    --text: #2c2015;
    --text-dim: #6c5a47;
    --text-faint: #a3907a;
    --shadow: 0 24px 46px rgba(60, 40, 20, 0.14);
    --radius: 22px;
    --knob-a: #4a3c2c;
    --knob-b: #221a10;
    --danger: #a53a2c;
    --danger-soft: rgba(165, 58, 44, 0.1);
    font-size: 17px;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    background: var(--bg-glow), var(--bg);
    color: var(--text);
    font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    display: flex;
    justify-content: center;
    padding: 40px 20px 70px;
}

h1, h2, h3 {
    font-family: "Fraunces", Georgia, serif;
    font-weight: 600;
    margin: 0;
}

.app {
    width: 100%;
    max-width: 740px;
}

/* ---------- Top bar ---------- */

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 34px;
}

.device {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
}

.device h1 {
    font-size: 1.7rem;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.device-dot {
    flex: 0 0 auto;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--text-faint);
}

.device-dot.live {
    background: var(--accent);
    animation: pulse 1.8s infinite;
}

@keyframes pulse {
    0% { box-shadow: 0 0 0 0 rgba(187, 106, 42, 0.4); }
    70% { box-shadow: 0 0 0 10px rgba(187, 106, 42, 0); }
    100% { box-shadow: 0 0 0 0 rgba(187, 106, 42, 0); }
}

.topbar-actions {
    display: flex;
    gap: clamp(6px, 2vw, 10px);
    flex: 0 0 auto;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.chip-btn {
    font: inherit;
    font-size: clamp(0.78rem, 2.6vw, 0.9rem);
    font-weight: 500;
    letter-spacing: 0.02em;
    color: var(--text);
    background: var(--accent-soft);
    border: 1px solid transparent;
    border-radius: 999px;
    padding: 9px clamp(10px, 4vw, 18px);
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease, transform 0.1s ease;
}

.chip-btn:hover {
    background: var(--accent);
    color: var(--accent-ink);
}

.chip-btn:active {
    transform: scale(0.96);
}

.chip-btn.ghost {
    background: transparent;
    border-color: var(--panel-line);
    color: var(--text-dim);
}

.chip-btn.ghost:hover {
    background: var(--panel);
    color: var(--text);
}

/* ---------- Zone picker ---------- */

.zone-picker {
    position: relative;
    min-width: 0;
}

#zone-btn {
    max-width: 38vw;
    overflow: hidden;
}

#zone-btn-label {
    display: inline-block;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    vertical-align: middle;
}

.zone-menu {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    z-index: 10;
    min-width: 200px;
    max-width: 70vw;
    display: flex;
    flex-direction: column;
    gap: 2px;
    background: var(--panel);
    border: 1px solid var(--panel-line);
    border-radius: 14px;
    box-shadow: var(--shadow);
    padding: 8px;
}

.zone-menu[hidden] {
    display: none;
}

.zone-option {
    all: unset;
    box-sizing: border-box;
    width: 100%;
    cursor: pointer;
    padding: 10px 12px;
    border-radius: 9px;
    font-size: 0.9rem;
    color: var(--text-dim);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.zone-option:hover {
    background: var(--accent-soft);
    color: var(--text);
}

.zone-option.active {
    color: var(--accent);
    font-weight: 600;
}

.zone-menu-empty {
    padding: 10px 12px;
    color: var(--text-faint);
    font-size: 0.88rem;
}

/* ---------- Deck / turntable ---------- */

.deck {
    background: var(--panel);
    border: 1px solid var(--panel-line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 48px clamp(16px, 6vw, 36px) 38px;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.turntable-wrap {
    position: relative;
    width: 340px;
    height: 340px;
    margin-bottom: 10px;
}

.platter {
    position: absolute;
    inset: 0;
    border-radius: 50%;
    background: #050403;
    box-shadow:
        inset 0 0 0 8px #1a1512,
        0 18px 38px rgba(60, 40, 20, 0.28);
}

.vinyl {
    position: absolute;
    inset: 13px;
    border-radius: 50%;
    background:
        radial-gradient(circle at 35% 30%, var(--vinyl-sheen), transparent 42%),
        repeating-radial-gradient(circle at center, var(--vinyl) 0px, var(--vinyl) 2px, var(--vinyl-groove) 2.6px, var(--vinyl) 3.2px);
    box-shadow: inset 0 0 14px rgba(0, 0, 0, 0.6);
}

.vinyl.spinning {
    animation: spin 2.6s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.label {
    position: absolute;
    inset: 32%;
    border-radius: 50%;
    background-color: #2a2118;
    background-size: cover;
    background-position: center;
    box-shadow: 0 0 0 4px #0b0b0c, inset 0 2px 8px rgba(0, 0, 0, 0.4);
}

.label::after {
    content: "";
    position: absolute;
    inset: 46%;
    border-radius: 50%;
    background: #0b0b0c;
    box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.08);
}

.tonearm {
    position: absolute;
    top: -8px;
    right: -24px;
    width: 156px;
    height: 194px;
    transform: rotate(-24deg);
    transform-origin: 115px 24px;
    transition: transform 0.6s cubic-bezier(0.34, 1.2, 0.4, 1);
    z-index: 2;
}

.tonearm.active {
    transform: rotate(2deg);
}

.tonearm-base {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: #2a2118;
    box-shadow: 0 2px 8px rgba(60, 40, 20, 0.35), inset 0 0 0 4px #40311f;
}

.tonearm-arm {
    position: absolute;
    top: 20px;
    right: 20px;
    width: 8px;
    height: 168px;
    border-radius: 5px;
    background: linear-gradient(180deg, #d8bd8f, #a9895c);
    transform-origin: top center;
}

.tonearm-head {
    position: absolute;
    bottom: -5px;
    right: 10px;
    width: 21px;
    height: 13px;
    border-radius: 4px;
    background: #241a0f;
}

/* ---------- Now playing ---------- */

.now-playing {
    text-align: center;
    margin-top: 28px;
    max-width: 100%;
}

.source-badge {
    display: inline-block;
    margin-bottom: 10px;
    padding: 4px 12px;
    background: var(--accent-soft);
    color: var(--accent);
    border-radius: 999px;
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.source-badge[hidden] {
    display: none;
}

.playlist-name {
    margin: 0 0 4px;
    color: var(--text-faint);
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.playlist-name[hidden] {
    display: none;
}

.now-playing h2 {
    font-size: 1.7rem;
    color: var(--text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.now-playing p {
    margin: 8px 0 0;
    color: var(--text-dim);
    font-size: 1.05rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ---------- Transport controls ---------- */

.transport {
    display: flex;
    align-items: center;
    gap: clamp(8px, 3vw, 26px);
    margin-top: 32px;
}

.ctrl-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: clamp(44px, 11vw, 58px);
    height: clamp(44px, 11vw, 58px);
    border-radius: 50%;
    border: 1px solid var(--panel-line);
    background: transparent;
    color: var(--text-dim);
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease, transform 0.1s ease;
}

.ctrl-btn:hover {
    color: var(--text);
    background: rgba(60, 40, 20, 0.05);
}

.ctrl-btn:active {
    transform: scale(0.94);
}

.ctrl-btn.primary {
    width: clamp(58px, 15vw, 78px);
    height: clamp(58px, 15vw, 78px);
    background: var(--accent);
    color: var(--accent-ink);
    border: none;
}

.ctrl-btn.primary:hover {
    background: #cd7b37;
}

.ctrl-btn .icon-pause {
    display: none;
}

.ctrl-btn.is-playing .icon-play {
    display: none;
}

.ctrl-btn.is-playing .icon-pause {
    display: block;
}

/* ---------- Knob controls (shuffle / repeat) ---------- */

.knob-control {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 9px;
}

.knob {
    position: relative;
    width: clamp(44px, 11vw, 58px);
    height: clamp(44px, 11vw, 58px);
    border-radius: 50%;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    background: radial-gradient(circle at 35% 28%, var(--knob-a), var(--knob-b) 72%);
    box-shadow:
        0 3px 6px rgba(60, 40, 20, 0.35),
        inset 0 1px 2px rgba(255, 255, 255, 0.14),
        inset 0 -3px 4px rgba(0, 0, 0, 0.35);
    color: #8a7a66;
    transition: color 0.2s ease, box-shadow 0.2s ease;
}

.knob svg {
    width: 22px;
    height: 22px;
    position: relative;
    z-index: 1;
}

.knob.active {
    color: var(--accent);
    box-shadow:
        0 0 0 4px var(--accent-soft),
        0 3px 6px rgba(60, 40, 20, 0.35),
        inset 0 1px 2px rgba(255, 255, 255, 0.18),
        inset 0 -3px 4px rgba(0, 0, 0, 0.35);
}

.knob:active {
    transform: scale(0.94);
}

.knob-badge {
    position: absolute;
    top: -3px;
    right: -3px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--accent);
    color: var(--accent-ink);
    font-size: 0.65rem;
    font-weight: 700;
    line-height: 18px;
    text-align: center;
    display: none;
    z-index: 2;
}

.knob.repeat-one .knob-badge {
    display: block;
}

.knob-led {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--panel-line);
}

.knob.active + .knob-led {
    background: var(--accent);
    box-shadow: 0 0 5px var(--accent);
}

.knob-label {
    font-size: 0.68rem;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--text-faint);
}

/* ---------- Volume ---------- */

.volume-section {
    width: 100%;
    max-width: 420px;
    margin-top: 38px;
}

.volume-heading {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    margin-bottom: 10px;
}

.volume-heading span:first-child {
    font-size: 0.72rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--text-faint);
}

.volume-row {
    display: flex;
    align-items: center;
    gap: 14px;
    width: 100%;
}

.volume-track-wrap {
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
    gap: 9px;
}

.volume-ticks {
    position: relative;
    height: 5px;
}

.volume-tick {
    position: absolute;
    top: 0;
    /* The thumb is 22px wide, so its center travels from 11px to
       (100% - 11px); mirror that so each tick sits exactly under the
       thumb's resting position for its level. */
    left: calc(11px + (100% - 22px) * var(--level) / 100);
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: var(--panel-line);
    transform: translateX(-50%);
    transition: background 0.15s ease, box-shadow 0.15s ease;
}

.volume-tick.active {
    background: var(--accent);
    box-shadow: 0 0 5px var(--accent);
}

#volume-label {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-dim);
    text-align: right;
    flex: 0 0 auto;
    font-variant-numeric: tabular-nums;
}

input[type="range"]:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

input[type="range"] {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 24px;
    border-radius: 8px;
    outline: none;
    background:
        repeating-linear-gradient(
            90deg,
            var(--text-faint) 0,
            var(--text-faint) 2px,
            transparent 2px,
            transparent 24px
        ),
        var(--panel-line);
    background-repeat: repeat-x, no-repeat;
    background-position: center, center;
    background-size: auto 14px, 100% 14px;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 22px;
    height: 42px;
    border-radius: 6px;
    background: linear-gradient(180deg, #f0d19d, var(--accent) 55%, #a5601f);
    box-shadow: 0 2px 5px rgba(60, 40, 20, 0.45), inset 0 1px 0 rgba(255, 255, 255, 0.5);
    border: 1px solid rgba(40, 25, 10, 0.3);
    cursor: pointer;
    margin-top: -9px;
}

input[type="range"]::-moz-range-thumb {
    width: 22px;
    height: 42px;
    border-radius: 6px;
    background: linear-gradient(180deg, #f0d19d, var(--accent) 55%, #a5601f);
    box-shadow: 0 2px 5px rgba(60, 40, 20, 0.45), inset 0 1px 0 rgba(255, 255, 255, 0.5);
    border: 1px solid rgba(40, 25, 10, 0.3);
    cursor: pointer;
}

input[type="range"]::-webkit-slider-runnable-track {
    height: 24px;
    border-radius: 8px;
}

input[type="range"]::-moz-range-track {
    height: 24px;
    border-radius: 8px;
    background:
        repeating-linear-gradient(
            90deg,
            var(--text-faint) 0,
            var(--text-faint) 2px,
            transparent 2px,
            transparent 24px
        ),
        var(--panel-line);
    background-repeat: repeat-x, no-repeat;
    background-position: center, center;
    background-size: auto 14px, 100% 14px;
}

.crossfade-btn {
    all: unset;
    box-sizing: border-box;
    width: 100%;
    margin-top: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    font: inherit;
    font-size: 0.85rem;
    font-weight: 600;
    letter-spacing: 0.02em;
    color: #8a7a66;
    background: linear-gradient(180deg, var(--knob-a), var(--knob-b));
    border: 1px solid rgba(0, 0, 0, 0.25);
    border-radius: 9px;
    padding: 11px 0;
    cursor: pointer;
    box-shadow: 0 2px 4px rgba(60, 40, 20, 0.3), inset 0 1px 0 rgba(255, 255, 255, 0.08);
    transition: color 0.15s ease, box-shadow 0.15s ease;
}

.crossfade-btn:hover {
    color: var(--accent);
}

.crossfade-btn:active {
    transform: translateY(1px);
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.4);
}

.crossfade-led {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--panel-line);
    flex: 0 0 auto;
}

.crossfade-btn.active {
    color: var(--accent);
    box-shadow:
        0 0 0 3px var(--accent-soft),
        0 2px 4px rgba(60, 40, 20, 0.3),
        inset 0 1px 0 rgba(255, 255, 255, 0.08);
}

.crossfade-btn.active .crossfade-led {
    background: var(--accent);
    box-shadow: 0 0 6px var(--accent);
}

/* ---------- Favorites shelf ---------- */

.shelf-section {
    margin-top: 40px;
}

.shelf-section h3 {
    font-size: 1.05rem;
    color: var(--text-dim);
    font-weight: 500;
    font-family: "Inter", sans-serif;
    letter-spacing: 0.03em;
    text-transform: uppercase;
    margin: 0 4px 16px;
}

.shelf-viewport {
    max-width: 700px;
    margin: 0 auto;
    position: relative;
    -webkit-mask-image: linear-gradient(90deg, transparent 0, #000 40px, #000 calc(100% - 40px), transparent 100%);
    mask-image: linear-gradient(90deg, transparent 0, #000 40px, #000 calc(100% - 40px), transparent 100%);
}

.shelf {
    display: flex;
    gap: 20px;
    overflow-x: auto;
    overflow-y: hidden;
    padding: 28px 40px 24px;
    scrollbar-width: none;
}

.shelf::-webkit-scrollbar {
    display: none;
}

.shelf-ledge {
    height: 12px;
    max-width: 700px;
    margin: -16px auto 0;
    border-radius: 4px;
    background: linear-gradient(180deg, var(--wood-a), var(--wood-b));
    box-shadow: 0 10px 18px rgba(60, 40, 20, 0.22);
}

.record {
    all: unset;
    flex: 0 0 auto;
    width: 190px;
    display: flex;
    flex-direction: column;
    align-items: center;
    cursor: pointer;
}

.record:hover .record-art {
    transform: translateY(-14px) rotate(-3deg);
}

.record-art {
    position: relative;
    transition: transform 0.2s ease;
    width: 190px;
    height: 190px;
}

.record-sleeve {
    position: absolute;
    top: 12px;
    left: 24px;
    width: 190px;
    height: 190px;
    border-radius: 12px;
    background: #2b2b2b;
    box-shadow: 0 6px 14px rgba(60, 40, 20, 0.28);
}

.record-disc {
    position: absolute;
    inset: 0;
    border-radius: 50%;
    background:
        radial-gradient(circle at 35% 30%, var(--vinyl-sheen), transparent 42%),
        repeating-radial-gradient(circle at center, var(--vinyl) 0px, var(--vinyl) 1.4px, var(--vinyl-groove) 1.8px, var(--vinyl) 2.2px);
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 8px 16px rgba(60, 40, 20, 0.3);
}

.record-label {
    width: 40%;
    height: 40%;
    border-radius: 50%;
    background-color: #2a2118;
    background-size: cover;
    background-position: center;
    box-shadow: 0 0 0 2px #0b0b0c;
}

.record-title {
    margin-top: 16px;
    font-size: 1rem;
    color: var(--text-dim);
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    width: 100%;
}

/* ---------- Status banner ---------- */

.status-banner {
    width: 100%;
    box-sizing: border-box;
    margin-bottom: 18px;
    padding: 12px 18px;
    background: var(--danger-soft);
    color: var(--danger);
    border-radius: 12px;
    font-size: 0.9rem;
    font-weight: 500;
    text-align: center;
}

.status-banner[hidden] {
    display: none;
}

/* ---------- Login ---------- */

.login-body {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
}

.login-card {
    width: 100%;
    max-width: 360px;
    margin: 20px;
    background: var(--panel);
    border: 1px solid var(--panel-line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 40px 32px;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
}

.login-disc {
    width: 72px;
    height: 72px;
    border-radius: 50%;
    margin-bottom: 20px;
    background:
        radial-gradient(circle at 35% 30%, var(--vinyl-sheen), transparent 42%),
        repeating-radial-gradient(circle at center, var(--vinyl) 0px, var(--vinyl) 2px, var(--vinyl-groove) 2.6px, var(--vinyl) 3.2px);
    box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.6), 0 10px 20px rgba(60, 40, 20, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
}

.login-disc-label {
    width: 34%;
    height: 34%;
    border-radius: 50%;
    background: #2a2118;
    box-shadow: 0 0 0 3px #0b0b0c;
}

.login-card h1 {
    font-size: 1.5rem;
    color: var(--text);
}

.login-sub {
    margin: 8px 0 28px;
    color: var(--text-dim);
    font-size: 0.95rem;
}

.login-form {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.login-field {
    display: flex;
    flex-direction: column;
    gap: 6px;
    text-align: left;
}

.login-field span {
    font-size: 0.72rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--text-faint);
}

.login-field input {
    font: inherit;
    font-size: 1rem;
    color: var(--text);
    background: var(--bg);
    border: 1px solid var(--panel-line);
    border-radius: 10px;
    padding: 12px 14px;
}

.login-field input:focus {
    outline: 2px solid var(--accent);
    outline-offset: 1px;
}

.login-error {
    margin: 0;
    padding: 10px 12px;
    background: var(--danger-soft);
    color: var(--danger);
    border-radius: 10px;
    font-size: 0.88rem;
}

.login-submit {
    font: inherit;
    font-size: 1rem;
    font-weight: 600;
    color: var(--accent-ink);
    background: var(--accent);
    border: none;
    border-radius: 10px;
    padding: 13px 0;
    cursor: pointer;
    transition: background 0.15s ease, transform 0.1s ease;
}

.login-submit:hover {
    background: #cd7b37;
}

.login-submit:active {
    transform: scale(0.98);
}

a.login-submit {
    display: block;
    text-decoration: none;
    text-align: center;
}

@media (prefers-reduced-motion: reduce) {
    .vinyl.spinning {
        animation: none;
    }
    .tonearm, .record-art {
        transition: none;
    }
}

@media (max-width: 480px) {
    .turntable-wrap {
        width: 270px;
        height: 270px;
    }
}
