/* ═══════════════════════════════════════════════
   Charlotte's Math Lab — Shared Design System
   lib/math-lab.css
   ═══════════════════════════════════════════════ */

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

:root {
  --bg: #f8f6ff;
  --surface: #ffffff;
  --text: #1a1a2e;
  --text-muted: #6b7280;
  --pink: #ff6b9d;
  --blue: #4a90d9;
  --green: #34c759;
  --orange: #ff9500;
  --purple: #af52de;
  --yellow: #ffcc02;
  --teal: #5ac8fa;
  --red: #ff3b30;
  --radius: 16px;
  --radius-sm: 10px;
  --radius-xs: 8px;
  --shadow: 0 4px 24px rgba(0,0,0,0.08);
  --shadow-hover: 0 8px 32px rgba(0,0,0,0.12);
  --font-display: 'Fredoka', sans-serif;
  --font-body: 'Inter', -apple-system, sans-serif;
  --max-width: 860px;
  --transition: 0.25s ease;
}

body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

/* ─── TOP NAV ─── */
.top-nav {
  background: var(--surface);
  border-bottom: 1px solid #eee;
  padding: 10px 20px;
  display: flex;
  gap: 20px;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
}
.top-nav a {
  text-decoration: none;
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--text-muted);
  padding: 4px 12px;
  border-radius: var(--radius-xs);
  transition: all var(--transition);
}
.top-nav a:hover { background: #f0eeff; color: var(--purple); }
.top-nav a.active { background: #f0eeff; color: var(--purple); }

/* ─── HERO ─── */
.hero {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  padding: 40px 24px 48px;
  text-align: center;
  border-radius: 0 0 32px 32px;
  position: relative;
  overflow: hidden;
}
.hero::after {
  content: '';
  position: absolute;
  bottom: -30px; left: -30px;
  width: 200px; height: 200px;
  background: rgba(255,255,255,0.06);
  border-radius: 50%;
}
.hero::before {
  content: '';
  position: absolute;
  top: -40px; right: -40px;
  width: 160px; height: 160px;
  background: rgba(255,255,255,0.06);
  border-radius: 50%;
}
.hero h1 {
  font-family: var(--font-display);
  font-size: 2.4rem;
  font-weight: 700;
  position: relative; z-index: 1;
}
.hero p {
  font-size: 1.1rem;
  opacity: 0.9;
  margin-top: 8px;
  position: relative; z-index: 1;
  max-width: 480px;
  margin-left: auto; margin-right: auto;
}

/* ─── LAYOUT ─── */
.container {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 24px 20px 60px;
}

/* ─── SECTION TITLES ─── */
.section-title {
  font-family: var(--font-display);
  font-size: 1.6rem;
  font-weight: 600;
  margin: 36px 0 16px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.section-title .emoji { font-size: 1.5rem; }
.section-subtitle {
  font-size: 1rem;
  color: var(--text-muted);
  margin: -12px 0 16px;
}

/* ─── MODEL CARDS ─── */
.model-card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 28px 24px;
  margin-bottom: 20px;
  border-left: 5px solid #ccc;
  transition: transform var(--transition);
}
.model-card:hover { transform: translateY(-2px); }
.model-card.card-blue { border-left-color: var(--blue); }
.model-card.card-green { border-left-color: var(--green); }
.model-card.card-orange { border-left-color: var(--orange); }
.model-card.card-purple { border-left-color: var(--purple); }
.model-card.card-pink { border-left-color: var(--pink); }
.model-card.card-teal { border-left-color: var(--teal); }

.model-card h2 {
  font-family: var(--font-display);
  font-size: 1.3rem;
  font-weight: 600;
  margin-bottom: 4px;
}
.model-card h3 {
  font-family: var(--font-display);
  font-size: 1.1rem;
  font-weight: 600;
  margin-bottom: 4px;
}

.tag {
  display: inline-block;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 20px;
  margin-bottom: 14px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.tag-blue { background: #e8f0fe; color: #1967d2; }
.tag-green { background: #e6f4ea; color: #137333; }
.tag-orange { background: #fef7e0; color: #b06000; }
.tag-purple { background: #f3e8ff; color: #7c3aed; }

.desc {
  color: var(--text-muted);
  font-size: 0.95rem;
  margin-bottom: 16px;
}

.when-to-use {
  background: #f8f9fa;
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  margin-bottom: 16px;
  font-size: 0.9rem;
}
.when-to-use strong { color: var(--text); }

/* ─── VISUALIZER CONTAINERS ─── */
.viz-box {
  margin: 16px 0 12px;
  padding: 20px;
  background: #fafbff;
  border-radius: 12px;
  border: 2px dashed #e0e0e0;
}

/* ─── BARS (reused from bar model explorer) ─── */
.bars { display: flex; flex-direction: column; gap: 10px; padding: 8px 0; }
.bar-row { display: flex; align-items: center; gap: 10px; }
.bar-row .label { min-width: 60px; font-size: 0.85rem; font-weight: 500; color: var(--text-muted); text-align: right; }
.bar-track { flex: 1; height: 36px; background: #eef0f5; border-radius: 8px; position: relative; overflow: hidden; }
.bar-fill {
  height: 100%; border-radius: 8px; transition: width 0.4s ease;
  display: flex; align-items: center; justify-content: flex-end;
  padding-right: 10px; font-weight: 600; font-size: 0.85rem; color: white; min-width: 32px;
}
.bar-fill.blue { background: linear-gradient(135deg, #4a90d9, #357abd); }
.bar-fill.green { background: linear-gradient(135deg, #34c759, #28a745); }
.bar-fill.orange { background: linear-gradient(135deg, #ff9500, #e68600); }
.bar-fill.pink { background: linear-gradient(135deg, #ff6b9d, #e85d8a); }
.bar-fill.purple { background: linear-gradient(135deg, #af52de, #9747c7); }
.bar-fill.teal { background: linear-gradient(135deg, #5ac8fa, #4ab7e8); }
.bar-fill.yellow { background: linear-gradient(135deg, #ffcc02, #e6b800); color: #333; }
.bar-fill.gray { background: linear-gradient(135deg, #b0b0b0, #909090); }
.bar-bracket { display: flex; align-items: center; justify-content: center; margin: 2px 0 4px; font-size: 0.85rem; font-weight: 600; color: var(--text-muted); }

.controls {
  display: flex; gap: 10px; flex-wrap: wrap; margin-top: 12px; align-items: center;
}
.controls label { font-size: 0.85rem; font-weight: 500; }
.controls input[type="range"] { width: 120px; accent-color: var(--blue); }
.controls .val { font-weight: 600; min-width: 28px; display: inline-block; }
.controls button, .btn {
  padding: 6px 16px; border: none; border-radius: var(--radius-xs); font-weight: 600;
  font-size: 0.85rem; cursor: pointer; transition: all var(--transition);
  background: var(--blue); color: white; font-family: var(--font-body);
}
.controls button:hover, .btn:hover { opacity: 0.85; transform: scale(1.03); }
.btn-green { background: var(--green); }
.btn-orange { background: var(--orange); }
.btn-purple { background: var(--purple); }
.btn-pink { background: var(--pink); }
.btn-outline { background: transparent; border: 2px solid var(--blue); color: var(--blue); }
.btn-outline:hover { background: var(--blue); color: white; }

.step-box {
  margin-top: 12px; padding: 12px 16px; background: #f0f4ff;
  border-radius: var(--radius-sm); font-size: 0.9rem; border-left: 3px solid var(--blue);
}
.step-box.green { background: #edf7ee; border-left-color: var(--green); }
.step-box.orange { background: #fef5e7; border-left-color: var(--orange); }
.step-box.purple { background: #f3e8ff; border-left-color: var(--purple); }

.op {
  display: inline-block; font-weight: 700; font-size: 1.1rem;
  padding: 2px 10px; border-radius: 6px; margin: 0 4px;
}
.op.add { background: #d3e3fd; color: #1967d2; }
.op.sub { background: #fce8e6; color: #d93025; }
.op.mul { background: #ceead6; color: #137333; }
.op.div { background: #fef7e0; color: #b06000; }

/* ─── GRID MODEL (Area Model) ─── */
.grid-model-container {
  margin: 12px 0;
}
.area-grid {
  display: grid;
  gap: 3px;
  margin-bottom: 12px;
  border-radius: 8px;
  overflow: hidden;
}
.area-cell {
  padding: 12px 8px;
  text-align: center;
  font-size: 0.85rem;
  font-weight: 600;
  min-height: 50px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
}
.area-cell .cell-label { font-size: 0.75rem; opacity: 0.8; margin-bottom: 2px; }
.area-cell .cell-value { font-size: 0.95rem; }
.area-cell .cell-product { font-size: 1rem; font-weight: 700; }
.area-cell.color-0 { background: #dbeafe; color: #1e40af; }
.area-cell.color-1 { background: #fce7f3; color: #9d174d; }
.area-cell.color-2 { background: #d1fae5; color: #065f46; }
.area-cell.color-3 { background: #fef3c7; color: #92400e; }
.area-cell.color-4 { background: #e0e7ff; color: #3730a3; }
.area-cell.color-5 { background: #f5d0fe; color: #6b21a8; }
.area-cell.color-6 { background: #ffe4e0; color: #9c4221; }
.area-cell.color-7 { background: #cffafe; color: #155e75; }

.area-total {
  text-align: center;
  padding: 12px;
  font-size: 1.1rem;
  font-weight: 700;
  background: #f0fdf4;
  border-radius: var(--radius-xs);
  border: 2px solid #bbf7d0;
  margin-top: 8px;
}
.area-total .total-label { font-size: 0.85rem; color: var(--text-muted); font-weight: 400; }
.area-total .total-value { font-size: 1.4rem; color: #166534; }

.area-breakdown {
  margin-top: 8px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: center;
}
.area-term {
  padding: 4px 12px;
  border-radius: 6px;
  font-size: 0.85rem;
  font-weight: 600;
}

/* Place value labels on grid edges */
.area-row-label, .area-col-label {
  padding: 6px 8px;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  text-align: center;
  background: #f3f4f6;
  border-radius: 4px;
}

/* ─── NUMBER LINE ─── */
.number-line-container {
  margin: 12px 0;
  padding: 20px 10px;
  position: relative;
}
.nl-svg {
  width: 100%;
  height: 80px;
  display: block;
}
.nl-marker {
  fill: var(--blue);
  cursor: pointer;
  transition: cx 0.3s ease;
}
.nl-label {
  font-size: 0.75rem;
  font-weight: 500;
  fill: var(--text-muted);
  text-anchor: middle;
}
.nl-midpoint {
  stroke: #ccc;
  stroke-dasharray: 4 3;
}
.nl-half-label {
  font-size: 0.7rem;
  fill: #aaa;
  text-anchor: middle;
}

/* ─── STEP ENGINE ─── */
.step-engine {
  margin: 12px 0;
}
.step-indicator {
  display: flex;
  gap: 6px;
  margin-bottom: 12px;
  justify-content: center;
}
.step-dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  background: #ddd;
  transition: all var(--transition);
}
.step-dot.active { background: var(--purple); transform: scale(1.3); }
.step-dot.done { background: var(--green); }

.step-content {
  padding: 16px;
  background: #fafbff;
  border-radius: var(--radius-sm);
  border: 2px solid #e0e0e0;
  min-height: 60px;
  margin-bottom: 10px;
}
.step-content .step-title {
  font-weight: 600;
  font-size: 0.9rem;
  margin-bottom: 6px;
  color: var(--purple);
}
.step-actions {
  display: flex;
  gap: 8px;
  justify-content: center;
}

/* ─── PRACTICE CARDS ─── */
.practice-card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
  margin-bottom: 16px;
}
.practice-card .problem {
  font-size: 1.05rem;
  margin-bottom: 10px;
  line-height: 1.5;
}
.practice-card .problem-num {
  display: inline-block;
  background: var(--purple);
  color: white;
  width: 26px; height: 26px;
  border-radius: 50%;
  text-align: center; line-height: 26px;
  font-size: 0.8rem; font-weight: 700;
  margin-right: 8px;
}
.practice-card .hint-text {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 6px;
}
.practice-card .btn-row { display: flex; gap: 8px; flex-wrap: wrap; }

.answer-box {
  margin-top: 8px;
  display: none;
  padding: 12px 16px;
  background: #e8f5e9;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 1rem;
  color: #2e7d32;
}
.answer-box.show { display: block; }

.hint-box {
  display: none;
  margin-top: 8px;
  font-size: 0.9rem;
  color: #7c3aed;
  background: #f3e8ff;
  border-radius: var(--radius-sm);
  padding: 8px 12px;
}
.hint-box.show { display: block; }

/* ─── RESPONSIVE ─── */
@media (max-width: 480px) {
  .hero h1 { font-size: 1.8rem; }
  .container { padding: 16px 14px 40px; }
  .model-card { padding: 20px 16px; }
  .area-cell { padding: 8px 4px; font-size: 0.75rem; min-height: 40px; }
  .area-cell .cell-product { font-size: 0.85rem; }
  .controls input[type="range"] { width: 80px; }
}
