:root {
  --bg: #0b0f17;
  --panel: #121a2a;
  --panel-2: #182236;
  --border: #24324a;
  --text: #e6edf7;
  --muted: #8fa3bf;
  --accent: #38bdf8;
  --accent-2: #22c55e;
  --danger: #f87171;
  --amber: #fbbf24;
  --pink: #f472b6;
  --violet: #a78bfa;
  --radius: 14px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: radial-gradient(1200px 700px at 70% -10%, #16233c 0%, var(--bg) 55%);
  color: var(--text);
  line-height: 1.55;
  min-height: 100vh;
  overscroll-behavior: none;
}

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

/* ---------- Hero ---------- */
.hero {
  max-width: 960px;
  margin: 0 auto;
  padding: 56px 20px 28px;
  text-align: center;
}

.badge {
  display: inline-block;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
  border: 1px solid var(--border);
  background: rgba(56, 189, 248, 0.08);
  padding: 6px 14px;
  border-radius: 999px;
  margin-bottom: 20px;
}

h1 {
  font-size: clamp(2.4rem, 7vw, 4rem);
  font-weight: 900;
  letter-spacing: -0.02em;
  margin-bottom: 16px;
}

h1 span { color: var(--accent); }

.tagline {
  color: var(--muted);
  font-size: clamp(1rem, 2.4vw, 1.15rem);
  max-width: 640px;
  margin: 0 auto;
}

/* ---------- Ad slots ---------- */
.ad-slot {
  max-width: 760px;
  margin: 10px auto;
  text-align: center;
  font-size: 12px;
  letter-spacing: 0.06em;
  color: var(--muted);
  background: var(--panel);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  padding: 26px;
}
.ad-slot.wide { max-width: 960px; }

/* ---------- Game grid ---------- */
main { max-width: 960px; margin: 0 auto; padding: 16px 20px 40px; }

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

.game-card {
  display: block;
  text-decoration: none;
  color: var(--text);
  background: linear-gradient(180deg, var(--panel), var(--panel-2));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  transition: transform 0.12s ease, border-color 0.12s ease, box-shadow 0.12s ease;
}

.game-card:hover {
  transform: translateY(-4px);
  border-color: var(--accent);
  box-shadow: 0 12px 30px rgba(56, 189, 248, 0.15);
}

.game-card .emoji {
  font-size: 44px;
  line-height: 1;
  display: block;
  margin-bottom: 12px;
}

.game-card h3 { font-size: 1.25rem; margin-bottom: 6px; }

.game-card p { color: var(--muted); font-size: 13.5px; margin-bottom: 14px; }

.game-card .best {
  display: inline-block;
  font-size: 12px;
  font-weight: 700;
  color: var(--amber);
  background: rgba(251, 191, 36, 0.1);
  border: 1px solid rgba(251, 191, 36, 0.3);
  border-radius: 999px;
  padding: 4px 12px;
}

.play-btn {
  display: block;
  text-align: center;
  margin-top: 14px;
  background: var(--accent);
  color: #04121f;
  font-weight: 800;
  border-radius: 9px;
  padding: 10px 0;
}

.game-card:hover .play-btn { filter: brightness(1.12); }

/* ---------- Cards / sections ---------- */
.loading {
  text-align: center;
  padding: 80px 20px;
  color: var(--muted);
  font-size: 16px;
}

.card {
  background: linear-gradient(180deg, var(--panel), var(--panel-2));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 26px;
  margin-bottom: 22px;
}

.card h2 { font-size: 1.2rem; margin-bottom: 10px; }

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

.support-row { margin-top: 18px; }

.btn {
  display: inline-block;
  text-decoration: none;
  text-align: center;
  font-weight: 800;
  border-radius: 9px;
  padding: 11px 20px;
}

.btn.support {
  background: var(--accent-2);
  color: #04140a;
}

.btn.support:hover { filter: brightness(1.1); }

.btn.support.big {
  display: block;
  padding: 15px;
  font-size: 1.05rem;
}

footer {
  text-align: center;
  color: var(--muted);
  font-size: 13px;
  padding: 26px 20px 48px;
  border-top: 1px solid var(--border);
}

footer p { margin-bottom: 4px; }

/* ---------- Game screen ---------- */
#game-root { max-width: 1400px; margin: 0 auto; padding: 18px 20px 30px; }

.game-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.game-head h2 { font-size: 1.4rem; }

.back-btn, .ghost-btn {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

.back-btn:hover, .ghost-btn:hover { border-color: var(--accent); color: var(--accent); }

.score-pill {
  font-variant-numeric: tabular-nums;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 14px;
  font-weight: 800;
  font-size: 13px;
}

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

.game-wrap, .overlay-wrap {
  display: flex;
  justify-content: center;
  align-items: center;
  margin-bottom: 10px;
  min-height: calc(100vh - 230px);
  min-height: 420px;
  position: relative;
}

.game-wrap canvas {
  max-width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel);
  touch-action: none;
}

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

.game-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  text-align: center;
  background: rgba(11, 15, 23, 0.82);
  border-radius: var(--radius);
}

