:root {
  --ink: #f4f1e8;
  --dim: #b9c2cf;
  --panel: rgba(16, 22, 34, 0.86);
  --edge: #f0a640;
  --hot: #ff7a2f;
  --good: #63d471;
  --bad: #ff5a4a;
  --coin: #ffcc33;
  --ore: #45e6df;
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #101826; color: var(--ink); user-select: none; }
canvas#game { position: fixed; inset: 0; width: 100%; height: 100%; display: block; cursor: crosshair; }

/* ---------- HUD ---------- */
#hud { position: fixed; inset: 0; pointer-events: none; text-shadow: 0 2px 0 rgba(0, 0, 0, 0.55); }
#wavebox { position: absolute; left: 18px; top: 14px; max-width: min(46vw, 560px); }
#waveTitle { font-size: 24px; font-weight: 900; letter-spacing: 0.02em; }
#waveSub { font-size: 14px; color: var(--dim); margin-top: 2px; font-weight: 600; }
#money { position: absolute; right: 18px; top: 14px; text-align: right; }
.res { font-size: 24px; font-weight: 900; line-height: 1.2; }
.res small { font-size: 13px; color: var(--dim); margin-left: 6px; font-weight: 600; }
.dot { display: inline-block; width: 14px; height: 14px; margin-right: 8px; border-radius: 3px; vertical-align: 1px; box-shadow: 0 2px 0 rgba(0,0,0,.45); }
.dot.coin { background: var(--coin); border-radius: 50%; }
.dot.ore { background: var(--ore); transform: rotate(45deg); }
#lvl { font-size: 13px; color: var(--dim); font-weight: 700; margin-top: 2px; }

#compass { position: absolute; left: 50%; top: 12px; width: min(420px, 40vw); height: 30px; transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.32); border-radius: 15px; overflow: hidden; }
#compassInner { position: absolute; inset: 0; }
#compassTick { position: absolute; left: 50%; top: 0; width: 2px; height: 8px; background: var(--ink); transform: translateX(-1px); }
.cd { position: absolute; top: 6px; font-size: 13px; font-weight: 700; color: var(--dim); transform: translateX(-50%); }
.cd.main { color: var(--ink); font-size: 15px; top: 5px; font-weight: 900; }
.cm { position: absolute; bottom: 3px; width: 12px; height: 12px; background: var(--bad); transform: translateX(-50%) rotate(45deg);
  box-shadow: 0 0 10px var(--bad); }

#cross { position: absolute; left: 50%; top: 50%; width: 22px; height: 22px; transform: translate(-50%, -50%); }
#cross::before, #cross::after { content: ""; position: absolute; background: rgba(255,255,255,.9); box-shadow: 0 0 2px #000; }
#cross::before { left: 10px; top: 3px; width: 2px; height: 16px; }
#cross::after { top: 10px; left: 3px; height: 2px; width: 16px; }
#ring { position: absolute; inset: -9px; border-radius: 50%; opacity: 0; --p: 0%;
  background: conic-gradient(var(--edge) var(--p), rgba(255,255,255,.12) 0);
  -webkit-mask: radial-gradient(circle, transparent 15px, #000 16px); mask: radial-gradient(circle, transparent 15px, #000 16px); }
#ring.on { opacity: 1; }

#toasts { position: absolute; left: 50%; top: 23%; transform: translateX(-50%); width: min(640px, 90vw); text-align: center; }
.toast { display: inline-block; margin: 3px auto; padding: 7px 14px; background: rgba(10, 14, 22, 0.75); border-radius: 8px;
  font-weight: 700; font-size: 15px; transition: opacity .5s; }
.toast.fade { opacity: 0; }
#banner { position: absolute; left: 50%; top: 13%; transform: translateX(-50%); text-align: center; }
#banner.go { animation: pop 4.2s ease forwards; }
#bannerTitle { font-size: 44px; font-weight: 900; color: var(--edge); letter-spacing: .03em; }
#bannerSub { font-size: 17px; font-weight: 700; margin-top: 4px; }
@keyframes pop { 0% { opacity: 0; transform: translateX(-50%) scale(.85); } 8% { opacity: 1; transform: translateX(-50%) scale(1); }
  80% { opacity: 1; } 100% { opacity: 0; } }

#bars { position: absolute; left: 18px; bottom: 18px; width: min(260px, 30vw); }
.bar { position: relative; height: 20px; background: rgba(0,0,0,.45); border-radius: 6px; margin-top: 6px; overflow: hidden; }
.bar .fill { position: absolute; left: 0; top: 0; bottom: 0; width: 100%; background: linear-gradient(#7fe28a, #3fae4f); transition: width .12s; }
.bar.hearth .fill { background: linear-gradient(#ffb15a, #e5612a); }
.bar span { position: relative; padding-left: 8px; font-size: 13px; font-weight: 800; line-height: 20px; }

#hotbar { position: absolute; left: 50%; bottom: 14px; transform: translateX(-50%); display: flex; gap: 6px; }
.slot { position: relative; width: 70px; height: 70px; background: rgba(10, 14, 22, 0.66); border: 3px solid rgba(255,255,255,.12);
  border-radius: 10px; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; padding-bottom: 4px; }
.slot.sel { border-color: var(--edge); background: rgba(40, 30, 14, 0.75); transform: translateY(-4px); }
.slot.locked, .slot.poor { opacity: 0.55; }
.slot .key { position: absolute; left: 5px; top: 2px; font-size: 12px; font-weight: 900; color: var(--dim); }
.slot .name { font-size: 11px; font-weight: 800; white-space: nowrap; }
.slot .price { font-size: 11px; color: var(--coin); font-weight: 800; min-height: 13px; }
.slot .ico { position: absolute; top: 12px; left: 50%; transform: translateX(-50%); width: 26px; height: 26px; }
.ico.place { background: var(--c); border-radius: 3px; box-shadow: inset -5px -5px 0 rgba(0,0,0,.25), inset 4px 4px 0 rgba(255,255,255,.2); }
.ico.turret { background: none; box-shadow: none; }
.ico.turret::before { content: ""; position: absolute; left: 3px; right: 3px; bottom: 0; height: 12px; background: #50555e; border-radius: 2px; }
.ico.turret::after { content: ""; position: absolute; left: 7px; top: 3px; width: 18px; height: 9px; background: #6b7a5c; border-radius: 2px; box-shadow: 9px 2px 0 -3px #222; }
.ico.drill { box-shadow: inset 0 -8px 0 #333, inset -5px -5px 0 rgba(0,0,0,.25); }
.ico.gun::before { content: ""; position: absolute; left: 0; top: 7px; width: 26px; height: 8px; background: #3a3d44; border-radius: 2px; }
.ico.gun::after { content: ""; position: absolute; left: 4px; top: 13px; width: 7px; height: 11px; background: #25272b; border-radius: 2px; }
.ico.shotgun::before { left: -6px; width: 36px; background: #2d2f34; }
.ico.shotgun::after { background: #7a4a24; left: -4px; width: 10px; }
.ico.pick::before { content: ""; position: absolute; left: 11px; top: 4px; width: 4px; height: 22px; background: #8c5e30; }
.ico.pick::after { content: ""; position: absolute; left: 2px; top: 2px; width: 22px; height: 6px; background: #a4a9b2; border-radius: 3px 3px 0 0; }

#hint { position: absolute; left: 50%; bottom: 100px; transform: translateX(-50%); font-size: 13px; color: var(--dim); font-weight: 700; white-space: nowrap; }
#ammo { position: absolute; right: 22px; bottom: 22px; font-size: 26px; font-weight: 900; }
#hurtFlash { position: absolute; inset: 0; opacity: 0; background: radial-gradient(ellipse at center, transparent 45%, rgba(200, 20, 10, .85)); }
#deadNote { position: absolute; left: 50%; top: 40%; transform: translateX(-50%); font-size: 26px; font-weight: 900; }
#fps { position: absolute; left: 18px; bottom: 74px; font: 12px/1.3 Consolas, monospace; color: #cfe; white-space: pre; }

/* ---------- screens ---------- */
.screen { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; padding: 16px;
  background: radial-gradient(ellipse at center, rgba(16,24,38,.55), rgba(5,8,14,.9)); overflow-y: auto; }
.screen.clear { background: rgba(5, 8, 14, 0.35); cursor: pointer; }
.screen[hidden], [hidden] { display: none !important; }
.panel { width: min(440px, 100%); background: var(--panel); border: 3px solid rgba(240, 166, 64, .55); border-radius: 18px;
  padding: 22px 26px; box-shadow: 0 12px 0 rgba(0,0,0,.35); max-height: calc(100vh - 32px); overflow-y: auto; }
.panel.wide { width: min(720px, 100%); }
.panel.small { width: min(360px, 100%); text-align: center; }
h1 { margin: 4px 0 6px; font-size: 64px; font-weight: 900; letter-spacing: .04em; line-height: 1; color: var(--ink);
  text-shadow: 0 5px 0 #6b2f12, 0 8px 18px rgba(0,0,0,.5); }
h1 span { color: var(--edge); margin-left: 14px; }
h2 { margin: 0 0 12px; font-size: 30px; font-weight: 900; }
h3 { margin: 18px 0 8px; font-size: 18px; }
p { line-height: 1.5; }
.tag { font-size: 17px; color: var(--dim); font-weight: 600; }
.info { color: var(--dim); }
.foot { color: #7d8796; font-size: 13px; margin-bottom: 0; }
.big-line { font-size: 22px; font-weight: 800; }
.actions { display: flex; flex-wrap: wrap; gap: 10px; margin: 16px 0 6px; }
button { font: inherit; font-weight: 800; font-size: 16px; color: var(--ink); background: #2a3446; border: 0; border-radius: 10px;
  padding: 11px 18px; cursor: pointer; box-shadow: 0 4px 0 rgba(0,0,0,.4); }
button:hover:not(:disabled) { background: #36435a; }
button:active:not(:disabled) { transform: translateY(2px); box-shadow: 0 2px 0 rgba(0,0,0,.4); }
button:disabled { opacity: .45; cursor: default; }
button.big { background: linear-gradient(#ff9a3c, #e2621c); font-size: 18px; padding: 13px 24px; }
button.big:hover:not(:disabled) { background: linear-gradient(#ffaa55, #ee6f28); }
.keys { width: 100%; border-collapse: collapse; margin: 12px 0; font-size: 14px; }
.keys td { padding: 5px 6px; border-bottom: 1px solid rgba(255,255,255,.08); }
.keys td:nth-child(odd) { font-weight: 900; color: var(--edge); white-space: nowrap; }
.slider { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 10px 0; font-weight: 700; }
.slider input { width: 55%; accent-color: var(--edge); }
.row { display: grid; grid-template-columns: 150px 1fr auto; gap: 12px; align-items: center; padding: 8px 0; border-bottom: 1px solid rgba(255,255,255,.08); }
.row span { color: var(--dim); font-size: 14px; }
.row em { font-style: normal; font-weight: 800; color: var(--coin); white-space: nowrap; }
.row.small b { font-size: 14px; }
#overStats { display: grid; grid-template-columns: 1fr auto; gap: 4px 16px; margin: 10px 0; font-weight: 700; }
#overStats span:nth-child(even) { text-align: right; color: var(--edge); }
@media (max-width: 760px) {
  .slot { width: 52px; height: 58px; } .slot .name { display: none; }
  h1 { font-size: 44px; } #hint { display: none; } .row { grid-template-columns: 1fr; }
}
