:root {
    --bg-dark: #07090f;
    --glass-bg: rgba(16, 20, 31, 0.45);
    --glass-border: rgba(255, 255, 255, 0.08);
    --accent-cyan: #00f0ff;
    --accent-red: #ff2a55;
    --text-primary: #ffffff;
    --text-secondary: #8a9bb3;
    --neon-shadow: 0 0 20px rgba(0, 240, 255, 0.4);
    --danger-shadow: 0 0 20px rgba(255, 42, 85, 0.4);
}

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

body {
    background-color: var(--bg-dark);
    background-image: 
        radial-gradient(circle at 15% 50%, rgba(0, 240, 255, 0.05), transparent 25%),
        radial-gradient(circle at 85% 30%, rgba(255, 42, 85, 0.05), transparent 25%);
    min-height: 100vh;
    font-family: 'Inter', sans-serif;
    color: var(--text-primary);
    overflow-x: clip; /* clip prevents scroll but still allows children to render fully */
}

/* TV Static Noise Overlay for aesthetic */
#noise-overlay {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: url('data:image/svg+xml;utf8,%3CSVG xmlns="http://www.w3.org/2000/svg" width="100" height="100"%3E%3Cfilter id="noise"%3E%3CfeTurbulence type="fractalNoise" baseFrequency="0.8" numOctaves="4" stitchTiles="stitch"/%3E%3C/filter%3E%3Crect width="100" height="100" filter="url(%23noise)" opacity="0.04"/%3E%3C/SVG%3E');
    pointer-events: none;
    z-index: 9999;
}

.container {
    max-width: 1800px;
    width: 100%;
    margin: 0 auto;
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    box-sizing: border-box;
}

.glass-panel {
    background: var(--glass-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--glass-border);
    border-radius: 16px;
    box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.37);
}

/* Header */
header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.5rem 2rem;
}

