:root {
  --bg0: #04070f;
  --bg1: #0a1224;
  --card: rgba(12, 18, 34, 0.88);
  --card-solid: #0e1628;
  --accent: #3ddc84;
  --accent-dim: rgba(61, 220, 132, 0.15);
  --accent2: #6b9bff;
  --text: #f4f7ff;
  --muted: #8fa3c4;
  --border: rgba(140, 170, 220, 0.16);
  --danger: #ff6b7a;
  --shadow: 0 28px 90px rgba(0, 0, 0, 0.55);
  --radius: 20px;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg0);
  color: var(--text);
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  touch-action: none;
  user-select: none;
  -webkit-font-smoothing: antialiased;
}

#c {
  display: block;
  width: 100vw;
  height: 100vh;
  background: #070b14;
}

/* ===== HUD ===== */
#hud {
  position: fixed;
  top: 14px;
  left: 14px;
  z-index: 5;
  display: flex;
  flex-direction: column;
  gap: 2px;
  pointer-events: none;
  text-shadow: 0 2px 12px rgba(0, 0, 0, 0.6);
}
#hud.hidden, #boards.hidden, .hidden { display: none !important; }
.brand { font-weight: 900; font-size: 1.22rem; letter-spacing: 0.01em; }
.brand span { color: var(--accent); }
#online, #scoreHud { font-size: 0.88rem; color: var(--muted); }
#scoreHud { color: #e8efff; font-weight: 700; }

#boards {
  position: fixed;
  top: 14px;
  right: 14px;
  z-index: 5;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: min(220px, 46vw);
  pointer-events: none;
}
#leaderboard, #alltime {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 10px 12px;
  font-size: 0.8rem;
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
}
.title {
  font-weight: 800;
  margin-bottom: 6px;
  color: var(--accent);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.row {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding: 3px 0;
  color: var(--muted);
}
.row.me { color: var(--text); font-weight: 700; }
.row .left {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ===== MENU ===== */
.menu {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 16px;
  overflow: auto;
}

.menu-bg {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse 80% 50% at 50% -10%, rgba(91, 140, 255, 0.22), transparent 55%),
    radial-gradient(ellipse 60% 40% at 80% 100%, rgba(61, 220, 132, 0.14), transparent 50%),
    radial-gradient(ellipse 50% 35% at 10% 80%, rgba(192, 132, 252, 0.1), transparent 50%),
    rgba(3, 6, 12, 0.78);
  backdrop-filter: blur(12px);
  pointer-events: none;
}

.menu-shell {
  position: relative;
  width: min(860px, 100%);
  z-index: 1;
}

.menu-hero {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 16px;
  padding: 4px 4px 0;
}

.logo-mark {
  width: 64px;
  height: 64px;
  border-radius: 18px;
  background: linear-gradient(145deg, #121c34, #0a1020);
  border: 1px solid var(--border);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.4), inset 0 1px 0 rgba(255, 255, 255, 0.06);
  position: relative;
  flex-shrink: 0;
  overflow: hidden;
}
.coil {
  position: absolute;
  border-radius: 50%;
  border: 3px solid transparent;
}
.coil.c1 {
  inset: 12px;
  border-color: #3ddc84 transparent #3ddc84 transparent;
  animation: spin 3.2s linear infinite;
}
.coil.c2 {
  inset: 20px;
  border-color: transparent #5b8cff transparent #5b8cff;
  animation: spin 2.4s linear infinite reverse;
}
.coil.c3 {
  inset: 28px;
  background: radial-gradient(circle, #3ddc84 40%, transparent 42%);
  opacity: 0.9;
}
@keyframes spin { to { transform: rotate(360deg); } }

.hero-text h1 {
  margin: 0;
  font-size: clamp(1.8rem, 4vw, 2.35rem);
  font-weight: 900;
  letter-spacing: -0.03em;
  line-height: 1.1;
}
.hero-text h1 span { color: var(--accent); }
.tagline {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.4;
}

.menu-grid {
  display: grid;
  grid-template-columns: 1.35fr 0.9fr;
  gap: 14px;
  align-items: stretch;
}

.panel {
  background: linear-gradient(165deg, rgba(18, 28, 48, 0.97), rgba(9, 14, 26, 0.98));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px 18px;
}

.play-panel { text-align: left; }
.hall-panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.field { margin-bottom: 14px; }
.field label, .field-row label {
  display: block;
  font-size: 0.72rem;
  font-weight: 800;
  color: var(--muted);
  margin-bottom: 7px;
  text-transform: uppercase;
  letter-spacing: 0.07em;
}
.field-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}
.skin-preview {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text);
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px 11px;
  white-space: nowrap;
}

