:root {
  --brass: #f2a950; --copper: #b87333; --iron: #9aa3ad; --ink: #0b0a10; --panel: #15121aee;
  --text: #efe6d8; --muted: #a99e8c; --danger: #ff5a4a; --steam: #7fd0ff; --scrap: #9be36d;
  --font: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--ink); color: var(--text); font-family: var(--font); overflow: hidden; }
canvas#gl { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
#overlay { position: fixed; inset: 0; pointer-events: none; }
#overlay > * { pointer-events: auto; }
[hidden] { display: none !important; }
.hidden { display: none !important; }

.screen { position: absolute; inset: 0; display: none; align-items: center; justify-content: center; padding: 16px; background: radial-gradient(ellipse at center, #1a1208cc, #0b0a10f2); }
.screen.active { display: flex; }
.panel { background: var(--panel); border: 1px solid #3a2f22; border-radius: 14px; padding: 24px 28px; width: min(520px, 100%); box-shadow: 0 20px 60px #000a; }
.panel.wide { width: min(760px, 100%); }
h1.logo { margin: 0 0 4px; font-size: 30px; letter-spacing: 3px; color: var(--brass); text-shadow: 0 0 18px #f2a95055; }
h1.logo .gear { display: inline-block; animation: spin 12s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
h2, h3 { margin: 0 0 8px; color: var(--brass); font-weight: 600; letter-spacing: 1px; }
.tag { margin: 0 0 16px; color: var(--muted); }
.hint { color: var(--muted); font-size: 13px; margin: 8px 0 0; }
.field { display: block; margin: 10px 0; font-size: 13px; color: var(--muted); }
input { width: 100%; margin-top: 4px; padding: 10px 12px; border-radius: 8px; border: 1px solid #4a3b2b; background: #0f0d14; color: var(--text); font-size: 16px; }
input#join-code { width: 110px; text-transform: uppercase; letter-spacing: 2px; }
.row { display: flex; gap: 12px; align-items: center; margin-top: 14px; flex-wrap: wrap; }
.join { display: flex; gap: 8px; align-items: center; }
.btn { padding: 10px 16px; border-radius: 8px; border: 1px solid #5a4530; background: #2a2030; color: var(--text); font-size: 15px; cursor: pointer; }
.btn:hover { background: #3a2c40; }
.btn.primary { background: linear-gradient(#f2a950, #c77d2b); color: #1a1208; border-color: #f2a950; font-weight: 700; }
.btn.primary:hover { filter: brightness(1.08); }
.btn:disabled { opacity: .5; cursor: default; }
.chip { margin-top: 14px; background: transparent; border: 1px dashed #5a4530; color: var(--muted); padding: 6px 10px; border-radius: 999px; font-size: 12px; cursor: pointer; }
.hero-pick { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin: 10px 0; }
.hero-card { border: 1px solid #4a3b2b; border-radius: 10px; padding: 10px 8px; background: #0f0d14; cursor: pointer; text-align: center; }
.hero-card .sw { width: 28px; height: 28px; border-radius: 50%; margin: 0 auto 6px; border: 2px solid #0006; }
.hero-card b { display: block; font-size: 13px; }
.hero-card small { color: var(--muted); font-size: 11px; }
.hero-card.sel { border-color: var(--brass); box-shadow: 0 0 0 1px var(--brass) inset, 0 0 14px #f2a95044; }
.lobby-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
#lobby-code { font-family: ui-monospace, monospace; letter-spacing: 4px; color: var(--text); }
.lobby-body { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin-top: 12px; }
ul.roster { list-style: none; margin: 0; padding: 0; }
ul.roster li { display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-bottom: 1px solid #2a2230; font-size: 14px; }
ul.roster li .sw { width: 14px; height: 14px; border-radius: 50%; }
ul.roster li .host { color: var(--brass); font-size: 11px; }
ul.roster li .off { color: var(--muted); font-size: 11px; }
ul.roster li .rdy { margin-left: auto; color: var(--scrap); font-size: 12px; }

#hud { position: absolute; inset: 0; pointer-events: none; font-size: 14px; }
#hud > * { pointer-events: none; }
.hud-top { position: absolute; top: 10px; left: 50%; transform: translateX(-50%); display: flex; gap: 14px; align-items: center; background: #0b0a10cc; border: 1px solid #3a2f22; border-radius: 10px; padding: 6px 14px; }
.hud-phase { color: var(--brass); font-weight: 700; letter-spacing: 2px; }
.hud-timer { font-family: ui-monospace, monospace; min-width: 48px; text-align: center; }
.hud-core { display: flex; align-items: center; gap: 6px; }
.hud-core .lbl { color: var(--muted); font-size: 12px; }
.bar { position: relative; width: 120px; height: 10px; background: #000a; border-radius: 6px; overflow: hidden; border: 1px solid #3a2f22; }
.bar i { display: block; height: 100%; width: 100%; background: var(--brass); transition: width .15s; }
.bar.hp { width: 180px; height: 14px; }
.bar.hp i { background: linear-gradient(#ff7a5a, #c8352a); }
.bar.hp span { position: absolute; inset: 0; font-size: 10px; line-height: 12px; text-align: center; color: #fff; text-shadow: 0 1px 2px #000; }
.bar.steam { width: 180px; margin-top: 4px; }
.bar.steam i { background: var(--steam); }
.hud-bottom { position: absolute; left: 14px; right: 14px; bottom: 14px; display: flex; justify-content: space-between; align-items: flex-end; }
.hud-stats { background: #0b0a10cc; border: 1px solid #3a2f22; border-radius: 10px; padding: 8px 12px; }
.res { color: var(--muted); font-size: 12px; margin-top: 6px; }
.res #scrap { color: var(--scrap); font-weight: 700; }
.hotbar { display: flex; gap: 6px; }
.hotbar .slot { width: 52px; height: 52px; border: 1px solid #3a2f22; border-radius: 8px; background: #0b0a10cc; display: flex; flex-direction: column; align-items: center; justify-content: center; font-size: 11px; color: var(--muted); }
.hotbar .slot b { font-size: 16px; color: var(--text); }
.hud-center { position: absolute; top: 38%; left: 50%; transform: translate(-50%, -50%); font-size: 56px; font-weight: 800; color: var(--brass); text-shadow: 0 0 30px #f2a95088; letter-spacing: 4px; }
.hud-hint { position: absolute; bottom: 90px; left: 50%; transform: translateX(-50%); color: var(--muted); font-size: 12px; background: #0b0a1099; padding: 4px 10px; border-radius: 6px; }
.btn.ready { position: absolute; right: 14px; top: 64px; pointer-events: auto !important; background: #1d3a1d; border-color: var(--scrap); }
.btn.ready.on { background: var(--scrap); color: #0b0a10; }

#touch-ui { position: absolute; inset: 0; pointer-events: none; }
.stick { position: absolute; left: 40px; bottom: 60px; width: 110px; height: 110px; border-radius: 50%; background: #ffffff12; border: 1px solid #ffffff33; }
.stick .nub { position: absolute; left: 35px; top: 35px; width: 40px; height: 40px; border-radius: 50%; background: #ffffff55; }
.tbtn { position: absolute; width: 64px; height: 64px; border-radius: 50%; background: #ffffff18; border: 1px solid #ffffff44; display: flex; align-items: center; justify-content: center; font-size: 24px; pointer-events: auto; }
#tbtn-attack { right: 40px; bottom: 60px; }
#tbtn-dodge { right: 120px; bottom: 90px; }
#tbtn-ready { right: 40px; bottom: 150px; }

#toasts { position: absolute; top: 60px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 6px; pointer-events: none; }
.toast { background: #0b0a10dd; border: 1px solid #3a2f22; border-radius: 8px; padding: 6px 12px; font-size: 13px; animation: fade 3s forwards; }
@keyframes fade { 0% { opacity: 0; transform: translateY(-6px); } 10% { opacity: 1; transform: none; } 80% { opacity: 1; } 100% { opacity: 0; } }
#debug { position: absolute; left: 10px; top: 10px; font: 11px ui-monospace, monospace; color: #9be36d; background: #000a; padding: 4px 6px; border-radius: 4px; white-space: pre; pointer-events: none; }

@media (max-width: 700px) {
  .hero-pick { grid-template-columns: repeat(2, 1fr); }
  .lobby-body { grid-template-columns: 1fr; }
  .panel { padding: 16px; }
  .hud-hint { display: none; }
}

.lanes { position: absolute; left: 14px; top: 64px; display: flex; flex-direction: column; gap: 6px; max-width: 240px; }
.lane { background: #0b0a10cc; border: 1px solid #3a2f22; border-left: 4px solid var(--lc, #fff); border-radius: 8px; padding: 6px 10px; font-size: 12px; }
.lane.closed { opacity: .45; }
.lane b { color: var(--text); letter-spacing: 1px; }
.lane .kinds { color: var(--muted); margin-top: 2px; }
.lane .kinds span { margin-right: 8px; white-space: nowrap; }
.lane .threat { height: 4px; background: #000a; border-radius: 2px; margin-top: 4px; overflow: hidden; }
.lane .threat i { display: block; height: 100%; background: var(--lc, #fff); }
.lane .boss { color: var(--danger); font-weight: 700; }
#result-title { font-size: 34px; letter-spacing: 4px; }
#screen-results .panel { text-align: center; }
#screen-results .row { justify-content: center; }

.hotbar .slot { width: 74px; height: 58px; position: relative; }
.hotbar .slot .nm { font-size: 10px; color: var(--text); line-height: 1.1; text-align: center; }
.hotbar .slot small { font-size: 9px; color: var(--muted); }
.hotbar .slot.sel { border-color: var(--brass); box-shadow: 0 0 0 1px var(--brass) inset, 0 0 12px #f2a95066; }
.prompt { position: absolute; bottom: 120px; left: 50%; transform: translateX(-50%); background: #0b0a10dd; border: 1px solid #3a2f22; border-radius: 8px; padding: 6px 12px; font-size: 13px; white-space: nowrap; }
.ghost-hint { position: absolute; top: 56%; left: 50%; transform: translateX(-50%); font-size: 13px; color: var(--scrap); background: #0b0a1099; padding: 3px 8px; border-radius: 6px; }
.ghost-hint.bad { color: var(--danger); }
.channel { position: absolute; top: 60%; left: 50%; transform: translateX(-50%); text-align: center; font-size: 12px; color: var(--muted); }
.channel .bar { width: 160px; margin: 4px auto 0; }

#dmg-layer { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.dmg { position: absolute; left: 0; top: 0; font-weight: 800; font-size: 15px; color: #fff; text-shadow: 0 1px 2px #000, 0 0 6px #000; will-change: transform, opacity; }
.dmg.crit { color: #ffe45b; font-size: 20px; }
.dmg.heal { color: #9be36d; }
.dmg.mine { color: #ffb3a0; }

.field.check { display: flex; align-items: center; gap: 8px; }
.field.check input { width: auto; margin: 0; }
input[type=range] { padding: 0; }
select { width: 100%; margin-top: 4px; padding: 8px; border-radius: 8px; border: 1px solid #4a3b2b; background: #0f0d14; color: var(--text); }
.tbtn.sm { width: 48px; height: 48px; font-size: 16px; }
#tbtn-q { right: 200px; bottom: 40px; } #tbtn-e { right: 200px; bottom: 100px; } #tbtn-f { right: 120px; bottom: 160px; }
#tbtn-rot { right: 120px; bottom: 20px; } #tbtn-place { right: 40px; bottom: 60px; background: #f2a95055; border-color: var(--brass); }
#tbtn-menu { right: 14px; top: 14px; }
.hotbar .slot { pointer-events: auto; cursor: pointer; }

.map-pick { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin: 6px 0; }
.map-card { border: 1px solid #4a3b2b; border-radius: 8px; padding: 8px 6px; background: #0f0d14; text-align: center; font-size: 12px; cursor: pointer; }
.map-card small { display: block; color: var(--muted); font-size: 10px; }
.map-card.sel { border-color: var(--brass); box-shadow: 0 0 0 1px var(--brass) inset; }
.map-card.ro { cursor: default; opacity: .85; }
.diff-pick { display: flex; gap: 6px; margin-top: 4px; }
.diff-pick .btn { padding: 6px 10px; font-size: 12px; }
.diff-pick .btn.sel { border-color: var(--brass); color: var(--brass); }

.bossbar { position: absolute; top: 52px; left: 50%; transform: translateX(-50%); text-align: center; }
.bossbar b { color: var(--danger); letter-spacing: 2px; font-size: 12px; text-shadow: 0 0 8px #ff5a4a88; }
.bossbar .bar { width: 320px; height: 10px; margin-top: 3px; }
.bossbar .bar i { background: linear-gradient(#ff7a5a, #8a1a1a); }

.eq-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin: 8px 0; }
.eq-slot { border: 1px solid var(--rc); border-radius: 8px; padding: 6px 8px; background: #0f0d14; font-size: 12px; min-height: 54px; }
.eq-slot small { color: var(--muted); display: block; font-size: 10px; }
.eq-slot b { color: var(--rc); display: block; }
.eq-slot span { color: var(--muted); font-size: 11px; display: block; }
.eq-slot.empty { opacity: .6; }
.bag-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 8px; max-height: 46vh; overflow-y: auto; margin-top: 10px; }
.item { border: 1px solid var(--rc); border-left-width: 4px; border-radius: 8px; padding: 8px; background: #0f0d14; font-size: 12px; }
.item b { color: var(--rc); }
.item small { color: var(--muted); display: block; font-size: 10px; }
.item > span { display: block; margin: 4px 0; color: var(--text); font-size: 11px; }
.item .pas { color: var(--brass); font-size: 11px; }
.item .row { margin-top: 6px; gap: 6px; }
.btn.tiny { padding: 4px 8px; font-size: 11px; }
.btn.ghost { background: transparent; }
.warn { color: var(--danger); }
.result-roster { list-style: none; padding: 0; margin: 8px 0; font-size: 13px; }
.result-roster li { display: flex; justify-content: space-between; gap: 12px; padding: 3px 0; border-bottom: 1px solid #2a2230; }
.result-roster li .xp { color: var(--scrap); }

.hint-box { position: absolute; top: 70%; left: 50%; transform: translateX(-50%); max-width: 520px; background: #0b0a10ee; border: 1px solid var(--brass); border-radius: 10px; padding: 10px 14px; font-size: 14px; color: var(--text); animation: fade 9s forwards; }
.kick { margin-left: 6px; }
#overlay { font-size: calc(14px * var(--ui, 1)); }
#hud { font-size: calc(14px * var(--ui, 1)); }

.boards { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-top: 12px; }
.board { background: #0f0d14; border: 1px solid #2a2230; border-radius: 8px; padding: 6px 8px; font-size: 11px; }
.board b { display: block; color: var(--brass); font-size: 12px; margin-bottom: 3px; }
.board ol { margin: 0; padding-left: 16px; color: var(--muted); }
.board li span { color: var(--text); }
@media (max-width: 700px) { .boards { grid-template-columns: 1fr; } }
