:root{
  --ink:#141414;
  --paper:#FFFCF5;
  --cream:#F8E9C8;
  --tomato:#E8442E;
  --mango:#FFB020;
  --leaf:#35A853;
  --berry:#E8478B;
  --mint:#6ED3C0;
  --copper:#C98B5A;
}

*{ box-sizing:border-box; -webkit-tap-highlight-color:transparent; }

html,body{
  margin:0;
  padding:0;
  height:100%;
  overscroll-behavior:none;
}

body{
  background:var(--cream);
  color:var(--ink);
  font-family:'Tajawal', system-ui, -apple-system, 'Segoe UI', sans-serif;
  font-weight:700;
  -webkit-font-smoothing:antialiased;
  user-select:none;
  -webkit-user-select:none;
  touch-action:manipulation;
}

.game{
  position:relative;
  display:flex;
  flex-direction:column;
  height:100vh;
  height:100dvh;
  width:100%;
  overflow:hidden;
  background:var(--cream);
}

/* ================= HUD ================= */
.hud{
  flex:0 0 auto;
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:4px;
  padding:7px 10px;
  background:var(--cream);
  border-bottom:2px solid var(--ink);
  position:relative;
  z-index:5;
}

.hud-cell{
  display:flex;
  flex-direction:column;
  align-items:center;
  gap:1px;
  min-width:0;
  flex:1 1 0;
}

.hud-k{
  font-size:10px;
  font-weight:700;
  color:#4a4034;
  line-height:1.1;
  white-space:nowrap;
}

.hud-v{
  font-size:18px;
  font-weight:900;
  line-height:1.1;
  font-variant-numeric:tabular-nums;
  color:var(--ink);
  white-space:nowrap;
}

.hud-sep{
  width:2px;
  height:22px;
  background:rgba(20,20,20,.16);
  border-radius:2px;
  flex:0 0 auto;
}

/* ================= STAGE ================= */
.stage{
  position:relative;
  flex:1 1 auto;
  min-height:0;
  overflow:hidden;
  background:var(--cream);
}

.stage canvas{
  display:block;
  width:100%;
  height:100%;
  touch-action:none;
}

/* ================= CONTROLS ================= */
.controls{
  flex:0 0 auto;
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:8px;
  padding:8px 10px 10px;
  background:var(--cream);
  border-top:2px solid var(--ink);
  position:relative;
  z-index:5;
}

.ctrl-group{
  display:flex;
  gap:6px;
  align-items:center;
}

.controls button{ direction:rtl; }

.btn-ctrl{
  display:flex;
  flex-direction:column;
  align-items:center;
  justify-content:center;
  gap:2px;
  min-height:52px;
  height:52px;
  width:56px;
  padding:0 4px;
  background:var(--paper);
  color:var(--ink);
  border:2px solid var(--ink);
  border-radius:14px;
  box-shadow:0 3px 0 var(--ink);
  font-family:inherit;
  font-weight:800;
  font-size:10px;
  line-height:1;
  cursor:pointer;
  transition:transform .08s ease, box-shadow .08s ease, background .12s ease;
}
.btn-ctrl:active{
  transform:translateY(3px);
  box-shadow:0 0 0 var(--ink);
  background:#F2EADB;
}
.btn-ctrl:focus-visible{ outline:3px solid var(--mango); outline-offset:2px; }

.btn-action{
  flex:1 1 auto;
  max-width:none;
  min-height:58px;
  height:58px;
  padding:0 20px;
  background:var(--tomato);
  color:var(--paper);
  border:2px solid var(--ink);
  border-radius:16px;
  box-shadow:0 4px 0 var(--ink);
  font-family:inherit;
  font-weight:900;
  font-size:21px;
  line-height:1;
  letter-spacing:0;
  cursor:pointer;
  transition:transform .08s ease, box-shadow .08s ease, background .12s ease;
}
.btn-action:active{
  transform:translateY(4px);
  box-shadow:0 0 0 var(--ink);
  background:#C9351F;
}
.btn-action:focus-visible{ outline:3px solid var(--mango); outline-offset:2px; }

#btnAction{ flex:1 1 auto; max-width:none; }

.hidden{ display:none !important; }

