:root {
    --bg: #0e0e12;
    --surface: #1a1a24;
    --surface2: #24243a;
    --border: #2e2e48;
    --text: #e4e4f0;
    --text-dim: #8888a8;
    --accent: #7c6aff;
    --accent-glow: rgba(124, 106, 255, 0.25);
    --danger: #ff4466;
    --success: #44dd88;
    --warning: #ffaa33;
    --radius: 12px;
    --transition: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family:
        -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* ---------- PASSWORD OVERLAY ---------- */
#passwordOverlay {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg);
    transition:
        opacity 0.4s ease,
        visibility 0.4s ease;
}

#passwordOverlay.hidden {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

.password-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 48px 40px 40px;
    width: 380px;
    max-width: 92vw;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 28px;
}

.password-card h1 {
    font-size: 28px;
    font-weight: 700;
    letter-spacing: -0.5px;
}

.password-card .subtitle {
    color: var(--text-dim);
    font-size: 13px;
    margin-top: -20px;
    text-align: center;
    line-height: 1.5;
}

.password-input-wrap {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.password-input-wrap label {
    font-size: 12px;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 1px;
}

.password-input {
    width: 100%;
    padding: 14px 16px;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 10px;
    color: var(--text);
    font-size: 15px;
    font-family: monospace;
    outline: none;
    transition: border-color var(--transition);
}

.password-input:focus {
    border-color: var(--accent);
}

.password-input::placeholder {
    color: var(--text-dim);
    opacity: 0.6;
}

.password-error {
    font-size: 12px;
    color: var(--danger);
    min-height: 1.4em;
    text-align: center;
}

.btn-subtle {
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 10px;
    font-size: 13px;
    font-weight: 600;
    padding: 10px 16px;
    cursor: pointer;
    color: var(--text-dim);
    transition: all var(--transition);
    width: 100%;
}

.btn-subtle:hover {
    background: var(--border);
    color: var(--text);
}

/* ---------- View switching ---------- */
#lobby,
#call {
    transition:
        opacity var(--transition),
        transform var(--transition);
}

#lobby {
    display: flex;
}

#call {
    display: none;
}

body.in-call #lobby {
    display: none;
}

body.in-call #call {
    display: flex;
}

/* ---------- LOBBY ---------- */
#lobby {
    flex: 1;
    align-items: center;
    justify-content: center;
}

.lobby-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 48px 40px 40px;
    width: 380px;
    max-width: 92vw;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 28px;
}

.lobby-card h1 {
    font-size: 28px;
    font-weight: 700;
    letter-spacing: -0.5px;
}

.lobby-card .subtitle {
    color: var(--text-dim);
    font-size: 13px;
    margin-top: -20px;
}

/* Mic preview meter */
.preview-meter {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

.preview-meter-label {
    font-size: 12px;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 1px;
}

.preview-bar-track {
    width: 100%;
    height: 6px;
    background: var(--surface2);
    border-radius: 3px;
    overflow: hidden;
}

.preview-bar-fill {
    height: 100%;
    width: 0%;
    background: var(--accent);
    border-radius: 3px;
    transition: width 60ms linear;
}

.preview-bar-fill.hot {
    background: var(--danger);
}

/* Settings toggles */
.settings {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.toggle-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px;
    background: var(--surface2);
    border-radius: 10px;
    font-size: 14px;
    cursor: pointer;
    user-select: none;
    transition: background var(--transition);
}

.toggle-row:hover {
    background: var(--border);
}

.toggle-row input {
    display: none;
}

.toggle-track {
    width: 40px;
    height: 22px;
    border-radius: 11px;
    background: var(--border);
    position: relative;
    transition: background var(--transition);
    flex-shrink: 0;
}

.toggle-track::after {
    content: "";
    position: absolute;
    top: 3px;
    left: 3px;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--text-dim);
    transition:
        transform var(--transition),
        background var(--transition);
}

.toggle-row input:checked + .toggle-track {
    background: var(--accent);
}

.toggle-row input:checked + .toggle-track::after {
    transform: translateX(18px);
    background: #fff;
}

.btn {
    border: none;
    border-radius: 10px;
    font-size: 15px;
    font-weight: 600;
    padding: 14px 32px;
    cursor: pointer;
    transition: all var(--transition);
    color: #fff;
    letter-spacing: 0.3px;
}

.btn-primary {
    background: var(--accent);
    width: 100%;
}

.btn-primary:hover {
    box-shadow: 0 0 24px var(--accent-glow);
    transform: translateY(-1px);
}

.btn-danger {
    background: var(--danger);
}

.btn-danger:hover {
    filter: brightness(1.15);
}

.btn-mute {
    background: var(--surface2);
    border: 1px solid var(--border);
    color: var(--text);
}

.btn-mute:hover {
    background: var(--border);
}

.btn-mute.muted {
    background: var(--warning);
    color: #000;
    border-color: transparent;
}

.badge {
    font-size: 11px;
    color: var(--text-dim);
    letter-spacing: 0.5px;
}

/* Admin panel inside lobby */
.admin-panel {
    width: 100%;
    flex-direction: column;
    gap: 10px;
    padding: 14px;
    background: var(--surface2);
    border-radius: 12px;
}

.admin-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.admin-panel .admin-label {
    font-size: 11px;
    color: var(--accent);
    text-transform: uppercase;
    letter-spacing: 1.5px;
}

