:root {
    /* Color Palette - Premium Futuristic */
    --bg-dark: #0a0a12;
    --bg-panel: rgba(20, 20, 35, 0.6);
    --panel-border: rgba(100, 100, 255, 0.2);
    
    --neon-cyan: #00f3ff;
    --neon-purple: #bc13fe;
    --neon-green: #00ff66;
    --neon-red: #ff0055;
    --text-main: #ffffff;
    --text-muted: #8a8a9d;
    
    /* Typography */
    --font-heading: 'Outfit', sans-serif;
    --font-mono: 'Space Mono', monospace;
    
    /* Effects */
    --glass-blur: blur(16px);
    --shadow-neon: 0 0 10px rgba(0, 243, 255, 0.3), 0 0 20px rgba(0, 243, 255, 0.1);
    --transition-smooth: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    user-select: none; /* Prevent text selection in game */
}

body {
    background-color: var(--bg-dark);
    color: var(--text-main);
    font-family: var(--font-heading);
    overflow: hidden; /* Prevent scrolling */
    width: 100vw;
    height: 100vh;
    touch-action: none; /* Prevent default touch actions on mobile */
}

/* Background Effects */
#bg-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: -1;
    background-image: url('../assets/images/background.png');
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
}

.glow-grid {
    position: absolute;
    width: 200%;
    height: 200%;
    top: -50%;
    left: -50%;
    background-image: 
        linear-gradient(rgba(0, 243, 255, 0.05) 1px, transparent 1px),
        linear-gradient(90deg, rgba(0, 243, 255, 0.05) 1px, transparent 1px);
    background-size: 40px 40px;
    transform: perspective(500px) rotateX(60deg) translateY(100px);
    animation: gridMove 20s linear infinite;
    pointer-events: none;
}

@keyframes gridMove {
    0% { transform: perspective(500px) rotateX(60deg) translateY(0); }
    100% { transform: perspective(500px) rotateX(60deg) translateY(40px); }
}

.ambient-light {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 60vw;
    height: 60vw;
    transform: translate(-50%, -50%);
    background: radial-gradient(circle, rgba(188, 19, 254, 0.15) 0%, transparent 70%);
    pointer-events: none;
}

/* Screens */
.screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.5s ease;
}

.screen.active {
    opacity: 1;
    pointer-events: auto;
    z-index: 10;
}

.screen.hidden {
    display: none;
}

.overlay {
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(5px);
    z-index: 100;
    justify-content: center;
    align-items: center;
}

/* Glassmorphism Panels */
.glass-panel {
    background: var(--bg-panel);
    backdrop-filter: var(--glass-blur);
    -webkit-backdrop-filter: var(--glass-blur);
    border: 1px solid var(--panel-border);
    border-radius: 16px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.5), inset 0 1px 0 rgba(255,255,255,0.1);
}

/* Main Menu */
#start-screen {
    justify-content: center;
    align-items: center;
}

.main-menu {
    padding: 40px;
    text-align: center;
    max-width: 500px;
    width: 90%;
    transform: translateY(20px);
    animation: floatIn 1s forwards cubic-bezier(0.1, 0.8, 0.1, 1);
}

@keyframes floatIn {
    to { transform: translateY(0); }
}

h1.glitch {
    font-size: 3rem;
    font-weight: 800;
    letter-spacing: 2px;
    margin-bottom: 5px;
    background: linear-gradient(to right, var(--neon-cyan), var(--neon-purple));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    text-shadow: var(--shadow-neon);
}

.subtitle {
    font-size: 1.2rem;
    font-weight: 300;
    color: var(--text-muted);
    letter-spacing: 4px;
    margin-bottom: 30px;
}

.guide-box {
    text-align: left;
    background: rgba(0,0,0,0.3);
    padding: 20px;
    border-radius: 8px;
    margin-bottom: 30px;
    border-left: 3px solid var(--neon-cyan);
}

.guide-box h3 {
    margin-bottom: 10px;
    font-size: 1rem;
    text-transform: uppercase;
    color: var(--neon-cyan);
}

.guide-box ul {
    list-style: none;
}

.guide-box li {
    margin-bottom: 10px;
    font-size: 0.95rem;
    display: flex;
    align-items: center;
}

.guide-box .icon {
    margin-right: 10px;
    font-size: 1.2rem;
}