.brand {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.pulse-ring {
    width: 12px;
    height: 12px;
    background: var(--accent-cyan);
    border-radius: 50%;
    box-shadow: 0 0 0 0 rgba(0, 240, 255, 0.7);
    animation: pulse 2s infinite cubic-bezier(0.66, 0, 0, 1);
}

@keyframes pulse {
    to { box-shadow: 0 0 0 15px rgba(0, 240, 255, 0); }
}

h1 {
    font-size: 1.4rem;
    font-weight: 700;
    letter-spacing: 2px;
}

.badge {
    background: var(--accent-cyan);
    color: #000;
    font-size: 0.6rem;
    padding: 2px 6px;
    border-radius: 4px;
    vertical-align: top;
    margin-left: 5px;
    font-weight: 700;
}

/* Hardware Controls */
.hardware-controls {
    display: flex;
    align-items: center;
    gap: 2rem;
}

.status-indicator {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.dot {
    width: 8px; height: 8px; border-radius: 50%;
}
.dot.online { background: var(--accent-cyan); box-shadow: var(--neon-shadow); }
.dot.offline { background: var(--accent-red); box-shadow: var(--danger-shadow); }

.btn {
    background: transparent;
    border: 1px solid var(--glass-border);
    color: white;
    padding: 0.8rem 1.5rem;
    border-radius: 8px;
    font-family: 'JetBrains Mono', monospace;
    font-weight: 700;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.btn-halted {
    border-color: var(--accent-red);
    color: var(--accent-red);
}
.btn-halted:hover {
    background: rgba(255, 42, 85, 0.1);
    box-shadow: var(--danger-shadow);
}

.btn-active {
    border-color: var(--accent-cyan);
    color: var(--accent-cyan);
}
.btn-active:hover {
    background: rgba(0, 240, 255, 0.1);
    box-shadow: var(--neon-shadow);
}

/* =============================================
   VIDEO GRID — Bulletproof responsive columns
   Based on: repeat(auto-fit, minmax(min(X, 100%), 1fr))
   This prevents: overflow, overlap, and blowout at any size.
   ============================================= */
.video-grid {
    display: grid;
    /* min(280px, 100%) ensures it ALWAYS fits within the container,
       even if the container is narrower than 280px */
    grid-template-columns: repeat(auto-fit, minmax(min(280px, 100%), 1fr));
    gap: 1rem;
    width: 100%;          /* Never wider than parent */
    box-sizing: border-box;
}

.camera-card {
    padding: 0.8rem;
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
    position: relative;   /* For calibration dots */
    min-width: 0;         /* Prevent grid blowout: allows cell to shrink below content size */
    overflow: hidden;     /* Clip any overflow from children */
    box-sizing: border-box;
}

/* Video: self-sizes to 16:9, never overflows its card */
.camera-card video {
    width: 100%;
    aspect-ratio: 16 / 9;
    object-fit: cover;
    border-radius: 8px;
    background: #000;
    display: block;
}

.cam-header {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.75rem;
    color: var(--text-secondary);
    letter-spacing: 1px;
    border-bottom: 1px solid var(--glass-border);
    padding-bottom: 0.5rem;
    overflow: hidden;
    text-overflow: ellipsis;
    flex-shrink: 0;
    /* Row layout so expand button sits on the right */
    display: flex;
    justify-content: space-between;
    align-items: center;
    white-space: nowrap;
}

/* Expand button — always visible on each camera card */
.expand-btn {
    background: none;
    border: 1px solid rgba(255,255,255,0.15);
    color: #64748b;
    border-radius: 4px;
    width: 22px;
    height: 22px;
    cursor: pointer;
    font-size: 0.8rem;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all 0.2s;
    line-height: 1;
    padding: 0;
}

.expand-btn:hover {
    border-color: var(--accent-cyan);
    color: var(--accent-cyan);
    box-shadow: 0 0 8px rgba(0,240,255,0.3);
}

/* In calibration mode the expand button glows amber */
.calibrating .expand-btn {
    border-color: rgba(245,158,11,0.5);
    color: #f59e0b;
}

/* Modal counter badge */
.modal-counter {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.85rem;
    color: #f59e0b;
    background: rgba(245,158,11,0.1);
    border: 1px solid rgba(245,158,11,0.3);
    border-radius: 20px;
    padding: 0.2rem 0.7rem;
}


iframe {
    width: 100%;
    aspect-ratio: 16 / 9;
    border: none;
    border-radius: 8px;
    background: #000;
    display: block;
}

/* =============================================
   TELEMETRY GRID — Fixed height prevents overlap
   Canvas intrinsic size (set by JS) would push
   layout if we use auto height. Fixed height + 
   overflow:hidden contains it completely.
   ============================================= */
.telemetry-grid {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 1rem;
    height: 420px;        /* Fixed: prevents canvas intrinsic size from bleeding out */
    min-height: 0;
    overflow: hidden;
}

.map-card, .log-card {
    padding: 1.2rem;
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
    min-height: 0;        /* Critical: lets flex children shrink below content size */
    overflow: hidden;     /* Canvas won't overflow the card */
    box-sizing: border-box;
}

.panel-title {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.85rem;
    color: var(--accent-cyan);
    letter-spacing: 1.5px;
    flex-shrink: 0;       /* Title never shrinks */
}

/* Canvas: fills remaining card height, JS resize handles the px values */
canvas {
    display: block;
    width: 100%;
    flex: 1 1 0;          /* Grow and shrink freely within flex parent */
    min-height: 0;        /* Critical: allow shrinking */
    background: #020305;
    border-radius: 8px;
    border: 1px solid #1a2030;
    overflow: hidden;
}


.log-window {
    flex-grow: 1;
    background: #020305;
    border-radius: 8px;
    border: 1px solid #1a2030;
    padding: 1rem;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.75rem;
    color: var(--text-secondary);
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.log-line {
    word-wrap: break-word;
}
.log-line span.id { color: #fff; font-weight: bold; }
.log-line span.dist { color: var(--accent-cyan); }
.log-line span.ang { color: var(--accent-red); }

/* --- CALIBRATOR GUI ELEMENTS --- */
.calibration-dot {
    position: absolute;
    width: 8px;
    height: 8px;
    background-color: #fbbf24; /* intense yellow */
    border: 1px solid #fff;
    border-radius: 50%;
    transform: translate(-50%, -50%);
    pointer-events: none;
    box-shadow: 0 0 10px rgba(251, 191, 36, 0.8);
    z-index: 100000; /* Ensure dots render beautifully above colossal modal boundaries */
}

/* --- FULLSCREEN MODAL OVERLAY --- */
.fullscreen-modal {
    position: fixed;
    top: 0; left: 0; width: 100vw; height: 100vh;
    background: rgba(7, 9, 15, 0.97);
    backdrop-filter: blur(24px);
    -webkit-backdrop-filter: blur(24px);
    z-index: 99990;
    display: none;          /* shown via JS: style.display = 'flex' */
    flex-direction: column;
    padding: 1.2rem 1.5rem;
    gap: 1rem;
    box-sizing: border-box;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--glass-border);
    padding-bottom: 0.8rem;
    flex-shrink: 0;
}

/* Two-column body */
.modal-body {
    display: flex;
    gap: 1.2rem;
    flex: 1;
    min-height: 0;
    overflow: hidden;
}

/* LEFT: video area expands to fill space */
.modal-video-box {
    flex: 1;
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    background: #000;
    border-radius: 12px;
    border: 2px solid var(--accent-cyan);
    box-shadow: var(--neon-shadow);
    cursor: crosshair;
    overflow: hidden;
    min-width: 0;
}

.modal-video-box video {
    max-width: 100%;
    max-height: 100%;
    border-radius: 8px;
    object-fit: contain;
    display: block;
}

.modal-video-box #radarMapWrapper {
    width: 100% !important;
    height: 100% !important;
}

/* Hint text overlay on video */
.next-point-hint {
    position: absolute;
    bottom: 1rem;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(245, 158, 11, 0.9);
    color: #000;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.8rem;
    font-weight: 700;
    padding: 0.4rem 1rem;
    border-radius: 20px;
    pointer-events: none;
    white-space: nowrap;
    letter-spacing: 1px;
}

/* RIGHT: guide panel fixed width, scrollable */
.modal-guide {
    width: 280px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    overflow-y: auto;
    padding-right: 0.3rem;
}

.guide-section-title {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.7rem;
    color: var(--accent-cyan);
    letter-spacing: 2px;
    border-bottom: 1px solid rgba(0,240,255,0.15);
    padding-bottom: 0.3rem;
    flex-shrink: 0;
}

/* SVG floor diagram */
.floor-diagram-svg {
    width: 100%;
    max-height: 200px;
    flex-shrink: 0;
}

/* Step list */
.guide-steps {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.guide-step {
    display: flex;
    align-items: flex-start;
    gap: 0.6rem;
    padding: 0.5rem 0.6rem;
    border-radius: 6px;
    border: 1px solid transparent;
    transition: all 0.2s;
}

.guide-step.active-step {
    background: rgba(245, 158, 11, 0.1);
    border-color: rgba(245, 158, 11, 0.4);
}

.guide-step.done-step {
    opacity: 0.5;
}

.step-num {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: rgba(100,116,139,0.3);
    border: 1px solid #475569;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.75rem;
    font-weight: 700;
    color: #94a3b8;
    flex-shrink: 0;
    transition: all 0.2s;
}

.step-num.active {
    background: rgba(245,158,11,0.2);
    border-color: #f59e0b;
    color: #f59e0b;
    box-shadow: 0 0 8px rgba(245,158,11,0.4);
}

.step-num.done {
    background: rgba(16,185,129,0.2);
    border-color: #10b981;
    color: #10b981;
}

.step-text {
    display: flex;
    flex-direction: column;
    font-size: 0.8rem;
}

.step-text strong {
    color: var(--text-primary);
    font-size: 0.82rem;
}

.step-text span {
    color: var(--text-secondary);
    font-size: 0.72rem;
}

/* Coordinates table */
.coords-table {
    width: 100%;
    border-collapse: collapse;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.72rem;
}

.coords-table th {
    color: #475569;
    padding: 0.25rem 0.3rem;
    text-align: left;
    border-bottom: 1px solid rgba(255,255,255,0.05);
    font-weight: 500;
}

.coords-table td {
    padding: 0.25rem 0.3rem;
    color: #64748b;
    border-bottom: 1px solid rgba(255,255,255,0.03);
    transition: color 0.3s;
}

.coords-table tr.captured td {
    color: #10b981;
}

.guide-tip {
    font-size: 0.72rem;
    color: #475569;
    background: rgba(255,255,255,0.03);
    border: 1px solid rgba(255,255,255,0.05);
    border-radius: 6px;
    padding: 0.6rem 0.7rem;
    line-height: 1.5;
    margin-top: 0.2rem;
}

.guide-tip strong {
    color: #94a3b8;
}



/* =============================================
   RESPONSIVE BREAKPOINTS
   NOTE: .video-grid needs NO breakpoints —
   auto-fit + minmax(min(280px,100%), 1fr) handles
   it natively at any width.
   ============================================= */

/* ≤1100px: Telemetry stacks to single column */
@media (max-width: 1100px) {
    .container { padding: 1.2rem; gap: 1.2rem; }
    h1 { font-size: 1.2rem; }
    .telemetry-grid {
        grid-template-columns: 1fr;
        height: auto;
    }
    .map-card  { height: 320px; overflow: hidden; }
    .log-card  { height: 200px; overflow: hidden; }
}

/* ≤900px: Header wraps, buttons shrink */
@media (max-width: 900px) {
    header {
        flex-wrap: wrap;
        gap: 0.8rem;
        padding: 1rem;
    }
    .hardware-controls {
        width: 100%;
        justify-content: flex-end;
        flex-wrap: wrap;
    }
    .btn {
        padding: 0.6rem 1rem;
        font-size: 0.8rem;
    }
}

/* ≤640px: Mobile */
@media (max-width: 640px) {
    .container { padding: 0.8rem; gap: 0.8rem; }
    .hardware-controls { gap: 0.5rem; }
    .btn {
        padding: 0.5rem 0.8rem;
        font-size: 0.75rem;
        letter-spacing: 0;
    }
    h1 { font-size: 1rem; letter-spacing: 1px; }
    .badge { display: none; }
    .fullscreen-modal { padding: 1rem; gap: 1rem; }
    .map-card  { height: 260px; }
    .log-card  { height: 160px; }
}
