/* ===== Numberblocks Math - Design System ===== */

@import url('https://fonts.googleapis.com/css2?family=Fredoka:wght@400;600;700&display=swap');

:root {
  /* Numberblock canonical colors */
  --nb-1: #E53935;
  --nb-2: #FB8C00;
  --nb-3: #FDD835;
  --nb-4: #43A047;
  --nb-5: #1E88E5;
  --nb-6: #8E24AA;
  --nb-7: #EC407A;
  --nb-8: #F48FB1;
  --nb-9: #00838F;
  --nb-10: #F5F5F5;

  /* Semantic */
  --correct: #66BB6A;
  --incorrect: #EF5350;
  --star-color: #FFD54F;

  /* UI */
  --text-dark: #333;
  --text-light: #fff;
  --btn-primary: #1E88E5;
  --bg-light: #FFF8E1;
  --bg-white: #FFFFFF;
  --bg-blue: #E3F2FD;
  --shadow-soft: rgba(0, 0, 0, 0.1);

  /* Typography */
  --font-main: 'Fredoka', 'Comic Sans MS', cursive, sans-serif;

  /* Sizing */
  --block-size: 48px;
  --block-size-sm: 36px;
  --btn-min-size: 64px;
  --radius-round: 16px;
  --radius-pill: 999px;
}

/* --- Reset & Base --- */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-main);
  background: linear-gradient(135deg, var(--bg-light) 0%, var(--bg-white) 50%, var(--bg-blue) 100%);
  background-attachment: fixed;
  min-height: 100vh;
  color: var(--text-dark);
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
}

/* --- Animations --- */
@keyframes block-stack {
  0% { transform: translateY(-40px); opacity: 0; }
  60% { transform: translateY(4px); opacity: 1; }
  80% { transform: translateY(-2px); }
  100% { transform: translateY(0); opacity: 1; }
}

@keyframes pop-in {
  0% { transform: scale(0); opacity: 0; }
  70% { transform: scale(1.15); opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}

@keyframes wiggle {
  0%, 100% { transform: rotate(0deg); }
  20% { transform: rotate(-5deg); }
  40% { transform: rotate(5deg); }
  60% { transform: rotate(-3deg); }
  80% { transform: rotate(3deg); }
}

@keyframes celebrate {
  0% { transform: scale(1) rotate(0deg); }
  25% { transform: scale(1.2) rotate(8deg); }
  50% { transform: scale(1.1) rotate(-4deg); }
  75% { transform: scale(1.15) rotate(4deg); }
  100% { transform: scale(1) rotate(0deg); }
}

@keyframes fade-in {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

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

@keyframes face-appear {
  0% { opacity: 0; transform: scale(0.5); }
  100% { opacity: 1; transform: scale(1); }
}

@keyframes confetti-fall {
  0% {
    transform: translateY(-10px) rotate(0deg);
    opacity: 1;
  }
  100% {
    transform: translateY(105vh) rotate(720deg);
    opacity: 0;
  }
}

@keyframes walk-in-left {
  0% { transform: translateX(-200px); opacity: 0; }
  100% { transform: translateX(0); opacity: 1; }
}

@keyframes walk-in-right {
  0% { transform: translateX(200px); opacity: 0; }
  100% { transform: translateX(0); opacity: 1; }
}

@keyframes bounce-happy {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-4px); }
}

@keyframes float-away {
  0% { transform: translateY(0) scale(1); opacity: 1; }
  100% { transform: translateY(-80px) scale(0.6); opacity: 0; }
}

@keyframes slide-to-center {
  0% { transform: translateX(var(--slide-from)); }
  100% { transform: translateX(0); }
}

/* --- Button System --- */
.nb-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: var(--btn-min-size);
  min-height: var(--btn-min-size);
  padding: 12px 28px;
  border: 3px solid rgba(0, 0, 0, 0.08);
  border-radius: var(--radius-round);
  background: var(--btn-primary);
  color: white;
  font-family: var(--font-main);
  font-size: 1.4rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.2s ease;
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.15);
  user-select: none;
  text-decoration: none;
  gap: 8px;
}

