body {
  font-family: -apple-system, "Segoe UI", Arial, Helvetica, sans-serif;
  width: 90%;
  max-width: 1600px;
  margin: 0 auto;
  padding: 20px;
  color: #1a1a1a;
  line-height: 1.55;
}
header { border-bottom: 3px solid #ea580c; margin-bottom: 24px; }
.crumbs { color: #666; }
.crumbs a { color: #ea580c; }
h1 { margin-bottom: 4px; }
h2 { margin-top: 36px; border-bottom: 1px solid #e7e5e4; padding-bottom: 6px; }
.subtitle { font-size: 1.05em; color: #444; }
.note { color: #666; font-size: 0.95em; }
section { margin-bottom: 20px; }
.controls { display: flex; flex-wrap: wrap; gap: 14px; align-items: center; margin: 12px 0; }
.controls label { font-weight: 600; }
button {
  padding: 7px 16px; font-size: 1em; cursor: pointer;
  background: #ea580c; color: #fff; border: none; border-radius: 6px;
}
button:disabled { background: #bbb; cursor: default; }
button:hover:not(:disabled) { background: #c2410c; }
canvas { border: 1px solid #e7e5e4; background: #fff; max-width: 100%; height: auto; }
.equation { font-size: 1.25em; font-weight: 700; }
.swatch { display: inline-block; width: 22px; height: 4px; vertical-align: middle; }
.swatch.parent { background: #999; }
.swatch.transformed { background: #1f6feb; }
.swatch.inverse { background: #0a7a42; }
.swatch.hole { background: #fff; border: 2px solid #d32f2f; border-radius: 50%; width: 10px; height: 10px; }
table { border-collapse: collapse; margin: 10px 0; }
th, td { border: 1px solid #e7e5e4; padding: 6px 12px; text-align: left; }
th { background: #fef3c7; }
article { background: #fff7ed; border-left: 4px solid #ea580c; padding: 10px 16px; margin: 14px 0; }
/* Worked examples: steps on the left, live animation on the right. */
.example { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 20px; align-items: start; }
.example-anim canvas { width: 100%; }
.anim-controls { display: flex; gap: 10px; align-items: center; margin-top: 8px; flex-wrap: wrap; }
.anim-status { color: #555; font-size: 0.95em; }
.anim-note { color: #555; font-size: 0.9em; margin: 6px 0 0; }
.red-dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; background: #d32f2f; vertical-align: middle; margin-right: 4px; }
@media (max-width: 1100px) {
  .example { grid-template-columns: 1fr; }
  .example-anim canvas { max-width: 420px; }
}
#questionCard { border: 1px solid #e7e5e4; border-radius: 8px; padding: 16px; margin-top: 10px; box-shadow: 0 1px 3px rgba(0,0,0,.08); }
#questionText { font-size: 1.1em; font-weight: 600; }
#feedback { font-weight: 700; }
#feedback.good { color: #0a7a42; }
#feedback.bad { color: #b3261e; }
#hintBox, #solutionBox {
  background: #fff8e1; border: 1px solid #e8c547; border-radius: 6px;
  padding: 10px 14px; margin-top: 10px;
}
.hidden { display: none; }
#answerArea label { display: block; margin: 6px 0; cursor: pointer; }
#answerArea input[type="number"] { width: 90px; padding: 5px; font-size: 1em; }
footer { margin-top: 40px; border-top: 1px solid #e7e5e4; color: #666; font-size: 0.9em; }

/* Two-column layout: explanation on the left, practice on the right.
   The practice panel sticks in view so students can read the lesson
   and answer questions without scrolling back and forth. */
main {
  display: grid;
  grid-template-columns: 1.15fr 0.85fr;
  gap: 28px;
  align-items: start;
}
#explorer, #examples, #summary { grid-column: 1; }
#practice {
  grid-column: 2;
  grid-row: 1 / 4;
  align-self: start;
  position: sticky;
  top: 16px;
  max-height: calc(100vh - 32px);
  overflow-y: auto;
  padding-right: 4px;
  /* Opaque background: the panel is nearly viewport-tall and sticky, so
     content scrolling up underneath it (e.g. the Printable Worksheet
     heading) would otherwise show through it and overlap its buttons. */
  background: #fff;
  /* z-index is the other half of the same fix: background alone is not
     enough — without an explicit z-index, sliding content can paint
     above a z-auto sticky panel. The panel must sit above everything
     scrolling under it. */
  z-index: 10;
}
@media (max-width: 1100px) {
  main { display: block; }
  #practice {
    position: static;
    max-height: none;
    overflow: visible;
    padding-right: 0;
  }
}

/* Once a worksheet is generated, unstick the Practice panel so it no
   longer covers the sheet on screen. Only applies while body has the
   ws-open class (added by generateWorksheet); reload restores sticky. */
body.ws-open #practice { position: static; max-height: none; overflow-y: visible; }

/* Stacked fractions: numerator over denominator with a real fraction bar. */
.mfrac { display: inline-block; vertical-align: middle; text-align: center; font-size: 0.85em; line-height: 1.15; }
.mfrac .mnum { display: block; padding: 0 0.2em; }
.mfrac .mden { display: block; border-top: 1.5px solid currentColor; padding: 0 0.2em; }

/* Printable Worksheet (screen view of the generated sheet).
   Lives inside #practice, after the mistakes list, so it travels
   with the right-hand panel: it sticks with the panel and scrolls
   inside it. No grid positioning needed. */
#wsSheet { margin-top: 16px; border: 1px solid #e7e5e4; border-radius: 8px; padding: 20px 24px; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.08); }
.ws-head h2 { margin-top: 0; border-bottom: 2px solid #1a1a1a; padding-bottom: 6px; }
.ws-topic { color: #444; }
.ws-fields { display: flex; gap: 48px; flex-wrap: wrap; }
.ws-blank { display: inline-block; width: 220px; border-bottom: 1px solid #1a1a1a; }
.ws-q { margin: 18px 0; break-inside: avoid; page-break-inside: avoid; }
.ws-stem { font-size: 1.05em; margin: 0 0 6px; }
.ws-options { margin: 4px 0 4px 24px; }
.ws-options li { margin: 3px 0; }
.ws-graph { display: block; max-width: 420px; width: 100%; height: auto; border: 1px solid #e7e5e4; margin: 8px 0; }
.ws-answer-line { margin: 6px 0; }
.ws-work { height: 72px; background-image: linear-gradient(#e7e5e4 1px, transparent 1px); background-size: 100% 24px; }
.ws-key { page-break-before: always; break-before: page; }
.ws-key h2 { border-bottom: 2px solid #1a1a1a; padding-bottom: 6px; }
.ws-key li { margin: 4px 0; }

/* Print: only the generated worksheet sheet prints. Everything else
   (header, explorer, examples, summary, footer, the practice
   questions and the worksheet controls) is hidden, so no blank
   pages sneak in. NOTE: #worksheet lives inside #practice, so the
   panel itself must stay visible (unclipped, un-stuck) while all
   its other children are hidden — hiding #practice would hide
   the sheet with it. */
@media print {
  body { width: 100%; max-width: none; padding: 0; }
  header, .crumbs, footer, #explorer, #examples, #summary { display: none !important; }
  main { display: block !important; }
  #practice { display: block !important; position: static !important; max-height: none !important; overflow: visible !important; }
  #practice > :not(#worksheet) { display: none !important; }
  #worksheet { display: block !important; }
  #worksheet > h2, #worksheet > p, #wsControls { display: none !important; }
  #wsSheet { border: none; border-radius: 0; padding: 0; }
  .ws-q { break-inside: avoid; page-break-inside: avoid; }
  .ws-graph { break-inside: avoid; page-break-inside: avoid; }
  .ws-key { break-before: page; page-break-before: always; }
}

@page { size: Letter; margin: 0.6in; }
