:root {
    /* Color Palette */
    --bg-dark: #050505;
    --bg-panel: #0a0a0a;
    --primary-blue: #00f0ff;
    --primary-pink: #ff0055;
    --grid-line: rgba(0, 240, 255, 0.1);
    --text-main: #e0e0e0;
    --text-dim: #707070;

    /* Effects */
    --glow-blue: 0 0 10px rgba(0, 240, 255, 0.5), 0 0 20px rgba(0, 240, 255, 0.3);
    --glow-pink: 0 0 10px rgba(255, 0, 85, 0.5);

    /* Fonts */
    --font-heading: 'Orbitron', sans-serif;
    --font-mono: 'Rajdhani', monospace;
}

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

body {
    background-color: var(--bg-dark);
    color: var(--text-main);
    font-family: var(--font-mono);
    height: 100vh;
    overflow: hidden;
    user-select: none;
}

/* Background Grid */
.bg-grid {
    position: fixed;
    top: 0;
    left: 0;
    width: 200%;
    height: 200%;
    background-image:
        linear-gradient(var(--grid-line) 1px, transparent 1px),
        linear-gradient(90deg, var(--grid-line) 1px, transparent 1px);
    background-size: 50px 50px;
    background-position: center center;
    transform: perspective(500px) rotateX(60deg) translateY(-100px) translateZ(-200px);
    animation: grid-move 20s linear infinite;
    z-index: -1;
    pointer-events: none;
    opacity: 0.5;
}

@keyframes grid-move {
    0% {
        transform: perspective(500px) rotateX(60deg) translateY(0) translateZ(-200px);
    }

    100% {
        transform: perspective(500px) rotateX(60deg) translateY(50px) translateZ(-200px);
    }
}

.app-container {
    display: flex;
    flex-direction: column;
    height: 100%;
}

/* Header */
.game-header {
    height: 80px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 40px;
    border-bottom: 1px solid var(--primary-blue);
    background: rgba(10, 10, 10, 0.9);
    backdrop-filter: blur(10px);
}

.neon-text {
    font-family: var(--font-heading);
    color: #fff;
    font-size: 2.5rem;
    letter-spacing: 2px;
    text-shadow: var(--glow-blue);
}

.neon-text span {
    color: var(--primary-pink);
    text-shadow: var(--glow-pink);
}

.status-panel {
    font-family: var(--font-mono);
    border: 1px solid var(--primary-blue);
    padding: 8px 16px;
    border-radius: 4px;
    background: rgba(0, 240, 255, 0.05);
}

.status-value {
    color: var(--primary-blue);
    font-weight: bold;
    margin-left: 8px;
    animation: pulse 2s infinite;
}

/* Main Layout */
.game-interface {
    flex: 1;
    display: flex;
    overflow: hidden;
}

/* Control Panel */
.control-panel {
    width: 350px;
    background: rgba(10, 10, 10, 0.8);
    border-right: 1px solid var(--primary-blue);
    padding: 30px;
    display: flex;
    flex-direction: column;
    gap: 30px;
    backdrop-filter: blur(5px);
}

.panel-section h2,
.panel-section h3 {
    font-family: var(--font-heading);
    color: var(--primary-blue);
    font-size: 1.1rem;
    margin-bottom: 20px;
    border-bottom: 2px solid var(--primary-blue);
    padding-bottom: 5px;
    display: inline-block;
}

/* Buttons */
.cyber-btn {
    position: relative;
    width: 100%;
    padding: 15px;
    margin-bottom: 15px;
    background: transparent;
    border: 1px solid var(--primary-blue);
    color: var(--primary-blue);
    font-family: var(--font-heading);
    font-size: 1rem;
    cursor: pointer;
    overflow: hidden;
    transition: all 0.3s;
    text-transform: uppercase;
}

.cyber-btn .btn-content {
    position: relative;
    z-index: 2;
}

.cyber-btn::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: var(--primary-blue);
    transition: left 0.3s;
    z-index: 1;
}

.cyber-btn:hover::before,
.cyber-btn.active::before {
    left: 0;
}

.cyber-btn:hover .btn-content,
.cyber-btn.active .btn-content {
    color: #000;
}

.cyber-btn.primary {
    border-color: var(--primary-blue);
    box-shadow: 0 0 10px rgba(0, 240, 255, 0.2);
}

.cyber-btn.danger {
    border-color: var(--primary-pink);
    color: var(--primary-pink);
}

.cyber-btn.danger::before {
    background: var(--primary-pink);
}

.cyber-btn.hidden {
    display: none;
}

/* Stats */
.stat-row {
    display: flex;
    justify-content: space-between;
    margin-bottom: 10px;
    font-size: 1.1rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    padding-bottom: 5px;
}

.mono {
    font-family: monospace;
    color: var(--primary-blue);
}

/* Console */
.console-output {
    flex: 1;
    background: #000;
    border: 1px solid #333;
    padding: 10px;
    font-family: monospace;
    color: #0f0;
    font-size: 0.9rem;
    overflow-y: auto;
    opacity: 0.8;
}

.log-line {
    margin-bottom: 5px;
}

/* Viewport Layout */
.viewport-container {
    flex: 1;
    position: relative;
    display: flex;
    flex-direction: column;
    /* Stack HUD and Canvas */
    align-items: center;
    justify-content: center;
    padding: 10px;
    background: rgba(0, 0, 0, 0.5);
    overflow: hidden;
}

