/*
 * CLASSROOM BASE CSS
 * Core typography, colors, layout, header, footer, progress
 * Used by all Junior Math chapters
 */

/* ========== CSS VARIABLES ========== */
:root {
  /* Warm, calm colors - no anxiety-inducing reds */
  --bg: #FFF8F0;
  --bg-cool: #F0F7FF;
  --card: #FFFFFF;

  /* Primary - Calm blue */
  --primary: #3B82F6;
  --primary-dark: #2563EB;
  --primary-soft: #DBEAFE;

  /* Secondary - Warm amber */
  --secondary: #F59E0B;
  --secondary-soft: #FEF3C7;

  /* Place value colors (consistent across chapters) */
  --thousands: #7C3AED;
  --thousands-soft: #EDE9FE;
  --hundreds: #0891B2;
  --hundreds-soft: #CFFAFE;
  --tens: #059669;
  --tens-soft: #D1FAE5;
  --ones: #F59E0B;
  --ones-soft: #FEF3C7;

  /* Overflow indicator colors */
  --overflow-safe: #22C55E;
  --overflow-likely: #F59E0B;
  --overflow-certain: #EF4444;

  /* Feedback */
  --success: #22C55E;
  --success-soft: #DCFCE7;
  --thinking: #8B5CF6;
  --thinking-soft: #EDE9FE;
  --info: #3B82F6;
  --info-soft: #DBEAFE;

  /* Text */
  --text: #1E293B;
  --text-light: #64748B;
  --text-muted: #94A3B8;

  /* Typography */
  --font-display: 'Baloo 2', cursive;
  --font-body: 'Nunito', sans-serif;
  --font-story: 'Comic Neue', cursive;

  --radius: 20px;
  --radius-lg: 28px;
}

/* ========== RESET ========== */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  user-select: none;
}

/* ========== HEADER ========== */
.header {
  background: var(--card);
  padding: 8px 12px;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 20px rgba(0,0,0,0.06);
}

.header-inner {
  max-width: 900px;
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.logo {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 1.1rem;
  color: var(--primary);
  display: flex;
  align-items: center;
  gap: 6px;
  text-decoration: none;
  flex-shrink: 1;
  min-width: 0;
}

.logo-text {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chapter-badge {
  background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
  color: white;
  padding: 3px 10px;
  border-radius: 50px;
  font-size: 0.7rem;
  font-weight: 700;
  white-space: nowrap;
  flex-shrink: 0;
}

.class-badge {
  background: var(--secondary);
  color: white;
  padding: 2px 6px;
  border-radius: 50px;
  font-size: 0.6rem;
  font-weight: 700;
  white-space: nowrap;
  flex-shrink: 0;
}

.header-controls {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

.control-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: var(--bg);
  font-size: 1.1rem;
  cursor: pointer;
  transition: all 0.2s;
}

.control-btn:hover {
  background: var(--primary-soft);
}

.control-btn.active {
  background: var(--primary);
  color: white;
}

.control-btn.muted {
  opacity: 0.5;
}

/* Mobile header adjustments */
@media (max-width: 480px) {
  .header { padding: 6px 10px; }
  .logo { font-size: 1rem; gap: 4px; }
  .logo-text { display: none; }
  .class-badge { display: none; }
  .chapter-badge { padding: 2px 8px; font-size: 0.65rem; }
  .header-controls { gap: 4px; }
  .control-btn { width: 32px; height: 32px; font-size: 1rem; }
}

@media (max-width: 360px) {
  .chapter-badge { padding: 2px 6px; font-size: 0.6rem; }
  .control-btn { width: 30px; height: 30px; font-size: 0.9rem; }
}

/* ========== PROGRESS BAR ========== */
.progress-bar {
  height: 4px;
  background: #E2E8F0;
  position: sticky;
  top: 52px;
  z-index: 99;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--ones) 0%, var(--tens) 33%, var(--hundreds) 66%, var(--thousands) 100%);
  transition: width 0.3s ease-out;
  width: 0%;
}