.field input {
  width: 100%;
  padding: 13px 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: rgba(4, 8, 16, 0.9);
  color: var(--text);
  font-size: 1rem;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.field input:focus {
  border-color: rgba(61, 220, 132, 0.65);
  box-shadow: 0 0 0 3px rgba(61, 220, 132, 0.12);
}
.field input::placeholder { color: #5a6d8c; }

/* Flag stripe preview bar */
.coil-preview {
  height: 14px;
  border-radius: 999px;
  margin-bottom: 10px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: linear-gradient(90deg, #FF9933, #FFFFFF, #138808);
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.25);
}

.skins {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(68px, 1fr));
  gap: 8px;
  max-height: 220px;
  overflow: auto;
  padding: 10px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: rgba(3, 7, 14, 0.72);
  scrollbar-width: thin;
  scrollbar-color: rgba(61, 220, 132, 0.35) transparent;
}
.skins::-webkit-scrollbar { width: 6px; }
.skins::-webkit-scrollbar-thumb {
  background: rgba(61, 220, 132, 0.3);
  border-radius: 99px;
}

.skin {
  appearance: none;
  border: 2px solid transparent;
  background: rgba(255, 255, 255, 0.03);
  border-radius: 12px;
  padding: 8px 4px 6px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  transition: transform 0.12s, border-color 0.12s, background 0.12s, box-shadow 0.12s;
  color: inherit;
  font: inherit;
}
.skin:hover {
  transform: translateY(-2px);
  background: rgba(255, 255, 255, 0.07);
}
.skin.selected {
  border-color: var(--accent);
  background: var(--accent-dim);
  box-shadow: 0 0 0 1px rgba(61, 220, 132, 0.28), 0 8px 20px rgba(61, 220, 132, 0.12);
}
.skin .flag {
  font-size: 1.45rem;
  line-height: 1;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.4));
}
.skin .swatch {
  width: 100%;
  height: 9px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.14);
}
.skin .lbl {
  font-size: 0.6rem;
  font-weight: 600;
  color: var(--muted);
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.skin.selected .lbl { color: var(--text); }

.btn-primary {
  width: 100%;
  margin-top: 4px;
  padding: 14px 18px;
  border: 0;
  border-radius: 14px;
  background: linear-gradient(135deg, #45e890 0%, #2bb86a 100%);
  color: #04210f;
  font-weight: 900;
  font-size: 1.05rem;
  cursor: pointer;
  box-shadow: 0 12px 32px rgba(61, 220, 132, 0.28);
  transition: transform 0.12s, filter 0.12s, box-shadow 0.12s;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}
.btn-primary:hover {
  filter: brightness(1.06);
  transform: translateY(-1px);
  box-shadow: 0 14px 36px rgba(61, 220, 132, 0.36);
}
.btn-primary:active { transform: translateY(0); }
.btn-arrow { font-weight: 700; opacity: 0.75; }

.btn-ghost {
  width: 100%;
  margin-top: 8px;
  padding: 12px 18px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--muted);
  font-weight: 700;
  cursor: pointer;
  transition: color 0.12s, border-color 0.12s;
}
.btn-ghost:hover {
  color: var(--text);
  border-color: rgba(255, 255, 255, 0.28);
}

.hint {
  margin: 14px 0 0;
  color: var(--muted);
  font-size: 0.76rem;
  line-height: 1.55;
  display: flex;
  flex-wrap: wrap;
  gap: 6px 14px;
}
.hint span {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.status {
  margin: 10px 0 0;
  min-height: 1.2em;
  color: #ffc857;
  font-size: 0.86rem;
}

.stat-t {
  font-size: 0.72rem;
  font-weight: 800;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 10px;
}
.stat-list {
  flex: 1;
  max-height: 340px;
  overflow: auto;
  scrollbar-width: thin;
}
.stat-list .row {
  padding: 6px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
  font-size: 0.84rem;
}
.hall-note {
  margin: 12px 0 0;
  font-size: 0.72rem;
  color: #6a7d9c;
}

/* Dead screen */
.dead-shell { width: min(400px, 100%); }
.dead-panel { text-align: center; padding: 28px 22px 22px; }
.dead-icon { font-size: 2.2rem; margin-bottom: 6px; }
.dead-panel h2 {
  margin: 0 0 8px;
  font-size: 1.65rem;
  color: var(--danger);
  font-weight: 900;
}
.dead-msg {
  color: var(--muted);
  margin: 0 0 16px;
  font-size: 0.95rem;
}
.dead-panel .stat-t { text-align: left; }
.dead-panel .stat-list {
  text-align: left;
  max-height: 160px;
  margin-bottom: 14px;
  padding: 8px 10px;
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid var(--border);
}

@media (max-width: 720px) {
  .menu-grid { grid-template-columns: 1fr; }
  .hall-panel { order: 2; }
  .stat-list { max-height: 140px; }
  .skins { max-height: 180px; grid-template-columns: repeat(auto-fill, minmax(60px, 1fr)); }
  .menu-hero { margin-bottom: 12px; }
  .logo-mark { width: 52px; height: 52px; border-radius: 14px; }
}

@media (max-width: 420px) {
  .panel { padding: 16px 14px; border-radius: 16px; }
  .hint { flex-direction: column; gap: 4px; }
  #boards { width: min(48vw, 170px); }
}