/* ================= OVERLAYS ================= */
[data-meeem-game-menu]{
  display:none !important;
  position:absolute;
  inset:0;
  z-index:60;
  padding:14px;
  background:rgba(20,20,20,.55);
  -webkit-backdrop-filter:blur(6px);
  backdrop-filter:blur(6px);
  overflow-y:auto;
  -webkit-overflow-scrolling:touch;
  touch-action:pan-y;
}
[data-meeem-game-menu].show{ display:flex !important; }

.sheet{
  margin:auto;
  width:100%;
  max-width:400px;
  background:var(--paper);
  color:var(--ink);
  border:3px solid var(--ink);
  border-radius:22px;
  box-shadow:0 6px 0 var(--ink);
  padding:18px 16px;
  text-align:center;
}
.sheet-small{ max-width:340px; }
.sheet-wide{ max-width:430px; }

.sheet-head{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:8px;
  margin-bottom:6px;
}
.sheet-head .sheet-title{ margin:0; }

.sheet-title{
  margin:0 0 12px;
  font-size:23px;
  font-weight:900;
  line-height:1.2;
}

.sheet-sub{
  margin:-4px 0 14px;
  font-size:13px;
  font-weight:700;
  color:#6b6055;
  line-height:1.5;
}

/* logo */
.logo{ margin-bottom:12px; }
.logo-mark{
  width:74px;
  height:78px;
  display:block;
  margin:0 auto 2px;
}
.logo-word{
  margin:0;
  font-size:38px;
  font-weight:900;
  line-height:1.05;
}
.tagline{
  margin:4px 0 0;
  font-size:12px;
  font-weight:700;
  color:#6b6055;
}

.start-stats{
  display:flex;
  gap:8px;
  justify-content:center;
  flex-wrap:wrap;
  margin-bottom:14px;
}
.chip{
  display:inline-flex;
  align-items:center;
  gap:7px;
  background:var(--cream);
  border:2px solid var(--ink);
  border-radius:999px;
  padding:5px 13px;
  font-size:12px;
  font-weight:800;
  white-space:nowrap;
}
.chip b{
  font-size:15px;
  font-weight:900;
  font-variant-numeric:tabular-nums;
}

/* buttons */
.btn-primary{
  display:block;
  width:100%;
  min-height:56px;
  padding:0 18px;
  background:var(--tomato);
  color:var(--paper);
  border:2px solid var(--ink);
  border-radius:16px;
  box-shadow:0 4px 0 var(--ink);
  font-family:inherit;
  font-weight:900;
  font-size:19px;
  line-height:1.15;
  cursor:pointer;
  transition:transform .08s ease, box-shadow .08s ease, background .12s ease;
}
.btn-primary:active{
  transform:translateY(4px);
  box-shadow:0 0 0 var(--ink);
  background:#C9351F;
}
.btn-primary:focus-visible{ outline:3px solid var(--mango); outline-offset:2px; }

.btn-row{
  display:flex;
  gap:8px;
  margin-top:10px;
  flex-wrap:wrap;
}

.btn-ghost{
  flex:1 1 0;
  min-width:110px;
  min-height:48px;
  padding:0 10px;
  background:var(--paper);
  color:var(--ink);
  border:2px solid var(--ink);
  border-radius:14px;
  box-shadow:0 3px 0 var(--ink);
  font-family:inherit;
  font-weight:800;
  font-size:14px;
  line-height:1.15;
  cursor:pointer;
  transition:transform .08s ease, box-shadow .08s ease, background .12s ease;
}
.btn-ghost:active{
  transform:translateY(3px);
  box-shadow:0 0 0 var(--ink);
  background:#F2EADB;
}
.btn-ghost:focus-visible{ outline:3px solid var(--mango); outline-offset:2px; }
.btn-wide{ width:100%; margin-top:10px; flex:1 1 100%; }

.btn-link{
  margin-top:12px;
  background:none;
  border:none;
  color:#6b6055;
  font-family:inherit;
  font-size:13px;
  font-weight:800;
  text-decoration:underline;
  text-underline-offset:3px;
  min-height:44px;
  padding:0 12px;
  cursor:pointer;
}
.btn-link:focus-visible{ outline:3px solid var(--mango); outline-offset:2px; border-radius:8px; }