@media (max-width: 480px) {
  .progress-bar { top: 44px; }
}

/* ========== MAIN CONTAINER ========== */
.main {
  max-width: 900px;
  margin: 0 auto;
  padding: 8px 12% 100px; /* Desktop: 12% side margins */
}

@media (max-width: 768px) {
  .main { padding: 4px 4% 100px; } /* Mobile: 4% side margins */
}

/* ========== SECTIONS ========== */
.section {
  margin: 20px 0;
  animation: fadeIn 0.6s ease;
}

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

.section-card {
  background: var(--card);
  border-radius: 16px;
  padding: 12px;
  box-shadow: 0 2px 10px rgba(0,0,0,0.05);
  position: relative;
  overflow: hidden;
}

.section-card .game-content,
.section-card .predictor-container,
.section-card .combine-container {
  padding: 8px;
  margin: 6px 0;
}

.section-header {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 10px;
  flex-wrap: nowrap;
}

.section-icon {
  font-size: 1.2rem;
  flex-shrink: 0;
}

.section-title {
  font-family: var(--font-display);
  font-size: 1rem;
  line-height: 1.2;
  flex: 1;
}

.section-subtitle {
  font-size: 0.7rem;
  color: var(--text-light);
}

.section-number {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-size: 0.7rem;
  color: var(--text-light);
}

.audio-btn {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: none;
  background: var(--primary-soft);
  font-size: 0.9rem;
  cursor: pointer;
  margin-left: auto;
  flex-shrink: 0;
}

.audio-btn:hover {
  background: var(--primary);
  color: white;
}

/* ========== CHAPTER HERO ========== */
.chapter-hero {
  background: linear-gradient(135deg, var(--primary-soft) 0%, var(--secondary-soft) 100%);
  border-radius: var(--radius);
  padding: 16px;
  text-align: center;
}

.chapter-title {
  font-family: var(--font-display);
  font-size: 1.4rem;
  color: var(--primary);
  margin: 0 0 4px 0;
}

.chapter-subtitle {
  font-size: 0.85rem;
  color: var(--text);
  margin: 0 0 8px 0;
}

/* ========== BOARD ALIGNMENT ========== */
.board-alignment {
  background: var(--card);
  border-radius: var(--radius);
  padding: 10px 12px;
  border-left: 3px solid var(--primary);
}

.board-text { font-size: 0.8rem; color: var(--text); line-height: 1.4; }
.board-link { font-size: 0.75rem; color: var(--text-light); margin-top: 4px; }
.board-link a { color: var(--primary); text-decoration: none; }

/* ========== SUMMARY CARD ========== */
.summary-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 12px;
}

.summary-title {
  font-family: var(--font-display);
  font-size: 1rem;
  color: var(--text);
  margin: 0 0 8px 0;
}

.summary-list {
  font-size: 0.85rem;
  color: var(--text);
  margin: 0;
  padding-left: 20px;
  line-height: 1.6;
}

.summary-list a { color: var(--primary); text-decoration: none; }

/* ========== BIG IDEA CARD ========== */
.big-idea-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 14px;
}

.big-idea-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.big-idea-title {
  font-family: var(--font-display);
  font-size: 1.1rem;
  color: var(--text);
  margin: 0;
}

/* Step-by-step Big Idea Stepper */
.big-idea-stepper {
  background: var(--bg);
  border-radius: 12px;
  padding: 14px;
}

