/* General Reset & Variables */
:root {
    --bg-main: #070913;
    --bg-panel: rgba(15, 23, 42, 0.65);
    --border-color: rgba(99, 102, 241, 0.15);
    --border-hover: rgba(99, 102, 241, 0.35);
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --color-primary: #6366f1;
    --color-primary-glow: rgba(99, 102, 241, 0.4);
    --color-success: #10b981;
    --color-warning: #f59e0b;
    --color-danger: #ef4444;
    --font-sans: 'Outfit', sans-serif;
    --font-mono: 'JetBrains Mono', monospace;
    --shadow-glow: 0 8px 32px 0 rgba(0, 0, 0, 0.37);
    --card-glow: 0 0 15px rgba(99, 102, 241, 0.1);
}

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

body {
    background-color: var(--bg-main);
    background-image: 
        radial-gradient(at 0% 0%, rgba(99, 102, 241, 0.15) 0px, transparent 50%),
        radial-gradient(at 100% 100%, rgba(168, 85, 247, 0.15) 0px, transparent 50%);
    color: var(--text-main);
    font-family: var(--font-sans);
    min-height: 100vh;
    padding: 20px;
    display: flex;
    justify-content: center;
    overflow-x: hidden;
}

.app-container {
    width: 100%;
    max-width: 1100px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

/* Header */
header {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 10px 0;
}

.logo {
    display: flex;
    align-items: center;
    gap: 10px;
}

.logo h1 {
    font-size: 1.8rem;
    font-weight: 700;
    letter-spacing: -0.5px;
}

.logo h1 span {
    color: var(--color-primary);
    text-shadow: 0 0 10px var(--color-primary-glow);
}

.pulse-dot {
    width: 10px;
    height: 10px;
    background-color: var(--color-success);
    border-radius: 50%;
    box-shadow: 0 0 10px var(--color-success);
    animation: pulse 1.8s infinite;
}

@keyframes pulse {
    0% { transform: scale(0.9); opacity: 0.6; }
    50% { transform: scale(1.2); opacity: 1; box-shadow: 0 0 15px var(--color-success); }
    100% { transform: scale(0.9); opacity: 0.6; }
}

.subtitle {
    font-size: 0.9rem;
    color: var(--text-muted);
    font-weight: 300;
}

/* Layout Grid */
.main-content {
    display: grid;
    grid-template-columns: 1.25fr 1fr;
    gap: 20px;
}

@media (max-width: 950px) {
    .main-content {
        grid-template-columns: 1fr;
    }
}

/* Panels */
.panel {
    background: var(--bg-panel);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    padding: 16px;
    box-shadow: var(--shadow-glow), var(--card-glow);
    transition: border-color 0.3s ease, box-shadow 0.3s ease;
}

.panel:hover {
    border-color: var(--border-hover);
    box-shadow: var(--shadow-glow), 0 0 20px rgba(99, 102, 241, 0.15);
}

.panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    padding-bottom: 8px;
}

.panel-header h2 {
    font-size: 1.05rem;
    font-weight: 600;
    color: var(--text-main);
    letter-spacing: 0.2px;
}

.status-badge {
    background-color: rgba(99, 102, 241, 0.15);
    color: var(--color-primary);
    border: 1px solid var(--color-primary);
    padding: 2px 10px;
    font-size: 0.75rem;
    font-weight: 600;
    border-radius: 20px;
    letter-spacing: 0.5px;
}

/* Canvas Configurations */
.canvas-wrapper {
    width: 100%;
    display: flex;
    justify-content: center;
}

.canvas-container {
    background: #080d16;
    border-radius: 12px;
    overflow: hidden;
    position: relative;
    border: 1px solid rgba(255, 255, 255, 0.05);
    aspect-ratio: 55/40;
    width: 100%;
}

#gameCanvas {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: contain;
}

/* Touch Joysticks Controls Overlay */
.touch-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none; /* Let clicks pass through if not on joysticks */
    display: none; /* Enabled dynamically in script on touch devices */
    justify-content: space-between;
    align-items: flex-end;
    padding: 20px;
    box-sizing: border-box;
}

.joystick-zone {
    width: 110px;
    height: 110px;
    display: flex;
    justify-content: center;
    align-items: center;
    pointer-events: auto;
}

.v-joystick {
    width: 85px;
    height: 85px;
    background: rgba(255, 255, 255, 0.04);
    border: 1.5px solid rgba(255, 255, 255, 0.1);
    border-radius: 50%;
    position: relative;
    box-shadow: 0 0 15px rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(4px);
    touch-action: none;
}

.joystick-knob {
    width: 34px;
    height: 34px;
    background: var(--color-primary);
    box-shadow: 0 0 10px var(--color-primary);
    border-radius: 50%;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    pointer-events: none;
    transition: background-color 0.2s;
}

.action-zone {
    display: flex;
    align-items: flex-end;
    justify-content: center;
    padding-bottom: 10px;
    pointer-events: auto;
}

.touch-btn-jump {
    width: 60px;
    height: 60px;
    background: rgba(99, 102, 241, 0.18);
    border: 1.5px solid var(--color-primary);
    color: var(--text-main);
    box-shadow: 0 0 12px var(--color-primary-glow);
    font-family: var(--font-sans);
    font-weight: 700;
    font-size: 0.8rem;
    border-radius: 50%;
    cursor: pointer;
    touch-action: none;
    display: flex;
    align-items: center;
    justify-content: center;
}

