/* ==========================================================================
   Hurdles Rhythm — HelloHiDear
   Self-contained stylesheet. Every class is prefixed "hr-" and this file is
   only ever loaded by games/hurdles-rhythm/index.html, so nothing here can
   leak into the rest of the platform.
   ========================================================================== */

/* ---- Brand tokens (mirrors the HelloHiDear design system) ----------------
   Defined on :root so <body> can use them too — this stylesheet is only ever
   loaded by the game's own document, so :root here is fully isolated. */
:root {
  --hr-purple: hsl(263 70% 55%);
  --hr-purple-dark: hsl(263 80% 45%);
  --hr-purple-light: hsl(263 60% 70%);
  --hr-orange: hsl(35 90% 60%);
  --hr-orange-dark: hsl(28 88% 52%);
  --hr-cyan: hsl(185 85% 55%);
  --hr-pink: hsl(340 80% 65%);
  --hr-green: hsl(142 66% 45%);
  --hr-gold: hsl(45 95% 55%);
  --hr-ink: hsl(225 15% 15%);
  --hr-ink-soft: hsl(225 10% 45%);
  --hr-bg: hsl(240 100% 99%);
  --hr-card: hsl(0 0% 100%);
  --hr-radius: 1.5rem;
  --hr-shadow-soft: 0 4px 15px -2px hsl(225 15% 15% / 0.10);
  --hr-shadow-pop: 0 14px 40px -8px hsl(263 70% 35% / 0.35);
  --hr-font: "Fredoka", "Comic Sans MS", "Segoe UI", system-ui, sans-serif;
}

/* ---- Page reset (this document only) ------------------------------------- */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  font-family: var(--hr-font);
  background: var(--hr-bg);
  color: var(--hr-ink);
  overflow: hidden;               /* no scrolling while playing */
  overscroll-behavior: none;
  touch-action: manipulation;     /* kills double-tap zoom latency */
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

/* ---- App frame: top bar / stage / bottom bar ------------------------------ */
.hr-root {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-height: 100dvh;
}

.hr-topbar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.6rem 0.9rem;
  background: var(--hr-card);
  box-shadow: var(--hr-shadow-soft);
  z-index: 5;
}

.hr-progress {
  flex: 1;
  height: 1.4rem;
  min-width: 4rem;
  background: hsl(240 20% 93%);
  border-radius: 999px;
  overflow: hidden;
  position: relative;
}

.hr-progress-fill {
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--hr-cyan), var(--hr-purple));
  transition: width 0.35s ease;
}

.hr-progress-runner {
  position: absolute;
  top: 50%;
  left: 0%;
  translate: -50% -54%;
  font-size: 1.1rem;
  transition: left 0.35s ease;
  pointer-events: none;
}

.hr-starcount {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  font-weight: 700;
  font-size: 1.25rem;
  color: var(--hr-ink);
  background: hsl(45 95% 55% / 0.18);
  border-radius: 999px;
  padding: 0.25rem 0.85rem;
  min-width: 4.5rem;
  justify-content: center;
}

/* ---- Icon buttons (pause / mute) ------------------------------------------ */
.hr-iconbtn {
  width: 3.25rem;
  height: 3.25rem;
  min-width: 3.25rem;
  border: none;
  border-radius: 1rem;
  background: hsl(263 70% 55% / 0.12);
  color: var(--hr-purple-dark);
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: transform 0.15s ease, background 0.2s ease;
}

.hr-iconbtn:hover { background: hsl(263 70% 55% / 0.22); }
.hr-iconbtn:active { transform: scale(0.9); }
.hr-iconbtn:focus-visible,
.hr-btn:focus-visible,
.hr-agebtn:focus-visible,
.hr-check:focus-visible input {
  outline: 4px solid var(--hr-cyan);
  outline-offset: 2px;
}

/* ---- Stage ----------------------------------------------------------------- */
.hr-stage {
  position: relative;
  flex: 1;
  min-height: 0;
  background: hsl(197 90% 84%);
}

.hr-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  cursor: pointer;
}

/* Timing feedback bubble ("Perfect Beat!" etc.) */
.hr-feedback {
  position: absolute;
  left: 50%;
  top: 18%;
  translate: -50% 0;
  padding: 0.55rem 1.4rem;
  border-radius: 999px;
  background: var(--hr-card);
  box-shadow: var(--hr-shadow-pop);
  font-size: clamp(1.15rem, 3.5vw, 1.7rem);
  font-weight: 700;
  color: var(--hr-purple-dark);
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  z-index: 4;
}

