:root {
  --bg: #fff8f0;
  --surface: #ffffff;
  --primary: #ff6b6b;
  --primary-dark: #ee5a5a;
  --secondary: #4ecdc4;
  --accent: #ffe66d;
  --purple: #a29bfe;
  --text: #2d3436;
  --text-muted: #636e72;
  --border: #dfe6e9;
  --shadow: 0 8px 24px rgba(45, 52, 54, 0.12);
  --radius: 20px;
  --font-display: "ZCOOL KuaiLe", "Noto Sans SC", sans-serif;
  --font-body: "Noto Sans SC", system-ui, sans-serif;
}

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

html {
  scroll-behavior: smooth;
}

body.body-locked {
  overflow: hidden;
}

body {
  margin: 0;
  font-family: var(--font-body);
  font-size: 18px;
  color: var(--text);
  background: var(--bg);
  background-image:
    radial-gradient(circle at 10% 20%, rgba(255, 230, 109, 0.4) 0%, transparent 40%),
    radial-gradient(circle at 90% 80%, rgba(78, 205, 196, 0.25) 0%, transparent 40%);
  min-height: 100vh;
}

/* Auth gate */
.auth-gate {
  position: fixed;
  inset: 0;
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: linear-gradient(160deg, #fff8f0 0%, #ffe0e0 50%, #e8f8f5 100%);
}

.auth-gate.hidden {
  display: none;
}

.auth-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border-radius: var(--radius);
  padding: 36px 32px;
  box-shadow: var(--shadow);
  text-align: center;
}

.auth-card.shake {
  animation: shake 0.45s;
}

.auth-icon {
  font-size: 3.5rem;
  margin-bottom: 8px;
}

.auth-card h2 {
  font-family: var(--font-display);
  font-size: 1.8rem;
  color: var(--primary);
  margin: 0 0 8px;
}

.auth-hint {
  color: var(--text-muted);
  font-size: 15px;
  margin: 0 0 24px;
  line-height: 1.5;
}

.auth-label {
  display: block;
  text-align: left;
  font-size: 14px;
  font-weight: 700;
  margin-bottom: 8px;
  color: var(--text-muted);
}

.auth-input {
  width: 100%;
  font-family: var(--font-display);
  font-size: 1.8rem;
  letter-spacing: 0.3em;
  text-align: center;
  padding: 14px 16px;
  border: 3px solid var(--border);
  border-radius: 16px;
  margin-bottom: 16px;
  outline: none;
  transition: border-color 0.2s;
}

.auth-input:focus {
  border-color: var(--primary);
}

.auth-remember {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 14px;
  color: var(--text-muted);
  margin-bottom: 20px;
  cursor: pointer;
}

.auth-remember input {
  width: 18px;
  height: 18px;
  accent-color: var(--primary);
}

.auth-submit {
  width: 100%;
}

.auth-error {
  margin: 16px 0 0;
  font-size: 14px;
  color: #c0392b;
  min-height: 1.2em;
  opacity: 0;
}

.auth-error.visible {
  opacity: 1;
}

.app--locked {
  visibility: hidden;
  pointer-events: none;
  height: 0;
  overflow: hidden;
}

.lock-btn {
  background: rgba(255, 255, 255, 0.25);
  border: none;
  font-size: 1.2rem;
  width: 44px;
  height: 44px;
  border-radius: 12px;
  cursor: pointer;
  flex-shrink: 0;
}

.lock-btn:hover {
  background: rgba(255, 255, 255, 0.4);
}

