:root {
  --ink: #1e293b;
  --bg: #f8fafc;
  --surface: #ffffff;
  --line: #e2e8f0;
  --math-purple: #7c3aed;
  --math-blue: #2563eb;
  --math-emerald: #059669;
  --math-amber: #d97706;
  --math-rose: #e11d48;
  --math-cyan: #0891b2;
  --math-pink: #db2777;
  --font-display: "Bricolage Grotesque", system-ui, sans-serif;
  --font-body: "Lexend", system-ui, sans-serif;
  --shadow: 0 8px 24px rgba(124, 58, 237, 0.08);
  --shadow-hover: 0 16px 36px rgba(124, 58, 237, 0.16);
  --radius-lg: 18px;
  --radius-md: 12px;
}

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

body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--ink);
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

header {
  background: #311042;
  color: #fff;
  padding: 0.9rem 1.4rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 1rem;
  border-bottom: 3px solid #c084fc;
  position: sticky;
  top: 0;
  z-index: 50;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  text-decoration: none;
  color: #fff;
}

.brand-icon {
  font-size: 2.2rem;
  background: rgba(192, 132, 252, 0.2);
  padding: 0.4rem;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.brand h1 {
  font-family: var(--font-display);
  font-size: 1.25rem;
  font-weight: 800;
  color: #f3e8ff;
  letter-spacing: -0.01em;
}

.brand p {
  font-size: 0.8rem;
  color: #d8b4fe;
}

.controls-bar {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
}

.tab-pills {
  display: flex;
  background: rgba(0, 0, 0, 0.25);
  padding: 0.25rem;
  border-radius: 999px;
  gap: 0.3rem;
}

.tab-btn {
  background: transparent;
  border: none;
  color: #e9d5ff;
  font-family: var(--font-body);
  font-size: 0.85rem;
  font-weight: 700;
  padding: 0.45rem 1rem;
  border-radius: 999px;
  cursor: pointer;
  transition: all 0.2s;
}

.tab-btn:hover {
  color: #fff;
}

.tab-btn.active {
  background: #c084fc;
  color: #311042;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.btn-header {
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.2);
  padding: 0.45rem 0.9rem;
  border-radius: 999px;
  font-family: var(--font-body);
  font-size: 0.82rem;
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  transition: all 0.2s;
}

.btn-header:hover {
  background: rgba(255, 255, 255, 0.25);
}

.game-container {
  max-width: 1200px;
  margin: 1.5rem auto;
  padding: 0 1.2rem;
  width: 100%;
  flex: 1;
}

.tab-pane {
  display: none;
  animation: fadeIn 0.25s ease-out;
}

.tab-pane.active {
  display: block;
}

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

.section-intro {
  margin-bottom: 1.5rem;
}

.section-intro h2 {
  font-family: var(--font-display);
  font-size: 1.5rem;
  color: #4c1d95;
}

.section-desc {
  color: #64748b;
  font-size: 0.95rem;
  margin-top: 0.3rem;
}

/* ================== TAB 1: FRACTION WALL ================== */
.wall-header {
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
  margin-bottom: 1.2rem;
}

.display-mode-selector {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}

.mode-label {
  font-weight: 700;
  font-size: 0.9rem;
  color: #475569;
}

.toggle-group {
  display: flex;
  background: #f1f5f9;
  border-radius: 999px;
  padding: 0.25rem;
  gap: 0.2rem;
  border: 1px solid var(--line);
}

.view-btn {
  background: transparent;
  border: none;
  padding: 0.4rem 0.9rem;
  border-radius: 999px;
  font-family: var(--font-body);
  font-size: 0.82rem;
  font-weight: 700;
  color: #475569;
  cursor: pointer;
  transition: all 0.2s;
}

.view-btn.active {
  background: var(--math-purple);
  color: #fff;
  box-shadow: 0 2px 6px rgba(124, 58, 237, 0.25);
}

.wall-highlight-info {
  background: #fdf4ff;
  border: 1.5px solid #f0abfc;
  border-radius: var(--radius-md);
  padding: 0.65rem 1rem;
  font-size: 0.9rem;
  color: #86198f;
  font-weight: 600;
}

