:root {
  --bg: #fff1f5;
  --ink: #5b2a4a;
  --accent: #e8557a;
  --accent-dark: #c63d63;
  --card: rgba(255, 255, 255, 0.88);
  --bar-bg: #f7d6e2;
  --pixel-ink: #1d2b53;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: radial-gradient(circle at 20% 0%, #ffe3ec 0, var(--bg) 45%, #fdeaff 100%);
  color: var(--ink);
  font-family: "Jersey 10", sans-serif;
  min-height: 100%;
}

.wrap {
  max-width: 940px;
  margin: 0 auto;
  padding: 20px 16px 32px;
}

h1 {
  margin: 0 0 16px;
  text-align: center;
  font-size: clamp(34px, 6vw, 54px);
  font-weight: normal;
  line-height: 1;
  color: var(--accent-dark);
}
h1 span {
  display: block;
  margin-top: 4px;
  font-size: 0.45em;
  color: var(--ink);
  opacity: 0.8;
}

.hud {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 12px;
  font-size: 22px;
}
.stat { white-space: nowrap; }
.stat b,
.pill b {
  display: inline-block;
  font-variant-numeric: tabular-nums;
  text-align: left;
}
/* reserve room for the widest value so the progress bar doesn't jump as digits are added */
#score { min-width: 4ch; }
#flowers { min-width: 2ch; }

.progress {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}
.track {
  position: relative;
  flex: 1;
  display: flex;
  align-items: center;
  height: 34px;
  margin: 0 14px;
}
.rider {
  position: absolute;
  top: 50%;
  left: 0%;
  height: 32px;
  /* the ears make the image top-heavy; shift up so the face sits on the bar */
  transform: translate(-50%, -64%);
  transition: left 0.15s linear;
  pointer-events: none;
}
/* Dora sits on the far end of the bar, overlapping it the same way Mousny does at the start */
.goal {
  position: absolute;
  top: 50%;
  left: 100%;
  display: inline-flex;
  transform: translate(-50%, -64%);
  pointer-events: none;
}
.goal img { height: 32px; }
.goal .crown {
  position: absolute;
  top: -6px;
  left: 50%;
  transform: translateX(-50%) rotate(8deg);
  font-size: 16px;
  line-height: 1;
  z-index: 1;
}
.inline-head {
  height: 1.2em;
  vertical-align: -0.25em;
}
.bar {
  flex: 1;
  height: 14px;
  background: #fff1e8;
  overflow: hidden;
}
#progress-fill {
  height: 100%;
  width: 0%;
  /* solid flat pink with a light strip along the top, like an old-school HP bar */
  background:
    linear-gradient(to bottom, rgba(255, 241, 232, 0.55) 0 3px, transparent 3px),
    #ff77a8;
  transition: width 0.15s linear;
}

/* ---------- the 8-bit border ----------
   Everything boxy shares one border: a --px-thick line on each side drawn with hard
   box-shadows, leaving the corners notched like classic pixel UI. No rounded corners. */
:root { --px: 3px; }
.bar,
.pill,
.mute,
.goal-popover,
.stage,
.card,
button {
  border-radius: 0;
  box-shadow:
    0 calc(-1 * var(--px)) 0 0 var(--pixel-ink),
    0 var(--px) 0 0 var(--pixel-ink),
    calc(-1 * var(--px)) 0 0 0 var(--pixel-ink),
    var(--px) 0 0 0 var(--pixel-ink);
}

/* score + flower count, each in its own retro pill over the top-right of the game */
.pills {
  position: absolute;
  top: 13px;
  right: 13px;
  display: flex;
  gap: 14px;
  pointer-events: none;
  z-index: 2; /* above the start card's overlay, so the star pill can be tapped */
}
.pill {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 10px;
  background: #fff1e8;
  color: var(--pixel-ink);
  font-size: 26px;
  line-height: 1;
  white-space: nowrap;
}
.pill b { font-weight: normal; }
/* before a run, the star pill opens the points-to-win setting */
.pill.configurable { pointer-events: auto; cursor: pointer; }
.pill.configurable:hover { background: #ffffff; }

.goal-popover {
  position: absolute;
  top: 58px;
  right: 13px;
  z-index: 3;
  padding: 10px 14px 12px;
  background: #fff1e8;
  color: var(--pixel-ink);
  text-align: center;
}
.goal-popover.hidden { display: none; }
.goal-title { font-size: 20px; margin-bottom: 6px; }
.goal-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-bottom: 10px;
}
.goal-row b {
  font-weight: normal;
  font-size: 30px;
  min-width: 4ch;
  font-variant-numeric: tabular-nums;
}
.goal-popover button {
  font-size: 22px;
  padding: 2px 12px;
}
.goal-popover .goal-reset {
  font-size: 18px;
  padding: 3px 10px;
  color: var(--pixel-ink);
  background: #ffccaa;
}
.goal-popover .goal-reset:disabled { opacity: 0.45; cursor: default; }
.pill-icon {
  height: 24px;
  image-rendering: pixelated;
}