.app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Header */
.header {
  background: linear-gradient(135deg, var(--primary), #ff8e53);
  color: #fff;
  box-shadow: var(--shadow);
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-inner {
  max-width: 1100px;
  margin: 0 auto;
  padding: 12px 20px;
  display: flex;
  align-items: center;
  gap: 16px;
}

.menu-btn {
  display: none;
  background: rgba(255, 255, 255, 0.25);
  border: none;
  color: #fff;
  font-size: 24px;
  width: 44px;
  height: 44px;
  border-radius: 12px;
  cursor: pointer;
}

.logo {
  font-family: var(--font-display);
  font-size: 1.5rem;
  font-weight: 400;
  margin: 0;
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
}

.stars-bar {
  background: rgba(255, 255, 255, 0.25);
  padding: 8px 16px;
  border-radius: 999px;
  font-family: var(--font-display);
  font-size: 1.2rem;
  display: flex;
  align-items: center;
  gap: 6px;
}

/* Layout */
.layout {
  flex: 1;
  display: flex;
  max-width: 1100px;
  margin: 0 auto;
  width: 100%;
  padding: 20px;
  gap: 24px;
}

.sidebar {
  width: 240px;
  flex-shrink: 0;
  background: var(--surface);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  height: fit-content;
  position: sticky;
  top: 88px;
}

.sidebar-title {
  font-family: var(--font-display);
  color: var(--primary);
  margin: 0 0 12px;
  font-size: 1.1rem;
}

.nav {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border: none;
  background: transparent;
  border-radius: 14px;
  font-family: var(--font-body);
  font-size: 15px;
  color: var(--text);
  cursor: pointer;
  text-align: left;
  transition: background 0.2s, transform 0.15s;
}

.nav-item:hover {
  background: #fff0f0;
}

.nav-item.active {
  background: linear-gradient(135deg, #ffe0e0, #fff5e6);
  color: var(--primary-dark);
  font-weight: 700;
}

.nav-item .emoji {
  font-size: 1.4rem;
}

.nav-item.done::after {
  content: "✓";
  margin-left: auto;
  color: var(--secondary);
  font-weight: bold;
}

.main {
  flex: 1;
  min-width: 0;
}

.page {
  display: none;
  animation: fadeIn 0.35s ease;
}

.page.active {
  display: block;
}

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

/* Home */
.hero {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 40px 32px;
  text-align: center;
  box-shadow: var(--shadow);
  margin-bottom: 24px;
}

.hero-mascot {
  font-size: 5rem;
  animation: bounce 2s ease infinite;
}

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

.hero h2 {
  font-family: var(--font-display);
  font-size: 2rem;
  color: var(--primary);
  margin: 8px 0;
}

.hero p {
  color: var(--text-muted);
  max-width: 420px;
  margin: 0 auto 24px;
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 16px;
}

.topic-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 20px;
  border: 3px solid transparent;
  cursor: pointer;
  transition: transform 0.2s, border-color 0.2s, box-shadow 0.2s;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.06);
  text-align: center;
}

.topic-card:hover {
  transform: translateY(-4px);
  border-color: var(--accent);
  box-shadow: var(--shadow);
}

.topic-card .icon {
  font-size: 2.5rem;
  display: block;
  margin-bottom: 8px;
}

.topic-card h3 {
  font-family: var(--font-display);
  font-size: 1.1rem;
  margin: 0 0 4px;
  color: var(--text);
}

.topic-card p {
  font-size: 13px;
  color: var(--text-muted);
  margin: 0;
}

/* Lesson */
.lesson-header {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 24px 28px;
  margin-bottom: 20px;
  box-shadow: var(--shadow);
  border-left: 6px solid var(--primary);
}

.lesson-header h2 {
  font-family: var(--font-display);
  font-size: 1.8rem;
  margin: 0 0 8px;
  color: var(--primary);
}

.lesson-header p {
  margin: 0;
  color: var(--text-muted);
  line-height: 1.6;
}

.panel {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 24px 28px;
  margin-bottom: 20px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.06);
}

.panel h3 {
  font-family: var(--font-display);
  font-size: 1.3rem;
  margin: 0 0 16px;
  color: var(--secondary);
}

/* Buttons */
.btn {
  font-family: var(--font-body);
  font-size: 16px;
  font-weight: 700;
  padding: 12px 24px;
  border: none;
  border-radius: 14px;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
}

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

.btn-primary {
  background: linear-gradient(135deg, var(--primary), #ff8e53);
  color: #fff;
  box-shadow: 0 4px 12px rgba(255, 107, 107, 0.4);
}

.btn-primary:hover {
  box-shadow: 0 6px 16px rgba(255, 107, 107, 0.5);
}

.btn-secondary {
  background: var(--secondary);
  color: #fff;
}

.btn-outline {
  background: #fff;
  border: 2px solid var(--border);
  color: var(--text);
}

.btn-lg {
  padding: 16px 32px;
  font-size: 1.1rem;
}

.btn-group {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 16px;
}

/* Counting area */
.count-row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  justify-content: center;
  min-height: 80px;
  padding: 16px;
  background: #f8f9fa;
  border-radius: 16px;
  margin: 16px 0;
}