.fraction-wall-wrap {
  position: relative;
  background: #ffffff;
  border: 2px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 1rem;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.laser-guide {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 3px;
  background: #ec4899;
  box-shadow: 0 0 10px #ec4899, 0 0 20px #ec4899;
  z-index: 10;
  pointer-events: none;
  display: none;
  transition: left 0.2s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.fraction-rows {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.wall-row {
  display: flex;
  height: 48px;
  width: 100%;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 1px 4px rgba(0,0,0,0.06);
}

.fraction-block {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  border-right: 1.5px solid rgba(255, 255, 255, 0.4);
  color: #ffffff;
  font-family: var(--font-body);
  font-weight: 800;
  font-size: 0.95rem;
  cursor: pointer;
  user-select: none;
  transition: transform 0.15s, filter 0.15s, box-shadow 0.15s;
  text-shadow: 0 1px 2px rgba(0,0,0,0.3);
}

.fraction-block:last-child {
  border-right: none;
}

.fraction-block:hover {
  filter: brightness(1.12);
  transform: scaleY(1.06);
  z-index: 2;
}

.fraction-block.highlighted {
  filter: brightness(1.2);
  box-shadow: inset 0 0 0 3px #ffffff, 0 0 14px rgba(255, 255, 255, 0.8);
  animation: pulseBlock 1.5s infinite;
  z-index: 5;
}

@keyframes pulseBlock {
  0% { transform: scaleY(1); }
  50% { transform: scaleY(1.08); }
  100% { transform: scaleY(1); }
}

.equivalence-ribbon {
  margin-top: 1.2rem;
  background: #ffffff;
  border: 2px solid var(--line);
  border-radius: var(--radius-md);
  padding: 0.9rem 1.4rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}

.ribbon-title {
  font-weight: 800;
  font-size: 0.95rem;
  color: var(--math-purple);
}

.ribbon-chips {
  display: flex;
  gap: 0.6rem;
  flex-wrap: wrap;
}

.equiv-chip {
  background: #ede9fe;
  border: 1.5px solid #c4b5fd;
  color: #5b21b6;
  font-weight: 800;
  font-size: 0.85rem;
  padding: 0.3rem 0.8rem;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
}

.chip-empty {
  color: #94a3b8;
  font-style: italic;
  font-size: 0.88rem;
}

/* ================== TAB 2: BALANCE SCALES ================== */
.scales-hud {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  margin-top: 0.8rem;
  background: #ffffff;
  padding: 0.6rem 1.2rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--line);
  flex-wrap: wrap;
}

.hud-stat {
  font-weight: 700;
  color: #334155;
}

.hud-stat span {
  color: var(--math-purple);
  font-size: 1.2rem;
}

#scale-status-msg {
  font-weight: 800;
  padding: 0.25rem 0.8rem;
  border-radius: 999px;
  background: #f1f5f9;
  font-size: 0.85rem;
}

#scale-status-msg.balanced {
  background: #dcfce7;
  color: #15803d;
}

.scales-stage {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.scale-svg-wrap {
  position: relative;
  background: #ffffff;
  border: 2px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  box-shadow: var(--shadow);
  display: flex;
  justify-content: center;
  min-height: 340px;
}

.balance-svg {
  width: 100%;
  max-width: 600px;
  height: 300px;
}

#scale-beam-group {
  transition: transform 0.6s cubic-bezier(0.34, 1.56, 0.64, 1);
  transform-origin: 300px 140px;
}

.scale-pans-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  justify-content: space-around;
  pointer-events: none;
  padding: 1.5rem;
}

.pan-box {
  pointer-events: auto;
  width: 140px;
  margin-top: 180px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.4rem;
}

.pan-label {
  font-size: 0.75rem;
  font-weight: 800;
  color: #64748b;
  text-transform: uppercase;
}

.pan-items {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  justify-content: center;
  min-height: 40px;
}

.scale-block-chip {
  background: var(--math-purple);
  color: #fff;
  border-radius: 6px;
  padding: 0.2rem 0.5rem;
  font-size: 0.8rem;
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 2px 4px rgba(0,0,0,0.15);
  transition: transform 0.15s;
}

.scale-block-chip:hover {
  transform: scale(1.1);
  background: #dc2626;
}

.scale-palette {
  background: #ffffff;
  border: 2px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 1.2rem;
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
}

.palette-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.6rem;
}

.palette-header h4 {
  font-size: 0.95rem;
  color: #334155;
}

.pan-selector {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.85rem;
  font-weight: 700;
}

.pan-pick-btn {
  background: #f1f5f9;
  border: 1.5px solid #cbd5e1;
  border-radius: 999px;
  padding: 0.3rem 0.8rem;
  font-family: var(--font-body);
  font-size: 0.8rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s;
}

.pan-pick-btn.active {
  background: var(--math-purple);
  color: #fff;
  border-color: var(--math-purple);
}

.blocks-tray {
  display: flex;
  gap: 0.6rem;
  flex-wrap: wrap;
}

.tray-block-btn {
  background: #f8fafc;
  border: 2px solid var(--line);
  border-radius: var(--radius-md);
  padding: 0.6rem 1rem;
  font-family: var(--font-body);
  font-size: 1rem;
  font-weight: 800;
  cursor: pointer;
  transition: all 0.2s;
  color: #fff;
  box-shadow: 0 2px 6px rgba(0,0,0,0.06);
}