/* Cyber Buttons */
.cyber-btn {
    background: linear-gradient(145deg, #1e1e2d, #151520);
    color: var(--neon-cyan);
    font-family: var(--font-heading);
    font-size: 1.1rem;
    font-weight: 800;
    letter-spacing: 2px;
    padding: 15px 30px;
    border: 1px solid rgba(255,255,255,0.05);
    border-radius: 12px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
    transition: all 0.2s cubic-bezier(0.25, 0.8, 0.25, 1);
    box-shadow: 
        8px 8px 16px rgba(0, 0, 0, 0.8), 
        -4px -4px 10px rgba(255, 255, 255, 0.05),
        inset 0px 2px 2px rgba(255, 255, 255, 0.1);
    text-shadow: 0 0 5px rgba(0, 243, 255, 0.5);
    width: 100%;
    text-transform: uppercase;
}

.cyber-btn:active {
    box-shadow: 
        inset 8px 8px 16px rgba(0, 0, 0, 0.8), 
        inset -4px -4px 10px rgba(255, 255, 255, 0.02);
    transform: translateY(2px);
    color: #fff;
    text-shadow: 0 0 10px var(--neon-cyan);
}

.cyber-btn.primary {
    border-bottom: 2px solid var(--neon-cyan);
}

.cyber-btn.success {
    color: var(--neon-green);
    border-bottom: 2px solid var(--neon-green);
    text-shadow: 0 0 5px rgba(0, 255, 102, 0.5);
}

.cyber-btn.success:active {
    text-shadow: 0 0 10px var(--neon-green);
}

/* Game Interface HUD */
#hud-header {
    display: flex;
    justify-content: space-between;
    padding: 20px;
    z-index: 20;
    pointer-events: none; /* Let clicks pass through empty areas */
}

#hud-header > * {
    pointer-events: auto;
}

.level-info {
    padding: 10px 20px;
    display: flex;
    flex-direction: column;
}

.level-label {
    font-size: 0.8rem;
    color: var(--text-muted);
    font-weight: 600;
    letter-spacing: 1px;
}

.level-title {
    font-size: 1.2rem;
    font-weight: 600;
    color: var(--neon-cyan);
    text-shadow: 0 0 5px rgba(0, 243, 255, 0.5);
}

.controls {
    display: flex;
    gap: 10px;
    padding: 5px;
}

.icon-btn {
    background: transparent;
    border: none;
    color: var(--text-main);
    font-size: 1.5rem;
    cursor: pointer;
    width: 44px;
    height: 44px;
    border-radius: 8px;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: var(--transition-smooth);
}

.icon-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    transform: scale(1.05);
}

#hud-footer {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    width: 90%;
    max-width: 600px;
    z-index: 20;
}

.test-panel {
    display: flex;
    align-items: center;
    padding: 15px;
    gap: 15px;
}

.status-indicator {
    display: flex;
    flex-direction: column;
    align-items: center;
    min-width: 100px;
}

.status-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--text-muted);
    margin-bottom: 5px;
    box-shadow: 0 0 5px rgba(0,0,0,0.5);
    transition: var(--transition-smooth);
}

.status-dot.active {
    background: var(--neon-cyan);
    box-shadow: 0 0 10px var(--neon-cyan);
}

.status-dot.error {
    background: var(--neon-red);
    box-shadow: 0 0 10px var(--neon-red);
}

.status-dot.success {
    background: var(--neon-green);
    box-shadow: 0 0 10px var(--neon-green);
}

#system-status-text {
    font-family: var(--font-mono);
    font-size: 0.7rem;
    color: var(--text-muted);
    white-space: nowrap;
}

.objective-box {
    flex-grow: 1;
    font-size: 0.95rem;
    color: var(--text-main);
    border-left: 2px solid var(--neon-purple);
    padding-left: 10px;
}

/* Game Canvas & Nodes Area */
#canvas-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 5;
}

#game-canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
    pointer-events: none; /* Let clicks pass through to nodes layer */
}

#nodes-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 2;
}

