/* ============================================================
   Mrs. Blocks' Sticks Method — Premium Educational App CSS
   Target: Ages 6–9 | Tablet-first, mobile-responsive
   ============================================================ */

/* ── Google Fonts ─────────────────────────────────────────── */
@import url('https://fonts.googleapis.com/css2?family=Fredoka:wght@400;500;600;700&family=Nunito:wght@400;600;700;800&display=swap');

/* ── Design Tokens (Custom Properties) ────────────────────── */
:root {
  /* Core palette */
  --primary-blue:    #4A90D9;
  --warm-orange:     #F5A623;
  --cool-teal:       #50C8C6;
  --success-green:   #67D575;
  --playful-pink:    #EF476F;
  --deep-purple:     #6C5CE7;

  /* Surfaces */
  --bg-start:        #8EC5FC;
  --bg-end:          #E0C3FC;
  --glass-bg:        rgba(255, 255, 255, 0.75);
  --glass-border:    rgba(255, 255, 255, 0.45);
  --glass-shadow:    rgba(31, 38, 135, 0.15);

  /* Text */
  --text-dark:       #2D3142;
  --text-muted:      #6B7280;
  --text-light:      #ffffff;

  /* House roof colours */
  --roof-thousands:  #6C5CE7;
  --roof-hundreds:   #EF476F;
  --roof-tens:       #F5A623;
  --roof-units:      #4A90D9;

  /* Stick colours */
  --stick-top:       #F5A623;
  --stick-bottom:    #50C8C6;
  --stick-carried:   #67D575;

  /* Sizing */
  --touch-min:       48px;
  --radius-sm:       10px;
  --radius-md:       16px;
  --radius-lg:       24px;
  --radius-xl:       32px;

  /* Transitions */
  --ease-bounce:     cubic-bezier(0.34, 1.56, 0.64, 1);
  --ease-smooth:     cubic-bezier(0.4, 0, 0.2, 1);
  --transition-fast: 0.2s var(--ease-smooth);
  --transition-med:  0.35s var(--ease-smooth);
  --transition-slow: 0.5s var(--ease-smooth);
}

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

html {
  font-size: 16px;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: 'Nunito', 'Segoe UI', sans-serif;
  color: var(--text-dark);
  min-height: 100vh;
  min-height: 100dvh;
  background: linear-gradient(135deg, var(--bg-start) 0%, var(--bg-end) 100%);
  background-attachment: fixed;
  overflow-x: hidden;
  position: relative;
  line-height: 1.5;
}

/* ── Animated Floating Background Shapes ──────────────────── */
body::before,
body::after {
  content: '';
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 0;
  opacity: 0.25;
}

body::before {
  background:
    radial-gradient(circle 80px at 15% 20%, var(--warm-orange) 0%, transparent 70%),
    radial-gradient(circle 60px at 80% 15%, var(--playful-pink) 0%, transparent 70%),
    radial-gradient(circle 100px at 50% 75%, var(--cool-teal) 0%, transparent 70%),
    radial-gradient(circle 50px at 90% 80%, var(--deep-purple) 0%, transparent 70%),
    radial-gradient(circle 70px at 25% 90%, var(--primary-blue) 0%, transparent 70%);
  animation: floatingShapes 25s ease-in-out infinite alternate;
}

body::after {
  background:
    radial-gradient(circle 90px at 70% 40%, var(--success-green) 0%, transparent 70%),
    radial-gradient(circle 55px at 10% 60%, var(--deep-purple) 0%, transparent 70%),
    radial-gradient(circle 75px at 40% 10%, var(--playful-pink) 0%, transparent 70%),
    radial-gradient(circle 65px at 85% 55%, var(--warm-orange) 0%, transparent 70%);
  animation: floatingShapes 30s ease-in-out 5s infinite alternate-reverse;
}

/* ── Utility ──────────────────────────────────────────────── */
.hidden {
  display: none !important;
}

/* ── Screens (Generic) ────────────────────────────────────── */
.screen {
  position: relative;
  z-index: 1;
  min-height: 100vh;
  min-height: 100dvh;
  padding: 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  opacity: 1;
  transition: opacity var(--transition-slow);
}

.screen.slide-in {
  animation: slideInFromRight 0.45s var(--ease-bounce) forwards;
}

.screen.slide-out {
  animation: slideOutToLeft 0.35s var(--ease-smooth) forwards;
}

/* ── Glass Panel ──────────────────────────────────────────── */
.glass-panel {
  background: var(--glass-bg);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  border: 1.5px solid var(--glass-border);
  border-radius: var(--radius-lg);
  box-shadow:
    0 8px 32px var(--glass-shadow),
    inset 0 1px 0 rgba(255, 255, 255, 0.5);
  padding: 28px;
  transition: transform var(--transition-fast), box-shadow var(--transition-fast);
}

/* ── Buttons ──────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: var(--touch-min);
  min-width: var(--touch-min);
  padding: 12px 28px;
  border: none;
  border-radius: var(--radius-md);
  font-family: 'Fredoka', sans-serif;
  font-size: 1.05rem;
  font-weight: 600;
  cursor: pointer;
  transition:
    transform var(--transition-fast),
    box-shadow var(--transition-fast),
    background var(--transition-fast);
  user-select: none;
  -webkit-user-select: none;
  text-decoration: none;
  outline-offset: 3px;
  position: relative;
  overflow: hidden;
}

.btn:active {
  transform: scale(0.95);
}

.btn:focus-visible {
  outline: 3px solid var(--primary-blue);
  outline-offset: 3px;
}

/* Ripple-like shine on hover */
.btn::after {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 60%;
  height: 100%;
  background: linear-gradient(
    90deg,
    transparent,
    rgba(255, 255, 255, 0.25),
    transparent
  );
  transition: left 0.5s ease;
  pointer-events: none;
}

.btn:hover::after {
  left: 120%;
}

.primary-btn {
  background: linear-gradient(135deg, var(--primary-blue), #3A7BD5);
  color: var(--text-light);
  box-shadow: 0 4px 15px rgba(74, 144, 217, 0.4);
}

.primary-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 22px rgba(74, 144, 217, 0.5);
}

.secondary-btn {
  background: var(--glass-bg);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  color: var(--text-dark);
  border: 2px solid rgba(74, 144, 217, 0.3);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.06);
}

.secondary-btn:hover {
  transform: translateY(-2px);
  border-color: var(--primary-blue);
  box-shadow: 0 4px 18px rgba(74, 144, 217, 0.25);
}

.success-btn {
  background: linear-gradient(135deg, var(--success-green), #4EC95F);
  color: var(--text-light);
  box-shadow: 0 4px 15px rgba(103, 213, 117, 0.4);
}

.success-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 22px rgba(103, 213, 117, 0.5);
}

.danger-btn {
  background: linear-gradient(135deg, var(--playful-pink), #D63B5C);
  color: var(--text-light);
  box-shadow: 0 4px 15px rgba(239, 71, 111, 0.4);
}

.danger-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 22px rgba(239, 71, 111, 0.5);
}

