:root {
    --phosphor-green: #33ff33;
    --phosphor-dim: #1a801a;
    --f1-color: #00eeff; /* Western Alliance */
    --f2-color: #ff3333; /* Eastern Coalition */
    --f3-color: #ffcc00; /* Asian Pact */
    --f4-color: #cc66ff; /* Southern Accord */
    --neutral-color: #aaaaaa;
    --bg-color: #050505;
}

body, html {
    margin: 0; padding: 0; width: 100%; height: 100%;
    background-color: var(--bg-color); color: var(--phosphor-green);
    font-family: 'VT323', monospace; overflow: hidden; user-select: none;
}

body::after {
    content: " "; display: block; position: absolute; top: 0; left: 0; bottom: 0; right: 0;
    background: linear-gradient(rgba(18, 16, 16, 0) 50%, rgba(0, 0, 0, 0.25) 50%), linear-gradient(90deg, rgba(255, 0, 0, 0.06), rgba(0, 255, 0, 0.02), rgba(0, 0, 255, 0.06));
    z-index: 1000; background-size: 100% 3px, 3px 100%; pointer-events: none; opacity: 0.6;
}

#screen-glow { position: absolute; top: 0; left: 0; width: 100%; height: 100%; box-shadow: inset 0 0 100px rgba(0,255,0,0.1); pointer-events: none; z-index: 999; }
#webgl-container { position: absolute; top: 0; left: 0; width: 100%; height: 100%; z-index: 1; }
#ui-layer { position: absolute; top: 0; left: 0; width: 100%; height: 100%; z-index: 10; pointer-events: none; }
#layout-shell {
    position: absolute;
    inset: 0;
    padding-top: calc(42px + env(safe-area-inset-top, 0px));
    display: grid;
    grid-template-columns: 310px minmax(0, 1fr) 310px;
    grid-template-rows: auto 1fr clamp(200px, 29vh, 250px);
    grid-template-areas:
        "top top top"
        "left . right"
        "left bottom right";
    gap: 12px;
    box-sizing: border-box;
    min-height: 0;
}
#top-area { grid-area: top; min-width: 0; padding: 0 12px; }
#left-sidebar {
    grid-area: left;
    min-height: 0;
    overflow: hidden;
    display: flex;
    padding: 15px 10px 15px 15px;
    background: rgba(0, 15, 0, 0.8);
    border: 2px solid var(--phosphor-dim);
    box-shadow: 0 0 10px var(--phosphor-dim);
    pointer-events: auto;
}

.panel { background: rgba(0, 15, 0, 0.8); border: 2px solid var(--phosphor-dim); padding: 15px; box-shadow: 0 0 10px var(--phosphor-dim); pointer-events: auto; }

#header { text-align: center; border-top: none; border-left: none; border-right: none; font-size: 28px; letter-spacing: 4px; text-shadow: 0 0 8px var(--phosphor-green); text-transform: uppercase; }

#stats-container { display: flex; flex: 1; flex-direction: column; align-items: stretch; width: 100%; height: 100%; gap: 12px; pointer-events: none; overflow-y: auto; padding-right: 4px; box-sizing: border-box; }
.sidebar { font-size: 18px; flex: 0 0 auto; max-width: none; text-align: center; pointer-events: auto; }

#p1-stats { border-color: var(--f1-color); color: var(--f1-color); text-shadow: 0 0 5px var(--f1-color); }
#p2-stats { border-color: var(--f2-color); color: var(--f2-color); text-shadow: 0 0 5px var(--f2-color); }
#p3-stats { border-color: var(--f3-color); color: var(--f3-color); text-shadow: 0 0 5px var(--f3-color); }
#p4-stats { border-color: var(--f4-color); color: var(--f4-color); text-shadow: 0 0 5px var(--f4-color); }

.stat-value { font-size: 26px; display: block; margin-top: 5px; }

#bottom-area { grid-area: bottom; display: flex; min-width: 0; min-height: 0; border-bottom: none; border-left: none; border-right: none; }
#console-log { flex-grow: 1; min-height: 0; overflow-y: auto; padding-right: 10px; font-size: 18px; line-height: 1.2; display: flex; flex-direction: column-reverse; }
#right-sidebar { grid-area: right; min-height: 0; overflow: hidden; }