.viewport-frame {
    position: relative;
    width: 100%;
    height: 100%;
    border: 2px solid var(--primary-blue);
    box-shadow: 0 0 30px rgba(0, 240, 255, 0.1);
    background: #000;
}

canvas {
    display: block;
    width: 100%;
    height: 100%;
}

/* HUD System (Stepper) */
.game-hud {
    display: flex;
    gap: 20px;
    margin-bottom: 15px;
    /* Separation from canvas */
    z-index: 5;
    background: transparent;
    padding: 0;
    border: none;
    box-shadow: none;
}

.hud-phase {
    color: var(--text-dim);
    font-size: 1rem;
    padding: 8px 15px;
    border: 1px solid #333;
    border-radius: 4px;
    font-weight: bold;
    text-transform: uppercase;
    transition: all 0.3s;
    background: rgba(0, 0, 0, 0.5);
    opacity: 0.5;
}

.hud-phase.active {
    background: rgba(0, 240, 255, 0.1);
    color: var(--primary-blue);
    border-color: var(--primary-blue);
    box-shadow: 0 0 15px rgba(0, 240, 255, 0.2);
    opacity: 1;
    transform: scale(1.05);
}

/* Overlay Layer */
.overlay-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    /* Let clicks pass through to canvas */
    z-index: 2;
    overflow: hidden;
}

/* High Visibility Marker */
.marker {
    position: absolute;
    transform: translate(-50%, -100%);
    /* Bottom point at coord */
    display: flex;
    flex-direction: column;
    align-items: center;
}

.marker.goal .marker-icon {
    font-size: 2rem;
    color: var(--primary-pink);
    text-shadow: 0 0 10px var(--primary-pink);
    animation: bounce 2s infinite ease-in-out;
}

.marker.goal .marker-pulse {
    width: 40px;
    height: 40px;
    background: rgba(255, 0, 85, 0.4);
    border-radius: 50%;
    position: absolute;
    bottom: -10px;
    animation: ripple 2s infinite linear;
}

@keyframes bounce {

    0%,
    100% {
        transform: translateY(0);
    }

    50% {
        transform: translateY(-10px);
    }
}

@keyframes ripple {
    0% {
        transform: scale(0.1);
        opacity: 1;
    }

    100% {
        transform: scale(2);
        opacity: 0;
    }
}

/* Loader */
.loader-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.9);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 10;
}

.scanner-line {
    width: 100%;
    height: 2px;
    background: var(--primary-blue);
    box-shadow: 0 0 15px var(--primary-blue);
    animation: scan 2s infinite ease-in-out;
}

.loading-text {
    margin-top: 20px;
    font-family: var(--font-heading);
    color: var(--primary-blue);
    letter-spacing: 5px;
    animation: blink 0.5s infinite;
}

.hidden {
    display: none !important;
}

@keyframes scan {
    0% {
        transform: translateY(-50px);
        opacity: 0;
    }

    50% {
        opacity: 1;
    }

    100% {
        transform: translateY(50px);
        opacity: 0;
    }
}

@keyframes blink {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.5;
    }
}

@keyframes pulse {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.7;
    }
}

/* Mobile Responsiveness */
@media (max-width: 768px) {

    /* Adjust Layout Direction */
    .game-interface {
        flex-direction: column;
    }

    /* Control Panel adjustments for mobile */
    .control-panel {
        width: 100%;
        max-height: 40vh;
        /* Occupy bottom part of screen */
        border-right: none;
        border-top: 1px solid var(--primary-blue);
        padding: 15px;
        order: 2;
        /* Move to bottom */
        overflow-y: auto;
        /* Allow scrolling within panel if needed */
        gap: 15px;
    }

    /* Adjust Viewport to take remaining space */
    .viewport-container {
        height: 60vh;
        /* Give meaningful space to the game */
        flex: none;
        /* Disable flex growing to strictly respect height */
        order: 1;
        /* Move to top */
        padding: 5px;
    }

    /* Header Adjustments */
    .game-header {
        height: 60px;
        padding: 0 15px;
    }

    .neon-text {
        font-size: 1.5rem;
    }

    .status-panel {
        padding: 4px 8px;
        font-size: 0.8rem;
    }

    /* Adjust panel sections to be more compact */
    .panel-section {
        margin-bottom: 0;
    }

    .panel-section h2,
    .panel-section h3 {
        font-size: 0.9rem;
        margin-bottom: 10px;
    }

    /* Make buttons more touch-friendly but compact */
    .cyber-btn {
        padding: 10px;
        margin-bottom: 10px;
        font-size: 0.9rem;
    }

    /* Stats row compaction */
    .stat-row {
        font-size: 0.9rem;
        margin-bottom: 5px;
    }

    /* HUD adjustments */
    .game-hud {
        gap: 5px;
        margin-bottom: 5px;
        flex-wrap: wrap;
        justify-content: center;
    }

    .hud-phase {
        font-size: 0.7rem;
        padding: 4px 8px;
    }

    /* Fix for Console Output clipping */
    .console-output {
        flex: 0 0 auto;
        /* Don't shrink or stretch, just take needed space */
        height: auto;
        /* Grow to fit content */
        min-height: 60px;
        /* Ensure minimum visibility */
        max-height: 150px;
        /* Prevent it from taking over the whole panel */
        overflow-y: auto;
        /* Scroll internally if it gets too big */
        padding: 10px;
        margin-top: 10px;
    }
}