:root {
  --cream: #fff3e2;
  --pink: #ff8fb2;
  --hotpink: #ff5c8a;
  --deep: #d94f7a;
  --mint: #b8f2d8;
  --mintdark: #2ea87c;
  --lav: #cdbcff;
  --choc: #5b4038;
  --sun: #ffd166;
  --sky: #a8d8ff;
  --paper: #fffdf8;
  --display: "Mochiy Pop One", sans-serif;
  --body: "Baloo 2", sans-serif;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--cream);
  font-family: var(--body);
  color: var(--choc);
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
}

/* per-encounter kawaii backdrops (CC0 photos), softened so the ring stays
   readable. Two stacked layers cross-fade on switch: setBg() paints the new
   image on the hidden layer and swaps the .show class, so backdrops melt into
   each other instead of hard-cutting (background-image itself can't animate
   reliably cross-browser — opacity can, and it's compositor-cheap). */
.bg-layer {
  position: fixed; inset: -40px;
  background-size: cover;
  background-position: center;
  filter: blur(2px); /* every backdrop shows near-sharp at full strength now */
  opacity: 0;
  transition: opacity 1.2s ease;
  z-index: 0;
}
.bg-layer.show { opacity: 1; }
/* solid-color mode (boss arena): the layer IS the color — no blur at all */
.bg-layer.solid { filter: none; }

#bg-dots {
  display: none; /* decorative circles + dot grid hidden — backdrop photos carry the scene */
  position: fixed; inset: 0;
  z-index: 1;
  background:
    radial-gradient(circle at 18% 30%, rgba(255,143,178,0.20) 0 140px, transparent 141px),
    radial-gradient(circle at 84% 70%, rgba(205,188,255,0.22) 0 180px, transparent 181px),
    radial-gradient(rgba(255,92,138,0.10) 2.5px, transparent 3px);
  background-size: auto, auto, 34px 34px;
  transition: filter 0.8s ease;
}
body.theme-boss #bg-dots {
  background:
    radial-gradient(circle at 18% 30%, rgba(122,94,214,0.20) 0 140px, transparent 141px),
    radial-gradient(circle at 84% 70%, rgba(255,92,138,0.16) 0 180px, transparent 181px),
    radial-gradient(rgba(122,94,214,0.14) 2.5px, transparent 3px);
  background-size: auto, auto, 34px 34px;
}
body.theme-shop #bg-dots {
  background:
    radial-gradient(circle at 18% 30%, rgba(46,168,124,0.16) 0 140px, transparent 141px),
    radial-gradient(circle at 84% 70%, rgba(255,209,102,0.20) 0 180px, transparent 181px),
    radial-gradient(rgba(46,168,124,0.12) 2.5px, transparent 3px);
  background-size: auto, auto, 34px 34px;
}

canvas#game {
  position: fixed; inset: 0;
  z-index: 2;
  display: block;
}

/* the transition wipe paints on its own layer ABOVE all DOM (HUD + screens),
   so new scenes can build fully covered and get revealed by the pink circle */
canvas#wipe {
  position: fixed; inset: 0;
  z-index: 10;
  pointer-events: none;
  display: block;
}

.hidden { display: none !important; }

/* ---------- HUD stickers ---------- */
#hud {
  position: fixed; inset: 0;
  z-index: 3;
  pointer-events: none;
}
.sticker-card {
  background: var(--paper);
  border: 3px solid var(--choc);
  border-radius: 14px;
  box-shadow: 4px 5px 0 rgba(91,64,56,0.28);
  padding: 8px 16px;
  font-family: var(--display);
  font-size: 22px;
}
/* offsets add the device safe-area insets so the HUD clears the iOS status bar,
   notch, and home indicator (viewport-fit=cover exposes env(); insets are 0 in a
   normal browser, so this is a no-op on desktop/web) */
#hearts {
  position: absolute;
  top: calc(22px + env(safe-area-inset-top));
  left: calc(22px + env(safe-area-inset-left));
  transform: rotate(-3deg);
  font-size: 26px;
  letter-spacing: 2px;
  min-width: 130px;
}
#coins {
  position: absolute;
  top: calc(22px + env(safe-area-inset-top));
  right: calc(22px + env(safe-area-inset-right));
  transform: rotate(2.5deg);
  color: var(--deep);
}
#coins .coin-ico { margin-right: 6px; }
#corner-tags {
  position: absolute;
  bottom: calc(22px + env(safe-area-inset-bottom));
  left: calc(22px + env(safe-area-inset-left));
  display: flex;
  gap: 10px;
  align-items: center;
}
#round-tag {
  transform: rotate(2deg);
  font-size: 16px;
  background: var(--pink);
  color: #fff;
  border-color: var(--choc);
}
/* the shop's identity card — inverted sign: green text on white */
#shop-tag {
  transform: rotate(-2deg);
  font-size: 16px;
  background: var(--paper);
  color: var(--mintdark);
  border-color: var(--choc);
}