.log-msg { margin-bottom: 5px; opacity: 0.9; }
.log-msg.f1 { color: var(--f1-color); }
.log-msg.f2 { color: var(--f2-color); }
.log-msg.f3 { color: var(--f3-color); }
.log-msg.f4 { color: var(--f4-color); }
.log-msg.system { color: var(--phosphor-green); }
.log-msg.error { color: #ffaa00; }

#controls { width: 100%; height: 100%; min-height: 0; padding-right: 8px; display: flex; flex-direction: column; justify-content: flex-start; align-items: stretch; text-align: center; gap: 8px; overflow-y: auto; overflow-x: hidden; scrollbar-width: thin; box-sizing: border-box; }
#turn-indicator { font-size: 24px; margin-bottom: 10px; }
#phase-indicator { font-size: 20px; margin-bottom: 8px; }
#round-timer { font-size: 18px; letter-spacing: 2px; color: #ffaa00; margin-bottom: 8px; }
#round-timer-value { font-size: 22px; font-weight: bold; }
#round-timer.urgent { color: #ff3333; animation: blink 0.8s infinite; }
#end-turn-btn { margin-top: auto; position: sticky; bottom: 0; background: rgba(5, 5, 5, 0.95); }

button { background: transparent; color: var(--phosphor-green); border: 2px solid var(--phosphor-green); font-family: 'VT323', monospace; font-size: 22px; padding: 10px 20px; cursor: pointer; text-transform: uppercase; box-shadow: 0 0 5px var(--phosphor-dim); transition: all 0.2s; }
button:hover { background: var(--phosphor-green); color: #000; box-shadow: 0 0 15px var(--phosphor-green); }
button:disabled { border-color: #555; color: #555; box-shadow: none; cursor: not-allowed; }
.status-block { display:none; margin-bottom: 6px; font-size: 18px; }
.control-panel { display:none; width: 100%; border-top: 1px solid var(--phosphor-dim); padding-top: 8px; }
.control-panel-title { font-size: 18px; margin-bottom: 6px; letter-spacing: 1px; }
.shop-grid, .missile-grid { display: grid; grid-template-columns: 1fr; gap: 6px; width: 100%; }
.shop-btn, .missile-btn { width: 100%; font-size: 18px; padding: 6px 8px; }
.missile-btn.active, .shop-btn.active { background: var(--phosphor-green); color: #000; box-shadow: 0 0 15px var(--phosphor-green); }
#city-detail { min-height: 54px; font-size: 16px; line-height: 1.05; border-top: 1px solid var(--phosphor-dim); border-bottom: 1px solid var(--phosphor-dim); padding: 8px 0; }
#buy-target { font-size: 16px; margin-bottom: 6px; }

/* --- Instructions Modal --- */
#instructions-overlay {
    position: absolute;
    inset: 0;
    display: none;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.82);
    z-index: 2100;
    pointer-events: auto;
    padding: 20px;
    box-sizing: border-box;
}
#instructions-overlay.visible { display: flex; }
#instructions-modal {
    width: min(780px, calc(100vw - 40px));
    max-height: calc(100vh - 290px);
    overflow-y: auto;
    border-color: var(--phosphor-green);
    box-shadow: 0 0 30px rgba(51, 255, 51, 0.22);
    scrollbar-width: thin;
}
#instructions-header {
    font-size: 32px;
    letter-spacing: 3px;
    text-align: center;
    margin-bottom: 16px;
    text-shadow: 0 0 10px var(--phosphor-green);
}
#instructions-body {
    font-size: 18px;
    line-height: 1.25;
}
.instructions-section {
    margin-bottom: 16px;
    border-bottom: 1px solid rgba(51, 255, 51, 0.2);
    padding-bottom: 12px;
}
.instructions-section:last-child { border-bottom: none; }
.instructions-title {
    font-size: 22px;
    letter-spacing: 2px;
    margin-bottom: 6px;
    text-shadow: 0 0 6px var(--phosphor-green);
}
.instructions-section p {
    margin: 4px 0;
    color: #aaffaa;
}
.instructions-section strong {
    color: var(--phosphor-green);
}

/* --- Resource Display --- */
#resource-display { display: flex; gap: 10px; margin-top: 6px; font-size: 16px; flex-wrap: wrap; }
.resource-icon { display: inline-flex; align-items: center; gap: 2px; }
.resource-icon.fuel { color: #ff8800; }
.resource-icon.steel { color: #aabbcc; }
.resource-icon.electronics { color: #44ccff; }
.resource-icon.uranium { color: #44ff44; }

/* --- Diplomacy Panel --- */
#diplomacy-panel { display: none; }
.diplomacy-grid { display: grid; grid-template-columns: 1fr; gap: 6px; width: 100%; }
.diplomacy-btn { width: 100%; font-size: 18px; padding: 6px 8px; }

/* --- Loyalty Bar --- */
.loyalty-bar { width: 100%; height: 4px; background: #222; margin-top: 2px; display: flex; overflow: hidden; }
.loyalty-bar-segment { height: 100%; }

/* --- Fog of War --- */
.fog-unknown { color: #555 !important; font-style: italic; }

/* --- Chemical Contamination --- */
.contaminated-label { color: #88ff00 !important; }

/* --- Satellite Indicator --- */
.satellite-indicator { display: inline-block; width: 6px; height: 6px; border-radius: 50%; background: #44ccff; margin-left: 4px; box-shadow: 0 0 4px #44ccff; vertical-align: middle; }

.city-label { position: absolute; color: white; font-size: 15px; pointer-events: none; transform: translate(-50%, -100%); margin-top: -10px; text-shadow: 1px 1px 0 #000, -1px -1px 0 #000, 1px -1px 0 #000, -1px 1px 0 #000; opacity: 0; transition: opacity 0.2s; z-index: 5; }
.city-label.visible { opacity: 1; }
.city-label .icbm-count { display: block; text-align: center; font-size: 18px; font-weight: bold; }
#city-modal-overlay {
    position: absolute;
    inset: 0;
    display: none;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.55);
    z-index: 120;
    pointer-events: auto;
}
#city-modal-overlay.visible { display: flex; }
#city-modal {
    width: min(420px, calc(100vw - 40px));
    border-color: var(--phosphor-green);
    text-align: left;
    box-shadow: 0 0 24px rgba(51, 255, 51, 0.2);
}
#city-modal-header { font-size: 30px; margin-bottom: 8px; text-align: center; }
#city-modal-owner { font-size: 20px; margin-bottom: 12px; text-align: center; }
#city-modal-body { font-size: 20px; line-height: 1.15; min-height: 108px; }
#city-modal-actions { display: flex; gap: 10px; margin-top: 14px; }
#city-modal-actions button { flex: 1; }
#game-over-screen {
    position: absolute;
    inset: 0;
    display: none;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.82);
    z-index: 180;
    pointer-events: auto;
    padding: 20px;
    box-sizing: border-box;
}
#game-over-screen.visible { display: flex; }
#game-over-panel {
    width: min(560px, calc(100vw - 40px));
    text-align: center;
    border-color: var(--phosphor-green);
    box-shadow: 0 0 30px rgba(51, 255, 51, 0.22);
}
#game-over-title {
    font-size: 42px;
    letter-spacing: 3px;
    margin-bottom: 8px;
    text-shadow: 0 0 10px var(--phosphor-green);
}
#game-over-subtitle {
    font-size: 24px;
    margin-bottom: 14px;
}
#game-over-summary {
    font-size: 20px;
    line-height: 1.2;
    margin-bottom: 18px;
    text-align: left;
}
.game-over-line {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    border-top: 1px solid rgba(51, 255, 51, 0.25);
    padding-top: 8px;
    margin-top: 8px;
}