.small-btn {
  min-height: 36px;
  padding: 6px 16px;
  font-size: 0.85rem;
  border-radius: var(--radius-sm);
}

/* ── Landing Screen ───────────────────────────────────────── */
#landing-screen {
  justify-content: center;
  text-align: center;
  gap: 12px;
}

#landing-screen .glass-panel {
  animation: float 4s ease-in-out infinite;
  max-width: 460px;
  width: 100%;
  padding: 40px 32px;
}

#landing-screen h1 {
  font-family: 'Fredoka', sans-serif;
  font-size: 2.2rem;
  font-weight: 700;
  color: var(--text-dark);
  line-height: 1.2;
  margin-bottom: 4px;
}

#landing-screen h1 span {
  background: linear-gradient(135deg, var(--primary-blue), var(--deep-purple));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

#landing-screen p {
  font-size: 1.05rem;
  color: var(--text-muted);
  margin-bottom: 20px;
}

#landing-screen .btn {
  width: 100%;
  max-width: 280px;
  margin: 6px auto;
}

/* ── Character ────────────────────────────────────────────── */
.character-container {
  display: flex;
  justify-content: center;
  align-items: center;
  margin: 0 auto 16px;
}

.character-img {
  width: 180px;
  height: auto;
  border-radius: 50%;
  object-fit: cover;
  animation: float 3.5s ease-in-out infinite;
  filter: drop-shadow(0 8px 20px rgba(0, 0, 0, 0.12));
  transition: transform var(--transition-fast);
}

.character-img:hover {
  transform: scale(1.05);
}

/* ── Mode Selection Screen ────────────────────────────────── */
#mode-screen {
  justify-content: flex-start;
  padding-top: 40px;
  gap: 24px;
}

#mode-screen h2 {
  font-family: 'Fredoka', sans-serif;
  font-size: 1.8rem;
  font-weight: 700;
  color: var(--text-dark);
}

.mode-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 18px;
  width: 100%;
  max-width: 560px;
}

.mode-card {
  background: var(--glass-bg);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1.5px solid var(--glass-border);
  border-radius: var(--radius-lg);
  padding: 24px 18px;
  text-align: center;
  cursor: pointer;
  transition:
    transform var(--transition-fast),
    box-shadow var(--transition-fast),
    border-color var(--transition-fast);
  box-shadow: 0 4px 16px var(--glass-shadow);
  user-select: none;
  position: relative;
  overflow: hidden;
}

.mode-card:hover {
  transform: translateY(-6px) scale(1.02);
  box-shadow:
    0 12px 36px rgba(74, 144, 217, 0.25),
    0 0 0 2px var(--primary-blue);
  border-color: var(--primary-blue);
}

.mode-card:active {
  transform: translateY(-2px) scale(0.98);
}

.mode-card .mode-icon {
  font-size: 2.8rem;
  margin-bottom: 10px;
  display: block;
  line-height: 1;
  filter: drop-shadow(0 2px 6px rgba(0, 0, 0, 0.1));
  transition: transform var(--transition-fast);
}

.mode-card:hover .mode-icon {
  transform: scale(1.15) rotate(-5deg);
}

.mode-card .mode-title {
  font-family: 'Fredoka', sans-serif;
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text-dark);
  margin-bottom: 4px;
}

.mode-card .mode-desc {
  font-size: 0.82rem;
  color: var(--text-muted);
  line-height: 1.4;
}

/* ── Top Bar (Game Header) ────────────────────────────────── */
.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  max-width: 700px;
  padding: 10px 18px;
  background: var(--glass-bg);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1.5px solid var(--glass-border);
  border-radius: var(--radius-xl);
  box-shadow: 0 4px 20px var(--glass-shadow);
  gap: 10px;
  flex-shrink: 0;
  z-index: 10;
}

.top-bar .btn {
  min-width: 40px;
  padding: 8px 12px;
}

.top-bar .score,
.top-bar .level {
  font-family: 'Fredoka', sans-serif;
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--text-dark);
  white-space: nowrap;
}

/* ── Stars Display ────────────────────────────────────────── */
.stars-display {
  display: flex;
  align-items: center;
  gap: 4px;
}

.star {
  font-size: 1.3rem;
  transition: transform var(--transition-fast), filter var(--transition-fast);
  line-height: 1;
}

.star.filled {
  color: var(--warm-orange);
  filter: drop-shadow(0 0 6px rgba(245, 166, 35, 0.5));
  animation: popIn 0.35s var(--ease-bounce);
}

.star.empty {
  color: #CBD5E1;
  opacity: 0.6;
}

.star.filled:hover {
  transform: scale(1.25) rotate(15deg);
}

/* ── Game Screen ──────────────────────────────────────────── */
#game-screen {
  justify-content: flex-start;
  padding-top: 16px;
  gap: 18px;
}

/* ── Problem Display ──────────────────────────────────────── */
/* ── Horizontal Equation Bar ──────────────────────────────── */
.horizontal-equation {
  width: 100%;
  max-width: 400px;
  padding: 14px 20px;
  text-align: center;
  transition: all 0.4s ease;
}

/* ── Word Problem Panel ──────────────────────────────────── */
.word-problem-panel {
  width: 100%;
  max-width: 440px;
  padding: 20px 24px;
  text-align: center;
  margin-bottom: 8px;
}

.word-problem-panel.wp-done {
  padding: 8px 16px;
  opacity: 0.6;
  transform: scale(0.9);
}

.word-problem-emoji {
  font-size: 2.8rem;
  margin-bottom: 8px;
  animation: float 3s ease-in-out infinite;
}

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

.word-problem-text {
  font-family: 'Nunito', sans-serif;
  font-size: 1.15rem;
  font-weight: 600;
  color: var(--text-dark);
  line-height: 1.6;
  margin-bottom: 16px;
  padding: 0 4px;
}

.word-eq-label {
  font-family: 'Fredoka', sans-serif;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--primary-blue);
  margin-bottom: 8px;
}

.word-eq-fields {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.word-eq-num {
  width: 90px;
  height: 48px;
  font-family: 'Fredoka', sans-serif;
  font-size: 1.5rem;
  font-weight: 700;
  text-align: center;
  border: 2.5px dashed rgba(74, 144, 217, 0.3);
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.7);
  color: var(--text-dark);
  outline: none;
  transition: all var(--transition-fast);
  -moz-appearance: textfield;
}

.word-eq-num::-webkit-outer-spin-button,
.word-eq-num::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.word-eq-num:focus {
  border-color: var(--primary-blue);
  border-style: solid;
  box-shadow: 0 0 0 3px rgba(74, 144, 217, 0.15);
}

.word-eq-num.eq-correct {
  border-color: var(--success-green);
  border-style: solid;
  background: rgba(103, 213, 117, 0.1);
  color: var(--success-green);
}

.word-eq-num.eq-wrong {
  border-color: var(--playful-pink);
  border-style: solid;
  background: rgba(239, 71, 111, 0.08);
  color: var(--playful-pink);
  animation: shake 0.4s ease-in-out;
}