/* level map */
.level-list{ text-align:right; }
.chapter-head{
  display:flex;
  align-items:center;
  gap:8px;
  margin:14px 0 8px;
  font-size:12px;
  font-weight:900;
  color:#6b6055;
}
.chapter-head::after{
  content:'';
  flex:1 1 auto;
  height:2px;
  background:rgba(20,20,20,.12);
  border-radius:2px;
}
.lv-grid{
  display:grid;
  grid-template-columns:repeat(2, minmax(0,1fr));
  gap:8px;
}
.lv{
  display:flex;
  flex-direction:column;
  align-items:center;
  gap:3px;
  padding:9px 6px 8px;
  background:var(--paper);
  color:var(--ink);
  border:2px solid var(--ink);
  border-radius:16px;
  box-shadow:0 3px 0 var(--ink);
  font-family:inherit;
  cursor:pointer;
  transition:transform .08s ease, box-shadow .08s ease;
}
.lv:active{ transform:translateY(3px); box-shadow:0 0 0 var(--ink); }
.lv:focus-visible{ outline:3px solid var(--mango); outline-offset:2px; }
.lv-n{
  width:28px;height:28px;
  border-radius:999px;
  background:var(--mango);
  border:2px solid var(--ink);
  font-weight:900;
  font-size:13px;
  line-height:24px;
  text-align:center;
  font-variant-numeric:tabular-nums;
}
.lv-name{ font-size:12px; font-weight:800; line-height:1.25; }
.lv-stars{
  font-size:13px;
  letter-spacing:2px;
  color:var(--mango);
  -webkit-text-stroke:1px var(--ink);
  line-height:1.1;
}
.lv-locked{
  background:#EDE6D6;
  color:#8b8073;
  box-shadow:none;
  opacity:.8;
  cursor:not-allowed;
}
.lv-locked .lv-n{ background:#D8CFBE; }
.lv-locked .lv-stars{ -webkit-text-stroke:0; color:#8b8073; }

/* how to play */
.how-list{
  list-style:none;
  margin:0 0 16px;
  padding:0;
  text-align:right;
  counter-reset:how;
}
.how-list li{
  position:relative;
  padding:9px 40px 9px 0;
  border-bottom:1.5px solid rgba(20,20,20,.12);
  counter-increment:how;
}
.how-list li:last-child{ border-bottom:none; }
.how-list li::before{
  content:counter(how);
  position:absolute;
  right:0;
  top:9px;
  width:26px;
  height:26px;
  border-radius:999px;
  background:var(--mango);
  border:2px solid var(--ink);
  font-size:13px;
  font-weight:900;
  line-height:22px;
  text-align:center;
}
.how-list b{ display:block; font-size:14px; font-weight:900; margin-bottom:2px; }
.how-list span{ display:block; font-size:12px; font-weight:500; line-height:1.55; color:#5c5348; }

/* settings */
.field{ text-align:right; margin-bottom:16px; }
.field-row{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:8px;
  margin-bottom:8px;
  font-size:14px;
  font-weight:800;
}
.field-val{ font-size:14px; font-weight:900; color:var(--tomato); font-variant-numeric:tabular-nums; }
.field-hint{ margin:8px 0 0; font-size:11px; font-weight:600; color:#7a6f62; line-height:1.5; }

input[type="range"]{
  -webkit-appearance:none;
  appearance:none;
  width:100%;
  height:14px;
  border-radius:999px;
  border:2px solid var(--ink);
  background:var(--cream);
  outline:none;
  margin:0;
}
input[type="range"]::-webkit-slider-thumb{
  -webkit-appearance:none;
  appearance:none;
  width:26px;height:26px;
  border-radius:999px;
  background:var(--tomato);
  border:2px solid var(--ink);
  box-shadow:0 2px 0 var(--ink);
  cursor:pointer;
  margin-top:-8px;
}
input[type="range"]::-moz-range-thumb{
  width:24px;height:24px;
  border-radius:999px;
  background:var(--tomato);
  border:2px solid var(--ink);
  cursor:pointer;
}

.seg{ display:flex; gap:6px; }
.seg button{
  flex:1 1 0;
  min-height:44px;
  padding:0 6px;
  background:var(--paper);
  color:var(--ink);
  border:2px solid var(--ink);
  border-radius:12px;
  font-family:inherit;
  font-weight:800;
  font-size:13px;
  cursor:pointer;
  transition:background .12s ease, color .12s ease;
}
.seg button[aria-pressed="true"]{ background:var(--ink); color:var(--paper); }
.seg button:focus-visible{ outline:3px solid var(--mango); outline-offset:2px; }

.toggle{
  min-height:44px;
  min-width:104px;
  padding:0 18px;
  background:var(--leaf);
  color:var(--paper);
  border:2px solid var(--ink);
  border-radius:12px;
  box-shadow:0 3px 0 var(--ink);
  font-family:inherit;
  font-weight:900;
  font-size:14px;
  cursor:pointer;
}
.toggle[aria-pressed="false"]{ background:var(--paper); color:var(--ink); }
.toggle:active{ transform:translateY(3px); box-shadow:0 0 0 var(--ink); }

/* results */
.over-kicker{ margin:0 0 6px; font-size:13px; font-weight:800; color:var(--tomato); }
.stars{ display:flex; justify-content:center; gap:8px; margin:0 0 8px; }
.star{
  font-size:36px;
  line-height:1;
  color:#DED4BF;
  transition:color .18s ease, transform .18s ease;
}
.star.on{
  color:var(--mango);
  transform:scale(1.08);
  -webkit-text-stroke:2px var(--ink);
}
.over-score{
  display:flex;
  align-items:baseline;
  justify-content:center;
  gap:6px;
  font-size:40px;
  font-weight:900;
  line-height:1;
  font-variant-numeric:tabular-nums;
  margin-bottom:4px;
}
.over-score small{ font-size:14px; font-weight:800; color:#6b6055; }
.over-best{ font-size:12px; font-weight:700; color:#6b6055; margin-bottom:12px; line-height:1.5; }
.stats{ display:flex; gap:7px; margin-bottom:14px; }
.stat{
  flex:1 1 0;
  background:var(--cream);
  border:2px solid var(--ink);
  border-radius:14px;
  padding:8px 3px;
}
.stat b{
  display:block;
  font-size:18px;
  font-weight:900;
  line-height:1.1;
  font-variant-numeric:tabular-nums;
}
.stat span{ display:block; font-size:10px; font-weight:700; color:#5c5348; margin-top:2px; }

/* leaderboard */
.lb-list{
  list-style:none;
  margin:0 0 14px;
  padding:0;
  max-height:40vh;
  overflow-y:auto;
}
.lb-list li{
  display:flex;
  align-items:center;
  gap:10px;
  padding:8px 4px;
  border-bottom:1.5px solid rgba(20,20,20,.1);
  font-size:14px;
  font-weight:700;
}
.lb-list li:last-child{ border-bottom:none; }
.lb-rank{
  width:24px;height:24px;
  flex:0 0 auto;
  border-radius:999px;
  background:var(--cream);
  border:2px solid var(--ink);
  font-size:12px;
  font-weight:900;
  line-height:20px;
  text-align:center;
}
.lb-name{ flex:1 1 auto; text-align:right; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.lb-score{ font-weight:900; font-variant-numeric:tabular-nums; }
.lb-list li.you{ background:rgba(255,176,32,.22); border-radius:10px; }
.lb-empty{ font-size:12px; font-weight:700; color:#6b6055; padding:14px 4px; }

@media (max-width:370px){
  .hud-v{ font-size:16px; }
  .hud-k{ font-size:9px; }
  .btn-ctrl{ width:50px; font-size:9px; }
  .btn-action{ font-size:19px; }
  .logo-word{ font-size:33px; }
  .logo-mark{ width:64px; height:68px; }
  .sheet{ padding:16px 13px; }
}

@media (max-height:560px){
  .logo-mark{ display:none; }
  .logo{ margin-bottom:8px; }
  .tagline{ display:none; }
  .start-stats{ margin-bottom:10px; }
}

@media (prefers-reduced-motion: reduce){
  *{ transition-duration:.01ms !important; animation-duration:.01ms !important; }
}