/* Device Nodes */
.device-node {
    position: absolute;
    width: 90px;
    height: 90px;
    background: linear-gradient(145deg, #1e1e2d, #151520);
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: 20px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
    padding: 5px;
    cursor: grab;
    transform: translate(-50%, -50%);
    box-shadow: 
        10px 10px 20px rgba(0, 0, 0, 0.6), 
        -5px -5px 15px rgba(255, 255, 255, 0.03),
        inset 0px 2px 2px rgba(255, 255, 255, 0.1),
        inset 0px -2px 5px rgba(0, 0, 0, 0.5);
    transition: all 0.2s cubic-bezier(0.25, 0.8, 0.25, 1);
    user-select: none;
    z-index: 10;
}

.device-node:active {
    cursor: grabbing;
    box-shadow: 
        inset 5px 5px 10px rgba(0, 0, 0, 0.8), 
        inset -2px -2px 5px rgba(255, 255, 255, 0.02);
    transform: translate(-50%, -48%) scale(0.96);
}

.device-node.type-trigger {
    border-bottom: 3px solid rgba(188, 19, 254, 0.4);
}

.device-node.type-action {
    border-bottom: 3px solid rgba(0, 243, 255, 0.4);
}

.device-node.type-logic {
    border-bottom: 3px solid rgba(255, 165, 0, 0.4);
}

.device-icon {
    font-size: 2.2rem;
    margin-bottom: 8px;
    filter: drop-shadow(0 2px 4px rgba(0,0,0,0.8));
    transition: filter 0.3s, transform 0.3s;
}

.device-label {
    font-size: 0.65rem;
    line-height: 1.1;
    width: 100%;
    word-wrap: break-word;
    font-family: var(--font-mono);
    text-transform: uppercase;
    color: var(--text-muted);
    font-weight: 700;
    letter-spacing: 1px;
    text-shadow: 0 1px 2px rgba(0,0,0,0.8);
}

/* Node States */
.device-node.active {
    background: linear-gradient(145deg, #151520, #1e1e2d);
    border: 1px solid var(--neon-cyan);
    box-shadow: 
        5px 5px 15px rgba(0, 0, 0, 0.8), 
        inset 0px 4px 10px rgba(0, 0, 0, 0.8),
        0 0 15px rgba(0, 243, 255, 0.3);
}

.device-node.active .device-icon {
    filter: drop-shadow(0 0 10px var(--neon-cyan));
    transform: scale(1.1);
}

.device-node.active .device-label {
    color: #fff;
    text-shadow: 0 0 5px var(--neon-cyan);
}

.device-node.type-trigger.active {
    border-color: var(--neon-purple);
    box-shadow: 
        5px 5px 15px rgba(0, 0, 0, 0.8), 
        inset 0px 4px 10px rgba(0, 0, 0, 0.8),
        0 0 15px rgba(188, 19, 254, 0.3);
}

.device-node.type-trigger.active .device-icon {
    filter: drop-shadow(0 0 10px var(--neon-purple));
}

.device-node.type-trigger.active .device-label {
    text-shadow: 0 0 5px var(--neon-purple);
}

/* Connection Ports */
.port {
    position: absolute;
    width: 16px;
    height: 16px;
    background: #111;
    border: 2px solid #555;
    border-radius: 50%;
    z-index: 3;
    cursor: pointer;
    transition: var(--transition-smooth);
}

.port:hover {
    transform: scale(1.3);
    background: var(--neon-cyan);
    border-color: #fff;
    box-shadow: 0 0 10px var(--neon-cyan);
}

.port-out {
    right: -8px;
    top: 50%;
    transform: translateY(-50%);
    border-color: var(--neon-purple);
}

.port-in {
    left: -8px;
    top: 50%;
    transform: translateY(-50%);
    border-color: var(--neon-cyan);
}

.port-in.top { left: 50%; top: -8px; transform: translateX(-50%); }
.port-out.bottom { left: 50%; bottom: -8px; top: auto; transform: translateX(-50%); }

/* Interactive States */
.device-node.connecting {
    animation: pulseBorder 1s infinite;
}

@keyframes pulseBorder {
    0% { border-color: rgba(255,255,255,0.2); }
    50% { border-color: rgba(255,255,255,0.8); box-shadow: 0 0 10px rgba(255,255,255,0.5); }
    100% { border-color: rgba(255,255,255,0.2); }
}

/* Success Overlay */
.success-panel {
    padding: 40px;
    text-align: center;
    max-width: 400px;
    width: 90%;
    transform: scale(0.9);
    transition: transform 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.screen.active .success-panel {
    transform: scale(1);
}

.success-panel h2 {
    color: var(--neon-green);
    font-size: 2rem;
    margin-bottom: 10px;
    text-shadow: 0 0 10px rgba(0, 255, 102, 0.3);
}

.success-stats {
    color: var(--text-muted);
    margin-bottom: 30px;
}

.highlight {
    color: #fff;
    font-family: var(--font-mono);
    font-weight: 700;
}

/* Responsive */
@media (max-width: 768px) {
    h1.glitch { font-size: 2.2rem; }
    .device-node { width: 85px; height: 85px; border-radius: 16px; }
    .device-icon { font-size: 1.8rem; margin-bottom: 4px; }
    .device-label { font-size: 0.55rem; letter-spacing: 0px; }
    .test-panel { flex-direction: column; align-items: stretch; text-align: center; gap: 10px; }
    .objective-box { border-left: none; border-bottom: 1px solid var(--neon-purple); padding-bottom: 10px; padding-left: 0; }
    .port { width: 22px; height: 22px; } /* Larger touch targets for mobile */
    .port-out { right: -11px; }
    .port-in { left: -11px; }
}

@media (max-width: 480px) {
    h1.glitch { font-size: 1.8rem; }
    .controls { flex-direction: column; }
    #hud-header { align-items: flex-start; }
}