.word-eq-op,
.word-eq-equals {
  font-family: 'Fredoka', sans-serif;
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--primary-blue);
}

.word-eq-question {
  font-family: 'Fredoka', sans-serif;
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text-muted);
}

.horizontal-equation.h-eq-done {
  padding: 6px 16px;
  opacity: 0.6;
  transform: scale(0.9);
}

.h-eq-instruction {
  margin-bottom: 8px;
  font-weight: 600;
  color: var(--primary-blue);
}

.h-eq-numbers {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 12px;
  flex-wrap: wrap;
}

.h-number-group {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.h-place-labels {
  font-family: 'Fredoka', sans-serif;
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--text-muted);
  letter-spacing: 4px;
  margin-bottom: 2px;
}

.h-number {
  font-family: 'Fredoka', sans-serif;
  font-size: 2rem;
  font-weight: 700;
  letter-spacing: 4px;
}

.h-top-num {
  color: var(--warm-orange);
}

.h-bottom-num {
  color: var(--cool-teal);
}

.h-operator {
  font-family: 'Fredoka', sans-serif;
  font-size: 1.8rem;
  font-weight: 700;
  color: var(--primary-blue);
  padding-bottom: 2px;
}

.h-equals {
  font-family: 'Fredoka', sans-serif;
  font-size: 1.8rem;
  font-weight: 700;
  color: var(--text-muted);
}

.h-question {
  font-family: 'Fredoka', sans-serif;
  font-size: 2rem;
  font-weight: 700;
  color: var(--playful-pink);
  animation: pulse 1.5s ease-in-out infinite;
}

/* ── Digit Input Cells ───────────────────────────────────── */
.digit-input {
  font-family: 'Fredoka', sans-serif;
  font-size: 1.5rem;
  font-weight: 700;
  text-align: center;
  width: 42px;
  height: 42px;
  padding: 0;
  border: 2.5px dashed rgba(74, 144, 217, 0.3);
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.6);
  color: var(--text-dark);
  outline: none;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast), background var(--transition-fast);
  caret-color: var(--primary-blue);
  -moz-appearance: textfield;
}

.digit-input::-webkit-outer-spin-button,
.digit-input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.digit-input:focus {
  border-color: var(--primary-blue);
  border-style: solid;
  box-shadow: 0 0 0 3px rgba(74, 144, 217, 0.15);
  background: rgba(255, 255, 255, 0.9);
}

.digit-input::placeholder {
  color: #CBD5E1;
  font-size: 1.2rem;
}

.top-digit-input { color: var(--warm-orange); }
.top-digit-input:focus { border-color: var(--warm-orange); box-shadow: 0 0 0 3px rgba(245, 166, 35, 0.15); }
.bottom-digit-input { color: var(--cool-teal); }
.bottom-digit-input:focus { border-color: var(--cool-teal); box-shadow: 0 0 0 3px rgba(80, 200, 198, 0.15); }

.digit-input.digit-correct {
  border-color: var(--success-green);
  border-style: solid;
  background: rgba(103, 213, 117, 0.1);
  color: var(--success-green);
}

.digit-input.digit-wrong {
  border-color: var(--playful-pink);
  border-style: solid;
  background: rgba(239, 71, 111, 0.08);
  color: var(--playful-pink);
  animation: shake 0.4s ease-in-out;
}

/* Locked digit (after correct placement) */
.digit-locked {
  font-family: 'Fredoka', sans-serif;
  font-size: 1.8rem;
  font-weight: 700;
  color: var(--text-dark);
  line-height: 1.3;
}

.top-number .digit-locked { color: var(--warm-orange); }
.bottom-number .digit-locked { color: var(--cool-teal); }

/* ── Problem Display ─────────────────────────────────────── */
.problem-display {
  background: var(--glass-bg);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1.5px solid var(--glass-border);
  border-radius: var(--radius-lg);
  padding: 16px 20px;
  box-shadow: 0 4px 20px var(--glass-shadow);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  min-width: 140px;
  font-family: 'Fredoka', sans-serif;
}

/* ── Column Table (grid paper style) ─────────────────────── */
.column-table {
  border-collapse: collapse;
  margin: 0 auto;
}

.column-table th,
.column-table td {
  text-align: center;
  vertical-align: middle;
  padding: 2px 4px;
  min-width: 42px;
}

.column-headers .col-label {
  font-family: 'Fredoka', sans-serif;
  font-size: 0.8rem;
  font-weight: 700;
  padding: 4px 6px;
  border-radius: 6px 6px 0 0;
  letter-spacing: 0.5px;
}

.col-label.col-th { color: var(--deep-purple); background: rgba(108, 92, 231, 0.1); }
.col-label.col-h  { color: var(--playful-pink); background: rgba(239, 71, 111, 0.1); }
.col-label.col-t  { color: var(--warm-orange); background: rgba(245, 166, 35, 0.1); }
.col-label.col-u  { color: var(--primary-blue); background: rgba(74, 144, 217, 0.1); }

.column-table tbody td.digit {
  font-size: 1.8rem;
  font-weight: 700;
  color: var(--text-dark);
  line-height: 1.3;
  border-left: 1.5px solid rgba(0, 0, 0, 0.08);
  border-right: 1.5px solid rgba(0, 0, 0, 0.08);
}

.row-label {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--primary-blue);
  min-width: 28px !important;
}

.row-label.operator {
  font-size: 1.6rem;
}

.row-label.answer-label {
  font-size: 1.4rem;
  color: var(--success-green);
}

.number-row.top-number td.digit {
  color: var(--warm-orange);
}

.number-row.bottom-number td.digit {
  color: var(--cool-teal);
}

.divider-row td {
  padding: 0;
}

.problem-divider {
  width: 100%;
  height: 3px;
  background: linear-gradient(90deg, var(--primary-blue), var(--deep-purple));
  border-radius: 2px;
  margin: 2px 0;
}

/* ── Answer Column Inputs ─────────────────────────────────── */
.answer-cell {
  padding: 2px 2px !important;
}

.answer-col-input {
  font-family: 'Fredoka', sans-serif;
  font-size: 1.5rem;
  font-weight: 700;
  text-align: center;
  width: 42px;
  height: 42px;
  padding: 0;
  border: 2.5px solid rgba(74, 144, 217, 0.25);
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.85);
  color: var(--success-green);
  outline: none;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
  caret-color: var(--primary-blue);
  -moz-appearance: textfield;
}

.answer-col-input::-webkit-outer-spin-button,
.answer-col-input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.answer-col-input:focus {
  border-color: var(--primary-blue);
  box-shadow: 0 0 0 3px rgba(74, 144, 217, 0.18), 0 2px 8px rgba(74, 144, 217, 0.12);
}

.answer-col-input::placeholder {
  color: #CBD5E1;
  font-weight: 400;
  font-size: 1.2rem;
}

.check-btn {
  margin-top: 6px;
  align-self: center;
}

/* ── Active Number Highlight (table rows) ─────────────────── */
.number-row.active-number td.digit {
  transition: color 0.3s ease, text-shadow 0.3s ease;
}