.hr-feedback.hr-show {
  animation: hr-feedback-pop 1.1s ease-out forwards;
}

.hr-feedback.hr-miss { color: var(--hr-orange-dark); }

@keyframes hr-feedback-pop {
  0%   { opacity: 0; transform: scale(0.4) translateY(14px); }
  18%  { opacity: 1; transform: scale(1.12) translateY(0); }
  30%  { transform: scale(1); }
  75%  { opacity: 1; transform: scale(1) translateY(-6px); }
  100% { opacity: 0; transform: scale(0.92) translateY(-22px); }
}

/* Countdown numbers */
.hr-countdown {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: clamp(4rem, 18vw, 8rem);
  font-weight: 700;
  color: var(--hr-card);
  text-shadow: 0 6px 0 hsl(263 80% 45% / 0.45);
  pointer-events: none;
  z-index: 4;
}

.hr-countdown span {
  display: inline-block;
  animation: hr-count-beat 0.5s ease-out;
}

@keyframes hr-count-beat {
  0%   { transform: scale(1.7); opacity: 0; }
  60%  { transform: scale(0.95); opacity: 1; }
  100% { transform: scale(1); }
}

/* ---- Bottom bar: mascot tip + giant jump button ---------------------------- */
.hr-bottombar {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.45rem;
  padding: 0.55rem 1rem calc(0.8rem + env(safe-area-inset-bottom));
  background: var(--hr-card);
  box-shadow: 0 -6px 20px -8px hsl(225 15% 15% / 0.15);
  z-index: 5;
}

.hr-tip {
  margin: 0;
  font-size: clamp(0.9rem, 2.6vw, 1.05rem);
  font-weight: 500;
  color: var(--hr-ink-soft);
  text-align: center;
  min-height: 1.3em;
}

.hr-jumpbtn {
  width: min(100%, 30rem);
  min-height: 5.5rem;               /* comfortably above the 64px minimum */
  border: none;
  border-radius: var(--hr-radius);
  background: linear-gradient(135deg, var(--hr-orange), var(--hr-orange-dark));
  color: #fff;
  font-family: inherit;
  font-size: clamp(1.6rem, 6vw, 2.2rem);
  font-weight: 700;
  letter-spacing: 0.06em;
  cursor: pointer;
  box-shadow: 0 8px 0 hsl(28 80% 40%), var(--hr-shadow-soft);
  transition: transform 0.08s ease, box-shadow 0.08s ease;
  touch-action: manipulation;
}

.hr-jumpbtn:active,
.hr-jumpbtn.hr-pressed {
  transform: translateY(6px);
  box-shadow: 0 2px 0 hsl(28 80% 40%), var(--hr-shadow-soft);
}

/* ---- Overlays (start / pause / results) ------------------------------------ */
.hr-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  background: hsl(255 60% 30% / 0.45);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 10;
  overflow-y: auto;
}

.hr-overlay[hidden] { display: none; }

