:root {
  --bg: #14170f;
  --panel: rgba(22, 26, 18, 0.92);
  --line: rgba(210, 220, 190, 0.14);
  --text: #e4e6dc;
  --muted: #9da38f;
  --accent: #c9a24a;
  --accent-2: #e0b85a;
  --danger: #c4493a;
  --hp: #6fae4c;
  --armor: #5b8fc4;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--bg); color: var(--text);
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; -webkit-user-select: none; user-select: none;
  touch-action: none; overscroll-behavior: none; -webkit-tap-highlight-color: transparent; }
canvas#c { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
body[data-screen="game"] canvas#c { cursor: none; }
body:not([data-screen="game"]) { background: radial-gradient(ellipse at 50% 30%, #2a3120 0%, #14170f 70%); }
body:not([data-screen="game"]) canvas#c { opacity: 0; }
[hidden] { display: none !important; }

/* ---------- panels ---------- */
.screen { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; padding: 16px; overflow: auto; z-index: 5; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 26px 28px; width: min(560px, 100%);
  box-shadow: 0 20px 60px rgba(0,0,0,.5); max-height: calc(100% - 8px); overflow: auto; -webkit-user-select: text; user-select: text; }
.panel.narrow { width: min(400px, 100%); }
.panel.wide { width: min(640px, 100%); }
h1 { margin: 0 0 4px; font-size: 34px; letter-spacing: .14em; font-weight: 800; color: var(--accent-2); }
h2 { margin: 0 0 14px; }
.sub { color: var(--muted); margin: 0 0 18px; }
.fine { color: var(--muted); font-size: 12px; margin: 16px 0 0; }
label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 12px; }
input { display: block; width: 100%; margin-top: 4px; padding: 11px 12px; font: inherit; font-size: 16px; color: var(--text);
  background: rgba(0,0,0,.35); border: 1px solid var(--line); border-radius: 6px; outline: none; -webkit-user-select: text; user-select: text; }
input:focus { border-color: var(--accent); }
.btn { font: inherit; font-weight: 600; padding: 11px 16px; border-radius: 6px; border: 1px solid var(--line); background: rgba(255,255,255,.06);
  color: var(--text); cursor: pointer; touch-action: manipulation; }
.btn:hover { background: rgba(255,255,255,.11); }
.btn.primary { background: var(--accent); color: #1a1a10; border-color: transparent; }
.btn.primary:hover { background: var(--accent-2); }
.btn.ghost { background: transparent; }
.btn.small { padding: 7px 11px; font-size: 13px; }
.btn:disabled { opacity: .45; cursor: default; }
form .btn { width: 100%; }
.status { min-height: 1.4em; color: #e3876f; margin: 10px 0 0; font-size: 14px; }
.menu-grid { display: grid; gap: 10px; }
.join { display: flex; gap: 8px; }
.join input { margin: 0; text-transform: uppercase; letter-spacing: .2em; }
.join .btn { width: auto; }
.howto { margin-top: 18px; color: var(--muted); font-size: 14px; }
.howto summary { cursor: pointer; color: var(--text); }
.howto ul { padding-left: 18px; }
body.touch .howto .desk, body:not(.touch) .howto .mob { display: none; }

.lobby-head { display: flex; justify-content: space-between; align-items: flex-end; margin-bottom: 16px; gap: 12px; }
.label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .1em; }
.code { font-size: 30px; font-weight: 800; letter-spacing: .25em; color: var(--accent-2); }
.players { list-style: none; padding: 0; margin: 0 0 8px; display: grid; gap: 6px; }
.players li { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 6px; background: rgba(255,255,255,.04); }
.players .dot { width: 12px; height: 12px; border-radius: 50%; flex: none; }
.players .nm { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.players .tag { font-size: 11px; color: var(--muted); border: 1px solid var(--line); padding: 1px 6px; border-radius: 4px; }
.players .empty { color: var(--muted); font-style: italic; }
.row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.row .btn { flex: 1; }
.results { width: 100%; border-collapse: collapse; margin-bottom: 12px; }
.results th, .results td { text-align: left; padding: 7px 8px; border-bottom: 1px solid var(--line); }
.results th { color: var(--muted); font-weight: 500; font-size: 13px; }
.results tr.me td { color: var(--accent-2); font-weight: 700; }

/* ---------- chat ---------- */
#chat { position: fixed; z-index: 8; display: none; }
body[data-screen="lobby"] #chat, body[data-screen="end"] #chat { display: block; right: 16px; bottom: 16px; width: min(320px, calc(100% - 32px)); }
body[data-screen="game"] #chat { display: block; left: 12px; bottom: 112px; width: min(340px, 45vw); pointer-events: none; }
#chat-log { list-style: none; margin: 0 0 6px; padding: 0; max-height: 160px; overflow: hidden; display: flex; flex-direction: column; justify-content: flex-end; font-size: 13px; }
body[data-screen="lobby"] #chat-log, body[data-screen="end"] #chat-log { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; height: 180px; max-height: none; overflow-y: auto; justify-content: flex-start; }
#chat-log li { padding: 1px 0; word-wrap: break-word; text-shadow: 0 1px 2px #000; }
#chat-log li.old { opacity: 0; transition: opacity 1s; }
body[data-screen="lobby"] #chat-log li.old { opacity: 1; }
#chat-log .who { font-weight: 700; margin-right: 6px; }
#chat-log .sys { color: var(--muted); font-style: italic; }
#chat input { margin: 0; padding: 7px 10px; font-size: 14px; pointer-events: auto; }
body[data-screen="game"] #chat input { opacity: 0; }
body[data-screen="game"] #chat input:focus { opacity: 1; }
body.touch[data-screen="game"] #chat { bottom: auto; top: 54px; left: 12px; }
body.touch[data-screen="game"] #chat-log { max-height: 90px; font-size: 12px; }

/* ---------- HUD ---------- */
#hud { position: fixed; inset: 0; z-index: 4; pointer-events: none; font-weight: 600; }
#hud-tl { position: absolute; left: 14px; top: 12px; text-shadow: 0 1px 3px #000; }
#lives { font-size: 20px; letter-spacing: 3px; color: #d2483a; }
#lives .lost { color: rgba(255,255,255,.2); }
#stats { font-size: 14px; }
#zone-info { font-size: 13px; color: #a9c7e8; margin-top: 2px; }
#zone-info.warn { color: #ff8f6a; }
#minimap { position: absolute; right: 12px; top: 12px; width: 180px; height: 180px; border: 1px solid rgba(255,255,255,.25); border-radius: 6px; background: #000; }
#feed { position: absolute; right: 12px; top: 200px; list-style: none; margin: 0; padding: 0; font-size: 13px; text-align: right; }
#feed li { background: rgba(0,0,0,.45); padding: 3px 8px; border-radius: 4px; margin-bottom: 3px; }
#feed .c { color: var(--muted); margin: 0 5px; font-weight: 400; }
#bottom { position: absolute; left: 50%; bottom: 14px; transform: translateX(-50%); display: flex; flex-direction: column; align-items: center; gap: 6px; width: min(460px, 90vw); }
#bars { width: 100%; display: grid; gap: 4px; }
.bar { position: relative; height: 16px; background: rgba(0,0,0,.55); border-radius: 3px; overflow: hidden; border: 1px solid rgba(255,255,255,.12); }
.bar.armor { height: 9px; }
.bar > div { position: absolute; inset: 0 auto 0 0; width: 0; transition: width .12s; }
.bar.hp > div { background: linear-gradient(#7fbd5a, #4d8a33); }
.bar.hp.low > div { background: linear-gradient(#d4553f, #a33224); }
.bar.armor > div { background: linear-gradient(#78a9d9, #3f6f9e); }
.bar span { position: absolute; right: 6px; top: 50%; transform: translateY(-50%); font-size: 11px; text-shadow: 0 1px 2px #000; }
.bar.armor span { display: none; }
#slots { display: flex; gap: 6px; width: 100%; }
.slot { flex: 1; display: flex; align-items: center; gap: 8px; padding: 6px 10px; background: rgba(0,0,0,.5); border: 1px solid rgba(255,255,255,.12); border-radius: 5px; font-size: 13px; min-width: 0; }
.slot.on { border-color: var(--accent); background: rgba(60,50,20,.6); }
.slot .k { color: var(--muted); font-size: 11px; }
.slot .wn { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.slot .am { font-variant-numeric: tabular-nums; }
.slot .am.empty { color: #e3876f; }
#inv { display: flex; gap: 14px; font-size: 14px; text-shadow: 0 1px 2px #000; }
#inv span { display: flex; align-items: center; gap: 5px; }
.ico { display: inline-block; width: 14px; height: 14px; border-radius: 3px; }
.ico.gren { background: #4f5a33; border-radius: 50% 50% 45% 45%; box-shadow: inset -2px -2px 0 rgba(0,0,0,.35); }
.ico.food { background: linear-gradient(#c8c8c0 0 25%, #b5452f 25% 75%, #c8c8c0 75%); border-radius: 3px; }
.ico.med { background: #eee; position: relative; }
.ico.med::before, .ico.med::after { content: ""; position: absolute; background: #c4372c; }
.ico.med::before { left: 5px; top: 2px; width: 4px; height: 10px; }
.ico.med::after { left: 2px; top: 5px; width: 10px; height: 4px; }
#actbar { position: relative; width: 180px; height: 14px; background: rgba(0,0,0,.6); border-radius: 7px; overflow: hidden; }
#actfill { position: absolute; inset: 0 auto 0 0; background: var(--accent); }
#acttext { position: absolute; inset: 0; text-align: center; font-size: 10px; line-height: 14px; color: #fff; text-shadow: 0 1px 2px #000; }
#prompt { position: absolute; left: 50%; bottom: 150px; transform: translateX(-50%); background: rgba(0,0,0,.6); padding: 6px 12px; border-radius: 5px; font-size: 14px; }
#center-msg { position: absolute; left: 50%; top: 32%; transform: translate(-50%, -50%); text-align: center; font-size: 26px; text-shadow: 0 2px 6px #000; }
#center-msg small { display: block; font-size: 15px; color: var(--muted); }
#vignette { position: absolute; inset: 0; box-shadow: inset 0 0 140px rgba(190, 20, 10, .75); opacity: 0; transition: opacity .25s; }
#toast { position: fixed; left: 50%; top: 18px; transform: translateX(-50%); z-index: 20; background: rgba(20,22,16,.95); border: 1px solid var(--line); padding: 9px 16px; border-radius: 6px; font-size: 14px; max-width: calc(100% - 32px); }
#rotate { display: none; }

/* ---------- touch ---------- */
#touch-ui { display: none; }
body.touch #touch-ui { display: block; }
body.touch #minimap { width: 120px; height: 120px; }
body.touch #feed { top: 138px; font-size: 11px; }
body.touch #bottom { bottom: 8px; width: min(340px, 46vw); gap: 3px; }
body.touch .slot { padding: 3px 7px; font-size: 11px; }
body.touch #inv { font-size: 12px; }
body.touch #hud-tl { top: 8px; left: 12px; }
body.touch #lives { font-size: 16px; }
.stick-zone { position: absolute; left: 0; top: 30%; bottom: 0; width: 45%; pointer-events: auto; }
.stick { position: absolute; width: 120px; height: 120px; margin: -60px 0 0 -60px; border-radius: 50%; background: rgba(255,255,255,.07); border: 2px solid rgba(255,255,255,.2); pointer-events: none; opacity: 0; }
.stick.on, .stick.fixed { opacity: 1; }
.stick .nub { position: absolute; left: 50%; top: 50%; width: 50px; height: 50px; margin: -25px; border-radius: 50%; background: rgba(255,255,255,.28); }
.stick.fixed { right: calc(22px + env(safe-area-inset-right)); bottom: 22px; left: auto; top: auto; margin: 0; pointer-events: auto; }
.stick.fixed.firing { border-color: rgba(230,120,80,.7); }
.tbtn { position: absolute; pointer-events: auto; width: 50px; height: 50px; border-radius: 50%; border: 2px solid rgba(255,255,255,.25); background: rgba(0,0,0,.4);
  color: #fff; font: 700 18px system-ui; touch-action: manipulation; padding: 0; }
.tbtn:active { background: rgba(255,255,255,.2); }
#tb-reload { right: calc(160px + env(safe-area-inset-right)); bottom: 20px; }
#tb-swap { right: calc(160px + env(safe-area-inset-right)); bottom: 80px; }
#tb-gren { right: calc(112px + env(safe-area-inset-right)); bottom: 150px; }
#tb-heal { right: calc(52px + env(safe-area-inset-right)); bottom: 158px; }
#tb-pick { right: calc(220px + env(safe-area-inset-right)); bottom: 50px; width: 96px; border-radius: 25px; font-size: 13px; }
#tb-chat { left: calc(12px + env(safe-area-inset-left)); top: auto; bottom: 12px; width: 40px; height: 40px; font-size: 16px; }
@media (orientation: portrait) {
  body.touch[data-screen="game"] #rotate { display: flex; position: fixed; inset: 0; z-index: 30; background: var(--bg); align-items: center; justify-content: center; font-size: 18px; padding: 24px; text-align: center; }
}
@media (max-width: 640px) {
  .panel { padding: 20px 18px; }
  h1 { font-size: 26px; }
  body[data-screen="lobby"] .screen, body[data-screen="end"] .screen { padding-bottom: 250px; align-items: flex-start; }
}

/* ---------- v2: username row, rules, settings, inventory ---------- */
.name-row { display: flex; gap: 8px; margin-top: 4px; }
.name-row input { margin: 0; }
.name-row .btn { width: auto; padding: 0 12px; font-size: 18px; }
select { font: inherit; color: var(--text); background: rgba(0,0,0,.35); border: 1px solid var(--line); border-radius: 6px; padding: 8px 10px; width: 100%; margin-top: 4px; }
select:disabled, input:disabled { opacity: .6; }
.rules { display: grid; grid-template-columns: 1fr 1fr auto; gap: 10px; align-items: end; margin-bottom: 4px; }
.rules label { margin: 0; }
label.chk { display: flex; align-items: center; gap: 8px; color: var(--text); font-size: 14px; padding-bottom: 9px; }
label.chk input { width: 18px; height: 18px; margin: 0; flex: none; }
#rules-desc { margin: 4px 0 14px; }
.players .team { font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 4px; color: #111; border: 0; cursor: pointer; font-family: inherit; }
.players .team.t0 { background: #7fb0ea; }
.players .team.t1 { background: #e89f55; }
.players .team:disabled { cursor: default; opacity: 1; }
@media (max-width: 560px) { .rules { grid-template-columns: 1fr 1fr; } }

#settings { position: fixed; inset: 0; z-index: 25; display: flex; align-items: center; justify-content: center; background: rgba(0,0,0,.55); padding: 16px; }
#settings input[type=range] { padding: 0; height: 28px; background: transparent; border: 0; accent-color: var(--accent); }
#settings label b { float: right; color: var(--text); }
body.touch .desk-only, body:not(.touch) .touch-only { display: none !important; }

#hud-btns { position: absolute; left: 14px; top: 92px; display: flex; gap: 6px; pointer-events: auto; }
body.touch #hud-btns { top: 8px; left: auto; right: calc(140px + env(safe-area-inset-right)); }
.hbtn { width: 34px; height: 34px; border-radius: 6px; border: 1px solid rgba(255,255,255,.2); background: rgba(0,0,0,.45); color: #fff; font-size: 16px; cursor: pointer; padding: 0; touch-action: manipulation; }
.hbtn:hover { background: rgba(255,255,255,.12); }
#lock-hint { position: absolute; left: 50%; top: 14px; transform: translateX(-50%); background: rgba(0,0,0,.6); padding: 6px 14px; border-radius: 5px; font-size: 13px; font-weight: 500; }
#inv-panel { position: absolute; left: 14px; top: 134px; width: 300px; max-height: calc(100% - 260px); overflow: auto; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; pointer-events: auto; font-weight: 500; z-index: 6; }
body.touch #inv-panel { top: 50px; left: 50%; transform: translateX(-50%); max-height: calc(100% - 70px); }
.inv-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 6px; }
.inv-head .fine { margin: 0; }
.inv-row { display: flex; align-items: center; gap: 8px; padding: 5px 0; border-bottom: 1px solid var(--line); font-size: 13px; }
.inv-row:last-child { border-bottom: 0; }
.inv-row .nm { flex: 1; }
.inv-row .ct { color: var(--muted); font-variant-numeric: tabular-nums; }
.inv-row .btn { padding: 4px 9px; font-size: 12px; }
.inv-empty { color: var(--muted); font-size: 13px; padding: 4px 0; }

.slot.hands { flex: 0 0 auto; }
body.touch .slot.hands .wn { display: none; }
body.touch .slot.hands::after { content: "✊"; }

/* ---------- v3: smoke, key hints ---------- */
.ico.smoke { background: linear-gradient(#e4e4de 0 30%, #7b7f76 30%); border-radius: 3px; }
#inv .kh { color: var(--muted); font-size: 10px; font-weight: 500; }
body.touch #inv .kh { display: none; }
#smoke-haze { position: absolute; inset: 0; background: radial-gradient(ellipse at center, rgba(205,205,198,0.35), rgba(170,170,165,0.85)); opacity: 0; transition: opacity .5s; }
#tb-smoke { right: calc(170px + env(safe-area-inset-right)); bottom: 140px; }

/* ---------- round 4 ---------- */
#inv span.on { color: var(--accent-2); }
#inv span.on .ico { box-shadow: 0 0 0 2px var(--accent-2); }
#mask-info { font-size: 13px; color: #b9e0a8; margin-top: 2px; }
#warn { position: absolute; left: 50%; top: 64px; transform: translateX(-50%); background: rgba(150,30,20,.85); color: #fff; padding: 8px 16px; border-radius: 6px; font-size: 15px; animation: warnpulse 1s infinite; }
@keyframes warnpulse { 50% { background: rgba(200,50,30,.95); } }

/* ---------- fullscreen / click to play ---------- */
#lock-cta { position: absolute; left: 50%; top: 56%; transform: translate(-50%, -50%); background: rgba(10,12,8,.78); border: 1px solid rgba(255,255,255,.18); border-radius: 8px; padding: 12px 18px; text-align: center; max-width: min(460px, 90vw); }
#lock-cta b { display: block; font-size: 18px; color: var(--accent-2); margin-bottom: 2px; }
#lock-cta span { font-size: 13px; font-weight: 500; color: var(--text); }
body.touch #lock-cta { display: none; }
