:root{
  --bg1:#ff6b7a;
  --bg2:#0bb3ff;
  --card:rgba(255,255,255,.14);
  --card2:rgba(255,255,255,.10);
  --stroke:rgba(255,255,255,.22);
  --text:#ffffff;
  --muted:rgba(255,255,255,.75);
  --tile:#eaf7ff;
  --tileText:#125b7a;
  --accent:#ffe082;
  --good:#3dff9a;
  --bad:#ff5b6b;
  --shadow: 0 18px 55px rgba(0,0,0,.22);
}

*{box-sizing:border-box}
html,body{height:100%}
body{
  margin:0;
  font-family: "Segoe UI", system-ui, -apple-system, Arial, sans-serif;
  color:var(--text);
  background: radial-gradient(1200px 600px at 30% 0%, rgba(255,255,255,.25), transparent 60%),
              linear-gradient(180deg, var(--bg1), var(--bg2));
  overflow-x:hidden;
}

.container{width:min(980px,92%);margin-inline:auto}
.topbar{
  position:sticky;top:0;z-index:10;
  background:rgba(0,0,0,.18);
  backdrop-filter: blur(10px);
  border-bottom:1px solid rgba(255,255,255,.15);
}
.topbar .wrap{display:flex;align-items:center;justify-content:space-between;padding:12px 0}
.brand{display:flex;gap:12px;align-items:center;text-decoration:none;color:var(--text)}
.brand .mark{
  width:44px;height:44px;border-radius:14px;
  display:grid;place-items:center;
  background:rgba(0,0,0,.22);
  border:1px solid rgba(255,255,255,.18);
  box-shadow: 0 10px 25px rgba(0,0,0,.18);
  font-weight:800;letter-spacing:.5px;
}
.brand .txt b{display:block;font-size:15px;line-height:1}
.brand .txt small{display:block;font-size:12px;color:var(--muted);margin-top:3px}

.actions{display:flex;gap:10px;align-items:center}
.btn{
  border:1px solid rgba(255,255,255,.18);
  background:rgba(0,0,0,.18);
  color:var(--text);
  padding:10px 12px;
  border-radius:12px;
  cursor:pointer;
  font-weight:700;
  transition:.15s ease;
}
.btn:hover{transform:translateY(-1px);background:rgba(0,0,0,.24)}
.btn.primary{background:rgba(255,255,255,.16)}
.btn.primary:hover{background:rgba(255,255,255,.22)}
.btn.icon{width:44px;height:44px;display:grid;place-items:center;padding:0}

.main{padding:18px 0 42px}

.card{
  background: linear-gradient(180deg, var(--card), var(--card2));
  border:1px solid rgba(255,255,255,.18);
  border-radius:22px;
  box-shadow:var(--shadow);
  overflow:hidden;
}

.screen{display:none}
.screen.active{display:block}

.hero{
  padding:18px 18px 12px;
  display:flex;gap:14px;align-items:flex-start;justify-content:space-between;
  border-bottom:1px solid rgba(255,255,255,.14);
}
.hero .left h1{margin:0;font-size:20px}
.hero .left p{margin:6px 0 0;color:var(--muted);font-size:13px;max-width:520px}
.pills{display:flex;gap:8px;flex-wrap:wrap;margin-top:12px}
.pill{
  padding:6px 10px;border-radius:999px;
  background:rgba(0,0,0,.18);
  border:1px solid rgba(255,255,255,.14);
  font-size:12px;color:var(--muted);font-weight:700;
}

.pad{padding:16px 18px 18px}
.row{display:flex;gap:14px;flex-wrap:wrap}
.col{flex:1;min-width:260px}

.field label{display:block;font-size:12px;color:var(--muted);font-weight:700;margin-bottom:8px}
.field input{
  width:100%;
  padding:12px 14px;
  border-radius:14px;
  border:1px solid rgba(255,255,255,.18);
  background:rgba(0,0,0,.14);
  color:#fff;
  outline:none;
  font-weight:800;
}
.field input::placeholder{color:rgba(255,255,255,.55);font-weight:600}

.level-grid{
  display:grid;
  grid-template-columns: repeat(8, minmax(0,1fr));
  gap:10px;
}
@media (max-width:860px){ .level-grid{grid-template-columns: repeat(6, minmax(0,1fr));} }
@media (max-width:520px){ .level-grid{grid-template-columns: repeat(5, minmax(0,1fr));} }

