:root {
  --bg: #0b1020;
  --bg-2: #121a33;
  --panel: rgba(255, 255, 255, 0.05);
  --border: rgba(255, 255, 255, 0.1);
  --text: #e8ecf8;
  --muted: #8f9bbd;
  --accent: #f6821f; /* Cloudflare orange */
  --accent-2: #fbad41;
  --good: #3ddc97;
  --radius: 16px;
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  font-family: system-ui, -apple-system, "PingFang SC", "Microsoft YaHei", "Segoe UI", sans-serif;
  color: var(--text);
  background:
    radial-gradient(1200px 600px at 10% -10%, rgba(246, 130, 31, 0.18), transparent 60%),
    radial-gradient(900px 500px at 110% 10%, rgba(99, 102, 241, 0.18), transparent 60%),
    var(--bg);
  background-attachment: fixed;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

a {
  color: inherit;
  text-decoration: none;
}

[hidden] {
  display: none !important;
}

.muted {
  color: var(--muted);
}

/* ---------- top bar ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 24px;
  background: rgba(11, 16, 32, 0.75);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}

.logo {
  font-size: 20px;
  font-weight: 800;
  white-space: nowrap;
}

.logo span {
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.online {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 14px;
}

.online b {
  color: var(--text);
}

.dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--good);
  box-shadow: 0 0 0 0 rgba(61, 220, 151, 0.7);
  animation: pulse 2s infinite;
}

@keyframes pulse {
  70% {
    box-shadow: 0 0 0 8px rgba(61, 220, 151, 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(61, 220, 151, 0);
  }
}

.player {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  color: var(--muted);
}

.player-name b {
  color: var(--text);
  display: inline-block;
  max-width: 10em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  vertical-align: bottom;
}

/* ---------- nickname gate ---------- */

body.gated {
  overflow: hidden;
}

.gate {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(7, 11, 24, 0.82);
  backdrop-filter: blur(10px);
  animation: fade 0.25s ease;
}

.gate-card {
  width: 100%;
  max-width: 400px;
  text-align: center;
  padding: 36px 32px 32px;
  background:
    radial-gradient(400px 200px at 50% -20%, rgba(246, 130, 31, 0.25), transparent 70%),
    var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 20px;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.6);
  animation: rise 0.3s ease;
}

@keyframes rise {
  from {
    transform: translateY(16px);
    opacity: 0;
  }
}

.gate-icon {
  font-size: 56px;
  line-height: 1;
  margin-bottom: 8px;
}

.gate-card h2 {
  margin: 0 0 8px;
  font-size: 24px;
}

.gate-card p {
  margin: 0;
  font-size: 14px;
}

.gate-card input {
  font: inherit;
  font-size: 18px;
  text-align: center;
  width: 100%;
  margin-top: 20px;
  padding: 12px 16px;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  outline: none;
  transition: border-color 0.2s;
}

.gate-card input:focus {
  border-color: var(--accent);
}

.gate-error {
  min-height: 1.6em;
  padding-top: 6px;
  color: #ff7b7b;
}

.btn.big {
  width: 100%;
  padding: 12px;
  font-size: 16px;
}

.btn.small {
  padding: 4px 10px;
  font-size: 12px;
}

/* ---------- layout ---------- */

#app {
  flex: 1;
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  padding: 24px;
}

.footer {
  text-align: center;
  color: var(--muted);
  font-size: 13px;
  padding: 24px;
}

.hero {
  text-align: center;
  padding: 32px 0 28px;
}

.hero h1 {
  font-size: clamp(32px, 6vw, 56px);
  margin: 0 0 8px;
  background: linear-gradient(90deg, #fff, var(--accent-2), var(--accent));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.hero p {
  color: var(--muted);
  margin: 0;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 18px;
}

.card {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 22px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  transition:
    transform 0.2s,
    border-color 0.2s,
    box-shadow 0.2s;
}

.card:hover {
  transform: translateY(-4px);
  border-color: rgba(246, 130, 31, 0.6);
  box-shadow: 0 12px 32px rgba(246, 130, 31, 0.15);
}

.card-icon {
  font-size: 44px;
  line-height: 1;
}

.card h3 {
  margin: 6px 0 0;
  font-size: 20px;
}

.card p {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
  flex: 1;
}

.card-meta {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 8px;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--muted);
}

.pill b {
  color: var(--text);
}

/* ---------- buttons ---------- */

.btn {
  font: inherit;
  font-size: 14px;
  cursor: pointer;
  color: var(--text);
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 14px;
  white-space: nowrap;
  transition: background 0.2s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  user-select: none;
}