/* --- Lobby & Multiplayer --- */
.start-mode-picker { display: flex; gap: 12px; flex-wrap: wrap; justify-content: center; }
#lobby-container { display: flex; flex-direction: column; align-items: center; width: 100%; max-width: 600px; padding: 20px; }
.lobby-title { font-size: 32px; letter-spacing: 3px; margin-bottom: 24px; text-shadow: 0 0 8px var(--phosphor-green); }
.lobby-section { display: flex; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; justify-content: center; }
.lobby-btn { width: 300px; }
.lobby-label { font-size: 20px; letter-spacing: 1px; margin-bottom: 8px; }
.lobby-input {
    background: rgba(0, 15, 0, 0.9);
    border: 2px solid var(--phosphor-green);
    color: var(--phosphor-green);
    font-family: 'VT323', monospace;
    font-size: 28px;
    padding: 10px 16px;
    text-align: center;
    letter-spacing: 4px;
    width: 240px;
    margin-bottom: 12px;
    text-transform: uppercase;
}
.lobby-input:focus { outline: none; box-shadow: 0 0 15px var(--phosphor-green); }
.lobby-code { font-size: 42px; letter-spacing: 6px; color: var(--phosphor-green); text-shadow: 0 0 12px var(--phosphor-green); margin-bottom: 8px; }
.lobby-player {
    font-size: 20px; padding: 8px 0; letter-spacing: 1px;
    border-bottom: 1px solid rgba(51, 255, 51, 0.1);
    transition: background 0.2s;
}
.lobby-player[data-player-uid]:hover {
    background: rgba(51, 255, 51, 0.05);
}
.lobby-player-name { font-size: 20px; letter-spacing: 2px; }
.lobby-player-detail {
    display: flex; gap: 12px; align-items: center; flex-wrap: wrap;
    font-size: 16px; margin-top: 2px;
}
.lobby-player-commander { opacity: 0.8; }
.lobby-player-status { font-size: 14px; letter-spacing: 2px; }
.lobby-player-elo {
    font-size: 14px; letter-spacing: 2px; opacity: 0.7;
    padding: 1px 6px;
    border: 1px solid rgba(51, 255, 51, 0.15);
}
.lobby-player-empty { color: #555; }
.lobby-player-offline { animation: blink 1.5s infinite; }
.lobby-wait-msg { font-size: 20px; margin-top: 16px; animation: blink 1s infinite; }
.lobby-error { color: #ffaa00; font-size: 20px; min-height: 28px; margin-top: 8px; }

/* --- Waiting overlay pulse --- */
#phase-indicator.waiting-pulse { animation: blink 1.5s infinite; }

.blink { animation: blink 1s infinite; }
.menu-btn { background: transparent; color: var(--phosphor-green); border: 2px solid var(--phosphor-green); font-family: 'VT323', monospace; font-size: 28px; padding: 15px 30px; margin: 10px; cursor: pointer; text-transform: uppercase; box-shadow: 0 0 10px var(--phosphor-dim); transition: all 0.2s; width: 350px; }
.menu-btn:hover { background: var(--phosphor-green); color: #000; box-shadow: 0 0 25px var(--phosphor-green); }
.start-subtitle { margin-bottom: 16px; letter-spacing: 2px; }
.faction-picker { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin: 0; }
.faction-btn { width: 100%; margin: 0; font-size: 22px; letter-spacing: 1px; transition: all 0.25s ease; }
.faction-btn.f1 { border-left: 4px solid var(--f1-color); color: var(--f1-color); }
.faction-btn.f2 { border-left: 4px solid var(--f2-color); color: var(--f2-color); }
.faction-btn.f3 { border-left: 4px solid var(--f3-color); color: var(--f3-color); }
.faction-btn.f4 { border-left: 4px solid var(--f4-color); color: var(--f4-color); }
.faction-btn.selected { box-shadow: 0 0 20px currentColor; }
.faction-btn.f1.selected { background: rgba(0, 238, 255, 0.15); border-color: var(--f1-color); color: var(--f1-color); text-shadow: 0 0 8px var(--f1-color); }
.faction-btn.f2.selected { background: rgba(255, 51, 51, 0.15); border-color: var(--f2-color); color: var(--f2-color); text-shadow: 0 0 8px var(--f2-color); }
.faction-btn.f3.selected { background: rgba(255, 204, 0, 0.15); border-color: var(--f3-color); color: var(--f3-color); text-shadow: 0 0 8px var(--f3-color); }
.faction-btn.f4.selected { background: rgba(204, 102, 255, 0.15); border-color: var(--f4-color); color: var(--f4-color); text-shadow: 0 0 8px var(--f4-color); }
.faction-btn:hover { background: rgba(51, 255, 51, 0.08); }
.visual-style-picker { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin: 0; }
.visual-style-btn { width: 100%; margin: 0; font-size: 22px; letter-spacing: 1px; transition: all 0.25s ease; }
.visual-style-btn.selected { box-shadow: 0 0 20px currentColor; }
.visual-style-btn[data-visual-style="1980s"].selected { background: rgba(125, 255, 125, 0.15); border-color: #7dff7d; color: #7dff7d; text-shadow: 0 0 8px rgba(125, 255, 125, 0.4); }
.visual-style-btn[data-visual-style="2026"].selected { background: rgba(111, 214, 255, 0.15); border-color: #6fd6ff; color: #6fd6ff; text-shadow: 0 0 8px rgba(111, 214, 255, 0.4); }
.visual-style-caption { width: 100%; margin: 10px 0 0; color: #93e8a2; font-size: 20px; line-height: 1.1; letter-spacing: 1px; }
#boot-screen {
    position: absolute;
    inset: 0;
    z-index: 2200;
    display: flex;
    align-items: center;
    justify-content: center;
    background:
        radial-gradient(circle at top, rgba(15, 60, 18, 0.24), rgba(0, 0, 0, 0.96) 58%),
        #000;
    opacity: 1;
    visibility: visible;
    transition: opacity 0.36s ease, visibility 0.36s ease;
}
#boot-screen.hidden {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}
#boot-screen::after {
    content: "";
    position: absolute;
    inset: 0;
    background: rgba(120, 255, 120, 0);
    opacity: 0;
    pointer-events: none;
}
#boot-screen.boot-complete::after {
    animation: boot-flash 0.42s ease-out forwards;
}
#boot-shell {
    position: relative;
    width: min(960px, calc(100vw - 40px));
    height: min(620px, calc(100vh - 40px));
    display: flex;
    flex-direction: column;
    gap: 14px;
    padding: 18px 20px;
    box-sizing: border-box;
    background: rgba(0, 16, 0, 0.92);
    border: 2px solid var(--phosphor-dim);
    box-shadow:
        0 0 40px rgba(51, 255, 51, 0.12),
        inset 0 0 60px rgba(20, 60, 20, 0.18);
    overflow: hidden;
}
#boot-shell::before {
    content: "";
    position: absolute;
    inset: 0;
    background: radial-gradient(circle at 50% 0%, rgba(80, 255, 110, 0.08), transparent 42%);
    pointer-events: none;
}
#boot-header {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    font-size: 24px;
    letter-spacing: 3px;
    text-transform: uppercase;
}
#boot-subtitle {
    color: #97e89f;
    font-size: 18px;
    letter-spacing: 1px;
    text-transform: uppercase;
}
#boot-terminal {
    position: relative;
    flex: 1;
    overflow-y: auto;
    border: 1px solid rgba(51, 255, 51, 0.25);
    background: rgba(0, 7, 0, 0.88);
    padding: 16px;
    box-sizing: border-box;
    box-shadow: inset 0 0 28px rgba(18, 70, 18, 0.22);
    font-size: 20px;
    line-height: 1.05;
}
#boot-terminal::-webkit-scrollbar {
    display: none;
}
#boot-terminal-content {
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-height: 100%;
    justify-content: flex-end;
}
.boot-line {
    white-space: pre-wrap;
    word-break: break-word;
    color: #8fe68d;
    opacity: 0.92;
    animation: boot-line-enter 0.16s ease-out;
}
.boot-line.dim {
    color: #6bac68;
    opacity: 0.76;
}
.boot-line.live {
    color: #aef7a8;
    text-shadow: 0 0 6px rgba(140, 255, 140, 0.2);
}
.boot-line.ok {
    color: #c8ffbe;
}
#boot-action-row {
    display: flex;
    justify-content: center;
    min-height: 66px;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.22s ease;
}
#boot-action-row.visible {
    opacity: 1;
    pointer-events: auto;
}
#boot-access-btn {
    width: min(360px, 100%);
    margin: 0;
    font-size: 26px;
    letter-spacing: 3px;
    box-shadow: 0 0 18px rgba(51, 255, 51, 0.14);
}
#boot-access-btn:disabled {
    border-color: rgba(120, 255, 120, 0.35);
    color: rgba(180, 255, 180, 0.45);
}
#boot-footer {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    font-size: 18px;
    letter-spacing: 1px;
    color: #84d48b;
    text-transform: uppercase;
}
#boot-cursor { animation: blink 1s step-end infinite; }
#start-screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 2000;
    background:
        radial-gradient(circle at top, rgba(18, 62, 18, 0.18), rgba(0, 0, 0, 0.96) 52%),
        #000;
    color: var(--phosphor-green);
    display: none;
    flex-direction: column;
    justify-content: flex-start;
    align-items: center;
    font-size: 24px;
    text-align: center;
    opacity: 0;
    transition: opacity 0.28s ease;
    overflow-y: auto;
    padding: 32px 20px 40px;
    box-sizing: border-box;
}
#start-screen.visible { opacity: 1; }

