:root {
    color-scheme: dark;
    --bg: #020812;
    --panel: rgba(8, 18, 33, 0.88);
    --panel-strong: rgba(7, 15, 28, 0.96);
    --border: rgba(123, 178, 255, 0.24);
    --cyan: #6ee7ff;
    --mint: #72efdd;
    --amber: #ffb703;
    --coral: #ff6b6b;
    --violet: #b388ff;
    --text: #ecf7ff;
    --muted: #91a4bf;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    min-height: 100vh;
    font-family: "Trebuchet MS", "Segoe UI", sans-serif;
    color: var(--text);
    background:
        radial-gradient(circle at top, rgba(110, 231, 255, 0.14), transparent 28%),
        radial-gradient(circle at bottom left, rgba(179, 136, 255, 0.16), transparent 30%),
        linear-gradient(180deg, #06101b 0%, #020812 100%);
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 24px;
}

.game-container {
    position: relative;
    width: min(100%, 1080px);
    border: 1px solid var(--border);
    border-radius: 28px;
    overflow: hidden;
    background: linear-gradient(180deg, rgba(6, 14, 26, 0.96), rgba(4, 9, 18, 0.98));
    box-shadow: 0 32px 80px rgba(0, 0, 0, 0.5), inset 0 1px 0 rgba(255, 255, 255, 0.06);
}

.screen {
    min-height: min(100dvh - 48px, 820px);
    display: flex;
    flex-direction: column;
    transition: opacity 0.35s ease, transform 0.35s ease;
}

.hidden {
    opacity: 0;
    pointer-events: none;
    position: absolute;
    inset: 0;
    transform: scale(0.985);
}

.hero-screen, .overlay-screen {
    justify-content: center;
    align-items: center;
    text-align: center;
    padding: 40px;
    background:
        linear-gradient(180deg, rgba(8, 18, 33, 0.75), rgba(2, 8, 18, 0.96)),
        radial-gradient(circle at top right, rgba(114, 239, 221, 0.12), transparent 28%);
}

.eyebrow {
    margin: 0;
    color: var(--cyan);
    letter-spacing: 0.24em;
    text-transform: uppercase;
    font-size: 0.78rem;
}

h1 {
    margin: 10px 0 14px;
    font-size: clamp(2.8rem, 5vw, 4.6rem);
    line-height: 0.95;
}

.hero-copy, .overlay-copy {
    max-width: 640px;
    color: var(--muted);
    font-size: 1rem;
    line-height: 1.6;
}

.logo {
    margin: 22px 0;
    font-size: 4rem;
    filter: drop-shadow(0 0 22px rgba(110, 231, 255, 0.45));
    animation: pulse 2.2s ease-in-out infinite;
}

.hero-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 12px;
    width: min(100%, 780px);
    margin: 28px 0;
}

.hero-card {
    padding: 16px;
    text-align: left;
    border: 1px solid rgba(123, 178, 255, 0.16);
    border-radius: 18px;
    background: rgba(11, 22, 38, 0.72);
}

.hero-card strong { display: block; margin-bottom: 6px; }
.hero-card span { color: var(--muted); font-size: 0.92rem; line-height: 1.45; }

.btn {
    border: 0;
    border-radius: 999px;
    padding: 15px 28px;
    font-size: 1rem;
    font-weight: 700;
    cursor: pointer;
    color: #03121a;
    background: linear-gradient(135deg, var(--cyan), var(--mint));
    box-shadow: 0 18px 40px rgba(110, 231, 255, 0.24);
    transition: transform 0.2s ease, box-shadow 0.2s ease, filter 0.2s ease;
}

.btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 22px 48px rgba(110, 231, 255, 0.3);
    filter: brightness(1.04);
}

.game-screen { padding: 18px; gap: 10px; }

.hud {
    display: grid;
    grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr);
    gap: 14px;
}

.stats-panel, .tower-panel {
    border-radius: 22px;
    border: 1px solid var(--border);
    background: var(--panel);
    backdrop-filter: blur(10px);
}

.stats-panel {
    padding: 16px 18px;
    display: grid;
    grid-template-columns: repeat(6, minmax(0, 1fr));
    gap: 12px;
    align-items: center;
}

.stat {
    padding: 10px 12px;
    border-radius: 16px;
    background: rgba(255, 255, 255, 0.03);
    min-height: 72px;
}

.label {
    display: block;
    color: var(--muted);
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.14em;
    margin-bottom: 8px;
}

.value { font-size: 1.08rem; font-weight: 700; }

.status-line { grid-column: 1 / -1; color: var(--muted); font-size: 0.95rem; }

.sector-brief {
    grid-column: 1 / -1;
    padding: 10px 14px;
    border-radius: 14px;
    border: 1px solid rgba(110, 231, 255, 0.16);
    background: rgba(110, 231, 255, 0.05);
    color: #c9f8ff;
    font-size: 0.84rem;
    letter-spacing: 0.04em;
}

.tower-panel { padding: 14px; }

.panel-heading {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    margin-bottom: 10px;
}

.panel-heading h2 { margin: 0; font-size: 1rem; }
.panel-heading span { color: var(--muted); font-size: 0.82rem; }

