/* ============================================================
   HOP! — style.css
   Mobile-first. No px for font sizes. No !important.
   Modern CSS: clamp(), container queries, logical properties,
   :has(), CSS custom properties, prefers-reduced-motion.
   ============================================================ */

/* ============================================================
   1. DESIGN TOKENS
   ============================================================ */

:root {
  --color-bg: #fdf6ec;
  --color-surface: #fffdf7;
  --color-border: #f5dfc0;
  --color-text: #3d2b1f;
  --color-text-muted: #9c8272;

  --color-score: #f4a261;
  --color-combo: #9b59b6;
  --color-time: #3498db;
  --color-perfect: #27ae60;
  --color-good: #e67e22;
  --color-miss: #e74c3c;

  --lane-1-bg: #ffd6e040;
  --lane-1-accent: #ffb3c6;
  --lane-1-pad: #ffd6e0;
  --lane-1-text: #c0394e;

  --lane-2-bg: #fff3cc40;
  --lane-2-accent: #ffe066;
  --lane-2-pad: #fff3cc;
  --lane-2-text: #8b6914;

  --lane-3-bg: #cceffd40;
  --lane-3-accent: #85c8f0;
  --lane-3-pad: #cceffd;
  --lane-3-text: #1565a3;

  --lane-4-bg: #d5f5e340;
  --lane-4-accent: #7dcea0;
  --lane-4-pad: #d5f5e3;
  --lane-4-text: #145a32;

  /* Fluid spacing */
  --space-xs: clamp(0.25rem, 1vw, 0.5rem);
  --space-sm: clamp(0.5rem, 2vw, 0.75rem);
  --space-md: clamp(0.75rem, 3vw, 1.25rem);
  --space-lg: clamp(1rem, 4vw, 2rem);
  --space-xl: clamp(1.5rem, 5vw, 3rem);

  /* Fluid type */
  --text-xs: clamp(0.625rem, 1.5vw, 0.75rem);
  --text-sm: clamp(0.75rem, 2vw, 0.875rem);
  --text-base: clamp(0.875rem, 2.5vw, 1rem);
  --text-lg: clamp(1rem, 3vw, 1.25rem);
  --text-xl: clamp(1.25rem, 4vw, 1.75rem);
  --text-2xl: clamp(1.75rem, 5vw, 2.5rem);
  --text-3xl: clamp(2.25rem, 7vw, 3.5rem);

  --radius-sm: 0.5rem;
  --radius-md: 1rem;
  --radius-lg: 1.5rem;
  --radius-full: 9999px;

  /* Lane sizing — fluid */
  --lane-width: clamp(3.5rem, 18vw, 5rem);
  --lane-height: clamp(220px, 52vh, 360px);
  --lily-size: clamp(2.5rem, 12vw, 3.75rem);
}

/* ============================================================
   2. RESET & BASE
   ============================================================ */

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

html {
  font-size: 100%;
  scroll-behavior: smooth;
  -webkit-text-size-adjust: none;
  text-size-adjust: none;
}

body {
  min-block-size: 100dvh;
  background-color: var(--color-bg);
  font-family: "Segoe UI", system-ui, sans-serif;
  color: var(--color-text);
  font-size: var(--text-base);
  overflow-x: hidden;
}

/* ============================================================
   3. SCREEN SYSTEM
   Three screens: title, game, results.
   Only one visible at a time — JS toggles .is-hidden.
   ============================================================ */

.screen {
  min-block-size: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding-inline: var(--space-md);
  padding-block: var(--space-lg);
  gap: var(--space-lg);

  /* Fade in when becoming visible */
  animation: screenFadeIn 0.4s ease forwards;
}

.screen.is-hidden {
  display: none;
}

@keyframes screenFadeIn {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (prefers-reduced-motion: reduce) {
  @keyframes screenFadeIn {
    from,
    to {
      opacity: 1;
      transform: none;
    }
  }
}

/* ============================================================
   4. TITLE SCREEN
   ============================================================ */

.title-screen-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-md);
  text-align: center;
  max-inline-size: 26rem;
  width: 100%;
}

.title {
  font-size: var(--text-3xl);
  font-weight: 800;
  color: var(--color-score);
  letter-spacing: -0.03em;
  line-height: 1;
  display: flex;
  align-items: center;
  gap: var(--space-xs);
}

.title--small {
  font-size: var(--text-2xl);
}

.title-icon {
  inline-size: 1em;
  block-size: 1em;
  flex-shrink: 0;
}

.title-sub {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  margin-block-start: calc(-1 * var(--space-sm));
}

.title-characters {
  font-size: var(--text-2xl);
  letter-spacing: 0.1em;
  /* Gentle bounce animation on the characters */
  animation: titleBounce 2s ease-in-out infinite;
}