.start-shell {
    width: min(980px, 100%);
    margin: auto;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 18px;
}

.start-hero {
    padding: 28px 30px 22px;
    border: 1px solid rgba(51, 255, 51, 0.35);
    background:
        linear-gradient(180deg, rgba(11, 30, 11, 0.96), rgba(2, 10, 2, 0.92) 70%),
        rgba(0, 0, 0, 0.92);
    box-shadow:
        0 0 40px rgba(51, 255, 51, 0.1),
        inset 0 0 50px rgba(20, 60, 20, 0.2);
    text-align: left;
    position: relative;
    overflow: hidden;
}
.start-hero::before {
    content: "";
    position: absolute;
    top: -1px;
    left: 0;
    right: 0;
    height: 3px;
    background: linear-gradient(90deg, transparent, var(--phosphor-green) 20%, var(--phosphor-green) 80%, transparent);
    opacity: 0.6;
}
.start-hero::after {
    content: "";
    position: absolute;
    inset: 0;
    background: repeating-linear-gradient(0deg, transparent, transparent 2px, rgba(0, 0, 0, 0.06) 2px, rgba(0, 0, 0, 0.06) 4px);
    pointer-events: none;
}

.start-kicker {
    font-size: 16px;
    letter-spacing: 4px;
    color: #6bac68;
    margin-bottom: 12px;
}

.start-title {
    font-size: clamp(52px, 8vw, 80px);
    letter-spacing: 10px;
    line-height: 0.88;
    text-shadow:
        0 0 20px rgba(51, 255, 51, 0.4),
        0 0 60px rgba(51, 255, 51, 0.15);
    animation: title-pulse 3s ease-in-out infinite;
}

.start-title-sub {
    font-size: clamp(18px, 2.5vw, 24px);
    letter-spacing: 8px;
    color: #7dd77c;
    margin-top: 6px;
    text-shadow: 0 0 8px rgba(51, 255, 51, 0.2);
}

@keyframes title-pulse {
    0%, 100% { text-shadow: 0 0 20px rgba(51, 255, 51, 0.4), 0 0 60px rgba(51, 255, 51, 0.15); }
    50% { text-shadow: 0 0 30px rgba(51, 255, 51, 0.6), 0 0 80px rgba(51, 255, 51, 0.25); }
}

