/* GRID BREACH — Cyberpunk Page Chrome */

@import url('https://fonts.googleapis.com/css2?family=Share+Tech+Mono&family=Orbitron:wght@400;700;900&display=swap');

:root {
    --bg-dark: #0a0a0f;
    --bg-panel: #12121a;
    --cyan: #00f5ff;
    --magenta: #ff00ff;
    --yellow: #f0ff00;
    --red: #ff3366;
    --green: #00ff88;
    --dim-cyan: #004455;
    --grid-line: #001a22;
}

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

body {
    background: var(--bg-dark);
    color: var(--cyan);
    font-family: 'Share Tech Mono', monospace;
    overflow: hidden;
    height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Scanline overlay */
body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: repeating-linear-gradient(
        0deg,
        rgba(0,0,0,0.1) 0px,
        rgba(0,0,0,0.1) 1px,
        transparent 1px,
        transparent 3px
    );
    pointer-events: none;
    z-index: 9999;
}

/* CRT vignette */
body::after {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: radial-gradient(ellipse at center, transparent 60%, rgba(0,0,0,0.7) 100%);
    pointer-events: none;
    z-index: 9998;
}

#game-wrapper {
    display: flex;
    flex-direction: column;
    height: 100vh;
}

/* TOP BAR */
#top-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 20px;
    background: var(--bg-panel);
    border-bottom: 1px solid var(--dim-cyan);
    height: 50px;
    flex-shrink: 0;
}

.logo {
    font-family: 'Orbitron', sans-serif;
    font-size: 24px;
    font-weight: 900;
    letter-spacing: 3px;
}

.logo .accent {
    color: var(--magenta);
    text-shadow: 0 0 10px var(--magenta), 0 0 20px var(--magenta);
}

.back-link {
    color: var(--cyan);
    text-decoration: none;
    font-size: 24px;
    margin-right: 15px;
    text-shadow: 0 0 5px var(--cyan);
    transition: color 0.15s, text-shadow 0.15s;
}

.back-link:hover {
    color: var(--magenta);
    text-shadow: 0 0 10px var(--magenta), 0 0 20px var(--magenta);
}

.stats-bar {
    display: flex;
    align-items: center;
    gap: 18px;
}

.stat {
    font-size: 14px;
    color: var(--cyan);
    text-shadow: 0 0 5px var(--cyan);
}

.stat span {
    color: var(--yellow);
    text-shadow: 0 0 5px var(--yellow);
}

/* Power widget — supply / demand / battery bar / net rate.
   Each numeric span is in a monospace font with a fixed width so the
   top bar doesn't reflow as the values change. */
.power-widget {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-family: 'Share Tech Mono', monospace;
    font-size: 13px;
    color: var(--cyan);
    text-shadow: 0 0 5px var(--cyan);
    padding: 4px 10px;
    border: 1px solid var(--dim-cyan);
    background: rgba(0, 68, 85, 0.15);
}

.power-widget .pw-unit {
    color: var(--dim-cyan);
    text-shadow: none;
    font-size: 10px;
    margin-left: -2px;
}

.power-widget .lbl {
    color: var(--dim-cyan);
    text-shadow: none;
    font-size: 10px;
}

.power-widget .num {
    display: inline-block;
    font-family: 'Share Tech Mono', monospace;
    /* Fixed width: 3 digits for power, 5 for the net rate sign+magnitude. */
    width: 3.5ch;
    text-align: right;
    color: var(--yellow);
    text-shadow: 0 0 5px var(--yellow);
}

.power-widget .pw-supply .num {
    color: var(--cyan);
    text-shadow: 0 0 5px var(--cyan);
}

.power-widget .pw-demand .num {
    color: #ff8800;
    text-shadow: 0 0 5px #ff8800;
}

.power-widget .pw-sep {
    color: var(--dim-cyan);
    text-shadow: none;
}

.power-widget .pw-battery {
    position: relative;
    width: 90px;
    height: 14px;
    background: rgba(0, 0, 0, 0.6);
    border: 1px solid var(--dim-cyan);
    margin: 0 6px;
    overflow: hidden;
}