.level-btn{
  padding:12px 0;
  border-radius:16px;
  border:1px solid rgba(255,255,255,.16);
  background:rgba(0,0,0,.14);
  color:#fff;
  font-weight:900;
  cursor:pointer;
  position:relative;
  transition:.12s ease;
}
.level-btn:hover{transform:translateY(-1px);background:rgba(0,0,0,.20)}
.level-btn.locked{opacity:.45;cursor:not-allowed}
.level-btn.solved::after{
  content:"✓";
  position:absolute;right:10px;top:8px;
  width:22px;height:22px;border-radius:999px;
  display:grid;place-items:center;
  background:rgba(61,255,154,.20);
  border:1px solid rgba(61,255,154,.50);
  color:var(--good);font-weight:1000;
}

.game-head{
  display:flex;align-items:center;justify-content:space-between;
  padding:14px 18px;
  border-bottom:1px solid rgba(255,255,255,.14);
  gap:12px;flex-wrap:wrap;
}
.game-head .meta{display:flex;gap:10px;align-items:center;flex-wrap:wrap}
.badge{
  padding:7px 10px;border-radius:999px;
  background:rgba(0,0,0,.18);
  border:1px solid rgba(255,255,255,.14);
  font-size:12px;font-weight:900;
}
.small{color:var(--muted);font-size:12px;font-weight:700}

.board-wrap{padding:16px 18px 10px;display:grid;gap:14px}
.board{
  width:min(520px,100%);
  margin-inline:auto;
  display:grid;
  grid-template-columns: repeat(5, 1fr);
  gap:10px;
  padding:14px;
  border-radius:22px;
  background:rgba(0,0,0,.12);
  border:1px solid rgba(255,255,255,.14);
}
.cell{
  height:62px;
  border-radius:16px;
  display:grid;
  place-items:center;
  font-weight:1000;
  user-select:none;
  position:relative;
  overflow:hidden;
}
.cell.fixed{
  background:rgba(255,255,255,.16);
  border:1px solid rgba(255,255,255,.10);
}
.cell.blank{
  background:rgba(255,255,255,.90);
  border:1px solid rgba(0,0,0,.08);
  color:#1a2b38;
  cursor:pointer;
}
.cell.blank.selected{
  outline:3px solid rgba(255,224,130,.75);
  outline-offset:2px;
}
.cell.spacer{
  background:transparent;
  border:1px dashed rgba(255,255,255,.18);
  opacity:.35;
}

.tiles{
  width:min(520px,100%);
  margin-inline:auto;
  display:flex;
  flex-wrap:wrap;
  gap:10px;
  justify-content:center;
  padding:10px 6px 6px;
}
.tile{
  min-width:74px;
  padding:12px 14px;
  border-radius:16px;
  background:rgba(234,247,255,.95);
  color:var(--tileText);
  font-weight:1000;
  border:1px solid rgba(0,0,0,.08);
  cursor:grab;
  transition:.12s ease;
}
.tile:active{cursor:grabbing}
.tile.used{
  opacity:.35;
  transform:scale(.98);
  cursor:not-allowed;
}

.feedback{
  text-align:center;
  font-weight:900;
  padding:0 18px 14px;
  min-height:22px;
}
.feedback.good{color:var(--good)}
.feedback.bad{color:var(--bad)}

.hud-actions{display:flex;gap:10px;justify-content:center;flex-wrap:wrap;padding:0 18px 18px}

.ad-slot{
  width:100%;
  padding:14px 18px 18px;
  border-top:1px solid rgba(255,255,255,.12);
  display:flex;justify-content:center;
}
/* Responsive */
@media (max-width:520px){
  .cell{height:56px;border-radius:14px}
  .tile{min-width:68px}
}