/* Shop composition (Death Spiral reference): the offer poster owns the
   top-left, so health/cash drop to the bottom corners and the shop/round
   identity chips move to the free top-right corner. */
body.theme-shop #hearts {
  top: auto;
  bottom: calc(22px + env(safe-area-inset-bottom));
}
body.theme-shop #coins {
  top: auto;
  bottom: calc(22px + env(safe-area-inset-bottom));
}
body.theme-shop #corner-tags {
  bottom: auto;
  left: auto;
  top: calc(22px + env(safe-area-inset-top));
  right: calc(22px + env(safe-area-inset-right));
}
/* Narrow screens: the chips would eat the width the offer poster needs, so
   they drop to the bottom centre (between health and cash) and the poster
   gets the whole top strip. */
@media (max-width: 760px) {
  /* the konbini scene and the clerk already say "shop" — drop the word chip
     so the round chip alone sits in the gap between health and cash */
  body.theme-shop #shop-tag { display: none; }
  body.theme-shop #corner-tags {
    top: auto;
    right: auto;
    bottom: calc(20px + env(safe-area-inset-bottom));
    left: 50%;
    transform: translateX(-50%);
  }
}

.bump { animation: bump 0.35s ease; }
@keyframes bump {
  0% { scale: 1; } 40% { scale: 1.25; rotate: -4deg; } 100% { scale: 1; }
}

/* ---------- full screens ---------- */
.screen {
  position: fixed; inset: 0;
  z-index: 4;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 22px;
  text-align: center;
  padding: 24px;
}

