/* ═══ AIRLOCKED — dark station theme ═══ */

:root {
    --bg: #060a12;
    --panel: #0c1420;
    --panel2: #101c2e;
    --line: #1e3450;
    --cyan: #4dd2ff;
    --green: #7dff4d;
    --red: #ff4d4d;
    --yellow: #ffd24d;
    --text: #cfe3f5;
    --muted: #6d87a3;
    --glow-cyan: 0 0 12px rgba(77, 210, 255, .45);
    --glow-red: 0 0 14px rgba(255, 77, 77, .55);
}

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

html, body {
    background: var(--bg);
    color: var(--text);
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    min-height: 100%;
}

body {
    background-image:
        radial-gradient(ellipse at 20% -10%, rgba(30, 60, 110, .25), transparent 55%),
        radial-gradient(ellipse at 90% 110%, rgba(80, 20, 40, .18), transparent 50%);
}

#app { min-height: 100vh; }

h1, h2, h3 { font-weight: 700; letter-spacing: .04em; }
h2 { font-size: 1.05rem; color: var(--cyan); text-transform: uppercase; margin-bottom: 12px; }
.muted { color: var(--muted); }
.small { font-size: .82rem; }
.mono { font-family: 'Consolas', 'Menlo', monospace; }

/* ── Buttons & inputs ── */
.btn {
    display: inline-block;
    background: var(--panel2);
    color: var(--text);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 10px 18px;
    font-size: .95rem;
    font-weight: 600;
    cursor: pointer;
    transition: all .15s;
    font-family: inherit;
}
.btn:hover { border-color: var(--cyan); box-shadow: var(--glow-cyan); }
.btn:active { transform: translateY(1px); }
.btn-primary {
    background: linear-gradient(180deg, #10405e, #0a2c44);
    border-color: #2a6a94;
    color: #d8f2ff;
}
.btn-danger { background: linear-gradient(180deg, #5e1010, #440a0a); border-color: #944; color: #ffd8d8; }
.btn-large { width: 100%; padding: 14px; font-size: 1.1rem; margin-top: 14px; }
.btn-sm { padding: 5px 12px; font-size: .8rem; }
.btn:disabled { opacity: .45; cursor: default; box-shadow: none; }

input, select {
    width: 100%;
    background: #08101c;
    border: 1px solid var(--line);
    border-radius: 8px;
    color: var(--text);
    padding: 11px 12px;
    font-size: 1rem;
    margin: 6px 0 14px;
    font-family: inherit;
}
input:focus, select:focus { outline: none; border-color: var(--cyan); box-shadow: var(--glow-cyan); }
label { font-size: .85rem; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.check-row { display: flex; align-items: center; gap: 8px; text-transform: none; letter-spacing: 0; font-size: .9rem; margin-bottom: 6px; }
.check-row input { width: auto; margin: 0; }

.card {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: 20px;
}

/* ── Home ── */
.home-container { max-width: 1000px; margin: 0 auto; padding: 28px 16px 60px; }
.hero { text-align: center; padding: 22px 0 30px; }
.game-title {
    font-size: clamp(2.4rem, 8vw, 4rem);
    letter-spacing: .22em;
    color: #eaf7ff;
    text-shadow: 0 0 18px rgba(77, 210, 255, .6), 0 0 60px rgba(77, 210, 255, .25);
}
.glitch { animation: titleFlicker 7s infinite; }
@keyframes titleFlicker {
    0%, 91%, 94%, 100% { opacity: 1; }
    92%, 93% { opacity: .55; text-shadow: 0 0 18px rgba(255, 77, 77, .7); }
}
.tagline { margin-top: 12px; color: var(--muted); line-height: 1.6; }
.tagline-red { color: #ff8888; }
.error-banner {
    background: rgba(255, 77, 77, .12);
    border: 1px solid #7a2020;
    color: #ffb0b0;
    border-radius: 10px;
    padding: 12px 16px;
    margin-bottom: 18px;
    text-align: center;
}
.home-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
@media (max-width: 760px) { .home-grid { grid-template-columns: 1fr; } }

.registry-head { margin: 20px 0 8px; font-size: .9rem; color: var(--muted); text-transform: uppercase; }
.live-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--green); animation: pulse 2s infinite; }
@keyframes pulse { 50% { opacity: .3; } }
.room-browser { list-style: none; max-height: 220px; overflow-y: auto; }
.room-row {
    display: flex; align-items: center; gap: 12px;
    padding: 9px 10px; border-bottom: 1px solid #101c2c; cursor: pointer;
}
.room-row:hover { background: rgba(77, 210, 255, .06); }
.room-code { font-family: monospace; font-size: 1.05rem; color: var(--cyan); letter-spacing: .12em; }
.room-row .btn { margin-left: auto; }
.empty-msg { padding: 14px 6px; }

.leaderboard-card { margin-top: 18px; }
.leaderboard { width: 100%; border-collapse: collapse; font-size: .9rem; }
.leaderboard th { color: var(--muted); text-align: left; font-size: .75rem; text-transform: uppercase; padding: 6px 8px; }
.leaderboard td { padding: 8px; border-top: 1px solid #101c2c; }
.crew-names { max-width: 280px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.how-to { margin-top: 34px; }
.how-to > h2 { text-align: center; margin-bottom: 18px; }
.how-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 14px; }
.how-card {
    background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
    padding: 16px;
}
.how-icon { font-size: 1.6rem; display: block; margin-bottom: 8px; }
.how-card b { color: #e8f4ff; }
.how-card p { color: var(--muted); font-size: .87rem; margin-top: 6px; line-height: 1.5; }
.home-footer { text-align: center; margin-top: 30px; }

/* ── Lobby ── */
.lobby-container { max-width: 900px; margin: 0 auto; padding: 26px 16px 50px; text-align: center; }
.room-code-display { margin: 18px 0 6px; font-size: 1.1rem; }
.room-code-display .code {
    font-family: monospace; font-size: 1.6rem; color: var(--cyan);
    letter-spacing: .25em; text-shadow: var(--glow-cyan); margin: 0 8px;
}
.share-hint { color: var(--muted); margin-bottom: 22px; font-size: .9rem; }
.lobby-grid { display: grid; grid-template-columns: 300px 1fr; gap: 16px; text-align: left; }
@media (max-width: 760px) { .lobby-grid { grid-template-columns: 1fr; } }

.player-list { list-style: none; }
.player-item { display: flex; align-items: center; gap: 10px; padding: 9px 4px; border-bottom: 1px solid #101c2c; flex-wrap: wrap; }
.player-dot { width: 13px; height: 13px; border-radius: 50%; box-shadow: 0 0 8px currentColor; flex: none; }
.player-name { font-weight: 600; }
.host-badge {
    background: #3a2a00; color: var(--yellow); font-size: .65rem;
    border: 1px solid #6a5210; padding: 2px 7px; border-radius: 20px; letter-spacing: .1em;
}
.role-chip { font-size: .75rem; color: var(--cyan); background: rgba(77,210,255,.08); border: 1px solid #1c3c56; padding: 2px 8px; border-radius: 20px; }
.role-chip.unassigned { color: var(--muted); border-color: var(--line); background: none; }

.role-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(215px, 1fr)); gap: 10px; }
.role-card {
    background: #0a1220; border: 1px solid var(--line); border-radius: 12px;
    padding: 12px; text-align: left; cursor: pointer; color: var(--text);
    display: flex; flex-direction: column; gap: 5px; font-family: inherit; transition: all .15s;
}
.role-card:hover:not([disabled]) { border-color: var(--cyan); box-shadow: var(--glow-cyan); }
.role-card.mine { border-color: var(--green); box-shadow: 0 0 12px rgba(125, 255, 77, .35); }
.role-card.taken { opacity: .55; cursor: default; }
.role-icon { font-size: 1.5rem; }
.role-name { font-weight: 700; letter-spacing: .05em; color: #e8f4ff; }
.role-ability { font-size: .76rem; color: var(--cyan); line-height: 1.4; }
.role-passive { font-size: .72rem; color: var(--muted); line-height: 1.4; }
.role-owner { font-size: .75rem; font-weight: 700; letter-spacing: .08em; }
.waiting-msg { margin-top: 22px; color: var(--muted); }
.blink { animation: pulse 1.6s infinite; }
.start-hint { color: var(--muted); font-size: .85rem; margin-top: 10px; }

/* ═══ GAME SCREEN ═══ */
.game-body { position: fixed; inset: 0; overflow: hidden; background: #04070d; }
#game-canvas { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; }

/* Alert overlays */
#alert-overlay { position: absolute; inset: 0; pointer-events: none; z-index: 5; }
#alert-overlay.yellow { animation: yellowAlert 2.2s infinite; }
#alert-overlay.red { animation: redAlert 1.1s infinite; }
@keyframes yellowAlert {
    0%, 100% { box-shadow: inset 0 0 0px rgba(255, 210, 77, 0); }
    50% { box-shadow: inset 0 0 120px rgba(255, 210, 77, .28); }
}
@keyframes redAlert {
    0%, 100% { box-shadow: inset 0 0 0px rgba(255, 40, 40, 0); }
    50% { box-shadow: inset 0 0 140px rgba(255, 40, 40, .4); }
}
#hurt-overlay {
    position: absolute; inset: 0; pointer-events: none; z-index: 6; opacity: 0;
    background: radial-gradient(ellipse at center, transparent 40%, rgba(255, 0, 0, .5));
    transition: opacity .3s;
}

/* HUD top bar */
#hud-top {
    position: absolute; top: 0; left: 0; right: 0; z-index: 10;
    display: flex; align-items: center; gap: 10px;
    padding: calc(6px + env(safe-area-inset-top)) 10px 6px;
    background: linear-gradient(180deg, rgba(4, 8, 14, .92), rgba(4, 8, 14, 0));
    pointer-events: none;
}
#hud-top > * { pointer-events: auto; }
#sector-name { font-weight: 700; letter-spacing: .08em; font-size: .95rem; white-space: nowrap; }
#alert-chip {
    font-size: .68rem; font-weight: 800; letter-spacing: .14em; padding: 3px 10px;
    border-radius: 20px; border: 1px solid var(--line); color: var(--muted);
}
#alert-chip.yellow { color: #1a1400; background: var(--yellow); border-color: var(--yellow); animation: pulse 1.4s infinite; }
#alert-chip.red { color: #fff; background: #c01818; border-color: #ff6060; animation: pulse .7s infinite; }
#threat-wrap { flex: 1; max-width: 260px; }
#threat-label { font-size: .62rem; color: var(--muted); letter-spacing: .12em; }
#threat-bar { height: 8px; background: #0a1424; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
#threat-fill { height: 100%; width: 10%; background: linear-gradient(90deg, #2a9a4a, #d8c020, #e03030); transition: width .5s; }
#o2-wrap { width: 90px; }
#o2-label { font-size: .62rem; color: var(--cyan); letter-spacing: .12em; }
#o2-bar { height: 8px; background: #0a1424; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
#o2-fill { height: 100%; width: 100%; background: var(--cyan); transition: width .3s; }
#o2-fill.low { background: var(--red); animation: pulse .6s infinite; }
#tank-chip {
    font-size: .68rem; font-weight: 800; letter-spacing: .1em; padding: 3px 10px;
    border-radius: 20px; border: 1px solid #2a6a94; color: #9fe4ff;
    background: rgba(30, 90, 130, .35); white-space: nowrap;
}
#hud-right { margin-left: auto; display: flex; gap: 8px; align-items: center; }
.hud-icon-btn {
    background: rgba(12, 20, 32, .8); border: 1px solid var(--line); color: var(--text);
    width: 38px; height: 38px; border-radius: 10px; font-size: 1.1rem; cursor: pointer;
}
.hud-icon-btn:active { transform: scale(.94); }

/* Crew strip */
#crew-strip {
    position: absolute; top: calc(52px + env(safe-area-inset-top)); left: 8px; z-index: 9;
    display: flex; flex-direction: column; gap: 4px; pointer-events: none;
}
.crew-pip {
    display: flex; align-items: center; gap: 6px; font-size: .72rem;
    background: rgba(6, 10, 18, .72); border: 1px solid #14243a; border-radius: 20px;
    padding: 2px 9px 2px 4px; max-width: 150px;
}
.crew-pip .dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.crew-pip .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.crew-pip.down { border-color: #7a2020; color: #ff9090; }
.crew-pip.pod { border-color: #2a6a2a; color: #a0ffa0; }

/* Minimap */
#minimap {
    position: absolute; right: 8px; top: calc(52px + env(safe-area-inset-top)); z-index: 9;
    background: rgba(6, 10, 18, .78); border: 1px solid #14243a; border-radius: 8px;
}

/* Bottom controls */
#controls {
    position: absolute; left: 0; right: 0; bottom: 0; z-index: 10;
    padding: 0 14px calc(14px + env(safe-area-inset-bottom));
    display: flex; align-items: flex-end; justify-content: space-between; pointer-events: none;
}
#joystick {
    width: 130px; height: 130px; border-radius: 50%; position: relative;
    background: rgba(20, 34, 54, .35); border: 1px solid rgba(77, 210, 255, .25);
    pointer-events: auto; touch-action: none; display: none;
}
#joystick .stick {
    position: absolute; width: 54px; height: 54px; border-radius: 50%;
    background: rgba(77, 210, 255, .35); border: 1px solid var(--cyan);
    left: 38px; top: 38px;
}
body.touch #joystick { display: block; }

