:root {
    --bg: #080a0d;
    --panel: #11161d;
    --panel-2: #171f28;
    --ink: #f3f7f6;
    --muted: rgba(243,247,246,0.62);
    --line: rgba(255,255,255,0.12);
    --accent: #56cfaa;
    --accent-ink: #03120d;
    --danger: #e05c6a;
    --danger-dim: rgba(224,92,106,0.12);
    --dock-h: 78px;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    min-height: 100svh;
    background: var(--bg);
    color: var(--ink);
    font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input {
    font: inherit;
}

button {
    border: 0;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
}

svg {
    width: 1.1rem;
    height: 1.1rem;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.icon-sprite { display: none; }

.app {
    min-height: 100svh;
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(280px, 360px);
    gap: 18px;
    padding: 18px 18px calc(var(--dock-h) + 24px);
}

.stage {
    position: relative;
    min-height: calc(100svh - var(--dock-h) - 60px);
    background: #000;
    border: 1px solid var(--line);
    overflow: hidden;
}

.player-frame,
#player,
#player iframe {
    width: 100%;
    height: 100%;
    min-height: inherit;
    border: 0;
}

.empty-state {
    position: absolute;
    inset: 0;
    display: grid;
    place-content: center;
    gap: 8px;
    text-align: center;
    padding: 32px;
    background: radial-gradient(ellipse 80% 60% at 50% 35%, rgba(86,207,170,0.16), transparent 62%), #050608;
}

.empty-state.hidden { display: none; }

.dismiss-layer {
    position: absolute;
    inset: 0;
    z-index: 2;
    padding: 0;
    background: transparent;
    pointer-events: none;
    cursor: default;
    touch-action: manipulation;
}

.player-notice {
    position: absolute;
    left: 16px;
    right: 16px;
    top: 16px;
    z-index: 4;
    padding: 10px 12px;
    border-radius: 8px;
    background: rgba(224,92,106,0.18);
    border: 1px solid rgba(224,92,106,0.34);
    color: #ffe8eb;
    font-size: 0.84rem;
    font-weight: 760;
    backdrop-filter: blur(14px);
}

.player-notice.hidden { display: none; }

.youtube-recovery-btn {
    position: absolute;
    left: 50%;
    top: 50%;
    z-index: 5;
    min-height: 44px;
    padding: 0 18px;
    transform: translate(-50%, -50%);
    border-radius: 999px;
    background: #fff;
    color: #050608;
    font-size: 0.9rem;
    font-weight: 780;
    box-shadow: 0 12px 34px rgba(0,0,0,0.36);
}

.youtube-recovery-btn.hidden { display: none; }

.empty-state h1 {
    margin: 0;
    font-size: clamp(2rem, 6vw, 5rem);
    letter-spacing: 0;
}

.empty-state p {
    margin: 0;
    color: var(--muted);
    font-size: 1rem;
}

.stage-controls {
    position: absolute;
    inset: 0;
    z-index: 3;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    background: linear-gradient(180deg, rgba(0,0,0,0.46), transparent 30%, transparent 55%, rgba(0,0,0,0.72));
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
    touch-action: manipulation;
}

.stage-controls.show {
    opacity: 1;
    pointer-events: none;
}

.stage-controls button,
.stage-controls input,
.stage-controls a {
    pointer-events: auto;
}

.stage-top,
.stage-center,
.stage-bottom {
    padding: 14px;
}

.stage-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.room-pill,
.icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 38px;
    border-radius: 999px;
    background: rgba(10,13,20,0.72);
    color: var(--ink);
    border: 1px solid var(--line);
    backdrop-filter: blur(16px);
}

.room-pill {
    padding: 0 14px;
    color: var(--muted);
    font-size: 0.82rem;
    font-weight: 750;
}

#userCount {
    margin-right: 0.32em;
}

.icon-btn {
    width: 42px;
}

.stage-center {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 24px;
    flex: 1;
}

.stage-btn {
    width: 54px;
    height: 54px;
    display: grid;
    place-items: center;
    border-radius: 50%;
    background: rgba(0,0,0,0.58);
    color: #fff;
    border: 1px solid rgba(255,255,255,0.16);
    backdrop-filter: blur(12px);
    transition: transform 0.12s ease, background 0.12s ease;
}

.stage-btn:active,
.dock-btn:active,
.icon-btn:active,
.add-btn:active {
    transform: scale(0.96);
}

.stage-btn.primary {
    width: 72px;
    height: 72px;
    background: var(--accent);
    color: var(--accent-ink);
}

.stage-bottom {
    display: grid;
    gap: 8px;
}

.seek-row {
    display: flex;
    align-items: center;
    gap: 10px;
}