.game-overlay h3 { font-size: 2rem; }
.game-overlay p { color: var(--muted); }

.overlay-wrap { position: relative; }

/* ---------- DOM games (2048, memory, tictactoe) ---------- */
.board-wrap { display: flex; justify-content: center; }

.hello-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  width: min(560px, 94vw, calc(100vh - 260px));
  aspect-ratio: 1;
}

.hello-cell { border-radius: 8px; background: rgba(255,255,255,0.04); }

.hello-tile {
  position: absolute;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 900;
  font-size: clamp(22px, 6vw, 34px);
  border-radius: 8px;
  transition: transform 0.12s ease;
}

.tile-2   { background: #233854; color: var(--text); }
.tile-4   { background: #2e4a6e; color: var(--text); }
.tile-8   { background: #3b6a8f; color: var(--text); }
.tile-16  { background: #1273a8; color: #fff; }
.tile-32  { background: #0e83b5; color: #fff; }
.tile-64  { background: #0a97c4; color: #fff; }
.tile-128 { background: #0fb5cf; color: #04121f; }
.tile-256 { background: #f59e0b; color: #3a1d00; }
.tile-512 { background: #f97316; color: #3a1d00; }
.tile-1024{ background: #f43f5e; color: #fff; }
.tile-2048{ background: #eab308; color: #3a1d00; box-shadow: 0 0 24px rgba(234,179,8,0.6); }

.memory-board {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  width: min(560px, 94vw, calc(100vh - 260px));
}

.mem-card {
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 30px;
  background: linear-gradient(180deg, var(--panel-2), var(--bg));
  border: 1px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
  user-select: none;
}

.mem-card.flipped, .mem-card.matched { background: var(--panel); border-color: var(--accent); }

.mem-card.matched { border-color: var(--accent-2); }

.ttt-board {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  width: min(480px, 90vw, calc(100vh - 260px));
}

.ttt-cell {
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(36px, 10vw, 56px);
  font-weight: 900;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
}

.ttt-cell.x { color: var(--accent); }
.ttt-cell.o { color: var(--danger); }

/* ---------- Support page ---------- */
.support-page {
  max-width: 720px;
  margin: 0 auto;
  padding: 30px 20px 60px;
  text-align: center;
}

.support-page h1 { font-size: clamp(2rem, 6vw, 3rem); margin: 20px 0 12px; }

.support-options {
  display: grid;
  gap: 14px;
  max-width: 360px;
  margin: 28px auto;
}

.note { margin-top: 24px; }

/* ---------- Tips ---------- */
.tip-box {
  max-width: 380px;
  margin: 28px auto 0;
  text-align: left;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
}

.tip-presets {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 12px;
}

.tip-btn {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 12px 0;
  font-size: 15px;
  font-weight: 800;
  cursor: pointer;
}

.tip-btn.active {
  border-color: var(--accent);
  color: var(--accent);
  background: rgba(56, 189, 248, 0.1);
}

.tip-custom {
  display: flex;
  align-items: center;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 0 14px;
  margin-bottom: 14px;
}

.tip-custom:focus-within { border-color: var(--accent); }

.currency { color: var(--muted); font-weight: 800; margin-right: 6px; }

.tip-custom input {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text);
  font-size: 16px;
  padding: 12px 0;
  min-width: 0;
}

.tip-custom input:focus { outline: none; }

.tip-error {
  background: rgba(248, 113, 113, 0.1);
  border: 1px solid rgba(248, 113, 113, 0.4);
  color: var(--danger);
  border-radius: 8px;
  padding: 10px 14px;
  margin: 12px 0;
  font-size: 13px;
}

.tip-box .muted { margin-top: 12px; font-size: 12.5px; text-align: center; }

.thanks {
  background: rgba(34, 197, 94, 0.12);
  border: 1px solid rgba(34, 197, 94, 0.45);
  color: var(--accent-2);
  border-radius: 10px;
  padding: 14px 18px;
  margin: 18px auto 0;
  max-width: 480px;
  font-size: 14px;
}

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

.btn.support.outline {
  background: transparent;
  color: var(--accent-2);
  border: 1px solid var(--accent-2);
}

.pass-card { max-width: 480px; margin: 22px auto 0; }
.pass-card .badge { background: var(--accent); color: #04140a; }

.advertise-card { max-width: 480px; margin: 22px auto 0; }

/* ---------- Shop ---------- */
.shop-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 18px;
  max-width: 640px;
  margin: 28px auto 0;
  text-align: left;
}

.shop-item { display: flex; flex-direction: column; gap: 8px; margin-bottom: 0; }

.shop-emoji { font-size: 42px; }

.price {
  color: var(--text);
  font-weight: 800;
  font-size: 1.1rem;
  margin: 6px 0;
}

.shop-item .btn { margin-top: auto; }

@media (max-width: 600px) {
  .hero { padding-top: 40px; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 12px; }
  .game-card { padding: 16px; }
  .game-card .emoji { font-size: 34px; }
}

/* ---------- Tetris ---------- */
.controls { display: flex; justify-content: center; flex-direction: column; gap: 8px; margin: 10px 0; }

.ctl-row { display: flex; gap: 10px; justify-content: center; }

.ctl {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 9px;
  width: 64px;
  height: 48px;
  font-size: 20px;
  cursor: pointer;
}

.ctl.wide { width: 138px; }

.ctl:hover { border-color: var(--accent); }

/* ---------- Minesweeper ---------- */
.ms-board {
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  gap: 3px;
  width: min(540px, 94vw, calc(100vh - 260px));
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px;
  user-select: none;
}

.ms-cell {
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(14px, 4vw, 20px);
  font-weight: 800;
  background: #24324a;
  border-radius: 4px;
  cursor: pointer;
}

.ms-cell.revealed { background: var(--panel-2); cursor: default; }

/* ---------- Wordle ---------- */
.wl-board { display: grid; gap: 6px; width: min(440px, 94vw, calc(100vh - 320px)); margin: 0 auto 16px; }

.wl-row { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }

.wl-cell {
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(22px, 6vw, 32px);
  font-weight: 800;
  text-transform: uppercase;
  border: 2px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
}

.wl-cell.active { border-color: var(--accent); }

.wl-cell.correct { background: #15803d; border-color: #15803d; color: #fff; }
.wl-cell.present { background: #b45309; border-color: #b45309; color: #fff; }
.wl-cell.absent  { background: #24324a; border-color: #24324a; color: var(--muted); }

.wl-kb { display: grid; gap: 6px; width: min(480px, 96vw); margin: 0 auto 12px; }

.wl-kb-row { display: flex; gap: 5px; justify-content: center; }

.wl-key {
  flex: 1;
  max-width: 44px;
  height: 48px;
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 7px;
  font-size: 14px;
  font-weight: 700;
  text-transform: uppercase;
  cursor: pointer;
}

.wl-key.wide { flex: 1.5; max-width: none; font-size: 11px; }
.wl-key.correct { background: #15803d; border-color: #15803d; }
.wl-key.present { background: #b45309; border-color: #b45309; }
.wl-key.absent  { background: #24324a; border-color: #24324a; color: var(--muted); }

.wl-msg { text-align: center; font-weight: 700; min-height: 22px; margin-bottom: 8px; }

.wl-share-wrap { display: flex; justify-content: center; margin-top: 6px; }

/* ---------- Simon ---------- */
.simon {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  width: min(480px, 92vw, calc(100vh - 260px));
  aspect-ratio: 1;
  position: relative;
}

.simon-pad {
  border-radius: 18px;
  opacity: 0.35;
  cursor: pointer;
}

.simon-pad[data-i="0"] { background: var(--danger); }
.simon-pad[data-i="1"] { background: var(--amber); }
.simon-pad[data-i="2"] { background: var(--accent-2); }
.simon-pad[data-i="3"] { background: var(--accent); }

.simon-center {
  position: absolute;
  inset: 50%;
  transform: translate(-50%, -50%);
  width: 32%;
  height: 32%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 50%;
}

/* ---------- RPS ---------- */
.rps-stage { flex-direction: column; align-items: center; gap: 16px; display: flex; }

.rps-vs {
  display: flex;
  align-items: center;
  gap: 22px;
  font-size: 18px;
  font-weight: 800;
  color: var(--muted);
}

.rps-choice {
  width: 84px;
  height: 84px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 44px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
}

.rps-result { font-weight: 800; min-height: 24px; }

.rps-buttons { display: flex; gap: 14px; }

.rps-btn {
  width: 72px;
  height: 72px;
  font-size: 34px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 16px;
  cursor: pointer;
}

.rps-btn:hover { border-color: var(--accent); transform: translateY(-2px); }
