:root {
  --bg: #fff8ee;
  --bg-dot: #eadbc6;
  --card: #ffffff;
  --card-border: #f0e4cf;
  --ink: #243046;
  --muted: #6b7a90;

  --primary: #ff6b6b;
  --primary-dark: #d94343;
  --secondary: #38a3ff;
  --secondary-dark: #1679d4;
  --accent: #ffbe2e;
  --accent-dark: #d99400;
  --success: #2ed47a;
  --success-dark: #18a558;
  --purple: #9b6bff;
  --purple-dark: #7442db;

  --radius: 26px;
  --shadow: 0 12px 28px -8px rgba(45, 35, 20, 0.10), 0 4px 10px -2px rgba(45, 35, 20, 0.05);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Nunito", "Segoe UI", system-ui, sans-serif;
  background-color: var(--bg);
  background-image: radial-gradient(var(--bg-dot) 1.6px, transparent 1.6px);
  background-size: 24px 24px;
  color: var(--ink);
  line-height: 1.5;
  -webkit-tap-highlight-color: transparent;
}

button, input, select, textarea { font: inherit; }

/* Inline SVG Icon helper */
.ico {
  width: 20px;
  height: 20px;
  display: inline-block;
  vertical-align: -0.22em;
  flex-shrink: 0;
}
.ico-lg { width: 26px; height: 26px; }

/* 3D Tactile Push Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 2px solid #d8dee9;
  border-bottom: 5px solid #cbd5e1;
  border-radius: 18px;
  padding: 10px 18px;
  font-weight: 800;
  cursor: pointer;
  background: #ffffff;
  color: var(--ink);
  text-decoration: none;
  transition: transform 0.08s ease, border-bottom-width 0.08s ease, filter 0.15s ease;
  user-select: none;
}
.btn:hover { filter: brightness(1.03); transform: translateY(-1px); }
.btn:active {
  transform: translateY(3px);
  border-bottom-width: 2px;
}

.btn-primary {
  background: var(--primary);
  border-color: var(--primary-dark);
  border-bottom-color: var(--primary-dark);
  color: #fff;
}
.btn-secondary {
  background: var(--secondary);
  border-color: var(--secondary-dark);
  border-bottom-color: var(--secondary-dark);
  color: #fff;
}
.btn-success {
  background: var(--success);
  border-color: var(--success-dark);
  border-bottom-color: var(--success-dark);
  color: #fff;
}
.btn-accent {
  background: var(--accent);
  border-color: var(--accent-dark);
  border-bottom-color: var(--accent-dark);
  color: #4a2e00;
}
.btn-purple {
  background: var(--purple);
  border-color: var(--purple-dark);
  border-bottom-color: var(--purple-dark);
  color: #fff;
}
.btn-outline {
  background: #fff;
  border-color: #e2d6c3;
  border-bottom-color: #cbbba2;
}
.btn-lg { padding: 13px 24px; font-size: 1.08rem; border-radius: 20px; }
.btn-sm { padding: 6px 12px; font-size: 0.88rem; border-radius: 14px; border-bottom-width: 4px; }

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 12px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 800;
  background: #eef2f6;
  color: #475569;
}
.badge-core { background: #dcfce7; color: #15803d; }
.badge-extra { background: #fef3c7; color: #b45309; }
.badge-planned { background: #f1f5f9; color: #64748b; }

/* Thick Storybook Cards */
.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px;
  border: 3px solid var(--card-border);
}

.hidden { display: none !important; }

/* Keyframe Animations */
@keyframes popIn {
  0% { transform: scale(0.88); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-7px); }
  75% { transform: translateX(7px); }
}
@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.08); }
}
@keyframes floatCloud {
  0%, 100% { transform: translateY(0px); }
  50% { transform: translateY(-6px); }
}
@keyframes bouncePlay {
  0%, 100% { transform: scale(1); }
  30% { transform: scale(1.06) rotate(-1deg); }
  65% { transform: scale(1.04) rotate(1deg); }
}
@keyframes waveBar {
  0%, 100% { height: 6px; }
  50% { height: 18px; }
}

