: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: minmax(0, 1fr);
  gap: 28px;
  max-width: 1100px;
  margin: 0 auto;
  padding: 28px 20px 40px;
}

.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: 42ch;
}

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

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

.big-number {
  display: inline-flex;
  font-weight: 800;
  font-size: 2.6rem;
  line-height: 1.05;
  color: var(--text);
  transition: opacity 0.4s ease;
}

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

.number-line-wrap {
  max-width: 420px;
}

#rlLineSvg {
  width: 100%;
  height: auto;
  display: block;
  overflow: visible;
}

.nl-line {
  stroke: var(--accent);
  stroke-width: 3;
}

.nl-tick {
  stroke: var(--accent);
  stroke-width: 3;
}

.nl-tick.mid {
  stroke: var(--brand);
  stroke-width: 3;
  stroke-dasharray: 5 4;
}

.nl-label {
  font-size: 15px;
  font-weight: 700;
  fill: var(--text);
  text-anchor: middle;
}

.nl-mid-label {
  font-size: 13px;
  font-weight: 800;
  fill: var(--brand);
  text-anchor: middle;
}

.nl-target-dot {
  fill: var(--brand);
  stroke: #fff;
  stroke-width: 2;
}

.nl-target-label {
  font-size: 16px;
  font-weight: 800;
  fill: var(--brand);
  text-anchor: middle;
}

/* Teach Me: dims the panel except during a highlighted moment */
.number-line-wrap, .fraction-display {
  transition: opacity 0.4s ease;
}

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

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

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

.endpoint-btn {
  background: #fff;
  border: 2px solid var(--line);
  color: var(--text);
  padding: 14px 10px;
  min-height: 64px;
  border-radius: 14px;
  font-size: 1.4rem;
  font-weight: 800;
  text-align: center;
  transition: transform 0.15s ease, background 0.2s ease, border-color 0.2s ease;
}

.endpoint-btn:hover:not(:disabled) {
  border-color: var(--brand);
}

.endpoint-btn:disabled {
  cursor: default;
}

.endpoint-btn.correct {
  background: var(--success);
  border-color: var(--success);
  color: #fff;
  transform: scale(1.04);
}

.endpoint-btn.incorrect {
  background: #fbe9e8;
  border-color: var(--danger);
  color: var(--danger);
}

.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;
}

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;
}

#rlTeachCtaBtn {
  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;
  line-height: 1.6;
  width: 100%;
}

.hint-blank {
  display: inline-block;
  min-width: 1.4em;
  padding: 0 6px;
  border: 2px dashed currentColor;
  border-radius: 6px;
}

.hint-sequence {
  display: block;
  margin-top: 4px;
  white-space: nowrap;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  text-align: left;
  padding-bottom: 2px;
}

.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;
}

.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 narrow box. */
  -moz-appearance: textfield;
}

.freeplay-input {
  width: 120px;
  font-size: 1.6rem;
}

.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%;
}

.midpoint-input-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.midpoint-input {
  width: 90px;
  font-size: 1.3rem;
}

.midpoint-solved {
  color: var(--success);
  font-weight: 700;
  font-size: 1.05rem;
}

.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;
  }

  .big-number {
    font-size: 2rem;
  }

  .endpoint-btn {
    font-size: 1.2rem;
  }
}

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