:root {
  --bg: #f8f4ef;
  --panel: #ffffff;
  --text: #2f251f;
  --muted: #6f6258;
  --line: #ddcec0;
  --brand: #c30000;
  --brand-soft: #f9dddd;
  --accent: #7a6f60;
  --success: #2f7d4f;
  --success-soft: #e3f3e8;
  --danger: #b33632;
  --piece-fill: #1d63d6;
  --piece-empty: #fffaf2;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Avenir Next", "Segoe UI", sans-serif;
  color: var(--text);
  background: radial-gradient(circle at top right, #fff8f3, var(--bg) 50%);
  min-height: 100vh;
}

h1, h2, p {
  margin: 0;
}

button {
  font: inherit;
  cursor: pointer;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 20px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, #fff, #fcf8f3);
  box-shadow: 0 4px 20px rgba(90, 52, 38, 0.08);
}

.mute-btn {
  flex-shrink: 0;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--panel);
  font-size: 1.3rem;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

.mute-btn:hover {
  border-color: var(--brand);
}

.brand-block {
  display: flex;
  align-items: center;
  gap: 14px;
}

.master-logo {
  width: 56px;
  height: 56px;
  object-fit: contain;
}

.topbar h1 {
  font-size: 1.5rem;
  color: var(--brand);
}

.topbar p {
  color: var(--muted);
  margin-top: 4px;
}

.layout {
  display: grid;
  grid-template-columns: 1fr;
  gap: 28px;
  max-width: 1100px;
  margin: 0 auto;
  padding: 28px 20px 40px;
}

.section-toggle-row {
  max-width: 1100px;
  margin: 0 auto;
  padding: 20px 20px 0;
}

.section-toggle {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 4px;
  gap: 4px;
  box-shadow: 0 4px 12px rgba(90, 52, 38, 0.06);
}

.section-toggle-btn {
  border: none;
  background: transparent;
  color: var(--muted);
  font-weight: 700;
  padding: 10px 18px;
  min-height: 44px;
  border-radius: 999px;
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 6px;
}

.section-toggle-btn.active {
  background: var(--success);
  color: #fff;
}

.section-toggle-btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.soon-badge {
  font-size: 0.65rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  background: var(--brand-soft);
  color: var(--brand);
  padding: 2px 6px;
  border-radius: 999px;
}

.bar-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
}

.bar-headline {
  text-align: center;
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text);
}

.skal-tip {
  text-align: center;
  color: var(--muted);
  font-size: 0.9rem;
  max-width: 40ch;
}

.skal-tip strong {
  color: var(--brand);
}

.fraction-display {
  display: flex;
  justify-content: center;
}

.frac {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  font-weight: 800;
  font-size: 2.4rem;
  line-height: 1.05;
  color: var(--text);
}

.frac-line {
  width: 100%;
  height: 3px;
  background: var(--text);
  margin: 2px 0;
}

.frac-num, .frac-den {
  text-align: center;
  min-width: 1.4ch;
}

.bar-wrap {
  width: 100%;
  max-width: 460px;
  display: flex;
  justify-content: center;
}

#eqBarSvg, #eqCompareBarSvg, #addABarSvg, #addBBarSvg, #addResultBarSvg {
  width: 100%;
  height: auto;
  display: block;
  filter: drop-shadow(0 8px 16px rgba(90, 52, 38, 0.18));
}