.top-number.active-number td.digit {
  color: var(--warm-orange);
  text-shadow: 0 0 8px rgba(245, 166, 35, 0.3);
}

.bottom-number.active-number td.digit {
  color: var(--cool-teal);
  text-shadow: 0 0 8px rgba(80, 200, 198, 0.3);
}

/* ── Place Value Houses ───────────────────────────────────── */
.houses-container {
  display: flex;
  justify-content: center;
  align-items: flex-end;
  gap: 14px;
  width: 100%;
  max-width: 680px;
  padding: 12px;
  flex-wrap: nowrap;
}

.house {
  flex: 1;
  min-width: 80px;
  max-width: 160px;
  display: flex;
  flex-direction: column;
  align-items: center;
  border-radius: 0 0 var(--radius-md) var(--radius-md);
  background: rgba(255, 255, 255, 0.55);
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: rgba(74, 144, 217, 0.15);
  user-select: none;
  -webkit-user-select: none;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1.5px solid rgba(255, 255, 255, 0.5);
  border-top: none;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.06);
  overflow: visible;
  transition: transform var(--transition-fast), box-shadow var(--transition-fast);
  position: relative;
}

.house:hover {
  transform: translateY(-3px);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.1);
}

/* Roof */
.house-roof {
  width: calc(100% + 20px);
  padding: 8px 10px;
  text-align: center;
  font-family: 'Fredoka', sans-serif;
  font-weight: 700;
  pointer-events: none;
  font-size: 0.85rem;
  color: var(--text-light);
  border-radius: var(--radius-md) var(--radius-md) 0 0;
  position: relative;
  letter-spacing: 0.3px;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.15);
  margin-top: -1px;
}

/* Roof peak triangle */
.house-roof::before {
  content: '';
  position: absolute;
  top: -12px;
  left: 50%;
  transform: translateX(-50%);
  width: 0;
  height: 0;
  border-left: 24px solid transparent;
  border-right: 24px solid transparent;
}

