:root {
    --bg-color: #050505;
    --text-primary: #a8ffb2; /* Ghostly Green */
    --text-alert: #ff3333;
    --text-dim: #4a5a4a;
    --hud-bg: rgba(0, 20, 0, 0.85);
    --scanline-color: rgba(0, 255, 0, 0.05);
    --font-main: "Courier New", Courier, monospace;
}

body {
    margin: 0;
    background-color: var(--bg-color);
    color: var(--text-primary);
    font-family: var(--font-main);
    overflow: hidden;
    height: 100vh;
    width: 100vw;
}

/* CRT SCANLINE EFFECT */
.scanlines {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: linear-gradient(
        to bottom,
        rgba(255,255,255,0),
        rgba(255,255,255,0) 50%,
        rgba(0,0,0,0.2) 50%,
        rgba(0,0,0,0.2)
    );
    background-size: 100% 4px;
    pointer-events: none;
    z-index: 999;
}

.vignette {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    box-shadow: 0 0 150px rgba(0,0,0,0.9) inset;
    pointer-events: none;
    z-index: 998;
}

/* UTILS */
.hidden { display: none !important; }
.active { display: flex !important; }

/* SCREENS */
.screen {
    display: none;
    flex-direction: column;
    height: 100%;
    width: 100%;
    padding: 20px;
    box-sizing: border-box;
    align-items: center;
    justify-content: center;
}

/* MENU */
.menu-container {
    border: 2px solid var(--text-primary);
    padding: 40px;
    background: var(--hud-bg);
    box-shadow: 0 0 20px var(--text-primary);
    text-align: center;
    max-width: 600px;
    width: 90%;
}

h1 {
    font-size: 3rem;
    margin-bottom: 10px;
    text-shadow: 0 0 10px var(--text-primary);
    letter-spacing: 5px;
}

.btn-group {
    display: flex;
    flex-direction: column;
    gap: 15px;
    margin-top: 30px;
}

button {
    background: transparent;
    border: 1px solid var(--text-primary);
    color: var(--text-primary);
    padding: 15px 30px;
    font-family: var(--font-main);
    font-size: 1.2rem;
    cursor: pointer;
    transition: all 0.2s;
    text-transform: uppercase;
}

button:hover {
    background: var(--text-primary);
    color: black;
    box-shadow: 0 0 15px var(--text-primary);
}

button.alert {
    border-color: var(--text-alert);
    color: var(--text-alert);
}
button.alert:hover {
    background: var(--text-alert);
    color: black;
    box-shadow: 0 0 15px var(--text-alert);
}

/* GLOBAL HEADER */
#global-header {
    width: 100%;
    height: 60px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 20px;
    box-sizing: border-box;
    background: var(--hud-bg);
    border-bottom: 2px solid var(--text-primary);
    z-index: 1000;
}

.brand {
    font-size: 1.5rem;
    font-weight: bold;
    letter-spacing: 2px;
}

.highlight {
    color: var(--text-primary);
    text-shadow: 0 0 5px var(--text-primary);
}

.status-indicator {
    padding: 5px 10px;
    border: 1px solid currentColor;
    border-radius: 4px;
    font-size: 0.8rem;
    font-weight: bold;
}

.status-indicator.connected { color: #00ff41; border-color: #00ff41; box-shadow: 0 0 5px #00ff41; }
.status-indicator.disconnected { color: red; border-color: red; box-shadow: 0 0 5px red; }

/* ACTIVE SCREEN & HUD */
#active-screen {
    padding: 0;
    justify-content: flex-start;
    height: calc(100vh - 60px); /* Subtract header height */
    position: relative;
}

#toolbar {
    width: 100%;
    height: 50px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 20px;
    background: var(--hud-bg);
    border-bottom: 1px solid var(--text-primary);
    box-sizing: border-box;
    z-index: 100;
}

/* SONDE VIEW */
#sonde-view {
    width: 100%;
    height: calc(100% - 50px); /* Subtract toolbar height */
    position: relative;
    display: flex;
    flex-direction: column;
}

.video-wrapper {
    position: relative;
    width: 100%;
    height: 100%;
    background: #000;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
}

video#input_video, canvas#output_canvas {
    position: absolute;
    width: 100%;
    height: 100%;
    object-fit: contain; /* Maintain aspect ratio */
    z-index: 1; /* Ensure video is above background but below HUD */
}

video#input_video {
    /* If we are using canvas for drawing pose, we might want to hide raw video or put it behind */
    /* But for debugging visibility, let's ensure it is visible if canvas is not drawn yet */
    display: block;
}

/* HUD OVERLAYS */
.hud-controls {
    position: absolute;
    bottom: 20px;
    right: 20px;
    display: flex;
    flex-direction: column;
    gap: 15px;
    z-index: 10;
    padding-right: max(10px, env(safe-area-inset-right));
    padding-bottom: max(10px, env(safe-area-inset-bottom));
}

.hud-btn {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    font-size: 24px;
    background: rgba(0,0,0,0.5);
}