/* v3 additions */
.btn:disabled{opacity:.45;cursor:not-allowed;transform:none}
.hint-counter{display:inline-flex;gap:8px;align-items:center}
.hint-dot{
  width:10px;height:10px;border-radius:99px;
  background:rgba(255,224,130,.95);
  box-shadow:0 0 0 2px rgba(0,0,0,.12);
}
.hint-dot.used{opacity:.25}
#confetti{
  position:fixed;inset:0;
  pointer-events:none;
  z-index:9999;
}
.toast{
  position:fixed;left:50%;bottom:18px;transform:translateX(-50%);
  background:rgba(0,0,0,.35);
  border:1px solid rgba(255,255,255,.18);
  color:#fff;
  padding:10px 14px;
  border-radius:14px;
  backdrop-filter: blur(10px);
  box-shadow: 0 12px 35px rgba(0,0,0,.22);
  font-weight:800;
  display:none;
  z-index:9998;
}
.toast.show{display:block;animation:pop .18s ease}
@keyframes pop{from{transform:translateX(-50%) translateY(8px);opacity:0}to{transform:translateX(-50%) translateY(0);opacity:1}}

/* v6 difficulty */
.diff-tabs{display:flex;gap:10px;flex-wrap:wrap;margin-top:10px}
.tab{
  padding:10px 12px;border-radius:14px;
  border:1px solid rgba(255,255,255,.16);
  background:rgba(0,0,0,.14);
  color:#fff;
  font-weight:1000;
  cursor:pointer;
  transition:.12s ease;
}
.tab.active{background:rgba(255,255,255,.18)}
.tab small{opacity:.75;font-weight:800}

/* v7 playful animations */
body::before, body::after{
  content:"";
  position:fixed;
  width:520px;height:520px;
  border-radius:50%;
  filter: blur(40px);
  opacity:.18;
  z-index:-1;
  animation: floaty 10s ease-in-out infinite;
  pointer-events:none;
}
body::before{
  left:-120px; top:120px;
  background: rgba(255,255,255,.9);
}
body::after{
  right:-160px; bottom:60px;
  background: rgba(255,255,255,.7);
  animation-duration: 13s;
}
@keyframes floaty{
  0%,100%{ transform: translate(0,0) scale(1); }
  50%{ transform: translate(30px,-25px) scale(1.06); }
}

.board{
  position:relative;
}
.board::after{
  content:"";
  position:absolute; inset:-2px;
  border-radius:24px;
  background: linear-gradient(120deg, rgba(255,224,130,.25), rgba(255,255,255,.08), rgba(61,255,154,.18));
  opacity:.45;
  filter: blur(14px);
  z-index:-1;
  animation: glowPulse 3.2s ease-in-out infinite;
}
@keyframes glowPulse{
  0%,100%{ opacity:.35; transform: scale(1); }
  50%{ opacity:.55; transform: scale(1.01); }
}

.tile{ animation: tilePop .22s ease both; }
@keyframes tilePop{
  from{ transform: translateY(6px) scale(.96); opacity:0; }
  to{ transform: translateY(0) scale(1); opacity:1; }
}
.tile:hover{ transform: translateY(-2px) scale(1.03); }
.tile:active{ transform: translateY(0) scale(.98); }

.cell.blank{ transition: transform .12s ease, box-shadow .12s ease, background .12s ease; position:relative; }
.cell.blank:hover{ transform: translateY(-1px); box-shadow: 0 10px 24px rgba(0,0,0,.12); }
.cell.blank.placed{ background: rgba(255,255,255,.96); }
.cell.blank.sparkle::after{
  content:"";
  position:absolute; inset:-8px;
  border-radius:18px;
  background: radial-gradient(circle at 30% 30%, rgba(255,224,130,.85), transparent 55%),
              radial-gradient(circle at 70% 65%, rgba(61,255,154,.65), transparent 55%);
  opacity:.65;
  filter: blur(6px);
  animation: sparkle .45s ease-out forwards;
  pointer-events:none;
}
@keyframes sparkle{
  from{ transform: scale(.85); opacity:.0; }
  30%{ opacity:.7; }
  to{ transform: scale(1.15); opacity:0; }
}

.shake{ animation: shake .28s ease-in-out; }
@keyframes shake{
  0%,100%{ transform: translateX(0); }
  25%{ transform: translateX(-6px); }
  50%{ transform: translateX(6px); }
  75%{ transform: translateX(-4px); }
}
.successGlow{ animation: successGlow 1.1s ease-in-out; }
@keyframes successGlow{
  0%{ box-shadow: 0 0 0 rgba(61,255,154,0); }
  35%{ box-shadow: 0 0 0 10px rgba(61,255,154,.18); }
  100%{ box-shadow: 0 0 0 rgba(61,255,154,0); }
}

