:root {
    --bg-base:        #0f1117;
    --bg-panel:       #1a1d27;
    --bg-card:        #22263a;
    --bg-card-hover:  #2a2f47;
    --bg-card-sel:    #1e3a5f;
    --border:         #2e3248;
    --border-sel:     #3b82f6;
    --text-primary:   #e2e8f0;
    --text-secondary: #8892a4;
    --text-muted:     #555e73;
    --accent-blue:    #3b82f6;
    --accent-orange:  #f97316;
    --health-high:    #22c55e;
    --health-low:     #ef4444;
    --armor-color:    #60a5fa;
    --badge-bg:       #1e3a5f;
    --badge-text:     #93c5fd;
    --dot-connected:  #22c55e;
    --dot-disc:       #ef4444;
    --header-height:  52px;
}

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

html, body {
    height: 100%;
    background: var(--bg-base);
    color: var(--text-primary);
    font-family: 'Inter', 'Segoe UI', system-ui, sans-serif;
    font-size: 14px;
    line-height: 1.5;
    overflow: hidden;
}

/* ── Header ── */

.header {
    height: var(--header-height);
    background: var(--bg-panel);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    flex-shrink: 0;
    gap: 12px;
}

.header-left,
.header-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

.site-title {
    font-size: 15px;
    font-weight: 600;
    letter-spacing: 0.02em;
    color: var(--text-primary);
}

.badge {
    background: var(--badge-bg);
    color: var(--badge-text);
    font-size: 12px;
    font-weight: 600;
    padding: 2px 10px;
    border-radius: 999px;
    letter-spacing: 0.03em;
}

.last-updated {
    font-size: 12px;
    color: var(--text-muted);
}

/* Connection status dot */
.status-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
}

.status-dot.connected {
    background: var(--dot-connected);
    box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.6);
    animation: pulse-green 2s infinite;
}

.status-dot.disconnected {
    background: var(--dot-disc);
    animation: none;
}

@keyframes pulse-green {
    0%   { box-shadow: 0 0 0 0   rgba(34, 197, 94, 0.6); }
    70%  { box-shadow: 0 0 0 7px rgba(34, 197, 94, 0); }
    100% { box-shadow: 0 0 0 0   rgba(34, 197, 94, 0); }
}

/* ── Main layout ── */

.main-content {
    display: flex;
    height: calc(100vh - var(--header-height));
    overflow: hidden;
}

.map-panel {
    flex: 0 0 65%;
    position: relative;
    background: #0a0c10;
}

#map {
    width: 100%;
    height: 100%;
}

/* Keep Leaflet attribution readable on dark map */
.leaflet-control-attribution {
    background: rgba(15, 17, 23, 0.75) !important;
    color: var(--text-muted) !important;
    font-size: 10px !important;
}

.leaflet-control-attribution a {
    color: var(--accent-blue) !important;
}

/* ── Player list panel ── */

.list-panel {
    flex: 0 0 35%;
    display: flex;
    flex-direction: column;
    background: var(--bg-panel);
    border-left: 1px solid var(--border);
    overflow: hidden;
}

.list-header {
    padding: 14px 16px 10px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.list-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.07em;
}

.player-list {
    flex: 1;
    overflow-y: auto;
    padding: 10px 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.player-list::-webkit-scrollbar {
    width: 5px;
}

.player-list::-webkit-scrollbar-track {
    background: transparent;
}

.player-list::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 999px;
}

/* ── Player card ── */

.player-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 10px 12px;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
    user-select: none;
}

.player-card:hover {
    background: var(--bg-card-hover);
}

.player-card.selected {
    background: var(--bg-card-sel);
    border-color: var(--border-sel);
}

.card-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.card-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.player-name {
    font-weight: 600;
    font-size: 13px;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 70%;
}

.ping-badge {
    font-size: 11px;
    color: var(--text-muted);
    flex-shrink: 0;
}

.ping-badge.high {
    color: #f97316;
}

/* ── Listen button ── */

.listen-btn {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-muted);
    font-size: 13px;
    line-height: 1;
    padding: 2px 5px;
    border-radius: 4px;
    cursor: pointer;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
    flex-shrink: 0;
}

.listen-btn:hover {
    background: var(--bg-card-hover);
    color: var(--text-secondary);
    border-color: var(--text-muted);
}

.listen-btn.active {
    background: rgba(34, 197, 94, 0.12);
    color: #22c55e;
    border-color: rgba(34, 197, 94, 0.35);
}


/* ── Bars ── */

.bars {
    display: flex;
    flex-direction: column;
    gap: 5px;
    margin-bottom: 8px;
}

.bar-row {
    display: flex;
    align-items: center;
    gap: 7px;
}

.bar-label {
    font-size: 10px;
    color: var(--text-muted);
    width: 18px;
    flex-shrink: 0;
}

.bar-track {
    flex: 1;
    height: 5px;
    background: var(--bg-base);
    border-radius: 999px;
    overflow: hidden;
}

.bar-fill {
    height: 100%;
    border-radius: 999px;
    transition: width 0.4s ease;
}

.bar-fill.health {
    /* gradient shifts from green at full health toward red as it empties */
    background: linear-gradient(to right, var(--health-low), var(--health-high));
    background-size: 200% 100%;
}

.bar-fill.armor {
    background: var(--armor-color);
}

.bar-value {
    font-size: 10px;
    color: var(--text-secondary);
    width: 28px;
    text-align: right;
    flex-shrink: 0;
}

/* ── Vehicle badge ── */

