@import url('https://fonts.googleapis.com/css2?family=Share+Tech+Mono&family=Barlow+Condensed:wght@400;600;700;800&display=swap');

:root {
    --bg: #080a0d;
    --panel: #0e1117;
    --panel2: #131720;
    --border: #1e2636;
    --border2: #28334a;
    --accent: #00d9ff;
    --accent-dim: rgba(0,217,255,0.12);
    --ct: #5bc8f5;
    --t: #f5a623;
    --green: #4dff91;
    --red: #ff4560;
    --text: #cdd9e8;
    --text-dim: #4a5c70;
    --text-mid: #7a8fa8;
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

html, body {
    height: 100%;
    overflow: hidden;
    background: var(--bg);
    color: var(--text);
    font-family: 'Barlow Condensed', sans-serif;
}

/* ─── LAYOUT ─── */
#app {
    display: grid;
    grid-template-rows: 44px 1fr;
    grid-template-columns: 200px 1fr;
    grid-template-areas:
        "topbar topbar"
        "sidebar canvas";
    height: 100vh;
    height: 100dvh;
}

/* ─── TOPBAR ─── */
#topbar {
    grid-area: topbar;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 14px;
    background: var(--panel);
    border-bottom: 1px solid var(--border);
    z-index: 20;
    gap: 10px;
}

#mapTitle {
    font-size: 16px;
    font-weight: 800;
    letter-spacing: 3px;
    color: var(--accent);
    text-transform: uppercase;
    white-space: nowrap;
    display: flex;
    align-items: center;
    gap: 7px;
}

#mapTitle::before {
    content: '';
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--accent);
    box-shadow: 0 0 8px var(--accent);
    animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.4; transform: scale(0.7); }
}

#statusText {
    font-family: 'Share Tech Mono', monospace;
    font-size: 11px;
    color: var(--text-dim);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
    text-align: center;
}

#menuToggle {
    display: none;
    width: 34px;
    height: 34px;
    border: 1px solid var(--border2);
    background: var(--panel2);
    border-radius: 6px;
    cursor: pointer;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    color: var(--text);
    font-size: 16px;
    transition: border-color 0.15s;
}

#menuToggle:active { border-color: var(--accent); }

/* ─── SIDEBAR (desktop) ─── */
#sidebar {
    grid-area: sidebar;
    background: var(--panel);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    z-index: 15;
    transition: transform 0.25s cubic-bezier(0.4,0,0.2,1);
}

.section {
    border-bottom: 1px solid var(--border);
    padding: 10px 12px;
    flex-shrink: 0;
}

.section-label {
    font-size: 9px;
    font-weight: 700;
    letter-spacing: 3px;
    text-transform: uppercase;
    color: var(--text-dim);
    margin-bottom: 8px;
}

.toggle-row {
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 4px 0;
    cursor: pointer;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-mid);
    transition: color 0.15s;
    user-select: none;
}

.toggle-row:hover { color: var(--text); }

.toggle-row input[type=checkbox] {
    appearance: none;
    width: 14px;
    height: 14px;
    border: 1.5px solid var(--border2);
    border-radius: 3px;
    background: var(--bg);
    cursor: pointer;
    flex-shrink: 0;
    position: relative;
    transition: background 0.15s, border-color 0.15s;
}

.toggle-row input[type=checkbox]:checked {
    background: var(--accent);
    border-color: var(--accent);
}

.toggle-row input[type=checkbox]:checked::after {
    content: '✓';
    position: absolute;
    top: -2px;
    left: 1px;
    font-size: 10px;
    color: #000;
    font-weight: 900;
}

.team-pills { display: flex; gap: 4px; }

.team-pill {
    flex: 1;
    padding: 5px 0;
    border: 1.5px solid var(--border2);
    background: var(--bg);
    color: var(--text-dim);
    font-family: 'Barlow Condensed', sans-serif;
    font-weight: 700;
    font-size: 12px;
    cursor: pointer;
    border-radius: 4px;
    text-align: center;
    letter-spacing: 1px;
    transition: all 0.15s;
}

