:root {
  --page-top: #c98a4b; --page-bot: #7a4521; --accent: #ffd27a;
  --wood1: #f7cd83; --wood2: #d9944a; --wood3: #8a4f22;
  --ink: #3b1f0c;
  --font: "Segoe UI", Roboto, system-ui, -apple-system, sans-serif;
}
* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { width: 100%; height: 100%; overflow: hidden; }
body {
  font-family: "Segoe UI", Roboto, system-ui, -apple-system, sans-serif;
  background: var(--page-bot);
  color: #fff; user-select: none; -webkit-user-select: none; touch-action: none;
  overscroll-behavior: none;
}
#app { position: fixed; inset: 0; }
.screen { position: absolute; inset: 0; display: none; flex-direction: column;
  padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom);
  background:
    radial-gradient(120% 60% at 50% -5%, rgba(255,240,200,.28), transparent 65%),
    repeating-linear-gradient(92deg, transparent 0 18px, rgba(255,255,255,.035) 19px 20px, transparent 21px 37px),
    linear-gradient(170deg, var(--page-top), var(--page-bot));
  transition: background 0.6s;
}
.screen.active { display: flex; }
.hidden { display: none !important; }

/* ---------- buttons ---------- */
.btn {
  border: 0; cursor: pointer; font: 900 18px/1.1 var(--font); color: #fff; letter-spacing: 1px;
  border-radius: 18px; padding: 14px 20px; position: relative;
  text-shadow: 0 2px 0 rgba(0,0,0,.28);
  background: linear-gradient(180deg, #ffd36b, #f09a1c);
  box-shadow: inset 0 3px 0 rgba(255,255,255,.55), inset 0 -4px 0 rgba(0,0,0,.18), 0 5px 0 #a35a12, 0 9px 14px rgba(0,0,0,.3);
  transition: transform .08s, box-shadow .08s;
}
.btn:active { transform: translateY(4px); box-shadow: inset 0 3px 0 rgba(255,255,255,.55), inset 0 -4px 0 rgba(0,0,0,.18), 0 1px 0 #a35a12, 0 3px 6px rgba(0,0,0,.3); }
.btn.green { background: linear-gradient(180deg, #8ee86a, #2fae3c); box-shadow: inset 0 3px 0 rgba(255,255,255,.5), inset 0 -4px 0 rgba(0,0,0,.18), 0 5px 0 #1d6e26, 0 9px 14px rgba(0,0,0,.3); }
.btn.blue { background: linear-gradient(180deg, #7fd0ff, #2a86e0); box-shadow: inset 0 3px 0 rgba(255,255,255,.5), inset 0 -4px 0 rgba(0,0,0,.18), 0 5px 0 #18508c, 0 9px 14px rgba(0,0,0,.3); }
.btn.red { background: linear-gradient(180deg, #ff8a7a, #e0402e); box-shadow: inset 0 3px 0 rgba(255,255,255,.5), inset 0 -4px 0 rgba(0,0,0,.18), 0 5px 0 #8c2218, 0 9px 14px rgba(0,0,0,.3); }
.btn.purple { background: linear-gradient(180deg, #c99bff, #7d43e0); box-shadow: inset 0 3px 0 rgba(255,255,255,.5), inset 0 -4px 0 rgba(0,0,0,.18), 0 5px 0 #4a2391, 0 9px 14px rgba(0,0,0,.3); }
.btn.wood { background: linear-gradient(180deg, #a86a3a, #6e3d1b); box-shadow: inset 0 2px 0 rgba(255,220,170,.4), 0 4px 0 #3e200b, 0 7px 12px rgba(0,0,0,.3); }
.btn.big { width: 100%; font-size: 24px; padding: 16px 20px 14px; display: flex; flex-direction: column; align-items: center; }
.btn.big .ico { position: absolute; left: 22px; top: 50%; transform: translateY(-50%); font-size: 22px; }
.btn small { display: block; font-size: 12px; font-weight: 800; opacity: .92; letter-spacing: .5px; margin-top: 2px; }
.btn.round { width: 54px; height: 54px; padding: 0; border-radius: 50%; font-size: 24px; display: grid; place-items: center; }
.btn.round.small { width: 44px; height: 44px; font-size: 16px; border-radius: 14px; }

/* ---------- home ---------- */
#homeBg { position: absolute; inset: 0; width: 100%; height: 100%; }
.home-inner { position: relative; z-index: 1; flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 18px; padding: 24px 32px; max-width: 460px; width: 100%; margin: 0 auto; }
.logo { display: flex; flex-direction: column; align-items: center; gap: 6px; margin-bottom: 8px; animation: logoIn .7s cubic-bezier(.2,1.6,.4,1) both; }
.logo-row { display: flex; gap: 5px; }
.logo-row span {
  width: 52px; height: 56px; display: grid; place-items: center; font: 900 36px/1 var(--font); color: #fff;
  border-radius: 10px; text-shadow: 0 3px 0 rgba(0,0,0,.3);
  box-shadow: inset 0 4px 0 rgba(255,255,255,.5), inset 0 -5px 0 rgba(0,0,0,.22), 0 5px 10px rgba(0,0,0,.35);
  animation: bob 2.4s ease-in-out infinite;
}
.logo-row.crush span { width: 46px; height: 50px; font-size: 32px; background: linear-gradient(180deg,#fff0c0,#e9a845); color: #7a3c10; text-shadow: 0 2px 0 rgba(255,255,255,.6); }
@keyframes bob { 0%,100% { transform: translateY(0) } 50% { transform: translateY(-5px) } }
@keyframes logoIn { from { transform: scale(.3); opacity: 0 } to { transform: scale(1); opacity: 1 } }
.home-best { font: 900 26px/1 var(--font); display: flex; align-items: center; gap: 8px; background: rgba(60,25,5,.45); padding: 8px 22px; border-radius: 30px; box-shadow: inset 0 2px 6px rgba(0,0,0,.35); }
.crown { filter: drop-shadow(0 2px 2px rgba(0,0,0,.4)); }
.home-buttons { width: 100%; display: flex; flex-direction: column; gap: 20px; margin-top: 10px; }
.home-small { display: flex; gap: 16px; margin-top: 6px; }
.home-tip { font-weight: 700; font-size: 14px; opacity: .85; text-align: center; text-shadow: 0 1px 2px rgba(0,0,0,.4); }

/* ---------- map ---------- */
.map-head { display: flex; align-items: center; padding: 10px 14px; gap: 10px; z-index: 2; }
.map-title { flex: 1; text-align: center; font: 900 22px/1.1 var(--font); letter-spacing: 2px; text-shadow: 0 2px 0 rgba(0,0,0,.3); }
.map-title small { display: block; font-size: 14px; color: #ffe27a; letter-spacing: 1px; }
.spacer { width: 44px; }
#mapScroll { flex: 1; overflow-y: auto; touch-action: pan-y; -webkit-overflow-scrolling: touch; }
#mapPath { padding: 10px 0 60px; }
.chapter { margin: 0 12px 18px; border-radius: 22px; padding: 14px 10px 18px; position: relative; box-shadow: inset 0 2px 0 rgba(255,255,255,.25), 0 6px 14px rgba(0,0,0,.3); }
.chapter h3 { text-align: center; font: 900 18px/1.2 var(--font); letter-spacing: 1.5px; text-shadow: 0 2px 0 rgba(0,0,0,.35); }
.chapter h3 small { display: block; font-size: 12px; opacity: .85; letter-spacing: .5px; }
.chapter.locked { filter: grayscale(.7) brightness(.8); }
.nodes { display: grid; grid-template-columns: repeat(5, 1fr); gap: 14px 6px; margin-top: 12px; justify-items: center; }
.node { width: 56px; height: 56px; border-radius: 16px; border: 0; font: 900 20px/1 var(--font); color: #fff; position: relative;
  background: linear-gradient(180deg,#ffd36b,#f09a1c); box-shadow: inset 0 3px 0 rgba(255,255,255,.5), 0 4px 0 #a35a12, 0 6px 10px rgba(0,0,0,.3); text-shadow: 0 2px 0 rgba(0,0,0,.3); }
.node.done { background: linear-gradient(180deg,#8ee86a,#2fae3c); box-shadow: inset 0 3px 0 rgba(255,255,255,.5), 0 4px 0 #1d6e26, 0 6px 10px rgba(0,0,0,.3); }
.node.locked { background: linear-gradient(180deg,#9a8f86,#6c625a); box-shadow: inset 0 2px 0 rgba(255,255,255,.25), 0 4px 0 #3f3934; color: rgba(255,255,255,.6); }
.node.current { animation: pulse 1.1s ease-in-out infinite; z-index: 1; }
.node.boss::before { content: "👑"; position: absolute; top: -14px; left: 50%; transform: translateX(-50%); font-size: 16px; }
.node .stars { position: absolute; bottom: -12px; left: 0; right: 0; font-size: 12px; color: #ffe14d; text-shadow: 0 1px 2px rgba(0,0,0,.7); letter-spacing: -1px; }
@keyframes pulse { 0%,100% { transform: scale(1) } 50% { transform: scale(1.12) } }

/* ---------- game ---------- */
#game { touch-action: none; }
#board, #fx { position: absolute; left: 0; top: 0; width: 100%; height: 100%; }
#fx { pointer-events: none; z-index: 3; }
#hud { position: relative; z-index: 2; padding: 8px 12px 0; pointer-events: none; max-width: 520px; width: 100%; margin: 0 auto; }
#hud button { pointer-events: auto; }
.hud-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.hud-center { flex: 1; text-align: center; }
.hud-label { font: 800 11px/1 var(--font); letter-spacing: 2px; opacity: .85; text-shadow: 0 1px 2px rgba(0,0,0,.4); }
.hud-score { font: 900 38px/1.05 var(--font); text-shadow: 0 3px 0 rgba(0,0,0,.25), 0 0 12px rgba(255,220,140,.35); font-variant-numeric: tabular-nums; transition: transform .12s; }
.hud-score.bump { transform: scale(1.18); }
.hud-best { min-width: 44px; display: flex; align-items: center; gap: 4px; font: 900 17px/1 var(--font); background: rgba(40,15,0,.35); padding: 6px 10px; border-radius: 14px; }
.hud-row2 { display: flex; align-items: center; gap: 8px; margin-top: 6px; }
.stage-tag, .mult { font: 900 12px/1 var(--font); letter-spacing: 1px; background: rgba(40,15,0,.4); padding: 6px 9px; border-radius: 10px; white-space: nowrap; }
.mult { color: #ffe27a; }
.stage-bar { flex: 1; height: 16px; border-radius: 10px; background: rgba(30,10,0,.5); position: relative; overflow: hidden; box-shadow: inset 0 2px 3px rgba(0,0,0,.45); }
.stage-bar i { position: absolute; left: 0; top: 0; bottom: 0; width: 0; border-radius: 10px; background: linear-gradient(180deg,#fff2a8,#ffb72a 60%,#f08a10); box-shadow: inset 0 2px 0 rgba(255,255,255,.6); transition: width .35s cubic-bezier(.3,1.4,.5,1); }
.stage-bar span { position: absolute; inset: 0; text-align: center; font: 900 11px/16px var(--font); text-shadow: 0 1px 2px rgba(0,0,0,.7); }
.goals { justify-content: center; flex-wrap: wrap; gap: 8px; }
.goal { display: flex; align-items: center; gap: 6px; background: rgba(30,10,0,.45); padding: 4px 12px 4px 6px; border-radius: 16px; font: 900 16px/1 var(--font); box-shadow: inset 0 2px 3px rgba(0,0,0,.35); transition: transform .15s; }
.goal img { width: 26px; height: 26px; }
.goal .gico { width: 26px; height: 26px; display: grid; place-items: center; font-size: 18px; }
.goal.done { background: rgba(30,140,50,.6); }
.goal.bump { transform: scale(1.2); }

/* ---------- modal ---------- */
.modal { position: fixed; inset: 0; z-index: 10; display: flex; align-items: center; justify-content: center; background: rgba(20,8,0,.55); padding: 20px; animation: fadeIn .2s; }
.modal-card { width: 100%; max-width: 360px; border-radius: 26px; padding: 22px 20px 22px; text-align: center; position: relative;
  background: linear-gradient(180deg,#fbe2b0,#e8b36a); color: var(--ink);
  box-shadow: inset 0 3px 0 rgba(255,255,255,.7), 0 0 0 6px #a8622a, 0 0 0 9px #6e3a14, 0 18px 40px rgba(0,0,0,.5);
  animation: popIn .35s cubic-bezier(.2,1.6,.4,1); }
.modal-card h2 { font: 900 30px/1.1 var(--font); letter-spacing: 1px; color: #fff; text-shadow: 0 3px 0 #a3531a, 0 0 2px #a3531a; margin: -54px auto 10px; background: linear-gradient(180deg,#ff9f45,#e0601e); border-radius: 18px; padding: 10px 18px; display: inline-block; box-shadow: inset 0 3px 0 rgba(255,255,255,.45), 0 5px 0 #8c3a0e; }
.modal-card p { font-weight: 700; margin: 6px 0; }
.modal-card .big-num { font: 900 46px/1.1 var(--font); color: #6b3410; }
.modal-card .sub { font-size: 14px; opacity: .8; font-weight: 800; letter-spacing: 1px; }
.modal-btns { display: flex; flex-direction: column; gap: 14px; margin-top: 18px; }
.modal-btns .row { display: flex; gap: 12px; }
.modal-btns .row .btn { flex: 1; }
.stars-big { font-size: 54px; letter-spacing: 6px; margin: 4px 0 2px; }
.stars-big span { display: inline-block; color: rgba(90,40,10,.25); transform: scale(.6); transition: transform .3s cubic-bezier(.2,1.8,.4,1), color .2s; }
.stars-big span.on { color: #ffcc1a; transform: scale(1); text-shadow: 0 3px 0 #b86f00, 0 0 14px rgba(255,220,80,.8); }
.goal-list { display: flex; justify-content: center; gap: 10px; flex-wrap: wrap; margin: 12px 0 4px; }
.goal-list .goal { color: #fff; }
.toggle { display: flex; align-items: center; justify-content: space-between; padding: 12px 6px; border-bottom: 2px dashed rgba(110,58,20,.25); font: 900 18px/1 var(--font); }
.toggle:last-of-type { border-bottom: 0; }
.switch { width: 64px; height: 34px; border-radius: 20px; background: #b9a58c; position: relative; border: 0; box-shadow: inset 0 2px 4px rgba(0,0,0,.35); transition: background .2s; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 28px; height: 28px; border-radius: 50%; background: #fff; box-shadow: 0 2px 3px rgba(0,0,0,.35); transition: left .2s; }
.switch.on { background: #3fbf4a; }
.switch.on::after { left: 33px; }
@keyframes fadeIn { from { opacity: 0 } }
@keyframes popIn { from { transform: scale(.5); opacity: 0 } }

.toast { position: fixed; left: 50%; bottom: 12%; transform: translate(-50%, 30px); opacity: 0; z-index: 20; background: rgba(40,15,0,.85); color: #fff; font-weight: 800; padding: 10px 18px; border-radius: 20px; transition: all .3s; pointer-events: none; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