.hr-card {
  width: min(100%, 30rem);
  max-height: 100%;
  overflow-y: auto;
  background: var(--hr-card);
  border-radius: var(--hr-radius);
  box-shadow: var(--hr-shadow-pop);
  padding: 1.4rem 1.5rem 1.6rem;
  text-align: center;
  animation: hr-card-in 0.45s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes hr-card-in {
  from { transform: scale(0.7) translateY(30px); opacity: 0; }
  to   { transform: scale(1) translateY(0); opacity: 1; }
}

.hr-title {
  margin: 0 0 0.1rem;
  font-size: clamp(1.9rem, 7vw, 2.6rem);
  font-weight: 700;
  background: linear-gradient(135deg, var(--hr-purple), var(--hr-pink));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.hr-subtitle {
  margin: 0 0 1rem;
  font-size: 1.05rem;
  font-weight: 500;
  color: var(--hr-ink-soft);
}

.hr-heading {
  margin: 1.1rem 0 0.5rem;
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--hr-ink);
}

/* Runner preview (start + results screens) */
.hr-runner-preview {
  width: 9rem;
  height: 9rem;
  margin: 0 auto;
  display: block;
}

.hr-runner-name {
  margin: 0.2rem 0 0;
  font-weight: 700;
  font-size: 1.15rem;
  color: var(--hr-purple-dark);
}

.hr-shuffle {
  margin-top: 0.35rem;
  border: none;
  background: hsl(185 85% 55% / 0.16);
  color: hsl(190 80% 30%);
  font-family: inherit;
  font-weight: 700;
  font-size: 1rem;
  border-radius: 999px;
  padding: 0.55rem 1.2rem;
  min-height: 2.9rem;
  cursor: pointer;
  transition: transform 0.15s ease;
}

.hr-shuffle:active { transform: scale(0.93); }

/* Age selection */
.hr-agegroup {
  display: flex;
  gap: 0.6rem;
  justify-content: center;
}

.hr-agebtn {
  flex: 1;
  max-width: 8.5rem;
  min-height: 4.25rem;
  border: 3px solid hsl(240 20% 90%);
  border-radius: 1.1rem;
  background: var(--hr-card);
  font-family: inherit;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.1rem;
  transition: transform 0.15s ease, border-color 0.2s ease, background 0.2s ease;
}

.hr-agebtn:active { transform: scale(0.94); }

.hr-agebtn .hr-age-emoji { font-size: 1.5rem; }
.hr-agebtn .hr-age-label { font-weight: 700; font-size: 1.05rem; color: var(--hr-ink); }

.hr-agebtn[aria-pressed="true"] {
  border-color: var(--hr-purple);
  background: hsl(263 70% 55% / 0.10);
  transform: scale(1.04);
}

/* Big rounded action buttons */
.hr-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  width: 100%;
  min-height: 4rem;
  margin-top: 0.9rem;
  border: none;
  border-radius: 1.2rem;
  font-family: inherit;
  font-size: 1.35rem;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.12s ease, filter 0.2s ease;
  text-decoration: none;
}

.hr-btn:hover { filter: brightness(1.06); }
.hr-btn:active { transform: scale(0.95); }

.hr-btn-primary {
  background: linear-gradient(135deg, var(--hr-purple), hsl(285 85% 60%));
  color: #fff;
  box-shadow: 0 6px 0 var(--hr-purple-dark), var(--hr-shadow-soft);
}

.hr-btn-primary:active { box-shadow: 0 2px 0 var(--hr-purple-dark); transform: translateY(4px) scale(0.98); }

.hr-btn-secondary {
  background: hsl(263 70% 55% / 0.10);
  color: var(--hr-purple-dark);
}

/* Settings toggles */
.hr-settings {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin-top: 1rem;
  text-align: left;
}

.hr-check {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  font-size: 1.02rem;
  font-weight: 500;
  color: var(--hr-ink-soft);
  padding: 0.45rem 0.4rem;
  border-radius: 0.8rem;
  cursor: pointer;
  min-height: 3rem;
}

.hr-check:hover { background: hsl(240 20% 96%); }

.hr-check input {
  width: 1.6rem;
  height: 1.6rem;
  accent-color: var(--hr-purple);
  cursor: pointer;
  flex-shrink: 0;
}

/* ---- Results screen -------------------------------------------------------- */
.hr-medal {
  width: 6.5rem;
  height: 6.5rem;
  margin: 0.4rem auto 0.2rem;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 3rem;
  animation: hr-medal-spin 0.9s cubic-bezier(0.34, 1.56, 0.64, 1);
  box-shadow: inset 0 -6px 0 hsl(0 0% 0% / 0.12), var(--hr-shadow-soft);
}

@keyframes hr-medal-spin {
  from { transform: rotateY(180deg) scale(0.3); opacity: 0; }
  to   { transform: rotateY(0) scale(1); opacity: 1; }
}

.hr-medal-gold   { background: linear-gradient(160deg, hsl(48 100% 67%), hsl(40 95% 50%)); }
.hr-medal-silver { background: linear-gradient(160deg, hsl(220 15% 88%), hsl(220 10% 68%)); }
.hr-medal-bronze { background: linear-gradient(160deg, hsl(28 60% 62%), hsl(25 55% 45%)); }

.hr-medal-label {
  margin: 0;
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--hr-ink);
}

.hr-result-stars {
  font-size: 1.6rem;
  font-weight: 700;
  margin: 0.5rem 0 0;
  color: var(--hr-ink);
}