@keyframes titleBounce {
  0%,
  100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-6px);
  }
}

.title-hint {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  line-height: 1.6;
  text-align: center;
}

/* ============================================================
   5. BUTTON
   ============================================================ */

.btn-start {
  background: var(--color-score);
  color: white;
  border: none;
  border-radius: var(--radius-full);
  padding-block: var(--space-sm);
  padding-inline: var(--space-xl);
  font-size: var(--text-lg);
  font-weight: 800;
  font-family: inherit;
  cursor: pointer;
  letter-spacing: 0.01em;
  transition:
    transform 0.15s ease,
    background 0.15s ease;
  touch-action: manipulation;

  /* Pulsing glow to draw attention */
  animation: btnPulse 2s ease-in-out infinite;
}

.btn-start:hover {
  background: #e8935a;
  transform: scale(1.04);
}

.btn-start:active {
  transform: scale(0.96);
}

.btn-start:focus-visible {
  outline: 3px solid var(--color-score);
  outline-offset: 4px;
}

@keyframes btnPulse {
  0%,
  100% {
    box-shadow: 0 0 0 0 rgba(244, 162, 97, 0.4);
  }
  50% {
    box-shadow: 0 0 0 12px rgba(244, 162, 97, 0);
  }
}

@media (prefers-reduced-motion: reduce) {
  .btn-start {
    animation: none;
  }
  .title-characters {
    animation: none;
  }
}

/* ============================================================
   6. GAME SCREEN — HEADER
   ============================================================ */

.header {
  width: 100%;
  max-inline-size: 32.5rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--space-md);
}

.hud {
  display: flex;
  gap: var(--space-md);
  align-items: flex-end;
}

.hud-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.125rem;
}

.hud-label {
  font-size: var(--text-xs);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--color-text-muted);
  font-weight: 600;
}

.hud-value {
  font-size: var(--text-xl);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

.hud-value.score {
  color: var(--color-score);
}
.hud-value.combo {
  color: var(--color-combo);
}
.hud-value.time {
  color: var(--color-time);
}

/* Timer turns red when under 10 seconds */
.hud-value.time.is-urgent {
  color: var(--color-miss);
  animation: timerUrgent 0.5s ease-in-out infinite;
}

@keyframes timerUrgent {
  0%,
  100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.15);
  }
}

@media (prefers-reduced-motion: reduce) {
  .hud-value.time.is-urgent {
    animation: none;
  }
}

/* ============================================================
   7. GAME AREA
   ============================================================ */

.game-area {
  container-type: inline-size;
  container-name: game;

  width: 100%;
  max-inline-size: 32.5rem;
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  border: 3px solid var(--color-border);
  padding-inline: var(--space-md);
  padding-block: var(--space-md);

  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-sm);

  position: relative;
  /* Relative so star particles can position inside */
}

.instruction {
  font-size: var(--text-xs);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--color-text-muted);
  font-weight: 600;
  text-align: center;
}

.feedback-text {
  font-size: var(--text-lg);
  font-weight: 800;
  min-block-size: 1.5em;
  text-align: center;
  letter-spacing: 0.02em;
}

/* Combo milestone burst — "×10 COMBO!" */
.combo-burst {
  font-size: var(--text-xl);
  font-weight: 800;
  color: var(--color-combo);
  min-block-size: 1.5em;
  text-align: center;
  letter-spacing: 0.02em;
}

/* ============================================================
   8. FEEDBACK STATES
   ============================================================ */

.feedback-text.is-perfect {
  color: var(--color-perfect);
}
.feedback-text.is-good {
  color: var(--color-good);
}
.feedback-text.is-miss {
  color: var(--color-miss);
}

@keyframes feedbackPop {
  0% {
    transform: scale(0.6);
    opacity: 0;
  }
  60% {
    transform: scale(1.2);
    opacity: 1;
  }
  100% {
    transform: scale(1);
    opacity: 1;
  }
}