.team-pill:hover { border-color: var(--border); color: var(--text-mid); }
.team-pill.active { color: #000; }
.team-pill[data-team="ALL"].active { background: var(--accent); border-color: var(--accent); }
.team-pill[data-team="CT"].active  { background: var(--ct);     border-color: var(--ct); }
.team-pill[data-team="T"].active   { background: var(--t);      border-color: var(--t); }

#zoomLabel {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 7px;
}

#zoomVal {
    font-family: 'Share Tech Mono', monospace;
    font-size: 11px;
    color: var(--accent);
}

#zoomSlider {
    width: 100%;
    height: 4px;
    accent-color: var(--accent);
    cursor: pointer;
    border-radius: 2px;
}

/* ─── FLOOR SWITCHER ─── */
#floorSwitcher {
    display: none;
    border-bottom: 1px solid var(--border);
    padding: 8px 12px;
    flex-shrink: 0;
}

#floorSwitcher.visible { display: block; }

.floor-pills {
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
}

.floor-pill {
    flex: 1;
    min-width: 0;
    padding: 5px 4px;
    border: 1.5px solid var(--border2);
    background: var(--bg);
    color: var(--text-dim);
    font-family: 'Barlow Condensed', sans-serif;
    font-weight: 700;
    font-size: 11px;
    cursor: pointer;
    border-radius: 4px;
    text-align: center;
    letter-spacing: 1px;
    transition: all 0.15s;
    white-space: nowrap;
}

.floor-pill:hover { border-color: var(--border); color: var(--text-mid); }
.floor-pill.active {
    background: var(--accent);
    border-color: var(--accent);
    color: #000;
}

/* ─── HEIGHT LEGEND ─── */
#heightLegend {
    display: none;
    padding: 8px 12px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

#heightLegend.visible { display: block; }

.legend-title {
    font-size: 9px;
    font-weight: 700;
    letter-spacing: 3px;
    text-transform: uppercase;
    color: var(--text-dim);
    margin-bottom: 6px;
}

.legend-items {
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 7px;
    font-size: 11px;
    color: var(--text-mid);
    font-weight: 600;
}

.legend-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
    border: 1.5px solid rgba(0,0,0,0.5);
}

/* ─── PLAYER LIST ─── */
#playerList {
    flex: 1;
    overflow-y: auto;
    padding: 6px;
    min-height: 0;
}

#playerList::-webkit-scrollbar { width: 3px; }
#playerList::-webkit-scrollbar-track { background: transparent; }
#playerList::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 2px; }

.player-card {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 7px 9px;
    border-radius: 5px;
    cursor: pointer;
    border: 1px solid transparent;
    margin-bottom: 3px;
    position: relative;
    transition: background 0.12s, border-color 0.12s;
}

.player-card:hover { background: rgba(255,255,255,0.04); }
.player-card.selected { border-color: var(--accent); background: var(--accent-dim); }
.player-card.dead { opacity: 0.3; }

.player-dot-wrap { position: relative; flex-shrink: 0; }

.player-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    border: 1.5px solid rgba(0,0,0,0.5);
}

/* Floor badge on player dot in list */
.floor-badge {
    position: absolute;
    top: -5px;
    right: -5px;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--panel2);
    border: 1px solid var(--border2);
    font-size: 7px;
    font-weight: 900;
    font-family: 'Share Tech Mono', monospace;
    color: var(--accent);
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

.c4-badge {
    position: absolute;
    top: -5px;
    right: -5px;
    width: 12px;
    height: 12px;
}

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

.player-name {
    font-weight: 700;
    font-size: 13px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.1;
}

.player-meta {
    font-family: 'Share Tech Mono', monospace;
    font-size: 10px;
    color: var(--text-dim);
    margin-top: 1px;
}

.floor-tag {
    font-size: 9px;
    padding: 1px 4px;
    border-radius: 3px;
    font-family: 'Share Tech Mono', monospace;
    font-weight: 700;
    color: #000;
    margin-left: 4px;
    vertical-align: middle;
}