.thousands-roof {
  background: linear-gradient(135deg, var(--roof-thousands), #8B7CF7);
}
.thousands-roof::before {
  border-bottom: 14px solid var(--roof-thousands);
}

.hundreds-roof {
  background: linear-gradient(135deg, var(--roof-hundreds), #F76F8E);
}
.hundreds-roof::before {
  border-bottom: 14px solid var(--roof-hundreds);
}

.tens-roof {
  background: linear-gradient(135deg, var(--roof-tens), #F7BC4F);
}
.tens-roof::before {
  border-bottom: 14px solid var(--roof-tens);
}

.units-roof {
  background: linear-gradient(135deg, var(--roof-units), #6BA8E8);
}
.units-roof::before {
  border-bottom: 14px solid var(--roof-units);
}

/* Variant classes on house itself */
.thousands-house { order: 1; }
.hundreds-house  { order: 2; }
.tens-house      { order: 3; }
.units-house     { order: 4; }

/* ── Sticks Area ──────────────────────────────────────────── */
.sticks-area {
  width: 100%;
  min-height: 120px;
  padding: 14px 10px;
  display: flex;
  flex-wrap: wrap;
  align-content: flex-start;
  justify-content: center;
  gap: 6px;
  cursor: pointer;
  touch-action: manipulation;
  transition: background var(--transition-fast);
  position: relative;
}

.sticks-area:hover {
  background: rgba(74, 144, 217, 0.04);
}

/* ── Sticks ───────────────────────────────────────────────── */
.stick {
  width: 8px;
  height: 40px;
  border-radius: 4px;
  transition:
    transform var(--transition-fast),
    box-shadow var(--transition-fast),
    opacity var(--transition-fast);
  pointer-events: none;
  flex-shrink: 0;
  position: relative;
}

.stick:hover {
  transform: scaleY(1.1) translateY(-2px);
}

.stick.top-number {
  background: linear-gradient(180deg, #FFCA6E, var(--stick-top));
  box-shadow: 0 2px 6px rgba(245, 166, 35, 0.35);
}

.stick.bottom-number {
  background: linear-gradient(180deg, #7EDCDB, var(--stick-bottom));
  box-shadow: 0 2px 6px rgba(80, 200, 198, 0.35);
}

.stick.carried {
  background: linear-gradient(180deg, #90EE9C, var(--stick-carried));
  box-shadow:
    0 2px 6px rgba(103, 213, 117, 0.4),
    0 0 12px rgba(103, 213, 117, 0.35);
  animation: glow 1.8s ease-in-out infinite;
}

.stick.grouped {
  animation: pulse 0.8s ease-in-out infinite;
  box-shadow:
    0 0 10px rgba(74, 144, 217, 0.5),
    0 0 20px rgba(74, 144, 217, 0.25);
}

.stick-placeholder {
  width: 8px;
  height: 40px;
  border-radius: 4px;
  border: 2px dashed rgba(74, 144, 217, 0.35);
  background: rgba(74, 144, 217, 0.06);
  animation: wiggle 1.5s ease-in-out infinite;
  cursor: pointer;
  flex-shrink: 0;
}

/* ── Tally Crossbar (every 5th stick) ─────────────────────── */
.stick.tally-fifth {
  position: relative;
}

.stick.tally-fifth::after {
  content: '';
  position: absolute;
  top: 40%;
  left: -12px;
  width: 32px;
  height: 3px;
  background: inherit;
  border-radius: 2px;
  transform: rotate(-25deg);
  opacity: 0.7;
}

/* ── Sticks Separator (+ between top and bottom) ──────────── */
.sticks-separator {
  width: 100%;
  text-align: center;
  font-family: 'Fredoka', sans-serif;
  font-size: 1.2rem;
  font-weight: 700;
  pointer-events: none;
  color: var(--primary-blue);
  padding: 2px 0;
  margin: 4px 0;
  border-top: 2px dashed rgba(74, 144, 217, 0.2);
  flex-basis: 100%;
}

/* ── Bundle Circle (oval around 10 sticks) ────────────────── */
.bundle-circle {
  position: absolute;
  inset: 4px;
  border: 3px solid var(--success-green);
  border-radius: 50%;
  animation: circleAppear 0.6s var(--ease-bounce) forwards;
  pointer-events: none;
  z-index: 5;
}

.bundle-circle.circle-shrink {
  animation: circleShrink 0.4s ease-in forwards;
}

@keyframes circleAppear {
  0% { transform: scale(0.3); opacity: 0; border-width: 0; }
  50% { transform: scale(1.1); opacity: 1; border-width: 4px; }
  100% { transform: scale(1); opacity: 1; border-width: 3px; }
}

@keyframes circleShrink {
  0% { transform: scale(1); opacity: 1; }
  100% { transform: scale(0.1) translateY(-40px); opacity: 0; }
}

.stick.being-bundled {
  animation: pulse 0.4s ease-in-out infinite;
  box-shadow: 0 0 8px var(--success-green);
}

/* ── Carry Indicator (+1 at top of column) ────────────────── */
.carry-indicator {
  width: 100%;
  text-align: center;
  font-family: 'Fredoka', sans-serif;
  font-size: 0.75rem;
  font-weight: 700;
  pointer-events: none;
  color: var(--success-green);
  background: rgba(103, 213, 117, 0.15);
  border-radius: 6px;
  padding: 2px 4px;
  margin: 0 8px 4px;
  animation: popIn 0.4s var(--ease-bounce);
  text-shadow: 0 0 6px rgba(103, 213, 117, 0.3);
}

/* ── Carry Animate (stick flying in) ──────────────────────── */
.stick.carry-animate {
  animation: carryOver 0.5s var(--ease-bounce) forwards;
}

@keyframes carryOver {
  0% { transform: scale(0) translateY(60px); opacity: 0; }
  60% { transform: scale(1.3) translateY(-5px); opacity: 1; }
  100% { transform: scale(1) translateY(0); opacity: 1; }
}

.counter-badge {
  position: absolute;
  top: -10px;
  right: -10px;
  min-width: 24px;
  height: 24px;
  pointer-events: none;
  padding: 0 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'Fredoka', sans-serif;
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--text-light);
  background: var(--primary-blue);
  border-radius: 12px;
  box-shadow: 0 2px 8px rgba(74, 144, 217, 0.4);
  z-index: 2;
}

/* ── Modals ───────────────────────────────────────────────── */
.modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  padding: 24px;
  opacity: 1;
  transition: opacity var(--transition-med);
}

.modal-content {
  background: var(--glass-bg);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1.5px solid var(--glass-border);
  border-radius: var(--radius-xl);
  padding: 36px 32px;
  max-width: 440px;
  width: 100%;
  box-shadow:
    0 20px 60px rgba(31, 38, 135, 0.2),
    inset 0 1px 0 rgba(255, 255, 255, 0.6);
  animation: popIn 0.4s var(--ease-bounce);
  text-align: center;
}

.modal-content h2 {
  font-family: 'Fredoka', sans-serif;
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: 12px;
  color: var(--text-dark);
}

.modal-content p {
  font-size: 1rem;
  color: var(--text-muted);
  margin-bottom: 20px;
  line-height: 1.6;
}

.modal-content .btn {
  margin: 6px;
}

/* Instructions Modal */
#instructions-modal .modal-content {
  max-width: 480px;
  text-align: left;
}

#instructions-modal .modal-content h2 {
  text-align: center;
}

/* Celebration Modal */
#celebration-modal .modal-content {
  overflow: hidden;
  position: relative;
}

/* ── Celebration Content ──────────────────────────────────── */
.celebration-content {
  text-align: center;
  position: relative;
  z-index: 1;
}

.celebration-content h2 {
  font-family: 'Fredoka', sans-serif;
  font-size: 2rem;
  font-weight: 700;
  margin-bottom: 8px;
}

.bounce-text {
  display: inline-block;
  animation: bounce 0.6s var(--ease-bounce);
  font-family: 'Fredoka', sans-serif;
  font-size: 2rem;
  font-weight: 700;
  background: linear-gradient(135deg, var(--warm-orange), var(--playful-pink), var(--deep-purple));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.confetti-piece {
  position: absolute;
  width: 10px;
  height: 10px;
  border-radius: 2px;
  opacity: 0;
  animation: confetti 1.8s ease-out forwards;
  pointer-events: none;
}

.confetti-piece:nth-child(odd) {
  border-radius: 50%;
}

.confetti-piece:nth-child(1)  { left: 10%; background: var(--warm-orange); animation-delay: 0s; }
.confetti-piece:nth-child(2)  { left: 25%; background: var(--playful-pink); animation-delay: 0.1s; }
.confetti-piece:nth-child(3)  { left: 40%; background: var(--cool-teal); animation-delay: 0.05s; }
.confetti-piece:nth-child(4)  { left: 55%; background: var(--deep-purple); animation-delay: 0.15s; }
.confetti-piece:nth-child(5)  { left: 70%; background: var(--success-green); animation-delay: 0.08s; }
.confetti-piece:nth-child(6)  { left: 85%; background: var(--primary-blue); animation-delay: 0.12s; }
.confetti-piece:nth-child(7)  { left: 18%; background: var(--playful-pink); animation-delay: 0.2s; }
.confetti-piece:nth-child(8)  { left: 50%; background: var(--warm-orange); animation-delay: 0.18s; }
.confetti-piece:nth-child(9)  { left: 65%; background: var(--cool-teal); animation-delay: 0.25s; }
.confetti-piece:nth-child(10) { left: 80%; background: var(--deep-purple); animation-delay: 0.22s; }

/* ── Tutorial Screen ──────────────────────────────────────── */
#tutorial-screen {
  justify-content: flex-start;
  padding-top: 32px;
  gap: 20px;
}

.tutorial-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
  width: 100%;
  max-width: 600px;
}

.speech-bubble {
  position: relative;
  background: var(--glass-bg);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1.5px solid var(--glass-border);
  border-radius: var(--radius-lg);
  padding: 22px 26px;
  box-shadow: 0 4px 20px var(--glass-shadow);
  font-size: 1.05rem;
  color: var(--text-dark);
  line-height: 1.6;
  max-width: 420px;
  width: 100%;
  animation: popIn 0.4s var(--ease-bounce);
}

.speech-bubble::after {
  content: '';
  position: absolute;
  bottom: -14px;
  left: 40px;
  width: 0;
  height: 0;
  border-left: 14px solid transparent;
  border-right: 14px solid transparent;
  border-top: 16px solid var(--glass-bg);
  filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.06));
}

.highlight-zone {
  position: relative;
  border-radius: var(--radius-md);
  box-shadow: 0 0 0 4px rgba(74, 144, 217, 0.4);
  animation: glow 1.5s ease-in-out infinite;
}

.tutorial-step-indicator {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 12px;
}

.tutorial-step-indicator .dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: rgba(74, 144, 217, 0.25);
  transition: background var(--transition-fast), transform var(--transition-fast);
}

.tutorial-step-indicator .dot.active {
  background: var(--primary-blue);
  transform: scale(1.3);
  box-shadow: 0 0 8px rgba(74, 144, 217, 0.4);
}

.tutorial-step-indicator .dot.completed {
  background: var(--success-green);
}

/* ── Progress Screen ──────────────────────────────────────── */
#progress-screen {
  justify-content: flex-start;
  padding-top: 32px;
  gap: 24px;
}

#progress-screen h2 {
  font-family: 'Fredoka', sans-serif;
  font-size: 1.8rem;
  font-weight: 700;
  color: var(--text-dark);
}

.progress-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 28px;
  width: 100%;
  max-width: 600px;
}

/* Stats Grid */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 14px;
  width: 100%;
}

