:root {
  --ink: #26304a;
  --blue: #3d86f0;
  --green: #3fc46a;
  --red: #ef4b4b;
  --yellow: #ffd23a;
  --card: #fffaf0;
  --font: ui-rounded, "SF Pro Rounded", "Nunito", "Varela Round", "Trebuchet MS", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; height: 100%; overflow: hidden; background: #93d36c;
  font-family: var(--font); color: var(--ink);
  user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
  overscroll-behavior: none; touch-action: none;
}
canvas#game { position: fixed; inset: 0; display: block; touch-action: none; }
#safe-probe {
  position: fixed; visibility: hidden; pointer-events: none;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
.hidden { display: none !important; }
button { font-family: inherit; color: inherit; border: 0; cursor: pointer; }

/* ---------- HUD ---------- */
#hud {
  position: fixed; left: 0; right: 0; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: calc(env(safe-area-inset-top) + 6px) calc(env(safe-area-inset-right) + 10px) 6px calc(env(safe-area-inset-left) + 10px);
  pointer-events: none;
}
#hud > * { pointer-events: auto; }
.round-btn {
  width: 44px; height: 44px; border-radius: 50%; background: #fff; display: grid; place-items: center;
  box-shadow: 0 4px 0 #c9d2e0, 0 6px 12px rgba(30, 40, 70, .18);
}
.round-btn:active { transform: translateY(3px); box-shadow: 0 1px 0 #c9d2e0; }
.round-btn svg { width: 22px; height: 22px; fill: var(--ink); }
#hud-title {
  background: rgba(255, 255, 255, .92); border-radius: 22px; padding: 7px 16px; font-weight: 900; font-size: 18px;
  box-shadow: 0 4px 0 #c9d2e0; display: flex; align-items: center; gap: 8px; white-space: nowrap;
}
#hud-tag { font-size: 11px; padding: 3px 8px; border-radius: 10px; color: #fff; background: var(--red); }
#hud-tag:empty { display: none; }
#hud-tag.easy { background: var(--green); }
#hud-tag.twist { background: #9b5cf0; }
.coins {
  display: flex; align-items: center; gap: 6px; background: rgba(255, 255, 255, .92); border-radius: 22px;
  padding: 6px 14px 6px 8px; font-weight: 900; font-size: 18px; box-shadow: 0 4px 0 #c9d2e0; min-width: 72px;
}
.coin {
  width: 24px; height: 24px; border-radius: 50%; display: inline-block;
  background: radial-gradient(circle at 35% 30%, #fff6b0 0 18%, #ffd23a 19% 60%, #e2a90c 61%);
  box-shadow: inset 0 -2px 0 #c48a00;
}
.coins.bump { animation: bump .35s; }
@keyframes bump { 40% { transform: scale(1.18); } }

#streak {
  position: fixed; z-index: 5; left: 50%; transform: translateX(-50%);
  top: calc(env(safe-area-inset-top) + 58px);
  display: flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 14px;
  background: linear-gradient(90deg, #ff9a2e, #ff6fb5); color: #fff; font-weight: 900; font-size: 12px;
  box-shadow: 0 3px 0 rgba(150, 60, 40, .35); pointer-events: none;
}
#streak .x { font-size: 16px; }
#streak .bar { width: 60px; height: 6px; border-radius: 3px; background: rgba(255, 255, 255, .35); overflow: hidden; }
#streak .bar i { display: block; height: 100%; background: #fff; width: 100%; }
#streak.pop { animation: bump .3s; }

#tip {
  position: fixed; z-index: 6; left: 50%; transform: translateX(-50%);
  bottom: calc(env(safe-area-inset-bottom) + 98px); width: min(92vw, 440px);
  background: var(--card); border-radius: 18px; padding: 12px 14px; font-weight: 700; font-size: 15px; line-height: 1.3;
  box-shadow: 0 6px 0 #d8ccb5, 0 10px 24px rgba(30, 40, 70, .25); pointer-events: none;
  animation: rise .35s ease-out;
}
#tip b { display: block; font-size: 17px; color: var(--blue); margin-bottom: 2px; }
@keyframes rise { from { transform: translate(-50%, 20px); opacity: 0; } }