.combo-stack {
  width: 100%;
  max-width: 460px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.mini-bar-block {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 12px;
  border-radius: 14px;
}

.result-block {
  background: var(--panel);
  border: 2px dashed var(--line);
}

.mini-frac {
  font-size: 1.6rem;
}

.mini-bar-wrap {
  width: 100%;
}

.mini-controls {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
  width: 100%;
}

.control-pair {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
  flex: 1 1 180px;
  min-width: 160px;
}

.result-block .mini-controls {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  max-width: 260px;
}

button.mini-btn {
  padding: 10px 6px;
  min-height: 46px;
  font-size: 0.8rem;
  border-radius: 10px;
}

.operator-symbol {
  font-size: 2rem;
  font-weight: 800;
  color: var(--brand);
  line-height: 1;
}

.bar-outline {
  fill: none;
  stroke: var(--accent);
  stroke-width: 3;
  pointer-events: none;
}

.bar-cell {
  stroke: var(--accent);
  stroke-width: 2;
  transition: fill 0.2s ease;
  cursor: pointer;
}

.bar-cell.filled {
  fill: var(--piece-fill);
}

.bar-cell.empty {
  fill: var(--piece-empty);
}

.bar-cell.locked {
  cursor: default;
}

/* Teach Me: dims the bar except during a highlighted moment */
.bar-cell, .frac {
  transition: opacity 0.4s ease, fill 0.2s ease;
}

.teach-dim {
  opacity: 0.25;
}

.teach-glow {
  animation: teach-pulse 1.1s ease-in-out infinite;
}

@keyframes teach-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.8; }
}

.factor-row {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  max-width: 420px;
}

.factor-label {
  font-weight: 700;
  font-size: 0.85rem;
  color: var(--muted);
}

.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  max-width: 420px;
}

.chip-btn {
  background: #fff;
  border: 1px solid var(--line);
  color: var(--text);
  padding: 8px 14px;
  min-height: 40px;
  border-radius: 999px;
  font-size: 0.9rem;
  font-weight: 700;
}

.chip-btn.active {
  background: var(--piece-fill);
  border-color: var(--piece-fill);
  color: #fff;
}

.stepper-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  width: 100%;
  max-width: 420px;
}

.stepper-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

button.stepper-btn {
  padding: 10px 10px;
  min-height: 56px;
  font-size: 0.95rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
}

.btn-label {
  font-weight: 700;
  font-size: 0.9rem;
}

.btn-sub {
  font-weight: 600;
  font-size: 0.7rem;
  color: var(--muted);
}

button.ghost {
  background: #fff;
  border: 1px solid var(--line);
  color: var(--text);
  padding: 14px 18px;
  min-height: 56px;
  border-radius: 12px;
  font-weight: 600;
  font-size: 1rem;
}

button.ghost:hover {
  border-color: var(--brand);
  color: var(--brand);
}

button.ghost:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

button.ghost:disabled:hover {
  border-color: var(--line);
  color: var(--text);
}

button.primary {
  background: var(--brand);
  color: #fff;
  border: none;
  padding: 12px 22px;
  border-radius: 10px;
  font-weight: 700;
  box-shadow: 0 6px 16px rgba(195, 0, 0, 0.25);
}

button.primary:hover {
  background: #a80000;
}

button.primary.success {
  background: var(--success);
  box-shadow: 0 6px 16px rgba(47, 125, 79, 0.3);
}

button.primary.success:hover {
  background: #256a42;
}

button.secondary {
  background: var(--brand-soft);
  color: var(--brand);
  border: 1px solid var(--brand-soft);
  padding: 10px 16px;
  border-radius: 10px;
  font-weight: 600;
}

.speak-btn {
  background: var(--panel);
  border: 1px solid var(--line);
  color: var(--text);
  padding: 14px 20px;
  min-height: 52px;
  border-radius: 999px;
  font-weight: 600;
  font-size: 1rem;
}

.speak-btn:hover {
  border-color: var(--brand);
  color: var(--brand);
}

.side-panel {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.mode-tabs {
  display: flex;
  gap: 8px;
  border-bottom: 1px solid var(--line);
}

.mode-tab {
  flex: 1;
  background: none;
  border: none;
  padding: 16px 12px;
  min-height: 56px;
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--muted);
  border-bottom: 3px solid transparent;
}

.mode-tab.active {
  color: var(--brand);
  border-bottom-color: var(--brand);
}

.panel-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 20px;
  box-shadow: 0 6px 18px rgba(90, 52, 38, 0.06);
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.panel-card h2 {
  color: var(--brand);
  font-size: 1.2rem;
}

.teach-dots {
  display: flex;
  justify-content: center;
  gap: 8px;
}

.teach-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: none;
  background: var(--line);
  padding: 0;
}

.teach-dot.active {
  background: var(--brand);
  transform: scale(1.25);
}

.teach-dot.done {
  background: var(--success);
}