.time {
    width: 48px;
    font-size: 0.74rem;
    color: rgba(255,255,255,0.78);
    font-variant-numeric: tabular-nums;
}

.time:last-child { text-align: right; }

.seekbar {
    flex: 1;
    height: 4px;
    accent-color: var(--accent);
    touch-action: none;
}

.now-playing {
    color: rgba(255,255,255,0.68);
    font-size: 0.82rem;
    font-weight: 700;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.next-playing {
    color: rgba(255,255,255,0.46);
    font-size: 0.74rem;
    font-weight: 720;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.next-playing.hidden {
    display: none;
}

.voice-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    background: rgba(86,207,170,0.055);
    border-bottom: 1px solid rgba(86,207,170,0.12);
    transition: opacity 0.22s ease, transform 0.22s ease;
}

.voice-bar.hidden,
.hidden {
    display: none !important;
}

.vbars {
    display: flex;
    align-items: flex-end;
    gap: 2px;
    height: 16px;
    flex-shrink: 0;
}

.vbar {
    width: 3px;
    border-radius: 2px;
    background: var(--accent);
    opacity: 0.7;
}

.voice-bar:not(.muted) .vbar:nth-child(1) { height: 45%; animation: vb 0.9s 0s ease-in-out infinite; }
.voice-bar:not(.muted) .vbar:nth-child(2) { height: 85%; animation: vb 0.9s 0.18s ease-in-out infinite; }
.voice-bar:not(.muted) .vbar:nth-child(3) { height: 60%; animation: vb 0.9s 0.32s ease-in-out infinite; }
.voice-bar:not(.muted) .vbar:nth-child(4) { height: 95%; animation: vb 0.9s 0.1s ease-in-out infinite; }
.voice-bar.muted .vbar { height: 35%; background: var(--danger); }

@keyframes vb {
    0%, 100% { transform: scaleY(1); }
    50% { transform: scaleY(0.25); }
}

.voice-bar-info {
    flex: 1;
    min-width: 0;
}

.voice-bar-label {
    font-size: 0.78rem;
    font-weight: 800;
    color: var(--accent);
    display: block;
}

.voice-bar-sub {
    font-size: 0.64rem;
    font-weight: 600;
    color: rgba(86,207,170,0.55);
    margin-top: 1px;
    display: block;
}

.voice-mute-mini {
    padding: 6px 12px;
    border-radius: 999px;
    background: var(--danger-dim);
    border: 1px solid rgba(224,92,106,0.2);
    color: var(--danger);
    font-size: 0.7rem;
    font-weight: 800;
}

.queue-panel {
    min-width: 0;
    background: var(--panel);
    border: 1px solid var(--line);
}

.add-form {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 44px;
    gap: 8px;
}

.add-form input {
    min-width: 0;
    height: 44px;
    padding: 0 12px;
    border-radius: 8px;
    border: 1px solid var(--line);
    background: #0c1016;
    color: var(--ink);
}

.add-btn {
    border-radius: 8px;
    background: var(--accent);
    color: var(--accent-ink);
}

.queue-head {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--muted);
    font-size: 0.78rem;
    font-weight: 850;
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.queue {
    list-style: none;
    padding: 0;
    margin: 0;
    display: grid;
    gap: 8px;
    overflow-y: auto;
    min-height: 0;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
}

.queue-item {
    display: grid;
    grid-template-columns: 70px minmax(0, 1fr) 36px;
    gap: 8px;
    align-items: center;
    min-height: 64px;
    border-radius: 8px;
    padding: 8px;
    background: var(--panel-2);
    border: 1px solid transparent;
}

.queue-thumb {
    width: 70px;
    aspect-ratio: 16 / 9;
    border-radius: 6px;
    object-fit: cover;
    background: #050608;
}

.queue-item.active {
    border-color: rgba(86,207,170,0.5);
    background: rgba(86,207,170,0.11);
}

.queue-item.failed {
    border-color: rgba(224,92,106,0.42);
}

.queue-select {
    min-width: 0;
    text-align: left;
    color: var(--ink);
    background: transparent;
    display: grid;
    gap: 2px;
}

.queue-title {
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    font-weight: 760;
}

.queue-id {
    color: var(--muted);
    font-size: 0.72rem;
}

.queue-author {
    color: var(--muted);
    font-size: 0.72rem;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.queue-error {
    color: var(--danger);
    font-size: 0.72rem;
    font-weight: 760;
}

.remove-btn {
    width: 36px;
    height: 36px;
    display: grid;
    place-items: center;
    border-radius: 8px;
    color: var(--danger);
    background: rgba(224,92,106,0.1);
}

.dock {
    position: fixed;
    left: 50%;
    bottom: 14px;
    z-index: 20;
    transform: translateX(-50%);
    width: min(560px, calc(100% - 28px));
    height: var(--dock-h);
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px;
    overflow-x: auto;
    scrollbar-width: none;
    border-radius: 22px;
    background: rgba(10,13,20,0.9);
    border: 1px solid var(--line);
    box-shadow: 0 -12px 40px rgba(0,0,0,0.4);
    backdrop-filter: blur(24px);
    transition: opacity 0.22s ease, transform 0.22s ease;
    touch-action: manipulation;
}

.app:not(.controls-visible):not(.sheet-open) .dock {
    opacity: 0;
    pointer-events: none;
    transform: translate(-50%, calc(100% + 24px));
}

.app:not(.controls-visible):not(.sheet-open) .voice-bar {
    opacity: 0;
    pointer-events: none;
    transform: translateY(-100%);
}

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

.dock-btn {
    flex: 1;
    min-width: 66px;
    min-height: 58px;
    border-radius: 16px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    background: transparent;
    color: var(--muted);
    font-size: 0.68rem;
    font-weight: 850;
}

.dock-play {
    background: var(--accent);
    color: var(--accent-ink);
}

.dock-voice.joined {
    background: var(--panel-2);
    color: var(--ink);
}

.dock-voice.live {
    background: rgba(86,207,170,0.15);
    color: var(--accent);
}

.dock-voice.muted {
    background: var(--danger-dim);
    color: var(--danger);
}

.dock-btn svg {
    width: 1.18rem;
    height: 1.18rem;
}

.scrim {
    position: fixed;
    inset: 0;
    z-index: 60;
    background: rgba(0,0,0,0.58);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s;
    backdrop-filter: blur(2px);
}

.scrim.open {
    opacity: 1;
    pointer-events: auto;
}

.sheet {
    position: fixed;
    z-index: 70;
    left: 8px;
    right: 8px;
    width: auto;
    max-width: calc(100vw - 16px);
    bottom: 8px;
    border-radius: 26px;
    background: rgba(11,14,21,0.97);
    border: 1px solid var(--line);
    box-shadow: 0 -16px 60px rgba(0,0,0,0.55);
    backdrop-filter: blur(32px);
    transform: translateY(calc(100% + 24px));
    transition: transform 0.28s cubic-bezier(0.32,0.72,0,1);
    overscroll-behavior: contain;
    touch-action: pan-y;
    overflow: hidden;
    max-height: 82svh;
    will-change: transform;
}

.sheet.open {
    transform: translateY(0);
}

.sheet-scroll {
    min-width: 0;
    min-height: 0;
    overflow-y: auto;
    max-height: 82svh;
    padding: 10px 12px calc(env(safe-area-inset-bottom, 0px) + 18px);
    display: flex;
    flex-direction: column;
    gap: 11px;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
}

.grip {
    width: 38px;
    height: 4px;
    border-radius: 999px;
    background: rgba(255,255,255,0.14);
    margin: 6px auto 0;
}

.sheet-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 2px 2px 0;
}

.sheet-label,
.slabel {
    font-size: 0.68rem;
    font-weight: 850;
    color: var(--accent);
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.sheet-head h2 {
    font-size: 1.38rem;
    font-weight: 850;
    letter-spacing: 0;
    margin: 2px 0 0;
}

.close-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--panel-2);
    border: 1px solid var(--line);
    color: var(--muted);
    flex-shrink: 0;
}