.nb-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 0 rgba(0, 0, 0, 0.15);
}

.nb-btn:active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.15);
}

.nb-btn--correct {
  background: var(--correct);
  color: white;
}

.nb-btn--incorrect {
  background: var(--incorrect);
  color: white;
  animation: wiggle 0.4s ease;
}

.nb-btn--gold {
  background: var(--star-color);
  color: var(--text-dark);
}

.nb-btn--large {
  font-size: 2.2rem;
  min-width: 88px;
  min-height: 88px;
  border-radius: 50%;
}

.nb-btn--answer {
  background: white;
  color: var(--text-dark);
  border: 3px solid #ddd;
  min-width: 80px;
  font-size: 1.6rem;
}

.nb-btn--answer:hover {
  border-color: var(--btn-primary);
  background: var(--bg-blue);
}

.nb-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

/* --- Card Component --- */
.nb-card {
  background: white;
  border: 2px solid rgba(0, 0, 0, 0.06);
  border-radius: var(--radius-round);
  padding: 24px;
  text-align: center;
  box-shadow: 0 4px 16px var(--shadow-soft);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.nb-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
}

/* --- Numberblock Unit Block --- */
.nb-unit {
  border-radius: 8px;
  border: 2px solid rgba(255, 255, 255, 0.5);
  position: relative;
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.12), 0 1px 2px rgba(0,0,0,0.1);
}

.nb-unit::after {
  content: '';
  position: absolute;
  top: 4px;
  left: 4px;
  width: 12px;
  height: 8px;
  background: rgba(255, 255, 255, 0.45);
  border-radius: 4px;
}

.nb-unit--animate {
  opacity: 0;
  animation: block-stack 0.35s ease forwards;
}

/* --- Numberblock Character Container (CSS Grid) --- */
.numberblock {
  display: inline-grid;
  gap: 3px;
  position: relative;
}

/* --- Outline cells (for Shape Filler game) --- */
.numberblock-outline {
  display: inline-grid;
  gap: 3px;
}

.nb-outline-cell {
  border-radius: 8px;
  border: 2px dashed #bbb;
  background: rgba(0, 0, 0, 0.04);
}

/* Filled cells in outline (already placed pieces) */
.nb-placed-cell {
  border-radius: 8px;
  border: 2px solid rgba(255, 255, 255, 0.5);
  box-shadow: inset 0 -3px 0 rgba(0,0,0,0.12);
}

.numberblock-filled {
  display: inline-grid;
  gap: 3px;
}

/* --- Numberblock Face --- */
.nb-face {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 1;
  opacity: 0;
  animation: face-appear 0.3s ease forwards;
}

/* --- Numberblock Label --- */
.nb-label {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--text-dark);
  margin-top: 6px;
  text-align: center;
}

/* --- Background Confetti --- */
.confetti-container {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 0;
  overflow: hidden;
}

.confetti-piece {
  position: absolute;
  top: -20px;
  width: 10px;
  height: 10px;
  border-radius: 2px;
  animation: confetti-fall linear infinite;
}

/* --- Counting Labels (teaching hint) --- */
.nb-count-label {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 0.85rem;
  font-weight: 700;
  color: white;
  text-shadow: 0 1px 3px rgba(0,0,0,0.6);
  opacity: 0;
  animation: fade-in 0.3s ease forwards;
  pointer-events: none;
  z-index: 2;
}

/* --- Streak Display --- */
.streak-display {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 3rem;
  font-weight: 700;
  color: var(--star-color);
  text-shadow: 0 2px 8px rgba(255,213,79,0.6);
  animation: float-away 1.2s ease forwards;
  pointer-events: none;
  z-index: 100;
}

/* --- Utilities --- */
.text-center { text-align: center; }
.mt-1 { margin-top: 8px; }
.mt-2 { margin-top: 16px; }
.mt-3 { margin-top: 24px; }
.mb-2 { margin-bottom: 16px; }
.gap-1 { gap: 8px; }
.gap-2 { gap: 16px; }

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
}
