@property --side { syntax: '<color>'; inherits: true; initial-value: #e04f8f; }
@property --accent { syntax: '<color>'; inherits: true; initial-value: #ff2a78; }

:root {
  --ink: #3b1460;
  --display: 'Unbounded', system-ui, sans-serif;
  --ui: 'Fredoka', system-ui, sans-serif;
  --side: #e04f8f;
  --accent: #ff2a78;
  --gemA: #ff78b0;
  --gemB: #e0186a;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  transition: --side .9s ease, --accent .9s ease;
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; overflow: hidden; background: #ff7a7a; }
body {
  font-family: var(--ui); color: #fff;
  user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
  overscroll-behavior: none;
}
canvas#game { position: fixed; inset: 0; display: block; touch-action: none; }
#ui { position: fixed; inset: 0; pointer-events: none; }
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; touch-action: manipulation; }
button:focus-visible { outline: 3px solid #fff; outline-offset: 4px; }
svg { display: block; }

/* ---------- screens + overlays */
.screen, .overlay {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: clamp(16px, 3.6vh, 34px);
  padding: calc(18px + var(--safe-t)) 18px calc(18px + var(--safe-b));
  opacity: 0; visibility: hidden;
  transition: opacity .35s ease, visibility 0s linear .35s;
}
.screen.show, .overlay.show { opacity: 1; visibility: visible; pointer-events: auto; transition: opacity .35s ease; }
.overlay {
  background: radial-gradient(120% 90% at 50% 45%, rgba(59, 20, 96, .14), rgba(59, 20, 96, .5));
  -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px);
}

/* ---------- the slab motif: everything pressable has an extruded underside */
.play {
  width: clamp(84px, 22vw, 104px); height: clamp(84px, 22vw, 104px); flex: none; border-radius: 50%;
  background: #fff; color: var(--accent);
  display: grid; place-items: center;
  box-shadow: 0 9px 0 var(--side), 0 22px 34px rgba(59, 20, 96, .28);
  transition: transform .12s ease, box-shadow .12s ease;
}
.play svg { width: 42px; height: 42px; fill: currentColor; }
.play:hover { transform: translateY(-2px); box-shadow: 0 11px 0 var(--side), 0 26px 38px rgba(59, 20, 96, .3); }
.play:active { transform: translateY(7px); box-shadow: 0 2px 0 var(--side), 0 10px 18px rgba(59, 20, 96, .25); }

.pills { display: flex; gap: 14px; flex-wrap: wrap; justify-content: center; }
.pill {
  min-height: 50px; padding: 0 26px; border-radius: 999px;
  background: rgba(255, 255, 255, .94); color: var(--ink);
  font-weight: 600; font-size: 18px; letter-spacing: .01em;
  display: inline-flex; align-items: center; gap: 10px;
  box-shadow: 0 5px 0 rgba(59, 20, 96, .22);
  transition: transform .12s ease, box-shadow .12s ease;
}
.pill:active { transform: translateY(4px); box-shadow: 0 1px 0 rgba(59, 20, 96, .22); }
.pill-sub { font-weight: 500; font-size: 14px; opacity: .6; }
.pill-sub:empty { display: none; }

.icon-btn {
  width: 48px; height: 48px; border-radius: 16px;
  background: rgba(255, 255, 255, .24); color: #fff;
  display: grid; place-items: center;
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, .35);
  transition: background .15s ease, transform .12s ease;
}
.icon-btn svg { width: 24px; height: 24px; fill: currentColor; }
.icon-btn:hover { background: rgba(255, 255, 255, .34); }
.icon-btn:active { transform: scale(.94); }
.icon-btn:disabled { opacity: .3; pointer-events: none; }

.bar {
  position: absolute; top: 0; left: 0; right: 0;
  display: flex; justify-content: space-between; align-items: center;
  padding: calc(14px + var(--safe-t)) 16px 0;
}
.gem-count {
  display: inline-flex; align-items: center; gap: 8px;
  font-family: var(--display); font-weight: 800; font-size: 17px;
  padding: 8px 14px 8px 12px; border-radius: 999px; background: rgba(59, 20, 96, .18);
}
.gem-ico { width: 15px; height: 18px; filter: drop-shadow(0 1px 0 rgba(59, 20, 96, .3)); }
.gem-count.bump { animation: bump .3s ease; }
@keyframes bump { 40% { transform: scale(1.18); } }

/* ---------- title */
.corner { position: absolute; top: calc(14px + var(--safe-t)); right: 16px; display: flex; gap: 10px; }
.corner-l { position: absolute; top: calc(14px + var(--safe-t)); left: 16px; }
.icon-btn[hidden] { display: none; }
.icon-btn.off { opacity: .55; }
.toast {
  position: absolute; left: 50%; bottom: calc(26px + var(--safe-b)); transform: translate(-50%, 12px);
  padding: 12px 20px; border-radius: 999px; background: rgba(255, 255, 255, .95); color: var(--ink);
  font-weight: 600; font-size: 16px; white-space: nowrap; box-shadow: 0 5px 0 rgba(59, 20, 96, .2);
  opacity: 0; pointer-events: none; transition: opacity .3s ease, transform .3s ease;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.logo {
  font-family: var(--display); font-weight: 900;
  font-size: clamp(88px, 27vw, 220px); line-height: .95; letter-spacing: -.045em;
  display: flex; align-items: baseline;
  margin-bottom: clamp(4px, 2vh, 20px);
  text-shadow:
    0 .015em 0 var(--side), 0 .03em 0 var(--side), 0 .045em 0 var(--side), 0 .06em 0 var(--side),
    0 .075em 0 var(--side), 0 .09em 0 var(--side), 0 .2em .2em rgba(59, 20, 96, .28);
}
.logo span { display: inline-block; animation: rise .9s cubic-bezier(.2, 1.5, .4, 1) both; animation-delay: calc(var(--i) * 90ms + 150ms); }
.logo span:nth-child(odd) { rotate: -4deg; }
.logo span:nth-child(2) { rotate: 3deg; }
.logo-orb {
  width: .6em; height: .6em; border-radius: 50%; margin-left: .05em;
  background: var(--orb, radial-gradient(circle at 34% 30%, #fff 0 9%, #ffd1e3 38%, #ff3d8b 100%));
  box-shadow: 0 .14em .1em -.04em rgba(59, 20, 96, .3);
  position: relative; top: -.02em;
}
.logo-orb.bob { animation: rise .9s cubic-bezier(.2, 1.5, .4, 1) both, bob 2.4s ease-in-out 1.4s infinite; animation-delay: calc(3 * 90ms + 150ms), 1.4s; }
@keyframes rise { from { transform: translateY(70%); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes bob { 50% { transform: translateY(-.08em); } }

/* ---------- level select */
#levels { justify-content: flex-start; padding-left: 0; padding-right: 0; padding-top: calc(76px + var(--safe-t)); gap: 10px; }
.worlds {
  width: 100%; flex: 1; min-height: 0;
  display: flex; overflow-x: auto; overflow-y: hidden;
  scroll-snap-type: x mandatory; scrollbar-width: none;
  touch-action: pan-x; overscroll-behavior-x: contain;
}
.worlds::-webkit-scrollbar { display: none; }
.world {
  flex: 0 0 100%; scroll-snap-align: center;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: clamp(8px, 2vh, 18px); padding: 0 16px;
  --slab: clamp(80px, 23vw, 112px);
}
.world-name {
  font-family: var(--display); font-weight: 900;
  font-size: clamp(40px, 11vw, 76px); letter-spacing: -.03em; line-height: 1;
  text-shadow: 0 .04em 0 var(--r), 0 .08em 0 var(--r), 0 .16em .2em rgba(59, 20, 96, .25);
}
.world-meta { display: flex; align-items: center; gap: 6px; font-weight: 600; font-size: 17px; opacity: .95; }
.world-meta svg { width: 18px; height: 18px; fill: #ffe066; }
.lv-path { position: relative; margin-top: clamp(4px, 2vh, 18px); }
.lv { position: absolute; width: var(--slab); height: calc(var(--slab) * .74); }
.lv .slab { width: 100%; height: 100%; overflow: visible; transition: transform .15s ease; filter: drop-shadow(0 10px 12px rgba(59, 20, 96, .18)); }
.lv .t { fill: var(--t); } .lv .l { fill: var(--l); } .lv .r { fill: var(--r); }
.lv .num {
  position: absolute; left: 50%; top: calc(var(--slab) * .24); transform: translate(-50%, -50%);
  font-family: var(--display); font-weight: 800; font-size: calc(var(--slab) * .19); color: var(--ink);
  pointer-events: none;
}
.lv .lv-stars { position: absolute; left: 50%; top: calc(var(--slab) * .4); transform: translateX(-50%); display: flex; gap: 2px; pointer-events: none; }
.lv .lv-stars svg { width: calc(var(--slab) * .1); height: calc(var(--slab) * .1); fill: rgba(59, 20, 96, .18); }
.lv .lv-stars svg.on { fill: #ffb300; }
.lv.done .t { fill: var(--lit); }
.lv:hover .slab, .lv:focus-visible .slab { transform: translateY(-5px); }
.lv:active .slab { transform: translateY(2px); }
.lv:focus-visible { outline: none; }
.lv:focus-visible .t { stroke: #fff; stroke-width: 4; }
.lv.locked { cursor: default; }
.lv.locked .t { fill: rgba(255, 255, 255, .42); }
.lv.locked .l { fill: rgba(255, 255, 255, .26); }
.lv.locked .r { fill: rgba(255, 255, 255, .18); }
.lv.locked .slab { filter: none; }
.lv.locked .num, .lv.locked .lv-stars { display: none; }
.lv.locked:hover .slab { transform: none; }
.lv .lock { position: absolute; left: 50%; top: calc(var(--slab) * .24); transform: translate(-50%, -50%); width: calc(var(--slab) * .16); height: calc(var(--slab) * .16); fill: rgba(255, 255, 255, .85); display: none; }
.lv.locked .lock { display: block; }
.lv.current::after {
  content: ''; position: absolute; left: 50%; top: calc(var(--slab) * -.08);
  width: calc(var(--slab) * .22); height: calc(var(--slab) * .22); margin-left: calc(var(--slab) * -.11);
  border-radius: 50%; background: var(--orb, radial-gradient(circle at 34% 30%, #fff 0 9%, #ffd1e3 38%, #ff3d8b 100%));
  box-shadow: 0 6px 10px rgba(59, 20, 96, .25);
  animation: hop 1.1s ease-in-out infinite;
}
@keyframes hop { 50% { transform: translateY(-8px); } }
.lock-note {
  display: none; align-items: center; gap: 8px;
  font-weight: 600; font-size: 17px; padding: 10px 18px; border-radius: 999px; background: rgba(59, 20, 96, .22);
}
.lock-note svg { width: 18px; height: 18px; fill: currentColor; }
.world.is-locked .lock-note { display: inline-flex; }
.world-nav { display: flex; align-items: center; gap: 18px; padding-bottom: 6px; }
.dots { display: flex; gap: 8px; }
.dots button { width: 10px; height: 10px; border-radius: 50%; background: rgba(255, 255, 255, .4); transition: width .25s ease, background .25s ease; }
.dots button.on { width: 26px; border-radius: 6px; background: #fff; }

/* ---------- orbs */
#orbs { padding-top: calc(70px + var(--safe-t)); }
.screen-title {
  font-family: var(--display); font-weight: 900; font-size: clamp(40px, 11vw, 68px); letter-spacing: -.03em;
  text-shadow: 0 .04em 0 var(--side), 0 .08em 0 var(--side), 0 .16em .2em rgba(59, 20, 96, .25);
}
.orb-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: clamp(14px, 3vh, 26px) clamp(10px, 4vw, 30px); width: min(100%, 520px); }
.orb-cell { display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 6px 0; border-radius: 20px; }
.orb-ball {
  width: clamp(54px, 16vw, 74px); aspect-ratio: 1; border-radius: 50%;
  box-shadow: 0 12px 18px -4px rgba(59, 20, 96, .35);
  transition: transform .2s cubic-bezier(.2, 1.5, .4, 1);
}
.orb-cell:hover .orb-ball { transform: translateY(-4px); }
.orb-cell.sel .orb-ball { outline: 4px solid #fff; outline-offset: 5px; }
.orb-cell.cant .orb-ball { opacity: .55; }
.orb-label { font-weight: 600; font-size: 15px; display: inline-flex; align-items: center; gap: 5px; white-space: nowrap; }
.orb-label .gem-ico { width: 11px; height: 14px; }
.orb-cell.cant .orb-label { opacity: .6; }
.orb-cell.shake { animation: shake .35s ease; }
@keyframes shake { 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }
.prism { background: conic-gradient(from 30deg, #ff4f9a, #ffd23f, #3dffc5, #1fb4ff, #b36cff, #ff4f9a); }

/* ---------- HUD */
#hud {
  position: absolute; top: 0; left: 0; right: 0;
  display: grid; grid-template-columns: 48px 1fr auto; align-items: start; gap: 12px;
  padding: calc(12px + var(--safe-t)) 14px 0;
  opacity: 0; visibility: hidden; transition: opacity .3s ease, visibility 0s .3s;
}
#hud.show { opacity: 1; visibility: visible; transition: opacity .3s ease; }
#hud .icon-btn { pointer-events: auto; }
.hud-mid { display: flex; justify-content: center; padding-top: 4px; }
.track-wrap { width: min(100%, 300px); display: flex; flex-direction: column; align-items: center; gap: 8px; }
.lvl-tag { font-family: var(--display); font-weight: 800; font-size: 15px; letter-spacing: .02em; text-shadow: 0 2px 0 rgba(59, 20, 96, .25); }
.track { position: relative; width: 100%; height: 10px; border-radius: 6px; background: rgba(255, 255, 255, .3); }
.track .fill { position: absolute; inset: 0; border-radius: 6px; background: #fff; transform-origin: left; transform: scaleX(0); }
.pips { position: absolute; inset: 0; }
.pips svg { position: absolute; top: 50%; width: 20px; height: 20px; margin: -10px 0 0 -10px; fill: rgba(255, 255, 255, .55); filter: drop-shadow(0 1px 1px rgba(59, 20, 96, .35)); transition: transform .3s cubic-bezier(.2, 1.6, .4, 1), fill .2s; }
.pips svg.on { fill: #ffd23f; transform: scale(1.35); }
.score-wrap { display: none; flex-direction: column; align-items: center; }
#hud.endless .score-wrap { display: flex; }
#hud.endless .track-wrap { display: none; }
.score {
  font-family: var(--display); font-weight: 900; font-size: clamp(44px, 12vw, 64px); line-height: 1;
  text-shadow: 0 3px 0 var(--side), 0 6px 0 var(--side), 0 10px 18px rgba(59, 20, 96, .25);
}
.score-best { font-weight: 600; font-size: 14px; opacity: .85; margin-top: 6px; }
.hud-gems { margin-top: 4px; }

/* ---------- first-run hint */
#hint {
  position: absolute; inset: 0; display: flex; flex-direction: column; justify-content: flex-end; align-items: center;
  padding: 0 14px calc(24px + var(--safe-b)); gap: 14px;
  opacity: 0; transition: opacity .5s ease;
}
#hint.show { opacity: 1; }
#hint p { font-family: var(--display); font-weight: 800; font-size: clamp(16px, 4.4vw, 22px); text-shadow: 0 2px 0 rgba(59, 20, 96, .3); }
.hint-sides { display: flex; gap: 14px; width: 100%; height: min(24vh, 200px); }
.hint-side {
  flex: 1; border-radius: 26px; display: grid; place-items: center;
  background: rgba(255, 255, 255, .14); box-shadow: inset 0 0 0 2px rgba(255, 255, 255, .45);
}
.hint-side svg { width: 46px; height: 46px; fill: #fff; animation: nudge-l 1.2s ease-in-out infinite; }
.hint-side + .hint-side svg { animation-name: nudge-r; }
@keyframes nudge-l { 50% { transform: translateX(-8px); } }
@keyframes nudge-r { 50% { transform: translateX(8px); } }

/* ---------- overlay content */
.ov-title, .big {
  font-family: var(--display); font-weight: 900; letter-spacing: -.03em; line-height: 1;
  text-shadow: 0 .04em 0 var(--side), 0 .08em 0 var(--side), 0 .18em .22em rgba(59, 20, 96, .3);
}
.ov-title { font-size: clamp(44px, 12vw, 80px); }
.big { font-size: clamp(76px, 24vw, 160px); }
.ov-sub { font-weight: 600; font-size: 19px; display: inline-flex; align-items: center; gap: 8px; min-height: 24px; }
.ov-sub .gem-ico { width: 15px; height: 18px; }
.ov-sub .new { font-family: var(--display); font-weight: 800; color: #ffe066; }
.win-stars { display: flex; gap: clamp(8px, 3vw, 18px); align-items: flex-end; }
.win-stars svg { width: clamp(64px, 18vw, 96px); height: clamp(64px, 18vw, 96px); fill: rgba(255, 255, 255, .28); }
.win-stars svg:nth-child(2) { width: clamp(80px, 22vw, 118px); height: clamp(80px, 22vw, 118px); margin-bottom: 14px; }
.win-stars svg.on { fill: #ffd23f; filter: drop-shadow(0 6px 0 #f29a00) drop-shadow(0 12px 18px rgba(59, 20, 96, .3)); animation: star-pop .55s cubic-bezier(.2, 1.7, .4, 1) both; }
@keyframes star-pop { from { transform: scale(0) rotate(-40deg); } to { transform: none; } }

@media (max-height: 560px) {
  .logo { font-size: clamp(64px, 20vh, 140px); }
  .hint-sides { height: 26vh; }
  #levels { padding-top: calc(12px + var(--safe-t)); }
  .world { --slab: clamp(60px, 17vh, 92px); display: grid; grid-template-columns: auto auto; grid-template-rows: auto auto auto; column-gap: clamp(24px, 6vw, 70px); align-content: center; justify-content: center; }
  .world-name { font-size: clamp(30px, 9vh, 48px); grid-column: 1; grid-row: 1; align-self: end; }
  .world-meta { grid-column: 1; grid-row: 2; justify-self: center; }
  .lock-note { grid-column: 1; grid-row: 3; justify-self: center; align-self: start; }
  .lv-path { grid-column: 2; grid-row: 1 / span 3; margin-top: 0; }
  #orbs { padding-top: calc(64px + var(--safe-t)); gap: 12px; }
  .orb-grid { grid-template-columns: repeat(8, minmax(0, 1fr)); width: min(100%, 860px); }
  .screen-title { font-size: 34px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