.start-brief {
    margin-top: 16px;
    max-width: 760px;
    font-size: 21px;
    line-height: 1.1;
    letter-spacing: 1px;
    color: #8cd68c;
}

.start-hero-status {
    display: flex;
    gap: 24px;
    margin-top: 16px;
    padding-top: 12px;
    border-top: 1px solid rgba(51, 255, 51, 0.15);
    font-size: 16px;
    letter-spacing: 2px;
    color: #6bac68;
}

.start-wizard {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.start-stage {
    padding: 18px 20px;
    border: 1px solid rgba(51, 255, 51, 0.18);
    border-left: 3px solid rgba(51, 255, 51, 0.25);
    background: rgba(0, 14, 0, 0.84);
    box-shadow: inset 0 0 24px rgba(14, 40, 14, 0.22);
    text-align: left;
    transition: opacity 0.3s ease, transform 0.3s ease, border-color 0.3s ease, box-shadow 0.3s ease;
    position: relative;
}

.start-stage.is-locked {
    opacity: 0.35;
    pointer-events: none;
    transform: translateY(2px);
    border-left-color: rgba(51, 255, 51, 0.08);
}

.start-stage.is-hidden {
    display: none;
}

.wizard-back-btn {
    display: inline-block;
    margin-top: 14px;
    padding: 6px 18px;
    background: none;
    border: 1px solid rgba(51, 255, 51, 0.2);
    color: #6bac68;
    font-family: 'VT323', monospace;
    font-size: 18px;
    letter-spacing: 2px;
    cursor: pointer;
    transition: color 0.2s, border-color 0.2s;
}
.wizard-back-btn:hover {
    color: var(--phosphor-green);
    border-color: rgba(51, 255, 51, 0.5);
}

.start-stage.is-active {
    border-color: rgba(125, 255, 125, 0.45);
    border-left-color: var(--phosphor-green);
    box-shadow:
        0 0 24px rgba(51, 255, 51, 0.08),
        inset 0 0 30px rgba(14, 40, 14, 0.22);
}

.start-stage-head {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 14px;
}

.start-step {
    font-size: 15px;
    letter-spacing: 4px;
    color: #5a9858;
}
.start-stage.is-active .start-step {
    color: #7dd77c;
}

.start-stage-title {
    font-size: 28px;
    letter-spacing: 3px;
    text-transform: uppercase;
    text-shadow: 0 0 6px rgba(51, 255, 51, 0.15);
}
.start-stage.is-active .start-stage-title {
    text-shadow: 0 0 10px rgba(51, 255, 51, 0.3);
}

.start-stage-copy {
    font-size: 18px;
    letter-spacing: 1px;
    color: #7aaf7a;
    line-height: 1.08;
}
.start-stage.is-active .start-stage-copy {
    color: #95d695;
}

.start-mode-choice-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
}

.start-mode-btn {
    width: 100%;
    min-height: 78px;
    margin: 0;
    font-size: 26px;
    letter-spacing: 2px;
    border-width: 2px;
    transition: all 0.25s ease;
}

.start-mode-btn.selected {
    background: rgba(51, 255, 51, 0.15);
    color: var(--phosphor-green);
    border-color: var(--phosphor-green);
    box-shadow: 0 0 20px rgba(51, 255, 51, 0.2), inset 0 0 20px rgba(51, 255, 51, 0.05);
    text-shadow: 0 0 8px rgba(51, 255, 51, 0.4);
}

.start-summary {
    font-size: 20px;
    letter-spacing: 1px;
    color: #b8efb6;
}

.start-launch-actions {
    display: none;
    gap: 12px;
    flex-wrap: wrap;
}

.start-launch-actions.visible {
    display: flex;
}

.start-launch-actions .menu-btn {
    width: auto;
    min-width: 280px;
    margin: 0;
}

.utility-btn {
    width: 240px;
    margin: 0;
    font-size: 18px;
    padding: 10px 16px;
    letter-spacing: 2px;
    border-color: rgba(51, 255, 51, 0.4);
    color: #7dd77c;
}
.utility-btn:hover {
    border-color: var(--phosphor-green);
}

#fullscreen-btn { position: absolute; top: calc(15px + env(safe-area-inset-top, 0px)); right: calc(15px + env(safe-area-inset-right, 0px)); font-size: 18px; padding: 5px 10px; z-index: 50; pointer-events: auto; }
#mobile-dock { display: none; }