.btn:hover {
  background: rgba(255, 255, 255, 0.14);
}

.btn.primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  border-color: transparent;
  color: #1a1206;
  font-weight: 700;
}

.btn.ghost {
  background: transparent;
}

.btn.active {
  border-color: var(--accent);
  color: var(--accent-2);
}

/* ---------- game view ---------- */

.game-head {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.game-head h2 {
  margin: 0;
  font-size: 26px;
}

.game-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  gap: 20px;
  align-items: start;
}

@media (max-width: 860px) {
  .game-layout {
    grid-template-columns: 1fr;
  }
  .topbar {
    padding: 10px 14px;
  }
  #app {
    padding: 14px;
  }
}

.scorebar {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 12px 16px;
  margin-bottom: 12px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  flex-wrap: wrap;
}

.stat small {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.stat b {
  font-size: 22px;
  font-variant-numeric: tabular-nums;
}

.scorebar .info {
  flex: 1;
  color: var(--muted);
  font-size: 14px;
  min-width: 120px;
}

.stage-wrap {
  position: relative;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  min-height: 300px;
  display: flex;
  justify-content: center;
}

.stage {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  user-select: none;
  -webkit-user-select: none;
}

.game-canvas {
  width: 100%;
  display: block;
  border-radius: 12px;
  background: #070b18;
  touch-action: none;
}

.hint {
  color: var(--muted);
  font-size: 13px;
  margin: 0;
  text-align: center;
}

.controls-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: center;
}

.touch-pad {
  display: none;
  gap: 8px;
  justify-content: center;
  flex-wrap: wrap;
}

.touch-pad .btn {
  min-width: 56px;
  min-height: 48px;
  font-size: 20px;
}

@media (pointer: coarse) {
  .touch-pad {
    display: flex;
  }
}

/* overlay */

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(7, 11, 24, 0.72);
  backdrop-filter: blur(4px);
  border-radius: var(--radius);
  z-index: 5;
  animation: fade 0.25s ease;
}

@keyframes fade {
  from {
    opacity: 0;
  }
}

.overlay-card {
  text-align: center;
  padding: 28px 32px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
  max-width: 90%;
}

.overlay-card h2 {
  margin: 0 0 8px;
}

.big-score {
  font-size: 48px;
  font-weight: 800;
  color: var(--accent-2);
  font-variant-numeric: tabular-nums;
}

.big-score small {
  font-size: 18px;
  color: var(--muted);
}

.badge {
  color: var(--good);
  margin: 4px 0;
}

.status {
  min-height: 1.4em;
  color: var(--muted);
  font-size: 14px;
}

.actions {
  display: flex;
  gap: 10px;
  justify-content: center;
  margin-top: 12px;
  flex-wrap: wrap;
}

/* side panel */

