:root {
  --font: "Fredoka", "Baloo 2", system-ui, -apple-system, sans-serif;
  --purple: #8b3ff2;
  --purple-d: #5d1fb8;
  --yellow: #ffd23a;
  --yellow-d: #e39a00;
  --green: #4bd34a;
  --green-d: #23901f;
  --red: #f0425a;
  --blue: #3d7bf2;
  --game-bg: #2b2e34;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; height: 100%; overflow: hidden; background: var(--game-bg);
  font-family: var(--font); color: #fff; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
  touch-action: manipulation; overscroll-behavior: none;
}
button { font-family: inherit; color: inherit; border: 0; background: none; cursor: pointer; padding: 0; }

.screen { position: fixed; inset: 0; display: none; }
.screen.active { display: block; }

/* ---------- shared ---------- */
.topbar {
  position: absolute; left: 0; right: 0; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: calc(10px + var(--safe-t)) 12px 6px;
}
.icon-btn {
  width: 44px; height: 44px; border-radius: 12px; font-size: 22px;
  background: linear-gradient(#9d5cff, var(--purple)); box-shadow: 0 4px 0 var(--purple-d), inset 0 2px 0 rgba(255,255,255,.35);
  display: grid; place-items: center;
}
.icon-btn:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--purple-d); }
.pill {
  display: flex; align-items: center; gap: 6px; padding: 5px 14px 5px 8px; border-radius: 14px;
  background: linear-gradient(#a874ff, #7f3fe6); box-shadow: inset 0 2px 0 rgba(255,255,255,.3), 0 3px 0 var(--purple-d);
  font-size: 19px; font-weight: 700; text-shadow: 0 2px 0 rgba(0,0,0,.25);
}
.coin {
  display: inline-block; width: 22px; height: 22px; border-radius: 50%; flex: none;
  background: radial-gradient(circle at 35% 30%, #fff3a6, #ffc81f 45%, #d68a00);
  box-shadow: inset 0 0 0 2px #e9a300;
}
.big-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 10px;
  min-width: 200px; padding: 14px 28px; border-radius: 20px; font-size: 26px; font-weight: 700;
  color: #4a2a00; background: linear-gradient(#ffe46b, var(--yellow)); text-shadow: 0 1px 0 rgba(255,255,255,.5);
  box-shadow: 0 6px 0 var(--yellow-d), 0 10px 18px rgba(0,0,0,.25), inset 0 2px 0 rgba(255,255,255,.6);
  transition: transform .08s;
}
.big-btn:active { transform: translateY(4px); box-shadow: 0 2px 0 var(--yellow-d); }
.big-btn.green { color: #fff; background: linear-gradient(#7ae86a, var(--green)); box-shadow: 0 6px 0 var(--green-d), inset 0 2px 0 rgba(255,255,255,.5); text-shadow: 0 2px 0 rgba(0,0,0,.25); }
.big-btn.blue { color: #fff; background: linear-gradient(#78a8ff, var(--blue)); box-shadow: 0 6px 0 #2550b0, inset 0 2px 0 rgba(255,255,255,.5); text-shadow: 0 2px 0 rgba(0,0,0,.25); }
.big-btn.red { color: #fff; background: linear-gradient(#ff7a8a, var(--red)); box-shadow: 0 6px 0 #a5192d, inset 0 2px 0 rgba(255,255,255,.5); }
.big-btn.small { min-width: 0; flex: 1; font-size: 19px; padding: 11px 12px; }
.big-btn[disabled] { filter: grayscale(.8) brightness(.8); }
.price { display: inline-flex; align-items: center; gap: 4px; padding: 2px 10px 2px 4px; border-radius: 12px; background: rgba(0,0,0,.2); font-size: 20px; }
.text-btn { margin-top: 14px; font-size: 18px; font-weight: 600; opacity: .8; padding: 8px 16px; }
.text-btn.danger { color: #ff9aa7; font-size: 15px; }

/* ---------- home ---------- */
#home {
  background: radial-gradient(ellipse at 50% 30%, #5aa6ff 0%, #2b6ff0 55%, #1d4fc4 100%);
  overflow: hidden;
}
.bubbles { position: absolute; inset: 0; pointer-events: none; }
.bubbles i {
  position: absolute; border-radius: 50%; bottom: -60px;
  background: radial-gradient(circle at 30% 30%, rgba(255,255,255,.55), rgba(255,255,255,.08) 60%);
  border: 1px solid rgba(255,255,255,.25);
  animation: rise linear infinite;
}
@keyframes rise { to { transform: translateY(-120vh); } }
.logo {
  position: absolute; top: calc(70px + var(--safe-t)); left: 0; right: 0; margin: 0; text-align: center;
  font-size: min(16vw, 70px); line-height: .9; letter-spacing: 1px; font-weight: 700;
  display: flex; flex-direction: column; align-items: center; transform: rotate(-3deg);
}
.logo span { color: #ffd23a; -webkit-text-stroke: 3px #7a3fd8; paint-order: stroke fill; text-shadow: 0 6px 0 #4b1f9a, 0 10px 20px rgba(0,0,0,.3); }
.logo span + span { color: #fff; }
.path {
  position: absolute; left: 0; right: 0; top: calc(220px + var(--safe-t)); bottom: calc(140px + var(--safe-b));
  display: flex; flex-direction: column-reverse; align-items: center; justify-content: flex-start; gap: 0;
  overflow: hidden;
}
.node {
  position: relative; width: 74px; height: 74px; border-radius: 50%; display: grid; place-items: center;
  font-size: 30px; font-weight: 700; text-shadow: 0 2px 0 rgba(0,0,0,.3);
  background: radial-gradient(circle at 40% 30%, #ffe680, #ffbf1a 60%, #d78a00); box-shadow: 0 5px 0 #b86f00, inset 0 0 0 4px rgba(255,255,255,.35);
  flex: none;
}
.node.done { background: radial-gradient(circle at 40% 30%, #8ff07a, #3fbf3a 60%, #24861f); box-shadow: 0 5px 0 #1d6c18, inset 0 0 0 4px rgba(255,255,255,.35); font-size: 22px; width: 58px; height: 58px; }
.node.current {
  width: 104px; height: 104px; font-size: 40px;
  background: radial-gradient(circle at 40% 30%, #c08bff, #8b3ff2 60%, #5d1fb8); box-shadow: 0 6px 0 #3f128a, 0 0 0 6px rgba(255,255,255,.25), 0 0 30px rgba(190,140,255,.8);
  animation: bob 1.6s ease-in-out infinite;
}
.node .tag {
  position: absolute; bottom: -12px; left: 50%; transform: translateX(-50%); white-space: nowrap;
  font-size: 13px; padding: 2px 9px; border-radius: 8px; background: #5d1fb8; box-shadow: 0 2px 0 #3f128a;
}
.node .tag.hard { background: #e0457a; box-shadow: 0 2px 0 #9b1f4a; }
.node .tag.veryhard { background: #c21f3a; box-shadow: 0 2px 0 #7d0e20; }
.link { width: 12px; height: 34px; background: #ffbf1a; box-shadow: inset 0 0 0 2px rgba(0,0,0,.08); flex: none; }
.link.done { background: #3fbf3a; }
@keyframes bob { 50% { transform: translateY(-6px) scale(1.03); } }
.play {
  position: absolute; left: 50%; bottom: calc(40px + var(--safe-b)); transform: translateX(-50%);
  font-size: 32px; padding: 18px 40px; min-width: 240px;
}
.play:active { transform: translateX(-50%) translateY(4px); }

/* ---------- game ---------- */
#game { background: radial-gradient(ellipse at 50% 0%, #3a3e46, var(--game-bg) 70%); }
#cv { position: absolute; left: 0; top: 0; touch-action: none; }
.mega-btn {
  position: absolute; right: 14px; bottom: calc(140px + var(--safe-b)); z-index: 5;
  font-size: 17px; padding: 9px 18px; border-radius: 999px; width: auto; min-width: 0;
}
#home .mega-btn { background: linear-gradient(180deg, #a35ee0, #7a3dbb); box-shadow: 0 4px 0 #55278a, 0 8px 18px rgba(90,40,150,.35); }
.mega-btn:active { transform: translateY(3px); }
body.mega #game .boosters, body.mega #tier { display: none; }
.game-top .level-box { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.level-pill { padding: 5px 16px; font-size: 18px; }
.tier { font-size: 13px; font-weight: 700; padding: 2px 10px; border-radius: 8px; display: none; }
.tier.hard { display: block; background: #e0457a; box-shadow: 0 2px 0 #9b1f4a; }
.tier.veryhard { display: block; background: #c21f3a; box-shadow: 0 2px 0 #7d0e20; }
.boosters {
  position: absolute; z-index: 5; left: 0; right: 0; top: calc(80px + var(--safe-t));
  display: flex; justify-content: center; gap: 18px;
}
.booster {
  position: relative; width: 62px; height: 58px; border-radius: 16px; font-size: 28px;
  background: linear-gradient(#7af06a, #3fc43a); box-shadow: 0 5px 0 #23861f, inset 0 2px 0 rgba(255,255,255,.5);
  display: grid; place-items: center;
}
.booster:active { transform: translateY(3px); box-shadow: 0 2px 0 #23861f; }
.booster .ico { filter: drop-shadow(0 2px 0 rgba(0,0,0,.25)); line-height: 1; }
.booster .lbl { position: absolute; bottom: -22px; left: 50%; transform: translateX(-50%); font-size: 11px; font-weight: 600; opacity: .7; }
.booster .badge {
  position: absolute; right: -8px; bottom: -6px; min-width: 24px; height: 24px; padding: 0 5px; border-radius: 12px;
  display: grid; place-items: center; font-size: 14px; font-weight: 700; background: #e3263f; border: 2px solid #fff;
}
.booster .badge.plus { background: #3fc43a; font-size: 18px; }
.booster.locked { filter: grayscale(1) brightness(.7); }
.booster.used-anim { animation: pulse .4s; }
@keyframes pulse { 50% { transform: scale(1.2); } }

.tip {
  position: absolute; z-index: 6; left: 50%; transform: translateX(-50%); width: min(88vw, 360px);
  padding: 12px 16px; border-radius: 16px; text-align: center; font-size: 17px; font-weight: 600; line-height: 1.25;
  background: rgba(20,22,28,.88); box-shadow: 0 6px 20px rgba(0,0,0,.35); pointer-events: none;
  opacity: 0; transition: opacity .3s;
}
.tip.show { opacity: 1; }
.hand {
  position: absolute; z-index: 7; font-size: 44px; pointer-events: none; display: none;
  filter: drop-shadow(0 4px 4px rgba(0,0,0,.4)); animation: tapme 1s ease-in-out infinite;
}
@keyframes tapme { 50% { transform: translate(6px, 10px) scale(.9); } }

/* ---------- modals ---------- */
.modal {
  position: fixed; inset: 0; z-index: 20; display: none; place-items: center; padding: 20px;
  background: rgba(10,12,20,.6); backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px);
}
.modal.show { display: grid; animation: fade .2s; }
@keyframes fade { from { opacity: 0; } }
.card {
  position: relative; width: min(100%, 360px); padding: 26px 22px 20px; border-radius: 26px; text-align: center;
  background: linear-gradient(#5d6fd8, #3b48b5); box-shadow: 0 8px 0 #262f80, 0 20px 40px rgba(0,0,0,.4), inset 0 2px 0 rgba(255,255,255,.3);
  display: flex; flex-direction: column; align-items: center; animation: pop .35s cubic-bezier(.2,1.6,.4,1);
}
@keyframes pop { from { transform: scale(.6); opacity: 0; } }
.card h2 { margin: 0 0 12px; font-size: 32px; text-shadow: 0 3px 0 rgba(0,0,0,.25); }
/* menus never trap the player: they scroll inside the screen and always show a close button */
.modal .card { max-height: calc(100dvh - 32px - var(--safe-t) - var(--safe-b)); overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }
.close-x {
  position: sticky; top: -14px; align-self: flex-end; z-index: 2; flex: none;
  width: 36px; height: 36px; margin: -12px -8px -24px 0; border-radius: 50%;
  font-size: 18px; font-weight: 700; line-height: 1; background: rgba(0,0,0,.28); color: #fff;
}
#m-pause .card { padding-top: 18px; }
#m-pause h2 { font-size: 26px; margin-bottom: 4px; }
#m-pause .toggle { padding: 7px 6px; font-size: 17px; }
#m-pause .looks { padding: 6px 6px 9px; font-size: 17px; }
#m-pause .look-btns { margin-top: 6px; gap: 6px; }
#m-pause .look-btns button { padding: 6px 4px; font-size: 13px; }
#m-pause .row { margin: 4px 0 12px; }
.card p { margin: 0 0 18px; font-size: 17px; opacity: .9; }
.card.win { background: linear-gradient(#ffb43a, #f07a12); box-shadow: 0 8px 0 #a54b00, 0 20px 40px rgba(0,0,0,.4), inset 0 2px 0 rgba(255,255,255,.4); overflow: visible; }
.card.lose { background: linear-gradient(#ff6b7d, #d02945); box-shadow: 0 8px 0 #7d0e20, 0 20px 40px rgba(0,0,0,.4), inset 0 2px 0 rgba(255,255,255,.3); }
.stars { font-size: 44px; letter-spacing: 4px; margin-bottom: 8px; animation: pop .6s .15s both cubic-bezier(.2,1.6,.4,1); }
.reward { display: flex; align-items: center; gap: 8px; font-size: 34px; font-weight: 700; margin-bottom: 20px; }
.reward .coin { width: 34px; height: 34px; }
.burst {
  position: absolute; left: 50%; top: 40px; width: 420px; height: 420px; margin-left: -210px; margin-top: -170px; z-index: -1;
  background: repeating-conic-gradient(rgba(255,255,255,.22) 0 10deg, transparent 10deg 20deg);
  border-radius: 50%; mask: radial-gradient(circle, #000 30%, transparent 70%); -webkit-mask: radial-gradient(circle, #000 30%, transparent 70%);
  animation: spin 12s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.row { display: flex; gap: 12px; width: 100%; margin: 6px 0 18px; }
.toggle {
  display: flex; align-items: center; justify-content: space-between; width: 100%; padding: 10px 6px; font-size: 19px; font-weight: 600;
  border-bottom: 1px solid rgba(255,255,255,.15);
}
.toggle:last-of-type { margin-bottom: 14px; }
.toggle input { display: none; }
.toggle i { position: relative; width: 52px; height: 30px; border-radius: 15px; background: rgba(0,0,0,.3); transition: background .2s; }
.toggle i::after { content: ""; position: absolute; left: 3px; top: 3px; width: 24px; height: 24px; border-radius: 50%; background: #fff; transition: transform .2s; }
.toggle input:checked + i { background: var(--green); }
.toggle input:checked + i::after { transform: translateX(22px); }
#m-pause.home .in-game { display: none; }
#m-pause:not(.home) .home-only { display: none; }
.shop-ico { font-size: 64px; margin: 4px 0 8px; }

.speed-btn {
  position: absolute; z-index: 6; left: 12px; top: calc(64px + var(--safe-t));
  height: 30px; padding: 0 12px; border-radius: 15px; font-size: 14px; font-weight: 800;
  background: rgba(20,24,40,.55); color: #fff; border: 1.5px solid rgba(255,255,255,.6);
  box-shadow: 0 3px 10px rgba(0,0,0,.18);
}
.look-btns.speed-row { grid-template-columns: repeat(3, 1fr); }
.speed-btn.on { background: #ff6b35; border-color: #fff; }

.toast {
  position: fixed; z-index: 30; left: 50%; top: calc(150px + var(--safe-t)); transform: translate(-50%, -12px);
  padding: 10px 18px; border-radius: 14px; background: rgba(15,17,22,.92); font-size: 16px; font-weight: 600;
  opacity: 0; transition: all .25s; pointer-events: none; white-space: nowrap;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.confetti { position: fixed; inset: 0; pointer-events: none; z-index: 19; }
#m-win { background: rgba(10,12,20,.35); backdrop-filter: none; -webkit-backdrop-filter: none; }

.banner {
  position: fixed; inset: 0; z-index: 15; display: none; place-items: center; pointer-events: none;
}
.banner.show { display: grid; }
.banner span {
  padding: 14px 34px; border-radius: 18px; font-size: 34px; font-weight: 700; transform: rotate(-4deg);
  background: linear-gradient(#ff5d78, #c21f3a); box-shadow: 0 6px 0 #7d0e20, 0 14px 30px rgba(0,0,0,.4);
  text-shadow: 0 3px 0 rgba(0,0,0,.25); animation: bannerIn 1.6s ease both;
}
@keyframes bannerIn {
  0% { transform: rotate(-4deg) scale(.3); opacity: 0; }
  18% { transform: rotate(-4deg) scale(1.1); opacity: 1; }
  28%, 80% { transform: rotate(-4deg) scale(1); opacity: 1; }
  100% { transform: rotate(-4deg) scale(.9); opacity: 0; }
}
.rotate { position: fixed; inset: 0; z-index: 50; display: none; place-items: center; align-content: center; background: #1d4fc4; text-align: center; font-size: 20px; font-weight: 600; }
.rotate div { font-size: 64px; transform: rotate(90deg); }
@media (orientation: landscape) and (max-height: 520px) { .rotate { display: grid; } }

.looks { width: 100%; padding: 8px 6px 12px; border-bottom: 1px solid rgba(255,255,255,.15); text-align: left; font-size: 19px; font-weight: 600; }
.look-btns { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; margin-top: 8px; }
.look-btns button { padding: 8px 6px; border-radius: 12px; font-size: 14px; font-weight: 700; background: rgba(0,0,0,.18); border: 2px solid transparent; }
.look-btns button.on { border-color: currentColor; background: rgba(255,255,255,.18); }

/* ---------- compact in-game HUD: leaves more room for the board ---------- */
#game .topbar { padding-top: calc(6px + var(--safe-t)); }
#game .icon-btn { width: 36px; height: 36px; font-size: 18px; }
#game .pill { font-size: 15px; padding: 4px 11px 4px 6px; }
#game .pill .coin { width: 18px; height: 18px; }
#game .level-pill { padding: 4px 12px; font-size: 15px; }
#game .game-top .level-box { flex-direction: row; gap: 6px; }
#game .tier { font-size: 11px; padding: 2px 8px; }
#game .boosters { top: calc(48px + var(--safe-t)); gap: 14px; }
#game .booster { width: 50px; height: 44px; font-size: 22px; border-radius: 13px; }
#game .booster .lbl { display: none; }
#game .booster .badge { min-width: 20px; height: 20px; font-size: 12px; right: -7px; bottom: -6px; }
#game .speed-btn { top: calc(50px + var(--safe-t)); height: 26px; padding: 0 9px; font-size: 12px; }

/* ---------- leaderboard ---------- */
/* home: board and level path share the space; the board keeps 2 rows, the path keeps done + current */
.home-mid {
  position: absolute; left: 0; right: 0; top: calc(205px + var(--safe-t)); bottom: calc(140px + var(--safe-b));
  display: flex; flex-direction: column; align-items: center; gap: 10px;
}
.home-mid .path { position: relative; inset: auto; flex: 1 1 300px; min-height: 200px; width: 100%; -webkit-mask-image: linear-gradient(transparent, #000 48px); mask-image: linear-gradient(transparent, #000 48px); }
.home-board {
  flex: 0 1 auto; min-height: 112px; overflow: hidden; width: min(100% - 32px, 340px); padding: 8px 10px 6px; border-radius: 16px;
  display: flex; flex-direction: column; text-align: left; cursor: pointer;
  background: color-mix(in srgb, currentColor 10%, transparent); border: 2px solid color-mix(in srgb, currentColor 25%, transparent);
}
.home-board[hidden] { display: none; }
.home-board:active { transform: scale(.98); }
.hb-head { display: flex; justify-content: space-between; align-items: baseline; padding: 0 4px 4px; font-size: 17px; font-weight: 700; }
.hb-all { font-size: 14px; font-weight: 700; opacity: .75; }
.hb-list li { padding: 4px; font-size: 15px; }
.hb-list li:last-child { border-bottom: 0; }
#m-board .card { padding-top: 18px; }
#m-board h2 { font-size: 26px; margin-bottom: 10px; }
.lb-form { display: flex; gap: 8px; width: 100%; margin-bottom: 8px; }
.lb-form input {
  flex: 1; min-width: 0; padding: 9px 12px; border-radius: 12px; border: 2px solid rgba(0,0,0,.2);
  background: #fff; color: #222; font: 600 17px var(--font); user-select: text; -webkit-user-select: text;
}
.lb-form button { padding: 0 16px; border-radius: 12px; font-size: 16px; font-weight: 700; color: #fff; background: var(--green); box-shadow: 0 3px 0 var(--green-d); }
.lb-form button:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--green-d); }
.lb-mine { min-height: 20px; margin-bottom: 8px; font-size: 15px; font-weight: 600; opacity: .85; }
.lb-list { list-style: none; width: 100%; margin: 0; padding: 0; text-align: left; }
.lb-list li {
  display: grid; grid-template-columns: 30px 1fr auto auto; gap: 8px; align-items: center;
  padding: 7px 6px; border-bottom: 1px solid color-mix(in srgb, currentColor 15%, transparent); font-size: 16px; font-weight: 600;
}
.lb-list li span:nth-child(2) { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-list li span:nth-child(3) { font-size: 13px; opacity: .7; }
.lb-list li span:last-child { font-weight: 800; text-align: right; }
.lb-list li.me { border-radius: 10px; background: color-mix(in srgb, currentColor 14%, transparent); }
.lb-list li.lb-msg { display: block; padding: 16px 0; border: 0; text-align: center; opacity: .8; }
.win-rank { min-height: 24px; margin: -10px 0 14px; font-size: 18px; font-weight: 700; }