@keyframes blink { 0%, 49% { opacity: 1; } 50%, 100% { opacity: 0; } }
@keyframes boot-flash {
    0% { opacity: 0; }
    16% { opacity: 0.92; }
    100% { opacity: 0; }
}
@keyframes boot-line-enter {
    0% {
        opacity: 0;
        transform: translateY(8px);
    }
    100% {
        opacity: 0.92;
        transform: translateY(0);
    }
}
@media (max-width: 1100px) {
    #boot-shell {
        width: calc(100vw - 20px);
        height: min(76vh, 560px);
        padding: 14px;
    }
    #boot-header {
        flex-direction: column;
        gap: 6px;
        font-size: 18px;
        letter-spacing: 2px;
    }
    #boot-subtitle,
    #boot-footer {
        font-size: 14px;
    }
    #boot-access-btn {
        width: min(280px, 100%);
        font-size: 20px;
    }
    #boot-terminal {
        font-size: 16px;
        padding: 12px;
    }
    #layout-shell {
        grid-template-columns: minmax(0, 1fr);
        grid-template-rows: auto 1fr;
        grid-template-areas:
            "top"
            ".";
        gap: 8px;
        padding-top: calc(46px + env(safe-area-inset-top, 0px));
    }
    #top-area { min-width: 0; }
    #left-sidebar { display: contents; }
    #header {
        margin: 0 8px;
        padding: 8px 70px 8px 8px;
        font-size: 18px;
        letter-spacing: 2px;
        line-height: 1.05;
    }
    #stats-container {
        position: fixed;
        top: calc(62px + env(safe-area-inset-top, 0px));
        left: 8px;
        right: 8px;
        z-index: 85;
        justify-content: flex-start;
        gap: 8px;
        overflow-x: auto;
        padding: 0 2px 2px;
        margin-top: 0;
        scrollbar-width: thin;
        pointer-events: auto;
        transform: translateY(calc(-100% - 18px));
        opacity: 0;
        transition: transform 0.22s ease, opacity 0.22s ease;
    }
    #ui-layer[data-mobile-panel="stats"] #stats-container { transform: translateY(0); opacity: 1; }
    .sidebar {
        flex: 0 0 160px;
        max-width: none;
        font-size: 13px;
        padding: 8px 6px;
        margin: 0;
    }
    .stat-value { font-size: 18px; margin-top: 2px; }
    #right-sidebar {
        position: fixed;
        left: 8px;
        right: 8px;
        bottom: calc(62px + env(safe-area-inset-bottom, 0px));
        z-index: 85;
        min-height: 0;
        margin: 0;
        max-height: min(46vh, 420px);
        transform: translateY(calc(100% + 18px));
        opacity: 0;
        pointer-events: none;
        transition: transform 0.22s ease, opacity 0.22s ease;
    }
    #ui-layer[data-mobile-panel="controls"] #right-sidebar { transform: translateY(0); opacity: 1; pointer-events: auto; }
    #controls {
        padding-right: 4px;
        gap: 6px;
    }
    #turn-indicator { font-size: 20px; margin-bottom: 4px; }
    #phase-indicator { font-size: 18px; margin-bottom: 4px; }
    #city-detail {
        min-height: 0;
        font-size: 14px;
        padding: 6px 0;
    }
    #buy-target { font-size: 13px; margin-bottom: 4px; }
    .control-panel-title { font-size: 16px; margin-bottom: 4px; }
    .shop-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 5px; }
    .missile-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 5px; }
    .diplomacy-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 5px; }
    .diplomacy-btn { font-size: 15px; padding: 6px 4px; }
    #resource-display { font-size: 14px; gap: 6px; }
    #instructions-modal {
        width: calc(100vw - 24px);
        max-height: calc(100vh - 40px);
        padding: 12px;
    }
    #instructions-header { font-size: 22px; }
    #instructions-body { font-size: 15px; }
    .instructions-title { font-size: 18px; }
    button { font-size: 16px; padding: 6px 10px; }
    .shop-btn, .missile-btn { font-size: 15px; padding: 6px 4px; }
    #bottom-area {
        position: fixed;
        left: 8px;
        right: 8px;
        bottom: calc(62px + env(safe-area-inset-bottom, 0px));
        z-index: 84;
        min-height: 0;
        margin: 0;
        max-height: min(32vh, 260px);
        transform: translateY(calc(100% + 18px));
        opacity: 0;
        pointer-events: none;
        transition: transform 0.22s ease, opacity 0.22s ease;
    }
    #ui-layer[data-mobile-panel="log"] #bottom-area { transform: translateY(0); opacity: 1; pointer-events: auto; }
    #console-log {
        padding-right: 4px;
        font-size: 13px;
        line-height: 1.08;
    }
    .city-label { font-size: 12px; }
    .city-label .icbm-count { font-size: 13px; }
    .menu-btn { width: 280px; font-size: 20px; }
    .start-shell { width: min(760px, 100%); }
    .start-stage { padding: 16px; }
    .start-stage-title { font-size: 24px; letter-spacing: 2px; }
    .start-stage-copy { font-size: 16px; }
    .start-mode-choice-grid,
    .visual-style-picker,
    .faction-picker { grid-template-columns: 1fr; gap: 8px; }
    .start-mode-btn { min-height: 0; font-size: 22px; }
    .faction-btn,
    .visual-style-btn { font-size: 18px; }
    .visual-style-caption { font-size: 16px; width: 100%; }
    .lobby-title { font-size: 24px; }
    .lobby-btn { width: 240px; font-size: 18px; }
    .lobby-input { font-size: 22px; width: 200px; }
    .lobby-code { font-size: 32px; letter-spacing: 4px; }
    .lobby-player { font-size: 16px; }
    .lobby-label { font-size: 16px; }
    .start-launch-actions .menu-btn { width: 100%; min-width: 0; font-size: 18px; }
    #city-modal {
        width: min(420px, calc(100vw - 24px));
        max-height: calc(100vh - 32px);
        overflow-y: auto;
    }
    #city-modal-header { font-size: 24px; }
    #city-modal-owner { font-size: 18px; }
    #city-modal-body { font-size: 17px; min-height: 0; }
    #game-over-title { font-size: 28px; }
    #game-over-subtitle { font-size: 20px; }
    #game-over-summary { font-size: 18px; }
    #fullscreen-btn { top: calc(6px + env(safe-area-inset-top, 0px)); right: calc(6px + env(safe-area-inset-right, 0px)); font-size: 12px; padding: 2px 5px; }
    #mobile-dock {
        position: fixed;
        left: 8px;
        right: 8px;
        bottom: calc(8px + env(safe-area-inset-bottom, 0px));
        z-index: 90;
        display: grid;
        grid-template-columns: repeat(3, minmax(0, 1fr));
        gap: 6px;
        pointer-events: auto;
    }
    .mobile-dock-btn {
        font-size: 15px;
        padding: 8px 6px;
        background: rgba(0, 15, 0, 0.92);
    }
    .mobile-dock-btn.active {
        background: var(--phosphor-green);
        color: #000;
        box-shadow: 0 0 15px var(--phosphor-green);
    }
}