.stage {
  position: relative;
  margin: var(--px);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  cursor: pointer;
}

canvas {
  display: block;
  width: 100%;
  aspect-ratio: 900 / 380;
}

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  /* clear the score pills and mute button along the top */
  padding: 54px 12px 10px;
}
.overlay.hidden { display: none; }
/* the start / game-over card sits right of centre, leaving room for Mousny on the left */
/* the start card sits right of centre to leave room for Mousny; the win card sits left of the throne */
.overlay[data-place="right"] { justify-content: flex-end; padding-right: 5%; }
.overlay[data-place="left"] { justify-content: flex-start; padding-left: 24px; }
.overlay[data-place="left"] .card { max-width: 380px; padding: 14px 20px; }
.overlay[data-place="left"] .card-title { font-size: 28px; }

.card {
  background: #fff1e8;
  padding: 12px 26px 16px;
  /* narrow enough that Mousny stays visible on the left behind it */
  max-width: 64%;
  text-align: center;
}
.card-title {
  font-size: 28px;
  line-height: 1.1;
  color: var(--accent-dark);
  margin-bottom: 8px;
}
.card-body b,
.card-title b {
  font-weight: normal;
  color: #c8237a; /* magenta-pink, kept well apart in hue from the red below */
}
.card-body .danger { color: #d81b1b; } /* true red for the tigers */
.card-body {
  font-size: 20px;
  line-height: 1.2;
  margin-bottom: 12px;
}

button {
  font: inherit;
  font-size: 26px;
  color: white;
  background: var(--accent);
  border: 0;
  padding: 6px 24px;
  cursor: pointer;
}
button:hover { background: #f06489; }
button:active { transform: translateY(2px); }

/* mute toggle: a retro box in the game's top-left corner, matching the pills */
.mute {
  position: absolute;
  top: 13px;
  left: 13px;
  z-index: 2;
  display: flex;
  align-items: center;
  padding: 5px 8px;
  background: #fff1e8;
}
.mute:hover { background: #ffffff; }
.mute:active { transform: translateY(1px); }

.controls {
  text-align: center;
  font-size: 18px;
  line-height: 1.2;
  opacity: 0.7;
  margin-top: 12px;
}

/* too narrow for the card to fit on top of the game: it drops below instead */
@media (max-width: 900px) {
  .stage { box-shadow: none; margin: 0; }
  canvas {
    box-shadow:
      0 calc(-1 * var(--px)) 0 0 var(--pixel-ink),
      0 var(--px) 0 0 var(--pixel-ink),
      calc(-1 * var(--px)) 0 0 0 var(--pixel-ink),
      var(--px) 0 0 0 var(--pixel-ink);
  }
  .overlay,
  .overlay[data-place] { position: static; padding: 16px 0 0; }
  /* full width below the game, its pixel border lined up with the game's */
  .card, .overlay[data-place="left"] .card { max-width: none; width: 100%; margin: 0; padding: 14px 16px; }
}

@media (max-width: 640px) {
  :root { --px: 2px; }
  .hud { font-size: 18px; gap: 8px; }
  .bar { height: 10px; }
  .mute { top: 6px; left: 6px; padding: 2px 5px; }
  .pills { top: 6px; right: 6px; gap: 8px; }
  .goal-popover { top: 36px; right: 6px; padding: 6px 10px 8px; }
  .pill { font-size: 17px; padding: 2px 6px; gap: 4px; }
  .pill-icon { height: 13px; }
  .card-title { font-size: 24px; }
  .card-body { font-size: 18px; }
}
