/* ═══════════════════════════════════════════════════════
   Pattern Party — Style
   Ages 5–8 · Mobile-first · WCAG 2.1 AA
   Theme: sunny day, party bridge, festive colors
════════════════════════════════════════════════════════ */

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

:root {
  /* Sky & scene */
  --sky-top:    #fffde7;
  --sky-mid:    #e3f2fd;
  --sky-bot:    #f3e5f5;
  --ground:     #a5d6a7;
  --bridge:     #c8864a;
  --bridge-shad:#8d5524;

  /* UI */
  --white:      #ffffff;
  --text:       #1a237e;
  --text-soft:  #455a64;
  --shadow-sm:  0 4px 14px rgba(0,0,0,0.11);
  --shadow-md:  0 8px 28px rgba(0,0,0,0.17);
  --shadow-lg:  0 16px 48px rgba(0,0,0,0.22);
  --radius-card: 20px;
  --radius-pill: 50px;

  /* Level accent colors (set via JS) */
  --accent: #43a047;
}

html, body {
  height: 100%;
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: linear-gradient(160deg, var(--sky-top) 0%, var(--sky-mid) 50%, var(--sky-bot) 100%);
  overflow: hidden;
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

/* ─── SCREENS ──────────────────────────────────────── */
.screen { display: none; position: fixed; inset: 0; flex-direction: column; }
.screen.active { display: flex; }

/* ═══════════════════════════════════════════════════════
   START SCREEN
════════════════════════════════════════════════════════ */

#start-screen {
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.start-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  text-align: center;
  max-width: 440px;
  width: 100%;
}

.start-bunting {
  font-size: 1.8rem;
  letter-spacing: 6px;
  animation: sway 2s ease-in-out infinite alternate;
}

.start-inner h1 {
  font-size: clamp(2.4rem, 8vw, 3.5rem);
  font-weight: 900;
  color: var(--text);
  letter-spacing: -0.02em;
}

.start-tagline {
  font-size: clamp(1rem, 3.5vw, 1.2rem);
  color: var(--text-soft);
  line-height: 1.6;
}

.start-learn-line {
  font-size: 0.95rem;
  line-height: 1.5;
  color: var(--text-soft);
  background: #fff8e1;
  border: 2px dashed var(--accent);
  border-radius: 16px;
  padding: 10px 14px;
  max-width: 34ch;
}

/* Demo pattern row */
.demo-row {
  display: flex;
  gap: 10px;
  align-items: center;
}

.demo-item {
  width: 64px;
  height: 64px;
  background: var(--white);
  border-radius: 16px;
  border: 3px solid #e0e0e0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2.2rem;
  box-shadow: var(--shadow-sm);
}

.demo-item.demo-gap {
  border: 3px dashed #bdbdbd;
  color: #bdbdbd;
  font-size: 1.8rem;
  font-weight: 800;
  animation: gapPulse 1.4s ease-in-out infinite;
}

/* ═══════════════════════════════════════════════════════
   GAME HEADER
════════════════════════════════════════════════════════ */

.game-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  background: rgba(255,255,255,0.8);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1.5px solid rgba(255,255,255,0.9);
  flex-shrink: 0;
  gap: 8px;
}

.level-badge {
  background: var(--accent);
  color: var(--white);
  border-radius: var(--radius-pill);
  padding: 5px 16px;
  font-size: 0.9rem;
  font-weight: 700;
  white-space: nowrap;
  transition: background 0.4s ease;
}

.star-pill {
  background: #fff8e1;
  border: 2px solid #ffe082;
  color: #f57f17;
  border-radius: var(--radius-pill);
  padding: 5px 14px;
  font-size: 0.9rem;
  font-weight: 700;
  white-space: nowrap;
}

.progress-dots {
  display: flex;
  gap: 7px;
  flex: 1;
  justify-content: center;
}

.dot {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: rgba(0,0,0,0.12);
  border: 2px solid rgba(0,0,0,0.15);
  transition: all 0.25s ease;
}