.big-idea-visual {
  text-align: center;
  padding: 12px;
  margin-bottom: 10px;
  min-height: 80px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.big-idea-visual .math-problem {
  font-family: var(--font-display);
  font-size: 1.4rem;
  color: var(--primary);
  margin-bottom: 8px;
}

.big-idea-visual .place-boxes {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin-top: 8px;
}

.big-idea-visual .place-box {
  padding: 8px 12px;
  border-radius: 8px;
  text-align: center;
  min-width: 50px;
}

.big-idea-visual .place-box.highlight {
  transform: scale(1.1);
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}

.big-idea-visual .place-box .label {
  font-size: 0.65rem;
  text-transform: uppercase;
  margin-bottom: 2px;
}

.big-idea-visual .place-box .value {
  font-family: var(--font-display);
  font-size: 1.1rem;
}

.big-idea-explanation {
  background: var(--success-soft);
  border-left: 4px solid var(--success);
  border-radius: 8px;
  padding: 12px;
  font-size: 0.9rem;
  line-height: 1.6;
  color: var(--text);
  margin-bottom: 12px;
}

.big-idea-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.step-btn {
  background: var(--primary-soft);
  color: var(--primary);
  border: none;
  padding: 8px 14px;
  border-radius: 8px;
  font-weight: 600;
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.2s;
}

.step-btn:hover:not(:disabled) {
  background: var(--primary);
  color: white;
}

.step-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.step-btn.primary {
  background: var(--primary);
  color: white;
}

.step-counter {
  font-size: 0.8rem;
  color: var(--text-light);
  font-weight: 600;
}

@media (max-width: 480px) {
  .big-idea-visual .math-problem { font-size: 1.2rem; }
  .big-idea-visual .place-box { padding: 6px 8px; min-width: 40px; }
  .big-idea-visual .place-box .value { font-size: 0.95rem; }
  .big-idea-explanation { font-size: 0.85rem; padding: 10px; }
  .step-btn { padding: 6px 10px; font-size: 0.8rem; }
}

/* Desktop enhancements for intro sections */
@media (min-width: 601px) {
  .chapter-hero { padding: 24px; }
  .chapter-title { font-size: 1.8rem; }
  .chapter-subtitle { font-size: 0.95rem; }
  .board-alignment { padding: 14px 16px; }
  .board-text { font-size: 0.85rem; }
  .summary-card, .big-idea-card { padding: 16px; }
  .summary-title, .big-idea-title { font-size: 1.1rem; }
  .big-idea-problem { font-size: 1.2rem; padding: 10px; }
}

/* ========== COGNITIVE CONTRACT ========== */
.contract-box {
  background: linear-gradient(135deg, var(--thinking-soft) 0%, var(--primary-soft) 100%);
  border-radius: 16px;
  padding: 12px 16px;
  margin: 12px 0;
  border-left: 4px solid var(--thinking);
}

.contract-title {
  font-family: var(--font-display);
  font-size: 1rem;
  color: var(--thinking);
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.contract-items {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.contract-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  color: var(--text);
}

.contract-icon {
  font-size: 1.2rem;
}

/* ========== EXPLANATION BOX ========== */
.explanation-box {
  background: linear-gradient(135deg, var(--primary-soft) 0%, var(--secondary-soft) 100%);
  border-radius: 12px;
  padding: 12px;
  margin: 10px 0;
}

.explanation-title {
  font-family: var(--font-display);
  font-size: 0.9rem;
  color: var(--primary);
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.explanation-text {
  font-size: 0.95rem;
  color: var(--text);
  line-height: 1.7;
}

/* ========== GOLDEN RULE ========== */
.golden-rule {
  background: linear-gradient(135deg, var(--secondary-soft) 0%, var(--primary-soft) 100%);
  border-radius: 12px;
  padding: 12px 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 12px 0;
}

.golden-rule-icon {
  font-size: 1.5rem;
  animation: sparkle 2s ease-in-out infinite;
}

@keyframes sparkle {
  0%, 100% { transform: rotate(0deg) scale(1); }
  25% { transform: rotate(-10deg) scale(1.1); }
  75% { transform: rotate(10deg) scale(1.1); }
}

.golden-rule-text {
  font-family: var(--font-display);
  font-size: 0.9rem;
  color: var(--text);
  line-height: 1.4;
}

/* ========== ACTION BUTTONS ========== */
.action-btn {
  padding: 10px 20px;
  border-radius: 25px;
  border: none;
  font-family: var(--font-display);
  font-size: 0.9rem;
  cursor: pointer;
  transition: all 0.2s;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.action-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.action-btn.primary {
  background: var(--primary);
  color: white;
}

.action-btn.primary:hover:not(:disabled) {
  background: var(--primary-dark);
  transform: translateY(-2px);
}

.action-btn.secondary {
  background: var(--bg);
  color: var(--text);
}

.action-btn.secondary:hover:not(:disabled) {
  background: var(--primary-soft);
}

/* Button Row - always horizontal */
.button-row {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin: 10px 0;
  flex-wrap: nowrap;
}

/* Goal/instruction text - natural flow, no card */
.goal-text {
  font-size: 0.85rem;
  color: var(--text-light);
  text-align: center;
  margin: 8px 0;
  line-height: 1.4;
}

/* ========== PHASE INDICATOR ========== */
.phase-indicator {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin: 20px 0;
}

.phase-dot {
  width: 40px;
  height: 8px;
  border-radius: 4px;
  background: #E2E8F0;
  transition: all 0.3s;
}

.phase-dot.active {
  background: var(--primary);
}

.phase-dot.complete {
  background: var(--success);
}

/* ========== TOAST ========== */
.toast {
  position: fixed;
  bottom: 100px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: var(--text);
  color: white;
  padding: 12px 24px;
  border-radius: 50px;
  font-family: var(--font-display);
  z-index: 200;
  opacity: 0;
  transition: all 0.3s;
  display: flex;
  align-items: center;
  gap: 8px;
}

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

/* ========== FEEDBACK ========== */
.feedback {
  padding: 10px 14px;
  border-radius: 10px;
  margin: 10px 0;
  text-align: center;
  font-weight: 600;
  font-size: 0.9rem;
  display: none;
}

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

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

.feedback.success {
  background: var(--success-soft);
  color: var(--success);
}

.feedback.thinking {
  background: var(--thinking-soft);
  color: var(--thinking);
}

.feedback.info {
  background: var(--info-soft);
  color: var(--info);
}

/* ========== PARENT SECTION ========== */
.parent-card,
.parent-section {
  background: var(--card);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: 0 8px 32px rgba(0,0,0,0.08);
}

.parent-header {
  background: linear-gradient(135deg, var(--primary-soft) 0%, var(--secondary-soft) 100%);
  padding: 16px 20px;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.parent-header-content {
  display: flex;
  align-items: center;
  gap: 10px;
}

.parent-header-icon {
  font-size: 1.5rem;
}

.parent-header-title {
  font-family: var(--font-display);
  font-size: 1.1rem;
  color: var(--primary-dark);
}

.parent-header-toggle {
  font-size: 1.2rem;
  transition: transform 0.3s;
}

.parent-content {
  padding: 20px;
  display: none;
}

.parent-content.show {
  display: block;
}

.parent-section {
  background: var(--bg);
  border-radius: 12px;
  padding: 12px;
  margin-bottom: 12px;
}

.parent-section h4 {
  font-family: var(--font-display);
  font-size: 0.95rem;
  margin-bottom: 8px;
}

.parent-section p {
  font-size: 0.85rem;
  line-height: 1.6;
}

.parent-section ul {
  font-size: 0.85rem;
  line-height: 1.8;
  padding-left: 20px;
}

.parent-box {
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 20px;
}

.parent-box h3 {
  font-family: var(--font-display);
  font-size: 1.1rem;
  margin-bottom: 16px;
}

.parent-box p {
  font-size: 0.9rem;
  line-height: 1.8;
  margin-bottom: 12px;
}

.parent-box ul {
  list-style: none;
  padding: 0;
}

.parent-box li {
  padding: 8px 0;
  padding-left: 24px;
  position: relative;
  font-size: 0.9rem;
  line-height: 1.6;
}

.parent-box li::before {
  content: '\2713';
  position: absolute;
  left: 0;
  color: var(--success);
}

/* ========== BOTTOM NAV ========== */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--card);
  box-shadow: 0 -4px 20px rgba(0,0,0,0.1);
  z-index: 100;
  transition: transform 0.3s ease, opacity 0.3s ease;
}

.bottom-nav.hidden {
  transform: translateY(100%);
  opacity: 0;
}

.nav-inner {
  max-width: 600px;
  margin: 0 auto;
  display: flex;
  justify-content: space-around;
  align-items: center;
  padding: 6px 4px;
  gap: 2px;
}

.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  padding: 6px 8px;
  background: none;
  border: none;
  cursor: pointer;
  border-radius: 10px;
  transition: all 0.2s;
  text-decoration: none;
  min-width: 0;
  flex: 1;
}

.nav-item:hover {
  background: var(--bg);
}

.nav-item.active {
  background: var(--primary-soft);
}

.nav-item.chapter-link {
  background: var(--primary);
  color: white;
}

.nav-item.chapter-link:hover {
  background: var(--primary-dark);
}

.nav-item.chapter-link .nav-item-icon,
.nav-item.chapter-link .nav-item-label {
  color: white;
}

.nav-item-icon { font-size: 1.2rem; }

.nav-item-label {
  font-size: 0.6rem;
  font-weight: 700;
  color: var(--text-light);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

.nav-item.active .nav-item-label {
  color: var(--primary);
}

/* Mobile: smaller icons and labels */
@media (max-width: 480px) {
  .nav-inner { padding: 5px 2px; gap: 1px; }
  .nav-item { padding: 5px 4px; border-radius: 8px; }
  .nav-item-icon { font-size: 1.1rem; }
  .nav-item-label { font-size: 0.55rem; }

  .section { margin: 8px 0; }
  .section-card { padding: 10px; }
  .section-number { top: 45px; }

  .explanation-box { padding: 10px; margin: 8px 0; }
  .explanation-title { font-size: 0.9rem; margin-bottom: 6px; }
  .explanation-text { font-size: 0.8rem; }

  .golden-rule { padding: 8px 10px; margin-top: 10px; }
  .golden-rule-icon { font-size: 1.1rem; }
  .golden-rule-text { font-size: 0.8rem; }
}

@media (max-width: 360px) {
  .nav-item { padding: 4px 3px; }
  .nav-item-icon { font-size: 1rem; }
  .nav-item-label { font-size: 0.5rem; }
}

/* Desktop: show inline chapter nav, keep bottom nav */
@media (min-width: 768px) {
  .chapter-nav-desktop { display: flex !important; }
}

/* ========== ANIMATIONS ========== */
@keyframes float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-5px); }
}

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

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20%, 60% { transform: translateX(-5px); }
  40%, 80% { transform: translateX(5px); }
}

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

