:root{
  --ivory:#FAF7F2;
  --lilac:#C9B8E8;
  --peach:#FFC9A8;
  --mint:#A8E0C8;
  --ink:#4A3F5C;
  --ink-2:#6A5F80;
  --ink-soft:rgba(74,63,92,.6);
  --shadow:0 4px 12px rgba(74,63,92,.12);
  --shadow-lg:0 10px 28px rgba(74,63,92,.16);
  --r:20px;
}

*{box-sizing:border-box;}
html,body{height:100%;margin:0;padding:0;}
body{
  font-family:'Baloo Bhaijaan 2','Tajawal','Segoe UI',system-ui,sans-serif;
  background:var(--ivory);
  color:var(--ink);
  overscroll-behavior:none;
  -webkit-tap-highlight-color:transparent;
  -webkit-font-smoothing:antialiased;
}
button{font-family:inherit;}

.app{
  position:relative;
  height:100%;
  width:100%;
  background:var(--ivory);
  color:var(--ink);
  overflow:hidden;
  user-select:none;
  -webkit-user-select:none;
}

/* ================= HUD ================= */
.hud{padding:8px 10px 0;}
.hud-bar{
  display:flex;
  align-items:center;
  gap:6px;
  width:100%;
  padding:6px 8px;
  border-radius:16px;
  background:rgba(250,247,242,.85);
  -webkit-backdrop-filter:blur(10px);
  backdrop-filter:blur(10px);
  box-shadow:var(--shadow);
}
.chip{
  flex:1 1 0;
  min-width:0;
  display:flex;
  flex-direction:column;
  align-items:center;
  justify-content:center;
  line-height:1.05;
  overflow:hidden;
}
.chip-k{
  font-size:10px;
  font-weight:600;
  color:var(--ink-soft);
  letter-spacing:0;
  white-space:nowrap;
}
.chip-v{
  font-size:17px;
  font-weight:800;
  color:var(--ink);
  font-variant-numeric:tabular-nums;
  white-space:nowrap;
}
.chip-v small{font-size:10px;font-weight:600;color:var(--ink-soft);margin-inline-start:2px;}