/* ransom-note sticker letters, each its own tile */
h1 {
  font-family: var(--display);
  font-size: clamp(34px, 6.5vw, 76px);
  line-height: 1.1;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px 26px;
}
h1 .word {
  display: flex;
  gap: 4px;
  white-space: nowrap;
}
h1 .ltr {
  display: inline-block;
  background: var(--paper);
  border: 3px solid var(--choc);
  border-radius: 12px;
  padding: 2px 10px;
  box-shadow: 4px 5px 0 rgba(91,64,56,0.25);
  animation: floaty 2.6s ease-in-out infinite;
}
h1 .ltr.sp { background: transparent; border: none; box-shadow: none; padding: 0 8px; animation: none; }
h1 .ltr:nth-child(4n+1) { transform: rotate(-5deg); background: var(--pink); color: #fff; }
h1 .ltr:nth-child(4n+2) { transform: rotate(3deg); }
h1 .ltr:nth-child(4n+3) { transform: rotate(-2deg); background: var(--sun); }
h1 .ltr:nth-child(4n+4) { transform: rotate(5deg); background: var(--lav); }
@keyframes floaty {
  0%, 100% { translate: 0 0; }
  50% { translate: 0 -6px; }
}
h1 .ltr { animation-delay: calc(var(--i) * 0.12s); }

.subtitle {
  font-family: var(--body);
  font-weight: 700;
  font-size: clamp(16px, 2.6vw, 22px);
  color: var(--deep);
  background: var(--paper);
  border: 3px solid var(--choc);
  border-radius: 999px;
  padding: 6px 20px;
  transform: rotate(-1.5deg);
  box-shadow: 3px 4px 0 rgba(91,64,56,0.22);
}

/* title subtitle hidden — it fought the ring/kupo for space at odd aspect
   ratios; the title art + footer tutorial line carry the screen. The win/over
   screens keep their .subtitle lines. Delete this rule to re-enable. */
#title-screen .subtitle { display: none; }

.hint {
  display: none; /* helper text hidden — the ring teaches itself */
  font-weight: 500;
  font-size: 15px;
  color: var(--choc);
  opacity: 0.75;
  line-height: 1.5;
}

.title-tape {
  /* decorative — cancel its own height + the flex gap below it so the title
     centers as if the tape weren't there; the tape just hangs above */
  margin-top: calc(-34px - 22px);
  width: 120px; height: 34px;
  background: repeating-linear-gradient(45deg, var(--pink) 0 12px, #ffb3cb 12px 24px);
  border: 3px solid var(--choc);
  border-radius: 6px;
  transform: rotate(-6deg);
  margin-bottom: -8px;
  opacity: 0.9;
}

.press-pill {
  font-family: var(--display);
  font-size: clamp(20px, 3.4vw, 30px);
  background: var(--choc);
  color: var(--paper);
  border-radius: 999px;
  padding: 12px 34px;
  box-shadow: 0 6px 0 rgba(91,64,56,0.35);
  animation: squish 1.4s ease-in-out infinite;
}
@keyframes squish {
  0%, 100% { transform: scale(1, 1); }
  50% { transform: scale(1.06, 0.94) translateY(3px); }
}

/* the title's press-pill is a footer tutorial line — small, out of the ring's
   way (on phones the centered pill overlapped the kupo portrait) */
/* game.js sets body.cramped when the viewport is too short for the footer to
   clear the play! wedge label (exact ring geometry, computed in resize()) */
body.cramped #title-screen .press-pill { display: none; }

#title-screen .press-pill {
  /* emoji can't take a border, so the sparkle gets contrast from a pink pill */
  background: var(--pink);
  color: #fff;
  position: absolute;
  bottom: calc(26px + env(safe-area-inset-bottom));
  /* centered via auto margins, NOT translate/transform — the squish animation
     owns `transform`, and the separate `translate` property proved unreliable
     in the iOS wrapper (pill rendered off-center, clipped at the right edge) */
  left: 0;
  right: 0;
  margin-inline: auto;
  width: fit-content;
  font-size: clamp(13px, 2vmin, 16px);
  padding: 8px 22px;
  white-space: nowrap;
}

/* game over */
#over-screen .subtitle { background: var(--lav); color: var(--choc); }

/* End & victory overlays compose INSIDE the ring (reference: Death Spiral puts
   the stats panel in the circle with the replay wedge at its south pole).
   The ring's diameter is 60vmin (R = 0.30 * min(W,H)), so everything is sized
   in vmin to track it, and the wedge itself is the call-to-action — no pill. */
#over-screen, #win-screen { gap: clamp(6px, 1.4vmin, 14px); }
#over-screen h1, #win-screen h1 {
  font-size: clamp(18px, 4vmin, 40px);
  gap: 4px 12px;
}
#over-screen h1 .ltr, #win-screen h1 .ltr {
  padding: 1px 7px;
  border-radius: 9px;
  border-width: 2px;
  box-shadow: 3px 3px 0 rgba(91,64,56,0.25);
}
#over-screen .subtitle, #win-screen .subtitle {
  font-size: clamp(11px, 1.9vmin, 16px);
  padding: 4px 14px;
}
#over-screen .stats-card, #win-screen .stats-card {
  padding: clamp(8px, 1.6vmin, 16px) clamp(14px, 2.6vmin, 26px);
  font-size: clamp(12px, 2.1vmin, 17px);
  gap: clamp(4px, 0.9vmin, 9px);
}
#over-screen .press-pill, #win-screen .press-pill { display: none; }
.stats-card {
  transform: rotate(-1deg);
  padding: 18px 30px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  font-family: var(--body);
  font-size: 19px;
  font-weight: 700;
}
.stats-card .stat {
  display: flex;
  justify-content: space-between;
  gap: 34px;
}
.stats-card .stat b {
  font-family: var(--display);
  color: var(--hotpink);
}
/* the record line — a run is an attempt at it */
#over-best span { color: var(--deep); }
#over-best b { color: var(--deep); }
#over-best.beat b { color: var(--mintdark); animation: bump 0.6s ease 3; }

/* sad flash when player loses heart */
body.oww #bg-dots { filter: hue-rotate(-30deg) saturate(1.6); }
@keyframes shake {
  0%, 100% { translate: 0 0; }
  25% { translate: -9px 3px; }
  50% { translate: 7px -4px; }
  75% { translate: -5px 2px; }
}
canvas#game.shake { animation: shake 0.3s ease; }

/* link between game versions (hidden on the main title for now) */
#title-screen .ver-link { display: none; }
.ver-link {
  pointer-events: auto;
  font-family: var(--body);
  font-weight: 700;
  font-size: 14px;
  color: var(--deep);
  background: var(--paper);
  border: 2px solid var(--choc);
  border-radius: 999px;
  padding: 4px 14px;
  text-decoration: none;
  box-shadow: 2px 3px 0 rgba(91,64,56,0.2);
  transform: rotate(1.5deg);
}
.ver-link:hover { background: var(--pink); color: #fff; }
