:root {
  --bg: #0b1020; --panel: #141c36; --panel2: #1b2546; --line: #2a3766;
  --ink: #e8edff; --muted: #8f9bc7; --acc: #5ee6a8; --acc2: #7aa7ff; --danger: #ff7a8a;
  color-scheme: dark;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%; overflow: hidden; color: var(--ink);
  background: radial-gradient(1200px 800px at 50% -10%, #1f2d5c 0%, var(--bg) 60%);
  -webkit-user-select: none; user-select: none; -webkit-tap-highlight-color: transparent;
}
input, select, button { font: inherit; color: inherit; }
input, select {
  width: 100%; margin-top: 6px; padding: 10px 12px; border-radius: 10px;
  border: 1px solid var(--line); background: #0e1530; user-select: text; outline: none;
}
input:focus, select:focus { border-color: var(--acc2); box-shadow: 0 0 0 3px rgba(122, 167, 255, .2); }
label { display: block; font-size: 14px; color: var(--muted); }
h1, h2, h3 { margin: 0; font-weight: 700; }
h2 { font-size: 20px; }
h3 { font-size: 14px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.muted { color: var(--muted); font-size: 14px; margin: 0; }
.empty { color: var(--muted); text-align: center; padding: 32px 0; }
.hidden { display: none !important; }
.center-text { text-align: center; }
.stack { display: flex; flex-direction: column; gap: 14px; }
.row { display: flex; gap: 10px; align-items: center; }
.row.between { justify-content: space-between; }
.row.end { justify-content: flex-end; }
.wrap { flex-wrap: wrap; }

.btn {
  padding: 10px 16px; border-radius: 10px; border: 1px solid var(--line); background: var(--panel2);
  cursor: pointer; transition: transform .08s, border-color .15s, filter .15s; white-space: nowrap;
}
.btn:hover { border-color: var(--acc2); }
.btn:active { transform: translateY(1px) scale(.98); }
.btn.primary { background: linear-gradient(135deg, #3ad49a, #2fb0c9); color: #04131c; border-color: transparent; font-weight: 700; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; }
.btn.danger { background: rgba(255, 122, 138, .12); border-color: rgba(255, 122, 138, .4); color: var(--danger); }
.btn.on { border-color: var(--acc); color: var(--acc); }
.btn.sm { padding: 6px 12px; font-size: 14px; }

.card {
  width: min(92vw, 520px); padding: 28px; border-radius: 18px;
  background: linear-gradient(180deg, var(--panel), #0f1530); border: 1px solid var(--line);
  box-shadow: 0 20px 60px rgba(0, 0, 0, .45);
}
.card.narrow { width: min(92vw, 420px); }
.logo { font-size: clamp(34px, 7vw, 52px); letter-spacing: -.02em; }
.logo span, .brand span { color: var(--acc); }

.screen { display: none; position: fixed; inset: 0; overflow: auto; flex-direction: column; }
body[data-view="name"] #s-name, body[data-view="lobby"] #s-lobby, body[data-view="room"] #s-room { display: flex; }
#s-name.center { align-items: center; justify-content: center; }
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  padding: 16px 24px; border-bottom: 1px solid var(--line); background: rgba(11, 16, 32, .6); backdrop-filter: blur(8px);
}
.brand { font-size: 20px; font-weight: 800; letter-spacing: -.01em; }
.content { width: min(1040px, 100%); margin: 0 auto; padding: 24px; display: flex; flex-direction: column; gap: 18px; }

.rooms { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; }
.room {
  text-align: left; padding: 16px; border-radius: 14px; border: 1px solid var(--line); background: var(--panel);
  cursor: pointer; display: flex; flex-direction: column; gap: 10px; transition: border-color .15s, transform .1s;
}
.room:hover { border-color: var(--acc2); transform: translateY(-2px); }
.room-top { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.room-name { font-weight: 700; font-size: 17px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.room-meta { display: flex; gap: 10px; color: var(--muted); font-size: 13px; flex-wrap: wrap; }
.badge { font-size: 12px; padding: 2px 8px; border-radius: 999px; background: rgba(122, 167, 255, .15); color: var(--acc2); }
.lock { color: #ffd479; }

.teams { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.team { padding: 16px; border-radius: 14px; border: 1px solid var(--line); background: var(--panel); }
.team.t0 { border-top: 3px solid #5ea8ff; }
.team.t1 { border-top: 3px solid #ff8a6b; }
.plist { list-style: none; padding: 0; margin: 12px 0 0; display: flex; flex-direction: column; gap: 8px; min-height: 40px; }
.player { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 10px; background: var(--panel2); }
.chip { width: 14px; height: 14px; border-radius: 50%; box-shadow: 0 0 0 2px rgba(255, 255, 255, .15); flex: none; }
.pname { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pname small { color: var(--muted); }
.tag { font-size: 12px; padding: 2px 8px; border-radius: 999px; background: #222c52; color: var(--muted); }
.tag.ok { background: rgba(94, 230, 168, .15); color: var(--acc); }

.chat { display: flex; flex-direction: column; gap: 8px; }
.chatlog {
  height: 180px; overflow-y: auto; padding: 10px 12px; border-radius: 12px; font-size: 14px;
  background: rgba(5, 9, 22, .6); border: 1px solid var(--line); user-select: text;
}
.msg { padding: 3px 0; overflow-wrap: anywhere; }
.msg b { color: var(--acc2); font-weight: 600; }
.msg.self b { color: var(--acc); }
.chat form input { margin-top: 0; }
.chat form .btn { flex: none; }

/* in-match */
#game { display: none; position: fixed; inset: 0; width: 100%; height: 100%; background: #07101f; touch-action: none; }
body[data-view="game"] #game { display: block; }
#hud { display: none; position: fixed; inset: 0; pointer-events: none; }
body[data-view="game"] #hud { display: block; }
#hud button, #hud input, #hud .chat-panel { pointer-events: auto; }
.hud-actions { position: absolute; top: 12px; right: 12px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; justify-content: flex-end; }
.ping { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; margin-right: 4px; }
.chat-panel {
  position: absolute; left: 12px; bottom: 12px; width: min(360px, 60vw); padding: 10px; border-radius: 14px;
  background: rgba(11, 16, 32, .75); border: 1px solid var(--line); display: none; flex-direction: column; gap: 8px;
}
.chat-panel.open { display: flex; }
.chat-panel .chatlog { height: 140px; }
.chat-panel input { margin-top: 0; }
#touch { display: none; position: fixed; inset: auto 0 16px 0; justify-content: space-between; padding: 0 16px; pointer-events: none; }
body[data-view="game"] #touch { display: flex; }
@media (hover: hover) and (pointer: fine) { #touch { display: none !important; } }
#touch .pad { display: flex; gap: 12px; pointer-events: auto; }
#touch button {
  width: 76px; height: 76px; border-radius: 50%; border: 1px solid var(--line);
  background: rgba(27, 37, 70, .7); font-size: 16px; font-weight: 700; touch-action: none;
}
#touch button.kick { background: rgba(94, 230, 168, .25); }
#touch .pad.tilt { flex-direction: column; gap: 8px; }
#touch .pad.tilt button { width: 56px; height: 56px; font-size: 22px; }
.hint { margin-top: 10px; }

.overlay {
  display: none; position: fixed; inset: 0; align-items: center; justify-content: center;
  background: rgba(5, 9, 22, .6); backdrop-filter: blur(4px);
}
.overlay.show { display: flex; }
.modal { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; background: rgba(5, 9, 22, .7); z-index: 20; }
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); opacity: 0;
  padding: 10px 16px; border-radius: 10px; background: #0e1530; border: 1px solid var(--line);
  transition: opacity .2s, transform .2s; pointer-events: none; z-index: 30; max-width: 90vw;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* offline entry + setup */
.btn.block { width: 100%; }
.btn.lg { padding: 12px 22px; font-size: 16px; }
.cta {
  display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap;
  padding: 18px 20px; border-radius: 16px; border: 1px solid var(--line);
  background: linear-gradient(135deg, rgba(94, 230, 168, .14), rgba(122, 167, 255, .10)), var(--panel);
}
.cta h2 { margin-bottom: 4px; }
.seg-group { border: 0; margin: 0; padding: 0; min-width: 0; display: flex; flex-direction: column; gap: 8px; }
.seg-group legend { padding: 0; margin-bottom: 6px; font-size: 14px; color: var(--muted); }
.seg-row { display: flex; gap: 8px; }
.seg { flex: 1; position: relative; display: block; margin: 0; }
.seg input { position: absolute; opacity: 0; width: 1px; height: 1px; margin: 0; padding: 0; border: 0; pointer-events: none; }
.seg span {
  display: block; text-align: center; padding: 9px 0; border-radius: 10px; cursor: pointer;
  border: 1px solid var(--line); background: #0e1530; color: var(--ink); transition: border-color .15s, background .15s;
}
.seg:hover span { border-color: var(--acc2); }
.seg input:checked + span { border-color: var(--acc); background: rgba(94, 230, 168, .12); color: var(--acc); font-weight: 700; }
.seg input:focus-visible + span { box-shadow: 0 0 0 3px rgba(122, 167, 255, .3); }

/* CPU controls in the waiting room */
.cpu-row { display: flex; gap: 8px; align-items: center; margin-top: 12px; }
.cpu-row select { width: auto; flex: 1; margin: 0; padding: 6px 10px; }
.cpu-row .btn { flex: none; }
.cpu-row .btn:disabled { opacity: .45; cursor: not-allowed; }
.tag.cpu { background: rgba(122, 167, 255, .15); color: var(--acc2); }
.player .remove { padding: 0 8px; line-height: 1.4; font-size: 16px; color: var(--muted); }
.player .remove:hover { color: var(--danger); border-color: rgba(255, 122, 138, .4); }
body.offline .online-only { display: none !important; }

/* game mode pickers */
.gcards { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.gcard {
  position: relative; display: flex; flex-direction: column; gap: 4px; padding: 10px; border-radius: 12px;
  border: 1px solid var(--line); background: #0e1530; cursor: pointer; transition: border-color .15s, background .15s;
}
.gcard:hover { border-color: var(--acc2); }
.gcard input { position: absolute; opacity: 0; width: 1px; height: 1px; margin: 0; pointer-events: none; }
.gcard:has(input:checked) { border-color: var(--acc); background: rgba(94, 230, 168, .12); }
.gcard:has(input:focus-visible) { box-shadow: 0 0 0 3px rgba(122, 167, 255, .3); }
.gicon { font-size: 26px; line-height: 1; }
.gcard b { font-size: 14px; }
.gcard small { font-size: 12px; line-height: 1.3; }
.badge.game { background: rgba(94, 230, 168, .12); color: var(--ink); }

/* badges */
.pbadge { font-size: 14px; cursor: help; }
.bgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 10px; }
.bcard { display: flex; flex-direction: column; gap: 4px; padding: 12px; border-radius: 12px; border: 2px solid var(--line); background: #0e1530; }
.bcard.locked { filter: grayscale(1); opacity: .5; }
.bicon { font-size: 28px; line-height: 1; }

/* full-screen takeover card */
.takeover {
  position: fixed; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center;
  pointer-events: none; opacity: 0; transition: opacity .25s; background: rgba(5, 9, 22, .35); text-align: center; z-index: 25;
}
.takeover.show { opacity: 1; }
.takeover h1 { font-size: clamp(36px, 8vw, 72px); margin: 0; text-shadow: 0 4px 24px rgba(0, 0, 0, .6); }
.takeover p { font-size: clamp(16px, 3vw, 22px); margin: 8px 0 0; }
