:root {
  --bg: #120f26;
  --bg2: #1b1638;
  --card: rgba(34, 28, 68, 0.86);
  --card-b: rgba(255, 255, 255, 0.08);
  --text: #f4f1ff;
  --muted: #a49ec9;
  --accent: #ffd43b;
  --accent-ink: #2a2100;
  --pink: #f783ac;
  --danger: #ff6b6b;
  --ok: #69db7c;
  --radius: 16px;
  --font: 'Fredoka', 'Segoe UI', system-ui, -apple-system, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font-family: var(--font); font-size: 15px; }
body {
  background:
    radial-gradient(900px 600px at 10% -10%, rgba(255, 212, 59, 0.14), transparent 60%),
    radial-gradient(900px 700px at 110% 20%, rgba(247, 131, 172, 0.14), transparent 60%),
    radial-gradient(800px 600px at 50% 120%, rgba(77, 171, 247, 0.14), transparent 60%),
    var(--bg);
  overflow-x: hidden;
}
[hidden] { display: none !important; }
h1, h2, h3 { margin: 0 0 .5em; font-weight: 700; letter-spacing: .01em; }
h1 { font-size: 2.1rem; }
h2 { font-size: 1.25rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
kbd {
  display: inline-block; padding: 1px 7px; border-radius: 6px; background: rgba(255, 255, 255, .1);
  border: 1px solid rgba(255, 255, 255, .18); border-bottom-width: 2px; font-family: var(--font); font-size: .82em; color: var(--text);
}

.screen { min-height: 100vh; padding: 28px clamp(16px, 4vw, 48px); }
.card {
  background: var(--card); border: 1px solid var(--card-b); border-radius: var(--radius); padding: 20px;
  box-shadow: 0 18px 50px rgba(0, 0, 0, .35); backdrop-filter: blur(10px);
}
.card.narrow { max-width: 760px; margin: 4vh auto; }
.card-head { display: flex; align-items: center; gap: 12px; justify-content: space-between; margin-bottom: 6px; }
.card-head h2 { margin: 0; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-top: 14px; }
.row.end { justify-content: flex-end; }

.btn {
  font-family: var(--font); font-size: 1rem; font-weight: 600; color: var(--text); cursor: pointer;
  background: rgba(255, 255, 255, .1); border: 1px solid rgba(255, 255, 255, .16); border-radius: 12px; padding: 9px 16px;
  transition: transform .08s, background .15s, box-shadow .15s;
}
.btn:hover { background: rgba(255, 255, 255, .16); }
.btn:active { transform: translateY(1px) scale(.98); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; box-shadow: 0 6px 0 #c9a10c, 0 10px 24px rgba(255, 212, 59, .25); }
.btn.primary:hover { background: #ffe066; }
.btn.primary:active { box-shadow: 0 3px 0 #c9a10c; transform: translateY(3px); }
.btn.danger { background: rgba(255, 107, 107, .18); border-color: rgba(255, 107, 107, .5); }
.btn.ghost { background: transparent; }
.btn.big { font-size: 1.1rem; padding: 12px 22px; }
.btn:disabled { opacity: .45; cursor: not-allowed; }

.field { display: flex; flex-direction: column; gap: 6px; margin: 12px 0; }
.field > span { font-size: .85rem; color: var(--muted); font-weight: 500; }
input, select {
  font-family: var(--font); font-size: 1rem; color: var(--text); background: rgba(0, 0, 0, .28);
  border: 1px solid rgba(255, 255, 255, .14); border-radius: 10px; padding: 9px 12px; outline: none; min-width: 0;
}
input:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(255, 212, 59, .2); }
select option { background: #221c44; }
input[type=range] { padding: 0; accent-color: var(--accent); }

/* ---------- menu ---------- */
.brand { display: flex; align-items: center; gap: 18px; margin-bottom: 22px; }
.brand h1 { margin: 0; font-size: clamp(1.8rem, 4vw, 2.8rem); background: linear-gradient(90deg, #ffd43b, #ff922b 45%, #f783ac); -webkit-background-clip: text; background-clip: text; color: transparent; }
.tag { margin: 4px 0 0; color: var(--muted); }
.logo { width: 76px; height: 76px; animation: bob 2.4s ease-in-out infinite; filter: drop-shadow(0 8px 18px rgba(255, 212, 59, .35)); }
.logo svg { width: 100%; height: 100%; }
@keyframes bob { 50% { transform: translateY(-6px) rotate(-6deg); } }
.menu-grid { display: grid; grid-template-columns: minmax(260px, 320px) 1fr minmax(260px, 330px); gap: 18px; align-items: start; }
@media (max-width: 1050px) { .menu-grid { grid-template-columns: 1fr; } }
.swatches { display: flex; flex-wrap: wrap; gap: 8px; }
.swatch { width: 34px; height: 34px; border-radius: 50%; border: 3px solid transparent; cursor: pointer; padding: 0; background: none; position: relative; }
.swatch svg { width: 100%; height: 100%; display: block; }
.swatch.sel { border-color: #fff; box-shadow: 0 0 0 3px rgba(255, 255, 255, .2); }
.swatch.taken { opacity: .25; cursor: not-allowed; }
.swatch.bot::after { content: '🤖'; position: absolute; right: -6px; bottom: -6px; font-size: 12px; }
#btn-create { width: 100%; margin-top: 8px; }
.howto ul.keys { list-style: none; padding: 0; margin: 0 0 12px; display: grid; gap: 8px; }

.room-list { display: grid; gap: 10px; }
.room-item { display: grid; grid-template-columns: 1fr auto; gap: 10px; align-items: center; padding: 14px 16px; border-radius: 14px; background: rgba(255, 255, 255, .05); border: 1px solid rgba(255, 255, 255, .07); }
.room-item:hover { background: rgba(255, 255, 255, .08); }
.room-item h3 { margin: 0 0 4px; font-size: 1.1rem; }
.room-item .meta { display: flex; flex-wrap: wrap; gap: 6px 14px; color: var(--muted); font-size: .85rem; }
.pill { display: inline-flex; align-items: center; gap: 4px; padding: 2px 9px; border-radius: 999px; font-size: .78rem; font-weight: 600; }
.pill.wait { background: rgba(105, 219, 124, .18); color: var(--ok); }
.pill.live { background: rgba(255, 107, 107, .18); color: #ffa8a8; }
.pill.done { background: rgba(255, 255, 255, .1); color: var(--muted); }
.empty { text-align: center; padding: 40px 10px; color: var(--muted); }
.empty .big-smiley { width: 64px; height: 64px; margin: 0 auto 10px; opacity: .8; }

/* ---------- create / rules ---------- */
.rules-form { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 4px 14px; }
.rules-form .field { margin: 8px 0; }
.rules-form .field.wide { grid-column: 1 / -1; }
.rules-form.readonly select, .rules-form.readonly input { pointer-events: none; opacity: .85; background: rgba(255, 255, 255, .04); border-style: dashed; }

/* ---------- room ---------- */
.room-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 16px; }
.room-head h1 { margin: 0; }
.room-grid { display: grid; grid-template-columns: minmax(250px, 1fr) minmax(320px, 1.6fr) minmax(260px, 1fr); gap: 18px; align-items: start; }
@media (max-width: 1100px) { .room-grid { grid-template-columns: 1fr; } }
.players { display: grid; gap: 6px; margin-bottom: 8px; }
.player-row { display: flex; align-items: center; gap: 10px; padding: 7px 10px; border-radius: 12px; background: rgba(255, 255, 255, .05); }
.player-row .name { flex: 1; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.player-row.me { outline: 2px solid rgba(255, 212, 59, .5); }
.tagx { font-size: .72rem; padding: 1px 7px; border-radius: 999px; background: rgba(255, 255, 255, .1); color: var(--muted); }
.tagx.host { background: rgba(255, 212, 59, .18); color: var(--accent); }
.chat-card { display: flex; flex-direction: column; }
.chat-log { height: 300px; overflow-y: auto; display: flex; flex-direction: column; gap: 4px; padding: 6px; background: rgba(0, 0, 0, .2); border-radius: 10px; margin-bottom: 8px; font-size: .92rem; }
.chat-log .sys { color: var(--muted); font-style: italic; }
.chat-form { display: flex; gap: 8px; }
.chat-form input { flex: 1; }
.room-foot { display: flex; justify-content: flex-end; align-items: center; gap: 16px; margin-top: 18px; flex-wrap: wrap; }

/* ---------- game ---------- */
.screen.game { padding: 0; position: fixed; inset: 0; overflow: hidden; background: #000; }
#view { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
#vignette { position: absolute; inset: 0; pointer-events: none; opacity: 0; transition: opacity .35s; background: radial-gradient(ellipse at center, transparent 45%, rgba(255, 30, 60, .55) 100%); }
#vignette.on { opacity: 1; transition: none; }
#hud { position: absolute; inset: 0; pointer-events: none; user-select: none; }
.panel { background: rgba(14, 11, 32, .55); border: 1px solid rgba(255, 255, 255, .1); border-radius: 14px; backdrop-filter: blur(6px); }
.hud-tl { position: absolute; left: 16px; top: 16px; padding: 10px 16px; min-width: 150px; }
.hud-score { font-size: 2rem; font-weight: 700; line-height: 1; }
.hud-score small { font-size: .9rem; color: var(--muted); margin-left: 4px; }
.hud-money { font-size: 1.25rem; font-weight: 600; color: var(--ok); margin-top: 2px; }
.hud-kd { font-size: .8rem; color: var(--muted); margin-top: 2px; }
.hud-tc { position: absolute; left: 50%; top: 16px; transform: translateX(-50%); padding: 6px 18px; text-align: center; }
#hud-timer { font-size: 1.6rem; font-weight: 700; font-variant-numeric: tabular-nums; }
#hud-timer.low { color: var(--danger); animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: .55; } }
.hud-tr { position: absolute; right: 16px; top: 16px; width: 250px; display: flex; flex-direction: column; gap: 8px; }
#hud-board { padding: 8px; display: grid; gap: 2px; }
.brow { display: grid; grid-template-columns: 16px 20px 1fr auto; gap: 6px; align-items: center; font-size: .88rem; padding: 2px 6px; border-radius: 8px; }
.brow.me { background: rgba(255, 212, 59, .16); }
.brow.dead { opacity: .45; }
.brow .rk { color: var(--muted); font-size: .75rem; }
.brow .nm { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.brow .sc { font-weight: 700; font-variant-numeric: tabular-nums; }
.brow svg { width: 18px; height: 18px; display: block; }
.feed { display: flex; flex-direction: column; gap: 4px; align-items: flex-end; }
.feed .fi { background: rgba(14, 11, 32, .6); border-radius: 10px; padding: 4px 10px; font-size: .85rem; display: flex; gap: 6px; align-items: center; animation: slidein .2s ease-out; transition: opacity .5s; }
.feed .fi.info { opacity: .75; font-size: .78rem; }
.feed .fi b { font-weight: 600; }
@keyframes slidein { from { transform: translateX(20px); opacity: 0; } }
.hud-r { position: absolute; left: 16px; top: 132px; width: 260px; }
.hud-r .feed { align-items: flex-start; }
.feed-title { text-align: left; font-size: .75rem; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; margin-bottom: 4px; }
.feed.mine .fi { background: rgba(255, 212, 59, .14); border: 1px solid rgba(255, 212, 59, .25); }
.feed.mine .fi.ko { background: rgba(255, 107, 107, .22); border-color: rgba(255, 107, 107, .5); }
.feed .pts { color: var(--ok); font-weight: 700; }
.hud-bl { position: absolute; left: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; align-items: flex-start; }
#minimap { display: block; }
.chat-lines { display: flex; flex-direction: column; gap: 3px; max-width: 420px; }
.chat-lines div { background: rgba(14, 11, 32, .55); padding: 3px 10px; border-radius: 8px; font-size: .88rem; transition: opacity 1s; }
.game-chat { pointer-events: auto; }
.game-chat input { width: 380px; }
.hud-bc { position: absolute; left: 50%; bottom: 18px; transform: translateX(-50%); display: flex; flex-direction: column; align-items: center; gap: 8px; }
.lives-panel { display: flex; align-items: center; gap: 10px; padding: 8px 14px; }
.lives { display: flex; gap: 4px; font-size: 1.6rem; line-height: 1; }
.lives .h { filter: drop-shadow(0 2px 3px rgba(0, 0, 0, .5)); transition: transform .2s; }
.lives .h.off { filter: grayscale(1) brightness(.5); opacity: .5; }
.lives.hurt .h { animation: shake .3s; }
@keyframes shake { 25% { transform: translateX(-3px); } 75% { transform: translateX(3px); } }
.shield-pill { font-size: 1.4rem; padding: 0 6px; border-radius: 999px; background: rgba(59, 201, 219, .2); border: 1px solid rgba(59, 201, 219, .6); }
.shield-pill.off { opacity: .35; filter: grayscale(1); }
.cooldown { width: 200px; height: 6px; border-radius: 6px; background: rgba(255, 255, 255, .12); overflow: hidden; }
#hud-cd { height: 100%; width: 100%; background: var(--accent); border-radius: 6px; }
.ups { display: flex; gap: 4px; flex-wrap: wrap; justify-content: center; max-width: 520px; }
.ups span { background: rgba(14, 11, 32, .6); border: 1px solid rgba(255, 255, 255, .1); border-radius: 8px; padding: 1px 6px; font-size: .85rem; }
.ups sup { color: var(--accent); font-weight: 700; margin-left: 1px; }
.status { font-weight: 600; text-shadow: 0 2px 6px rgba(0, 0, 0, .8); min-height: 1.2em; color: #a5f3fc; }
.hud-br { position: absolute; right: 16px; bottom: 16px; display: flex; gap: 10px; text-shadow: 0 1px 3px #000; }
#crosshair { position: absolute; left: 50%; top: 50%; width: 26px; height: 26px; transform: translate(-50%, -50%); }
#crosshair i { position: absolute; background: #fff; box-shadow: 0 0 3px rgba(0, 0, 0, .9); border-radius: 2px; }
#crosshair i:nth-child(1) { left: 12px; top: 0; width: 2px; height: 8px; }
#crosshair i:nth-child(2) { left: 12px; bottom: 0; width: 2px; height: 8px; }
#crosshair i:nth-child(3) { top: 12px; left: 0; height: 2px; width: 8px; }
#crosshair i:nth-child(4) { top: 12px; right: 0; height: 2px; width: 8px; }
#hitmarker { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%) scale(.6); font-size: 34px; font-weight: 700; color: #fff; opacity: 0; text-shadow: 0 0 6px rgba(0, 0, 0, .8); }
#hitmarker.on { animation: hm .35s ease-out; }
#hitmarker.ko { color: var(--danger); }
@keyframes hm { 0% { opacity: 1; transform: translate(-50%, -50%) scale(1.3); } 100% { opacity: 0; transform: translate(-50%, -50%) scale(.8); } }
#dmg-dir { position: absolute; left: 50%; top: 50%; width: 260px; height: 260px; margin: -130px 0 0 -130px; border-radius: 50%; opacity: 0; transition: opacity .8s;
  background: conic-gradient(from -20deg, rgba(255, 50, 70, .9) 0 40deg, transparent 40deg); -webkit-mask: radial-gradient(circle, transparent 112px, #000 114px, #000 128px, transparent 130px); mask: radial-gradient(circle, transparent 112px, #000 114px, #000 128px, transparent 130px); }
#dmg-dir.on { opacity: 1; transition: none; }
#popups { position: absolute; left: 50%; top: 44%; }
.popup { position: absolute; transform: translate(-50%, 0); font-weight: 700; font-size: 1.5rem; color: var(--ok); text-shadow: 0 2px 6px rgba(0, 0, 0, .8); animation: rise 1s ease-out forwards; white-space: nowrap; }
.popup.ko { color: var(--accent); font-size: 1.9rem; }
@keyframes rise { to { transform: translate(-50%, -60px); opacity: 0; } }

/* ---------- overlays ---------- */
.overlay { position: absolute; inset: 0; display: grid; place-items: center; background: rgba(10, 8, 24, .6); backdrop-filter: blur(4px); padding: 20px; overflow-y: auto; }
.overlay.soft { background: rgba(10, 8, 24, .35); backdrop-filter: none; pointer-events: none; }
#death { background: rgba(30, 10, 30, .35); backdrop-filter: grayscale(.85); }
.death-box { text-align: center; text-shadow: 0 2px 8px rgba(0, 0, 0, .8); }
.death-box h2 { font-size: 2.2rem; margin: 6px 0; }
.big-smiley { width: 90px; height: 90px; margin: 0 auto; }
.big-smiley svg { width: 100%; height: 100%; }
.respawn { font-size: 1.4rem; margin: 8px 0; }
.respawn b { color: var(--accent); font-size: 2rem; font-variant-numeric: tabular-nums; }
.pause-card { width: min(440px, 100%); text-align: center; }
.pause-card .btn.big { width: 100%; margin: 6px 0 4px; }
.pause-card .row { justify-content: center; }
.shop-card { width: min(980px, 100%); }
.shop-money { font-size: 1.6rem; font-weight: 700; color: var(--ok); margin-left: auto; }
.shop-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 10px; margin-top: 10px; }
.up-card { display: flex; flex-direction: column; gap: 6px; padding: 12px; border-radius: 14px; background: rgba(255, 255, 255, .05); border: 1px solid rgba(255, 255, 255, .08); text-align: left; font-family: var(--font); color: var(--text); cursor: pointer; transition: transform .1s, background .15s, border-color .15s; }
.up-card:hover:not(:disabled) { background: rgba(255, 212, 59, .1); border-color: rgba(255, 212, 59, .45); transform: translateY(-2px); }
.up-card:disabled { cursor: default; }
.up-card.poor { opacity: .55; }
.up-card.maxed { opacity: .7; border-color: rgba(105, 219, 124, .35); }
.up-top { display: flex; align-items: center; gap: 8px; }
.up-icon { font-size: 1.6rem; }
.up-name { font-weight: 700; flex: 1; }
.up-pips { display: flex; gap: 3px; }
.up-pips i { width: 9px; height: 9px; border-radius: 50%; background: rgba(255, 255, 255, .15); }
.up-pips i.on { background: var(--accent); }
.up-desc { font-size: .85rem; color: var(--muted); min-height: 2.4em; }
.up-cost { font-weight: 700; color: var(--ok); }
.up-card.poor .up-cost { color: var(--danger); }
.score-card { width: min(860px, 100%); }
.score-table { width: 100%; border-collapse: collapse; font-size: .95rem; }
.score-table th { text-align: left; color: var(--muted); font-weight: 500; font-size: .8rem; padding: 6px 8px; border-bottom: 1px solid rgba(255, 255, 255, .1); }
.score-table td { padding: 6px 8px; border-bottom: 1px solid rgba(255, 255, 255, .05); }
.score-table tr.me td { background: rgba(255, 212, 59, .1); }
.score-table .pn { display: flex; align-items: center; gap: 8px; font-weight: 600; }
.score-table .pn svg { width: 22px; height: 22px; }
.score-table .upl { font-size: .85rem; letter-spacing: 1px; }
#bigmap canvas { max-width: min(90vw, 90vh); max-height: min(90vw, 90vh); border-radius: 18px; background: rgba(14, 11, 32, .75); }
.end-card { width: min(820px, 100%); text-align: center; }
.end-card h1 { font-size: 2.6rem; }
.podium { display: flex; justify-content: center; align-items: flex-end; gap: 18px; margin: 10px 0 18px; }
.pod { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.pod .face svg { width: 64px; height: 64px; }
.pod.p1 .face svg { width: 90px; height: 90px; animation: bob 1.6s ease-in-out infinite; }
.pod .block { width: 110px; border-radius: 12px 12px 0 0; background: linear-gradient(180deg, rgba(255, 212, 59, .5), rgba(255, 212, 59, .1)); display: grid; place-items: center; font-weight: 700; font-size: 1.4rem; }
.pod.p1 .block { height: 90px; }
.pod.p2 .block { height: 64px; background: linear-gradient(180deg, rgba(220, 220, 240, .45), rgba(220, 220, 240, .08)); }
.pod.p3 .block { height: 44px; background: linear-gradient(180deg, rgba(205, 127, 50, .5), rgba(205, 127, 50, .08)); }
.pod .pname { font-weight: 600; max-width: 130px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.end-card .row.end { justify-content: flex-end; }

#toasts { position: fixed; top: 80px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; align-items: center; z-index: 50; pointer-events: none; }
.toast { background: rgba(14, 11, 32, .88); border: 1px solid rgba(255, 255, 255, .15); padding: 8px 16px; border-radius: 12px; font-weight: 500; animation: slidein .2s ease-out; transition: opacity .4s; }
.toast.err { border-color: rgba(255, 107, 107, .6); }
.toast.good { border-color: rgba(105, 219, 124, .6); }
#conn-banner { position: fixed; top: 0; left: 0; right: 0; padding: 10px; text-align: center; background: var(--danger); color: #fff; font-weight: 600; z-index: 100; }