.hr-result-best {
  margin: 0.15rem 0 0;
  font-size: 1rem;
  color: var(--hr-ink-soft);
  font-weight: 500;
}

.hr-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  justify-content: center;
  margin: 0.6rem 0 0;
  padding: 0;
  list-style: none;
}

.hr-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  background: hsl(45 95% 55% / 0.16);
  border-radius: 999px;
  padding: 0.35rem 0.85rem;
  font-size: 0.95rem;
  font-weight: 700;
  color: hsl(30 70% 32%);
  animation: hr-card-in 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) backwards;
}

.hr-badge:nth-child(2) { animation-delay: 0.12s; }
.hr-badge:nth-child(3) { animation-delay: 0.24s; }
.hr-badge:nth-child(4) { animation-delay: 0.36s; }
.hr-badge:nth-child(5) { animation-delay: 0.48s; }

.hr-parent-tip {
  margin: 1rem 0 0;
  padding: 0.8rem 1rem;
  border-radius: 1rem;
  background: hsl(185 85% 55% / 0.12);
  color: hsl(195 60% 26%);
  font-size: 0.95rem;
  font-weight: 500;
  text-align: left;
}

.hr-parent-tip strong { display: block; margin-bottom: 0.15rem; }

/* ---- Accessibility helpers -------------------------------------------------- */
.hr-visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* ---- Compact start card on small phones -------------------------------------
   The stage on a 375×812 phone is ~570px tall; the default card is taller and
   would cut the settings row in half. Tightened spacing keeps everything
   visible without shrinking any touch target below 64px. */
@media (max-width: 480px), (max-height: 760px) {
  .hr-card { padding: 1rem 1.1rem 1.1rem; }
  .hr-title { font-size: 1.7rem; }
  .hr-subtitle { font-size: 0.95rem; margin-bottom: 0.5rem; }
  .hr-runner-preview { width: 6rem; height: 6rem; }
  .hr-runner-name { font-size: 1.02rem; margin-top: 0; }
  .hr-shuffle { margin-top: 0.2rem; padding: 0.4rem 1rem; min-height: 2.5rem; font-size: 0.92rem; }
  .hr-heading { margin: 0.7rem 0 0.4rem; font-size: 0.98rem; }
  .hr-agebtn { min-height: 4rem; }
  .hr-agebtn .hr-age-emoji { font-size: 1.2rem; }
  .hr-btn { min-height: 4rem; margin-top: 0.7rem; font-size: 1.2rem; }
  .hr-settings { margin-top: 0.5rem; gap: 0.15rem; }
  .hr-check { min-height: 2.6rem; padding: 0.25rem 0.4rem; font-size: 0.92rem; }
}

/* ---- Small screens / landscape phones --------------------------------------- */
@media (max-height: 480px) {
  .hr-jumpbtn { min-height: 4rem; font-size: 1.4rem; }
  .hr-tip { display: none; }
  .hr-bottombar { padding-top: 0.35rem; }
  .hr-card { padding: 1rem 1.1rem 1.2rem; }
  .hr-runner-preview { width: 6rem; height: 6rem; }
  .hr-title { font-size: 1.6rem; }
}

@media (max-width: 420px) {
  .hr-topbar { gap: 0.5rem; padding: 0.5rem 0.6rem; }
  .hr-starcount { font-size: 1.05rem; min-width: 3.8rem; }
}

/* ---- Reduced motion: kill decorative animation everywhere -------------------- */
@media (prefers-reduced-motion: reduce) {
  .hr-card,
  .hr-medal,
  .hr-badge,
  .hr-countdown span { animation: none; }
  .hr-feedback.hr-show { animation: hr-feedback-fade 1.1s ease forwards; }
}

.hr-root.hr-reduced-motion .hr-card,
.hr-root.hr-reduced-motion .hr-medal,
.hr-root.hr-reduced-motion .hr-badge,
.hr-root.hr-reduced-motion .hr-countdown span { animation: none; }

.hr-root.hr-reduced-motion .hr-feedback.hr-show {
  animation: hr-feedback-fade 1.1s ease forwards;
}

@keyframes hr-feedback-fade {
  0% { opacity: 0; }
  15% { opacity: 1; }
  80% { opacity: 1; }
  100% { opacity: 0; }
}