.user-pass-display {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 12px;
    font-family: monospace;
    font-size: 14px;
    text-align: center;
    color: var(--accent);
    letter-spacing: 1px;
    word-break: break-all;
}

/* Floating pop panels above call bar buttons */
.btn-wrap {
    position: relative;
}

.pop-panel {
    position: absolute;
    bottom: calc(100% + 8px);
    left: 50%;
    transform: translateX(-50%);
    z-index: 100;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
    padding: 14px;
    min-width: 200px;
}

.pop-panel-body {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.pop-panel-body .admin-label {
    font-size: 11px;
    color: var(--accent);
    text-transform: uppercase;
    letter-spacing: 1.5px;
    text-align: center;
}

.pop-panel-body .btn-subtle {
    width: 100%;
}

.pop-panel-body .toggle-row {
    padding: 8px 12px;
    font-size: 13px;
}

/* ---------- CALL VIEW ---------- */
#call {
    flex: 1;
    flex-direction: column;
}

.call-header {
    padding: 16px 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--border);
}

.call-header h2 {
    font-size: 18px;
    font-weight: 600;
}

#callStatus {
    font-size: 13px;
    padding: 4px 12px;
    border-radius: 20px;
    background: var(--surface2);
    color: var(--text-dim);
}

#callStatus.connected {
    background: rgba(68, 221, 136, 0.12);
    color: var(--success);
}

#callStatus.error {
    background: rgba(255, 68, 102, 0.12);
    color: var(--danger);
}

/* Participant grid */
.grid-wrap {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    overflow: auto;
}

#peerGrid {
    display: grid;
    gap: 16px;
    width: 100%;
    max-width: 900px;
    transition: all var(--transition);
}

#peerGrid.cols-1 {
    grid-template-columns: 1fr;
    max-width: 240px;
}

#peerGrid.cols-2 {
    grid-template-columns: repeat(2, 1fr);
    max-width: 500px;
}

#peerGrid.cols-3 {
    grid-template-columns: repeat(3, 1fr);
    max-width: 720px;
}

#peerGrid.cols-5 {
    grid-template-columns: repeat(5, 1fr);
    max-width: 900px;
}

.tile {
    aspect-ratio: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 10px;
    background: var(--surface);
    border: 2px solid var(--border);
    border-radius: 20px;
    position: relative;
    transition:
        border-color var(--transition),
        box-shadow var(--transition);
}

.tile.you {
    border-color: var(--accent);
    box-shadow: 0 0 20px var(--accent-glow);
}

.tile.speaking {
    border-color: var(--success);
    box-shadow: 0 0 16px rgba(68, 221, 136, 0.3);
}

.tile .avatar {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--surface2);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    font-weight: 700;
    color: var(--accent);
    text-transform: uppercase;
}

.tile.you .avatar {
    background: var(--accent);
    color: #fff;
}

.tile .peer-label {
    font-size: 12px;
    color: var(--text-dim);
    max-width: 90%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.tile .conn-dot {
    position: absolute;
    top: 10px;
    right: 10px;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--success);
}

.tile .conn-dot.disconnected {
    background: var(--danger);
}

/* Per-tile stereo meters */
.tile-meters {
    display: flex;
    gap: 6px;
    height: 48px;
    align-items: stretch;
}

.tile-meter-col {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    height: 100%;
}

.tile-meter {
    width: 6px;
    flex: 1;
    min-height: 0;
    border-radius: 3px;
    background: var(--surface2);
    overflow: hidden;
    position: relative;
}

.tile-meter-fill {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 0%;
    background: var(--accent);
    border-radius: 3px;
    transition: height 60ms linear;
}

.tile-meter-fill.hot {
    background: var(--danger);
}

.tile-meter-ch {
    font-size: 9px;
    color: var(--text-dim);
    text-align: center;
    line-height: 1;
}

/* Bottom bar */
.call-bar {
    padding: 16px 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 16px;
    border-top: 1px solid var(--border);
    background: var(--surface);
}

.call-bar .peer-count {
    font-size: 13px;
    color: var(--text-dim);
    margin-right: auto;
}

.call-bar .btn {
    padding: 10px 24px;
    font-size: 14px;
}

.vol-slider {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    color: var(--text-dim);
}

.vol-slider input[type="range"] {
    width: 80px;
    height: 4px;
    -webkit-appearance: none;
    appearance: none;
    background: var(--border);
    border-radius: 2px;
    outline: none;
}

.vol-slider input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--accent);
    border: none;
    cursor: pointer;
}

.vol-slider input[type="range"]::-moz-range-thumb {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--accent);
    border: none;
    cursor: pointer;
}

.peer-vol {
    width: 64px;
    height: 3px;
    -webkit-appearance: none;
    appearance: none;
    background: var(--border);
    border-radius: 2px;
    outline: none;
}

.peer-vol::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--text-dim);
    border: none;
    cursor: pointer;
}

.peer-vol::-moz-range-thumb {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--text-dim);
    border: none;
    cursor: pointer;
}

/* ---------- RESPONSIVE ---------- */
@media (max-width: 600px) {
    .lobby-card {
        padding: 32px 24px;
    }

    #peerGrid.cols-5 {
        grid-template-columns: repeat(3, 1fr);
    }

    .tile .avatar {
        width: 40px;
        height: 40px;
        font-size: 16px;
    }

    .tile-meters {
        height: 28px;
    }

    .call-bar {
        padding: 12px 16px;
    }
}