/* v9 PRO: stars, xp, ranks, tracing */
.badge.rank{background:rgba(255,255,255,.14);border:1px solid rgba(255,255,255,.18)}
.badge.rank b{letter-spacing:.4px}
.kpi{display:flex;gap:10px;flex-wrap:wrap;margin-top:10px}
.kpi .chip{
  padding:10px 12px;border-radius:14px;
  border:1px solid rgba(255,255,255,.16);
  background:rgba(0,0,0,.12);
  color:#fff;font-weight:900
}
.kpi .chip small{display:block;opacity:.75;font-weight:800;margin-top:2px}
.xpbar{
  height:10px;border-radius:999px;
  background:rgba(255,255,255,.12);
  overflow:hidden; border:1px solid rgba(255,255,255,.14);
}
.xpbar > i{
  display:block;height:100%;
  width:0%;
  background:linear-gradient(90deg, rgba(255,224,130,.85), rgba(61,255,154,.75));
  transition: width .35s ease;
}
.stars{display:inline-flex;gap:4px;align-items:center}
.star{opacity:.35;filter:drop-shadow(0 6px 12px rgba(0,0,0,.18));transform:translateY(0);transition:.15s ease}
.star.on{opacity:1;transform:translateY(-1px)}
.level-btn .mini-stars{
  display:flex;gap:3px;justify-content:center;margin-top:6px
}
.level-btn .mini-stars i{
  width:6px;height:6px;border-radius:99px;background:rgba(255,224,130,.25)
}
.level-btn.s1 .mini-stars i:nth-child(-n+1){background:rgba(255,224,130,.85)}
.level-btn.s2 .mini-stars i:nth-child(-n+2){background:rgba(255,224,130,.85)}
.level-btn.s3 .mini-stars i:nth-child(-n+3){background:rgba(255,224,130,.85)}

.mode-toggle{
  display:flex;gap:10px;align-items:center;flex-wrap:wrap
}
.switch{
  display:inline-flex;align-items:center;gap:10px;
  padding:10px 12px;border-radius:16px;
  background:rgba(0,0,0,.12);
  border:1px solid rgba(255,255,255,.16);
  color:#fff;font-weight:900;
}
.switch input{width:18px;height:18px}
.timer{
  font-variant-numeric: tabular-nums;
  font-weight:1000;
  padding:8px 10px;border-radius:14px;
  background:rgba(255,255,255,.12);
  border:1px solid rgba(255,255,255,.16);
}
.timer.danger{animation: pulseRed .7s ease-in-out infinite}
@keyframes pulseRed{
  0%,100%{transform:scale(1);}
  50%{transform:scale(1.03);}
}

/* equation tracing */
.cell.trace{position:relative}
.cell.trace::before{
  content:"";
  position:absolute; inset:-6px;
  border-radius:18px;
  background:linear-gradient(90deg, rgba(61,255,154,.0), rgba(61,255,154,.25), rgba(255,224,130,.22), rgba(61,255,154,0));
  filter: blur(7px);
  opacity:.0;
  animation: trace 650ms ease-out forwards;
  pointer-events:none;
}
@keyframes trace{
  0%{opacity:0; transform:translateX(-12px);}
  35%{opacity:.7;}
  100%{opacity:0; transform:translateX(12px);}
}

/* modal */
.modal{
  position:fixed; inset:0;
  display:none; align-items:center; justify-content:center;
  background:rgba(0,0,0,.45);
  z-index:9997;
}
.modal.show{display:flex}
.modal-card{
  width:min(520px, calc(100% - 28px));
  border-radius:22px;
  background:rgba(10,18,28,.92);
  border:1px solid rgba(255,255,255,.14);
  box-shadow: 0 24px 80px rgba(0,0,0,.35);
  backdrop-filter: blur(12px);
  padding:18px;
  color:#fff;
}
.modal-card h2{margin:0 0 8px 0}
.modal-card p{margin:0 0 12px 0; opacity:.85}
.modal-actions{display:flex;gap:10px;justify-content:flex-end;flex-wrap:wrap;margin-top:14px}