.follow-badge { font-size: 12px; color: var(--accent); display: none; flex-shrink: 0; }
.player-card.selected .follow-badge { display: block; }

#emptyList {
    text-align: center;
    color: var(--text-dim);
    font-size: 12px;
    padding: 24px 0;
}

/* ─── CANVAS AREA ─── */
#canvasArea {
    grid-area: canvas;
    position: relative;
    overflow: hidden;
    background: #0a0c10;
    touch-action: none;
}

canvas {
    position: absolute;
    top: 0; left: 0;
    image-rendering: pixelated;
    transform-origin: 0 0;
    cursor: grab;
}

canvas.dragging { cursor: grabbing; }

/* ─── MULTI-LEVEL MAP LAYER STACKING ─── */
/* Lower floor canvas sits behind upper floor canvas */
#radarCanvasLower {
    z-index: 1;
    opacity: 0.5;
}

#radarCanvas {
    z-index: 2;
    background: transparent;
}

/* ─── FLOOR INDICATOR OVERLAY ─── */
#floorIndicator {
    position: absolute;
    top: 10px;
    left: 10px;
    background: rgba(14,17,23,0.88);
    border: 1px solid var(--border2);
    border-radius: 6px;
    padding: 4px 10px;
    font-family: 'Share Tech Mono', monospace;
    font-size: 11px;
    color: var(--accent);
    letter-spacing: 2px;
    display: none;
    z-index: 5;
    backdrop-filter: blur(4px);
}

#floorIndicator.visible { display: block; }

/* ─── ZOOM CONTROLS ─── */
#zoomControls {
    position: absolute;
    top: 10px;
    right: 10px;
    display: flex;
    flex-direction: column;
    gap: 3px;
    z-index: 5;
}

.z-btn {
    width: 32px;
    height: 32px;
    background: rgba(14,17,23,0.9);
    border: 1px solid var(--border2);
    color: var(--text-mid);
    font-size: 18px;
    font-weight: 700;
    cursor: pointer;
    border-radius: 5px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: border-color 0.15s, color 0.15s;
    line-height: 1;
    font-family: 'Barlow Condensed', sans-serif;
    backdrop-filter: blur(4px);
}

.z-btn:hover { border-color: var(--accent); color: var(--accent); }
.z-btn:active { background: var(--accent-dim); }

/* ─── FOLLOW INDICATOR ─── */
#followIndicator {
    position: absolute;
    bottom: 14px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0,217,255,0.1);
    border: 1px solid rgba(0,217,255,0.4);
    color: var(--accent);
    font-family: 'Share Tech Mono', monospace;
    font-size: 11px;
    padding: 5px 14px;
    border-radius: 20px;
    letter-spacing: 2px;
    display: none;
    pointer-events: none;
    backdrop-filter: blur(4px);
    white-space: nowrap;
}

#followIndicator.visible { display: block; }

/* ─── MOBILE BOTTOM SHEET ─── */
#bottomSheet {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--panel);
    border-top: 1px solid var(--border2);
    border-radius: 14px 14px 0 0;
    z-index: 30;
    max-height: 70vh;
    transform: translateY(100%);
    transition: transform 0.3s cubic-bezier(0.4,0,0.2,1);
    overflow: hidden;
    flex-direction: column;
}

#bottomSheet.open { transform: translateY(0); }

#sheetHandle {
    width: 36px;
    height: 4px;
    background: var(--border2);
    border-radius: 2px;
    margin: 10px auto 6px;
    flex-shrink: 0;
}

#sheetContent {
    overflow-y: auto;
    flex: 1;
    padding: 0 0 env(safe-area-inset-bottom, 12px);
}

#sheetContent::-webkit-scrollbar { display: none; }

/* ─── MOBILE QUICK BAR ─── */
#quickBar {
    display: none;
    position: absolute;
    bottom: 14px;
    left: 10px;
    gap: 6px;
    z-index: 10;
}

