:root {
  --bg-0: #0f1226;
  --bg-1: #1a1f3d;
  --bg-2: #232a52;
  --fg: #f1f3ff;
  --muted: #9aa3c7;
  --accent: #7c5cff;
  --accent-2: #4cc9f0;
  --good: #2ecc71;
  --warn: #ffb84c;
  --tile-bg: linear-gradient(160deg, #6f4cff 0%, #4cc9f0 100%);
  --tile-empty: rgba(255, 255, 255, 0.04);
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  --radius: 14px;
  --gap: 8px;
  --font: "Inter", "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background:
    radial-gradient(1200px 600px at 20% -10%, rgba(124, 92, 255, 0.35), transparent 60%),
    radial-gradient(900px 500px at 110% 10%, rgba(76, 201, 240, 0.25), transparent 60%),
    var(--bg-0);
  color: var(--fg);
  font-family: var(--font);
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
}

.shell {
  max-width: 980px;
  margin: 0 auto;
  padding: 24px 20px 64px;
}

.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 22px;
}

.brand { display: flex; align-items: center; gap: 14px; }
.brand h1 { margin: 0; font-size: 22px; letter-spacing: 0.2px; }
.brand .tag { margin: 2px 0 0; color: var(--muted); font-size: 13px; }
.logo {
  display: inline-grid; place-items: center;
  width: 46px; height: 46px; border-radius: 12px;
  background: var(--tile-bg); color: white; font-weight: 800;
  box-shadow: var(--shadow);
}

.tabs { display: flex; background: var(--bg-1); border-radius: 999px; padding: 4px; gap: 2px; }
.tab {
  border: 0; background: transparent; color: var(--muted);
  padding: 8px 14px; border-radius: 999px; cursor: pointer;
  font-size: 13px; font-weight: 600; transition: 160ms ease;
}
.tab:hover { color: var(--fg); }
.tab.active { background: var(--accent); color: white; box-shadow: var(--shadow); }

.view { display: none; }
.view.active { display: block; }

.controls, .board-controls {
  display: flex; flex-wrap: wrap; align-items: center; gap: 12px;
  background: var(--bg-1); border-radius: var(--radius);
  padding: 14px; margin-bottom: 18px; box-shadow: var(--shadow);
}
.ctrl { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; }
.ctrl select {
  appearance: none; -webkit-appearance: none;
  background: var(--bg-2); color: var(--fg);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 10px; padding: 8px 12px; font-size: 14px; cursor: pointer;
}

.btn {
  background: var(--bg-2); color: var(--fg);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 10px; padding: 9px 14px; font-size: 14px; font-weight: 600;
  cursor: pointer; transition: transform 100ms ease, background 160ms ease;
}
.btn:hover { background: #2c3360; }
.btn:active { transform: translateY(1px); }
.btn.primary {
  background: var(--accent); border-color: transparent;
}
.btn.primary:hover { background: #8b6cff; }

.stats {
  margin-left: auto; display: flex; gap: 10px;
}
.stats > div {
  background: var(--bg-2);
  border-radius: 12px; padding: 8px 14px; min-width: 90px;
  display: flex; flex-direction: column; align-items: center; line-height: 1.1;
}
.stat-label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.6px; }
.stat-val { font-size: 18px; font-weight: 700; font-variant-numeric: tabular-nums; }

.board-wrap { position: relative; }

.board {
  --n: 4;
  position: relative;
  width: 100%;
  max-width: 520px;
  aspect-ratio: 1 / 1;
  margin: 0 auto;
  padding: var(--gap);
  background: var(--bg-1);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  user-select: none;
  touch-action: manipulation;
}
.board::after {
  /* subtle inner glow */
  content: ""; position: absolute; inset: 0;
  border-radius: var(--radius); pointer-events: none;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.04);
}

.tile {
  position: absolute;
  display: grid; place-items: center;
  background: var(--tile-bg);
  color: white;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  border-radius: 10px;
  cursor: pointer;
  box-shadow: 0 6px 14px rgba(0, 0, 0, 0.35), inset 0 1px 0 rgba(255,255,255,0.25);
  transition: transform 180ms cubic-bezier(.2,.7,.2,1), box-shadow 200ms ease, opacity 200ms;
  will-change: transform;
  -webkit-tap-highlight-color: transparent;
}
.tile:hover { box-shadow: 0 10px 18px rgba(0,0,0,0.45), inset 0 1px 0 rgba(255,255,255,0.35); }
.tile.empty { background: transparent; box-shadow: none; cursor: default; }
.tile.correct {
  background: linear-gradient(160deg, #2ecc71 0%, #4cc9f0 100%);
}
.tile.disabled { cursor: not-allowed; }

.win {
  position: absolute; inset: 0;
  display: grid; place-items: center;
  background: rgba(15, 18, 38, 0.78);
  backdrop-filter: blur(6px);
  border-radius: var(--radius);
  animation: pop 280ms ease both;
}
.win[hidden] { display: none; }
.win > * { text-align: center; }
.win h2 { margin: 0 0 6px; font-size: 28px; }
.win form { display: grid; gap: 12px; margin-top: 14px; min-width: 280px; }
.win input {
  background: var(--bg-2); color: var(--fg);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 10px; padding: 10px 12px; font-size: 15px;
}
.win .row { display: flex; gap: 10px; justify-content: center; }
.win .hint { color: var(--muted); font-size: 13px; margin: 0; min-height: 1em; }
.win label { display: grid; gap: 6px; text-align: left; color: var(--muted); font-size: 13px; }

@keyframes pop { from { transform: scale(0.96); opacity: 0; } to { transform: scale(1); opacity: 1; } }

/* Leaderboard table */
.board-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--bg-1);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}
.board-table th, .board-table td {
  text-align: left; padding: 12px 14px; font-size: 14px;
}
.board-table thead { background: var(--bg-2); color: var(--muted); text-transform: uppercase; font-size: 11px; letter-spacing: 0.6px; }
.board-table tbody tr { border-top: 1px solid rgba(255,255,255,0.04); }
.board-table tbody tr.you { background: rgba(124, 92, 255, 0.15); }
.board-table td.empty { text-align: center; color: var(--muted); padding: 24px; }
.board-table td.rank { font-weight: 700; color: var(--accent-2); width: 56px; }

/* How-to */
.howto {
  background: var(--bg-1); padding: 22px 24px; border-radius: var(--radius); box-shadow: var(--shadow);
  line-height: 1.55;
}
.howto h2 { margin-top: 0; }
.howto code { background: var(--bg-2); padding: 1px 6px; border-radius: 6px; }

.foot { margin-top: 28px; text-align: center; color: var(--muted); font-size: 12px; }
.foot code { background: var(--bg-1); padding: 1px 6px; border-radius: 5px; }

.hint { color: var(--muted); font-size: 13px; }

@media (max-width: 640px) {
  .brand h1 { font-size: 18px; }
  .stats { margin-left: 0; width: 100%; justify-content: space-between; }
  .stats > div { min-width: 0; flex: 1; }
  .topbar { gap: 10px; }
  .tabs { width: 100%; justify-content: space-between; }
  .tab { flex: 1; text-align: center; }
}