.feedback-text.is-perfect,
.feedback-text.is-good,
.feedback-text.is-miss {
  animation: feedbackPop 0.25s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

@keyframes comboBurst {
  0% {
    transform: scale(0.5) rotate(-6deg);
    opacity: 0;
  }
  60% {
    transform: scale(1.2) rotate(2deg);
    opacity: 1;
  }
  100% {
    transform: scale(1) rotate(0deg);
    opacity: 1;
  }
}

.combo-burst.is-active {
  animation: comboBurst 0.35s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

@media (prefers-reduced-motion: reduce) {
  .feedback-text.is-perfect,
  .feedback-text.is-good,
  .feedback-text.is-miss,
  .combo-burst.is-active {
    animation: none;
  }
}

/* ============================================================
   9. STAR PARTICLES
   Burst out on Perfect hit.
   Created and destroyed by JS.
   ============================================================ */

.star-particle {
  position: absolute;
  pointer-events: none;
  font-size: var(--text-lg);
  animation: starFly var(--star-duration, 0.7s) ease-out forwards;
}

@keyframes starFly {
  0% {
    transform: translate(0, 0) scale(1);
    opacity: 1;
  }
  100% {
    transform: translate(var(--star-dx, 40px), var(--star-dy, -60px)) scale(0.3);
    opacity: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  .star-particle {
    display: none;
  }
}

/* ============================================================
   10. LANES
   ============================================================ */

.lanes {
  display: flex;
  gap: var(--space-sm);
  justify-content: center;
  width: 100%;
  list-style: none;
}

.lane {
  inline-size: var(--lane-width);
  block-size: var(--lane-height);
  border-radius: var(--radius-md);
  border: 3px dashed rgba(0, 0, 0, 0.1);
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  overflow: hidden;
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
  transition: border-color 0.1s ease;
}

.lane[data-lane="1"] {
  background: var(--lane-1-bg);
  border-color: var(--lane-1-accent);
}
.lane[data-lane="2"] {
  background: var(--lane-2-bg);
  border-color: var(--lane-2-accent);
}
.lane[data-lane="3"] {
  background: var(--lane-3-bg);
  border-color: var(--lane-3-accent);
}
.lane[data-lane="4"] {
  background: var(--lane-4-bg);
  border-color: var(--lane-4-accent);
}

/* :has() — parent reacts when lily pad is active */
.lane[data-lane="1"]:has(.lily-pad.active) {
  border-color: var(--lane-1-text);
  border-style: solid;
}
.lane[data-lane="2"]:has(.lily-pad.active) {
  border-color: var(--lane-2-text);
  border-style: solid;
}
.lane[data-lane="3"]:has(.lily-pad.active) {
  border-color: var(--lane-3-text);
  border-style: solid;
}
.lane[data-lane="4"]:has(.lily-pad.active) {
  border-color: var(--lane-4-text);
  border-style: solid;
}

/* ============================================================
   11. HIT ZONE
   ============================================================ */

.hit-zone {
  position: absolute;
  inset-block-end: 0;
  inset-inline: 0;
  block-size: 30%;
  border-radius: 0 0 calc(var(--radius-md) - 3px) calc(var(--radius-md) - 3px);
  opacity: 0.08;
  pointer-events: none;
}

.lane[data-lane="1"] .hit-zone {
  background: var(--lane-1-text);
}
.lane[data-lane="2"] .hit-zone {
  background: var(--lane-2-text);
}
.lane[data-lane="3"] .hit-zone {
  background: var(--lane-3-text);
}
.lane[data-lane="4"] .hit-zone {
  background: var(--lane-4-text);
}

/* ============================================================
   12. LILY PAD
   ============================================================ */

.lily-pad {
  position: absolute;
  inset-block-end: 0.75rem;
  inline-size: var(--lily-size);
  block-size: var(--lily-size);
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--text-sm);
  font-weight: 800;
  letter-spacing: 0.05em;
  border: 3px solid rgba(0, 0, 0, 0.12);
  transition:
    transform 0.1s ease,
    box-shadow 0.1s ease;
}

.lane[data-lane="1"] .lily-pad {
  background: var(--lane-1-pad);
  border-color: var(--lane-1-accent);
  color: var(--lane-1-text);
}
.lane[data-lane="2"] .lily-pad {
  background: var(--lane-2-pad);
  border-color: var(--lane-2-accent);
  color: var(--lane-2-text);
}
.lane[data-lane="3"] .lily-pad {
  background: var(--lane-3-pad);
  border-color: var(--lane-3-accent);
  color: var(--lane-3-text);
}
.lane[data-lane="4"] .lily-pad {
  background: var(--lane-4-pad);
  border-color: var(--lane-4-accent);
  color: var(--lane-4-text);
}

.lily-pad.active {
  transform: scale(0.86);
}

/* ============================================================
   13. GRASS STRIP
   ============================================================ */

.grass {
  position: absolute;
  inset-block-end: 0;
  inset-inline: 0;
  block-size: 1rem;
  border-radius: 0 0 calc(var(--radius-md) - 3px) calc(var(--radius-md) - 3px);
  opacity: 0.35;
}

.lane[data-lane="1"] .grass {
  background: var(--lane-1-text);
}
.lane[data-lane="2"] .grass {
  background: var(--lane-2-text);
}
.lane[data-lane="3"] .grass {
  background: var(--lane-3-text);
}
.lane[data-lane="4"] .grass {
  background: var(--lane-4-text);
}

/* ============================================================
   14. FALLING NOTE
   ============================================================ */

.note {
  position: absolute;
  inset-block-start: -4rem;
  inline-size: 80%;
  aspect-ratio: 1 / 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0.2rem;
  animation:
    fall var(--fall-duration, 2s) ease-in var(--fall-delay, 0s) 1 forwards,
    wobble var(--fall-duration, 2s) ease-in-out var(--fall-delay, 0s) 1 forwards;
}

.note svg {
  inline-size: 100%;
  block-size: 100%;
  flex-shrink: 0;
}

@keyframes fall {
  from {
    transform: translateY(0);
    opacity: 1;
  }
  85% {
    opacity: 1;
  }
  to {
    transform: translateY(calc(var(--lane-height) + 5rem));
    opacity: 0;
  }
}

@keyframes wobble {
  0% {
    rotate: -8deg;
  }
  25% {
    rotate: 8deg;
  }
  50% {
    rotate: -5deg;
  }
  75% {
    rotate: 5deg;
  }
  100% {
    rotate: 0deg;
  }
}

@keyframes noteHit {
  0% {
    transform: scale(1);
    opacity: 1;
  }
  50% {
    transform: scale(1.4);
    opacity: 1;
  }
  100% {
    transform: scale(0);
    opacity: 0;
  }
}

@keyframes noteMiss {
  0% {
    opacity: 1;
    transform: translateX(0);
  }
  30% {
    transform: translateX(-8px);
  }
  60% {
    transform: translateX(8px);
  }
  100% {
    opacity: 0;
    transform: translateX(0);
  }
}

.note.is-hit {
  animation: noteHit 0.3s ease-out forwards;
}
.note.is-miss {
  animation: noteMiss 0.35s ease-out forwards;
}

@media (prefers-reduced-motion: reduce) {
  @keyframes wobble {
    from,
    to {
      rotate: 0deg;
    }
  }
  .note.is-hit,
  .note.is-miss {
    animation: none;
    opacity: 0;
  }
}

/* ============================================================
   15. RESULTS SCREEN
   ============================================================ */

.results-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-md);
  text-align: center;
  max-inline-size: 24rem;
  width: 100%;
}