.vehicle-badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-size: 11px;
    background: rgba(249, 115, 22, 0.12);
    color: var(--accent-orange);
    border: 1px solid rgba(249, 115, 22, 0.25);
    border-radius: 4px;
    padding: 2px 7px;
    margin-top: 2px;
}

.vehicle-plate {
    font-size: 10px;
    color: var(--text-muted);
    margin-left: 2px;
}

/* ── Empty state ── */

.empty-state {
    text-align: center;
    color: var(--text-muted);
    font-size: 13px;
    padding: 40px 16px;
}

/* ── Leaflet popup dark theme ── */

.leaflet-popup-content-wrapper {
    background: var(--bg-panel) !important;
    color: var(--text-primary) !important;
    border: 1px solid var(--border) !important;
    border-radius: 8px !important;
    box-shadow: 0 8px 24px rgba(0,0,0,0.5) !important;
}

.leaflet-popup-tip {
    background: var(--bg-panel) !important;
}

.leaflet-popup-content {
    font-size: 12px !important;
    line-height: 1.6 !important;
}

.popup-name {
    font-weight: 700;
    font-size: 13px;
    margin-bottom: 6px;
    color: var(--text-primary);
}

.popup-row {
    color: var(--text-secondary);
    font-size: 11px;
}

.popup-row span {
    color: var(--text-primary);
}

.leaflet-container a.leaflet-popup-close-button {
    color: var(--text-muted) !important;
}

/* ── Map style switcher ── */

.map-style-ctrl {
    position: absolute;
    bottom: 28px;
    left: 10px;
    z-index: 1000;
    display: flex;
    gap: 4px;
}

.map-style-btn {
    background: rgba(15, 17, 23, 0.82);
    border: 1px solid var(--border);
    color: var(--text-secondary);
    font-size: 11px;
    font-weight: 600;
    padding: 3px 9px;
    border-radius: 4px;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
    letter-spacing: 0.03em;
}

.map-style-btn:hover {
    background: var(--bg-card-hover);
    color: var(--text-primary);
}

.map-style-btn.active {
    background: var(--accent-blue);
    border-color: var(--accent-blue);
    color: #fff;
}

/* ── Spectate button ── */

.spectate-btn {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-muted);
    font-size: 13px;
    line-height: 1;
    padding: 2px 5px;
    border-radius: 4px;
    cursor: pointer;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
    flex-shrink: 0;
}

.spectate-btn:hover {
    background: var(--bg-card-hover);
    color: var(--text-secondary);
    border-color: var(--text-muted);
}

.spectate-btn.active {
    background: rgba(239, 68, 68, 0.12);
    color: #ef4444;
    border-color: rgba(239, 68, 68, 0.35);
}

/* ── Spectate overlay (covers .map-panel) ── */

.spectate-overlay {
    position: absolute;
    inset: 0;
    z-index: 1000;
    background: #000;
    display: flex;
    flex-direction: column;
}

.spectate-bar {
    height: 36px;
    background: rgba(0, 0, 0, 0.85);
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0 14px;
    flex-shrink: 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.spectate-live {
    font-size: 11px;
    font-weight: 700;
    color: #ef4444;
    letter-spacing: 0.08em;
    animation: blink 1.5s step-start infinite;
}

@keyframes blink {
    50% { opacity: 0.3; }
}

.spectate-name {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
    flex: 1;
}

.spectate-no-audio {
    font-size: 11px;
    color: var(--text-muted);
    letter-spacing: 0.03em;
    flex-shrink: 0;
}

.spectate-close-btn {
    background: rgba(239, 68, 68, 0.15);
    border: 1px solid rgba(239, 68, 68, 0.3);
    color: #ef4444;
    font-size: 12px;
    padding: 3px 10px;
    border-radius: 4px;
    cursor: pointer;
    transition: background 0.15s;
}

.spectate-close-btn:hover {
    background: rgba(239, 68, 68, 0.3);
}

.spectate-screen-wrap {
    flex: 1;
    position: relative;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Wrapper isolates <video> from ancestor transforms so browser-injected
   overlays (PiP, cast button) render correctly. */
.spectate-video-flip {
    position: absolute;
    inset: 0;
    overflow: hidden;
}

#spectate-video {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.spectate-no-signal {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    font-size: 14px;
    background: #090b10;
}

.spectate-debug {
    position: absolute;
    top: 8px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 11px;
    color: rgba(100, 180, 255, 0.75);
    font-family: monospace;
    white-space: nowrap;
    pointer-events: none;
    z-index: 10;
}

/* ── Spectate quality toggle ── */

.spectate-quality-grp {
    display: flex;
    gap: 3px;
    align-items: center;
    flex-shrink: 0;
}

.spectate-quality-btn {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-muted);
    font-size: 10px;
    font-weight: 600;
    padding: 2px 7px;
    border-radius: 4px;
    cursor: pointer;
    letter-spacing: 0.04em;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.spectate-quality-btn:hover {
    background: var(--bg-card-hover);
    color: var(--text-secondary);
}

.spectate-quality-btn.active {
    background: rgba(59, 130, 246, 0.2);
    border-color: rgba(59, 130, 246, 0.5);
    color: var(--accent-blue);
}

/* ── Responsive ── */

@media (max-width: 800px) {
    html, body {
        overflow: auto;
    }

    .main-content {
        flex-direction: column;
        height: auto;
    }

    .map-panel {
        flex: none;
        width: 100%;
        height: 55vw;
        min-height: 260px;
    }

    .list-panel {
        flex: none;
        width: 100%;
        border-left: none;
        border-top: 1px solid var(--border);
        max-height: 45vh;
    }
}