.anim-pop { animation: popIn 0.25s cubic-bezier(0.22, 1, 0.36, 1); }
.anim-shake { animation: shake 0.32s ease; }
.anim-pulse { animation: pulse 0.55s infinite; }
.is-playing {
  animation: bouncePlay 0.55s ease;
  box-shadow: 0 0 0 5px rgba(56, 163, 255, 0.28), var(--shadow) !important;
}

.soundwave {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  height: 18px;
}
.soundwave i {
  display: block;
  width: 3px;
  height: 6px;
  border-radius: 3px;
  background: currentColor;
}
.is-playing .soundwave i:nth-child(1) { animation: waveBar 0.45s infinite 0s; }
.is-playing .soundwave i:nth-child(2) { animation: waveBar 0.45s infinite 0.15s; }
.is-playing .soundwave i:nth-child(3) { animation: waveBar 0.45s infinite 0.3s; }

/* ================= PORTAL PAGE ================= */
.portal-wrap {
  max-width: 1080px;
  margin: 0 auto;
  padding: 28px 18px 64px;
}

.hero {
  background: linear-gradient(135deg, #ff7a59 0%, #ffb347 100%);
  color: #fff;
  border-radius: 32px;
  padding: 34px 30px;
  box-shadow: 0 14px 32px -8px rgba(255, 122, 89, 0.35);
  border: 4px solid #fff;
  margin-bottom: 24px;
  position: relative;
  overflow: hidden;
}
.hero h1 { margin: 0 0 8px; font-size: 2.05rem; letter-spacing: 0.3px; }
.hero p { margin: 0; opacity: 0.96; font-size: 1.05rem; }
.hero-deco {
  position: absolute;
  right: 24px;
  top: 50%;
  transform: translateY(-50%);
  opacity: 0.22;
  pointer-events: none;
}

.role-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 20px;
  margin-bottom: 26px;
}

.role-card {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 16px;
}

.icon-pill {
  width: 52px;
  height: 52px;
  border-radius: 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 10px;
}

.lesson-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 14px;
}

.lesson-tile {
  background: #fffdf9;
  border-radius: 22px;
  padding: 16px;
  border: 3px dashed #e2d6c3;
  display: flex;
  flex-direction: column;
  gap: 8px;
  transition: transform 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}
.lesson-tile.ready {
  background: #fff;
  border-style: solid;
  border-color: #d8ebff;
  box-shadow: 0 6px 16px -6px rgba(56, 163, 255, 0.16);
}
.lesson-tile.ready:hover {
  transform: translateY(-3px);
  border-color: var(--secondary);
}

/* ================= TEACHER CLASSROOM ================= */
.teacher-topbar {
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(10px);
  border-bottom: 3px solid var(--card-border);
  padding: 10px 20px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  position: sticky;
  top: 0;
  z-index: 40;
}

.team-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
}

