:root {
  --bg: #0c0f1a;
  --bg2: #151a2c;
  --line: #2a3350;
  --txt: #e8edf7;
  --dim: #94a1c0;
  --accent: #3fd0ff;
  --gold: #ffd23f;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  background: var(--bg);
  color: var(--txt);
  font-family: "Trebuchet MS", "Segoe UI", system-ui, sans-serif;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}
#app { position: fixed; inset: 0; }

.screen { position: absolute; inset: 0; display: none; flex-direction: column; }
.screen.active { display: flex; }

/* ------------------------------------------------------------------ HOME */
#home {
  align-items: center; justify-content: center;
  background:
    radial-gradient(circle at 20% 10%, #24345e 0%, transparent 55%),
    radial-gradient(circle at 85% 85%, #3a1f5e 0%, transparent 55%),
    var(--bg);
}
.starbox {
  position: absolute; top: 18px; right: 20px;
  display: flex; align-items: center; gap: 8px;
  background: rgba(0,0,0,.45);
  border: 2px solid var(--gold);
  border-radius: 999px;
  padding: 8px 18px;
  font-size: 22px; font-weight: 700;
  box-shadow: 0 0 24px rgba(255,210,63,.25);
}
.star { color: var(--gold); text-shadow: 0 0 10px rgba(255,210,63,.7); }
.coin { color: var(--gold); }
.home-inner { text-align: center; padding: 20px; }
.logo {
  font-size: clamp(38px, 9vw, 96px);
  letter-spacing: 3px;
  line-height: .95;
  font-weight: 900;
  background: linear-gradient(180deg, #fff, #6fd0ff 60%, #2f7bff);
  -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 6px 0 rgba(0,0,0,.45));
}
.logo span { display: block; font-size: .72em; letter-spacing: 14px;
  background: linear-gradient(180deg, #ffe6a8, #ffb01a);
  -webkit-background-clip: text; background-clip: text; color: transparent; }
.tagline { color: var(--dim); margin: 14px 0 34px; font-size: 15px; }
.home-row { display: flex; gap: 18px; justify-content: center; align-items: center; flex-wrap: wrap; }
.bigbtn {
  border: none; cursor: pointer; color: #fff;
  border-radius: 18px;
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 18px 26px; min-width: 110px;
  font: 700 15px/1 inherit; letter-spacing: 1px;
  background: #232c46; border: 2px solid var(--line);
  transition: transform .12s, box-shadow .12s, border-color .12s;
}
.bigbtn .ico { font-size: 30px; }
.bigbtn:hover { transform: translateY(-3px); border-color: var(--accent); }
.bigbtn.play {
  padding: 26px 52px; min-width: 190px;
  background: linear-gradient(180deg, #3fd0ff, #1f7bd8);
  border-color: #9ce8ff;
  box-shadow: 0 8px 0 #12457a, 0 12px 30px rgba(63,208,255,.3);
}
.bigbtn.play .ico { font-size: 40px; }
.bigbtn.play:hover { box-shadow: 0 10px 0 #12457a, 0 16px 40px rgba(63,208,255,.45); }
.home-foot { margin-top: 34px; display: flex; gap: 20px; justify-content: center; align-items: center; flex-wrap: wrap; color: var(--dim); font-size: 13px; }
.toggle { cursor: pointer; display: flex; align-items: center; gap: 6px; }
.linkbtn { background: none; border: none; color: var(--dim); text-decoration: underline; cursor: pointer; font: inherit; font-size: 13px; }
.linkbtn:hover { color: var(--accent); }

/* ------------------------------------------------------------------- BAR */
.bar {
  display: flex; align-items: center; gap: 14px;
  padding: 14px 18px; background: var(--bg2);
  border-bottom: 2px solid var(--line); flex-shrink: 0;
}
.bar h2 { font-size: 20px; letter-spacing: 1px; flex: 1; }
.backbtn { background: #2a3350; border: none; color: var(--txt); padding: 8px 16px; border-radius: 10px; cursor: pointer; font: 700 14px inherit; }
.backbtn:hover { background: #3a4670; }
.barstats { display: flex; gap: 10px; }
.chip { background: #0e1424; border: 1px solid var(--line); border-radius: 999px; padding: 6px 14px; font-size: 14px; }

/* --------------------------------------------------------------- LEVELS */
.levellist { flex: 1; overflow-y: auto; padding: 16px; display: grid; gap: 12px;
  grid-template-columns: repeat(auto-fill, minmax(330px, 1fr)); align-content: start; }
.lvl {
  background: linear-gradient(135deg, var(--bg2), #10152a);
  border: 2px solid var(--line); border-radius: 14px; padding: 14px 16px;
  display: flex; flex-direction: column; gap: 10px;
}
.lvl-top { display: flex; align-items: center; gap: 10px; }
.lvl-num { width: 30px; height: 30px; border-radius: 8px; background: #0e1424; display: grid; place-items: center; font-weight: 700; font-size: 13px; color: var(--dim); flex-shrink: 0; }
.lvl-name { font-weight: 700; font-size: 16px; flex: 1; }
.pill { font-size: 11px; font-weight: 700; letter-spacing: .5px; padding: 3px 10px; border-radius: 999px; color: #0c0f1a; }
.lvl-meta { display: flex; align-items: center; gap: 14px; font-size: 13px; color: var(--dim); }
.lvl-coins { display: flex; gap: 5px; }
.lvl-coins i { width: 13px; height: 13px; border-radius: 50%; border: 2px solid #6b5a1f; background: #21242f; display: block; }
.lvl-coins i.got { background: var(--gold); border-color: #fff3bd; box-shadow: 0 0 8px rgba(255,210,63,.8); }
.lvl-bar { height: 6px; border-radius: 4px; background: #0e1424; overflow: hidden; }
.lvl-bar i { display: block; height: 100%; background: linear-gradient(90deg, #3fd0ff, #7dffc4); }
.lvl-btns { display: flex; gap: 8px; }
.lvl-btns button { flex: 1; border: none; border-radius: 10px; padding: 10px; cursor: pointer; font: 700 14px inherit; }
.b-play { background: linear-gradient(180deg,#3fd0ff,#1f7bd8); color: #fff; }
.b-prac { background: #2a3350; color: var(--txt); }
.b-play:hover { filter: brightness(1.12); }
.b-prac:hover { background: #3a4670; }
.done-tag { color: #7dffc4; font-weight: 700; }

/* ------------------------------------------------------------ CUSTOMIZE */
.cust-wrap { flex: 1; display: flex; gap: 20px; padding: 18px; overflow: hidden; }
.cust-preview { width: 240px; flex-shrink: 0; display: flex; flex-direction: column; align-items: center; gap: 12px;
  background: radial-gradient(circle at 50% 40%, #22305a, #0e1424); border: 2px solid var(--line); border-radius: 16px; padding: 16px; }
#iconPreview { width: 200px; height: 200px; }
.cust-name { font-weight: 700; font-size: 18px; letter-spacing: 1px; }
.cust-panels { flex: 1; overflow-y: auto; padding-right: 6px; }
.cust-panels h3 { font-size: 13px; letter-spacing: 2px; text-transform: uppercase; color: var(--dim); margin: 4px 0 10px; }
.grid { display: grid; gap: 8px; margin-bottom: 22px; }
.grid.icons { grid-template-columns: repeat(auto-fill, minmax(76px, 1fr)); }
.grid.colors { grid-template-columns: repeat(auto-fill, minmax(46px, 1fr)); }
.cell {
  position: relative; border: 2px solid var(--line); border-radius: 12px; background: #10152a;
  cursor: pointer; aspect-ratio: 1; background-size: cover; background-position: center;
}
.cell:hover { border-color: var(--accent); }
.cell.sel { border-color: var(--gold); box-shadow: 0 0 0 2px rgba(255,210,63,.35); }
.cell.locked { cursor: not-allowed; filter: grayscale(1) brightness(.4); }
.cell.locked::after { content: "🔒"; position: absolute; inset: 0; display: grid; place-items: center; font-size: 18px; filter: none; }
.cell.color { border-radius: 50%; }

/* ---------------------------------------------------------- ACHIEVEMENTS */
.achlist { flex: 1; overflow-y: auto; padding: 16px; }
.achgroup { font-size: 13px; letter-spacing: 2px; text-transform: uppercase; color: var(--dim); margin: 18px 0 10px; }
.achgroup:first-child { margin-top: 0; }
.achgrid { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
.ach { display: flex; gap: 12px; align-items: center; background: var(--bg2); border: 2px solid var(--line); border-radius: 12px; padding: 12px 14px; }
.ach.unlocked { border-color: #3d7a4d; background: linear-gradient(135deg, #16281d, #10152a); }
.ach-badge { width: 40px; height: 40px; border-radius: 10px; background: #0e1424; display: grid; place-items: center; font-size: 18px; flex-shrink: 0; }
.ach.unlocked .ach-badge { background: #ffd23f22; color: var(--gold); }
.ach-name { font-weight: 700; font-size: 14px; }
.ach-desc { font-size: 12px; color: var(--dim); }
.ach-rew { font-size: 11px; color: var(--accent); margin-top: 3px; }

/* ------------------------------------------------------------------ GAME */
#game { background: #000; }
#gl { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
.hud { position: absolute; top: 0; left: 0; right: 0; padding: 12px 14px; pointer-events: none; }
.hud-top { display: flex; align-items: center; gap: 12px; }
.iconbtn { pointer-events: auto; width: 38px; height: 38px; border-radius: 10px; border: 2px solid rgba(255,255,255,.35);
  background: rgba(0,0,0,.4); color: #fff; cursor: pointer; font: 700 14px inherit; flex-shrink: 0; }
.progress { flex: 1; height: 20px; border-radius: 999px; background: rgba(0,0,0,.45);
  border: 2px solid rgba(255,255,255,.35); position: relative; overflow: hidden; }
.progress-fill { height: 100%; width: 0; background: linear-gradient(90deg, #7dffc4, #3fd0ff); }
.progress span { position: absolute; inset: 0; display: grid; place-items: center; font-size: 12px; font-weight: 700;
  text-shadow: 0 1px 2px #000; }
.coinrow { display: flex; gap: 6px; }
.coinrow i { width: 16px; height: 16px; border-radius: 50%; border: 2px solid rgba(255,255,255,.4); background: rgba(0,0,0,.35); display: block; }
.coinrow i.got { background: var(--gold); border-color: #fff3bd; box-shadow: 0 0 10px var(--gold); }
.hud-sub { display: flex; justify-content: space-between; margin-top: 8px; font-size: 13px;
  text-shadow: 0 1px 3px #000; color: #fff; opacity: .9; }

.tapHint { position: absolute; bottom: 26px; left: 0; right: 0; text-align: center; color: #fff;
  text-shadow: 0 2px 6px #000; font-size: 14px; opacity: .8; pointer-events: none; transition: opacity .4s; }
.tapHint.hide { opacity: 0; }

.toasts { position: absolute; top: 74px; right: 14px; display: flex; flex-direction: column; gap: 8px; pointer-events: none; }
.toast {
  background: linear-gradient(135deg, #1a2340, #101728);
  border: 2px solid var(--gold); border-radius: 12px; padding: 10px 14px; min-width: 220px;
  box-shadow: 0 8px 30px rgba(0,0,0,.6);
  animation: toastin .4s ease-out;
}
.toast b { display: block; font-size: 14px; color: var(--gold); }
.toast small { font-size: 12px; color: var(--dim); }
.toast .rew { font-size: 11px; color: var(--accent); }
@keyframes toastin { from { transform: translateX(40px); opacity: 0; } to { transform: none; opacity: 1; } }

.overlay { position: absolute; inset: 0; display: none; place-items: center; background: rgba(4,6,14,.78); backdrop-filter: blur(3px); }
.overlay.show { display: grid; }
.panel { background: var(--bg2); border: 2px solid var(--line); border-radius: 18px; padding: 26px 30px; text-align: center; min-width: 300px; }
.panel.wide { min-width: 340px; max-width: 90vw; }
.panel h2 { font-size: 26px; margin-bottom: 6px; letter-spacing: 1px; }
.panel .sub { color: var(--dim); font-size: 14px; margin-bottom: 18px; }
.pbtn { display: block; width: 100%; margin: 8px 0; padding: 12px 20px; border: none; border-radius: 12px; cursor: pointer;
  font: 700 15px inherit; background: linear-gradient(180deg,#3fd0ff,#1f7bd8); color: #fff; }
.pbtn.ghost { background: #2a3350; color: var(--txt); }
.pbtn:hover { filter: brightness(1.12); }
.panel-row { display: flex; gap: 10px; }
.panel-row .pbtn { margin-top: 14px; }
.rewards { display: flex; flex-direction: column; gap: 8px; margin: 10px 0; }
.rewline { background: #0e1424; border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; font-size: 13px; text-align: left; }
.rewline b { color: var(--gold); }
.bigstars { font-size: 30px; color: var(--gold); letter-spacing: 3px; margin-bottom: 6px; text-shadow: 0 0 18px rgba(255,210,63,.6); }

.loaderr { position: fixed; inset: auto 20px 20px 20px; background: #401c1c; border: 2px solid #ff6b6b;
  border-radius: 12px; padding: 14px 18px; font-size: 14px; z-index: 99; }

@media (max-width: 620px) {
  .cust-wrap { flex-direction: column; overflow-y: auto; }
  .cust-preview { width: 100%; }
  #iconPreview { width: 150px; height: 150px; }
  .levellist { grid-template-columns: 1fr; }
  .starbox { font-size: 18px; padding: 6px 14px; }
}
