:root {
  --bg: #070b14;
  --bg2: #0b1222;
  --panel: rgba(15, 22, 40, 0.92);
  --panel-2: rgba(22, 31, 56, 0.9);
  --line: rgba(140, 170, 255, 0.16);
  --line-2: rgba(140, 170, 255, 0.28);
  --text: #e9efff;
  --muted: #8d99bd;
  --me: #2ee6ff;
  --opp: #ff5277;
  --gold: #ffd166;
  --good: #3ddc97;
  --bad: #ff5d73;
  --radius: 16px;
  --display: "Bahnschrift", "DIN Alternate", "DIN Condensed", "Barlow Condensed", "Roboto Condensed", "Arial Narrow", system-ui, sans-serif;
  --body: "Inter", "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Roboto, Arial, sans-serif;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%; overflow: hidden;
  background: var(--bg); color: var(--text);
  font-family: var(--body); font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}
body::before {
  content: ""; position: fixed; inset: 0; pointer-events: none;
  background:
    radial-gradient(900px 500px at 15% -10%, rgba(46, 230, 255, 0.12), transparent 60%),
    radial-gradient(800px 500px at 110% 110%, rgba(255, 82, 119, 0.12), transparent 60%),
    repeating-linear-gradient(135deg, rgba(255,255,255,0.015) 0 2px, transparent 2px 14px);
}
button, input { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; }
.hidden { display: none !important; }

