:root {
  --bg: #07090c;
  --glass: rgba(14, 16, 18, 0.72);
  --glass-strong: rgba(14, 15, 17, 0.92);
  --panel2: rgba(40, 40, 38, 0.7);
  --line: rgba(200, 180, 140, 0.18);
  --text: #e8e2d6;
  --muted: #9a9284;
  --accent: #e0a43a;
  --accent-dim: #7a5a24;
  --good: #7cc46a;
  --bad: #e0503c;
  --warn: #e8a040;
  --blue: #6aa8d8;
  --radius: 10px;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; }
body { background: var(--bg); color: var(--text); font-family: 'Space Grotesk', system-ui, sans-serif; font-size: 14px; user-select: none; -webkit-tap-highlight-color: transparent; }
.mono { font-family: 'JetBrains Mono', ui-monospace, monospace; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.tiny { font-size: 11px; }
.hidden { display: none !important; }
h2 { margin: 0 0 12px; font-family: 'Black Ops One', 'Space Grotesk', sans-serif; font-weight: 400; letter-spacing: 0.04em; font-size: 24px; }
h3 { margin: 16px 0 8px; font-size: 14px; color: var(--accent); text-transform: uppercase; letter-spacing: 0.08em; }
button { font-family: inherit; color: inherit; cursor: pointer; }
kbd { font-family: 'JetBrains Mono', monospace; font-size: 11px; background: rgba(255, 255, 255, 0.08); border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 4px; padding: 0 5px; margin: 0 1px; white-space: nowrap; }
#viewport { position: fixed; inset: 0; }
#viewport canvas { display: block; }

/* ---------------------------------------------------------------- HUD */
#hud { position: fixed; inset: 0; pointer-events: none; z-index: 10; }
.chip, .loot, .buildbar, .toast, .prompt, .ammo, .vitals, .hotbar .slot, .minimap, .compass { backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); }
.hud-tl { position: absolute; top: 12px; left: 12px; display: flex; flex-direction: column; align-items: flex-start; gap: 6px; }
.chip { background: var(--glass); border: 1px solid var(--line); border-radius: 999px; padding: 4px 12px; font-size: 12.5px; white-space: nowrap; }
.chip.safe { border-color: rgba(124, 196, 106, 0.7); color: #b8f0a6; }
.chip.exposed { border-color: rgba(224, 164, 58, 0.5); color: #f0d090; }
.chip.danger { border-color: rgba(224, 80, 60, 0.8); color: #ffb0a0; animation: pulse 1.4s infinite; }
.chip.goal { border-color: rgba(224, 164, 58, 0.35); color: #e8d8b0; max-width: 360px; white-space: normal; border-radius: 10px; font-size: 12px; }
.chip.goal:empty { display: none; }
@keyframes pulse { 50% { box-shadow: 0 0 14px rgba(224, 80, 60, 0.6); } }

.compass { position: absolute; top: 12px; left: 50%; transform: translateX(-50%); width: min(420px, 48vw); height: 26px; overflow: hidden; background: var(--glass); border: 1px solid var(--line); border-radius: 6px; -webkit-mask-image: linear-gradient(90deg, transparent, #000 18%, #000 82%, transparent); mask-image: linear-gradient(90deg, transparent, #000 18%, #000 82%, transparent); }
.compass-strip { position: absolute; top: 0; left: 50%; height: 100%; white-space: nowrap; font-family: 'JetBrains Mono', monospace; font-size: 11px; line-height: 26px; }
.compass-strip span { position: absolute; transform: translateX(-50%); color: var(--muted); }
.compass-strip span.c { color: var(--accent); font-weight: 600; font-size: 13px; }
.compass-strip span.m { color: #ff9a6a; }
.compass-tick { position: absolute; left: 50%; top: 0; width: 2px; height: 7px; background: var(--accent); transform: translateX(-50%); }

.minimap { position: absolute; top: 12px; right: 12px; padding: 5px; background: var(--glass); border: 1px solid var(--line); border-radius: 50%; }
.minimap canvas { display: block; width: 176px; height: 176px; border-radius: 50%; }
.mm-n { position: absolute; top: 2px; left: 50%; transform: translateX(-50%); font-size: 10px; font-weight: 700; color: var(--accent); }

.cross { position: absolute; left: 50%; top: 50%; width: 0; height: 0; --s: 8px; }
.cross i { position: absolute; background: rgba(240, 235, 225, 0.9); box-shadow: 0 0 2px #000; }
.cross i:nth-child(1), .cross i:nth-child(2) { width: 2px; height: 7px; left: -1px; }
.cross i:nth-child(3), .cross i:nth-child(4) { height: 2px; width: 7px; top: -1px; }
.cross i:nth-child(1) { top: calc(-7px - var(--s)); }
.cross i:nth-child(2) { top: var(--s); }
.cross i:nth-child(3) { left: calc(-7px - var(--s)); }
.cross i:nth-child(4) { left: var(--s); }
.cross b { position: absolute; width: 3px; height: 3px; left: -1.5px; top: -1.5px; border-radius: 50%; background: rgba(240, 235, 225, 0.9); }
.cross.melee i { display: none; }
.cross.hide { display: none; }
.hitmark { position: absolute; left: 50%; top: 50%; opacity: 0; transition: opacity 0.15s; }
.hitmark i { position: absolute; width: 2px; height: 8px; background: #fff; left: -1px; top: -4px; }
.hitmark i:nth-child(1) { transform: rotate(45deg) translateY(-10px); }
.hitmark i:nth-child(2) { transform: rotate(135deg) translateY(-10px); }
.hitmark i:nth-child(3) { transform: rotate(225deg) translateY(-10px); }
.hitmark i:nth-child(4) { transform: rotate(315deg) translateY(-10px); }
.hitmark.show { opacity: 1; transition: none; }
.hitmark.kill i { background: #ff4a3a; height: 11px; }

.prompt { position: absolute; left: 50%; top: calc(50% + 46px); transform: translateX(-50%); background: var(--glass-strong); border: 1px solid var(--line); border-radius: 8px; padding: 6px 14px; font-size: 13px; text-align: center; max-width: min(520px, 90vw); }
.prompt b { color: var(--accent); }
.prompt .hold { height: 3px; background: rgba(255, 255, 255, 0.1); border-radius: 2px; margin-top: 5px; overflow: hidden; display: none; }
.prompt.holding .hold { display: block; }
.prompt .hold div { height: 100%; width: 0; background: var(--accent); }

.vitals { position: absolute; left: 12px; bottom: 12px; background: var(--glass); border: 1px solid var(--line); border-radius: var(--radius); padding: 9px 12px; display: flex; flex-direction: column; gap: 6px; width: 230px; }
.vital { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.vital span { width: 18px; text-align: center; }
.vital .bar { flex: 1; height: 7px; background: rgba(255, 255, 255, 0.08); border-radius: 4px; overflow: hidden; }
.vital .bar i { display: block; height: 100%; width: 100%; border-radius: 4px; transition: width 0.2s; }
.vital.hp i { background: linear-gradient(90deg, #a8302a, #e0503c); }
.vital.st i { background: linear-gradient(90deg, #b88a2a, #e8c050); }
.vital.fd i { background: linear-gradient(90deg, #9a6a3a, #d89a5a); }
.vital.wt i { background: linear-gradient(90deg, #3a6a9a, #6aa8d8); }
.vital.inf i { background: linear-gradient(90deg, #4a8a2a, #9ad04a); }
.vital.low .bar { box-shadow: 0 0 0 1px rgba(224, 80, 60, 0.8); animation: pulse 1s infinite; }
.status { display: flex; flex-wrap: wrap; gap: 4px; }
.status:empty { display: none; }
.status span { font-size: 11px; padding: 1px 7px; border-radius: 999px; background: rgba(224, 80, 60, 0.18); color: #ffb0a0; border: 1px solid rgba(224, 80, 60, 0.4); }
.status span.ok { background: rgba(124, 196, 106, 0.15); color: #b8f0a6; border-color: rgba(124, 196, 106, 0.4); }

.hotbar { position: absolute; left: 50%; bottom: 12px; transform: translateX(-50%); display: flex; gap: 6px; }
.slot { width: 74px; height: 58px; border-radius: 8px; background: var(--glass); border: 1px solid var(--line); position: relative; display: flex; align-items: center; justify-content: center; }
.slot.sel { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset, 0 0 14px rgba(224, 164, 58, 0.25); }
.slot img { max-width: 64px; max-height: 40px; filter: drop-shadow(0 1px 2px #000); }
.slot .emoji { font-size: 26px; }
.slot .k { position: absolute; top: 2px; left: 5px; font-size: 10px; color: var(--muted); font-family: 'JetBrains Mono', monospace; }
.slot .n { position: absolute; bottom: 2px; right: 5px; font-size: 10.5px; font-family: 'JetBrains Mono', monospace; color: #e8dcc0; }
.slot.empty { opacity: 0.45; }
.ammo { position: absolute; right: 12px; bottom: 12px; background: var(--glass); border: 1px solid var(--line); border-radius: var(--radius); padding: 8px 14px; text-align: right; min-width: 150px; }
.ammo .wname { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; }
.ammo .mag { font-size: 26px; font-weight: 600; line-height: 1.1; }
.ammo .mag small { font-size: 14px; color: var(--muted); }
.ammo .mag.low { color: var(--bad); }

.loot { position: absolute; left: calc(50% + 70px); top: 50%; transform: translateY(-50%); width: 270px; background: var(--glass-strong); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; }
.loot h4 { margin: 0 0 6px; font-size: 13px; color: var(--accent); text-transform: uppercase; letter-spacing: 0.06em; }
.loot .li { display: flex; align-items: center; gap: 8px; padding: 3px 0; font-size: 13px; }
.loot .li kbd { min-width: 18px; text-align: center; }
.loot .li .ic { width: 22px; text-align: center; }
.loot .li .ic img { max-width: 30px; max-height: 18px; vertical-align: middle; }
.loot .li .nm { flex: 1; }
.loot .foot { margin-top: 7px; font-size: 11.5px; color: var(--muted); border-top: 1px solid var(--line); padding-top: 6px; }
.loot .empty { color: var(--muted); font-size: 12.5px; padding: 4px 0; }

.buildbar { position: absolute; left: 50%; bottom: 84px; transform: translateX(-50%); background: var(--glass-strong); border: 1px solid var(--line); border-radius: var(--radius); padding: 8px 14px; font-size: 12.5px; text-align: center; min-width: 360px; }
.buildbar .bn { font-weight: 700; font-size: 14px; }
.buildbar .why { color: #ff9a8a; }
.buildbar .ok { color: var(--good); }
.buildbar .cost span { margin: 0 4px; }
.buildbar .cost .no { color: #ff9a8a; }
.buildbar .dm { height: 3px; background: rgba(255, 255, 255, 0.1); margin-top: 5px; border-radius: 2px; overflow: hidden; }
.buildbar .dm div { height: 100%; background: var(--bad); }

#toasts { position: absolute; left: 12px; bottom: 196px; display: flex; flex-direction: column-reverse; gap: 5px; max-width: 360px; }
.toast { background: var(--glass-strong); border: 1px solid var(--line); border-left: 3px solid var(--blue); border-radius: 6px; padding: 5px 10px; font-size: 12.5px; animation: tIn 0.25s ease-out; }
.toast.good { border-left-color: var(--good); }
.toast.bad { border-left-color: var(--bad); }
.toast.muted { border-left-color: var(--muted); color: #c8c0b0; }
.toast.loot { border-left-color: var(--accent); }
.toast.big { font-size: 14px; border-left-color: var(--accent); }
.toast.out { opacity: 0; transform: translateX(-12px); transition: all 0.4s; }
@keyframes tIn { from { opacity: 0; transform: translateX(-12px); } to { opacity: 1; transform: none; } }

.scope { position: absolute; inset: 0; background: radial-gradient(circle at 50% 50%, transparent 0, transparent min(32vh, 32vw), #000 calc(min(32vh, 32vw) + 2px)); }
.scope i { position: absolute; left: 50%; top: 50%; width: min(64vh, 64vw); height: min(64vh, 64vw); transform: translate(-50%, -50%); background: linear-gradient(#000, #000) center / 1px 100% no-repeat, linear-gradient(#000, #000) center / 100% 1px no-repeat; }
.vignette { position: absolute; inset: 0; opacity: 0; background: radial-gradient(ellipse at center, transparent 45%, rgba(160, 0, 0, 0.75) 100%); }
.infect { position: absolute; inset: 0; opacity: 0; background: radial-gradient(ellipse at center, transparent 50%, rgba(60, 120, 20, 0.6) 100%); }
.fade { position: fixed; inset: 0; background: #000; opacity: 0; pointer-events: none; z-index: 40; transition: opacity 1.2s; }
.fade.on { opacity: 1; }

/* ---------------------------------------------------------------- screens */
.screen { position: fixed; inset: 0; z-index: 30; display: flex; align-items: center; justify-content: center; padding: 16px; background: rgba(5, 6, 8, 0.6); backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px); }
.title-screen { background: linear-gradient(180deg, rgba(0, 0, 0, 0.1), rgba(0, 0, 0, 0.55)); backdrop-filter: none; justify-content: flex-start; padding-left: 7vw; }
.title-box { max-width: 520px; }
.logo { font-family: 'Black Ops One', sans-serif; font-size: clamp(54px, 9vw, 110px); letter-spacing: 0.04em; margin: 0; color: #e8dcc4; text-shadow: 0 4px 30px rgba(0, 0, 0, 0.8), 0 0 2px #000; line-height: 0.95; }
.logo::first-letter { color: var(--bad); }
.tagline { font-size: 16px; color: #d0c4ac; text-shadow: 0 1px 6px #000; margin: 12px 0 26px; }
.menu { display: flex; flex-direction: column; gap: 9px; align-items: stretch; max-width: 280px; }
.foot { margin-top: 24px; text-shadow: 0 1px 4px #000; }
.panel-box { background: var(--glass-strong); border: 1px solid var(--line); border-radius: 14px; padding: 22px 24px; width: min(440px, 100%); max-height: calc(100vh - 32px); overflow-y: auto; box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6); }
.panel-box.wide { width: min(820px, 100%); }
.row { display: flex; gap: 8px; justify-content: flex-end; margin-top: 14px; }
.btn { background: var(--accent); color: #1a1408; border: none; border-radius: 8px; padding: 9px 14px; font-weight: 700; font-size: 13.5px; transition: filter 0.15s, transform 0.08s; }
.btn:hover:not(:disabled) { filter: brightness(1.12); }
.btn:active:not(:disabled) { transform: scale(0.97); }
.btn:disabled { background: #3a3a36; color: #7a766c; cursor: not-allowed; }
.btn.big { font-size: 16px; padding: 12px 18px; letter-spacing: 0.03em; }
.btn.ghost { background: rgba(255, 255, 255, 0.04); border: 1px solid var(--line); color: var(--text); font-weight: 500; }
.btn.ghost:hover:not(:disabled) { background: rgba(255, 255, 255, 0.09); }
.btn.small { padding: 5px 9px; font-size: 12px; }
.btn.danger { background: var(--bad); color: #fff; }
.diff-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 10px; }
.diff { background: var(--panel2); border: 1px solid var(--line); border-radius: 12px; padding: 14px; text-align: left; display: flex; flex-direction: column; align-items: flex-start; justify-content: flex-start; gap: 6px; }
.diff:hover { border-color: var(--accent); }
.diff b { font-family: 'Black Ops One', sans-serif; font-weight: 400; font-size: 20px; letter-spacing: 0.03em; }
.diff span { color: var(--muted); font-size: 12.5px; line-height: 1.4; }
.diff.rec b::after { content: ' ★'; color: var(--accent); font-size: 14px; }
.pause-stats, .death-stats { display: grid; grid-template-columns: 1fr auto; gap: 4px 16px; font-size: 13px; margin-bottom: 16px; }
.pause-stats span:nth-child(odd), .death-stats span:nth-child(odd) { color: var(--muted); }
.died { font-family: 'Black Ops One', sans-serif; font-weight: 400; font-size: 52px; color: var(--bad); margin: 0 0 6px; letter-spacing: 0.05em; }
.set-grid { display: grid; grid-template-columns: auto 1fr; gap: 12px 16px; align-items: center; margin-bottom: 10px; }
.set-grid input[type=range] { width: 100%; accent-color: var(--accent); }
.seg { display: flex; gap: 4px; }
.seg button { flex: 1; background: var(--panel2); border: 1px solid var(--line); border-radius: 6px; padding: 6px; }
.seg button.on { border-color: var(--accent); color: var(--accent); }
.controls-grid { display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; font-size: 13px; align-items: center; }
.howto { padding-left: 18px; line-height: 1.55; color: #d8d0c0; font-size: 13px; }
.howto li { margin-bottom: 5px; }
.resume-screen { cursor: pointer; }
.death-screen { background: radial-gradient(circle, rgba(60, 0, 0, 0.5), rgba(0, 0, 0, 0.85)); }

/* ---------------------------------------------------------------- inventory */
.inv-screen { align-items: stretch; }
.inv-box { background: var(--glass-strong); border: 1px solid var(--line); border-radius: 14px; width: min(1180px, 100%); display: flex; flex-direction: column; padding: 16px 18px; gap: 12px; max-height: calc(100vh - 32px); margin: auto; }
.inv-head { display: flex; align-items: center; gap: 16px; }
.inv-head h2 { margin: 0; }
.inv-head .close { margin-left: auto; }
.weight { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.weight .meter { width: 140px; height: 6px; background: rgba(255, 255, 255, 0.08); border-radius: 3px; overflow: hidden; }
.weight .meter div { height: 100%; background: var(--good); }
.inv-cols { display: grid; grid-template-columns: 1.15fr 1fr 1.2fr; gap: 12px; min-height: 0; flex: 1; }
.inv-list, .inv-detail, .inv-side { background: rgba(0, 0, 0, 0.25); border: 1px solid var(--line); border-radius: 10px; padding: 10px; overflow-y: auto; max-height: calc(100vh - 230px); min-height: 360px; }
.cat { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.08em; margin: 10px 0 4px; }
.cat:first-child { margin-top: 0; }
.it { display: flex; align-items: center; gap: 8px; padding: 5px 7px; border-radius: 7px; cursor: pointer; border: 1px solid transparent; }
.it:hover { background: rgba(255, 255, 255, 0.05); }
.it.sel { border-color: var(--accent); background: rgba(224, 164, 58, 0.08); }
.it .ic { width: 34px; text-align: center; font-size: 18px; }
.it .ic img { max-width: 34px; max-height: 20px; vertical-align: middle; }
.it .nm { flex: 1; font-size: 13px; }
.it .ct { font-family: 'JetBrains Mono', monospace; font-size: 12px; color: #e8dcc0; }
.it .wt { font-family: 'JetBrains Mono', monospace; font-size: 11px; color: var(--muted); width: 48px; text-align: right; }
.inv-detail h3 { margin-top: 0; display: flex; align-items: center; gap: 10px; color: var(--text); text-transform: none; letter-spacing: 0; font-size: 17px; }
.inv-detail .big-ic { font-size: 40px; text-align: center; margin: 8px 0; }
.inv-detail .big-ic img { max-width: 220px; max-height: 110px; }
.inv-detail p { color: #cfc6b4; line-height: 1.45; font-size: 13px; }
.inv-detail .acts { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.tag { display: inline-block; font-size: 11px; padding: 2px 8px; border-radius: 999px; background: rgba(255, 255, 255, 0.07); margin: 2px 3px 2px 0; font-family: 'JetBrains Mono', monospace; }
.tabs { display: flex; gap: 4px; margin-bottom: 8px; }
.tabs button { flex: 1; background: rgba(255, 255, 255, 0.04); border: 1px solid var(--line); border-radius: 6px; padding: 6px; font-size: 12.5px; }
.tabs button.active { border-color: var(--accent); color: var(--accent); }
.rec { background: rgba(255, 255, 255, 0.03); border: 1px solid var(--line); border-radius: 8px; padding: 7px 9px; margin-bottom: 6px; display: flex; align-items: center; gap: 8px; }
.rec .ic { width: 32px; text-align: center; font-size: 18px; }
.rec .ic img { max-width: 32px; max-height: 20px; }
.rec .bd { flex: 1; font-size: 12.5px; }
.rec .bd b { font-size: 13px; }
.rec .cost { font-size: 11px; color: var(--muted); }
.rec .cost .no { color: #ff9a8a; }
.rec.cant { opacity: 0.6; }
.inv-hotbar { display: flex; gap: 6px; justify-content: center; }
.inv-hotbar .slot { cursor: pointer; }
.inv-hotbar .slot.assign { border-color: var(--good); animation: pulse 1s infinite; }

/* ---------------------------------------------------------------- build menu & map */
.bm-cat { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.08em; margin: 12px 0 6px; }
.bm-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(176px, 1fr)); gap: 8px; }
.bm-card { background: var(--panel2); border: 1px solid var(--line); border-radius: 10px; padding: 9px 10px; text-align: left; display: flex; flex-direction: column; gap: 3px; }
.bm-card:hover:not(.cant) { border-color: var(--accent); }
.bm-card .t { display: flex; align-items: center; gap: 7px; font-weight: 600; font-size: 13px; }
.bm-card .t span { font-size: 18px; }
.bm-card .d { font-size: 11.5px; color: var(--muted); line-height: 1.35; }
.bm-card .c { font-size: 11px; font-family: 'JetBrains Mono', monospace; color: #e8dcc0; }
.bm-card .c .no { color: #ff9a8a; }
.bm-card.cant { opacity: 0.55; }
.bm-card .hp { font-size: 10.5px; color: var(--muted); }
.map-box { background: var(--glass-strong); border: 1px solid var(--line); border-radius: 14px; padding: 14px; display: flex; flex-direction: column; gap: 10px; max-height: calc(100vh - 32px); }
#map-canvas { width: min(82vh, 88vw); height: min(82vh, 88vw); border-radius: 8px; background: #1a1c18; }

#loading { position: fixed; inset: 0; z-index: 100; background: radial-gradient(circle at 50% 40%, #1c1a16, #050506); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; transition: opacity 0.6s; }
#loading.done { opacity: 0; pointer-events: none; }
#load-msg { color: var(--muted); }
.load-bar { width: 240px; height: 3px; background: rgba(255, 255, 255, 0.08); border-radius: 2px; overflow: hidden; }
.load-bar div { height: 100%; width: 0; background: var(--accent); transition: width 0.3s; }

@media (max-width: 760px) {
  .vitals { width: 170px; padding: 7px 9px; }
  .slot { width: 52px; height: 44px; }
  .slot img { max-width: 44px; }
  .minimap canvas { width: 110px; height: 110px; }
  .ammo { min-width: 100px; padding: 6px 10px; }
  .ammo .mag { font-size: 20px; }
  .compass { display: none; }
  .hotbar { bottom: 74px; }
  .inv-cols { grid-template-columns: 1fr; }
  .inv-box { overflow-y: auto; }
  .inv-list, .inv-detail, .inv-side { min-height: 0; max-height: none; overflow: visible; }
  .loot { left: auto; right: 12px; top: auto; bottom: 130px; transform: none; }
}