/* ---------- boosters ---------- */
#boosters {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
  display: flex; justify-content: center; gap: 8px;
  padding: 8px calc(env(safe-area-inset-right) + 8px) calc(env(safe-area-inset-bottom) + 8px) calc(env(safe-area-inset-left) + 8px);
  pointer-events: none;
}
.booster {
  pointer-events: auto; position: relative; flex: 0 1 96px; height: 74px; border-radius: 18px; background: #fff;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px;
  box-shadow: 0 5px 0 #c9d2e0, 0 8px 14px rgba(30, 40, 70, .18); font-weight: 900;
}
.booster:active { transform: translateY(4px); box-shadow: 0 1px 0 #c9d2e0; }
.booster svg { width: 34px; height: 34px; }
.booster .name { font-size: 11px; }
.booster .price {
  position: absolute; top: -8px; right: -4px; background: var(--yellow); color: #5a4200; font-size: 11px;
  padding: 2px 7px; border-radius: 10px; box-shadow: 0 2px 0 #c99a14; white-space: nowrap;
}
.booster .price.free { background: var(--green); color: #fff; box-shadow: 0 2px 0 #24894a; }
.booster.locked { filter: grayscale(1); opacity: .6; }
.booster.locked .price { background: #8a93a3; color: #fff; box-shadow: none; }
.booster.off { opacity: .55; }
.booster.active { background: #fff6c8; box-shadow: 0 5px 0 #e2b72a, 0 0 0 4px #ffd23a; animation: wiggle .6s infinite; }
@keyframes wiggle { 50% { transform: translateY(-3px); } }

/* ---------- overlays ---------- */
#overlay { position: fixed; inset: 0; z-index: 10; display: none; }
#overlay.show { display: block; }
.scrim {
  position: absolute; inset: 0; background: rgba(28, 36, 60, .45); display: grid; place-items: center;
  padding: calc(env(safe-area-inset-top) + 16px) 16px calc(env(safe-area-inset-bottom) + 16px);
  animation: fade .2s;
}
@keyframes fade { from { opacity: 0; } }
.card {
  width: min(100%, 400px); max-height: 100%; overflow: auto; background: var(--card); border-radius: 28px;
  padding: 22px 20px 20px; text-align: center;
  box-shadow: 0 8px 0 #d8ccb5, 0 18px 40px rgba(20, 30, 60, .35);
  animation: pop .32s cubic-bezier(.2, 1.4, .4, 1);
}
@keyframes pop { from { transform: scale(.7); opacity: 0; } }
.card h1 { margin: 0 0 6px; font-size: 30px; line-height: 1.1; }
.card h2 { margin: 0 0 6px; font-size: 24px; }
.card p { margin: 6px 0 14px; font-size: 16px; font-weight: 700; line-height: 1.35; color: #4a5470; }
.btn {
  display: block; width: 100%; padding: 15px 16px; margin: 10px 0 0; border-radius: 18px; font-size: 20px; font-weight: 900;
  background: var(--blue); color: #fff; box-shadow: 0 6px 0 #2459b8; text-shadow: 0 2px 0 rgba(0, 0, 0, .15);
}
.btn:active { transform: translateY(4px); box-shadow: 0 2px 0 #2459b8; }
.btn.green { background: var(--green); box-shadow: 0 6px 0 #24894a; }
.btn.green:active { box-shadow: 0 2px 0 #24894a; }
.btn.yellow { background: var(--yellow); color: #5a4200; text-shadow: none; box-shadow: 0 6px 0 #c99a14; }
.btn.white { background: #fff; color: var(--ink); text-shadow: none; box-shadow: 0 6px 0 #c9d2e0; }
.btn.red { background: var(--red); box-shadow: 0 6px 0 #b8303a; }
.btn.small { font-size: 16px; padding: 11px; }
.btn[disabled] { opacity: .5; }
.row { display: flex; gap: 10px; }
.row .btn { flex: 1; }

/* title */
.title-wrap { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; padding: calc(env(safe-area-inset-top) + 20px) 20px calc(env(safe-area-inset-bottom) + 20px); background: radial-gradient(ellipse at 50% 45%, rgba(24, 44, 96, .62), rgba(24, 44, 96, .38) 60%, rgba(24, 44, 96, .15)); }
.logo { text-align: center; filter: drop-shadow(0 6px 0 rgba(30, 40, 80, .35)); margin-bottom: 8px; }
.logo .l1, .logo .l2 { display: block; font-weight: 900; line-height: .95; letter-spacing: -1px; }
.logo .l1 { font-size: clamp(52px, 16vw, 84px); }
.logo .l2 { font-size: clamp(46px, 14vw, 74px); color: #fff; -webkit-text-stroke: 3px var(--ink); paint-order: stroke fill; }
.logo .l1 span { -webkit-text-stroke: 3px var(--ink); paint-order: stroke fill; display: inline-block; animation: bob 2.4s ease-in-out infinite; }
.logo .l1 span:nth-child(2n) { animation-delay: -.6s; }
.logo .l1 span:nth-child(3n) { animation-delay: -1.2s; }
@keyframes bob { 50% { transform: translateY(-6px) rotate(-3deg); } }
.tagline { color: #fff; font-weight: 800; font-size: 16px; text-shadow: 0 2px 0 rgba(30, 40, 80, .4); margin: 0 0 14px; text-align: center; background: rgba(22, 32, 66, .7); padding: 7px 16px; border-radius: 16px; }
.title-btns { width: min(100%, 320px); }
.title-btns .btn.big { font-size: 26px; padding: 18px; }

/* level map */
.map { position: absolute; inset: 0; display: flex; flex-direction: column; background: #93d36c; }
.map-head {
  display: flex; align-items: center; justify-content: space-between; gap: 10px; background: #3d86f0;
  padding: calc(env(safe-area-inset-top) + 8px) 12px 10px; color: #fff; box-shadow: 0 4px 0 #2459b8; z-index: 1;
}
.map-head h2 { margin: 0; font-size: 22px; }
.map-scroll { flex: 1; overflow-y: auto; overscroll-behavior: contain; touch-action: pan-y; padding: 20px 0 calc(env(safe-area-inset-bottom) + 30px);
  background-image: radial-gradient(circle at 20% 30%, rgba(255, 255, 255, .12) 0 2px, transparent 3px), radial-gradient(circle at 70% 60%, rgba(60, 140, 60, .2) 0 2px, transparent 3px);
  background-size: 34px 34px, 46px 46px; }
.map-list { position: relative; width: min(100%, 420px); margin: 0 auto; display: flex; flex-direction: column-reverse; }
.node-row { height: 86px; position: relative; }
.node-row::before { content: ""; position: absolute; left: 50%; top: -43px; height: 86px; width: 14px; margin-left: -7px; background: #5f6779; border-radius: 7px; z-index: 0; transform: translateX(var(--road, 0)) rotate(var(--rot, 0)); }
.node {
  position: absolute; top: 12px; left: 50%; width: 62px; height: 62px; margin-left: -31px; border-radius: 50%;
  display: grid; place-items: center; font-weight: 900; font-size: 22px; background: #fff; z-index: 1;
  box-shadow: 0 5px 0 #c9d2e0, 0 8px 14px rgba(30, 40, 70, .2); transform: translateX(var(--x, 0));
}
.node.done { background: var(--green); color: #fff; box-shadow: 0 5px 0 #24894a; }
.node.hard { outline: 4px solid var(--red); outline-offset: 2px; }
.node.current { background: var(--yellow); box-shadow: 0 5px 0 #c99a14, 0 0 0 6px rgba(255, 255, 255, .7); animation: pulse 1.2s infinite; }
.node.locked { background: #c4cad4; color: #7d8696; box-shadow: 0 5px 0 #9aa2b0; }
.node .badge { position: absolute; bottom: -8px; left: 50%; transform: translateX(-50%); font-size: 10px; background: #9b5cf0; color: #fff; padding: 2px 7px; border-radius: 9px; white-space: nowrap; }
@keyframes pulse { 50% { transform: translateX(var(--x, 0)) scale(1.08); } }

/* settings */
.toggle { display: flex; align-items: center; justify-content: space-between; padding: 12px 4px; font-weight: 800; font-size: 18px; border-bottom: 2px dashed #eadfc9; }
.switch { width: 58px; height: 34px; border-radius: 17px; background: #c4cad4; position: relative; transition: background .15s; flex: none; }
.switch::after { content: ""; position: absolute; top: 4px; left: 4px; width: 26px; height: 26px; border-radius: 50%; background: #fff; box-shadow: 0 2px 0 rgba(0, 0, 0, .15); transition: transform .15s; }
.switch.on { background: var(--green); }
.switch.on::after { transform: translateX(24px); }

/* how to */
.howto { text-align: left; }
.howto li { margin: 8px 0; font-weight: 700; line-height: 1.35; }
.howto ul { padding-left: 20px; margin: 6px 0 10px; }

/* win / lose */
.reward { display: flex; flex-direction: column; gap: 6px; margin: 8px 0 6px; }
.reward div { display: flex; justify-content: space-between; align-items: center; background: #fff; border-radius: 14px; padding: 9px 14px; font-weight: 800; }
.reward .total { background: #fff6c8; font-size: 20px; }
.reward .amt { display: flex; align-items: center; gap: 6px; }
.big-icon { font-size: 54px; line-height: 1; margin-bottom: 4px; }
.twist-icon { width: 96px; height: 96px; margin: 0 auto 6px; display: block; }
.tag { display: inline-block; font-size: 12px; font-weight: 900; color: #fff; background: #9b5cf0; padding: 3px 10px; border-radius: 10px; margin-bottom: 6px; }

#toast {
  position: fixed; z-index: 20; left: 50%; top: calc(env(safe-area-inset-top) + 64px); transform: translate(-50%, -20px);
  background: rgba(30, 36, 56, .92); color: #fff; font-weight: 800; padding: 10px 18px; border-radius: 18px; font-size: 15px;
  opacity: 0; transition: opacity .2s, transform .2s; pointer-events: none; text-align: center; max-width: 90vw;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
.fly-coin { position: fixed; z-index: 30; width: 22px; height: 22px; pointer-events: none; transition: transform .6s cubic-bezier(.5, -0.3, .7, 1), opacity .6s; }

@media (min-width: 700px) {
  .booster { flex-basis: 110px; }
}

#banner {
  position: fixed; z-index: 7; left: 50%; top: 38%; transform: translate(-50%, -50%); pointer-events: none; text-align: center;
  animation: banner 1.7s ease-out forwards; white-space: nowrap;
}
#banner .b1 { font-size: 46px; font-weight: 900; color: #fff; -webkit-text-stroke: 2.5px var(--ink); paint-order: stroke fill; filter: drop-shadow(0 4px 0 rgba(30, 40, 80, .35)); }
#banner .b2 { display: inline-block; margin-top: 4px; font-size: 16px; font-weight: 900; color: var(--ink); background: var(--yellow); padding: 4px 14px; border-radius: 14px; box-shadow: 0 3px 0 #c99a14; }
@keyframes banner {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(.5); }
  15% { opacity: 1; transform: translate(-50%, -50%) scale(1.08); }
  25% { transform: translate(-50%, -50%) scale(1); }
  75% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -70%) scale(.96); }
}