.count-item {
  font-size: 2.5rem;
  cursor: pointer;
  user-select: none;
  transition: transform 0.2s;
  animation: popIn 0.3s ease backwards;
}

.count-item:hover {
  transform: scale(1.15);
}

@keyframes popIn {
  from {
    opacity: 0;
    transform: scale(0);
  }
}

.number-pad {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 10px;
  max-width: 360px;
  margin: 0 auto;
}

.num-btn {
  aspect-ratio: 1;
  font-family: var(--font-display);
  font-size: 1.8rem;
  border: 3px solid var(--border);
  background: #fff;
  border-radius: 16px;
  cursor: pointer;
  transition: all 0.2s;
}

.num-btn:hover {
  border-color: var(--primary);
  background: #fff5f5;
}

.num-btn.selected {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.num-btn.correct {
  background: #00b894;
  border-color: #00b894;
  color: #fff;
}

.num-btn.wrong {
  background: #fab1a0;
  border-color: #e17055;
  animation: shake 0.4s;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-6px); }
  75% { transform: translateX(6px); }
}

/* Compare */
.compare-zone {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 24px;
  flex-wrap: wrap;
}

.compare-box {
  flex: 1;
  min-width: 140px;
  max-width: 200px;
  padding: 24px;
  background: #f1f2f6;
  border-radius: 16px;
  text-align: center;
  font-size: 3rem;
  cursor: pointer;
  border: 4px solid transparent;
  transition: all 0.2s;
}

.compare-box:hover {
  border-color: var(--accent);
}

.compare-box.selected {
  border-color: var(--primary);
  background: #fff5f5;
}

.compare-symbol {
  font-family: var(--font-display);
  font-size: 3rem;
  color: var(--purple);
}

/* Shapes */
.shape-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 16px;
}

.shape-card {
  padding: 20px;
  text-align: center;
  border-radius: 16px;
  background: #f8f9fa;
  cursor: pointer;
  border: 3px solid transparent;
  transition: all 0.2s;
}

.shape-card:hover,
.shape-card.highlight {
  border-color: var(--secondary);
  background: #e8f8f5;
}

.shape-svg {
  width: 80px;
  height: 80px;
  margin: 0 auto 8px;
  display: block;
}

/* Clock */
.clock-face {
  width: 220px;
  height: 220px;
  margin: 0 auto 20px;
  position: relative;
  border-radius: 50%;
  background: #fff;
  border: 8px solid var(--primary);
  box-shadow: inset 0 0 20px rgba(0, 0, 0, 0.05);
}

.clock-center {
  position: absolute;
  width: 14px;
  height: 14px;
  background: var(--text);
  border-radius: 50%;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 10;
}

.clock-hand {
  position: absolute;
  bottom: 50%;
  left: 50%;
  transform-origin: bottom center;
  border-radius: 4px;
  margin-left: -3px;
}

.clock-hour {
  width: 6px;
  height: 55px;
  background: var(--text);
}

.clock-minute {
  width: 4px;
  height: 75px;
  background: var(--primary);
}

.clock-label {
  position: absolute;
  font-family: var(--font-display);
  font-size: 14px;
  font-weight: bold;
}

.clock-controls {
  display: flex;
  justify-content: center;
  gap: 16px;
  flex-wrap: wrap;
}

.clock-controls label {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  font-size: 14px;
}

.clock-controls input[type="range"] {
  width: 120px;
  accent-color: var(--primary);
}

/* Math quiz */
.quiz-display {
  font-family: var(--font-display);
  font-size: 3rem;
  text-align: center;
  padding: 24px;
  color: var(--primary);
}

.answer-input {
  font-family: var(--font-display);
  font-size: 2.5rem;
  width: 100px;
  text-align: center;
  border: 3px solid var(--border);
  border-radius: 16px;
  padding: 8px;
  margin: 0 auto;
  display: block;
}