.tower-select {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 10px;
}

.tower-option {
    border: 1px solid rgba(123, 178, 255, 0.16);
    background:
        linear-gradient(180deg, rgba(255, 255, 255, 0.05), rgba(255, 255, 255, 0.02)),
        radial-gradient(circle at top, rgba(110, 231, 255, 0.12), transparent 52%);
    border-radius: 18px;
    padding: 12px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
    transition: border-color 0.2s ease, transform 0.2s ease, background 0.2s ease, opacity 0.2s ease, box-shadow 0.2s ease;
}

.tower-option:hover {
    transform: translateY(-2px);
    border-color: rgba(110, 231, 255, 0.48);
    box-shadow: 0 18px 28px rgba(0, 0, 0, 0.26);
}

.tower-option.selected {
    border-color: var(--cyan);
    background:
        linear-gradient(180deg, rgba(110, 231, 255, 0.14), rgba(255, 255, 255, 0.04)),
        radial-gradient(circle at top, rgba(110, 231, 255, 0.18), transparent 58%);
    box-shadow: inset 0 0 0 1px rgba(110, 231, 255, 0.18), 0 18px 30px rgba(0, 0, 0, 0.24);
}

.tower-option.disabled { opacity: 0.42; }

.tower-icon {
    position: relative;
    width: 76px;
    height: 76px;
    margin: 0 auto 10px;
    border-radius: 20px;
    border: 1px solid rgba(255, 255, 255, 0.08);
    background:
        radial-gradient(circle at 50% 35%, rgba(255, 255, 255, 0.1), transparent 42%),
        linear-gradient(180deg, rgba(6, 12, 23, 0.9), rgba(13, 27, 46, 0.92));
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08), inset 0 -10px 24px rgba(0, 0, 0, 0.3);
}

.tower-option::after {
    content: "";
    position: absolute;
    inset: 0;
    background: linear-gradient(120deg, transparent 22%, rgba(255, 255, 255, 0.12) 50%, transparent 78%);
    transform: translateX(-140%);
    transition: transform 0.45s ease;
}

.tower-option:hover::after, .tower-option.selected::after { transform: translateX(140%); }

.tower-core, .tower-arm, .tower-emitter, .tower-shell-ring,
.tower-barrel, .tower-fin, .tower-orbit, .tower-node,
.tower-coil, .tower-bolt { position: absolute; display: block; }

.tower-core {
    left: 50%; top: 50%;
    width: 20px; height: 20px;
    border-radius: 50%;
    transform: translate(-50%, -50%);
}