@media (max-width: 700px) {
    #layout-shell { gap: 6px; padding-top: calc(42px + env(safe-area-inset-top, 0px)); }
    #header {
        margin: 0 6px;
        padding: 7px 62px 7px 7px;
        font-size: 14px;
        letter-spacing: 1px;
    }
    #stats-container {
        left: 6px;
        right: 6px;
        top: calc(52px + env(safe-area-inset-top, 0px));
        gap: 6px;
        padding: 0 2px 2px;
    }
    .sidebar {
        flex: 0 0 118px;
        font-size: 11px;
        padding: 6px 4px;
    }
    .stat-value { font-size: 16px; }
    #right-sidebar {
        left: 6px;
        right: 6px;
        bottom: calc(54px + env(safe-area-inset-bottom, 0px));
        max-height: min(56vh, 420px);
    }
    #controls { gap: 5px; padding-right: 2px; }
    #turn-indicator { font-size: 18px; }
    #phase-indicator { font-size: 16px; }
    .status-block { font-size: 15px; }
    #city-detail, #buy-target { font-size: 13px; }
    .control-panel-title { font-size: 15px; }
    button { font-size: 15px; padding: 6px 8px; }
    .shop-grid { gap: 4px; }
    .shop-btn, .missile-btn { font-size: 13px; padding: 6px 4px; }
    #bottom-area {
        left: 6px;
        right: 6px;
        bottom: calc(54px + env(safe-area-inset-bottom, 0px));
        max-height: min(34vh, 220px);
    }
    #console-log { font-size: 11px; line-height: 1.05; }
    .city-label { font-size: 11px; }
    .city-label .icbm-count { font-size: 12px; }
    #city-modal {
        width: calc(100vw - 16px);
        padding: 12px;
    }
    #city-modal-header { font-size: 20px; }
    #city-modal-owner { font-size: 15px; margin-bottom: 8px; }
    #city-modal-body { font-size: 14px; }
    #city-modal-actions { gap: 6px; }
    #fullscreen-btn { font-size: 10px; }
    #mobile-dock {
        left: 6px;
        right: 6px;
        bottom: calc(6px + env(safe-area-inset-bottom, 0px));
        gap: 4px;
    }
    .mobile-dock-btn { font-size: 13px; padding: 8px 4px; }
    .auth-btn { width: 220px !important; font-size: 16px !important; }
    .auth-avatar { width: 24px; height: 24px; }
    .auth-name { font-size: 16px; }
    .start-secondary-row { flex-direction: column; align-items: center; gap: 0; }
    .start-secondary-row .menu-btn { width: 220px !important; font-size: 16px !important; }
    #ad-banner-start { max-width: calc(100vw - 40px); }
    .ad-interstitial { max-width: calc(100vw - 40px); }
    .leaderboard-table { font-size: 14px; }
    .leaderboard-table th, .leaderboard-table td { padding: 4px 6px; }
    #leaderboard-modal, #profile-modal { width: calc(100vw - 24px); padding: 12px; }
    #leaderboard-header, #profile-header { font-size: 22px; }
    .profile-stats-grid { grid-template-columns: 1fr 1fr; font-size: 14px; }
    .profile-match { font-size: 13px; padding: 6px; }
}