.progress-bar {
  height: 10px;
  background: #eee;
  border-radius: 999px;
  overflow: hidden;
  margin-bottom: 20px;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--secondary), var(--accent));
  border-radius: 999px;
  transition: width 0.4s ease;
}

.feedback {
  text-align: center;
  padding: 16px;
  border-radius: 14px;
  margin-top: 16px;
  font-family: var(--font-display);
  font-size: 1.2rem;
  display: none;
}

.feedback.show {
  display: block;
  animation: fadeIn 0.3s;
}

.feedback.success {
  background: #d4edda;
  color: #155724;
}

.feedback.error {
  background: #f8d7da;
  color: #721c24;
}

/* Position grid */
.pos-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  max-width: 280px;
  margin: 0 auto;
}

.pos-cell {
  aspect-ratio: 1;
  background: #f1f2f6;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2rem;
  cursor: pointer;
  border: 3px solid transparent;
}

.pos-cell.target {
  background: #fff9e6;
}

.pos-cell.correct {
  border-color: #00b894;
  background: #d4edda;
}

.pos-cell.wrong {
  border-color: #e17055;
  animation: shake 0.4s;
}

/* Sort */
.sort-bins {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  justify-content: center;
  margin-bottom: 20px;
}

.sort-bin {
  flex: 1;
  min-width: 140px;
  min-height: 120px;
  border: 3px dashed var(--border);
  border-radius: 16px;
  padding: 12px;
  text-align: center;
}

.sort-bin h4 {
  font-family: var(--font-display);
  margin: 0 0 8px;
  font-size: 1rem;
}

.sort-items {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
  padding: 16px;
  background: #f8f9fa;
  border-radius: 16px;
}

.sort-chip {
  font-size: 2rem;
  padding: 8px 12px;
  background: #fff;
  border-radius: 12px;
  cursor: grab;
  border: 2px solid var(--border);
  touch-action: none;
}

.sort-chip.dragging {
  opacity: 0.5;
}

.sort-bin .sort-chip {
  cursor: default;
  margin: 4px;
}

/* Pattern */
.pattern-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  flex-wrap: wrap;
  font-size: 2.5rem;
  margin: 20px 0;
}

.pattern-slot {
  width: 64px;
  height: 64px;
  border: 3px dashed var(--primary);
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #fff9f9;
}

.pattern-options {
  display: flex;
  gap: 12px;
  justify-content: center;
  flex-wrap: wrap;
}

.pattern-opt {
  font-size: 2rem;
  padding: 12px 16px;
  background: #fff;
  border: 3px solid var(--border);
  border-radius: 14px;
  cursor: pointer;
}

.pattern-opt:hover {
  border-color: var(--primary);
}

/* Toast */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: var(--text);
  color: #fff;
  padding: 14px 28px;
  border-radius: 999px;
  font-family: var(--font-display);
  font-size: 1.1rem;
  z-index: 200;
  opacity: 0;
  transition: transform 0.35s, opacity 0.35s;
  pointer-events: none;
}

.toast.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

/* Confetti */
.confetti {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 150;
  overflow: hidden;
}

.confetti-piece {
  position: absolute;
  width: 10px;
  height: 10px;
  animation: fall 2.5s ease forwards;
}

@keyframes fall {
  to {
    transform: translateY(100vh) rotate(720deg);
    opacity: 0;
  }
}

/* Responsive */
@media (max-width: 768px) {
  .menu-btn {
    display: block;
  }

  .layout {
    flex-direction: column;
    padding: 12px;
  }

  .sidebar {
    position: fixed;
    left: -280px;
    top: 0;
    bottom: 0;
    width: 260px;
    z-index: 90;
    border-radius: 0 20px 20px 0;
    transition: left 0.3s;
    overflow-y: auto;
    padding-top: 80px;
  }

  .sidebar.open {
    left: 0;
  }

  .hero {
    padding: 28px 20px;
  }

  .number-pad {
    grid-template-columns: repeat(5, 1fr);
    max-width: 100%;
  }

  .quiz-display {
    font-size: 2.2rem;
  }
}

.overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.3);
  z-index: 80;
}

.overlay.show {
  display: block;
}
