:root {
  --bg: #090b15;
  --panel: rgba(16, 20, 38, 0.72);
  --card: rgba(255, 255, 255, 0.045);
  --line: rgba(255, 255, 255, 0.09);
  --text: #e9edff;
  --muted: #8d95bd;
  --accent: #ffd23f;
  --accent2: #6c8cff;
  --danger: #ff5a6e;
  --good: #4cd98a;
  --radius: 14px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font: 15px/1.45 system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif; overflow: hidden; }
body[data-screen='game'] { cursor: none; }
body[data-screen='game'] .interactive, body[data-screen='game'] .interactive * { cursor: auto; }
#bg { position: fixed; inset: 0; z-index: -1; background:
  radial-gradient(900px 500px at 15% 10%, rgba(108, 140, 255, 0.16), transparent 60%),
  radial-gradient(800px 500px at 90% 90%, rgba(255, 210, 63, 0.10), transparent 60%),
  linear-gradient(160deg, #0b0e1c, #070913); }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
kbd { display: inline-block; min-width: 22px; padding: 1px 6px; border: 1px solid rgba(255,255,255,0.22); border-bottom-width: 2px; border-radius: 6px; background: rgba(255,255,255,0.07); font: 600 12px/1.5 ui-monospace, Consolas, monospace; text-align: center; }
h1, h2, h3 { margin: 0 0 10px; line-height: 1.15; }
h2 { font-size: 18px; }
h3 { font-size: 14px; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; margin-top: 18px; }

.screen { position: fixed; inset: 0; overflow: auto; }
.screen.center { display: flex; align-items: center; justify-content: center; padding: 20px; }
.wrap { max-width: 1100px; margin: 0 auto; padding: 18px 20px 40px; }
.wrap.two { display: grid; grid-template-columns: 1.25fr 1fr; gap: 18px; align-items: start; }
@media (max-width: 860px) { .wrap.two { grid-template-columns: 1fr; } }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; backdrop-filter: blur(8px); }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.card-head h2 { margin: 0; }
.topbar { display: flex; align-items: center; justify-content: space-between; padding: 14px 22px; border-bottom: 1px solid var(--line); background: rgba(0,0,0,0.2); }
.brand { font-weight: 800; letter-spacing: .12em; display: flex; align-items: center; gap: 10px; }
.brand b { color: var(--accent); }
.brand svg { width: 28px; height: 28px; }