.power-widget .pw-battery-fill {
    position: absolute;
    inset: 0;
    width: 0%;
    background: linear-gradient(90deg, #00ff88, #f0ff00);
    box-shadow: 0 0 8px #00ff88;
    transition: width 0.2s linear;
}

.power-widget .pw-battery-text {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #0a0a0f;
    font-size: 10px;
    font-weight: bold;
    text-shadow: none;
    font-family: 'Share Tech Mono', monospace;
    letter-spacing: 0.5px;
}

.power-widget .pw-net {
    width: 6ch;
    text-align: right;
}

.power-widget .pw-net.positive {
    color: var(--green);
    text-shadow: 0 0 5px var(--green);
}

.power-widget .pw-net.negative {
    color: var(--red);
    text-shadow: 0 0 5px var(--red);
}

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

button {
    background: transparent;
    border: 1px solid var(--cyan);
    color: var(--cyan);
    font-family: 'Share Tech Mono', monospace;
    font-size: 12px;
    padding: 5px 15px;
    cursor: pointer;
    text-transform: uppercase;
    letter-spacing: 2px;
    transition: all 0.2s;
}

button:hover {
    background: var(--cyan);
    color: var(--bg-dark);
    box-shadow: 0 0 10px var(--cyan);
}

button:active {
    transform: scale(0.95);
}

/* GAME AREA */
#game-area {
    flex: 1;
    position: relative;
    overflow: hidden;
}

#game-canvas {
    display: block;
    width: 100%;
    height: 100%;
    background: var(--bg-dark);
}

/* HUD OVERLAY */
#hud-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    pointer-events: none;
    display: flex;
    justify-content: space-between;
    padding: 20px;
}

.panel {
    background: rgba(18, 18, 26, 0.9);
    border: 1px solid var(--dim-cyan);
    padding: 15px;
    pointer-events: auto;
    min-width: 200px;
}

.panel h3 {
    font-family: 'Orbitron', sans-serif;
    font-size: 12px;
    color: var(--magenta);
    text-shadow: 0 0 5px var(--magenta);
    margin-bottom: 10px;
    letter-spacing: 2px;
    border-bottom: 1px solid var(--dim-cyan);
    padding-bottom: 5px;
}

.hidden {
    display: none !important;
}

/* Build panel items */
.build-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px;
    margin-bottom: 5px;
    border: 1px solid transparent;
    cursor: pointer;
    transition: all 0.2s;
}

.build-item:hover {
    border-color: var(--cyan);
    background: rgba(0, 245, 255, 0.1);
}

.build-item .icon {
    width: 30px;
    height: 30px;
    border: 1px solid var(--cyan);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
}

.build-item .info {
    flex: 1;
}

.build-item .name {
    font-size: 12px;
    color: var(--cyan);
}

.build-item .cost {
    font-size: 10px;
    color: var(--yellow);
}

.build-item.selected {
    border-color: var(--magenta);
    box-shadow: 0 0 10px var(--magenta);
}

/* Power panel */
.power-panel-section {
    margin-bottom: 12px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--dim-cyan);
}

.power-panel-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 11px;
    margin-bottom: 4px;
}

.pp-label {
    font-size: 10px;
    letter-spacing: 1px;
}

.pp-value {
    color: var(--yellow);
    text-shadow: 0 0 5px var(--yellow);
    font-family: 'Share Tech Mono', monospace;
    /* Fixed width for value column to keep the panel tidy. */
    min-width: 90px;
    text-align: right;
}

.env-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 6px;
    font-size: 10px;
    color: var(--dim-cyan);
}

.env-icon {
    width: 18px;
    text-align: center;
    font-size: 14px;
    line-height: 1;
}

.env-track {
    flex: 1;
    height: 8px;
    background: rgba(0, 0, 0, 0.5);
    border: 1px solid var(--dim-cyan);
    position: relative;
    overflow: hidden;
}

.env-fill {
    height: 100%;
    transition: width 0.3s linear;
}

.env-fill-solar {
    background: linear-gradient(90deg, #001a22, #f0ff00, #ff8800, #001a22);
    box-shadow: 0 0 5px #f0ff00;
}

.env-fill-wind {
    background: linear-gradient(90deg, #00f5ff, #00ff88);
    box-shadow: 0 0 5px #00ff88;
}

.power-source-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 5px;
    margin-bottom: 3px;
    font-size: 11px;
    border-left: 3px solid var(--cyan);
}

.power-source-item.unstable {
    border-left-color: var(--yellow);
}

.power-source-item.offline {
    border-left-color: var(--red);
    opacity: 0.5;
}

/* Turret info panel */
#turret-info .turret-header {
    font-size: 14px;
    color: var(--yellow);
    margin-bottom: 10px;
}

#turret-info .stat-row {
    display: flex;
    justify-content: space-between;
    font-size: 11px;
    margin-bottom: 5px;
}

#turret-info .stat-label {
    color: var(--dim-cyan);
}

#turret-info .stat-value {
    color: var(--cyan);
}

.upgrade-btn {
    width: 100%;
    margin-top: 10px;
    font-size: 11px;
}