.q-btn {
    height: 32px;
    padding: 0 10px;
    background: rgba(14,17,23,0.88);
    border: 1px solid var(--border2);
    color: var(--text-mid);
    font-family: 'Barlow Condensed', sans-serif;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 1px;
    cursor: pointer;
    border-radius: 6px;
    display: flex;
    align-items: center;
    backdrop-filter: blur(4px);
    transition: border-color 0.15s, color 0.15s;
    white-space: nowrap;
}

.q-btn.active { border-color: var(--accent); color: var(--accent); }

/* ─── SIDEBAR OVERLAY ─── */
#sidebarOverlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.55);
    z-index: 25;
    backdrop-filter: blur(2px);
}

#sidebarOverlay.visible { display: block; }

/* ─── MOBILE ─── */
@media (max-width: 680px) {
    #app {
        grid-template-columns: 1fr;
        grid-template-areas:
            "topbar"
            "canvas";
    }

    #sidebar { display: none; }
    #menuToggle { display: flex; }
    #bottomSheet { display: flex; }
    #quickBar { display: flex; }

    #zoomControls {
        top: auto;
        bottom: 60px;
        right: 10px;
    }

    #followIndicator { bottom: 58px; }

    #canvasArea {
        height: calc(100dvh - 44px);
    }
}

/* ─── TABLET ─── */
@media (max-width: 900px) and (min-width: 681px) {
    #app { grid-template-columns: 180px 1fr; }
}

/* ─── SHEET SECTIONS ─── */
.sheet-section {
    border-bottom: 1px solid var(--border);
    padding: 10px 16px;
}

.sheet-toggles {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 2px;
}

.sheet-toggle-row {
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 6px 0;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    color: var(--text-mid);
    user-select: none;
}

.sheet-toggle-row input[type=checkbox] {
    appearance: none;
    width: 16px;
    height: 16px;
    border: 1.5px solid var(--border2);
    border-radius: 3px;
    background: var(--bg);
    cursor: pointer;
    flex-shrink: 0;
    position: relative;
}

.sheet-toggle-row input[type=checkbox]:checked {
    background: var(--accent);
    border-color: var(--accent);
}

.sheet-toggle-row input[type=checkbox]:checked::after {
    content: '✓';
    position: absolute;
    top: -1px;
    left: 2px;
    font-size: 11px;
    color: #000;
    font-weight: 900;
}

/* ─── SHEET FLOOR PILLS ─── */
.sheet-floor-section {
    border-bottom: 1px solid var(--border);
    padding: 8px 16px;
}

.sheet-floor-pills {
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
}

.sheet-floor-pill {
    flex: 1;
    min-width: 60px;
    padding: 5px 4px;
    border: 1.5px solid var(--border2);
    background: var(--bg);
    color: var(--text-dim);
    font-family: 'Barlow Condensed', sans-serif;
    font-weight: 700;
    font-size: 12px;
    cursor: pointer;
    border-radius: 4px;
    text-align: center;
    letter-spacing: 1px;
    transition: all 0.15s;
}

.sheet-floor-pill.active {
    background: var(--accent);
    border-color: var(--accent);
    color: #000;
}

#sheetPlayerList {
    padding: 6px 12px 12px;
}

.sheet-player-card {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 10px;
    border-radius: 6px;
    cursor: pointer;
    border: 1px solid transparent;
    margin-bottom: 4px;
}

.sheet-player-card.selected { border-color: var(--accent); background: var(--accent-dim); }
.sheet-player-card.dead { opacity: 0.3; }
#viewerBadge {
    display: flex;
    align-items: center;
    gap: 6px;
    background: rgba(255,255,255,0.07);
    border: 1px solid rgba(255,255,255,0.12);
    border-radius: 20px;
    padding: 4px 10px;
    font-size: 12px;
    font-weight: 600;
    color: #eee;
    white-space: nowrap;
}

#viewerDot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #4dff91;
    animation: viewerPulse 1.5s ease-in-out infinite;
}

@keyframes viewerPulse {
    0%, 100% { opacity: 1; }
    50%       { opacity: 0.35; }
}