#status-readout {
    position: absolute;
    top: 20px;
    left: 20px;
    font-size: 1.5rem;
    font-weight: bold;
    color: var(--text-primary);
    text-shadow: 0 0 5px black;
    background: rgba(0,0,0,0.5);
    padding: 5px 10px;
    z-index: 10;
}

/* PC CENTRAL GRID */
#pc-central-view {
    width: 100%;
    height: calc(100% - 50px);
    display: flex;
    flex-direction: row; /* Split between Grid and Log/Controls */
}

#probes-grid {
    flex: 3;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
    gap: 10px;
    padding: 10px;
    overflow-y: auto;
    align-content: start;
}

/* PROBE CARD (VIDEO FEED) */
.probe-card {
    background: #111;
    border: 1px solid var(--text-dim);
    display: flex;
    flex-direction: column;
    position: relative;
    aspect-ratio: 16/9;
}

.probe-card.alert {
    border: 2px solid var(--text-alert);
    box-shadow: 0 0 20px var(--text-alert) inset;
}

.video-preview-container {
    flex: 1;
    position: relative;
    overflow: hidden;
    background: #000;
}

.live-feed {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.probe-ui {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: rgba(0,0,0,0.7);
    padding: 5px 10px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.9rem;
}

.probe-controls {
    display: flex;
    gap: 5px;
}

.mini-btn {
    padding: 2px 8px;
    font-size: 0.8rem;
    border: 1px solid var(--text-primary);
}

/* LOG PANEL */
#central-panel {
    flex: 1;
    border-left: 1px solid var(--text-primary);
    background: rgba(0,10,0,0.3);
    display: flex;
    flex-direction: column;
    padding: 10px;
    min-width: 300px;
}

.log-title {
    font-size: 1.2rem;
    border-bottom: 1px solid var(--text-dim);
    margin-bottom: 10px;
    padding-bottom: 5px;
}

/* PC CENTRAL CONTROLS */
.control-group {
    display: flex;
    gap: 10px;
    align-items: center;
    margin-bottom: 10px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--text-dim);
}

.toggle-control {
    display: flex;
    align-items: center;
    gap: 5px;
    cursor: pointer;
    font-size: 0.9rem;
    border: 1px solid var(--text-primary);
    padding: 2px 5px;
    transition: all 0.2s;
}

.toggle-control:hover {
    background: rgba(0, 255, 65, 0.1);
}

.toggle-control input {
    accent-color: var(--text-primary);
}

#central-log {
    flex: 1;
    overflow-y: auto;
    font-size: 0.9rem;
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.log-msg { opacity: 0.8; }
.log-msg.alert { color: var(--text-alert); font-weight: bold; }

/* MODAL */
.modal {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
}

.modal-content {
    background: var(--bg-color);
    border: 2px solid var(--text-primary);
    padding: 20px;
    width: 300px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

/* PERMISSION PROMPT */
#permission-overlay {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: black;
    color: white;
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
}

/* LATENCY INDICATOR */
.latency-indicator {
    font-size: 0.8rem;
    font-weight: bold;
    padding: 2px 5px;
    border-radius: 3px;
    background: rgba(0,0,0,0.5);
    margin-left: 10px;
}

.latency-good {
    color: #00ff41;
}

.latency-warning {
    color: #ffcc00;
    animation: pulse 2s infinite;
}

.latency-critical {
    color: #ff0000;
    border: 1px solid red;
    animation: flash 1s infinite;
}

@keyframes pulse {
    0% { opacity: 1; }
    50% { opacity: 0.5; }
    100% { opacity: 1; }
}

@keyframes flash {
    0% { background: rgba(255,0,0,0.1); }
    50% { background: rgba(255,0,0,0.5); }
    100% { background: rgba(255,0,0,0.1); }
}

/* RESPONSIVE */
@media (max-width: 768px) {
    #pc-central-view { flex-direction: column; }
    #central-panel { max-height: 200px; border-left: none; border-top: 1px solid var(--text-primary); }
    #probes-grid { grid-template-columns: 1fr; }
}

/* MOBILE OPTIMIZATIONS (Agent Detected) */
body.is-mobile .btn-menu {
    padding: 25px;
    font-size: 1.3rem;
}

body.is-mobile .hud-controls {
    bottom: 40px;
    gap: 20px;
}

body.is-mobile .hud-btn {
    width: 70px;
    height: 70px;
    font-size: 28px;
    background: rgba(0, 20, 0, 0.7);
    border: 2px solid var(--text-primary);
}

body.is-mobile #status-readout {
    font-size: 1.2rem;
    top: 10px;
    left: 10px;
    right: 10px;
    background: rgba(0,0,0,0.7);
    border: 1px solid var(--text-primary);
}

/* Simplify Mobile Menu */
body.is-mobile .terminal-content {
    width: 100%;
    padding: 10px;
}

body.is-mobile .menu-container {
    padding: 20px;
}

/* Better touch targets for setup */
body.is-mobile .input-group input {
    height: 50px;
    font-size: 1.5rem;
}

body.is-mobile #nearby-rooms-list button {
    padding: 15px;
    width: 100%;
    margin-bottom: 10px;
}