.touch-btn-jump:active {
    background: var(--color-primary);
    box-shadow: 0 0 20px var(--color-primary);
}

/* Speed Controls */
.speed-controls {
    margin-top: 15px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.slider-container {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.slider-container .label {
    font-size: 0.85rem;
    color: var(--text-muted);
    font-weight: 500;
}

.slider-container .label span {
    color: var(--color-primary);
    font-weight: 600;
    font-family: var(--font-mono);
}

input[type="range"] {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 6px;
    border-radius: 3px;
    background: rgba(255, 255, 255, 0.1);
    outline: none;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--color-primary);
    cursor: pointer;
    box-shadow: 0 0 10px var(--color-primary);
    transition: transform 0.1s;
}

input[type="range"]::-webkit-slider-thumb:hover {
    transform: scale(1.2);
}

/* Buttons Group */
.btn-group {
    display: flex;
    gap: 10px;
}

.btn {
    flex: 1;
    padding: 10px;
    border: none;
    border-radius: 8px;
    font-family: var(--font-sans);
    font-weight: 600;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn.secondary {
    background-color: rgba(255, 255, 255, 0.08);
    color: var(--text-main);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.btn.secondary:hover {
    background-color: rgba(255, 255, 255, 0.15);
}

.btn.danger {
    background-color: rgba(239, 68, 68, 0.15);
    color: var(--color-danger);
    border: 1px solid rgba(239, 68, 68, 0.3);
}

.btn.danger:hover {
    background-color: rgba(239, 68, 68, 0.25);
}

/* Toggle Switch Styling */
.switch-container {
    position: relative;
    display: inline-block;
    width: 46px;
    height: 24px;
}

.switch-container input {
    opacity: 0;
    width: 0;
    height: 0;
}

.switch-slider {
    position: absolute;
    cursor: pointer;
    top: 0; left: 0; right: 0; bottom: 0;
    background-color: rgba(255, 255, 255, 0.1);
    transition: .3s;
    border-radius: 24px;
    border: 1px solid rgba(255, 255, 255, 0.06);
}

.switch-slider:before {
    position: absolute;
    content: "";
    height: 16px;
    width: 16px;
    left: 3px;
    bottom: 3px;
    background-color: var(--text-muted);
    transition: .3s;
    border-radius: 50%;
}

input:checked + .switch-slider {
    background-color: var(--color-primary);
    border-color: var(--color-primary);
}

input:checked + .switch-slider:before {
    transform: translateX(22px);
    background-color: #fff;
    box-shadow: 0 0 8px rgba(255, 255, 255, 0.6);
}

.toggle-control {
    display: flex;
    align-items: center;
    gap: 12px;
}

.toggle-label {
    font-size: 0.95rem;
    font-weight: 500;
    color: var(--text-main);
}

.mode-panel {
    display: flex;
    flex-direction: column;
}

.mode-control-grid {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.settings-control {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-top: 5px;
}

.label-with-val {
    display: flex;
    justify-content: space-between;
    font-size: 0.85rem;
    color: var(--text-muted);
    font-weight: 500;
}

.label-with-val span {
    color: var(--color-primary);
    font-weight: 600;
    font-family: var(--font-mono);
}

.mode-hint {
    font-size: 0.8rem;
    color: var(--text-muted);
    line-height: 1.4;
}

/* Sidebar & Stats */
.sidebar {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
}

.stat-card {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.04);
    border-radius: 12px;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.stat-label {
    font-size: 0.75rem;
    color: var(--text-muted);
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.stat-value {
    font-family: var(--font-mono);
    font-size: 1.4rem;
    font-weight: 700;
}

.stat-value.highlight {
    color: var(--color-primary);
    text-shadow: 0 0 10px rgba(99, 102, 241, 0.2);
}

.stat-value.gold {
    color: var(--color-warning);
    text-shadow: 0 0 10px rgba(245, 158, 11, 0.2);
}

/* Brain Panel */
.brain-container {
    background: #090d16;
    border-radius: 12px;
    padding: 10px;
    display: flex;
    flex-direction: column;
    align-items: center;
    border: 1px solid rgba(255, 255, 255, 0.03);
}

#brainCanvas {
    max-width: 100%;
    height: auto;
}

.network-legend {
    display: flex;
    gap: 15px;
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 8px;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 5px;
}

.line-pos {
    display: inline-block;
    width: 12px;
    height: 2px;
    background-color: var(--color-primary);
}

.line-neg {
    display: inline-block;
    width: 12px;
    height: 2px;
    background-color: var(--color-danger);
}

/* Guide Panel */
.guide-content {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.guide-item {
    font-size: 0.85rem;
    color: var(--text-main);
    display: flex;
    justify-content: space-between;
}

.guide-item span {
    color: var(--color-primary);
    font-weight: 600;
    font-family: var(--font-mono);
}

/* Footer */
footer {
    text-align: center;
    padding: 10px 0 20px 0;
    font-size: 0.8rem;
    color: var(--text-muted);
}

/* Touch Device adjustments */
body.touch-device .touch-overlay {
    display: flex;
}

@media (max-width: 600px) {
    body {
        padding: 10px;
    }
    .panel {
        padding: 12px;
    }
    .stats-grid {
        grid-template-columns: 1fr 1fr;
    }
    .logo h1 {
        font-size: 1.5rem;
    }
}