.stat-card {
  background: var(--glass-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1.5px solid var(--glass-border);
  border-radius: var(--radius-md);
  padding: 18px 14px;
  text-align: center;
  box-shadow: 0 3px 12px var(--glass-shadow);
  transition: transform var(--transition-fast);
}

.stat-card:hover {
  transform: translateY(-3px);
}

.stat-card .stat-value {
  font-family: 'Fredoka', sans-serif;
  font-size: 1.8rem;
  font-weight: 700;
  color: var(--primary-blue);
  line-height: 1.2;
}

.stat-card .stat-label {
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-top: 4px;
}

/* Progress Bar */
.progress-bar-container {
  width: 100%;
  height: 16px;
  background: rgba(0, 0, 0, 0.07);
  border-radius: 8px;
  overflow: hidden;
  position: relative;
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.06);
}

.progress-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--primary-blue), var(--cool-teal), var(--success-green));
  border-radius: 8px;
  transition: width 0.8s var(--ease-bounce);
  position: relative;
  min-width: 0%;
}

.progress-bar-fill::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 50%;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.35), transparent);
  border-radius: 8px 8px 0 0;
}

/* Badges Grid */
.badges-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
  width: 100%;
}

.badge-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 18px 10px;
  border-radius: var(--radius-md);
  background: var(--glass-bg);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1.5px solid var(--glass-border);
  box-shadow: 0 3px 12px var(--glass-shadow);
  text-align: center;
  transition: transform var(--transition-fast), box-shadow var(--transition-fast);
  position: relative;
  overflow: hidden;
}

.badge-item .badge-icon {
  font-size: 2rem;
  line-height: 1;
}

.badge-item .badge-name {
  font-family: 'Fredoka', sans-serif;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-dark);
}

.badge-item.unlocked {
  border-color: rgba(245, 166, 35, 0.4);
}

.badge-item.unlocked::before {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 60%;
  height: 100%;
  background: linear-gradient(
    90deg,
    transparent,
    rgba(255, 255, 255, 0.45),
    transparent
  );
  animation: shine 3s ease-in-out infinite;
}

.badge-item.unlocked:hover {
  transform: translateY(-4px) scale(1.03);
  box-shadow: 0 8px 24px rgba(245, 166, 35, 0.25);
}

.badge-item.locked {
  opacity: 0.5;
  filter: grayscale(0.8);
}

.badge-item.locked .badge-icon::after {
  content: '🔒';
  display: block;
  font-size: 0.9rem;
  margin-top: 2px;
}

/* ── Settings Screen ──────────────────────────────────────── */
#settings-screen {
  justify-content: flex-start;
  padding-top: 32px;
  gap: 24px;
}

#settings-screen h2 {
  font-family: 'Fredoka', sans-serif;
  font-size: 1.8rem;
  font-weight: 700;
  color: var(--text-dark);
}

.settings-list {
  width: 100%;
  max-width: 480px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.setting-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 22px;
  background: var(--glass-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--glass-border);
  font-family: 'Nunito', sans-serif;
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-dark);
  min-height: var(--touch-min);
  transition: background var(--transition-fast);
}

.setting-item:first-child {
  border-radius: var(--radius-md) var(--radius-md) 0 0;
}

.setting-item:last-child {
  border-radius: 0 0 var(--radius-md) var(--radius-md);
}

.setting-item:only-child {
  border-radius: var(--radius-md);
}

.setting-item:hover {
  background: rgba(255, 255, 255, 0.85);
}

/* Toggle Switch */
.toggle-switch {
  position: relative;
  width: 52px;
  height: 30px;
  flex-shrink: 0;
}

.toggle-switch input {
  opacity: 0;
  width: 0;
  height: 0;
  position: absolute;
}

.toggle-switch .slider {
  position: absolute;
  inset: 0;
  background: #CBD5E1;
  border-radius: 15px;
  cursor: pointer;
  transition: background var(--transition-fast);
}

.toggle-switch .slider::before {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 24px;
  height: 24px;
  background: white;
  border-radius: 50%;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
  transition: transform var(--transition-fast);
}

.toggle-switch input:checked + .slider {
  background: var(--success-green);
}

.toggle-switch input:checked + .slider::before {
  transform: translateX(22px);
}

.toggle-switch input:focus-visible + .slider {
  outline: 3px solid var(--primary-blue);
  outline-offset: 3px;
}

/* ── Feedback ─────────────────────────────────────────────── */
.feedback-correct {
  animation: popIn 0.35s var(--ease-bounce);
  color: var(--success-green);
  font-family: 'Fredoka', sans-serif;
  font-size: 1.2rem;
  font-weight: 700;
}

.feedback-incorrect {
  animation: wiggle 0.4s ease-in-out;
  color: var(--playful-pink);
  font-family: 'Fredoka', sans-serif;
  font-size: 1.2rem;
  font-weight: 700;
}

/* Colour flash on the answer row */
.answer-row.feedback-correct .answer-col-input {
  border-color: var(--success-green);
  box-shadow: 0 0 0 3px rgba(103, 213, 117, 0.25);
  background: rgba(103, 213, 117, 0.08);
}

.answer-row.feedback-incorrect .answer-col-input {
  border-color: var(--playful-pink);
  box-shadow: 0 0 0 3px rgba(239, 71, 111, 0.2);
  background: rgba(239, 71, 111, 0.06);
}

/* ── Hint Text ────────────────────────────────────────────── */
.hint-text {
  font-size: 0.82rem;
  color: var(--text-muted);
  font-style: italic;
  text-align: center;
  padding: 4px 10px;
  animation: wiggle 2s ease-in-out infinite;
}

/* ── Timer Bar ────────────────────────────────────────────── */
.timer-bar {
  width: 100%;
  max-width: 700px;
  height: 8px;
  background: rgba(0, 0, 0, 0.07);
  border-radius: 4px;
  overflow: hidden;
  flex-shrink: 0;
}

.timer-bar .timer-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--success-green), var(--warm-orange), var(--playful-pink));
  border-radius: 4px;
  transition: width 1s linear;
}

/* ── Streak Counter ───────────────────────────────────────── */
.streak-counter {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: 'Fredoka', sans-serif;
  font-size: 1rem;
  font-weight: 700;
  color: var(--warm-orange);
  padding: 4px 14px;
  background: rgba(245, 166, 35, 0.12);
  border-radius: 20px;
  border: 1.5px solid rgba(245, 166, 35, 0.25);
}

.streak-counter .streak-icon {
  font-size: 1.1rem;
}

/* ── Keyframe Animations ──────────────────────────────────── */

/* Float — gentle up/down bobbing */
@keyframes float {
  0%, 100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-10px);
  }
}

/* Pop In — scale with overshoot */
@keyframes popIn {
  0% {
    opacity: 0;
    transform: scale(0.5);
  }
  70% {
    transform: scale(1.08);
  }
  100% {
    opacity: 1;
    transform: scale(1);
  }
}

/* Pulse — breathing scale */
@keyframes pulse {
  0%, 100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.15);
  }
}

/* Bounce — playful vertical bounce */
@keyframes bounce {
  0%   { transform: translateY(0); }
  25%  { transform: translateY(-16px); }
  50%  { transform: translateY(0); }
  75%  { transform: translateY(-8px); }
  100% { transform: translateY(0); }
}