/* BOTTOM BAR */
#bottom-bar {
    height: 40px;
    background: var(--bg-panel);
    border-top: 1px solid var(--dim-cyan);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    flex-shrink: 0;
}

.mini-game-area {
    flex: 1;
}

.hotkeys {
    display: flex;
    gap: 20px;
    font-size: 10px;
    color: var(--dim-cyan);
}

.hotkeys span {
    padding: 2px 5px;
    border: 1px solid var(--dim-cyan);
}

/* OVERLAYS */
.overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(10, 10, 15, 0.95);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
}

.menu-box {
    text-align: center;
    padding: 50px;
    border: 2px solid var(--magenta);
    box-shadow: 0 0 30px var(--magenta), inset 0 0 30px rgba(255,0,255,0.1);
    background: var(--bg-panel);
}

.menu-box h2 {
    font-family: 'Orbitron', sans-serif;
    font-size: 48px;
    color: var(--cyan);
    text-shadow: 0 0 20px var(--cyan);
    margin-bottom: 20px;
    letter-spacing: 5px;
}

.menu-box p {
    font-size: 14px;
    color: var(--dim-cyan);
    margin-bottom: 30px;
}

.menu-box button {
    display: block;
    width: 200px;
    margin: 10px auto;
    padding: 15px;
    font-size: 14px;
}

/* Wave Banner */
#wave-banner {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-family: 'Orbitron', sans-serif;
    font-size: 60px;
    color: var(--magenta);
    text-shadow: 0 0 30px var(--magenta), 0 0 60px var(--magenta);
    z-index: 50;
    letter-spacing: 10px;
    animation: wave-pulse 2s ease-in-out;
}

#wave-banner span:last-child {
    font-size: 100px;
    display: block;
}

@keyframes wave-pulse {
    0% { transform: translate(-50%, -50%) scale(0.5); opacity: 0; }
    50% { transform: translate(-50%, -50%) scale(1.1); opacity: 1; }
    100% { transform: translate(-50%, -50%) scale(1); opacity: 0; }
}

/* Animations */
@keyframes blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.3; }
}

@keyframes glow-pulse {
    0%, 100% { box-shadow: 0 0 5px var(--cyan); }
    50% { box-shadow: 0 0 20px var(--cyan), 0 0 30px var(--cyan); }
}

/* Low power turret flicker */
.low-power {
    animation: flicker 0.5s infinite;
}

@keyframes flicker {
    0%, 100% { opacity: 1; }
    25% { opacity: 0.4; }
    50% { opacity: 0.8; }
    75% { opacity: 0.3; }
}

/* Power grid pulse */
.power-pulse {
    animation: power-pulse 1s infinite;
}

@keyframes power-pulse {
    0%, 100% { filter: brightness(1); }
    50% { filter: brightness(1.3); }
}

/* Loading bar */
.loading-bar {
    width: 100%;
    height: 4px;
    background: var(--bg-dark);
    border: 1px solid var(--dim-cyan);
    margin-top: 5px;
}

.loading-bar .fill {
    height: 100%;
    background: var(--cyan);
    transition: width 0.3s;
    box-shadow: 0 0 10px var(--cyan);
}

/* Right-click build menu on canvas */
.build-menu {
    position: fixed;
    z-index: 200;
    background: rgba(18, 18, 26, 0.95);
    border: 1px solid var(--magenta);
    box-shadow: 0 0 15px var(--magenta);
    padding: 5px;
    min-width: 200px;
    font-family: 'Share Tech Mono', monospace;
    font-size: 12px;
    color: var(--cyan);
    max-height: 70vh;
    overflow-y: auto;
}

.build-menu .bm-title {
    color: var(--magenta);
    font-size: 10px;
    letter-spacing: 2px;
    padding: 4px 6px;
    border-bottom: 1px solid var(--dim-cyan);
    margin-bottom: 4px;
}

.build-menu .bm-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 8px;
    cursor: pointer;
    border: 1px solid transparent;
    transition: all 0.15s;
}

.build-menu .bm-item:hover {
    border-color: var(--cyan);
    background: rgba(0, 245, 255, 0.1);
}

.build-menu .bm-item.disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.build-menu .bm-item .bm-name {
    color: var(--cyan);
}

.build-menu .bm-item .bm-cost {
    color: var(--yellow);
    text-shadow: 0 0 5px var(--yellow);
    font-size: 10px;
}

.build-menu .bm-item .bm-key {
    color: var(--magenta);
    font-size: 10px;
    margin-left: 8px;
    border: 1px solid var(--dim-cyan);
    padding: 0 4px;
}