/* --- Auth Bar --- */
#auth-bar { margin-top: 14px; min-height: 50px; display: flex; justify-content: flex-start; align-items: center; }
#auth-signed-in { display: flex; align-items: center; gap: 10px; }
.auth-avatar { width: 32px; height: 32px; border-radius: 50%; border: 2px solid var(--phosphor-green); }
.auth-name { font-size: 20px; color: var(--phosphor-green); letter-spacing: 1px; cursor: pointer; }
.auth-name:hover { text-shadow: 0 0 10px var(--phosphor-green); }
.auth-link { background: none; border: none; color: var(--phosphor-dim); font-family: 'VT323', monospace; font-size: 16px; cursor: pointer; padding: 0; text-transform: uppercase; }
.auth-link:hover { color: var(--phosphor-green); text-shadow: 0 0 5px var(--phosphor-green); background: none; box-shadow: none; }
.auth-btn { border-color: #4285f4 !important; color: #4285f4 !important; box-shadow: 0 0 10px rgba(66, 133, 244, 0.3) !important; }
.auth-btn:hover { background: #4285f4 !important; color: #000 !important; box-shadow: 0 0 25px rgba(66, 133, 244, 0.6) !important; }
.start-secondary-row { display: flex; gap: 12px; flex-wrap: wrap; justify-content: center; }

/* --- Leaderboard Modal --- */
#leaderboard-overlay {
    position: absolute; inset: 0; display: none; align-items: center; justify-content: center;
    background: rgba(0, 0, 0, 0.82); z-index: 2100; pointer-events: auto; padding: 20px; box-sizing: border-box;
}
#leaderboard-overlay.visible { display: flex; }
#leaderboard-modal {
    width: min(620px, calc(100vw - 40px)); max-height: calc(100vh - 60px); overflow-y: auto;
    border-color: var(--phosphor-green); box-shadow: 0 0 30px rgba(51, 255, 51, 0.22); scrollbar-width: thin;
}
#leaderboard-header {
    font-size: 32px; letter-spacing: 3px; text-align: center; margin-bottom: 16px;
    text-shadow: 0 0 10px var(--phosphor-green);
}
#leaderboard-body { font-size: 18px; line-height: 1.25; min-height: 100px; }
.leaderboard-loading { text-align: center; padding: 40px 0; }
.leaderboard-table { width: 100%; border-collapse: collapse; }
.leaderboard-table th {
    text-align: left; border-bottom: 2px solid var(--phosphor-dim); padding: 6px 8px;
    font-size: 16px; letter-spacing: 1px; color: var(--phosphor-dim);
}
.leaderboard-table td { padding: 6px 8px; border-bottom: 1px solid rgba(51, 255, 51, 0.15); }
.leaderboard-table tr.highlight { background: rgba(51, 255, 51, 0.1); }
.leaderboard-table .rank { width: 40px; text-align: center; }
.leaderboard-table .elo { color: #ffcc00; font-size: 20px; }
.leaderboard-table .record { color: #aaffaa; font-size: 16px; }
.leaderboard-empty { text-align: center; color: #555; padding: 30px 0; }

/* --- Profile Modal --- */
#profile-overlay {
    position: absolute; inset: 0; display: none; align-items: center; justify-content: center;
    background: rgba(0, 0, 0, 0.82); z-index: 2100; pointer-events: auto; padding: 20px; box-sizing: border-box;
}
#profile-overlay.visible { display: flex; }
#profile-modal {
    width: min(560px, calc(100vw - 40px)); max-height: calc(100vh - 60px); overflow-y: auto;
    border-color: var(--phosphor-green); box-shadow: 0 0 30px rgba(51, 255, 51, 0.22); scrollbar-width: thin;
}
#profile-header {
    font-size: 32px; letter-spacing: 3px; text-align: center; margin-bottom: 16px;
    text-shadow: 0 0 10px var(--phosphor-green);
}
#profile-body { font-size: 18px; line-height: 1.3; }
.profile-loading { text-align: center; padding: 40px 0; }
.profile-info { display: flex; align-items: center; gap: 14px; margin-bottom: 16px; }
.profile-avatar-lg { width: 56px; height: 56px; border-radius: 50%; border: 2px solid var(--phosphor-green); }
.profile-name { font-size: 26px; letter-spacing: 2px; }
.profile-elo { font-size: 22px; color: #ffcc00; }
.profile-record { display: flex; gap: 16px; margin-bottom: 16px; font-size: 20px; }
.profile-record .win { color: #33ff33; }
.profile-record .loss { color: #ff3333; }
.profile-record .draw { color: #ffcc00; }
.profile-stats-grid {
    display: grid; grid-template-columns: 1fr 1fr; gap: 6px 16px; margin-bottom: 16px;
    font-size: 16px; border-top: 1px solid var(--phosphor-dim); padding-top: 12px;
}
.profile-stat-label { color: #aaffaa; }
.profile-stat-value { text-align: right; }
.profile-history-title { font-size: 20px; letter-spacing: 1px; margin-bottom: 8px; border-top: 1px solid var(--phosphor-dim); padding-top: 12px; }
.profile-match {
    padding: 8px; border-bottom: 1px solid rgba(51, 255, 51, 0.15); font-size: 16px; display: flex;
    justify-content: space-between; align-items: center; gap: 8px;
}
.profile-match .outcome-win { color: #33ff33; }
.profile-match .outcome-loss { color: #ff3333; }
.profile-match .outcome-draw { color: #ffcc00; }
.profile-match .match-detail { color: #aaffaa; font-size: 14px; }
.profile-no-history { text-align: center; color: #555; padding: 20px 0; }

/* --- Queue Status --- */
#queue-status { margin-top: 16px; text-align: center; }
.queue-searching { font-size: 22px; letter-spacing: 2px; margin-bottom: 12px; }
#queue-players { margin: 10px 0; text-align: left; max-width: 360px; margin-left: auto; margin-right: auto; }
.queue-player {
    font-size: 18px; padding: 6px 8px; letter-spacing: 1px;
    border-bottom: 1px solid rgba(51, 255, 51, 0.1);
    display: flex; justify-content: space-between; align-items: center;
    cursor: pointer; transition: background 0.2s;
}
.queue-player:hover { background: rgba(51, 255, 51, 0.05); }
.queue-player-name { }
.queue-player-elo { font-size: 14px; opacity: 0.7; }
.queue-timer { font-size: 18px; color: #aaffaa; margin-bottom: 12px; }

/* --- Ad Containers --- */
.ad-container { text-align: center; margin: 16px auto; }
.ad-banner { max-width: 728px; min-height: 90px; }
.ad-interstitial { max-width: 560px; min-height: 250px; margin: 12px auto; }
.ad-placeholder {
    border: 1px dashed rgba(51, 255, 51, 0.3); color: rgba(51, 255, 51, 0.3);
    font-family: 'VT323', monospace; font-size: 16px; letter-spacing: 2px;
    display: flex; align-items: center; justify-content: center;
    min-height: inherit; padding: 20px;
}

/* --- Game Over Session Stats --- */
#game-over-session-stats {
    font-size: 18px; line-height: 1.3; margin-bottom: 12px; text-align: left;
    border-top: 1px solid rgba(51, 255, 51, 0.25); padding-top: 10px; margin-top: 10px;
}
.session-stat-line { display: flex; justify-content: space-between; gap: 12px; padding: 2px 0; }
.session-stat-label { color: #aaffaa; }
.session-stat-value { color: var(--phosphor-green); }

/* --- Cookie Consent Banner --- */
#cookie-consent {
    display: none;
    position: fixed;
    bottom: 0; left: 0; right: 0;
    z-index: 99999;
    justify-content: center;
    padding: 0 16px 16px;
    pointer-events: none;
}
#cookie-consent-inner {
    pointer-events: all;
    max-width: 720px;
    width: 100%;
    background: rgba(0, 10, 0, 0.96);
    border: 1px solid rgba(51, 255, 51, 0.35);
    border-top: 2px solid var(--phosphor-green);
    padding: 18px 22px;
    font-family: 'VT323', monospace;
    box-shadow: 0 0 30px rgba(0, 255, 0, 0.08), inset 0 0 20px rgba(0, 20, 0, 0.5);
}
#cookie-consent-text {
    font-size: 18px;
    color: #95d695;
    letter-spacing: 1px;
    line-height: 1.3;
    margin-bottom: 14px;
}
#cookie-consent-text a {
    color: var(--phosphor-green);
    text-decoration: underline;
}
#cookie-consent-buttons {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
}
.cookie-btn {
    font-size: 18px !important;
    padding: 8px 20px !important;
    min-width: 160px;
    margin: 0 !important;
}
.cookie-btn-secondary {
    background: transparent !important;
    border-color: rgba(51, 255, 51, 0.3) !important;
    color: #6bac68 !important;
}
.cookie-btn-secondary:hover {
    border-color: rgba(51, 255, 51, 0.6) !important;
    color: var(--phosphor-green) !important;
}
@media (max-width: 600px) {
    #cookie-consent-inner { padding: 14px 16px; }
    #cookie-consent-text { font-size: 16px; }
    .cookie-btn { width: 100%; min-width: 0; font-size: 16px !important; }
}