/* Slide In from Right */
@keyframes slideInFromRight {
  0% {
    opacity: 0;
    transform: translateX(60px);
  }
  100% {
    opacity: 1;
    transform: translateX(0);
  }
}

/* Slide Out to Left */
@keyframes slideOutToLeft {
  0% {
    opacity: 1;
    transform: translateX(0);
  }
  100% {
    opacity: 0;
    transform: translateX(-60px);
  }
}

/* Confetti — falling pieces */
@keyframes confetti {
  0% {
    opacity: 1;
    transform: translateY(-20px) rotate(0deg) scale(1);
  }
  100% {
    opacity: 0;
    transform: translateY(350px) rotate(720deg) scale(0.4);
  }
}

/* Shine — sweep highlight across badges */
@keyframes shine {
  0%   { left: -100%; }
  50%  { left: 150%; }
  100% { left: 150%; }
}

/* Carry Over — stick flying between houses */
@keyframes carryOver {
  0% {
    transform: translateX(0) translateY(0) scale(1);
    opacity: 1;
  }
  40% {
    transform: translateX(-40px) translateY(-60px) scale(1.3);
    opacity: 1;
  }
  100% {
    transform: translateX(-120px) translateY(0) scale(1);
    opacity: 1;
  }
}

/* Wiggle — attention-seeking side-to-side */
@keyframes wiggle {
  0%, 100% { transform: rotate(0deg); }
  20%      { transform: rotate(-3deg); }
  40%      { transform: rotate(3deg); }
  60%      { transform: rotate(-2deg); }
  80%      { transform: rotate(2deg); }
}

/* Glow — pulsing glow ring */
@keyframes glow {
  0%, 100% {
    box-shadow:
      0 0 6px rgba(74, 144, 217, 0.3),
      0 0 12px rgba(74, 144, 217, 0.15);
  }
  50% {
    box-shadow:
      0 0 14px rgba(74, 144, 217, 0.5),
      0 0 28px rgba(74, 144, 217, 0.25);
  }
}

/* Floating Shapes — background decoration drift */
@keyframes floatingShapes {
  0% {
    transform: translate(0, 0) rotate(0deg) scale(1);
  }
  33% {
    transform: translate(30px, -20px) rotate(5deg) scale(1.05);
  }
  66% {
    transform: translate(-20px, 15px) rotate(-3deg) scale(0.97);
  }
  100% {
    transform: translate(10px, -10px) rotate(2deg) scale(1.02);
  }
}

/* ── Responsive: Tablet (≤ 900px) ─────────────────────────── */
@media (max-width: 900px) {
  .mode-grid {
    gap: 14px;
  }

  .badges-grid {
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
  }

  .house {
    min-width: 70px;
  }
}

/* ── Responsive: Mobile (≤ 768px) ─────────────────────────── */
@media (max-width: 768px) {
  html {
    font-size: 15px;
  }

  .screen {
    padding: 16px;
  }

  /* Houses stack vertically on small screens */
  .houses-container {
    flex-direction: column;
    align-items: center;
    gap: 16px;
  }

  .house {
    width: 100%;
    max-width: 320px;
    min-width: unset;
  }

  .house-roof {
    width: calc(100% + 16px);
  }

  .sticks-area {
    min-height: 80px;
    flex-direction: row;
    flex-wrap: wrap;
  }

  /* Mode grid goes to single column */
  .mode-grid {
    grid-template-columns: 1fr;
    max-width: 340px;
  }

  .mode-card {
    padding: 20px 16px;
  }

  /* Stats grid remains 2-col but tighter */
  .stats-grid {
    gap: 10px;
  }

  /* Badges go 2-col on mobile */
  .badges-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  /* Top bar adjusts */
  .top-bar {
    padding: 8px 12px;
    border-radius: var(--radius-lg);
    gap: 6px;
  }

  .top-bar .score,
  .top-bar .level {
    font-size: 0.82rem;
  }

  /* Landing */
  #landing-screen .glass-panel {
    padding: 28px 22px;
  }

  #landing-screen h1 {
    font-size: 1.7rem;
  }

  .character-img {
    width: 140px;
  }

  /* Problem display */
  .problem-display {
    padding: 16px 20px;
  }

  .digit {
    font-size: 1.5rem;
    min-width: 24px;
  }

  .operator {
    font-size: 1.3rem;
  }

  /* Modal */
  .modal-content {
    padding: 28px 22px;
    border-radius: var(--radius-lg);
  }

  /* Speech bubble */
  .speech-bubble {
    padding: 18px 20px;
    font-size: 0.95rem;
  }
}

/* ── Responsive: Small Mobile (≤ 480px) ───────────────────── */
@media (max-width: 480px) {
  html {
    font-size: 14px;
  }

  .screen {
    padding: 12px;
  }

  #landing-screen h1 {
    font-size: 1.45rem;
  }

  .character-img {
    width: 120px;
  }

  .glass-panel {
    padding: 20px 16px;
    border-radius: var(--radius-md);
  }

  .top-bar {
    flex-wrap: wrap;
    justify-content: center;
  }

  .star {
    font-size: 1.1rem;
  }

  .badge-item {
    padding: 14px 8px;
  }

  .badge-item .badge-icon {
    font-size: 1.6rem;
  }

  .stat-card .stat-value {
    font-size: 1.4rem;
  }

  .answer-col-input {
    width: 36px;
    height: 36px;
    font-size: 1.2rem;
  }
}

/* ── Accessibility: Reduced Motion ────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ── Accessibility: Focus Styles ──────────────────────────── */
:focus-visible {
  outline: 3px solid var(--primary-blue);
  outline-offset: 3px;
}

/* ── Accessibility: High Contrast ─────────────────────────── */
@media (prefers-contrast: high) {
  :root {
    --glass-bg: rgba(255, 255, 255, 0.92);
    --glass-border: rgba(0, 0, 0, 0.3);
    --text-muted: #4A4A4A;
  }

  .btn {
    border: 2px solid currentColor;
  }
}

/* ── Screen Header & Title ────────────────────────────────── */
.screen-header {
  display: flex;
  align-items: center;
  gap: 16px;
  width: 100%;
  max-width: 700px;
  padding: 10px 0;
  flex-shrink: 0;
}

.screen-title {
  font-family: 'Fredoka', sans-serif;
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text-dark);
  flex: 1;
}

/* ── Landing Panel ────────────────────────────────────────── */
.landing-panel {
  max-width: 420px;
  width: 92%;
  padding: 2.5rem 2rem;
  animation: float 6s ease-in-out infinite;
}

/* ── Button Variants ──────────────────────────────────────── */
.back-btn {
  background: rgba(255, 255, 255, 0.5);
  color: var(--text-dark);
  font-size: 0.85rem;
  min-width: auto;
  padding: 8px 14px;
  border: 1.5px solid rgba(255, 255, 255, 0.6);
}

.back-btn:hover {
  background: rgba(255, 255, 255, 0.75);
  transform: translateX(-2px);
}