/* ========== FOOTER ========== */
.footer {
  background: var(--card);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  padding: 24px 20px;
  margin-top: 32px;
  text-align: center;
  box-shadow: 0 -4px 20px rgba(0,0,0,0.05);
}

.footer-content {
  max-width: 600px;
  margin: 0 auto;
}

.footer-logo {
  font-family: var(--font-display);
  font-size: 1.2rem;
  color: var(--primary);
  margin-bottom: 4px;
}

.footer-text {
  font-size: 0.85rem;
  color: var(--text-light);
  margin-bottom: 16px;
}

.footer-nav {
  display: flex;
  justify-content: center;
  gap: 24px;
  flex-wrap: wrap;
}

.footer-nav a {
  color: var(--primary);
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 600;
  padding: 8px 16px;
  border-radius: 50px;
  background: var(--primary-soft);
  transition: all 0.2s;
}

.footer-nav a:hover {
  background: var(--primary);
  color: white;
}

.footer-nav span {
  color: var(--text-light);
  font-size: 0.9rem;
  font-weight: 600;
  padding: 8px 16px;
}

@media (max-width: 480px) {
  .footer { padding: 20px 16px; margin-top: 24px; }
  .footer-logo { font-size: 1.1rem; }
  .footer-text { font-size: 0.8rem; margin-bottom: 12px; }
  .footer-nav { gap: 12px; }
  .footer-nav a, .footer-nav span { font-size: 0.8rem; padding: 6px 12px; }
}