.iconbtn{
  flex:0 0 auto;
  width:44px;height:44px;
  display:grid;place-items:center;
  border:0;border-radius:13px;
  background:rgba(201,184,232,.38);
  color:var(--ink);
  cursor:pointer;
  transition:transform .1s ease,background .18s ease;
}
.iconbtn:active{transform:scale(.94);background:rgba(201,184,232,.6);}
.iconbtn:focus-visible{outline:3px solid #7C6BA8;outline-offset:2px;}

/* ================= STAGE ================= */
.stage{
  position:relative;
  min-height:0;
  min-width:0;
  touch-action:none;
  overflow:hidden;
  background:#F6EBF0;
}
.stage canvas{
  display:block;
  touch-action:none;
}

.toast{
  position:absolute;
  inset-inline:0;
  top:12%;
  margin:0 auto;
  width:max-content;
  max-width:86%;
  padding:7px 18px;
  border-radius:999px;
  background:rgba(250,247,242,.94);
  box-shadow:var(--shadow);
  color:var(--ink);
  font-size:14px;
  font-weight:700;
  pointer-events:none;
  opacity:0;
  transform:translateY(-8px);
  transition:opacity .25s ease,transform .25s ease;
  z-index:5;
}
.toast.show{opacity:1;transform:translateY(0);}

/* ================= CONTROLS ================= */
.controls{
  padding:6px 12px 10px;
  touch-action:none;
}
.ctrl-group{
  display:flex;
  align-items:center;
  justify-content:center;
  gap:14px;
  width:100%;
}
.ctrl-hint{
  order:1;
  font-size:13px;
  font-weight:600;
  color:var(--ink-soft);
  max-width:46vw;
  line-height:1.3;
  text-align:center;
}
.jumpbtn{
  order:2;
  flex:0 0 auto;
  width:82px;height:82px;
  border:0;border-radius:50%;
  display:flex;flex-direction:column;
  align-items:center;justify-content:center;
  gap:1px;
  background:linear-gradient(180deg,#BEEEDA,#A8E0C8);
  color:#3B3350;
  font-weight:800;
  font-size:13px;
  cursor:pointer;
  touch-action:none;
  box-shadow:0 6px 16px rgba(74,63,92,.18), inset 0 -4px 0 rgba(74,63,92,.1);
  transition:transform .08s ease, box-shadow .12s ease;
}
.jumpbtn:active,.jumpbtn.pressed{
  transform:translateY(3px) scale(.96);
  box-shadow:0 2px 8px rgba(74,63,92,.16), inset 0 -1px 0 rgba(74,63,92,.1);
}
.jumpbtn:focus-visible{outline:3px solid #7C6BA8;outline-offset:3px;}

/* ================= OVERLAYS ================= */
.overlay{
  position:absolute;
  inset:0;
  z-index:30;
  display:flex;
  flex-direction:column;
  align-items:center;
  padding:16px;
  overflow-y:auto;
  touch-action:pan-y;
  background:rgba(250,247,242,.55);
  -webkit-backdrop-filter:blur(3px);
  backdrop-filter:blur(3px);
}
.overlay.hidden{display:none !important;}
.overlay.over{padding-top:118px;padding-bottom:18px;}

.card{
  margin:auto 0;
  width:100%;
  max-width:382px;
  padding:20px 18px 18px;
  border-radius:24px;
  background:rgba(255,253,250,.96);
  -webkit-backdrop-filter:blur(14px);
  backdrop-filter:blur(14px);
  box-shadow:var(--shadow-lg);
  text-align:center;
  animation:cardIn .34s cubic-bezier(.2,.9,.3,1.1) both;
}
@keyframes cardIn{
  from{opacity:0;transform:translateY(14px) scale(.985);}
  to{opacity:1;transform:none;}
}
@media (prefers-reduced-motion:reduce){
  .card{animation:none;}
}

.mascot{width:92px;margin:0 auto 2px;}
.mascot-svg{width:100%;height:auto;display:block;}

h1{
  margin:2px 0 4px;
  font-size:26px;
  font-weight:800;
  line-height:1.25;
  color:var(--ink);
}
h2{
  margin:0 0 6px;
  font-size:22px;
  font-weight:800;
  color:var(--ink);
}
.sub{
  margin:0 0 14px;
  font-size:14px;
  font-weight:500;
  line-height:1.5;
  color:var(--ink-soft);
}

.howto{
  display:flex;
  flex-direction:column;
  gap:9px;
  margin:0 0 18px;
  text-align:start;
}
.how{
  display:flex;
  align-items:center;
  gap:10px;
  padding:9px 11px;
  border-radius:14px;
  background:rgba(201,184,232,.16);
}
.howic{flex:0 0 auto;width:30px;height:30px;}
.howtx{display:flex;flex-direction:column;line-height:1.25;min-width:0;flex:1 1 auto;}
.howtx b{font-size:13.5px;font-weight:700;color:var(--ink);}
.howtx span{font-size:12px;font-weight:500;color:var(--ink-soft);}
.howarc{flex:0 0 auto;width:30px;height:30px;}

/* ================= BUTTONS ================= */
.btn{
  display:block;
  width:100%;
  min-height:52px;
  padding:12px 20px;
  border:0;
  border-radius:16px;
  background:#fff;
  color:var(--ink);
  font-size:17px;
  font-weight:700;
  cursor:pointer;
  box-shadow:var(--shadow);
  transition:transform .1s ease, background .18s ease, box-shadow .18s ease;
  user-select:none;
  -webkit-user-select:none;
}
.btn + .btn{margin-top:9px;}
.btn:active{transform:translateY(1px) scale(.988);}
.btn:focus-visible{outline:3px solid #7C6BA8;outline-offset:2px;}
.btn.primary{
  background:linear-gradient(180deg,#D3C4EF,#C9B8E8);
  color:#332C48;
  box-shadow:0 6px 16px rgba(74,63,92,.18);
}
.btn.primary:active{background:linear-gradient(180deg,#C6B5E6,#BCA8E0);}
.btn.ghost{background:rgba(201,184,232,.26);color:var(--ink);box-shadow:none;}
.btn.ghost:active{background:rgba(201,184,232,.44);}
.btn.small{font-size:14px;min-height:44px;}
.btn.tiny{
  width:auto;
  min-height:36px;
  padding:6px 14px;
  font-size:12.5px;
  font-weight:700;
  border-radius:999px;
  background:rgba(168,224,200,.6);
  color:#2E4A3D;
  box-shadow:none;
  margin:0;
}

.best-line{
  margin:12px 0 0;
  font-size:13px;
  font-weight:600;
  color:var(--ink-soft);
}
.best-line b{color:var(--ink);font-weight:800;font-size:15px;}

/* ================= LIVES NOTE ================= */
.lives-note{
  display:flex;
  align-items:center;
  justify-content:center;
  gap:6px;
  margin:-6px 0 14px;
  padding:8px 10px;
  border-radius:12px;
  background:rgba(240,122,122,.13);
  color:var(--ink-2);
  font-size:12px;
  font-weight:600;
  line-height:1.4;
  text-align:start;
}
.lives-note svg{flex:0 0 auto;}

/* ================= GAME OVER ================= */
.over-card{padding-top:18px;}
.over-k{
  margin:0 0 2px;
  font-size:13px;
  font-weight:700;
  color:var(--ink-soft);
  letter-spacing:.02em;
}
.score-big{
  font-size:58px;
  font-weight:800;
  line-height:1.05;
  color:var(--ink);
  font-variant-numeric:tabular-nums;
  margin:0 0 2px;
}
.score-meta{
  display:flex;
  align-items:center;
  justify-content:center;
  gap:8px;
  font-size:13px;
  font-weight:600;
  color:var(--ink-soft);
  margin-bottom:16px;
}
.score-meta b{color:var(--ink);font-weight:800;}
.dots{opacity:.45;}

/* ================= LEADERBOARD ================= */
.lb{
  margin-top:16px;
  padding-top:14px;
  border-top:1px dashed rgba(74,63,92,.16);
  text-align:start;
}
.lb-head{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:8px;
  font-size:13px;
  font-weight:800;
  color:var(--ink);
  margin-bottom:8px;
}
.lb-list{
  list-style:none;
  margin:0;
  padding:0;
  display:flex;
  flex-direction:column;
  gap:5px;
  max-height:172px;
  overflow-y:auto;
}
.lb-list li{
  display:flex;
  align-items:center;
  gap:8px;
  padding:6px 10px;
  border-radius:11px;
  background:rgba(201,184,232,.16);
  font-size:13px;
  font-weight:600;
  color:var(--ink);
}
.lb-list li.me{background:rgba(168,224,200,.4);}
.lb-rank{
  flex:0 0 auto;
  width:20px;
  font-weight:800;
  color:var(--ink-soft);
  font-variant-numeric:tabular-nums;
}
.lb-name{
  flex:1 1 auto;
  min-width:0;
  overflow:hidden;
  text-overflow:ellipsis;
  white-space:nowrap;
}
.lb-score{
  flex:0 0 auto;
  font-weight:800;
  font-variant-numeric:tabular-nums;
}
.lb-empty{
  font-size:12.5px;
  font-weight:500;
  color:var(--ink-soft);
  padding:6px 2px;
}
.lb-note{
  margin:8px 0 0;
  font-size:11px;
  font-weight:500;
  color:rgba(74,63,92,.5);
}

/* ================= NOISE ================= */
.noise{
  position:fixed;
  inset:0;
  z-index:60;
  pointer-events:none;
  opacity:.05;
  background-image:url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='140' height='140'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='3' stitchTiles='stitch'/></filter><rect width='140' height='140' filter='url(%23n)'/></svg>");
  background-size:140px 140px;
  mix-blend-mode:multiply;
}

/* ================= SMALL SCREENS ================= */
@media (max-width:430px){
  .card{padding:16px 14px 14px;border-radius:20px;}
  h1{font-size:22px;}
  .mascot{width:74px;}
  .score-big{font-size:50px;}
  .how{padding:8px 9px;}
  .howtx b{font-size:12.5px;}
  .howtx span{font-size:11px;}
  .howic,.howarc{width:26px;height:26px;}
  .jumpbtn{width:76px;height:76px;font-size:12px;}
  .ctrl-hint{font-size:12px;}
  .chip-v{font-size:16px;}
}

@media (max-height:430px){
  .mascot{display:none;}
  h1{font-size:20px;}
  .sub{margin-bottom:10px;}
  .howto{gap:6px;margin-bottom:12px;}
  .how{padding:6px 9px;}
  .score-big{font-size:44px;}
  .overlay.over{padding-top:104px;}
}

[hidden]{display:none !important;}