/* ═══ MELTDOWN — industrial control-room theme ═══ */

:root {
    --bg: #0d0a05;
    --panel: #1a140b;
    --panel2: #241b0e;
    --line: #3d3018;
    --amber: #ffb020;
    --hot: #ff3030;
    --green: #46e05a;
    --cyan: #4dd2ff;
    --text: #f2e8d5;
    --muted: #a08d66;
}

* { 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(120, 80, 20, .22), transparent 55%),
        radial-gradient(ellipse at 90% 110%, rgba(160, 30, 30, .14), transparent 50%);
}

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

.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(--amber); box-shadow: 0 0 14px rgba(255, 176, 32, .35); }
.btn:active { transform: translateY(1px); }
.btn-primary { background: linear-gradient(180deg, #7a5510, #543908); border-color: #a87a20; color: #ffe9bd; }
.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: #120d06; 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(--amber); box-shadow: 0 0 12px rgba(255, 176, 32, .3); }
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 / lobby ── */
.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: .18em; color: var(--amber);
    text-shadow: 0 0 22px rgba(255, 176, 32, .55);
    animation: hazardFlicker 6s infinite;
}
@keyframes hazardFlicker {
    0%, 88%, 92%, 100% { opacity: 1; }
    89%, 91% { opacity: .6; text-shadow: 0 0 22px rgba(255, 48, 48, .7); }
}
.tagline { margin-top: 12px; color: var(--muted); line-height: 1.6; }
.tagline-hot { color: #ff9a7a; }
.error-banner {
    background: rgba(255, 48, 48, .12); border: 1px solid #7a2020; color: #ffb0a0;
    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 #221a0e; cursor: pointer; }
.room-row:hover { background: rgba(255, 176, 32, .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 #221a0e; }
.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: #fff; }
.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-container { max-width: 640px; margin: 0 auto; padding: 26px 16px 50px; text-align: center; }
.lobby-card { text-align: left; margin-bottom: 14px; }
.lobby-tip { text-align: left; font-size: .9rem; color: var(--muted); margin-bottom: 8px; }
.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; margin: 0 8px; }
.share-hint { color: var(--muted); margin-bottom: 22px; font-size: .9rem; }
.player-list { list-style: none; }
.player-item { display: flex; align-items: center; gap: 10px; padding: 9px 4px; border-bottom: 1px solid #221a0e; }
.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(--amber); font-size: .65rem;
    border: 1px solid #6a5210; padding: 2px 7px; border-radius: 20px; letter-spacing: .1em;
}
.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-shell {
    min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column;
    max-width: 900px; margin: 0 auto; padding: 0 10px calc(10px + env(safe-area-inset-bottom));
    position: relative;
}
#alert-flash { position: fixed; inset: 0; pointer-events: none; z-index: 5; }
#alert-flash.strike { animation: strikeFlash .6s; }
@keyframes strikeFlash {
    0% { background: rgba(255, 40, 40, .35); } 100% { background: transparent; }
}
#alert-flash.danger { animation: dangerPulse 1s infinite; }
@keyframes dangerPulse {
    0%, 100% { box-shadow: inset 0 0 0 rgba(255, 40, 40, 0); }
    50% { box-shadow: inset 0 0 120px rgba(255, 40, 40, .3); }
}
.game-shell.shaking { animation: shake .5s; }
@keyframes shake {
    0%, 100% { transform: translate(0); } 20% { transform: translate(-10px, 4px); }
    40% { transform: translate(9px, -5px); } 60% { transform: translate(-7px, -3px); }
    80% { transform: translate(5px, 4px); }
}

#game-top {
    display: flex; align-items: center; gap: 10px;
    padding: calc(10px + env(safe-area-inset-top)) 4px 8px;
}
.mini-logo { font-weight: 800; letter-spacing: .08em; color: var(--amber); white-space: nowrap; }
#role-chip {
    font-size: .68rem; font-weight: 800; letter-spacing: .1em; padding: 4px 12px;
    border-radius: 20px; border: 1px solid var(--line); color: var(--muted);
    text-transform: uppercase; white-space: nowrap;
}
#role-chip.operator { color: #1a1000; background: var(--amber); border-color: var(--amber); }
#role-chip.expert { color: var(--cyan); border-color: #1c4c66; }
#strike-lights { display: flex; gap: 6px; }
.strike-led {
    width: 16px; height: 16px; border-radius: 50%; background: #2a1a10;
    border: 1px solid #4a2a1a;
}
.strike-led.on { background: var(--hot); box-shadow: 0 0 12px var(--hot); animation: pulse 1s infinite; }
#timer-big {
    margin-left: auto; font-family: 'Consolas', monospace; font-size: 1.7rem;
    font-weight: 700; color: var(--green); font-variant-numeric: tabular-nums;
    text-shadow: 0 0 12px rgba(70, 224, 90, .5);
}
#timer-big.warn { color: var(--amber); text-shadow: 0 0 12px rgba(255, 176, 32, .6); }
#timer-big.danger { color: var(--hot); text-shadow: 0 0 14px rgba(255, 48, 48, .7); animation: pulse .5s infinite; }
.hud-icon-btn {
    background: var(--panel); border: 1px solid var(--line); color: var(--text);
    width: 36px; height: 36px; border-radius: 10px; font-size: 1rem; cursor: pointer;
}

#roster-strip { display: flex; flex-wrap: wrap; gap: 6px; padding: 2px 4px 10px; }
.crew-pip {
    display: flex; align-items: center; gap: 6px; font-size: .72rem;
    background: rgba(26, 20, 11, .85); border: 1px solid #2c2212; border-radius: 20px;
    padding: 3px 10px 3px 5px;
}
.crew-pip .dot { width: 10px; height: 10px; border-radius: 50%; }
.crew-pip.op { border-color: #6a5210; color: var(--amber); }
.crew-pip.away { opacity: .45; }

#stage { flex: 1; padding-bottom: 120px; }
.center-note { color: var(--muted); text-align: center; padding: 40px 20px; }

/* frame data plate (operator) */
.frame-plate {
    display: flex; gap: 16px; align-items: center; flex-wrap: wrap;
    background: #241d10; border: 2px solid #4a3a18; border-radius: 12px;
    padding: 10px 16px; margin-bottom: 12px;
    background-image: repeating-linear-gradient(45deg, transparent 0 18px, rgba(255,176,32,.05) 18px 36px);
}
.serial-tag { font-family: monospace; font-size: 1.3rem; letter-spacing: .18em; color: #ffe9bd; }
.serial-label, .batt-label { font-size: .62rem; color: var(--muted); text-transform: uppercase; letter-spacing: .12em; display: block; }
.batteries { display: flex; gap: 4px; align-items: center; }
.batt { width: 14px; height: 22px; background: var(--green); border-radius: 3px; border: 1px solid #2a6a2a; }
.frame-note { margin-left: auto; font-size: .74rem; color: var(--muted); max-width: 210px; }

/* module grid */
.module-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 12px; }
.module {
    background: var(--panel); border: 2px solid var(--line); border-radius: 14px;
    padding: 14px; position: relative; min-height: 170px;
}
.module.disarmed { border-color: #2a6a2a; opacity: .75; }
.module-title { font-size: .8rem; font-weight: 800; letter-spacing: .08em; color: var(--muted); text-transform: uppercase; margin-bottom: 10px; }
.module-led {
    position: absolute; top: 12px; right: 12px; width: 13px; height: 13px;
    border-radius: 50%; background: #3a1a10; border: 1px solid #5a2a1a;
}
.module.disarmed .module-led { background: var(--green); box-shadow: 0 0 10px var(--green); }
.disarmed-stamp {
    position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
    font-weight: 900; letter-spacing: .2em; color: var(--green); font-size: 1.1rem;
    text-shadow: 0 0 12px rgba(70, 224, 90, .6); transform: rotate(-8deg);
}

/* wires */
.wire-row { display: flex; align-items: center; gap: 10px; margin: 9px 0; }
.wire-num { font-size: .7rem; color: var(--muted); width: 14px; }
.wire {
    flex: 1; height: 12px; border-radius: 6px; cursor: pointer; position: relative;
    box-shadow: 0 2px 5px rgba(0,0,0,.5);
}
.wire:hover:not(.cut) { transform: scaleY(1.3); }
.wire.cut { opacity: .9; cursor: default; background: transparent !important; }
.wire.cut::before, .wire.cut::after {
    content: ''; position: absolute; top: 0; height: 100%; width: 42%; border-radius: 6px;
    background: var(--wire-color);
}
.wire.cut::before { left: 0; transform: rotate(6deg); }
.wire.cut::after { right: 0; transform: rotate(-6deg); }

/* keypad */
.glyph-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.glyph-btn {
    height: 56px; font-size: 1.7rem; background: #14100a; color: #ffe9bd;
    border: 1px solid var(--line); border-radius: 10px; cursor: pointer; font-family: serif;
}
.glyph-btn.lit { border-color: var(--green); color: var(--green); box-shadow: 0 0 10px rgba(70,224,90,.4); }
.glyph-btn:active { background: #241b0e; }

/* big button */
.bigbtn-wrap { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.bigbtn {
    width: 110px; height: 110px; border-radius: 50%; border: 6px solid #0a0805;
    font-weight: 900; letter-spacing: .06em; cursor: pointer; color: #fff;
    text-shadow: 0 1px 3px rgba(0,0,0,.7); font-size: .95rem;
    box-shadow: 0 6px 0 #000, inset 0 -6px 12px rgba(0,0,0,.4);
    touch-action: none; user-select: none; -webkit-user-select: none; font-family: inherit;
}
.bigbtn:active { transform: translateY(4px); box-shadow: 0 2px 0 #000, inset 0 -4px 10px rgba(0,0,0,.4); }
.strip {
    width: 80%; height: 14px; border-radius: 7px; background: #1a140b;
    border: 1px solid var(--line);
}
.strip.lit { box-shadow: 0 0 16px currentColor; border-color: currentColor; }

/* simon */
.simon-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.simon-pad { height: 54px; border-radius: 10px; cursor: pointer; opacity: .45; border: 1px solid #000; }
.simon-pad.lit { opacity: 1; box-shadow: 0 0 18px currentColor; }
.simon-play { margin-top: 8px; width: 100%; }
.simon-progress { text-align: center; font-size: .75rem; color: var(--muted); margin-top: 6px; }

/* memory */
.mem-display {
    font-family: monospace; font-size: 2.4rem; text-align: center; color: var(--green);
    background: #0c1408; border: 1px solid #2a4a1a; border-radius: 10px; padding: 4px; margin-bottom: 10px;
}
.mem-btns { display: flex; gap: 6px; }
.mem-btn {
    flex: 1; height: 48px; font-size: 1.2rem; font-weight: 800; background: #14100a;
    color: var(--text); border: 1px solid var(--line); border-radius: 10px; cursor: pointer;
    font-family: inherit;
}
.mem-btn:active { background: #241b0e; }
.mem-stages { display: flex; gap: 5px; justify-content: center; margin-top: 9px; }
.mem-stage { width: 11px; height: 11px; border-radius: 50%; background: #241b0e; border: 1px solid var(--line); }
.mem-stage.done { background: var(--green); }

/* frequency */
.freq-code {
    font-family: monospace; font-size: 1.4rem; text-align: center; letter-spacing: .12em;
    color: var(--amber); background: #14100a; border: 1px solid var(--line);
    border-radius: 10px; padding: 6px; margin-bottom: 10px;
}
.freq-value { text-align: center; font-family: monospace; font-size: 1.5rem; color: var(--cyan); margin-bottom: 4px; }
.freq-slider { width: 100%; margin: 6px 0 10px; accent-color: var(--amber); }
.freq-tune { width: 100%; }

/* expert manual */
.manual-intro { margin-bottom: 12px; }
.manual-holders { font-size: .8rem; color: var(--muted); margin-top: 8px; line-height: 1.6; }
.manual-section {
    background: #f2ead6; color: #241a08; border-radius: 12px; padding: 18px;
    margin-bottom: 14px; box-shadow: 0 4px 14px rgba(0,0,0,.4);
    font-family: Georgia, 'Times New Roman', serif;
}
.manual-section h3 {
    font-size: 1.15rem; border-bottom: 2px solid #8a7a50; padding-bottom: 6px; margin-bottom: 10px;
    letter-spacing: .04em;
}
.manual-section h4 { margin: 12px 0 6px; font-size: .95rem; color: #5a4a20; }
.manual-section p { font-size: .92rem; line-height: 1.55; margin: 8px 0; }
.manual-section ul { margin: 6px 0 6px 22px; font-size: .92rem; line-height: 1.6; }
.manual-section table { width: 100%; border-collapse: collapse; margin: 8px 0; font-size: .88rem; }
.manual-section th, .manual-section td { border: 1px solid #b0a070; padding: 5px 8px; text-align: left; }
.manual-section th { background: #e0d4b4; }
.manual-cols { display: flex; gap: 14px; justify-content: center; margin: 10px 0; }
.manual-col { border: 1px solid #b0a070; border-radius: 8px; padding: 8px 14px; text-align: center; }
.manual-col .g { font-size: 1.4rem; line-height: 1.7; font-family: serif; }
.manual-col-label { font-size: .7rem; color: #7a6a40; text-transform: uppercase; }

/* chat dock */
#chat-dock {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
    background: linear-gradient(0deg, rgba(13, 10, 5, .97) 70%, transparent);
    padding: 6px 12px calc(8px + env(safe-area-inset-bottom));
    max-width: 900px; margin: 0 auto;
}
#chat-log {
    max-height: 96px; overflow-y: auto; display: flex; flex-direction: column;
    gap: 2px; font-size: .8rem; padding-bottom: 4px;
}
.chat-line b { margin-right: 4px; }
.chat-line.sys { color: var(--amber); font-style: italic; }
#chat-bar { display: flex; gap: 6px; }
#chat-bar input { margin: 0; flex: 1; padding: 8px 12px; }

/* result overlay */
.overlay {
    position: fixed; inset: 0; z-index: 40; display: flex; align-items: center;
    justify-content: center; background: rgba(6, 4, 2, .82); padding: 14px;
}
.overlay-card {
    background: var(--panel); border: 1px solid #4a3a18; border-radius: 16px;
    width: min(520px, 100%); padding: 26px; text-align: center;
}
#result-title { font-size: 1.7rem; letter-spacing: .14em; }
#result-title.win { color: var(--green); text-shadow: 0 0 20px rgba(70, 224, 90, .5); }
#result-title.lose { color: var(--hot); text-shadow: 0 0 20px rgba(255, 48, 48, .6); }
.result-time { font-family: monospace; font-size: 2.2rem; color: var(--cyan); margin: 12px 0; }
.results-actions { display: flex; gap: 10px; justify-content: center; margin-top: 14px; flex-wrap: wrap; align-items: center; }

@media (max-width: 700px) {
    #timer-big { font-size: 1.35rem; }
    .module-grid { grid-template-columns: 1fr; }
    #chat-log { max-height: 66px; }
}