.team-pill {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 12px;
  border-radius: 20px;
  font-weight: 800;
  border: 2px solid transparent;
}
.team-red { background: #fff1f2; border-color: #fecdd3; color: #be123c; }
.team-blue { background: #eff6ff; border-color: #bfdbfe; color: #1d4ed8; }

.team-meta {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 90px;
}
.team-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  font-size: 0.92rem;
}
.team-score { font-size: 1.25rem; font-weight: 900; }
.energy-track {
  width: 100%;
  height: 8px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.08);
  overflow: hidden;
}
.energy-fill {
  height: 100%;
  width: 0%;
  border-radius: 999px;
  transition: width 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.team-red .energy-fill { background: linear-gradient(90deg, #ff6b6b, #f43f5e); }
.team-blue .energy-fill { background: linear-gradient(90deg, #38a3ff, #2563eb); }

.crown-badge {
  display: inline-flex;
  color: #f59e0b;
  animation: floatCloud 1.8s ease-in-out infinite;
}

.teacher-main {
  max-width: 1220px;
  margin: 0 auto;
  padding: 20px;
  display: grid;
  grid-template-columns: 1fr 300px;
  gap: 20px;
}
@media (max-width: 960px) {
  .teacher-main { grid-template-columns: 1fr; }
}

.mode-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 16px;
}
.mode-tabs .btn.active {
  background: var(--ink);
  border-color: #0f172a;
  border-bottom-color: #0f172a;
  color: #fff;
}

/* Polaroid Storybook Flashcard Stage */
.flash-stage {
  min-height: 410px;
  background: linear-gradient(180deg, #e8f7ff 0%, #f0fdf4 100%);
  border-radius: 28px;
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 26px;
  cursor: pointer;
  overflow: hidden;
  border: 3px solid #cfe9ff;
}

.flash-frame {
  background: #fff;
  padding: 14px;
  border-radius: 28px;
  box-shadow: 0 14px 30px rgba(36, 48, 70, 0.12);
  border: 3px solid #fff;
  transition: transform 0.2s ease;
}
.flash-stage:hover .flash-frame { transform: scale(1.03) rotate(-1deg); }

.flash-img {
  width: 240px;
  height: 240px;
  object-fit: cover;
  border-radius: 20px;
  display: block;
  user-select: none;
}

.word-reveal { margin-top: 14px; text-align: center; }
.word-reveal .en { font-size: 2.9rem; font-weight: 900; color: var(--ink); letter-spacing: 1px; line-height: 1.1; }
.word-reveal .zh { font-size: 1.3rem; color: var(--muted); font-weight: 700; margin-top: 4px; }
.word-reveal .ex {
  display: inline-block;
  margin-top: 8px;
  padding: 6px 16px;
  background: #eff6ff;
  border-radius: 999px;
  font-size: 1.2rem;
  color: var(--secondary-dark);
  font-weight: 800;
}

/* True 3D Flip Memory Grid */
.memory-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
}
@media (max-width: 640px) {
  .memory-grid { grid-template-columns: repeat(3, 1fr); }
}

.mem-card {
  height: 128px;
  perspective: 1000px;
  cursor: pointer;
  user-select: none;
}
.mem-inner {
  position: relative;
  width: 100%;
  height: 100%;
  transition: transform 0.48s cubic-bezier(0.34, 1.56, 0.64, 1);
  transform-style: preserve-3d;
}
.mem-card.flipped .mem-inner,
.mem-card.matched .mem-inner {
  transform: rotateY(180deg);
}
.mem-face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  border-radius: 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 8px;
}
.mem-front {
  background: linear-gradient(135deg, #38a3ff 0%, #6366f1 100%);
  color: #fff;
  border: 3px solid #fff;
  border-bottom: 6px solid #2648b5;
  box-shadow: 0 8px 16px rgba(56, 163, 255, 0.25);
  font-size: 2rem;
  font-weight: 900;
}
.mem-back {
  background: #fff;
  color: var(--ink);
  border: 3px solid var(--secondary);
  transform: rotateY(180deg);
  box-shadow: 0 6px 14px rgba(0, 0, 0, 0.08);
}
.mem-card.matched .mem-back {
  background: #dcfce7;
  border-color: var(--success);
  color: #166534;
}

/* Phonics Blender */
.phonics-tiles {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 14px;
  margin: 18px 0;
}
.letter-block {
  width: 84px;
  height: 92px;
  border-radius: 22px;
  background: #fff;
  border: 3px solid var(--secondary);
  border-bottom: 7px solid var(--secondary-dark);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2.9rem;
  font-weight: 900;
  cursor: pointer;
  transition: transform 0.1s ease;
}
.letter-block:active { transform: translateY(3px); }
.letter-block.vowel {
  border-color: var(--primary);
  border-bottom-color: var(--primary-dark);
  color: var(--primary);
  background: #fff5f5;
}

/* Bomb Stage */
.bomb-box {
  text-align: center;
  padding: 28px 18px;
  border-radius: 26px;
  background: linear-gradient(180deg, #fff1f2 0%, #ffe4e6 100%);
  border: 3px dashed #fda4af;
}

/* ================= STUDENT MOBILE VIEW ================= */
.student-wrap {
  max-width: 540px;
  margin: 0 auto;
  padding: 14px 14px 96px;
}

.student-header {
  background: linear-gradient(135deg, #38a3ff 0%, #8b5cf6 100%);
  color: #fff;
  border-radius: 28px;
  padding: 20px;
  margin-bottom: 16px;
  box-shadow: 0 12px 26px -6px rgba(56, 163, 255, 0.35);
  border: 3px solid #fff;
  position: relative;
  overflow: hidden;
}

.word-list-mobile {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 14px;
}

.word-card-mobile {
  background: #fff;
  border-radius: 22px;
  padding: 12px;
  text-align: center;
  box-shadow: var(--shadow);
  border: 3px solid var(--card-border);
  border-bottom: 6px solid #e5d4b8;
  cursor: pointer;
  transition: transform 0.12s ease, border-color 0.15s ease;
}
.word-card-mobile.core-card { border-bottom-color: #86efac; }
.word-card-mobile.extra-card { border-bottom-color: #fde047; }
.word-card-mobile:active { transform: translateY(3px); }

.word-card-mobile .word-img {
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  border-radius: 16px;
  margin-top: 8px;
  display: block;
}
.word-card-mobile .en { font-size: 1.22rem; font-weight: 900; margin-top: 8px; color: var(--ink); }
.word-card-mobile .zh { font-size: 0.9rem; color: var(--muted); font-weight: 600; }

/* Floating Pill Dock */
.bottom-nav {
  position: fixed;
  bottom: 12px;
  left: 50%;
  transform: translateX(-50%);
  width: calc(100% - 24px);
  max-width: 500px;
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(12px);
  border: 2px solid var(--card-border);
  border-radius: 999px;
  box-shadow: 0 14px 30px rgba(36, 48, 70, 0.16);
  display: flex;
  justify-content: space-around;
  padding: 6px;
  z-index: 50;
}
.nav-item {
  border: none;
  background: transparent;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  font-size: 0.76rem;
  font-weight: 800;
  color: var(--muted);
  cursor: pointer;
  padding: 6px 14px;
  border-radius: 999px;
  transition: all 0.18s ease;
}
.nav-item.active {
  color: #fff;
  background: linear-gradient(135deg, #38a3ff, #6366f1);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(56, 163, 255, 0.35);
}

/* Quiz */
.quiz-progress-track {
  width: 100%;
  height: 12px;
  background: #eef2f6;
  border-radius: 999px;
  overflow: hidden;
  margin-bottom: 14px;
}
.quiz-progress-fill {
  height: 100%;
  background: linear-gradient(90deg, #2ed47a, #38a3ff);
  border-radius: 999px;
  transition: width 0.35s ease;
}

.quiz-options {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 14px;
  margin-top: 16px;
}
.quiz-opt {
  background: #fff;
  border: 3px solid var(--card-border);
  border-bottom: 6px solid #dfd1ba;
  border-radius: 22px;
  padding: 8px;
  text-align: center;
  cursor: pointer;
  overflow: hidden;
  transition: transform 0.1s ease;
}
.quiz-opt:active { transform: translateY(3px); }
.quiz-opt.correct { border-color: var(--success); border-bottom-color: var(--success-dark); background: #dcfce7; }
.quiz-opt.wrong { border-color: var(--primary); border-bottom-color: var(--primary-dark); background: #fee2e2; }
.quiz-img {
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  border-radius: 16px;
  display: block;
}

.checklist-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 14px;
  background: #fffaf2;
  border: 2px solid #f3e6d0;
  border-radius: 18px;
  margin-bottom: 10px;
  cursor: pointer;
  font-weight: 600;
}
.checklist-item input { width: 22px; height: 22px; margin-top: 2px; accent-color: var(--success); }

.confetti-layer {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 100;
  overflow: hidden;
}