.btn { appearance: none; border: 1px solid rgba(255,255,255,0.18); background: rgba(255,255,255,0.08); color: var(--text); padding: 9px 16px; border-radius: 10px; font: 600 14px system-ui, sans-serif; cursor: pointer; transition: transform .08s, background .15s, border-color .15s; }
.btn:hover { background: rgba(255,255,255,0.15); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: linear-gradient(180deg, #ffe066, #ffc21f); color: #2a2100; border-color: #ffd23f; box-shadow: 0 4px 18px rgba(255, 200, 30, .25); }
.btn.primary:hover { background: linear-gradient(180deg, #ffe98a, #ffd23f); }
.btn.danger { background: rgba(255, 90, 110, .15); border-color: rgba(255, 90, 110, .5); color: #ffb3bd; }
.btn.ghost { background: transparent; }
.btn.big { padding: 13px 28px; font-size: 16px; }
.btn.small { padding: 5px 10px; font-size: 12.5px; }

/* ---- name screen ---- */
.hero { width: min(460px, 100%); text-align: center; padding: 30px 28px 24px; }
.hero h1 { font-size: 44px; letter-spacing: .14em; margin: 6px 0 6px; }
.hero h1 span { color: var(--accent); }
.tag { color: var(--muted); margin: 0 0 22px; }
.logo-row { display: flex; justify-content: center; gap: 6px; margin-bottom: 6px; }
.logo-row svg { width: 44px; height: 44px; animation: bob 2.2s ease-in-out infinite; }
.logo-row svg:nth-child(2n) { animation-delay: -.7s; }
.logo-row svg:nth-child(3n) { animation-delay: -1.3s; }
@keyframes bob { 50% { transform: translateY(-7px); } }
#name-form { display: flex; flex-direction: column; gap: 10px; align-items: stretch; }
#name-form label { text-align: left; color: var(--muted); font-size: 13px; }
input[type=text], input[type=number], input:not([type]), select {
  width: 100%; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line); background: rgba(0,0,0,0.3); color: var(--text); font: 600 15px system-ui; outline: none; }
input:focus, select:focus { border-color: var(--accent2); }
select option { background: #15192e; }
#conn-status { margin-top: 10px; min-height: 18px; font-size: 13px; }

/* ---- game list ---- */
#game-list { display: flex; flex-direction: column; gap: 10px; }
.empty { padding: 26px 10px; text-align: center; color: var(--muted); border: 1px dashed var(--line); border-radius: 12px; }
.game { display: flex; align-items: center; gap: 14px; padding: 12px 14px; border: 1px solid var(--line); border-radius: 12px; background: rgba(0,0,0,0.18); }
.game .main { flex: 1; min-width: 0; }
.game .main b { font-size: 16px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0 4px; }
.chip { padding: 2px 8px; border-radius: 99px; background: rgba(255,255,255,0.08); font-size: 12px; color: #cfd6ff; white-space: nowrap; }
.game .side { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }
.badge { padding: 2px 9px; border-radius: 99px; font-size: 11.5px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; }
.badge.lobby { background: rgba(76, 217, 138, .16); color: var(--good); }
.badge.playing { background: rgba(255, 210, 63, .16); color: var(--accent); }
.badge.ended { background: rgba(255,255,255,.1); color: var(--muted); }
.howto { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 9px; }
.howto.plain { list-style: disc; padding-left: 18px; gap: 6px; color: #cdd3f5; }

/* ---- room ---- */
.players { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 10px; }
.pl { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border: 1px solid var(--line); border-radius: 12px; background: rgba(0,0,0,0.2); position: relative; }
.pl svg { width: 34px; height: 34px; flex: none; }
.pl .nm { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pl .sub { font-size: 12px; color: var(--muted); }
.pl .x { margin-left: auto; border: 0; background: transparent; color: var(--muted); cursor: pointer; font-size: 18px; line-height: 1; padding: 2px 6px; border-radius: 6px; }
.pl .x:hover { color: var(--danger); background: rgba(255,90,110,.12); }
.pl.me { border-color: rgba(255, 210, 63, .5); }
.rules { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 14px; margin-bottom: 14px; }
.rules .f { display: flex; flex-direction: column; gap: 4px; }
.rules .f.wide { grid-column: 1 / -1; }
.rules label { font-size: 12.5px; color: var(--muted); }
.rules .hint { font-size: 11.5px; color: #6f77a0; }
.rules .chk { flex-direction: row; align-items: center; gap: 10px; }
.rules .chk input { width: 18px; height: 18px; accent-color: var(--accent); }
.rules .chk label { color: var(--text); font-size: 14px; }
.rules input:disabled, .rules select:disabled { opacity: .7; cursor: not-allowed; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 8px; }

/* ---- results ---- */
.results { width: min(720px, 100%); text-align: center; }
.results h1 { font-size: 34px; }
.podium { display: flex; justify-content: center; align-items: flex-end; gap: 14px; margin: 18px 0 20px; min-height: 190px; }
.pod { display: flex; flex-direction: column; align-items: center; gap: 4px; width: 130px; }
.pod svg { width: 56px; height: 56px; }
.pod .nm { font-weight: 800; max-width: 130px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pod .bar { width: 100%; border-radius: 10px 10px 0 0; display: flex; align-items: flex-start; justify-content: center; padding-top: 8px; font-size: 26px; font-weight: 800; background: linear-gradient(180deg, rgba(255,255,255,.18), rgba(255,255,255,.05)); }
.pod.p1 .bar { height: 110px; background: linear-gradient(180deg, rgba(255,210,63,.6), rgba(255,210,63,.1)); }
.pod.p2 .bar { height: 80px; }
.pod.p3 .bar { height: 60px; }
.pod .sc { font-weight: 700; color: var(--accent); }
table { border-collapse: collapse; width: 100%; font-size: 14px; }
th, td { padding: 6px 10px; text-align: right; border-bottom: 1px solid var(--line); }
th:nth-child(1), td:nth-child(1) { text-align: left; width: 36px; color: var(--muted); }
th:nth-child(2), td:nth-child(2) { text-align: left; }
th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; }
tr.me td { background: rgba(255,210,63,.08); }
td small { color: var(--muted); }
.dot { display: inline-block; width: 11px; height: 11px; border-radius: 50%; margin-right: 7px; border: 1.5px solid rgba(0,0,0,.55); vertical-align: -1px; }

/* ================= IN-GAME ================= */
#s-game { overflow: hidden; background: #000; }
#view, #hud { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
#hud { pointer-events: none; }
#dmg { position: absolute; inset: 0; pointer-events: none; opacity: 0; background: radial-gradient(ellipse at center, rgba(255,0,30,0) 35%, rgba(255,20,40,.75) 100%); transition: opacity .06s; }
#lowhp { position: absolute; inset: 0; pointer-events: none; opacity: 0; transition: opacity .4s; box-shadow: inset 0 0 120px rgba(255, 0, 30, .45); animation: pulse 1s ease-in-out infinite; }
@keyframes pulse { 50% { box-shadow: inset 0 0 180px rgba(255, 0, 30, .6); } }
.panel { position: absolute; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; backdrop-filter: blur(6px); color: var(--text); }
#s-game .panel { pointer-events: none; }
#s-game .panel.interactive-panel { pointer-events: auto; }

#board { top: 12px; left: 12px; padding: 6px 8px; width: 250px; font-size: 13px; }
#board .row { display: grid; grid-template-columns: 18px 14px 1fr auto 44px; align-items: center; gap: 4px; padding: 2px 4px; border-radius: 6px; }
#board .row.me { background: rgba(255, 210, 63, .16); font-weight: 700; }
#board .pos { color: var(--muted); font-size: 11px; text-align: right; }
#board .dot { margin: 0; }
#board .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#board .sc { text-align: right; font-variant-numeric: tabular-nums; font-weight: 700; }
#board .hp i, #lives i { display: inline-block; width: 8px; height: 8px; margin-left: 2px; border-radius: 50%; background: rgba(255,255,255,.2); }
#board .hp i.on { background: #ff5a6e; }
#board .dead { font-size: 11px; color: var(--muted); }

#timer { top: 12px; left: 50%; transform: translateX(-50%); padding: 6px 18px; text-align: center; min-width: 120px; }
#timer-main { font: 800 26px/1.1 ui-monospace, Consolas, monospace; letter-spacing: .04em; }
#timer-sub { font-size: 12px; color: var(--muted); }
#timer.urgent #timer-main { color: var(--danger); animation: pulse2 .5s steps(2) infinite; }
@keyframes pulse2 { 50% { opacity: .35; } }

#hud-feed { position: absolute; top: 12px; right: 12px; width: 320px; display: flex; flex-direction: column; gap: 4px; align-items: flex-end; pointer-events: none; }
.feed-row { padding: 5px 10px; border-radius: 8px; background: var(--panel); font-size: 13px; border: 1px solid transparent; transition: opacity 1s; }
.feed-row.mine { border-color: rgba(255,210,63,.55); }
.feed-row.fade { opacity: 0; }
.bounty { background: var(--accent); color: #2a2100; font-weight: 800; font-size: 10px; padding: 1px 5px; border-radius: 4px; margin-left: 4px; }

#myhits { position: absolute; left: 12px; bottom: 150px; display: flex; flex-direction: column; gap: 4px; pointer-events: none; width: 260px; }
.myhit { display: flex; justify-content: space-between; gap: 10px; padding: 5px 10px; border-radius: 8px; background: var(--panel); border-left: 4px solid #fff; font-size: 13px; transition: opacity 1s; animation: slidein .2s ease-out; }
.myhit em { font-style: normal; font-weight: 800; color: var(--good); }
.myhit.kill { border-left-color: var(--danger); background: rgba(80, 16, 28, .75); }
.myhit.kill em { color: var(--accent); }
.myhit.miss em { color: var(--muted); }
.myhit.fade { opacity: 0; }
@keyframes slidein { from { transform: translateX(-20px); opacity: 0; } }

#stats { left: 12px; bottom: 12px; padding: 10px 14px; min-width: 220px; }
#lives { height: 20px; margin-bottom: 4px; display: flex; align-items: center; }
#lives i { width: 18px; height: 16px; border-radius: 0; margin: 0 3px 0 0; background: rgba(255,255,255,.16); clip-path: path('M9 16 C-6 6 2 -4 9 3 C16 -4 24 6 9 16Z'); }
#lives i.on { background: #ff4d63; filter: drop-shadow(0 0 4px rgba(255,60,90,.8)); }
#lives .shield-ic { margin-left: 8px; font-size: 16px; }
#stats .line { display: flex; align-items: baseline; gap: 10px; font-size: 14px; }
#stats .lbl { color: var(--muted); width: 74px; }
#stats b { font-size: 20px; font-variant-numeric: tabular-nums; }
#stats #money { color: #7dffa8; }
#rank { color: var(--muted); font-size: 12px; }
#upbar { position: absolute; left: 12px; bottom: 112px; display: flex; gap: 6px; flex-wrap: wrap; width: 260px; font-size: 18px; pointer-events: none; }
#upbar span { background: var(--panel); border-radius: 8px; padding: 1px 6px; }
#upbar sup { font-size: 10px; color: var(--accent); margin-left: 1px; font-weight: 800; }
#buyhint { left: 50%; bottom: 10px; transform: translateX(-50%); padding: 4px 12px; font-size: 12px; color: var(--muted); }

#mapwrap { position: absolute; right: 12px; bottom: 12px; width: 200px; height: 200px; border-radius: 10px; overflow: hidden; border: 1px solid var(--line); background: #000; pointer-events: none; opacity: .94; }
#mapwrap canvas { width: 100%; height: 100%; display: block; image-rendering: pixelated; }
#mapwrap.big { right: 50%; bottom: 50%; transform: translate(50%, 50%); width: min(78vh, 78vw); height: min(78vh, 78vw); z-index: 5; opacity: .97; box-shadow: 0 0 0 100vmax rgba(0,0,0,.45); }
#fps { position: absolute; right: 14px; top: 140px; font-size: 11px; color: rgba(255,255,255,.35); pointer-events: none; }

#shop { right: 12px; top: 44%; transform: translateY(-50%); width: 400px; max-height: 92vh; overflow: auto; padding: 10px; z-index: 4; pointer-events: auto !important; }
.shop-head { display: flex; align-items: center; gap: 10px; padding: 4px 6px 8px; flex-wrap: wrap; }
.shop-head b { font-size: 16px; }
.shop-head .muted { font-size: 11.5px; flex: 1; }
.money-big { font-size: 16px; font-weight: 700; color: #7dffa8; }
.shop-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; }
.item { position: relative; display: grid; grid-template-columns: 34px 1fr auto; align-items: center; gap: 8px; padding: 8px 9px; border-radius: 10px; border: 1px solid var(--line); background: rgba(0,0,0,.3); cursor: pointer; user-select: none; }
.item .key { position: absolute; left: -5px; top: -7px; background: #2b3160; border: 1px solid rgba(255,255,255,.3); border-radius: 6px; font: 700 11px ui-monospace, monospace; padding: 0 5px; }
.item .ico { font-size: 24px; text-align: center; }
.item .nm { font-weight: 700; font-size: 13px; line-height: 1.1; }
.item .ds { font-size: 10.5px; color: var(--muted); line-height: 1.25; margin-top: 2px; }
.item .cost { font-weight: 800; font-size: 14px; color: var(--muted); }
.item .pips { display: flex; gap: 3px; margin-top: 2px; }
.item .pips i { width: 14px; height: 4px; border-radius: 2px; background: rgba(255,255,255,.15); }
.item .pips i.on { background: var(--accent); }
.item.afford { border-color: rgba(125, 255, 168, .55); background: rgba(40, 110, 70, .22); }
.item.afford .cost { color: #7dffa8; }
.item.afford:hover { background: rgba(60, 150, 95, .3); }
.item.poor { opacity: .6; }
.item.maxed { opacity: .5; border-color: rgba(255, 210, 63, .4); }
.item.maxed .cost { color: var(--accent); }
.shop-foot { text-align: center; padding: 8px 0 2px; font-size: 11.5px; }
.pad { padding: 10px; }

#scoreboard { left: 50%; top: 50%; transform: translate(-50%, -50%); width: min(560px, 92vw); padding: 14px 18px; z-index: 4; }
#scoreboard h3 { margin: 0 0 8px; }

#center-msg { position: absolute; left: 0; right: 0; top: 24%; text-align: center; pointer-events: none; text-shadow: 0 2px 12px rgba(0,0,0,.8); }
#center-msg .big { font: 900 72px/1 system-ui; letter-spacing: .06em; }
#center-msg .big.count { font-size: 120px; color: var(--accent); animation: pop .5s ease-out; }
#center-msg .big.dead { color: var(--danger); font-size: 54px; }
#center-msg .sub { font-size: 18px; margin-top: 8px; }
#center-msg .sub.protect { font-size: 13px; color: #9fe8ff; margin-top: -20px; opacity: .8; }
@keyframes pop { from { transform: scale(1.5); opacity: 0; } }

.overlay { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; background: rgba(4, 6, 14, .5); z-index: 10; }
.pausecard { width: min(430px, 92vw); text-align: center; background: rgba(14, 18, 36, .94); }
.pausecard .settings { display: grid; gap: 10px; margin: 16px 0 12px; text-align: left; }
.pausecard label { display: flex; align-items: center; justify-content: space-between; gap: 12px; color: var(--muted); font-size: 13px; }
.pausecard input[type=range] { width: 200px; accent-color: var(--accent); }
.pausecard select { width: 200px; }
.pausecard .keys { display: flex; flex-wrap: wrap; gap: 8px 14px; justify-content: center; font-size: 12px; margin-bottom: 8px; }
.pausecard .actions { justify-content: center; }

#toast { position: fixed; left: 50%; top: 18px; transform: translateX(-50%); z-index: 100; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.toast { background: rgba(20, 24, 46, .96); border: 1px solid rgba(255,255,255,.2); padding: 9px 16px; border-radius: 10px; box-shadow: 0 8px 30px rgba(0,0,0,.5); animation: slidein .2s ease-out; transition: opacity .4s; }
.toast.err { border-color: rgba(255, 90, 110, .6); }
.toast.fade { opacity: 0; }

@media (max-width: 900px) {
  #board { width: 200px; font-size: 12px; }
  #shop { width: 330px; }
  #mapwrap { width: 150px; height: 150px; }
}
