* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; overscroll-behavior: none; }

:root {
  --bg: #191333;
  --bg2: #241a4a;
  --panel: #2c2260;
  --panel2: #382d78;
  --accent: #7c4dff;
  --accent2: #ff5c8a;
  --accent3: #ffb347;
  --text: #f4f1ff;
  --text-dim: #b8adf0;
  --cell-empty: #372c66;
  --cell-border: #4c3f8a;
  --target-exact: #ff5c8a;
  --target-pow2: #4dd0e1;
  --target-mult3: #ffd54d;
  --filled: #34d399;
  --block-grad: linear-gradient(145deg, #8e6bff, #6a3df0);
  --radius: 16px;
  --font: 'Segoe UI', system-ui, -apple-system, Roboto, sans-serif;
}

body[data-theme="wood"] {
  --bg: #2b1b12; --bg2: #3a2416; --panel: #4a2f1c; --panel2: #5c3c24;
  --accent: #c9822f; --accent2: #e0a458; --accent3: #f2c879;
  --cell-empty: #5a3d24; --cell-border: #7a5432;
  --block-grad: linear-gradient(145deg, #d9a15c, #a9702f);
}
body[data-theme="neon"] {
  --bg: #05060f; --bg2: #0a0d1f; --panel: #0f1530; --panel2: #141a40;
  --accent: #00f0ff; --accent2: #ff2bd6; --accent3: #baff29;
  --cell-empty: #10163a; --cell-border: #1e2a60;
  --block-grad: linear-gradient(145deg, #00f0ff, #7b2bff);
  --text: #eafcff;
}
body[data-theme="crystal"] {
  --bg: #0d1b2e; --bg2: #13253d; --panel: #17304f; --panel2: #1d3b60;
  --accent: #7fdfff; --accent2: #a78bfa; --accent3: #c4f1ff;
  --cell-empty: #16324f; --cell-border: #2a5a86;
  --block-grad: linear-gradient(145deg, #bff4ff, #7fb8ff);
  --text: #eef8ff;
}

body {
  font-family: var(--font);
  background: radial-gradient(circle at 50% 0%, var(--bg2), var(--bg));
  color: var(--text);
  min-height: 100vh;
  display: flex;
  justify-content: center;
}

#app {
  width: 100%;
  max-width: 480px;
  min-height: 100vh;
  position: relative;
  display: flex;
  flex-direction: column;
}

.screen { display: none; flex-direction: column; flex: 1; min-height: 100vh; padding-bottom: 12px; }
.screen.active { display: flex; }

/* ---------- MENU ---------- */
.menu-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  text-align: center;
  gap: 10px;
}
.logo { font-size: 44px; font-weight: 800; letter-spacing: -1px; }
.logo span { color: var(--accent2); }
.tagline { color: var(--text-dim); margin-bottom: 12px; font-size: 14px; }
.menu-stats { display: flex; gap: 18px; margin-bottom: 18px; }
.stat { background: var(--panel); padding: 8px 16px; border-radius: 999px; font-weight: 700; display: flex; align-items: center; gap: 6px; }
.stat-icon { font-size: 16px; }
.menu-buttons { display: flex; flex-direction: column; gap: 12px; width: 100%; max-width: 300px; }
.footnote { color: var(--text-dim); font-size: 11px; margin-top: 22px; opacity: .7; }
.footnote.center { text-align: center; padding: 10px; }

/* ---------- BUTTONS ---------- */
.btn {
  border: none; border-radius: 14px; padding: 12px 18px; font-size: 15px; font-weight: 700;
  cursor: pointer; color: var(--text); background: var(--panel2); transition: transform .1s, filter .15s;
  position: relative;
}
.btn:active { transform: scale(.96); }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn-primary { background: linear-gradient(135deg, var(--accent), var(--accent2)); color: white; box-shadow: 0 6px 16px rgba(124,77,255,.35); }
.btn-secondary { background: var(--panel2); }
.btn-ghost { background: transparent; color: var(--text-dim); }
.btn-lg { padding: 16px; font-size: 16px; border-radius: 16px; }
.booster { background: var(--panel); font-size: 12px; padding: 10px 12px; flex: 1; }
.icon-btn { background: var(--panel); border: none; color: var(--text); width: 38px; height: 38px; border-radius: 50%; font-size: 18px; cursor: pointer; }
.badge { background: var(--filled); color: #063; font-size: 10px; padding: 2px 8px; border-radius: 999px; margin-left: 8px; font-weight: 800; }
.hidden { display: none !important; }

/* ---------- HUD ---------- */
.hud { display: flex; align-items: center; justify-content: space-between; padding: 12px 14px; }
.hud-mid { text-align: center; flex: 1; }
.hud-title { font-weight: 800; font-size: 16px; }
.hud-phase { font-size: 11px; color: var(--text-dim); text-transform: uppercase; letter-spacing: .5px; }
.pill { background: var(--panel); padding: 7px 14px; border-radius: 999px; font-weight: 800; font-size: 14px; }

.progress-row { display: flex; gap: 6px; padding: 0 14px 8px; flex-wrap: wrap; justify-content: center; }
.progress-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--cell-border); }
.progress-dot.done { background: var(--filled); }

/* ---------- BOARD ---------- */
.board-wrap { display: flex; justify-content: center; padding: 6px 14px; }
.board {
  display: grid;
  gap: 8px;
  width: 100%;
  max-width: 420px;
}
.cell {
  aspect-ratio: 1;
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  position: relative;
  transition: transform .15s, box-shadow .15s, background .2s;
}
.cell.bg { background: transparent; }
.cell.target {
  background: var(--cell-empty);
  border: 2px dashed var(--cell-border);
  font-size: 15px;
}
.cell.target .target-type-icon { font-size: 10px; color: var(--text-dim); font-weight: 600; margin-top: 2px; }
.cell.target.type-exact { border-color: var(--target-exact); }
.cell.target.type-pow2 { border-color: var(--target-pow2); }
.cell.target.type-mult3 { border-color: var(--target-mult3); }
.cell.target.filled {
  border-style: solid;
  background: var(--block-grad);
  color: white;
  box-shadow: 0 4px 14px rgba(0,0,0,.35);
  animation: pop .3s ease;
}
.cell.target.valid-drop { box-shadow: 0 0 0 3px var(--accent3); animation: pulse 1s infinite; }
.cell.target.reject { animation: shake .35s; }

@keyframes pop { 0% { transform: scale(.6); } 60% { transform: scale(1.1); } 100% { transform: scale(1); } }
@keyframes pulse { 0%,100% { box-shadow: 0 0 0 3px var(--accent3);} 50% { box-shadow: 0 0 0 6px transparent; } }
@keyframes shake { 0%,100%{transform:translateX(0);} 25%{transform:translateX(-6px);} 75%{transform:translateX(6px);} }

/* ---------- TRAY ---------- */
.tray-panel { padding: 10px 14px; margin-top: auto; }
.tray-label { font-size: 12px; color: var(--text-dim); font-weight: 700; margin-bottom: 6px; }
.tray {
  display: flex;
  gap: 8px;
  min-height: 70px;
  background: var(--panel);
  border-radius: 16px;
  padding: 8px;
  flex-wrap: wrap;
  align-content: flex-start;
}
.block {
  background: var(--block-grad);
  color: white;
  min-width: 62px;
  height: 54px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 16px;
  cursor: pointer;
  box-shadow: 0 4px 10px rgba(0,0,0,.3);
  transition: transform .12s, box-shadow .12s;
  animation: pop .25s ease;
  padding: 0 8px;
}
.block.selected { box-shadow: 0 0 0 3px var(--accent3); transform: translateY(-4px); }
.tray-actions { display: flex; gap: 10px; margin-top: 10px; }
.tray-actions .btn { flex: 1; }

.booster-row { display: flex; gap: 8px; padding: 6px 14px 14px; }

/* ---------- MODALS ---------- */
.modal {
  position: fixed; inset: 0; background: rgba(5,3,15,.72);
  display: flex; align-items: center; justify-content: center; z-index: 50; padding: 20px;
}
.modal-card {
  background: var(--panel); border-radius: 20px; padding: 24px; max-width: 380px; width: 100%;
  text-align: center; animation: pop .25s ease;
}
.modal-card h2 { font-size: 19px; margin-bottom: 14px; }
.split-options { display: flex; flex-direction: column; gap: 10px; margin-bottom: 16px; }
.split-option {
  background: var(--panel2); border: 2px solid transparent; border-radius: 14px; padding: 14px;
  display: flex; align-items: center; justify-content: center; gap: 10px; font-weight: 800; font-size: 18px;
  cursor: pointer; color: var(--text);
}
.split-option:active { transform: scale(.97); }
.split-option .plus { color: var(--text-dim); font-weight: 400; }
.win-emoji { font-size: 52px; margin-bottom: 6px; }
.win-card p { color: var(--text-dim); margin-bottom: 10px; }
.coins-earned { font-size: 22px; font-weight: 800; color: var(--accent3); margin-bottom: 18px; }
.lose-actions { display: flex; flex-direction: column; gap: 10px; margin-top: 14px; }

.ad-card { max-width: 320px; }
.ad-tag { font-size: 10px; letter-spacing: 1px; color: var(--accent3); font-weight: 800; margin-bottom: 8px; }
.ad-visual { font-size: 46px; margin-bottom: 10px; }
.ad-bar { height: 8px; background: var(--panel2); border-radius: 999px; overflow: hidden; margin-top: 14px; }
.ad-bar-fill { height: 100%; width: 0%; background: linear-gradient(90deg, var(--accent), var(--accent2)); transition: width .1s linear; }

.confirm-text { color: var(--text-dim); font-size: 13.5px; margin-bottom: 16px; line-height: 1.5; white-space: pre-line; }

.name-input {
  width: 100%; background: var(--panel2); border: 2px solid var(--cell-border); color: var(--text);
  border-radius: 12px; padding: 12px 14px; font-size: 15px; margin: 6px 0 4px; font-family: var(--font);
}
.name-input:focus { outline: none; border-color: var(--accent3); }

.toast {
  position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%);
  background: var(--panel2); color: var(--text); padding: 12px 18px; border-radius: 12px;
  font-size: 13.5px; font-weight: 600; max-width: 320px; text-align: center;
  box-shadow: 0 8px 20px rgba(0,0,0,.4); z-index: 80; animation: pop .2s ease;
}

/* ---------- THEMES ---------- */
.themes-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; padding: 16px; }
.theme-card {
  background: var(--panel); border-radius: 16px; padding: 14px; text-align: center; cursor: pointer;
  border: 2px solid transparent;
}
.theme-card.active { border-color: var(--accent3); }
.theme-swatch { height: 60px; border-radius: 10px; margin-bottom: 10px; }
.theme-name { font-weight: 800; font-size: 14px; margin-bottom: 4px; }
.theme-price { font-size: 12px; color: var(--text-dim); }
.theme-owned { font-size: 11px; color: var(--filled); font-weight: 800; }

/* ---------- HOW TO ---------- */
.howto-content { padding: 16px; }
.howto-content h3 { margin-top: 16px; margin-bottom: 4px; font-size: 15px; color: var(--accent3); }
.howto-content p { color: var(--text-dim); font-size: 13.5px; line-height: 1.5; }

@media (max-width: 360px) {
  .block { min-width: 52px; height: 48px; font-size: 14px; }
}