.btn-p,
.btn-s,
.btn-d {
    min-height: 50px;
    border-radius: 16px;
    font-size: 0.9rem;
    font-weight: 850;
    width: 100%;
}

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

.btn-s {
    background: var(--panel-2);
    border: 1px solid var(--line);
    color: var(--ink);
}

.btn-d {
    background: var(--danger);
    color: #fff;
}

.btn-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.btn-row .wide {
    grid-column: 1 / -1;
}

.tog-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 11px 13px;
    border-radius: 16px;
    background: rgba(255,255,255,0.04);
    border: 1px solid var(--line);
}

.tog-copy {
    flex: 1;
    min-width: 0;
}

.tog-copy strong {
    display: block;
    font-size: 0.88rem;
    font-weight: 800;
}

.tog-copy small {
    display: block;
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--muted);
    margin-top: 2px;
}

.tog {
    position: relative;
    width: 44px;
    height: 26px;
    flex-shrink: 0;
    cursor: pointer;
}

.tog input {
    opacity: 0;
    width: 0;
    height: 0;
    position: absolute;
}

.tog-track {
    position: absolute;
    inset: 0;
    border-radius: 999px;
    background: var(--panel-2);
    border: 1px solid var(--line);
    transition: background 0.18s, border-color 0.18s;
}

.tog-thumb {
    position: absolute;
    top: 3px;
    left: 3px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--muted);
    transition: transform 0.18s cubic-bezier(0.4,0,0.2,1), background 0.18s;
}