.side {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.panel {
  padding: 16px 18px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.panel h3 {
  margin: 0 0 4px;
  font-size: 16px;
}

.panel p {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.6;
}

.lb {
  list-style: none;
  margin: 12px 0 0;
  padding: 0;
}

.lb li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 6px;
  border-bottom: 1px dashed var(--border);
  font-size: 14px;
}

.lb li:last-child {
  border-bottom: 0;
}

.lb li.me {
  background: rgba(246, 130, 31, 0.12);
  border-radius: 8px;
}

.lb .rank {
  width: 26px;
  text-align: center;
  color: var(--muted);
}

.lb .name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lb .score {
  font-variant-numeric: tabular-nums;
  color: var(--accent-2);
  font-weight: 600;
}

.lb .empty {
  color: var(--muted);
  justify-content: center;
}

.error {
  text-align: center;
  color: #ff7b7b;
}

/* toast */

.toast {
  position: fixed;
  left: 50%;
  bottom: 32px;
  transform: translate(-50%, 20px);
  background: var(--bg-2);
  border: 1px solid var(--border);
  padding: 10px 18px;
  border-radius: 999px;
  opacity: 0;
  pointer-events: none;
  transition:
    opacity 0.25s,
    transform 0.25s;
  z-index: 50;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* ---------- 2048 ---------- */

.g2048 {
  width: 100%;
  max-width: 420px;
  aspect-ratio: 1;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  padding: 10px;
  background: #1b2340;
  border-radius: 12px;
  touch-action: none;
}

.g2048 .cell {
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.05);
  font-weight: 800;
  font-size: clamp(18px, 6vw, 34px);
  color: #fff;
  transition: background 0.1s;
}

.g2048 .cell.new {
  animation: pop 0.18s ease;
}

.g2048 .cell.merged {
  animation: bump 0.18s ease;
}

@keyframes pop {
  from {
    transform: scale(0.3);
    opacity: 0;
  }
}

@keyframes bump {
  50% {
    transform: scale(1.12);
  }
}

.g2048 .v2 { background: #eee4da; color: #776e65; }
.g2048 .v4 { background: #ede0c8; color: #776e65; }
.g2048 .v8 { background: #f2b179; }
.g2048 .v16 { background: #f59563; }
.g2048 .v32 { background: #f67c5f; }
.g2048 .v64 { background: #f65e3b; }
.g2048 .v128 { background: #edcf72; font-size: clamp(16px, 5vw, 28px); }
.g2048 .v256 { background: #edcc61; font-size: clamp(16px, 5vw, 28px); }
.g2048 .v512 { background: #edc850; font-size: clamp(16px, 5vw, 28px); }
.g2048 .v1024 { background: #edc53f; font-size: clamp(14px, 4vw, 24px); }
.g2048 .v2048 { background: #edc22e; font-size: clamp(14px, 4vw, 24px); box-shadow: 0 0 20px #edc22e; }
.g2048 .vbig { background: #3c3a32; font-size: clamp(12px, 3.6vw, 22px); }

/* ---------- minesweeper ---------- */

.mines {
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  gap: 3px;
  width: 100%;
  max-width: 400px;
  aspect-ratio: 1;
  touch-action: manipulation;
}

.mines .c {
  display: flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 5px;
  font: inherit;
  font-weight: 800;
  font-size: clamp(14px, 4vw, 20px);
  background: linear-gradient(180deg, #3a4878, #2b365e);
  color: var(--text);
  cursor: pointer;
  padding: 0;
  -webkit-touch-callout: none;
}

.mines .c:hover {
  filter: brightness(1.15);
}

.mines .c.open {
  background: #141b33;
  cursor: default;
}

.mines .c.boom {
  background: #b3261e;
}

.mines .n1 { color: #60a5fa; }
.mines .n2 { color: #4ade80; }
.mines .n3 { color: #f87171; }
.mines .n4 { color: #a78bfa; }
.mines .n5 { color: #fb923c; }
.mines .n6 { color: #22d3ee; }
.mines .n7 { color: #f472b6; }
.mines .n8 { color: #e5e7eb; }

/* ---------- memory ---------- */

.memory {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  width: 100%;
  max-width: 420px;
}

.memory .mc {
  aspect-ratio: 1;
  perspective: 600px;
  border: 0;
  padding: 0;
  background: none;
  cursor: pointer;
}

.memory .mc-inner {
  position: relative;
  width: 100%;
  height: 100%;
  transition: transform 0.35s;
  transform-style: preserve-3d;
}

.memory .mc.flipped .mc-inner,
.memory .mc.matched .mc-inner {
  transform: rotateY(180deg);
}

.memory .mc-face {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 12px;
  backface-visibility: hidden;
  font-size: clamp(28px, 8vw, 44px);
}

.memory .mc-back {
  background: linear-gradient(135deg, var(--accent), #8b5cf6);
}

.memory .mc-back::after {
  content: "?";
  color: rgba(255, 255, 255, 0.8);
  font-weight: 800;
}

.memory .mc-front {
  background: #1b2340;
  transform: rotateY(180deg);
}

.memory .mc.matched .mc-front {
  background: rgba(61, 220, 151, 0.2);
  box-shadow: inset 0 0 0 2px var(--good);
}

/* ---------- whack-a-mole ---------- */

.whack {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
  width: 100%;
  max-width: 420px;
}

.whack .hole {
  position: relative;
  aspect-ratio: 1;
  border-radius: 50%;
  border: 0;
  padding: 0;
  overflow: hidden;
  cursor: pointer;
  background: radial-gradient(circle at 50% 70%, #1a0f08 0 45%, #5b3a1e 46% 60%, #3d6b2a 61%);
  touch-action: manipulation;
}

.whack .mole {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 18%;
  text-align: center;
  font-size: clamp(36px, 11vw, 64px);
  transform: translateY(110%);
  transition: transform 0.12s ease-out;
  pointer-events: none;
}

.whack .hole.up .mole {
  transform: translateY(0);
}

.whack .hole.hit .mole {
  filter: grayscale(1) brightness(1.5);
  transform: translateY(20%) scale(0.9);
}
