/* ============================================================================
   FORMULA SHEET — shared styles for The Magic Codex formula sheets.
   Screen: toolbar + collapsible mind-map tree. Print: ink-friendly, hides
   all site chrome and tool UI, expands every branch, exam mode blanks the
   formulas so the printout is a self-test worksheet.
   ============================================================================ */
:root { --fs-scale: 1; } /* text-size slider (70–130%), set on <html> by JS */

/* ---- toolbar ---- */
.fs-toolbar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 0.6rem 1rem;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; padding: 0.8rem 1rem; margin: 1.2rem 0;
}
.fs-toolbar .fs-ctl { display: flex; align-items: center; gap: 0.45rem; font-size: 0.92rem; }
.fs-toolbar select {
  font: inherit; padding: 0.45rem 0.6rem; border: 1px solid var(--border);
  border-radius: 8px; background: var(--surface); color: var(--ink);
  min-height: 44px; /* big tap target on phones */
}
.fs-toolbar .btn { min-height: 44px; }
.fs-toolbar input[type="range"] { min-height: 44px; accent-color: var(--violet); max-width: 130px; }
/* Legacy single-toggle exam button (still used by formula-sheet-builder). */
.fs-exam-state { font-weight: 700; }
#fs-exam-btn[aria-pressed="true"] { background: var(--violet); border-color: var(--violet); color: #fff; }
/* Exam mode segmented control: [ Offline | Online ]. */
.fs-exam-seg { display: inline-flex; align-items: center; gap: 0.45rem; }
.fs-exam-seg-label { font-size: 0.92rem; color: var(--ink-soft); }
.fs-exam-mode[aria-pressed="true"] { background: var(--violet); border-color: var(--violet); color: #fff; }

/* ---- online quiz ---- */
.fs-quiz {
  background: var(--surface); border: 1px solid var(--gold);
  border-radius: 12px; padding: 1.2rem 1.2rem 1.4rem; margin: 0 0 1.5rem;
}
.fs-quiz h3 { margin: 0 0 0.4rem; font-size: 1.5rem; }
.fs-quiz h4 { margin: 1.1rem 0 0.5rem; }
.fs-quiz-sub { color: var(--ink-soft); margin: 0 0 1rem; }
.fs-quiz-sub code { font-size: 0.9em; }
.fs-quiz-progress { font-weight: 700; color: var(--arcane); margin: 0 0 0.3rem; }
.fs-quiz-path {
  font-family: "Cormorant Garamond", Georgia, serif;
  font-size: 1.45rem; font-weight: 700; margin: 0 0 0.4rem;
}
.fs-quiz-hint { font-size: 0.93rem; color: var(--ink-soft); margin: 0 0 1rem; }
.fs-quiz-label { display: block; font-weight: 700; margin-bottom: 0.4rem; }
.fs-quiz-input {
  width: 100%; font: inherit; font-size: 1.1rem; padding: 0.8rem;
  border: 1px solid var(--border); border-radius: 10px; min-height: 52px;
  background: #fff; color: var(--ink); box-sizing: border-box;
}
.fs-quiz-actions { display: flex; gap: 0.7rem; margin-top: 0.9rem; flex-wrap: wrap; }
.fs-quiz-actions .btn { min-height: 48px; flex: 1 1 10rem; }
.fs-quiz-verdict { font-size: 1.3rem; font-weight: 700; margin: 0.6rem 0; }
.fs-quiz-verdict.ok { color: #2e7d32; }
.fs-quiz-verdict.bad { color: #b3261e; }
.fs-quiz-answer-label { font-weight: 700; margin: 0.6rem 0 0.2rem; }
.fs-quiz-answer {
  font-family: "Cormorant Garamond", Georgia, serif; font-size: 1.35rem; font-weight: 600;
  background: var(--parchment); border-radius: 8px; padding: 0.7rem 0.9rem; margin: 0 0 0.8rem;
}
.fs-quiz-your { color: var(--ink-soft); margin: 0 0 0.8rem; }
.fs-quiz-score { font-size: 1.35rem; font-weight: 700; margin: 0 0 0.6rem; }
.fs-quiz-missed { list-style: none; padding: 0; margin: 0 0 1.2rem; display: flex; flex-direction: column; gap: 0.8rem; }
.fs-quiz-missed li { border: 1px solid var(--border); border-radius: 10px; padding: 0.7rem 0.9rem; }
.fs-quiz-missed .fs-formula { font-size: 1.15rem; }
.fs-quiz-quit { margin: 1rem 0 0; }

/* ---- mind-map tree ---- */
#fs-tree { display: flex; flex-direction: column; gap: 1.1rem; margin: 0 0 1.5rem; }
.fs-topic {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; padding: 1rem 1.1rem;
}
.fs-topic-head,
.fs-topic-toggle {
  display: flex; align-items: center; gap: 0.6rem; width: 100%;
  background: none; border: 0; border-bottom: 2px solid var(--gold);
  padding: 0 0 0.35rem; margin: 0 0 0.7rem; cursor: pointer;
  font-family: "Cormorant Garamond", Georgia, serif;
  font-size: calc(1.35rem * var(--fs-scale, 1)); font-weight: 700; color: var(--ink); text-align: left;
  min-height: 44px;
}
.fs-topic-toggle .fs-twisty { width: 0.75em; height: 0.75em; }
.fs-topic-toggle[aria-expanded="true"] .fs-twisty { transform: rotate(45deg); }
.fs-branch { margin: 0.15rem 0; }
.fs-branch-head {
  display: flex; align-items: center; gap: 0.55rem; width: 100%;
  background: none; border: 0; padding: 0.5rem 0.3rem; cursor: pointer;
  font: inherit; font-weight: 700; font-size: calc(1.02rem * var(--fs-scale, 1)); color: var(--ink);
  text-align: left; border-radius: 8px; min-height: 44px;
}
.fs-branch-head:hover { background: var(--gold-soft, rgba(163,126,34,.08)); }
.fs-twisty {
  flex: none; width: 0.9em; height: 0.9em;
  border-right: 2.5px solid var(--violet); border-bottom: 2.5px solid var(--violet);
  transform: rotate(-45deg); transition: transform 0.15s ease; margin-left: 0.2rem;
}
.fs-branch-head[aria-expanded="true"] .fs-twisty { transform: rotate(45deg); }
.fs-children {
  margin-left: 1.05rem; padding-left: 0.9rem;
  border-left: 2px solid var(--border);
}
.fs-leaf {
  display: grid; grid-template-columns: minmax(9rem, 15rem) 1fr;
  gap: 0.4rem 1rem; padding: 0.42rem 0.3rem;
  border-bottom: 1px dotted var(--border); align-items: baseline;
}
.fs-leaf:last-child { border-bottom: 0; }
.fs-label { font-size: calc(0.93rem * var(--fs-scale, 1)); color: var(--ink-soft); }
.fs-formula {
  font-size: calc(1.06rem * var(--fs-scale, 1)); color: var(--ink); line-height: 1.5;
  font-family: "Cormorant Garamond", Georgia, serif; font-weight: 600;
}
.fs-formula sub, .fs-formula sup { font-size: 0.72em; }

/* Exam mode: hide formula values but keep their space, so the printed page
   is a blank worksheet with room to write answers. */
.fs-exam .fs-formula { visibility: hidden; }
.fs-exam .fs-leaf { border-bottom: 1px solid var(--border); }

/* Print-only header (course name on the paper). */
.fs-print-head { display: none; }

/* ---- customize panel ---- */
.fs-customize {
  background: var(--surface); border: 1px solid var(--gold);
  border-radius: 12px; padding: 1rem 1.1rem; margin: 0 0 1.2rem;
}
.fs-customize h3 { margin: 0 0 0.3rem; font-size: 1.25rem; }
.fs-customize h4 { margin: 1.1rem 0 0.5rem; font-size: 1.05rem; }
.fs-cust-sub { margin: 0 0 0.8rem; font-size: 0.93rem; color: var(--ink-soft); }
.fs-cust-row {
  display: grid; grid-template-columns: auto 1fr auto; gap: 0.15rem 0.7rem;
  align-items: start; padding: 0.5rem 0.3rem;
  border-bottom: 1px dotted var(--border); cursor: pointer;
}
.fs-cust-row:last-child { border-bottom: 0; }
.fs-cust-row input[type="checkbox"] { width: 1.25rem; height: 1.25rem; margin-top: 0.15rem; }
.fs-cust-label { font-weight: 700; }
.fs-cust-desc { grid-column: 2; font-size: 0.88rem; color: var(--ink-soft); }
.fs-cust-row.off .fs-cust-label { opacity: 0.55; text-decoration: line-through; }
.fs-cust-course { margin-bottom: 0.6rem; }
.fs-cust-course h4 { margin: 0.8rem 0 0.2rem; font-size: 1rem; color: var(--arcane); }
.fs-cust-note { font-size: 0.92rem; color: var(--ink-soft); }
.fs-mod-btn { min-height: 40px; }

/* Excluded topics: dimmed on screen so the choice stays visible. */
.fs-topic.fs-excluded { opacity: 0.45; }
/* Added cross-sheet modules: badge shows the source course. */
.fs-from {
  font-family: inherit; font-size: 0.72rem; font-weight: 600;
  border: 1px solid var(--gold); border-radius: 999px; padding: 0.1rem 0.55rem;
  color: var(--ink-soft); white-space: nowrap;
}

/* ============================================================================
   PRINT — ink-friendly, paper-sized, chrome-free.
   ============================================================================ */
@media print {
  /* Hide everything that is not the sheet itself (quiz never prints). */
  #site-header, #site-footer, .breadcrumbs, .fs-toolbar, .fs-customize,
  #fs-quiz,
  .page-head .lede, .card.guide, .card.faq, .card.promo, .card.donate,
  .codex-frame > .cf-art, .codex-frame > .cf-edge { display: none !important; }

  /* Topics unchecked in Customize never print. */
  .fs-topic.fs-excluded { display: none !important; }

  body { background: #fff !important; color: #000 !important; }
  .codex-frame { border: 0 !important; box-shadow: none !important; background: #fff !important; }
  .layout, main.layout > div { display: block !important; max-width: none !important; }

  .fs-print-head { display: block; margin-bottom: 0.6rem; }
  .fs-print-head h1 { font-size: calc(20pt * var(--fs-scale, 1)); margin: 0; color: #000; }
  .fs-print-head p { font-size: calc(10pt * var(--fs-scale, 1)); margin: 0.15rem 0 0; color: #333; }

  /* Always print the full tree expanded. */
  .fs-topic-body, .fs-children { display: block !important; }
  .fs-branch-head, .fs-topic-toggle { pointer-events: none; }
  .fs-twisty { display: none; }

  #fs-tree { gap: 0.55rem; }
  .fs-topic {
    background: #fff !important; border: 1px solid #999;
    border-radius: 0; padding: 0.45rem 0.6rem; break-inside: avoid;
  }
  .fs-topic-toggle {
    font-size: calc(13pt * var(--fs-scale, 1)); color: #000; border-bottom: 1.5px solid #000;
    padding-bottom: 0.2rem; margin-bottom: 0.4rem; min-height: 0;
  }
  .fs-branch-head { color: #000; font-size: calc(11pt * var(--fs-scale, 1)); min-height: 0; padding: 0.25rem 0; }
  .fs-children { border-left: 1px solid #bbb; }
  .fs-leaf { border-bottom: 1px dotted #bbb; padding: 0.22rem 0; break-inside: avoid; }
  .fs-label { color: #222; font-size: calc(10pt * var(--fs-scale, 1)); }
  .fs-formula { color: #000; font-size: calc(11.5pt * var(--fs-scale, 1)); }
  /* Exam mode on paper: formulas invisible, rows keep blank writing space. */
  .fs-exam .fs-formula { visibility: hidden; }
  .fs-exam .fs-leaf { border-bottom: 1px solid #666; min-height: 1.6em; }
}

/* ============================================================================
   PRINT LAYOUT SIMULATION (screen) — body.fs-print-sim mirrors the print
   stylesheet so users can eyeball the printer's view before printing.
   The toolbar stays visible (it holds the exit toggle); everything else
   matches @media print above. Keep the two blocks in sync.
   ============================================================================ */
body.fs-print-sim #site-header,
body.fs-print-sim #site-footer,
body.fs-print-sim .breadcrumbs,
body.fs-print-sim .fs-customize,
body.fs-print-sim #fs-quiz,
body.fs-print-sim .page-head .lede,
body.fs-print-sim .card.guide,
body.fs-print-sim .card.faq,
body.fs-print-sim .card.promo,
body.fs-print-sim .card.donate,
body.fs-print-sim .codex-frame > .cf-art,
body.fs-print-sim .codex-frame > .cf-edge { display: none !important; }
body.fs-print-sim .fs-topic.fs-excluded { display: none !important; }
body.fs-print-sim { background: #fff !important; color: #000 !important; }
body.fs-print-sim .codex-frame { border: 0 !important; box-shadow: none !important; background: #fff !important; }
body.fs-print-sim .layout,
body.fs-print-sim main.layout > div { display: block !important; max-width: none !important; }
body.fs-print-sim .fs-print-head { display: block; margin-bottom: 0.6rem; }
body.fs-print-sim .fs-print-head h1 { font-size: calc(20pt * var(--fs-scale, 1)); margin: 0; color: #000; }
body.fs-print-sim .fs-print-head p { font-size: calc(10pt * var(--fs-scale, 1)); margin: 0.15rem 0 0; color: #333; }
body.fs-print-sim .fs-topic-body,
body.fs-print-sim .fs-children { display: block !important; }
body.fs-print-sim .fs-branch-head,
body.fs-print-sim .fs-topic-toggle { pointer-events: none; }
body.fs-print-sim .fs-twisty { display: none; }
body.fs-print-sim #fs-tree { gap: 0.55rem; }
body.fs-print-sim .fs-topic {
  background: #fff !important; border: 1px solid #999;
  border-radius: 0; padding: 0.45rem 0.6rem;
}
body.fs-print-sim .fs-topic-toggle {
  font-size: calc(13pt * var(--fs-scale, 1)); color: #000; border-bottom: 1.5px solid #000;
  padding-bottom: 0.2rem; margin-bottom: 0.4rem; min-height: 0;
}
body.fs-print-sim .fs-branch-head { color: #000; font-size: calc(11pt * var(--fs-scale, 1)); min-height: 0; padding: 0.25rem 0; }
body.fs-print-sim .fs-children { border-left: 1px solid #bbb; }
body.fs-print-sim .fs-leaf { border-bottom: 1px dotted #bbb; padding: 0.22rem 0; }
body.fs-print-sim .fs-label { color: #222; font-size: calc(10pt * var(--fs-scale, 1)); }
body.fs-print-sim .fs-formula { color: #000; font-size: calc(11.5pt * var(--fs-scale, 1)); }
body.fs-print-sim .fs-exam .fs-formula { visibility: hidden; }
body.fs-print-sim .fs-exam .fs-leaf { border-bottom: 1px solid #666; min-height: 1.6em; }
/* Active state for the toggle button. */
#fs-printsim-btn[aria-pressed="true"] { background: var(--arcane); border-color: var(--arcane); color: #fff; }