.tog input:checked ~ .tog-track {
    background: var(--accent);
    border-color: var(--accent);
}

.tog input:checked ~ .tog-thumb {
    transform: translateX(18px);
    background: var(--accent-ink);
}

.vol-card {
    padding: 14px;
    border-radius: 16px;
    background: rgba(255,255,255,0.04);
    border: 1px solid var(--line);
    display: flex;
    flex-direction: column;
    gap: 9px;
}

.vol-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.vol-title {
    font-size: 0.88rem;
    font-weight: 800;
}

.vol-pct {
    font-size: 0.7rem;
    color: var(--muted);
    font-variant-numeric: tabular-nums;
}

.vol {
    width: 100%;
    accent-color: var(--accent);
}

.warning {
    padding: 10px 12px;
    border-radius: 14px;
    background: var(--danger-dim);
    border: 1px solid rgba(224,92,106,0.24);
    color: #ffdce1;
    font-size: 0.78rem;
    font-weight: 760;
}

.debug {
    color: var(--muted);
    font-size: 0.72rem;
    line-height: 1.45;
}

.diagnostics summary {
    color: var(--muted);
    cursor: pointer;
    font-size: 0.78rem;
    font-weight: 760;
}

@media (min-width: 981px) {
    .queue-panel {
        position: static;
        transform: none;
        max-height: none;
        overflow: hidden;
        border-radius: 0;
        box-shadow: none;
        backdrop-filter: none;
    }

    .queue-panel .grip,
    .queue-panel .close-btn {
        display: none;
    }

    .queue-panel .sheet-scroll {
        max-height: calc(100svh - var(--dock-h) - 60px);
        padding: 12px;
    }

    .queue-panel .sheet-head {
        padding: 0;
    }
}

@media (max-width: 980px) {
    html,
    body {
        overflow-x: hidden;
        overscroll-behavior: none;
    }

    .app {
        display: block;
        min-height: 100svh;
        padding: 0;
    }

    .stage {
        height: 100svh;
        min-height: 100svh;
        border: 0;
    }

    .app:not(.sheet-open):not(.youtube-recovery) .dismiss-layer {
        pointer-events: auto;
    }

    .stage-controls {
        pointer-events: none;
        background: transparent;
    }

    .stage-controls.show {
        background: linear-gradient(180deg, rgba(0,0,0,0.34), transparent 28%, transparent 62%, rgba(0,0,0,0.58));
    }

    .stage-controls:not(.show) button,
    .stage-controls:not(.show) input {
        pointer-events: none;
    }

    .stage-top,
    .stage-center,
    .stage-bottom {
        padding-left: max(14px, env(safe-area-inset-left, 0px));
        padding-right: max(14px, env(safe-area-inset-right, 0px));
    }

    .stage-bottom {
        padding-bottom: calc(var(--dock-h) + max(18px, env(safe-area-inset-bottom, 0px)));
    }

    .stage-center,
    .seek-row {
        display: none;
    }

    .player-frame,
    #player,
    #player iframe {
        min-height: 0;
        height: 100%;
    }

    .sheet {
        left: 8px;
        right: 8px;
        bottom: max(8px, env(safe-area-inset-bottom, 0px));
        max-width: calc(100vw - 16px);
        max-height: min(72svh, 620px);
        border-radius: 22px;
    }

    .sheet-scroll {
        max-height: min(72svh, 620px);
        padding: 10px 12px calc(env(safe-area-inset-bottom, 0px) + 14px);
    }

    .queue-panel {
        border-left: 1px solid var(--line);
        border-right: 1px solid var(--line);
        min-width: 0;
    }

    .queue-panel.open {
        height: min(72svh, 620px);
    }

    .queue-panel .sheet-scroll {
        height: 100%;
        overflow: hidden;
    }

    .queue {
        flex: 1;
        overflow-y: auto;
    }

    .add-form {
        width: 100%;
        max-width: 100%;
        grid-template-columns: minmax(0, 1fr) 44px;
    }

    .add-form input {
        width: 100%;
        min-width: 0;
    }

    .dock {
        justify-content: flex-start;
        width: calc(100% - 16px);
        bottom: max(8px, env(safe-area-inset-bottom, 0px));
        height: 70px;
        border-radius: 20px;
    }

    .app:not(.controls-visible):not(.sheet-open) .dock {
        opacity: 0;
        pointer-events: none;
        transform: translate(-50%, calc(100% + 24px));
    }

    .app:not(.controls-visible):not(.sheet-open) .voice-bar {
        opacity: 0;
        pointer-events: none;
        transform: translateY(-100%);
    }

    .dock-btn {
        min-width: 58px;
        min-height: 52px;
    }
}