#action-cluster { display: flex; flex-direction: column; gap: 10px; align-items: flex-end; pointer-events: auto; }
.action-btn {
    min-width: 120px; padding: 13px 20px; border-radius: 14px; font-weight: 800;
    font-size: .95rem; letter-spacing: .06em; border: 1px solid;
    cursor: pointer; font-family: inherit;
}
#interact-btn { background: rgba(16, 64, 94, .92); border-color: var(--cyan); color: #d8f2ff; display: none; }
#interact-btn.show { display: block; animation: popIn .18s; }
#ability-btn {
    background: rgba(40, 18, 66, .92); border-color: #b84dff; color: #efd8ff;
    position: relative; overflow: hidden;
}
#ability-btn .cd-fill {
    position: absolute; left: 0; top: 0; bottom: 0; background: rgba(0, 0, 0, .55); width: 0%;
}
#ability-btn .lbl { position: relative; }
#ability-btn.ready { box-shadow: 0 0 16px rgba(184, 77, 255, .5); }
@keyframes popIn { from { transform: scale(.7); opacity: 0; } }

/* Chat */
#chat-log {
    position: absolute; left: 8px; bottom: calc(160px + env(safe-area-inset-bottom)); z-index: 8;
    max-width: 300px; max-height: 30vh; overflow-y: auto; pointer-events: none;
    display: flex; flex-direction: column; gap: 3px; font-size: .8rem;
}
.chat-line {
    background: rgba(6, 10, 18, .78); border-radius: 8px; padding: 4px 9px;
    animation: chatFade 9s forwards;
}
.chat-line b { margin-right: 4px; }
.chat-line.sys { color: var(--cyan); font-style: italic; }
.chat-line.bad { color: #ff9090; }
@keyframes chatFade { 0%, 80% { opacity: 1; } 100% { opacity: .25; } }
#chat-bar {
    position: absolute; left: 8px; bottom: calc(8px + env(safe-area-inset-bottom)); z-index: 11;
    display: none; gap: 6px; width: min(420px, calc(100% - 170px));
}
#chat-bar.open { display: flex; }
#chat-bar input { margin: 0; flex: 1; }
#quick-chat { display: flex; gap: 5px; flex-wrap: wrap; margin-top: 5px; }