.results-emoji {
  font-size: clamp(3rem, 12vw, 5rem);
  animation: trophyBounce 1s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

@keyframes trophyBounce {
  0% {
    transform: scale(0) rotate(-10deg);
    opacity: 0;
  }
  100% {
    transform: scale(1) rotate(0deg);
    opacity: 1;
  }
}

@media (prefers-reduced-motion: reduce) {
  .results-emoji {
    animation: none;
  }
}

.results-title {
  font-size: var(--text-2xl);
  font-weight: 800;
  color: var(--color-score);
}

.results-score-label {
  font-size: var(--text-xs);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--color-text-muted);
  font-weight: 600;
}

.results-score {
  font-size: var(--text-3xl);
  font-weight: 800;
  color: var(--color-text);
  font-variant-numeric: tabular-nums;
}

.results-stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--space-sm);
  width: 100%;
  background: var(--color-surface);
  border-radius: var(--radius-md);
  border: 2px solid var(--color-border);
  padding: var(--space-md);
}

.stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.2rem;
}

.stat-value {
  font-size: var(--text-xl);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  color: var(--color-text);
}

.stat-label {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  letter-spacing: 0.05em;
  text-align: center;
}

/* ============================================================
   16. FOOTER
   ============================================================ */

.footer {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  display: flex;
  align-items: center;
  gap: var(--space-xs);
}

/* ============================================================
   17. CONTAINER QUERIES — game area responsive
   ============================================================ */

@container game (min-inline-size: 28rem) {
  .instruction {
    font-size: var(--text-sm);
  }
}

/* ============================================================
   18. MEDIA QUERIES — page-level only
   ============================================================ */

@media (min-width: 37.5rem) {
  :root {
    --lane-width: clamp(4.5rem, 10vw, 5.5rem);
    --lily-size: clamp(3rem, 9vw, 4rem);
  }

  .game-area {
    padding-inline: var(--space-lg);
    padding-block: var(--space-lg);
  }

  .results-stats {
    gap: var(--space-md);
  }
}

@media (min-width: 64rem) {
  :root {
    --lane-height: clamp(300px, 55vh, 420px);
  }
}

/* ============================================================
   19. ACCESSIBILITY — reduced motion
   ============================================================ */

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }
  .lily-pad {
    transition: none;
  }
  .lane {
    transition: none;
  }
  .btn-start {
    animation: none;
    transition: none;
  }
  .hud-value.time.is-urgent {
    animation: none;
  }
}

/* ============================================================
   20. UTILITIES
   ============================================================ */

.visually-hidden {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