.accent-btn {
  background: linear-gradient(135deg, var(--warm-orange), #FFCA6E);
  color: var(--text-dark);
}

.accent-btn:hover {
  box-shadow: 0 6px 20px rgba(245, 166, 35, 0.4);
}

.ghost-btn {
  background: transparent;
  color: var(--text-muted);
  border: 2px solid rgba(45, 49, 66, 0.15);
}

.ghost-btn:hover {
  background: rgba(255, 255, 255, 0.4);
  border-color: rgba(45, 49, 66, 0.3);
  color: var(--text-dark);
}

.sound-btn {
  background: rgba(255, 255, 255, 0.4);
  font-size: 1.2rem;
  padding: 6px 10px;
  min-width: var(--touch-min);
  min-height: var(--touch-min);
  border: none;
}

/* ── Bundle Button ────────────────────────────────────────── */
.bundle-btn {
  margin: 8px auto;
  background: linear-gradient(135deg, var(--success-green), #4AE85E);
  color: white;
  font-weight: 700;
  padding: 10px 16px;
  border-radius: var(--radius-md);
  animation: pulse 1.2s ease-in-out infinite;
  min-height: var(--touch-min);
  font-size: 0.85rem;
  box-shadow: 0 4px 12px rgba(103, 213, 117, 0.4);
  width: calc(100% - 16px);
}

.bundle-btn:hover {
  transform: scale(1.05);
  box-shadow: 0 6px 18px rgba(103, 213, 117, 0.5);
}

/* ── Top Bar Center & Right ───────────────────────────────── */
.top-bar-center {
  display: flex;
  align-items: center;
  gap: 14px;
  flex: 1;
  justify-content: center;
  flex-wrap: wrap;
}

.top-bar-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.score-display,
.level-display {
  font-family: 'Fredoka', sans-serif;
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--text-dark);
  white-space: nowrap;
}

/* ── Active Number Highlight ──────────────────────────────── */
.active-number .digit {
  color: var(--primary-blue);
  text-shadow: 0 0 8px rgba(74, 144, 217, 0.3);
  transition: color 0.3s ease, text-shadow 0.3s ease;
}

.top-number.active-number .digit {
  color: var(--warm-orange);
  text-shadow: 0 0 8px rgba(245, 166, 35, 0.3);
}

.bottom-number.active-number .digit {
  color: var(--cool-teal);
  text-shadow: 0 0 8px rgba(80, 200, 198, 0.3);
}

/* ── Inline Color Labels ──────────────────────────────────── */
.top-color {
  color: var(--warm-orange);
  font-weight: 700;
}

.bottom-color {
  color: var(--cool-teal);
  font-weight: 700;
}

/* ── Placement Controls ───────────────────────────────────── */
.placement-controls {
  display: flex;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
  width: 100%;
  max-width: 700px;
  padding: 0 12px;
}

/* ── Timer Bar ────────────────────────────────────────────── */
.timer-bar {
  width: 100%;
  max-width: 700px;
  height: 8px;
  background: rgba(255, 255, 255, 0.35);
  border-radius: 4px;
  overflow: hidden;
  flex-shrink: 0;
}

.timer-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--success-green), var(--primary-blue));
  border-radius: 4px;
  transition: width 1s linear;
}

.timer-bar-fill.timer-danger {
  background: linear-gradient(90deg, var(--playful-pink), #FF6B6B);
  animation: pulse 0.5s ease-in-out infinite;
}

/* ── Story Progress ───────────────────────────────────────── */
.story-progress {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  max-width: 700px;
  padding: 8px 16px;
  background: var(--glass-bg);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-radius: var(--radius-lg);
  border: 1px solid var(--glass-border);
  flex-shrink: 0;
}

.story-house-visual {
  font-size: 2rem;
  line-height: 1;
}

.story-complete-visual {
  font-size: 4rem;
  margin: 16px 0;
  animation: bounce 1.5s ease-in-out infinite;
}

/* ── Shake Animation ──────────────────────────────────────── */
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-6px); }
  40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(4px); }
}

.shake,
.answer-row.shake .answer-col-input {
  animation: shake 0.4s ease-in-out;
}

/* ── Tutorial ─────────────────────────────────────────────── */
.tutorial-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  width: 100%;
  max-width: 600px;
  padding: 20px;
}

.tutorial-character {
  width: 120px;
}

.tutorial-character .character-img {
  width: 120px;
}

.tutorial-game-area {
  width: 100%;
  min-height: 100px;
  display: flex;
  justify-content: center;
  gap: 16px;
}

.tutorial-nav {
  display: flex;
  justify-content: center;
  gap: 12px;
}

.step-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: rgba(74, 144, 217, 0.25);
  margin: 0 3px;
  transition: all 0.3s ease;
}

.step-dot.active {
  background: var(--primary-blue);
  transform: scale(1.3);
  box-shadow: 0 0 8px rgba(74, 144, 217, 0.5);
}

.step-dot.completed {
  background: var(--success-green);
}

/* ── Settings ─────────────────────────────────────────────── */
.setting-label {
  font-family: 'Fredoka', sans-serif;
  font-weight: 600;
  font-size: 1rem;
  color: var(--text-dark);
  flex: 1;
}

.toggle-slider {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background: #CBD5E1;
  border-radius: 24px;
  transition: background 0.3s ease;
}

.toggle-slider::before {
  content: '';
  position: absolute;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: white;
  top: 2px;
  left: 2px;
  transition: transform 0.3s ease;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.15);
}

.toggle-switch input:checked + .toggle-slider {
  background: var(--success-green);
}

.toggle-switch input:checked + .toggle-slider::before {
  transform: translateX(24px);
}

.section-title {
  font-family: 'Fredoka', sans-serif;
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--text-dark);
  margin: 20px 0 10px;
  width: 100%;
  max-width: 600px;
}

/* ── Button Group Horizontal ──────────────────────────────── */
.button-group.horizontal {
  flex-direction: row;
  justify-content: center;
  gap: 12px;
}

/* ── Free Play ────────────────────────────────────────────── */
.freeplay-info {
  padding: 20px 24px;
  max-width: 400px;
  width: 100%;
}

.freeplay-number-display {
  font-family: 'Fredoka', sans-serif;
  font-size: 3rem;
  font-weight: 700;
  color: var(--primary-blue);
  margin: 12px 0;
  text-shadow: 0 2px 8px rgba(74, 144, 217, 0.2);
}

/* ── Large Text Mode ──────────────────────────────────────── */
body.large-text {
  font-size: 20px;
}

body.large-text .digit {
  font-size: 2.4rem;
}

body.large-text .btn {
  font-size: 1.4rem;
  padding: 14px 28px;
}

body.large-text .answer-col-input {
  font-size: 1.6rem;
  width: 50px;
  height: 50px;
}

body.large-text .house-roof {
  font-size: 1.1rem;
}

body.large-text .hint-text {
  font-size: 1rem;
}

/* ── Print (hide decorative elements) ─────────────────────── */
@media print {
  body::before,
  body::after {
    display: none;
  }

  .modal {
    display: none;
  }
}
