:root {
  --bg: #0b0f14;
  --panel: #141b24;
  --line: #2a3644;
  --text: #d8e1ea;
  --muted: #7d8b99;
  --accent: #3fb7ff;
  --escaper: #ff9a3c;
  --guard: #4a8cff;
  --danger: #ff4d4d;
  --ok: #3ddc84;
  --warn: #ffd23f;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text);
  font: 14px/1.4 system-ui, -apple-system, Segoe UI, sans-serif; overflow: hidden; }
[hidden] { display: none !important; }
button { background: var(--accent); color: #001018; border: 0; padding: 8px 14px; border-radius: 6px;
  font-weight: 600; cursor: pointer; }
button:disabled { opacity: .4; cursor: default; }
button.small { padding: 3px 8px; font-size: 12px; }
input, select { background: #0c1218; color: var(--text); border: 1px solid var(--line); border-radius: 5px;
  padding: 6px 8px; font: inherit; width: 100%; }
label { display: block; margin: 8px 0; color: var(--muted); }
label input, label select { margin-top: 3px; }
fieldset { border: 1px solid var(--line); border-radius: 8px; margin: 12px 0; padding: 8px 12px; }
legend { color: var(--muted); padding: 0 4px; }
kbd { background: #222c38; border: 1px solid var(--line); border-radius: 3px; padding: 0 4px; font-size: 12px; }

.screen { position: fixed; inset: 0; }
.overlay { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center;
  background: rgba(0,0,0,.55); text-align: center; z-index: 20; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 20px 24px; }

/* Lobby */
#lobby { overflow: auto; display: flex; justify-content: center; align-items: flex-start; padding: 24px 16px; }
.lobby-panel { width: 100%; max-width: 520px; }
h1 { margin: 0 0 4px; letter-spacing: .15em; }
.tagline { color: var(--muted); margin-top: 0; }
.roles label { display: flex; gap: 8px; align-items: center; color: var(--text); }
.roles input { width: auto; margin: 0; }
.roles small { color: var(--muted); }
.room-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.role-switch { display: flex; gap: 6px; }
.role-switch button { flex: 1; background: #222c38; color: var(--text); }
.role-switch button.active { background: var(--accent); color: #001018; }
#player-list { list-style: none; padding: 0; margin: 12px 0; }
#player-list li { display: flex; justify-content: space-between; padding: 6px 8px; border-bottom: 1px solid var(--line); }
#player-list .role-escaper { color: var(--escaper); }
#player-list .role-guard { color: var(--guard); }
#player-list .role-operator { color: var(--ok); }
#start-btn { width: 100%; }
.msg { color: var(--warn); min-height: 1.4em; }
.help { margin-top: 16px; color: var(--muted); }
.help li { margin: 6px 0; }

/* 3D game */
#viewport, #viewport canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
#crosshair { position: absolute; left: 50%; top: 50%; width: 6px; height: 6px; margin: -3px 0 0 -3px;
  border-radius: 50%; background: rgba(255,255,255,.8); pointer-events: none; }
#hud { position: absolute; inset: 0; pointer-events: none; }
#hud-top { position: absolute; top: 10px; left: 50%; transform: translateX(-50%); display: flex; gap: 18px;
  background: rgba(0,0,0,.5); padding: 6px 14px; border-radius: 8px; font-weight: 600; white-space: nowrap; }
#hud-room { position: absolute; top: 50px; left: 50%; transform: translateX(-50%); color: var(--muted); }
#hud-hint { position: absolute; top: 60%; left: 50%; transform: translateX(-50%); background: rgba(0,0,0,.5);
  padding: 4px 10px; border-radius: 6px; }
#hud-hint:empty { display: none; }
#hud-budget { position: absolute; top: 10px; right: 10px; width: 200px; background: rgba(0,0,0,.5);
  padding: 6px 10px; border-radius: 8px; font-size: 12px; }
.bar { height: 8px; background: #263241; border-radius: 4px; overflow: hidden; margin: 4px 0; }
.bar .fill { height: 100%; background: var(--ok); width: 0; transition: width .1s linear; }
#progress { position: absolute; top: 65%; left: 50%; transform: translateX(-50%); width: 260px; text-align: center; }
#progress .fill { background: var(--warn); }
#minimap { position: absolute; left: 10px; bottom: 10px; background: rgba(0,0,0,.55); border-radius: 8px; }
#click-to-play small { color: var(--muted); }
#click-to-play > div, #status-overlay > div { background: rgba(10,15,20,.85); padding: 18px 26px; border-radius: 10px;
  font-size: 20px; }
#status-overlay { background: transparent; pointer-events: none; align-items: flex-start; padding-top: 18vh; }

/* Console */
#console { display: flex; background: #060a0e; z-index: 30; }
#console.overlay-mode { background: rgba(4,8,12,.94); }
.console-main { flex: 1; position: relative; min-width: 0; }
#console-map { position: absolute; inset: 0; width: 100%; height: 100%; cursor: crosshair; }
.console-side { width: 300px; border-left: 1px solid var(--line); padding: 12px; overflow-y: auto; background: var(--panel); }
.console-side h2 { margin: 0 0 12px; font-size: 15px; letter-spacing: .12em; display: flex; justify-content: space-between; }
.stat { display: flex; justify-content: space-between; align-items: center; margin: 8px 0; flex-wrap: wrap; }
.stat.budget { display: block; }
.stat span { color: var(--muted); }
#c-reset { width: 100%; background: #3a2a2a; color: var(--text); margin: 8px 0; }
.legend { font-size: 12px; color: var(--muted); margin: 10px 0; }
.legend div { margin: 3px 0; }
.sw { display: inline-block; width: 10px; height: 10px; border-radius: 2px; vertical-align: middle; margin: 0 2px 0 6px; }
.sw.door { background: var(--ok); } .sw.locked { background: var(--danger); }
.sw.sealed { background: #8a8f96; } .sw.sensor { border: 2px solid var(--warn); }
.console-side h3 { font-size: 13px; color: var(--muted); margin: 14px 0 6px; }
#alert-log { list-style: none; padding: 0; margin: 0; font-size: 12px; }
#alert-log li { padding: 5px 6px; border-left: 3px solid var(--warn); margin-bottom: 4px; background: #1b222c; }
#alert-log li.tamper, #alert-log li.forced { border-color: var(--danger); }
#alert-log li .t { color: var(--muted); margin-right: 6px; }

#toasts { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); z-index: 50; display: flex;
  flex-direction: column; align-items: center; gap: 6px; pointer-events: none; }
.toast { background: rgba(20,27,36,.95); border: 1px solid var(--line); padding: 6px 12px; border-radius: 6px; }
.toast.error { border-color: var(--danger); }
.toast.alert { border-color: var(--warn); }

#end { z-index: 60; }
#end .panel { min-width: 300px; }

@media (max-width: 720px) {
  #console { flex-direction: column; }
  .console-main { min-height: 55vh; }
  .console-side { width: auto; border-left: 0; border-top: 1px solid var(--line); }
}