/* Prompt toast */
#prompt-toast {
    position: absolute; left: 50%; transform: translateX(-50%);
    bottom: calc(190px + env(safe-area-inset-bottom)); z-index: 9;
    background: rgba(6, 10, 18, .85); border: 1px solid var(--line);
    padding: 8px 16px; border-radius: 10px; font-size: .88rem; pointer-events: none;
    display: none;
}
#prompt-toast.show { display: block; }
#prompt-toast b { color: var(--cyan); }

/* Event banner */
#event-banner {
    position: absolute; top: 18%; left: 50%; transform: translateX(-50%); z-index: 12;
    font-size: clamp(1.1rem, 4vw, 1.8rem); font-weight: 800; letter-spacing: .12em;
    color: #ffd0d0; text-shadow: 0 0 20px rgba(255, 60, 60, .8); text-align: center;
    opacity: 0; pointer-events: none; transition: opacity .3s; white-space: nowrap;
}
#event-banner.show { opacity: 1; }
#event-banner.good { color: #d0ffd0; text-shadow: 0 0 20px rgba(60, 255, 120, .8); }

/* ── Modals ── */
.overlay {
    position: fixed; inset: 0; z-index: 40; display: flex; align-items: center;
    justify-content: center; background: rgba(2, 4, 8, .78); padding: 14px;
}
.hidden { display: none !important; }
.overlay-card {
    background: var(--panel); border: 1px solid #24466a; border-radius: 16px;
    width: min(560px, 100%); max-height: 88vh; overflow-y: auto; padding: 22px;
    box-shadow: 0 0 40px rgba(77, 210, 255, .15);
}
.overlay-card h2 { display: flex; align-items: center; gap: 8px; }
.puzzle-prompt { margin: 12px 0 16px; line-height: 1.55; color: #e6f2ff; }
.puzzle-flavor { font-size: .8rem; color: var(--muted); margin-bottom: 10px; }

.answer-blanks { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 14px; }
.answer-blanks .blank {
    width: 26px; border-bottom: 2px solid var(--cyan); text-align: center;
    font-family: monospace; font-size: 1.3rem; height: 32px; color: #fff;
}
.puzzle-actions { display: flex; gap: 10px; margin-top: 16px; flex-wrap: wrap; }
.puzzle-actions .btn { flex: 1; min-width: 110px; }
.hint-box {
    background: rgba(255, 210, 77, .08); border: 1px solid #4a3c10; color: #ffe9a8;
    border-radius: 10px; padding: 10px 14px; margin-top: 12px; font-size: .9rem; line-height: 1.5;
}
.wrong-shake { animation: shake .4s; }
@keyframes shake {
    0%, 100% { transform: translateX(0); } 20% { transform: translateX(-10px); }
    40% { transform: translateX(9px); } 60% { transform: translateX(-6px); } 80% { transform: translateX(4px); }
}

/* Keypad */
.keypad { display: grid; grid-template-columns: repeat(3, 72px); gap: 8px; justify-content: center; }
.keypad button {
    height: 58px; font-size: 1.4rem; background: #0a1626; color: var(--cyan);
    border: 1px solid #1c3c56; border-radius: 10px; cursor: pointer; font-family: monospace;
}
.keypad button:active { background: #10304a; }
.code-display {
    text-align: center; font-family: monospace; font-size: 2rem; letter-spacing: .4em;
    background: #050d18; border: 1px solid var(--line); border-radius: 10px;
    padding: 10px; margin-bottom: 14px; min-height: 58px; color: var(--green);
}

/* Wires */
.wires-box { display: flex; justify-content: space-between; gap: 20px; }
.wire-col { display: flex; flex-direction: column; gap: 10px; flex: 1; }
.wire-end, .wire-term {
    padding: 13px 10px; border-radius: 10px; border: 2px solid; cursor: pointer;
    font-weight: 800; text-align: center; letter-spacing: .06em; background: #0a1220;
    font-family: inherit; font-size: .9rem; color: var(--text);
}
.wire-end.sel { box-shadow: 0 0 14px currentColor; transform: scale(1.04); }
.wire-end.done, .wire-term.done { opacity: .45; cursor: default; }
.wire-term { border-color: var(--line); }

/* Simon */
.simon-grid { display: grid; grid-template-columns: repeat(2, 96px); gap: 12px; justify-content: center; margin: 10px 0; }
.simon-pad {
    height: 96px; border-radius: 14px; border: 2px solid #223; cursor: pointer; opacity: .5;
    transition: opacity .1s, transform .1s;
}
.simon-pad.lit { opacity: 1; transform: scale(1.05); box-shadow: 0 0 24px currentColor; }
.simon-status { text-align: center; color: var(--muted); margin-bottom: 8px; min-height: 22px; }

/* Order */
.order-pool, .order-answer { display: flex; flex-direction: column; gap: 8px; margin: 8px 0; }
.order-item {
    padding: 11px 14px; background: #0a1626; border: 1px solid #1c3c56; border-radius: 10px;
    cursor: pointer; font-weight: 600; font-family: inherit; color: var(--text); text-align: left; font-size: .92rem;
}
.order-item:active { background: #10304a; }
.order-answer .order-item { border-color: var(--green); background: #0a2010; }
.order-slot-label { font-size: .72rem; color: var(--muted); text-transform: uppercase; letter-spacing: .1em; margin-top: 8px; }

/* Text answer */
.text-answer { font-size: 1.25rem; text-align: center; letter-spacing: .12em; text-transform: uppercase; }

/* Clue toast */
#clue-toast {
    position: absolute; top: 26%; left: 50%; transform: translateX(-50%); z-index: 30;
    background: rgba(8, 14, 24, .95); border: 1px solid var(--cyan); border-radius: 12px;
    padding: 14px 22px; font-family: monospace; font-size: 1.15rem; color: var(--green);
    box-shadow: var(--glow-cyan); display: none; text-align: center;
}
#clue-toast.show { display: block; animation: popIn .2s; }

/* Downed overlay */
#downed-overlay {
    position: absolute; inset: 0; z-index: 20; pointer-events: none; display: none;
    align-items: center; justify-content: center; flex-direction: column; gap: 10px;
    background: radial-gradient(ellipse at center, rgba(60, 0, 0, .35), rgba(10, 0, 0, .8));
}
#downed-overlay.show { display: flex; }
#downed-overlay h2 { color: #ff8080; font-size: 1.6rem; letter-spacing: .18em; animation: pulse 1.2s infinite; }
#downed-overlay p { color: #d0a0a0; }

/* Results / cutscene */
#cutscene-canvas { position: absolute; inset: 0; width: 100%; height: 100%; z-index: 45; display: none; }
#results-overlay .overlay-card { text-align: center; }
.results-title { font-size: 1.9rem; letter-spacing: .2em; margin-bottom: 4px; }
.results-title.win { color: var(--green); text-shadow: 0 0 24px rgba(125, 255, 77, .5); }
.results-title.lose { color: var(--red); text-shadow: var(--glow-red); }
.results-time { font-family: monospace; font-size: 2.4rem; color: var(--cyan); margin: 10px 0; }
.results-stats { display: flex; justify-content: center; gap: 22px; flex-wrap: wrap; margin: 12px 0 6px; color: var(--muted); font-size: .9rem; }
.results-stats b { color: var(--text); display: block; font-size: 1.3rem; }
.crew-results { margin: 14px 0; text-align: left; }
.crew-result-row {
    display: flex; align-items: center; gap: 9px; padding: 7px 6px;
    border-bottom: 1px solid #101c2c; font-size: .88rem; flex-wrap: wrap;
}
.crew-result-row .awards { color: var(--yellow); font-size: .78rem; margin-left: auto; }
.results-actions { display: flex; gap: 10px; justify-content: center; margin-top: 16px; flex-wrap: wrap; }

/* Mute / fullscreen row on small screens */
@media (max-width: 700px) {
    #threat-wrap { max-width: 130px; }
    #sector-name { font-size: .8rem; }
    #chat-log { bottom: calc(210px + env(safe-area-inset-bottom)); max-width: 220px; }
    #minimap { transform-origin: top right; transform: scale(.8); }
    .keypad { grid-template-columns: repeat(3, 62px); }
    .keypad button { height: 50px; }
}