.teach-caption {
  text-align: center;
  font-size: 1.1rem;
  font-weight: 600;
  line-height: 1.5;
  color: var(--text);
  white-space: pre-line;
}

.teach-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.teach-nav .speak-btn {
  flex: 1;
}

#eqTeachCtaBtn {
  width: 100%;
}

.hint-text {
  color: var(--muted);
  line-height: 1.5;
}

.level-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.level-btn {
  background: #fff;
  border: 1px solid var(--line);
  color: var(--text);
  padding: 14px 10px;
  min-height: 56px;
  border-radius: 999px;
  font-size: 0.95rem;
  font-weight: 600;
  text-align: center;
}

.level-btn.active {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
}

.prompt-box {
  background: var(--brand-soft);
  border-radius: 14px;
  padding: 16px;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: center;
}

.prompt-label {
  color: var(--brand);
  font-weight: 700;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.prompt-primary {
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--text);
}

.prompt-secondary {
  font-size: 1rem;
  color: var(--muted);
}

.feedback {
  min-height: 1.6rem;
  font-weight: 700;
  text-align: center;
  border-radius: 10px;
  padding: 8px;
  font-size: 1.05rem;
}

.feedback.correct {
  color: var(--success);
  background: var(--success-soft);
  animation: feedback-pop 0.5s ease;
}

@keyframes feedback-pop {
  0% { transform: scale(0.7); opacity: 0; }
  60% { transform: scale(1.08); opacity: 1; }
  100% { transform: scale(1); }
}

.feedback.incorrect {
  color: var(--danger);
  background: #fbe9e8;
}

.practice-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
}

.score-line {
  text-align: center;
  color: var(--muted);
  font-size: 0.9rem;
}

.simplify-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: var(--success-soft);
  border-radius: 12px;
  padding: 12px 16px;
}

.simplify-frac {
  font-size: 1.3rem;
  color: var(--success);
}

.target-frac {
  font-size: 1.8rem;
}

.equation-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
}

.equation-eq {
  font-size: 1.6rem;
  font-weight: 800;
  color: var(--muted);
}

.equation-num-input {
  width: 52px;
  font-size: 1.3rem;
}

.frac.zero .frac-line,
.frac.zero .frac-den {
  display: none;
}

.frac-input {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.frac-input .frac-line {
  width: 56px;
}

.frac-input-field {
  width: 56px;
  text-align: center;
  font: inherit;
  font-weight: 800;
  font-size: 1.4rem;
  color: var(--text);
  border: 2px solid var(--line);
  border-radius: 8px;
  padding: 6px 2px;
  background: #fff;
  /* Hide the native up/down spinner so it doesn't crowd a 56px-wide box. */
  -moz-appearance: textfield;
}

.frac-input-field::-webkit-outer-spin-button,
.frac-input-field::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.frac-input-field:focus {
  outline: none;
  border-color: var(--brand);
}

.answer-input-row {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding-top: 6px;
  border-top: 1px dashed var(--line);
  width: 100%;
}

.compare-block {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding-top: 8px;
  border-top: 1px dashed var(--line);
}

.compare-bar-wrap {
  max-width: 360px;
}

.hidden {
  display: none !important;
}

.site-footer {
  text-align: center;
  padding: 20px;
  color: var(--muted);
  font-size: 0.85rem;
}

.site-footer a {
  color: var(--brand);
}

@media (min-width: 880px) {
  .layout {
    grid-template-columns: minmax(0, 1.1fr) minmax(0, 0.9fr);
    align-items: start;
  }
}

@media (max-width: 879px) {
  .bar-panel {
    position: sticky;
    top: 0;
    z-index: 5;
    background: var(--bg);
    gap: 10px;
    padding: 10px 12px 14px;
    border-bottom: 1px solid var(--line);
    box-shadow: 0 8px 12px -8px rgba(90, 52, 38, 0.15);
  }

  .bar-headline {
    font-size: 1rem;
  }

  .skal-tip {
    font-size: 0.8rem;
  }

  .frac {
    font-size: 1.8rem;
  }
}

@media (min-width: 1300px) {
  .topbar h1 {
    font-size: 1.8rem;
  }
}