#app { position: fixed; inset: 0; }
.screen {
  position: absolute; inset: 0; display: none;
  overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: calc(16px + var(--safe-top)) 16px calc(16px + var(--safe-bottom));
}
.screen.active { display: block; animation: screen-in 0.22s ease-out; }
@keyframes screen-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ---------- buttons ---------- */
.primary, .ghost, .danger {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 46px; padding: 0 20px; border-radius: 12px;
  font-family: var(--display); font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; font-size: 15px;
  transition: transform 0.08s ease, filter 0.15s ease, background 0.15s ease, border-color 0.15s;
}
.primary { background: linear-gradient(180deg, #49efff, #14b8dc); color: #03202b; box-shadow: 0 6px 24px rgba(46, 230, 255, 0.25), inset 0 1px 0 rgba(255,255,255,0.5); }
.primary:hover { filter: brightness(1.08); }
.ghost { background: rgba(255,255,255,0.04); border: 1px solid var(--line-2); }
.ghost:hover { background: rgba(255,255,255,0.08); }
.danger { background: rgba(255, 93, 115, 0.12); border: 1px solid rgba(255, 93, 115, 0.5); color: #ffb3bf; }
.danger:hover { background: rgba(255, 93, 115, 0.2); }
.primary:active, .ghost:active, .danger:active, .mode-card:active { transform: scale(0.97); }
button:disabled { opacity: 0.45; cursor: default; filter: grayscale(0.4); }
.wide { width: 100%; }
.icon { width: 46px; padding: 0; }
:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }

/* ---------- home ---------- */
.home-wrap { max-width: 560px; margin: 0 auto; display: flex; flex-direction: column; gap: 18px; min-height: 100%; justify-content: center; }
.brand { text-align: center; margin-top: 4px; }
.logo { width: 74px; height: 74px; margin: 0 auto 6px; position: relative; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #ff9fb4, var(--opp) 45%, #7d0f2b 100%);
  box-shadow: 0 0 34px rgba(255, 82, 119, 0.55), inset 0 -6px 12px rgba(0,0,0,0.35); }
.logo::after { content: ""; position: absolute; inset: 23px; border-radius: 50%; background: radial-gradient(circle at 35% 30%, #fff, #ffc2cf); }
.logo-puck { position: absolute; width: 30px; height: 30px; right: -16px; bottom: -6px; border-radius: 50%;
  background: radial-gradient(circle, #fff4d6 35%, #1a1d27 38%); border: 3px solid var(--gold); box-shadow: 0 0 18px rgba(255, 209, 102, 0.6);
  animation: puck-bob 3s ease-in-out infinite; }
@keyframes puck-bob { 50% { transform: translate(-8px, 4px); } }
.brand h1 { margin: 0; font-family: var(--display); font-weight: 800; font-style: italic; font-size: clamp(40px, 11vw, 64px); letter-spacing: 0.04em; line-height: 0.95; }
.brand h1 span { color: var(--me); text-shadow: 0 0 24px rgba(46, 230, 255, 0.5); margin-left: 6px; }
.brand .tag { margin: 8px 0 0; color: var(--muted); font-family: var(--display); letter-spacing: 0.22em; text-transform: uppercase; font-size: 13px; }

.player-card { display: flex; align-items: center; gap: 14px; width: 100%; text-align: left;
  padding: 12px 16px; border-radius: var(--radius); background: var(--panel); border: 1px solid var(--line); }
.player-card:hover { border-color: var(--line-2); }
.pc-avatar { width: 44px; height: 44px; border-radius: 12px; display: grid; place-items: center; flex: none;
  font-family: var(--display); font-weight: 800; font-size: 20px; color: #03202b; background: linear-gradient(135deg, #7af3ff, #14b8dc); }
.pc-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.pc-name { font-weight: 700; font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pc-sub { color: var(--muted); font-size: 13px; }
.pc-rating { display: flex; flex-direction: column; align-items: flex-end; }
.pc-rating b { font-family: var(--display); font-size: 26px; color: var(--gold); line-height: 1; }
.pc-rating small { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.12em; }

.modes { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.mode-card { position: relative; overflow: hidden; text-align: left; padding: 18px 16px 16px; min-height: 132px;
  border-radius: var(--radius); background: var(--panel); border: 1px solid var(--line);
  display: flex; flex-direction: column; gap: 6px; transition: transform 0.08s, border-color 0.15s, box-shadow 0.2s; }
.mode-card::before { content: ""; position: absolute; inset: 0; opacity: 0.9; pointer-events: none;
  background: radial-gradient(220px 120px at 100% 0%, var(--accent, #fff) -200%, transparent 70%); }
.mode-card:hover { border-color: var(--accent); box-shadow: 0 10px 34px -12px var(--accent); }
.mode-card.ranked { --accent: rgba(255, 209, 102, 0.55); }
.mode-card.casual { --accent: rgba(46, 230, 255, 0.5); }
.mode-card.duel { --accent: rgba(255, 82, 119, 0.5); }
.mode-card.bot { --accent: rgba(61, 220, 151, 0.5); }
.mc-icon { font-size: 22px; line-height: 1; }
.ranked .mc-icon { color: var(--gold); } .casual .mc-icon { color: var(--me); } .duel .mc-icon { color: var(--opp); } .bot .mc-icon { color: var(--good); }
.mc-title { font-family: var(--display); font-weight: 800; font-size: 24px; letter-spacing: 0.04em; text-transform: uppercase; font-style: italic; }
.mc-desc { color: var(--muted); font-size: 13.5px; line-height: 1.35; }

.home-nav { display: flex; gap: 10px; justify-content: center; }
.home-nav .ghost:not(.icon) { flex: 1; }

/* ---------- panels ---------- */
.panel-wrap { max-width: 620px; margin: 0 auto; display: flex; flex-direction: column; gap: 14px; }
.panel-head { display: flex; align-items: center; gap: 12px; }
.panel-head h2 { margin: 0; font-family: var(--display); font-weight: 800; font-style: italic; text-transform: uppercase; letter-spacing: 0.04em; font-size: 28px; }
.back { width: 42px; height: 42px; border-radius: 12px; border: 1px solid var(--line-2); background: rgba(255,255,255,0.04); font-size: 20px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; display: flex; flex-direction: column; gap: 10px; }
.card h3 { margin: 0; font-family: var(--display); text-transform: uppercase; letter-spacing: 0.08em; font-size: 15px; color: var(--muted); }
.hint { margin: 0; color: var(--muted); font-size: 14px; line-height: 1.45; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.center { justify-content: center; }
.row input { flex: 1; min-width: 0; }
input { height: 46px; border-radius: 12px; border: 1px solid var(--line-2); background: rgba(0,0,0,0.25); padding: 0 14px; outline: none; }
input:focus { border-color: var(--me); box-shadow: 0 0 0 3px rgba(46, 230, 255, 0.15); }
.code-input { font-family: var(--display); font-size: 22px; letter-spacing: 0.3em; text-transform: uppercase; text-align: center; }
.loading { color: var(--muted); padding: 16px; text-align: center; }

/* bots */
.bot-list { display: grid; gap: 10px; }
.bot-card { display: grid; grid-template-columns: 1fr auto; gap: 6px 14px; align-items: center; text-align: left;
  padding: 14px 16px; border-radius: var(--radius); background: var(--panel); border: 1px solid var(--line); transition: border-color .15s, transform .08s; }
.bot-card:hover { border-color: var(--bc); }
.bot-card:active { transform: scale(0.98); }
.bot-card .bc-name { font-family: var(--display); font-weight: 800; font-style: italic; text-transform: uppercase; font-size: 22px; color: var(--bc); }
.bot-card .bc-desc { grid-column: 1 / -1; color: var(--muted); font-size: 13.5px; }
.bot-card .bc-bars { grid-column: 1 / -1; display: grid; grid-template-columns: auto 1fr; gap: 4px 10px; align-items: center; font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.08em; }
.bar { height: 6px; border-radius: 3px; background: rgba(255,255,255,0.08); overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--bc); border-radius: 3px; }
.bc-best { font-size: 12px; color: var(--muted); }

/* leaderboard */
.lb { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.lb-row { display: grid; grid-template-columns: 44px 1fr auto 70px; gap: 10px; align-items: center; padding: 11px 14px; border-top: 1px solid var(--line); }
.lb-row:first-child { border-top: 0; }
.lb-row.head { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.1em; background: rgba(255,255,255,0.03); }
.lb-row.me { background: rgba(46, 230, 255, 0.08); }
.lb-rank { font-family: var(--display); font-weight: 800; font-size: 18px; color: var(--muted); }
.lb-row:nth-child(2) .lb-rank { color: var(--gold); } .lb-row:nth-child(3) .lb-rank { color: #d7e1f5; } .lb-row:nth-child(4) .lb-rank { color: #e0a272; }
.lb-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.lb-wl { color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }
.lb-rating { font-family: var(--display); font-weight: 800; font-size: 19px; text-align: right; font-variant-numeric: tabular-nums; }
.prov { display: inline-block; font-size: 10px; font-weight: 800; border-radius: 4px; padding: 1px 4px; margin-left: 6px; color: #241a00; background: var(--gold); vertical-align: 2px; }

/* profile */
.stats-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.stat { background: rgba(255,255,255,0.03); border: 1px solid var(--line); border-radius: 12px; padding: 10px; text-align: center; }
.stat b { display: block; font-family: var(--display); font-size: 22px; }
.stat small { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; }
.history { display: flex; flex-direction: column; gap: 6px; }
.h-row { display: grid; grid-template-columns: 54px 1fr auto auto; gap: 10px; align-items: center; font-size: 14px; padding: 8px 10px; border-radius: 10px; background: rgba(255,255,255,0.03); }
.h-res { font-family: var(--display); font-weight: 800; text-transform: uppercase; }
.h-res.win { color: var(--good); } .h-res.loss { color: var(--bad); } .h-res.void { color: var(--muted); }
.h-mode { color: var(--muted); font-size: 12px; text-transform: uppercase; }
.h-delta.up { color: var(--good); } .h-delta.down { color: var(--bad); }
.rules ul { margin: 0; padding-left: 18px; display: flex; flex-direction: column; gap: 10px; line-height: 1.5; color: #cdd6f2; }
.rules b { color: var(--text); }

/* ---------- queue ---------- */
.queue-wrap { max-width: 440px; margin: 0 auto; min-height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16px; text-align: center; }
.queue-wrap h2 { margin: 0; font-family: var(--display); font-weight: 800; font-style: italic; text-transform: uppercase; font-size: 30px; letter-spacing: 0.04em; }
.q-status { margin: 0; color: var(--muted); min-height: 1.4em; }
.radar { position: relative; width: 180px; height: 180px; border-radius: 50%; border: 1px solid var(--line-2);
  background: radial-gradient(circle, rgba(46,230,255,0.10), transparent 70%); overflow: hidden; }
.radar::before { content: ""; position: absolute; inset: 0; border-radius: 50%;
  background: conic-gradient(from 0deg, rgba(46,230,255,0.45), transparent 25%); animation: sweep 1.6s linear infinite; }
.radar span { position: absolute; inset: 0; margin: auto; border-radius: 50%; border: 1px solid rgba(46,230,255,0.25); }
.radar span:nth-child(1) { width: 60px; height: 60px; } .radar span:nth-child(2) { width: 110px; height: 110px; } .radar span:nth-child(3) { width: 160px; height: 160px; }
.radar-puck { position: absolute; left: 50%; top: 50%; width: 22px; height: 22px; margin: -11px; border-radius: 50%;
  background: radial-gradient(circle, #fff4d6 40%, #1a1d27 43%); border: 3px solid var(--gold); box-shadow: 0 0 16px rgba(255,209,102,0.7); }
@keyframes sweep { to { transform: rotate(360deg); } }
.q-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; width: 100%; }
.q-stats div { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 10px 6px; }
.q-stats b { display: block; font-family: var(--display); font-size: 22px; font-variant-numeric: tabular-nums; }
.q-stats small { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; }
.q-found { display: flex; align-items: center; gap: 14px; font-family: var(--display); font-weight: 800; font-size: 20px; animation: pop 0.35s cubic-bezier(.2,1.6,.4,1); }
.vs { color: var(--gold); font-style: italic; font-size: 26px; }
.vs-name.me { color: var(--me); } .vs-name.opp { color: var(--opp); }
@keyframes pop { from { transform: scale(0.6); opacity: 0; } }

/* ---------- game ---------- */
#screen-game { padding: 0; overflow: hidden; touch-action: none; user-select: none; -webkit-user-select: none; }
#table { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; cursor: none; }
.hud { position: absolute; left: 0; right: 0; top: 0; height: calc(56px + var(--safe-top)); padding: var(--safe-top) 8px 0;
  display: grid; grid-template-columns: 44px 1fr auto 1fr 44px; align-items: center; gap: 8px; pointer-events: none;
  background: linear-gradient(180deg, rgba(7,11,20,0.95), rgba(7,11,20,0.6) 70%, transparent); }
.hud > * { pointer-events: auto; }
.hud-btn { width: 40px; height: 40px; border-radius: 12px; background: rgba(255,255,255,0.06); border: 1px solid var(--line-2); font-size: 14px; display: grid; place-items: center; }
.hud-player { display: flex; flex-direction: column; min-width: 0; pointer-events: none; }
.hud-player.me { align-items: flex-end; text-align: right; }
.hud-player.opp { align-items: flex-start; }
.hp-name { font-weight: 700; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.hud-player.me .hp-name { color: var(--me); } .hud-player.opp .hp-name { color: var(--opp); }
.hp-sub { font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }
.hud-score { display: flex; align-items: center; gap: 6px; font-family: var(--display); font-weight: 800; font-variant-numeric: tabular-nums; pointer-events: none; }
.sc { font-size: 34px; min-width: 34px; text-align: center; line-height: 1; }
.sc.me { color: var(--me); text-shadow: 0 0 18px rgba(46,230,255,0.5); }
.sc.opp { color: var(--opp); text-shadow: 0 0 18px rgba(255,82,119,0.5); }
.sc.bump { animation: bump 0.5s ease-out; }
@keyframes bump { 30% { transform: scale(1.5); } }
.sc-sep small { display: block; font-size: 10px; letter-spacing: 0.14em; color: var(--muted); padding: 3px 6px; border: 1px solid var(--line-2); border-radius: 6px; }
.ping { position: absolute; right: 10px; bottom: calc(8px + var(--safe-bottom)); font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; pointer-events: none; }
.ping.warn { color: var(--gold); } .ping.bad { color: var(--bad); }

.center-msg { position: absolute; left: 0; right: 0; top: 50%; transform: translateY(-50%); text-align: center; pointer-events: none;
  font-family: var(--display); font-weight: 800; font-style: italic; text-transform: uppercase; letter-spacing: 0.04em;
  font-size: clamp(42px, 12vw, 96px); text-shadow: 0 4px 30px rgba(0,0,0,0.6); }
.center-msg.show { animation: msg-in 0.5s cubic-bezier(.2,1.5,.4,1); }
.center-msg .sub { display: block; font-size: 0.28em; letter-spacing: 0.18em; font-style: normal; color: var(--text); opacity: 0.85; margin-top: 6px; }
.center-msg.me { color: var(--me); } .center-msg.opp { color: var(--opp); } .center-msg.neutral { color: var(--text); } .center-msg.gold { color: var(--gold); }
@keyframes msg-in { from { transform: translateY(-50%) scale(0.5); opacity: 0; } }

.banner { position: absolute; left: 50%; top: calc(64px + var(--safe-top)); transform: translateX(-50%); padding: 10px 16px; border-radius: 12px;
  background: rgba(15,22,40,0.95); border: 1px solid rgba(255,209,102,0.5); color: var(--gold); font-weight: 600; font-size: 14px; white-space: nowrap;
  box-shadow: 0 10px 30px rgba(0,0,0,0.4); pointer-events: none; }

.overlay { position: absolute; inset: 0; display: grid; place-items: center; padding: 16px; background: rgba(4, 7, 14, 0.66); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); animation: fade 0.2s ease-out; z-index: 5; }
@keyframes fade { from { opacity: 0; } }
.ov-card { width: min(440px, 100%); background: var(--panel); border: 1px solid var(--line-2); border-radius: 20px; padding: 22px; display: flex; flex-direction: column; gap: 12px; text-align: center; box-shadow: 0 30px 80px rgba(0,0,0,0.5); animation: pop 0.3s cubic-bezier(.2,1.4,.4,1); }
.ov-card.small { width: min(340px, 100%); }
.ov-card h2 { margin: 0; font-family: var(--display); font-weight: 800; font-style: italic; text-transform: uppercase; letter-spacing: 0.04em; }
.big-code { font-family: var(--display); font-weight: 800; font-size: 44px; letter-spacing: 0.25em; color: var(--gold); padding: 8px 0 8px 0.25em; border: 1px dashed rgba(255,209,102,0.5); border-radius: 14px; background: rgba(255,209,102,0.05); }
.link-box { display: flex; gap: 8px; }
.link-box input { flex: 1; min-width: 0; font-size: 13px; color: var(--muted); }

.results { gap: 10px; }
.res-title { font-family: var(--display); font-weight: 800; font-style: italic; font-size: 52px; letter-spacing: 0.04em; line-height: 1; }
.res-title.win { color: var(--me); text-shadow: 0 0 30px rgba(46,230,255,0.5); }
.res-title.loss { color: var(--opp); text-shadow: 0 0 30px rgba(255,82,119,0.4); }
.res-title.void { color: var(--muted); }
.res-reason { color: var(--muted); font-size: 14px; min-height: 1em; }
.res-score { font-family: var(--display); font-weight: 800; font-size: 64px; line-height: 1; display: flex; justify-content: center; gap: 18px; font-variant-numeric: tabular-nums; }
.res-score .me { color: var(--me); } .res-score .opp { color: var(--opp); } .res-score .dash { color: var(--muted); }
.res-names { display: flex; justify-content: center; gap: 56px; font-size: 13px; color: var(--muted); margin-top: -4px; }
.res-rating { display: flex; justify-content: center; align-items: baseline; gap: 10px; font-family: var(--display); font-weight: 800; font-size: 24px; padding: 10px; border-radius: 12px; background: rgba(255,255,255,0.04); border: 1px solid var(--line); }
.rr-before { color: var(--muted); } .rr-arrow { color: var(--muted); font-size: 18px; } .rr-after { color: var(--gold); }
.rr-delta { font-size: 18px; } .rr-delta.up { color: var(--good); } .rr-delta.down { color: var(--bad); }
.res-note { color: var(--muted); font-size: 13px; min-height: 0; }
.res-stats { display: flex; justify-content: center; gap: 18px; color: var(--muted); font-size: 13px; }
.res-stats b { color: var(--text); }
.res-actions { display: flex; flex-direction: column; gap: 8px; margin-top: 4px; }
.vote-dots { display: inline-flex; gap: 4px; margin-left: 6px; }
.vote-dots i { width: 8px; height: 8px; border-radius: 50%; background: rgba(0,0,0,0.25); border: 1px solid rgba(0,0,0,0.4); }
.vote-dots i.on { background: #03202b; }

.toast-host { position: fixed; left: 50%; bottom: calc(18px + var(--safe-bottom)); transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 50; width: min(420px, calc(100% - 24px)); pointer-events: none; }
.toast { padding: 12px 16px; border-radius: 12px; background: rgba(20,28,50,0.97); border: 1px solid var(--line-2); box-shadow: 0 12px 30px rgba(0,0,0,0.45); font-size: 14px; animation: toast-in 0.25s ease-out; }
.toast.err { border-color: rgba(255,93,115,0.6); }
.toast.ok { border-color: rgba(61,220,151,0.6); }
@keyframes toast-in { from { transform: translateY(10px); opacity: 0; } }

@media (max-width: 420px) {
  .mode-card { min-height: 118px; padding: 14px 12px; }
  .mc-title { font-size: 20px; }
  .mc-desc { font-size: 12.5px; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .hud { grid-template-columns: 40px 1fr auto 1fr 40px; gap: 6px; }
  .sc { font-size: 28px; min-width: 26px; }
  .res-title { font-size: 44px; }
  .res-score { font-size: 54px; }
}
@media (max-height: 640px) and (orientation: landscape) {
  .home-wrap { justify-content: flex-start; }
  .brand .logo { display: none; }
  .mode-card { min-height: 96px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; }
}
