:root {
  --peach: #ffe3cf;
  --peach-deep: #ffd0b5;
  --cream: #fff6ec;
  --blush: #ffc9d4;
  --blush-deep: #ff9fb4;
  --blue: #9fc4f0;
  --blue-deep: #7aa9e0;
  --sage: #a8c9a0;
  --gold: #f0c979;
  --ink: #5b4a4a;
  --ink-soft: #8b7575;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  height: 100dvh;
  overflow: hidden;
  background: var(--peach);
  color: var(--ink);
  font-family: "Quicksand", system-ui, -apple-system, sans-serif;
  letter-spacing: 0.04em;
  -webkit-font-smoothing: antialiased;
}

body {
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

/* 100vh on iOS is the *large* viewport — taller than what you can actually see,
   so the top of the stage (and with it the timer bar) hides under Safari's
   toolbar. dvh tracks the visible viewport instead. */
#stage {
  position: relative;
  width: min(100vw, calc(100vh * 0.5625));
  height: min(100vh, calc(100vw / 0.5625));
  width: min(100vw, calc(100dvh * 0.5625));
  height: min(100dvh, calc(100vw / 0.5625));
}

#scene, #confetti {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

#confetti {
  z-index: 30;
  pointer-events: none;
}

/* ---------- hud ---------- */

#hud {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  /* viewport-fit=cover lets the page run under the notch, so inset the bar out of it */
  padding: calc(14px + env(safe-area-inset-top, 0px)) 16px 0;
  z-index: 40;              /* stays reachable above the intro card, so sound can be set before starting */
  pointer-events: none;
}

#timer-track {
  height: 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.55);
  overflow: hidden;
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.04) inset;
}

#timer-fill {
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: var(--blush-deep);
  transition: background-color 0.6s ease;
}

#timer-fill.finale {
  background: var(--gold);
}

#hud-row {
  margin-top: 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

#score {
  font-size: 26px;
  font-weight: 700;
  color: var(--ink);
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.6);
  transition: transform 0.18s ease;
}

#score.pop { transform: scale(1.22); }

#sound-toggle {
  pointer-events: auto;
  border: none;
  border-radius: 999px;
  padding: 7px 14px;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.06em;
  color: var(--ink-soft);
  background: rgba(255, 255, 255, 0.7);
  cursor: pointer;
}

#sound-toggle[aria-pressed="true"] {
  background: var(--blush);
  color: var(--ink);
}

/* ---------- intro ---------- */

#intro {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(255, 246, 236, 0.82);
}

#intro[hidden] { display: none; }

#intro-card {
  width: 100%;
  max-width: 320px;
  padding: 24px 24px 26px;
  border-radius: 28px;
  background: var(--cream);
  box-shadow: 0 10px 30px rgba(160, 120, 110, 0.16);
  text-align: center;
}

#intro-title {
  margin: 0;
  font-size: 26px;
  font-weight: 700;
}

#intro-sub {
  margin: 4px 0 18px;
  font-size: 14px;
  font-weight: 500;
  color: var(--ink-soft);
}

#intro-list {
  margin: 0 0 16px;
  padding: 0;
  list-style: none;
  text-align: left;
}

#intro-list li {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 9px;
  font-size: 14px;
  font-weight: 600;
  line-height: 1.35;
}

.chip {
  flex: 0 0 auto;
  width: 18px;
  height: 18px;
  border-radius: 6px;
}

.chip-blue { background: var(--blue); }
.chip-green { background: var(--sage); }
.chip-cactus { background: #8bb87f; border-radius: 9px 9px 4px 4px; }
.chip-barry { background: #9a94b3; border-radius: 9px; }
.chip-move { background: var(--blush); border-radius: 9px 9px 9px 2px; }

#intro-note {
  margin: 0 0 20px;
  font-size: 13px;
  font-weight: 500;
  color: var(--blush-deep);
  line-height: 1.4;
}

#start {
  border: none;
  border-radius: 999px;
  padding: 13px 34px;
  font: inherit;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: var(--ink);
  background: var(--blush);
  box-shadow: 0 4px 0 var(--blush-deep);
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}

#start:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 var(--blush-deep);
}

/* ---------- end screen ---------- */

#end {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(255, 246, 236, 0.82);
  animation: fade-in 0.5s ease both;
}

#end[hidden] { display: none; }

#end-card {
  width: 100%;
  max-width: 320px;
  padding: 18px 22px 24px;
  border-radius: 28px;
  background: var(--cream);
  box-shadow: 0 10px 30px rgba(160, 120, 110, 0.16);
  text-align: center;
}

#end-art {
  width: 100%;
  height: auto;
  display: block;
}

#end-message {
  margin: 6px 0 0;
  font-size: 21px;
  font-weight: 700;
}

#end-score {
  margin: 6px 0 0;
  font-size: 15px;
  font-weight: 600;
  color: var(--ink-soft);
}

#end-love {
  margin: 2px 0 16px;
  font-size: 14px;
  font-weight: 500;
  color: var(--blush-deep);
}

#play-again {
  border: none;
  border-radius: 999px;
  padding: 13px 30px;
  font: inherit;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: var(--ink);
  background: var(--blush);
  box-shadow: 0 4px 0 var(--blush-deep);
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}

#play-again:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 var(--blush-deep);
}

@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* ---------- scene animation ---------- */

.twinkle {
  animation: twinkle 2.4s ease-in-out infinite;
}

.finale .twinkle {
  animation-duration: 0.7s;
}

@keyframes twinkle {
  0%, 100% { opacity: 0.45; }
  50% { opacity: 1; }
}

.wiggle {
  animation: wiggle 0.5s ease-in-out;
}

@keyframes wiggle {
  0%, 100% { transform: rotate(0deg); }
  25% { transform: rotate(-6deg); }
  75% { transform: rotate(6deg); }
}

@media (prefers-reduced-motion: reduce) {
  .twinkle, .finale .twinkle {
    animation: none;
    opacity: 0.85;
  }
  .wiggle { animation: none; }
  #end { animation: none; }
}
