*, *::before, *::after { box-sizing: border-box; }

body { overflow-x: hidden; }
header .main-title { margin-bottom: 0; }
.main-content { min-width: 0; }

.fraction-tutor-page {
  gap: 1.5rem;
  overflow: hidden;
  min-width: 0;
}

.fraction-hero {
  max-width: 900px;
  margin: 0 auto .4rem;
  text-align: center;
}

.hero-kicker {
  display: inline-block;
  margin-bottom: .55rem;
  color: #5e78ad;
  font-size: .72rem;
  font-weight: 900;
  letter-spacing: .12em;
}

.fraction-hero h1 {
  margin: 0 0 .7rem;
  color: var(--primary-color, #2f66d8);
  font: 700 clamp(2rem, 4vw, 3.15rem)/1.15 'Raleway', sans-serif;
  overflow-wrap: anywhere;
}

.fraction-hero p {
  max-width: 760px;
  margin: 0 auto;
  color: #4a5568;
  font-size: 1.06rem;
  line-height: 1.65;
  text-align: center;
}

.fraction-tool {
  --blue: #3f73c9;
  --blue-dark: #2d5fae;
  --blue-soft: #edf5ff;
  --rose: #e69aa4;
  --rose-soft: #fff1f3;
  --gold: #c58a2d;
  --gold-soft: #fff7e9;
  --mint: #559b78;
  --mint-soft: #eef9f3;
  --ink: #172033;
  --muted: #64748b;
  width: 100%;
  max-width: 1040px;
  margin: 0 auto 1.8rem;
  padding: 26px 22px 32px;
  background: #f5f8fc;
  border: 1px solid #e7edf5;
  border-radius: 20px;
  color: var(--ink);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Arial, sans-serif;
}

.problem-setup {
  max-width: 820px;
  margin: 0 auto;
}

.operation-switch {
  display: flex;
  justify-content: center;
  gap: 8px;
  width: fit-content;
  max-width: 100%;
  margin: 0 auto 14px;
  padding: 5px;
  background: #eef3fa;
  border: 1px solid #dbe4f0;
  border-radius: 14px;
}

.operation-choice {
  min-width: 140px;
  min-height: 44px;
  padding: 0 18px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: #53657d;
  font: 750 .98rem/1 system-ui, sans-serif;
  cursor: pointer;
  transition: background .16s, color .16s, box-shadow .16s, transform .16s;
}

.operation-choice:hover { background: rgba(255,255,255,.72); }

.operation-choice.active {
  color: #2457bf;
  background: #fff;
  box-shadow: 0 5px 14px rgba(45,72,110,.10);
}

.op-symbol {
  margin-right: 7px;
  font-size: 1.15em;
}

.setup-card {
  display: grid;
  grid-template-columns: minmax(120px,1fr) auto minmax(120px,1fr) minmax(170px,auto);
  gap: 18px;
  align-items: center;
  padding: 20px 22px;
  background: #fff;
  border: 1px solid #e2e9f2;
  border-radius: 16px;
  box-shadow: 0 10px 28px rgba(42,61,92,.08);
}

.fraction-entry {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 7px;
}

.entry-label {
  color: var(--muted);
  font-size: .8rem;
  font-weight: 750;
}

.fraction-input {
  display: grid;
  grid-template-rows: 44px 3px 44px;
  width: 82px;
  align-items: center;
}

.fraction-input input {
  width: 100%;
  height: 40px;
  padding: 4px 7px;
  border: 2px solid #d5deea;
  border-radius: 10px;
  background: #fbfdff;
  color: var(--ink);
  font: 750 1.2rem/1 system-ui, sans-serif;
  text-align: center;
  outline: none;
  transition: border-color .16s, box-shadow .16s, background .16s;
}

.fraction-input input::placeholder { color: #a7b2c2; }

.fraction-input input:focus {
  border-color: #8fb0e6;
  background: #fff;
  box-shadow: 0 0 0 4px rgba(63,115,201,.10);
}

.fraction-line {
  height: 2px;
  margin: 0 4px;
  background: #29364a;
  border-radius: 999px;
}

.setup-operator {
  color: #42556f;
  font-size: 2rem;
  font-weight: 700;
}

.setup-actions {
  display: grid;
  gap: 8px;
  min-width: 170px;
}

.btn-start,
.btn-random,
.btn-help,
.step-choice,
.check-step,
.summary-button,
.hint-help {
  font-family: inherit;
  cursor: pointer;
  transition: transform .16s, box-shadow .16s, background .16s, border-color .16s;
}

.btn-start,
.btn-random {
  min-height: 46px;
  padding: 0 17px;
  border-radius: 11px;
  font-size: .9rem;
  font-weight: 800;
}

.btn-start {
  border: 0;
  background: var(--blue);
  color: #fff;
  box-shadow: 0 6px 14px rgba(63,115,201,.18);
}

.btn-start:hover {
  background: var(--blue-dark);
  transform: translateY(-1px);
}

.btn-random {
  border: 1px solid #b7c9e2;
  background: #f8fbff;
  color: #3d638f;
}

.btn-random:hover {
  background: #edf5ff;
  border-color: #92afd4;
  transform: translateY(-1px);
}

.btn-random i { margin-right: 6px; }

.setup-message {
  min-height: 1.35em;
  margin: 10px auto 4px;
  color: #c84d59;
  font-size: .88rem;
  font-weight: 700;
  text-align: center;
}

.setup-message.ready { color: #3d7b5d; }

.setup-note {
  max-width: 680px;
  margin: 0 auto;
  color: var(--muted);
  font-size: .84rem;
  line-height: 1.5;
  text-align: center;
}

/* The Tutor starts here only after Start Tutor is pressed. */
.tutor-workspace {
  max-width: 920px;
  margin: 26px auto 0;
}

.equation-stage {
  position: relative;
  min-height: 390px;
  padding: 26px 24px 24px;
  background: #fff;
  border: 1px solid #e1e8f1;
  border-radius: 18px;
  box-shadow: 0 16px 38px rgba(34,50,78,.09);
}

.stage-kicker {
  margin-bottom: 12px;
  color: #6d86ad;
  font-size: .72rem;
  font-weight: 900;
  letter-spacing: .11em;
  text-align: center;
}

.equation-work {
  display: grid;
  gap: 19px;
  justify-content: center;
  min-height: 205px;
  padding: 12px 0 14px;
  color: #15243a;
}

.work-row {
  display: grid;
  grid-template-columns: 112px 44px 112px;
  align-items: center;
  justify-content: center;
  min-height: 104px;
  font-family: Georgia, 'Times New Roman', serif;
}

.work-row.result-row,
.work-row.simplify-row {
  grid-template-columns: 112px;
}

.work-row.row-muted {
  opacity: .84;
}

.row-connector {
  color: #8190a2;
  font-family: system-ui, sans-serif;
  font-size: 1rem;
  font-weight: 800;
  text-align: center;
}

.work-operator {
  color: #263b56;
  font-family: system-ui, sans-serif;
  font-size: 2.25rem;
  font-weight: 700;
  text-align: center;
}

.work-fraction {
  position: relative;
  display: grid;
  grid-template-rows: 43px 6px 43px;
  width: 98px;
  min-width: 98px;
  justify-self: center;
  align-items: center;
  font-size: 1.95rem;
  font-weight: 500;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.work-fraction .bar {
  height: 3px;
  margin: 0 2px;
  background: #172033;
  border-radius: 999px;
  box-shadow: 0 1px 0 rgba(23,32,51,.08);
}

.work-value {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
  height: 39px;
  border-radius: 9px;
}

.work-value.is-focus {
  color: #1f568e;
  background: #e8f2ff;
  outline: 3px solid #77a1db;
  outline-offset: -3px;
  box-shadow: 0 0 0 3px #fff;
}

.work-value.is-done {
  color: #254b77;
  background: #f1f6fc;
}

.work-value.is-placeholder {
  color: #9aa8ba;
  background: #f7f9fc;
  border: 1px dashed #cbd6e3;
  font-family: system-ui, sans-serif;
  font-size: 1.25rem;
  font-weight: 800;
}

.work-input {
  width: 68px;
  height: 39px;
  margin: 0 auto;
  padding: 0 6px;
  border: 2px solid #80a8de;
  border-radius: 8px;
  background: #fbfdff;
  color: #173960;
  font: 800 1.1rem/1 system-ui, sans-serif;
  text-align: center;
  outline: none;
  box-shadow: 0 0 0 4px rgba(63,115,201,.09);
}

.work-input:focus {
  border-color: #3f73c9;
  background: #fff;
}

.work-input.wrong {
  border-color: #d96a75;
  background: #fff7f7;
  box-shadow: 0 0 0 4px rgba(217,106,117,.08);
  animation: shake .35s ease-in-out;
}

@keyframes shake {
  0%,100% { transform: translateX(0); }
  33% { transform: translateX(-4px); }
  66% { transform: translateX(4px); }
}

.equation-hint {
  position: relative;
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 10px;
  width: min(430px, calc(100% - 16px));
  min-height: 64px;
  margin: 8px auto 0;
  padding: 11px 13px 11px 16px;
  color: #78551f;
  background: #fff8eb;
  border: 1px solid #edcf98;
  border-radius: 13px;
  box-shadow: 0 7px 18px rgba(111,78,25,.08);
}

.hint-arrow {
  position: absolute;
  top: -27px;
  left: var(--hint-x, 50%);
  transform: translateX(-50%);
  color: #bd8330;
  font-size: 1.55rem;
  font-weight: 900;
}

.hint-copy {
  display: grid;
  gap: 2px;
  min-width: 0;
  font-size: .9rem;
  line-height: 1.4;
}

.hint-copy strong {
  color: #6d4816;
  font-size: .95rem;
}

.hint-help {
  width: 38px;
  height: 38px;
  border: 2px solid #7da4dc;
  border-radius: 50%;
  background: #fff;
  color: #2f65b7;
  font-size: 1rem;
  font-weight: 900;
}

.hint-help:hover {
  background: #f0f6ff;
  transform: translateY(-1px);
}

.equation-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 9px;
  min-height: 42px;
  margin-top: 13px;
}

.step-choice,
.check-step {
  min-height: 40px;
  padding: 0 15px;
  border-radius: 10px;
  font-size: .88rem;
  font-weight: 800;
}

.step-choice {
  border: 1px solid #b8cce5;
  background: #f8fbff;
  color: #345f92;
}

.step-choice:hover {
  background: #edf5ff;
  border-color: #8eaed5;
  transform: translateY(-1px);
}

.check-step {
  border: 0;
  background: var(--blue);
  color: #fff;
  box-shadow: 0 5px 12px rgba(63,115,201,.16);
}

.check-step:hover {
  background: var(--blue-dark);
  transform: translateY(-1px);
}

.step-feedback {
  min-height: 1.5em;
  margin: 10px auto 0 !important;
  color: #5a6d84 !important;
  font-size: .86rem !important;
  font-weight: 750;
  text-align: center !important;
}

.step-feedback.good { color: #3c795c !important; }
.step-feedback.error { color: #bd4f59 !important; }

.visual-explanation {
  margin-top: 16px;
  padding: 16px 18px 17px;
  background: #f9fbfe;
  border: 1px solid #e0e8f2;
  border-radius: 15px;
}

.visual-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.visual-heading strong {
  color: #334a67;
  font-size: .92rem;
}

.visual-heading span {
  color: #718096;
  font-size: .8rem;
  text-align: right;
}

.models-area {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 16px;
  align-items: end;
}

.fraction-model { min-width: 0; }

.model-heading {
  min-height: 23px;
  margin-bottom: 7px;
  color: #50657e;
  font-size: .82rem;
  font-weight: 800;
  text-align: center;
}

.model-operator {
  align-self: center;
  color: #52677f;
  font-size: 1.55rem;
  font-weight: 800;
}

.fraction-strip {
  display: grid;
  width: 100%;
  height: 66px;
  overflow: hidden;
  border: 2px solid #8798ad;
  border-radius: 13px;
  background: #fff;
}

.fraction-piece {
  min-width: 0;
  border-right: 1px solid rgba(70,82,100,.34);
  background: #fff;
}

.fraction-piece:last-child { border-right: 0; }
.strip-a .fraction-piece.filled { background: #a7c9ef; }
.strip-b .fraction-piece.filled { background: #f3bcc2; }

.fraction-strip.recut { animation: recut .55s ease-out; }

@keyframes recut {
  0% { transform: scaleY(.88); opacity: .68; }
  55% { transform: scaleY(1.04); }
  100% { transform: scaleY(1); opacity: 1; }
}

.same-size-status {
  display: flex;
  justify-content: center;
  min-height: 38px;
  margin-top: 11px;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 7px 11px;
  border-radius: 999px;
  font-size: .8rem;
  font-weight: 800;
}

.status-pill.not-yet {
  color: #865b1b;
  background: var(--gold-soft);
  border: 1px solid #edd29f;
}

.status-pill.ready {
  color: #347457;
  background: var(--mint-soft);
  border: 1px solid #bfe0cf;
}

.controls {
  display: flex;
  justify-content: center;
  margin-top: 13px;
}

.btn-help {
  min-height: 42px;
  padding: 0 16px;
  border: 1px solid #9eb9de;
  border-radius: 11px;
  background: #fff;
  color: #315f9d;
  font-size: .9rem;
  font-weight: 800;
}

.btn-help:hover {
  background: #f1f7ff;
  transform: translateY(-1px);
}

.help-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 21px;
  height: 21px;
  margin-right: 7px;
  border: 1.5px solid #6f98d2;
  border-radius: 50%;
  font-size: .75rem;
  font-weight: 900;
}

.result-summary {
  display: none;
  max-width: 760px;
  margin: 22px auto 0;
  padding: 22px 10px 4px;
  border-top: 1px solid #dfe6ef;
  text-align: center;
}

.result-summary.show { display: block; }

.result-summary h2 {
  margin: 0 0 9px;
  color: #263e59;
  font-size: 1.28rem;
}

.result-summary p {
  max-width: 610px;
  margin: 0 auto 14px;
  color: #53657a;
  text-align: center;
}

.summary-button {
  min-height: 40px;
  padding: 0 14px;
  border: 1px solid #9eb9de;
  border-radius: 10px;
  background: #fff;
  color: #315f9d;
  font-weight: 800;
}

.summary-button:hover {
  background: #f1f7ff;
  transform: translateY(-1px);
}

.fraction-content {
  display: grid;
  gap: 1rem;
  max-width: 980px;
  margin: 0 auto;
}

.content-card {
  padding: 1.35rem 1.45rem;
  background: #fff;
  border: 1px solid #e6ebf1;
  border-radius: 15px;
  box-shadow: 0 6px 18px rgba(37,51,74,.05);
}

.content-card h2 {
  margin: 0 0 .7rem;
  color: #2c3e50;
  font-size: 1.35rem;
  text-align: left;
}

.content-card h3 {
  margin: .7rem 0 .2rem;
  color: #3c526c;
  font-size: 1rem;
}

.content-card p,
.content-card li {
  color: #526071;
  line-height: 1.65;
}

.content-card p {
  max-width: none;
  margin: .45rem 0;
  text-align: left;
}

.content-card ol {
  margin: .2rem 0 0;
  padding-left: 1.25rem;
}

.worked-example {
  display: grid;
  gap: 8px;
  max-width: 330px;
  margin: .9rem auto;
  padding: 14px 16px;
  background: #f8fbff;
  border: 1px solid #dce8f5;
  border-radius: 13px;
}

.worked-row {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 10px;
  align-items: center;
  color: #2f4866;
  font-weight: 800;
  text-align: center;
}

.worked-arrow { color: #7898bd; }

.worked-result {
  margin-top: 5px;
  padding-top: 9px;
  border-top: 1px solid #dbe5f0;
  color: #2c674d;
  font-weight: 900;
  text-align: center;
}

@media (max-width: 930px) {
  .setup-card {
    grid-template-columns: 1fr auto 1fr;
  }

  .setup-actions {
    grid-column: 1 / -1;
    grid-template-columns: 1fr 1fr;
    width: min(390px,100%);
    justify-self: center;
  }
}

@media (max-width: 760px) {
  .fraction-tool { padding: 20px 13px 26px; }

  .setup-card {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .setup-operator { text-align: center; }

  .fraction-entry {
    flex-direction: row;
    justify-content: center;
    gap: 15px;
  }

  .entry-label {
    width: 95px;
    text-align: right;
  }

  .setup-actions {
    grid-column: auto;
    grid-template-columns: 1fr;
    width: min(270px,100%);
  }

  .operation-switch {
    width: calc(100% - 12px);
  }

  .operation-choice {
    flex: 1 1 0;
    min-width: 0;
    padding: 0 10px;
  }

  .equation-stage {
    min-height: 365px;
    padding: 22px 12px 20px;
  }

  .work-row {
    grid-template-columns: 82px 32px 82px;
  }

  .work-row.result-row,
  .work-row.simplify-row {
    grid-template-columns: 82px;
  }

  .work-fraction {
    width: 72px;
    min-width: 72px;
    font-size: 1.55rem;
  }

  .models-area {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .model-operator {
    padding: 0;
    text-align: center;
  }

  .visual-heading {
    display: grid;
    gap: 3px;
    text-align: center;
  }

  .visual-heading span { text-align: center; }
}

@media (max-width: 440px) {
  .fraction-hero h1 { font-size: 1.9rem; }

  .fraction-tool {
    width: calc(100% + 8px);
    margin-left: -4px;
    margin-right: -4px;
  }

  .equation-stage { padding-left: 8px; padding-right: 8px; }

  .work-row {
    grid-template-columns: 74px 28px 74px;
  }

  .work-row.result-row,
  .work-row.simplify-row {
    grid-template-columns: 74px;
  }

  .work-fraction {
    width: 66px;
    min-width: 66px;
  }

  .work-input { width: 51px; }

  .equation-hint {
    width: calc(100% - 8px);
    grid-template-columns: 1fr auto;
  }
}

/* Completed equation: keep the final answer connected to the whole derivation. */
.complete-equation {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin: 13px auto 15px;
  color: #20384c;
  font-family: Georgia, 'Times New Roman', serif;
  font-size: 1.45rem;
  font-weight: 650;
}

.complete-equation .eq-symbol {
  color: #50657e;
  font-family: system-ui, sans-serif;
  font-size: 1.35rem;
  font-weight: 800;
}

.final-frac {
  display: inline-grid;
  grid-template-rows: 30px 4px 30px;
  width: 62px;
  align-items: center;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.final-frac .final-bar {
  height: 3px;
  margin: 0 2px;
  background: #172033;
  border-radius: 999px;
}

.final-whole {
  min-width: 30px;
  text-align: center;
}

@media (max-width: 760px) {
  .work-row {
    grid-template-columns: 98px 38px 98px;
    min-height: 96px;
  }

  .work-row.result-row,
  .work-row.simplify-row {
    grid-template-columns: 98px;
  }

  .work-fraction {
    width: 88px;
    min-width: 88px;
    grid-template-rows: 40px 6px 40px;
    font-size: 1.75rem;
  }
}

@media (max-width: 440px) {
  .work-row {
    grid-template-columns: 86px 32px 86px;
  }

  .work-row.result-row,
  .work-row.simplify-row {
    grid-template-columns: 86px;
  }

  .work-fraction {
    width: 78px;
    min-width: 78px;
    font-size: 1.6rem;
  }

  .work-input { width: 58px; }
  .complete-equation { gap: 7px; font-size: 1.22rem; }
  .final-frac { width: 54px; }
}