/* Arrow tower icon */
.tower-icon-arrow .tower-core {
    background: radial-gradient(circle, #fff8db 0%, #ffc94d 46%, #9a5a00 100%);
    box-shadow: 0 0 16px rgba(255, 183, 3, 0.45);
}
.tower-icon-arrow .tower-arm {
    width: 30px; height: 5px; left: 50%; top: 50%;
    margin-left: -15px; margin-top: -2px;
    border-radius: 999px;
    background: linear-gradient(90deg, rgba(255, 196, 76, 0.25), #ffd166, rgba(255, 196, 76, 0.25));
}
.tower-icon-arrow .arm-a { transform: rotate(28deg) translateY(-8px); }
.tower-icon-arrow .arm-b { transform: rotate(-28deg) translateY(8px); }
.tower-icon-arrow .tower-emitter {
    left: 50%; top: 50%;
    width: 40px; height: 40px;
    margin-left: -20px; margin-top: -20px;
    border-radius: 50%;
    border: 1px solid rgba(255, 209, 102, 0.3);
    animation: iconSpin 6s linear infinite;
}

/* Cannon tower icon */
.tower-icon-cannon .tower-core {
    width: 28px; height: 28px;
    background: radial-gradient(circle, #ffe9d8 0%, #fb5607 48%, #6d2200 100%);
    box-shadow: 0 0 18px rgba(251, 86, 7, 0.38);
}
.tower-icon-cannon .tower-shell-ring { inset: 14px; border-radius: 50%; border: 2px solid rgba(255, 162, 94, 0.34); }
.tower-icon-cannon .tower-barrel {
    left: 50%; top: 24px; width: 11px; height: 30px; margin-left: -5px;
    border-radius: 10px;
    background: linear-gradient(180deg, #ffd6b5, #fb5607 62%, #8b2f00 100%);
    box-shadow: 0 0 14px rgba(251, 86, 7, 0.26);
}
.tower-icon-cannon .tower-fin { width: 12px; height: 22px; top: 30px; border-radius: 10px; background: linear-gradient(180deg, rgba(255, 214, 181, 0.85), rgba(251, 86, 7, 0.15)); }
.tower-icon-cannon .fin-a { left: 16px; transform: rotate(-26deg); }
.tower-icon-cannon .fin-b { right: 16px; transform: rotate(26deg); }

/* Magic tower icon */
.tower-icon-magic .tower-core {
    width: 18px; height: 18px;
    background: radial-gradient(circle, #f7efff 0%, #b388ff 52%, #38136d 100%);
    box-shadow: 0 0 18px rgba(179, 136, 255, 0.44);
}
.tower-icon-magic .tower-orbit { inset: 13px; border-radius: 50%; border: 1px solid rgba(207, 178, 255, 0.4); }
.tower-icon-magic .orbit-a { animation: iconSpin 6s linear infinite; }
.tower-icon-magic .orbit-b { transform: rotate(60deg) scaleX(0.72); animation: iconSpinReverse 4.2s linear infinite; }
.tower-icon-magic .tower-node {
    width: 8px; height: 8px; border-radius: 50%;
    background: #e8d9ff; box-shadow: 0 0 12px rgba(179, 136, 255, 0.45);
}
.tower-icon-magic .node-a { left: 50%; top: 14px; margin-left: -4px; }
.tower-icon-magic .node-b { left: 18px; bottom: 18px; }
.tower-icon-magic .node-c { right: 18px; bottom: 18px; }

/* Tesla tower icon */
.tower-icon-tesla .tower-core {
    width: 18px; height: 18px;
    background: radial-gradient(circle, #e0fcff 0%, #00e5ff 52%, #004a55 100%);
    box-shadow: 0 0 18px rgba(0, 229, 255, 0.5);
}
.tower-icon-tesla .tower-coil { inset: 12px; border-radius: 50%; border: 2px solid rgba(0, 229, 255, 0.35); }
.tower-icon-tesla .coil-a { animation: iconSpin 4s linear infinite; }
.tower-icon-tesla .coil-b { inset: 18px; border: 1px solid rgba(178, 247, 255, 0.25); animation: iconSpinReverse 3s linear infinite; }
.tower-icon-tesla .tower-bolt {
    left: 50%; top: 50%; width: 3px; height: 28px;
    margin-left: -1.5px; margin-top: -14px;
    background: linear-gradient(180deg, transparent, #00e5ff 30%, #b2f7ff 50%, #00e5ff 70%, transparent);
    animation: teslaPulse 1.2s ease-in-out infinite;
}

.tower-name, .tower-cost { display: block; font-weight: 700; }
.tower-cost { color: var(--amber); margin-top: 4px; }
.tower-description { margin-top: 8px; color: var(--muted); font-size: 0.8rem; line-height: 1.45; }

@keyframes iconSpin { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }
@keyframes iconSpinReverse { from { transform: rotate(60deg) scaleX(0.72); } to { transform: rotate(-300deg) scaleX(0.72); } }
@keyframes teslaPulse { 0%, 100% { opacity: 0.3; } 50% { opacity: 1; } }
@keyframes pulse { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.08); } }

/* 3D Canvas shell */
.canvas-shell {
    border-radius: 24px;
    border: 1px solid var(--border);
    background: var(--panel-strong);
    overflow: hidden;
    position: relative;
    aspect-ratio: 960 / 528;
}

.canvas-shell canvas {
    width: 100% !important;
    height: 100% !important;
    display: block;
    border-radius: 18px;
}

/* Controls bar */
.controls-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 14px;
    border-radius: 16px;
    border: 1px solid var(--border);
    background: var(--panel);
}

.ctrl-btn {
    border: 1px solid rgba(123, 178, 255, 0.2);
    background: rgba(255, 255, 255, 0.05);
    color: var(--text);
    border-radius: 12px;
    padding: 8px 14px;
    font-size: 0.82rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s, border-color 0.2s, transform 0.15s;
}
.ctrl-btn:hover { background: rgba(110, 231, 255, 0.12); border-color: rgba(110, 231, 255, 0.4); transform: translateY(-1px); }
.ctrl-btn.active { background: rgba(110, 231, 255, 0.18); border-color: var(--cyan); }
.ctrl-sell { margin-left: auto; }
.ctrl-sell:not(:disabled):hover { background: rgba(255, 183, 3, 0.15); border-color: var(--amber); }
.ctrl-btn:disabled { opacity: 0.35; cursor: not-allowed; }
.shortcut-hint { color: var(--muted); font-size: 0.7rem; opacity: 0.7; margin-left: auto; }

/* Game over extras */
.overlay-screen { gap: 18px; }
.high-score-label { color: var(--amber); font-size: 1.1rem; font-weight: 700; }
.btn-secondary {
    background: linear-gradient(135deg, var(--amber), #fb5607);
    color: #1a0800;
    box-shadow: 0 18px 40px rgba(255, 183, 3, 0.2);
}
.btn-secondary:hover { box-shadow: 0 22px 48px rgba(255, 183, 3, 0.28); }

/* Responsive */
@media (max-width: 980px) {
    .hud { grid-template-columns: 1fr; }
    .stats-panel { grid-template-columns: repeat(3, minmax(0, 1fr)); }
    .hero-grid { grid-template-columns: 1fr; }
}

@media (max-width: 720px) {
    body { padding: 10px; align-items: flex-start; }
    .screen { min-height: auto; }
    .game-screen { padding: 10px; }
    .stats-panel { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .tower-select { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .controls-bar { flex-wrap: wrap; }
    .shortcut-hint { display: none; }
    h1 { font-size: 2.5rem; }
}