.tray-block-btn:hover {
  transform: translateY(-3px);
  filter: brightness(1.1);
}

/* ================== TAB 3: FRACTION COMPARISON ================== */
.compare-stage {
  max-width: 780px;
  margin: 0 auto;
}

.compare-hud {
  display: flex;
  justify-content: space-between;
  background: #ffffff;
  padding: 0.8rem 1.4rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--line);
  margin-bottom: 1.2rem;
}

.compare-card {
  background: #ffffff;
  border: 2px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 2.2rem;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.compare-card h2 {
  font-family: var(--font-display);
  font-size: 1.45rem;
  color: #4c1d95;
}

.compare-duel {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1.5rem;
  background: #f8fafc;
  border-radius: var(--radius-lg);
  padding: 1.8rem;
  border: 1px solid var(--line);
}

.compare-frac-box {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.8rem;
}

.frac-symbol {
  font-family: var(--font-display);
  font-size: 2.6rem;
  font-weight: 800;
  color: var(--math-purple);
}

.frac-bar-visual {
  width: 100%;
  height: 24px;
  background: #e2e8f0;
  border-radius: 999px;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  background: linear-gradient(90deg, #a855f7, #7c3aed);
  border-radius: 999px;
  transition: width 0.3s;
}

.operator-target {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: #ffffff;
  border: 3px dashed #c084fc;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.8rem;
  font-weight: 800;
  color: var(--math-purple);
}

.operator-btns {
  display: flex;
  gap: 1rem;
  justify-content: center;
}

.op-btn {
  background: #ffffff;
  border: 2px solid #cbd5e1;
  border-radius: var(--radius-md);
  padding: 0.8rem 1.6rem;
  font-family: var(--font-body);
  font-size: 1.05rem;
  font-weight: 800;
  cursor: pointer;
  transition: all 0.2s;
  color: var(--ink);
}

.op-btn:hover {
  background: #fdf4ff;
  border-color: var(--math-purple);
  transform: translateY(-2px);
}

.op-btn.correct {
  background: #dcfce7 !important;
  border-color: #16a34a !important;
  color: #14532d !important;
}

.op-btn.wrong {
  background: #fee2e2 !important;
  border-color: #dc2626 !important;
  color: #7f1d1d !important;
}

.compare-exp {
  background: #fdf4ff;
  border: 1.5px solid #f0abfc;
  border-radius: var(--radius-md);
  padding: 1rem;
  font-size: 0.95rem;
  color: #701a75;
}

.compare-footer {
  display: flex;
  justify-content: flex-end;
}

/* ================== TAB 4: FDP MATCHER ================== */
.matcher-header {
  margin-bottom: 1.5rem;
}

.matcher-hud {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  background: #ffffff;
  padding: 0.7rem 1.2rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--line);
  margin-bottom: 0.5rem;
  flex-wrap: wrap;
}

.matcher-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1rem;
}

.matcher-card {
  background: #ffffff;
  border: 2px solid #cbd5e1;
  border-radius: var(--radius-md);
  min-height: 100px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--ink);
  cursor: pointer;
  transition: all 0.2s;
  box-shadow: 0 4px 10px rgba(0,0,0,0.05);
  user-select: none;
  padding: 0.6rem;
  text-align: center;
}

.matcher-card:hover {
  border-color: var(--math-purple);
  transform: translateY(-3px);
}

.matcher-card.selected {
  outline: 3px solid var(--math-purple);
  background: #fdf4ff;
}

.matcher-card.matched {
  background: #dcfce7 !important;
  border-color: #16a34a !important;
  color: #14532d !important;
  cursor: default;
  transform: none !important;
  animation: matchedPop 0.4s ease;
}

@keyframes matchedPop {
  50% { transform: scale(1.08); }
  100% { transform: scale(1); }
}

.matcher-card-sub {
  font-size: 0.75rem;
  font-family: var(--font-body);
  color: #64748b;
  font-weight: 600;
}

.btn-action {
  font-family: var(--font-body);
  font-size: 0.88rem;
  font-weight: 800;
  background: var(--math-purple);
  color: #fff;
  border: none;
  padding: 0.55rem 1.2rem;
  border-radius: 999px;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-action:hover {
  background: #6b21a8;
  transform: translateY(-2px);
}

.btn-danger {
  background: #fee2e2;
  color: #dc2626;
  border: 1px solid #fca5a5;
}

.btn-danger:hover {
  background: #fecaca;
}

@media (max-width: 800px) {
  .matcher-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  .compare-duel {
    flex-direction: column;
  }
}