.dot.active  { background: var(--accent); border-color: var(--accent); transform: scale(1.3); }
.dot.done    { background: #43a047; border-color: #2e7d32; }
.dot.wrong   { background: #ef9a9a; border-color: #e57373; }

/* ═══════════════════════════════════════════════════════
   SCENE
════════════════════════════════════════════════════════ */

.scene {
  flex-shrink: 0;
  padding: 16px 16px 0;
  min-height: 170px;
}

/* Bridge + sequence */
.bridge-area {
  position: relative;
  z-index: 1;
}

.sequence-row {
  display: flex;
  gap: clamp(5px, 1.5vw, 10px);
  align-items: flex-end;
  padding-bottom: 6px;
  overflow-x: auto;
  scrollbar-width: none;
  -ms-overflow-style: none;
  scroll-snap-type: x proximity;
  scroll-padding-inline: 16px;
}

.sequence-row::-webkit-scrollbar { display: none; }

/* On narrow screens the sequence is wider than the viewport. The mask
   fades both edges so a swipeable strip reads as "more this way," not
   as a hard, accidental crop. */
.sequence-row.is-scrollable {
  -webkit-mask-image: linear-gradient(to right, transparent 0, #000 24px, #000 calc(100% - 24px), transparent 100%);
          mask-image: linear-gradient(to right, transparent 0, #000 24px, #000 calc(100% - 24px), transparent 100%);
}

.bridge-plank {
  height: 20px;
  background: linear-gradient(180deg, var(--bridge) 0%, var(--bridge-shad) 100%);
  border-radius: 4px;
  box-shadow: 0 5px 10px rgba(0,0,0,0.25);
  position: relative;
}

.bridge-plank::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 5px;
  background: rgba(255,255,255,0.2);
  border-radius: 4px 4px 0 0;
}

.ground {
  height: 14px;
  background: linear-gradient(180deg, var(--ground) 0%, #81c784 100%);
  border-radius: 0 0 4px 4px;
  margin-top: 2px;
}

/* ─── Sequence items ─────────────────────────────────── */

/* Sized to match .option-btn exactly — the pattern reads as part of the
   same puzzle as the answer choices, not a decorative strip above it. */
.seq-item {
  flex-shrink: 0;
  scroll-snap-align: center;
  width:  clamp(82px, 26vw, 112px);
  height: clamp(82px, 26vw, 112px);
  background: var(--white);
  border-radius: var(--radius-card);
  border: 3px solid #e0e0e0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-size: clamp(2.2rem, 7.5vw, 3rem);
  box-shadow: var(--shadow-sm);
  transition: transform 0.2s ease;
  position: relative;
}

.seq-item.gap-slot {
  border: 3px dashed #bdbdbd;
  background: #fafafa;
}

.gap-mark {
  font-size: clamp(1.8rem, 6vw, 2.6rem);
  font-weight: 900;
  color: #bdbdbd;
  animation: gapPulse 1.4s ease-in-out infinite;
}

.seq-item.just-filled {
  animation: itemFill 0.5s cubic-bezier(0.34,1.56,0.64,1) forwards;
  border-color: #43a047 !important;
}

.seq-item.dancing {
  animation: dance 0.5s ease infinite alternate;
}

.seq-emoji { line-height: 1; }
.seq-emoji.is-big   { font-size: 1.45em; }
.seq-emoji.is-small { font-size: 0.72em; }

/* ═══════════════════════════════════════════════════════
   INSTRUCTION
════════════════════════════════════════════════════════ */

.instruction {
  text-align: center;
  font-size: clamp(1.05rem, 3.8vw, 1.3rem);
  font-weight: 700;
  color: var(--text);
  padding: 10px 20px 4px;
  flex-shrink: 0;
}

/* ═══════════════════════════════════════════════════════
   OPTIONS ROW
════════════════════════════════════════════════════════ */

.options-row {
  display: flex;
  gap: clamp(10px, 3vw, 20px);
  justify-content: center;
  align-items: center;
  padding: 8px 16px 4px;
  flex-shrink: 0;
}

.option-btn {
  width:  clamp(82px, 26vw, 112px);
  height: clamp(82px, 26vw, 112px);
  background: var(--white);
  border-radius: var(--radius-card);
  border: 3px solid #e0e0e0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  cursor: pointer;
  font-family: inherit;
  transition: transform 0.14s ease, box-shadow 0.14s ease, border-color 0.14s ease;
  box-shadow: var(--shadow-sm);
  position: relative;
  overflow: hidden;
}

.option-btn:hover:not(:disabled),
.option-btn:focus-visible {
  transform: translateY(-4px) scale(1.04);
  box-shadow: var(--shadow-md);
  border-color: var(--accent);
}

.option-btn:focus-visible {
  outline: 4px solid var(--accent);
  outline-offset: 3px;
}

.option-emoji {
  font-size: clamp(2.2rem, 7.5vw, 3rem);
  line-height: 1;
  pointer-events: none;
}

.option-emoji.is-big   { font-size: clamp(2.7rem, 9vw, 3.6rem); }
.option-emoji.is-small { font-size: clamp(1.6rem, 5.5vw, 2.2rem); }

.option-name {
  font-size: clamp(0.65rem, 2.2vw, 0.8rem);
  font-weight: 600;
  color: var(--text-soft);
  pointer-events: none;
}

.option-btn.correct-flash {
  animation: optionCorrect 0.45s ease forwards;
  border-color: #43a047 !important;
}

.option-btn.wrong-shake {
  animation: optionShake 0.4s ease forwards;
  border-color: #ef5350 !important;
}

/* ─── Rule chip: names the pattern after a solve ─────── */

.rule-chip {
  margin: 8px auto 2px;
  max-width: min(92vw, 460px);
  background: #fff8e1;
  border: 2px dashed #f9a825;
  color: #7a4f01;
  border-radius: 999px;
  padding: 7px 16px;
  font-size: clamp(0.88rem, 3.4vw, 1.05rem);
  font-weight: 800;
  text-align: center;
  box-shadow: var(--shadow-sm);
  flex-shrink: 0;
}

/* ═══════════════════════════════════════════════════════
   SPARKY HINT STRIP
════════════════════════════════════════════════════════ */

.hint-strip {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 16px 8px;
  flex-shrink: 0;
  flex: 1;
  align-content: flex-end;
  flex-wrap: wrap;
}

.sparky-mini svg { width: 48px; height: auto; }

.hint-bubble {
  background: rgba(255,255,255,0.85);
  backdrop-filter: blur(6px);
  border-radius: 14px;
  padding: 8px 14px;
  font-size: clamp(0.8rem, 2.8vw, 0.95rem);
  font-weight: 600;
  color: var(--text);
  box-shadow: var(--shadow-sm);
  flex: 1;
  max-width: 300px;
}

/* ═══════════════════════════════════════════════════════
   OVERLAYS
════════════════════════════════════════════════════════ */

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(10,25,60,0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 20px;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

.overlay.hidden { display: none; }

.overlay-card {
  background: var(--white);
  border-radius: 32px;
  padding: 36px 28px;
  text-align: center;
  max-width: 380px;
  width: 100%;
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  position: relative;
  z-index: 1;
  animation: popIn 0.35s cubic-bezier(0.34,1.56,0.64,1) forwards;
}

.overlay-emoji       { font-size: 3.5rem; }
.overlay-emoji.big   { font-size: 4.5rem; }

.trophy {
  font-size: 3rem;
  line-height: 1;
  animation: trophyBounce 1.2s ease-in-out infinite;
  filter: drop-shadow(0 6px 12px rgba(255,193,7,0.55));
}

.trophy.large { font-size: 3.8rem; }

.level-praise {
  background: #e8f5e9;
  border-radius: 999px;
  padding: 7px 16px;
  color: #1b5e20 !important;
  font-size: 0.95rem !important;
}

.overlay-card h2 {
  font-size: clamp(1.6rem, 6vw, 2.1rem);
  font-weight: 900;
  color: var(--text);
}

.overlay-card p {
  font-size: clamp(1rem, 3.5vw, 1.1rem);
  color: var(--text-soft);
}

.learn-box {
  background: #e8f5e9;
  border-radius: 16px;
  padding: 14px 18px;
}

.learn-box p {
  font-size: clamp(0.88rem, 3vw, 0.98rem);
  color: #1b5e20;
  line-height: 1.55;
  text-align: left;
}

.stars-row       { font-size: 2rem;   letter-spacing: 4px; }
.stars-row.large { font-size: 2.8rem; letter-spacing: 6px; }

/* ─── Confetti ───────────────────────────────────────── */

#confetti-stage {
  position: fixed; inset: 0;
  pointer-events: none; z-index: 0; overflow: hidden;
}

.confetti-bit {
  position: absolute;
  top: -20px;
  border-radius: 3px;
  animation: confettiFall linear forwards;
}

/* In-game burst stage (sits above screens, below the mute button) */
#burst-stage {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 8500;
  overflow: hidden;
}

.burst-bit {
  position: absolute;
  border-radius: 3px;
  animation: burstFly ease-out forwards;
}

/* ═══════════════════════════════════════════════════════
   BUTTONS
════════════════════════════════════════════════════════ */

.btn-primary {
  background: var(--text);
  color: var(--white);
  border: none;
  border-radius: var(--radius-pill);
  padding: 14px 38px;
  font-size: clamp(1.05rem, 3.8vw, 1.2rem);
  font-weight: 800;
  font-family: inherit;
  cursor: pointer;
  box-shadow: 0 6px 20px rgba(26,35,126,0.35);
  transition: transform 0.14s ease, box-shadow 0.14s ease, background 0.14s ease;
  min-height: 52px;
}

.btn-primary:hover { background: #283593; transform: translateY(-2px); box-shadow: 0 10px 28px rgba(26,35,126,0.45); }
.btn-primary:active { transform: translateY(0); }
.btn-primary:focus-visible { outline: 4px solid #ffd54f; outline-offset: 3px; }

.mute-btn {
  position: fixed; top: 12px; right: 14px;
  padding: 8px 14px;
  border-radius: 999px;
  border: 2px solid rgba(26,35,126,0.18);
  background: rgba(255,255,255,0.9);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  font-family: inherit;
  font-size: 0.82rem;
  font-weight: 800;
  color: var(--text);
  cursor: pointer;
  z-index: 9000;
  box-shadow: var(--shadow-sm);
  transition: transform 0.12s ease;
  white-space: nowrap;
}
.mute-btn:hover { transform: scale(1.1); }
.mute-btn:focus-visible { outline: 3px solid #ffd54f; outline-offset: 3px; }

.hidden { display: none !important; }

/* ═══════════════════════════════════════════════════════
   ANIMATIONS
════════════════════════════════════════════════════════ */

@keyframes sway {
  from { letter-spacing: 4px; }
  to   { letter-spacing: 10px; }
}

@keyframes gapPulse {
  0%, 100% { opacity: 1;   transform: scale(1); }
  50%       { opacity: 0.5; transform: scale(0.85); }
}

@keyframes itemFill {
  0%   { transform: scale(0) rotate(-15deg); }
  60%  { transform: scale(1.18) rotate(4deg); }
  100% { transform: scale(1)    rotate(0deg); }
}

@keyframes dance {
  from { transform: translateY(0) rotate(-5deg); }
  to   { transform: translateY(-8px) rotate(5deg); }
}

@keyframes optionCorrect {
  0%   { transform: scale(1); }
  35%  { transform: scale(1.18) rotate(5deg); }
  65%  { transform: scale(0.95) rotate(-3deg); }
  100% { transform: scale(1) rotate(0deg); }
}

@keyframes optionShake {
  0%, 100% { transform: translateX(0) rotate(0deg); }
  20%       { transform: translateX(-12px) rotate(-5deg); }
  40%       { transform: translateX(12px)  rotate(5deg); }
  60%       { transform: translateX(-7px)  rotate(-3deg); }
  80%       { transform: translateX(5px)   rotate(2deg); }
}

@keyframes popIn {
  0%   { transform: scale(0.55); opacity: 0; }
  70%  { transform: scale(1.06); }
  100% { transform: scale(1);    opacity: 1; }
}

@keyframes trophyBounce {
  0%, 100% { transform: translateY(0) scale(1); }
  50%      { transform: translateY(-8px) scale(1.08); }
}

@keyframes rulePop {
  0%   { transform: scale(0.7) rotate(-2deg); opacity: 0; }
  60%  { transform: scale(1.06) rotate(1deg); }
  100% { transform: scale(1) rotate(0deg);   opacity: 1; }
}

@keyframes burstFly {
  0%   { transform: translate(0, 0) scale(1);   opacity: 1; }
  100% { transform: translate(var(--dx), var(--dy)) scale(0.4); opacity: 0; }
}

.animate-rule { animation: rulePop 0.3s cubic-bezier(0.34,1.56,0.64,1) forwards; }

@keyframes confettiFall {
  0%   { transform: translateY(-30px) rotate(0deg);   opacity: 1; }
  85%  { opacity: 1; }
  100% { transform: translateY(110vh) rotate(720deg); opacity: 0; }
}

/* ═══════════════════════════════════════════════════════
   RESPONSIVE
════════════════════════════════════════════════════════ */

@media (max-width: 360px) {
  .seq-item { width: 76px; height: 76px; font-size: 2rem; }
  .option-btn { width: 76px; height: 76px; }
  .option-emoji { font-size: 2rem; }
}

@media (min-width: 600px) {
  .seq-item { width: 120px; height: 120px; font-size: 3.2rem; }
  .option-btn { width: 120px; height: 120px; }
  .option-emoji { font-size: 3.2rem; }
  .bridge-plank { height: 24px; }
  .ground { height: 18px; }
  .scene { min-height: 190px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
