/* The Mathematician's Notebook — new-style theme.
   One fixed, light paper theme for the whole site, matching new-style.html.
   Loaded after app.css on every page; all old dark/white styling is replaced
   here so the whole site shares the exact same design language. */
@font-face {
  font-family: "EB Garamond Local";
  src: url("/static/fonts/eb-garamond-regular.ttf") format("truetype");
  font-style: normal;
  font-weight: 400 600;
  font-display: swap;
}
@font-face {
  font-family: "EB Garamond Local";
  src: url("/static/fonts/eb-garamond-italic.ttf") format("truetype");
  font-style: italic;
  font-weight: 400 500;
  font-display: swap;
}

:root {
  --paper: #f4f1ea;
  --paper-deep: #ece4d0;
  --paper-card: rgba(250, 247, 239, .8);
  --ink: #2c2b29;
  --ink-soft: #6b6862;
  --prose-ink: #3d3b37;
  --ink-faint: rgba(44, 43, 41, .55);
  --red-ink: #9c3b35;
  --blue-ink: #1a4066;
  --yellow-mark: rgba(255, 221, 89, .52);
  --line: rgba(44, 43, 41, .3);
  --grid: #e0dcce;
  --shadow-note: 5px 5px 0 rgba(44, 43, 41, .1);
  --font-text: "EB Garamond", "EB Garamond Local", Georgia, serif;
  --font-mono: "Space Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  --sans: var(--font-text);
  --ui-font: var(--font-text);
  --mono: var(--font-mono);
  /* Compatibility aliases used by the existing calculator and geometry UI. */
  --bg0: var(--paper);
  --bg1: var(--paper-deep);
  --card: var(--paper-card);
  --card2: rgba(250, 247, 239, .92);
  --stroke: var(--line);
  --text: var(--ink);
  --muted: var(--ink-soft);
  --muted2: var(--ink-faint);
  --accent: var(--red-ink);
  --accent2: var(--blue-ink);
  --danger: var(--red-ink);
  --shadow: var(--shadow-note);
  --max: 940px;
  --radius2: 0;
  --gap: 22px;
}

html, body {
  min-height: 100%;
  background: var(--paper);
}

html { scroll-behavior: smooth; }

body {
  margin: 0;
  color: var(--ink);
  font-family: var(--font-text);
  font-size: 19px;
  line-height: 1.7;
  font-feature-settings: "liga", "dlig";
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow-x: hidden;
}

/* Notebook grid — off by default (body.no-grid), toggled by notebook.js. */
body:not(.no-grid) {
  background-image:
    linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 28px 28px;
  background-position: -1px -1px;
}

body.no-grid { background-image: none; }

.bg { z-index: -2; }
.bg-grid { display: none; }
.bg-float span {
  color: rgba(44, 43, 41, .16) !important;
  font-family: var(--font-mono);
}
/* The construction studio has its own drawing surface. Keep the page clear
   of the decorative floating glyphs. */
body.geom-studio-page .bg-float { display: none; }

h1, h2, h3, h4, p { overflow-wrap: anywhere; }
h1, h2, h3, h4, h5, h6, .brand-title, .brand-sub,
.calc-suite-kicker, .calculator-card-cat, .site-menu-kicker, .site-menu-title,
.preview-title, .footerbar, .primary, .chip, .tab, .calc-field label {
  font-family: var(--font-text);
}

/* Paragraph copy uses the same Space Mono face as the geometry studio's
   "Point tool selected" status text. */
p {
  font-family: var(--font-mono) !important;
  font-size: 15px !important;
  color: var(--prose-ink) !important;
}

main ul,
main ol,
main li,
.bottom-help ul,
.bottom-help ol,
.bottom-help li,
.bottom-faq ul,
.bottom-faq ol,
.bottom-faq li,
.bottom-tools ul,
.bottom-tools ol,
.bottom-tools li {
  font-family: var(--font-mono) !important;
  font-size: 13px !important;
  color: var(--prose-ink) !important;
}

/* Form guidance uses the same Space Mono face as the surrounding prose. Keep
   entered mathematical expressions in their dedicated math typeface. */
input::placeholder,
textarea::placeholder,
.mq-input:not(.has-content)::before {
  font-family: var(--font-mono) !important;
}

select,
option {
  font-family: var(--font-mono) !important;
  font-size: 15px !important;
}

input,
textarea {
  font-size: 15px !important;
}

/* Calculator guidance beneath the INPUT marker and nested form-section copy
   are divs rather than paragraphs, so give them the same prose typography. */
.calc-builder-copy,
.loan-section-intro,
.fc-note {
  font-family: var(--font-mono) !important;
  color: var(--prose-ink) !important;
}

.calc-builder-copy,
.loan-section-intro {
  font-size: 15px !important;
}

/* FAQ questions and answers use the same face as the rest of the prose. */
.faq-q,
.faq-a,
.faq-answer,
.faq-item summary {
  font-family: var(--font-mono) !important;
}

.faq-a,
.faq-answer {
  font-size: 15px !important;
  color: var(--prose-ink) !important;
}

/* Keep prose consistent with new-style.html without the scattered italic
   treatment that had crept into cards, FAQs, and supporting copy. */
p,
.fc-note,
.faq-a,
.faq-item .faq-answer,
.tools-mini-desc,
.math-lesson-row small,
.geom-lead,
.geom-section-copy,
.geom-topic-copy,
.geom-definition,
.geom-example-copy,
.geom-studio-hint,
.ocr-tip {
  font-style: normal !important;
}

/* --- TOP BAR (nav) --- */
.topbar {
  position: relative;
  top: auto;
  z-index: 100;
  width: min(var(--max), calc(100% - 32px));
  max-width: none;
  min-height: 64px;
  margin: 0 auto;
  padding: 0 14px;
  border-bottom: 1px solid var(--ink);
  background: var(--paper);
}

.brand, .top-actions { position: relative; z-index: 1; }
.brand { gap: 10px; padding: 0 8px; background: transparent; }
.site-brand-logo {
  display: block;
  width: auto;
  height: 44px;
  max-width: min(240px, 46vw);
  object-fit: contain;
  object-position: left center;
}
.brand-title {
  color: var(--ink);
  font-size: 1.5rem;
  font-weight: 600;
  line-height: 1.1;
}
.brand-sub {
  color: var(--red-ink);
  font-family: var(--font-mono);
  font-size: .78rem;
  letter-spacing: 2px;
  text-transform: uppercase;
}
.logo {
  width: 36px;
  height: 36px;
  border: 1px solid var(--ink);
  border-radius: 50%;
  background: transparent;
  color: var(--red-ink);
  box-shadow: none;
  font-family: var(--font-mono);
  font-size: 22px;
}
.top-actions { gap: 8px; padding: 0 8px; background: transparent; }

.action-btn, .icon-btn, .grid-toggle, .chip, .tab, .step-trigger-link, .math-grade-pill, .btn-ink, .generate-btn {
  font-family: var(--font-mono);
}
.action-btn, .icon-btn, .grid-toggle {
  min-height: 38px;
  border: 1px solid var(--ink);
  border-radius: 0;
  background: transparent;
  color: var(--ink);
  box-shadow: none;
  font-size: 14px;
  transition: transform .18s ease, color .18s ease, background .18s ease;
}
.action-btn { height: 38px; padding: 0 12px; font-weight: 400; }
.action-btn:hover, .icon-btn:hover, .grid-toggle:hover { transform: translate(-1px, -1px); background: var(--ink); color: var(--paper); }
.ab-ico { color: var(--red-ink); }
.action-btn:hover .ab-ico { color: var(--paper); }
.icon-btn { width: 38px; height: 38px; border-radius: 0; }
.menu-btn { display: grid; place-items: center; }
.grid-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-width: 92px;
  padding: 5px 11px;
  cursor: pointer;
  font-size: 14px;
  letter-spacing: .04em;
  text-transform: uppercase;
}
.grid-toggle::before {
  content: "";
  width: 8px;
  height: 8px;
  flex: 0 0 8px;
  border-radius: 50%;
  background: #16845a;
  box-shadow: 0 0 0 3px rgba(22, 132, 90, .16);
}
.grid-toggle[data-state="on"] {
  border-color: #16845a;
  background: rgba(22, 132, 90, .13);
  color: #116445;
}
.grid-toggle[data-state="off"] {
  border-color: var(--red-ink);
  background: rgba(156, 59, 53, .13);
  color: var(--red-ink);
}
.grid-toggle[data-state="off"]::before {
  background: var(--red-ink);
  box-shadow: 0 0 0 3px rgba(156, 59, 53, .16);
}
.grid-toggle:focus-visible {
  outline: 3px solid rgba(255, 193, 7, .72);
  outline-offset: 2px;
}

/* --- SITE MENU --- */
.site-menu-panel {
  border: 1px solid var(--ink);
  border-radius: 0;
  background: var(--paper);
  box-shadow: var(--shadow-note);
}
.site-menu-backdrop { background: rgba(44, 43, 41, .18); backdrop-filter: blur(2px); }
.site-menu-title, .site-menu-link-title { color: var(--ink); }
.site-menu-kicker, .site-menu-link-desc { color: var(--red-ink); font-family: var(--font-mono); letter-spacing: 1px; }
.site-menu-head { align-items: center; }
.site-menu-head-actions { display: flex; align-items: center; justify-content: flex-end; gap: 8px; margin-left: auto; }
.site-menu-head .menu-grid-toggle { margin: 0; flex: 0 0 auto; }
.site-menu-link { border: 1px solid var(--line); border-radius: 0; background: rgba(250,247,239,.6); color: var(--ink); }
.site-menu-link:hover { background: rgba(250,247,239,.9); border-color: var(--red-ink); }
.site-menu-link-icon { border-radius: 50%; background: var(--ink); color: var(--paper); box-shadow: none; }
.site-menu-link-arrow { color: var(--red-ink); }
/* --- SITE-WIDE SEARCH --- */
body.site-search-open { overflow: hidden; }
.site-search-wrap {
  position: fixed;
  inset: 0;
  z-index: 13000;
  display: grid;
  place-items: start center;
  padding: max(22px, env(safe-area-inset-top)) 16px 22px;
  visibility: hidden;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s ease, visibility .2s ease;
}
.site-search-wrap.open {
  visibility: visible;
  opacity: 1;
  pointer-events: auto;
}
.site-search-backdrop {
  position: absolute;
  inset: 0;
  width: 100%;
  border: 0;
  background: rgba(44, 43, 41, .32);
  backdrop-filter: blur(3px);
  cursor: default;
}
.site-search-panel {
  position: relative;
  width: min(820px, 100%);
  max-height: calc(100dvh - 44px);
  overflow: auto;
  padding: 24px;
  border: 1px solid var(--ink);
  background: var(--paper);
  box-shadow: 8px 8px 0 rgba(44, 43, 41, .16);
  transform: translateY(-18px) scale(.985);
  transition: transform .22s ease;
}
.site-search-wrap.open .site-search-panel { transform: translateY(0) scale(1); }
.site-search-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 18px;
}
.site-search-head h2 {
  margin: 0;
  color: var(--ink);
  font-family: var(--font-text);
  font-size: 2rem;
  line-height: 1.1;
}
.site-search-head p {
  margin: 5px 0 0;
  color: var(--prose-ink);
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.5;
}
.site-search-form {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  border: 1px solid var(--ink);
  background: var(--paper-card);
}
.site-search-form:focus-within { border-color: var(--red-ink); box-shadow: 4px 4px 0 rgba(156, 59, 53, .14); }
.site-search-form-icon { display: grid; place-items: center; width: 44px; color: var(--red-ink); }
.site-search-form-icon svg { width: 21px; height: 21px; fill: currentColor; }
.site-search-form input {
  min-width: 0;
  padding: 13px 10px;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--ink);
  font-family: var(--font-mono);
  font-size: 15px;
  caret-color: var(--red-ink);
}
.site-search-form input::placeholder { color: var(--ink-soft); opacity: 1; }
.site-search-submit {
  align-self: stretch;
  padding: 0 17px;
  border: 0;
  border-left: 1px solid var(--ink);
  background: var(--ink);
  color: var(--paper);
  font-family: var(--font-mono);
  font-size: 13px;
  cursor: pointer;
}
.site-search-status {
  min-height: 22px;
  margin: 10px 0 12px;
  color: var(--ink-soft);
  font-family: var(--font-mono);
  font-size: 12px;
}
.site-search-results {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}
.site-search-result { padding: 17px 18px; }
.site-search-result h3 {
  margin: 0 0 7px;
  color: var(--ink);
  font-family: var(--font-text);
  font-size: 1.3rem;
  line-height: 1.2;
}
.site-search-result p { margin: 0; font-size: 13px !important; line-height: 1.55; }
.site-search-result-meta {
  display: block;
  margin-top: 10px;
  color: var(--red-ink);
  font-family: var(--font-mono);
  font-size: 12px;
}

/* --- LAYOUT --- */
.wrap, .bottom-help, .bottom-faq, .bottom-tools {
  width: min(var(--max), calc(100% - 32px));
  max-width: none;
  margin-left: auto;
  margin-right: auto;
  padding-left: 14px;
  padding-right: 14px;
}
.wrap { margin-top: 26px; margin-bottom: 62px; }
.main-col { gap: 28px; }

.panel {
  position: relative;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  color: var(--ink);
}
.page-ad-slot { opacity: .72; }

/* Corner brackets — the worksheet treatment from new-style.html. */
.input-panel, .calc-suite-panel, .output-panel, .help-panel, .faq-panel,
.calculator-directory-panel, .geom-hero-panel, .geom-studio-panel,
.geom-simple-panel, .geom-live-panel {
  padding: 34px 36px;
}
.input-panel {
  border: 1px solid var(--ink);
  background: var(--paper-card);
  box-shadow: 8px 8px 0 rgba(44, 43, 41, .05);
}
.input-panel::before, .input-panel::after {
  content: "";
  position: absolute;
  width: 20px;
  height: 20px;
  border: 1px solid var(--ink);
  pointer-events: none;
}
.input-panel::before {
  top: -5px; left: -5px;
  border-right: none; border-bottom: none;
}
.input-panel::after {
  bottom: -5px; right: -5px;
  border-left: none; border-top: none;
}

/* --- TITLES & MARKERS --- */
.section-marker, .calc-suite-kicker, .geom-kicker, .geom-section-kicker,
.geom-topic-number, .geom-category-kicker, .preview-title, .inline-answer-label,
.site-menu-kicker, .answer-mode-label, .math-subject-number, .math-lesson-number {
  font-family: var(--font-mono);
  font-size: .85rem;
  color: var(--red-ink);
  letter-spacing: 2px;
  text-transform: uppercase;
}
.solver-page-title, .calc-suite-title, .help-title, .geom-title,
.geom-section-title, .geom-category-title, .geom-topic-title,
.tools-title, .faq-title, .calculator-group-title {
  font-family: var(--font-text);
  color: var(--ink);
  font-weight: 600;
}
.solver-page-title, .calc-suite-title, .geom-title, .fc-title {
  display: inline-block;
  max-width: 100%;
}
.solver-page-title { font-size: clamp(38px, 6vw, 64px); line-height: 1.08; margin-bottom: 26px; font-weight: 400; }
.help-title, .faq-title, .tools-title, .geom-section-title, .calculator-group-title {
  font-size: 2.5rem;
  font-weight: 400;
  border-bottom: 1px solid var(--ink);
  padding-bottom: 10px;
  display: inline-block;
  margin-bottom: 14px;
}
.calc-suite-title { font-size: clamp(38px, 5vw, 56px); line-height: 1.08; font-weight: 400; }
.help-title { font-size: clamp(32px, 4vw, 48px); }
.faq-title { font-size: clamp(32px, 4vw, 48px); }
.tools-title { font-size: clamp(30px, 4vw, 44px); }
.calc-suite-sub, .calc-builder-copy, .help-lead, .help-note,
.calculator-group-sub, .calculator-card-desc {
  color: var(--ink-soft);
}
.calc-suite-sub { max-width: 740px; font-size: 20px; line-height: 1.5; }
.help-lead { max-width: 850px; font-size: 19px; line-height: 1.55; }
.help-note { font-size: 17px; line-height: 1.62; }
.manual-inline-link { color: var(--red-ink); text-decoration-color: var(--red-ink); }
p { margin-bottom: 20px; }

/* --- HOME SOLVER (worksheet) --- */
.tabs-container { border-bottom: 1px dashed var(--ink-faint); padding-bottom: 16px; flex-wrap: wrap; }
.tabs { gap: 6px; }
.tab {
  border: 1px solid var(--ink-soft);
  border-radius: 0;
  color: var(--ink-soft);
  background: transparent;
  font-size: .9rem;
  padding: 6px 16px;
}
.tab.active, .tab:hover { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.input-actions { align-items: center; flex-wrap: wrap; justify-content: flex-end; }
.sample-math-btn {
  min-height: 36px;
  padding: 6px 12px;
  border: 1px solid var(--red-ink);
  border-radius: 0;
  background: var(--red-ink);
  color: var(--paper);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.2;
  cursor: pointer;
  transition: transform .18s ease, background .18s ease, color .18s ease;
}
.sample-math-btn:hover { transform: translate(-1px, -1px); background: var(--ink); border-color: var(--ink); }
.sample-math-icon { width: 18px; height: 18px; display: inline-grid; place-items: center; flex: 0 0 18px; }
.sample-math-icon svg { width: 18px; height: 18px; fill: currentColor; }
.ibtn { border-radius: 0; border-color: var(--ink); color: var(--ink); background: transparent !important; }
.ibtn:hover { background: var(--ink) !important; color: var(--paper); filter: none; }
.input-bar { margin-top: 16px; }

/* Underline inputs — the worksheet-input style from new-style.html. */
.mq-input, .txt-input {
  min-height: 104px;
  border: none;
  border-bottom: 2px solid var(--ink);
  border-radius: 0;
  background: transparent !important;
  color: var(--blue-ink);
  box-shadow: none;
  font-family: var(--font-text);
  font-size: 1.5rem;
  padding: 10px 0;
}
.mq-input.mq-focused, .txt-input:focus { border-bottom-color: var(--red-ink); box-shadow: none; outline: none; }
.mq-input:not(.has-content)::before { color: var(--ink-faint); font-size: 15px; }
.mq-input .mq-root-block { font-size: 21px; }
.txt-input { font-family: var(--font-text); font-size: 15px; }

.primary {
  width: auto;
  min-height: 46px;
  padding: 10px 28px;
  border: 1px solid var(--ink);
  border-radius: 0;
  background: var(--ink);
  color: var(--paper);
  box-shadow: none;
  text-transform: uppercase;
  letter-spacing: 3px;
  font-size: 1rem;
}
.primary:hover { transform: translate(-1px, -1px); background: var(--red-ink); border-color: var(--red-ink); }
.primary-row { display: flex; justify-content: flex-start; }

.chip { border: 1px solid var(--ink); border-radius: 0; background: transparent; color: var(--ink); font-size: .9rem; padding: 6px 14px; }
.chip:hover, .chip.active { background: var(--ink); color: var(--paper); }

.preview-box, .inline-answer-box, .answer-box, .empty {
  border: 1px dashed var(--ink-faint);
  border-radius: 0;
  background: rgba(250, 247, 239, .6);
  color: var(--ink);
  box-shadow: none;
}
.step-trigger-link { border: 1px solid var(--ink); border-radius: 0; background: transparent; color: var(--ink); box-shadow: none; }
.step-trigger-link::before { border-radius: 50%; color: var(--paper); background: var(--red-ink); box-shadow: none; }
.step-trigger-link:hover { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.input-boot { border-radius: 0; background: var(--paper); color: var(--ink); }

/* --- CALCULATOR SUITE --- */
.calc-suite-panel { padding-top: 34px; }
.calc-suite-hero-with-icon { align-items: start; }
.calc-hero-icon {
  width: 72px; height: 72px;
  border: 1px solid var(--ink);
  border-radius: 50%;
  background: var(--paper-deep);
  color: var(--ink);
  box-shadow: none;
}
.calc-fields-grid { gap: 16px; }
.calc-field { gap: 6px; }
.calc-field label, .fc-label, .calc-mini-label, .input-group label {
  color: var(--ink-soft);
  font-family: var(--font-mono);
  font-size: .8rem;
  text-transform: uppercase;
  letter-spacing: 1px;
}
.fc-label { font-weight: 400; }
.fc-note { color: var(--ink-soft) !important; }

.calc-text-input, .calc-textarea, .calc-select, .answer-mode-select,
.directory-search-input, .calc-repeat-input, .calc-repeat-select,
.fc-num, .fc-select {
  min-height: 44px;
  border: none;
  border-bottom: 2px solid var(--ink);
  border-radius: 0;
  background: transparent !important;
  color: var(--blue-ink) !important;
  font-family: var(--font-text);
  font-size: 15px;
  box-shadow: none;
  padding: 8px 0;
}
.calc-textarea { min-height: 110px; line-height: 1.6; }
.calc-text-input:focus, .calc-textarea:focus, .calc-select:focus,
.answer-mode-select:focus, .directory-search-input:focus,
.calc-repeat-input:focus, .calc-repeat-select:focus,
.fc-num:focus, .fc-select:focus {
  outline: none;
  border-bottom-color: var(--red-ink);
}
.calc-toggle { border: 1px solid var(--ink); border-radius: 0; background: transparent; color: var(--ink); }
.loan-form-section, .calc-section-box { border: 1px solid var(--ink); border-radius: 0; background: rgba(250, 247, 239, .5); }
.loan-section-title, .loan-section-intro { color: var(--ink); }
.calc-mode-wrap { padding: 14px; border-left: 3px solid var(--red-ink); background: rgba(250, 247, 239, .5); }
.answer-mode-label { color: var(--red-ink); }
.calc-device-shell { border: 1px solid var(--ink); border-radius: 0; background: rgba(250, 247, 239, .7); box-shadow: var(--shadow-note); }
.calc-device-display {
  border: 1px solid var(--ink);
  border-radius: 0;
  background: var(--ink);
  color: var(--paper);
  box-shadow: none;
  font-family: var(--font-mono);
}
.calc-device-btn { border: 1px solid var(--ink); border-radius: 0; background: rgba(250, 247, 239, .7); color: var(--ink); font-family: var(--font-mono); }
.calc-device-btn:hover { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.calc-device-btn-accent { background: var(--red-ink); color: var(--paper); }

/* --- FRACTION CALCULATOR --- */
.fc-card {
  border: 1px solid var(--ink);
  border-radius: 0;
  background: rgba(250, 247, 239, .5);
  padding: 16px;
  min-height: 100%;
}
.fc-card-title { color: var(--ink); font-weight: 600; font-size: 1.1rem; }
.fc-operator-mark { color: var(--red-ink); }
.fc-frac-line { background: var(--ink); }
.fc-modebar .chip.active {
  color: var(--paper);
  background: var(--ink);
  border-color: var(--ink);
  box-shadow: none;
}

/* --- HELP SECTIONS --- */
.help-panel { padding: 34px 36px; }
.help-grid { gap: 18px; }
.help-box { border: 1px solid var(--ink); border-radius: 0; background: rgba(250, 247, 239, .5) !important; padding: 20px; }
.help-box h3 { color: var(--ink); font-size: 1.2rem; line-height: 1.3; }
.help-box h3::before { content: "∴ "; color: var(--red-ink); }
.help-box ul, .help-box ol { color: var(--ink-soft); }
.help-box li { color: var(--ink-soft); }
.help-box strong { color: var(--ink); }

/* --- FAQ (new-style accordion) --- */
.faq-panel { padding-bottom: 10px; }
.faq-list { margin-top: 24px; }
.faq-item {
  border: 0;
  border-bottom: 1px solid var(--ink-soft);
  border-radius: 0;
  background: transparent;
  padding: 25px 0;
  margin: 0;
  cursor: pointer;
}
.faq-q {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 16px;
  font-size: 1.3rem;
  font-weight: 600;
  color: var(--ink);
}
.faq-q .icon {
  flex: 0 0 auto;
  transition: transform .3s ease;
  font-family: var(--font-mono);
  color: var(--red-ink);
}
.faq-item.open .faq-q .icon { transform: rotate(45deg); }
.faq-a {
  max-height: 0;
  overflow: hidden;
  transition: max-height .4s ease, margin .4s ease;
  color: var(--ink-soft);
}
.faq-item.open .faq-a { max-height: 400px; margin-top: 15px; }
.faq-a p { margin-bottom: 10px; }
.faq-a a { color: var(--red-ink); }

/* Details-based FAQ fallback (same motion). */
.faq-item summary {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 16px;
  padding: 0;
  color: var(--ink);
  font-size: 1.3rem;
  font-weight: 600;
  cursor: pointer;
  list-style: none;
}
.faq-item summary::-webkit-details-marker { display: none; }
.faq-item summary::after {
  content: "+";
  transition: transform .3s ease;
  font-family: var(--font-mono);
  color: var(--red-ink);
}
.faq-item[open] summary::after { transform: rotate(45deg); }
.faq-item .faq-answer {
  max-height: 0;
  overflow: hidden;
  transition: max-height .4s ease, margin .4s ease;
  color: var(--ink-soft);
}
.faq-item[open] .faq-answer { max-height: 400px; margin-top: 15px; }

/* One compact FAQ treatment for both the JavaScript accordion and the native
   details fallback used before enhancement. */
.faq-q,
.faq-item summary {
  font-family: var(--font-mono) !important;
  font-size: 16px !important;
  font-weight: 600;
  line-height: 1.45;
}
.faq-a,
.faq-item .faq-answer {
  padding: 0 !important;
  border: 0 !important;
  font-family: var(--font-mono) !important;
  font-size: 15px !important;
  line-height: 1.65;
  color: var(--prose-ink) !important;
}
.faq-item.open .faq-a,
.faq-item[open] .faq-answer {
  margin-top: 12px;
}

/* --- CALCULATORS DIRECTORY (new-style index) --- */
.calculator-directory-panel { padding-bottom: 28px; }
.index-header { margin-bottom: 40px; }
.index-header .section-marker { margin-bottom: 15px; }
.index-header h1, .index-header h2 { border-bottom: 1px solid var(--ink); padding-bottom: 10px; display: inline-block; margin-bottom: 14px; }
.index-header p { color: var(--ink-soft); font-size: 1.05rem; }

.search-ledger {
  display: flex;
  align-items: stretch;
  gap: 0;
  margin-bottom: 30px;
  font-family: var(--font-mono);
  border: 1px solid var(--ink);
  background: var(--paper-card);
  box-shadow: 4px 4px 0 rgba(44, 43, 41, .08);
  scroll-margin-top: 24px;
}
.search-ledger:focus-within {
  border-color: var(--red-ink);
  box-shadow: 4px 4px 0 rgba(156, 59, 53, .14);
}
.search-ledger label {
  display: flex;
  align-items: center;
  color: var(--red-ink);
  flex: 0 0 auto;
  padding: 11px 14px;
  border-right: 1px dashed var(--ink-faint);
  font-size: 13px;
  letter-spacing: .5px;
}
.search-ledger input {
  flex: 1;
  border: none;
  background: transparent;
  font-family: var(--font-mono);
  font-size: 15px;
  outline: none;
  padding: 11px 14px;
  color: var(--ink);
  caret-color: var(--red-ink);
}
.search-ledger input::placeholder { color: var(--ink-soft); opacity: 1; }
.search-ledger input:focus { border: 0; box-shadow: none; }

.category-tabs { display: flex; gap: 12px; margin-bottom: 40px; flex-wrap: wrap; }

.index-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 24px; }
.index-card {
  display: block;
  border: 1px solid var(--ink-soft);
  padding: 25px;
  transition: all .2s;
  cursor: pointer;
  position: relative;
  background: rgba(250, 247, 239, .55);
  color: var(--ink);
  text-decoration: none;
}
.index-card:hover { border-color: var(--ink); transform: translateY(-4px); box-shadow: 5px 5px 0 var(--ink); }
.index-card .card-num { font-family: var(--font-mono); font-size: .8rem; color: var(--red-ink); margin-bottom: 10px; display: block; letter-spacing: 1px; }
.index-card h4 { font-size: 1.4rem; margin-bottom: 10px; font-weight: 600; }
.index-card p { font-size: .95rem; color: var(--ink-soft); margin: 0; }
.bottom-tools.related-content-section {
  display: block !important;
  width: min(var(--max), calc(100% - 32px));
  margin: 42px auto 38px;
  padding: 0 14px;
  box-sizing: border-box;
}
.related-content-section > .tools-title {
  margin: 0 0 20px;
  padding-bottom: 9px;
  border-bottom: 1px solid var(--ink);
  font-size: clamp(27px, 3vw, 34px);
  line-height: 1.15;
}
.related-content-grid {
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  align-items: stretch;
  gap: 18px;
  margin-top: 0;
}
.related-content-card {
  display: flex;
  min-width: 0;
  padding: 20px;
  flex-direction: column;
}
.related-content-card h4 { font-size: 1.25rem; line-height: 1.2; }
.related-content-card p { flex: 1; font-size: 13px !important; line-height: 1.6; }
.related-content-card .math-subject-link { margin-top: 16px; }

/* Legacy directory cards (kept for any page still using them). */
.calculator-group-section { padding: 24px 0 0; margin-top: 18px; border-top: 1px dashed var(--ink-faint); }
.calculator-group-section:first-of-type { border-top: 0; padding-top: 0; }
.calculator-group-title { font-size: 2.2rem; }
.calculator-group-head-fancy {
  margin: 0 0 24px;
  padding: 0 0 12px;
  border: 0;
  border-bottom: 1px solid var(--ink);
  border-radius: 0;
  background: transparent;
  overflow: visible;
}
.calculator-group-head-fancy::after { content: none; display: none; }
.calculator-group-title-fancy {
  margin: 0;
  background: none;
  color: var(--ink);
  font-family: var(--font-display);
  font-size: 2.2rem;
  font-weight: 600;
  line-height: 1.15;
}
.calculator-card-grid { gap: 14px; }
.calculator-card-mini {
  border: 1px solid var(--ink);
  border-radius: 0;
  background: rgba(250, 247, 239, .55);
  color: var(--ink);
  padding: 16px;
  box-shadow: none;
  text-decoration: none;
}
.calculator-card-mini:hover { transform: translate(-2px,-2px); border-color: var(--red-ink); background: rgba(250, 247, 239, .85); box-shadow: 4px 5px 0 rgba(156, 59, 53, .2); }
.calculator-card-icon { border: 1px solid var(--ink); border-radius: 50%; background: var(--paper-deep); color: var(--ink); }
.calculator-card-title { color: var(--ink); font-size: 1.1rem; }
.calculator-card-cat { color: var(--red-ink); font-family: var(--font-mono); font-size: .8rem; letter-spacing: 1px; }

/* --- HOME INSTRUMENT LIST (borderless listing) --- */
.bottom-tools { margin-top: 40px; }
.tools-panel { padding: 34px 36px; }
.tools-head-stack { margin-bottom: 30px; }
.tools-sub { color: var(--ink-soft); font-size: 1.05rem; max-width: 720px; }
.instrument-list { border-top: 2px solid var(--ink); margin: 30px 0 40px; }
.instrument {
  display: grid;
  grid-template-columns: 60px 1fr 40px;
  align-items: center;
  padding: 25px 0;
  border-bottom: 1px solid var(--grid);
  gap: 20px;
  transition: all .2s;
  cursor: pointer;
  text-decoration: none;
  color: var(--ink);
}
.instrument:hover { background: rgba(250, 247, 239, .5); padding-left: 10px; }
.instrument .num { font-family: var(--font-mono); color: var(--red-ink); font-size: .9rem; }
.instrument .icon { font-size: 2.5rem; text-align: center; color: var(--blue-ink); opacity: .8; }
.instrument h4 { font-size: 1.6rem; margin: 0 0 5px 0; font-weight: 600; }
.instrument p { font-size: 1rem; color: var(--ink-soft); margin: 0; }
.instrument .arrow { font-size: 1.5rem; color: var(--ink-soft); transition: transform .2s; }
.instrument:hover .arrow { transform: translateX(5px); color: var(--ink); }
.btn-ink {
  background: transparent;
  border: 1px solid var(--ink);
  color: var(--ink);
  padding: 8px 16px;
  cursor: pointer;
  transition: all .2s;
  font-size: .9rem;
}
.btn-ink:hover { background: var(--ink); color: var(--paper); }
.btn-ink.primary { background: var(--ink); color: var(--paper); }
.btn-ink.primary:hover { background: var(--red-ink); border-color: var(--red-ink); }
.tools-foot { margin-top: 6px; text-align: center; }
.tools-all-link {
  display: inline-block;
  border: 1px solid var(--ink);
  border-radius: 0;
  padding: 8px 16px;
  color: var(--ink);
  text-decoration: none;
  font-family: var(--font-mono);
  font-size: .9rem;
  background: transparent;
  font-weight: 400;
  transition: all .2s;
}
.tools-all-link:hover { background: var(--ink); color: var(--paper); }
.tools-mini-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 14px; }
.tools-mini-card {
  display: block;
  border: 0;
  border-bottom: 1px dashed var(--ink-faint);
  padding: 12px 2px;
  text-decoration: none;
  color: var(--ink);
}
.tools-mini-card:hover { padding-left: 8px; }
.tools-mini-title { display: block; font-weight: 600; font-size: 1.15rem; }
.tools-mini-desc { display: block; color: var(--ink-soft); font-size: .95rem; }

/* --- LESSONS PAGES --- */
.math-lessons-main { padding-bottom: 28px; }
.math-lessons-breadcrumb {
  display: flex;
  gap: 9px;
  align-items: center;
  margin: 0 0 14px;
  color: var(--ink-soft);
  font-family: var(--font-mono);
  font-size: .85rem;
}
.math-lessons-breadcrumb a, .geom-breadcrumbs a { color: var(--red-ink); font-weight: 400; }
.math-lessons-hero { margin-bottom: 24px; }
.math-grade-switcher { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 22px; }
.math-grade-pill {
  display: inline-flex;
  padding: 7px 11px;
  border: 1px solid var(--ink-soft);
  border-radius: 0;
  color: var(--ink-soft);
  font-size: .85rem;
  text-decoration: none;
  background: transparent;
}
.math-grade-pill:hover, .math-grade-pill.active { color: var(--paper); background: var(--ink); border-color: var(--ink); }
.math-subject-section, .math-grade-directory, .math-geometry-list { margin-top: 28px; }
.math-subject-section .index-grid,
.math-grade-directory .index-grid,
.math-geometry-list .index-grid { margin-top: 14px; }
.math-subject-card-unavailable { cursor: default; }
.math-subject-card-unavailable:hover {
  border-color: var(--ink-soft);
  transform: none;
  box-shadow: none;
}
.math-subject-link { display: inline-block; margin-top: 16px; color: var(--red-ink); font-family: var(--font-mono); font-size: .85rem; }
.math-subject-note { display: inline-block; margin-top: 16px; color: var(--ink-faint); font-family: var(--font-mono); font-size: .8rem; }
.math-geometry-preview { margin-top: 28px; padding: 20px; }
.math-lesson-list { margin: 14px 0 18px; border-top: 1px dashed var(--ink-faint); }
.math-lesson-row {
  display: grid;
  grid-template-columns: 42px 1fr 24px;
  gap: 12px;
  align-items: center;
  padding: 13px 0;
  border-bottom: 1px dashed var(--ink-faint);
  color: var(--ink);
  text-decoration: none;
}
.math-lesson-row strong { display: block; font-size: 1.1rem; font-weight: 600; }
.math-lesson-row small { display: block; margin-top: 3px; color: var(--ink-soft); }
.math-lesson-row > span:last-child { color: var(--red-ink); font-size: 20px; }
.math-see-all { display: inline-block; margin-top: 2px; text-decoration: none; }
@media (max-width: 560px) {
  .math-lesson-row { grid-template-columns: 34px 1fr 18px; }
}

/* --- GEOMETRY --- */
.geom-hero-panel, .geom-live-panel, .geom-simple-panel, .geom-studio-panel,
.geom-category-panel, .geom-topic-card, .geom-copy-card, .geom-example-card,
.geom-stage-card {
  border-color: var(--ink) !important;
  border-radius: 0 !important;
  background: var(--paper-card) !important;
  color: var(--ink) !important;
  box-shadow: var(--shadow-note) !important;
}
.geom-lesson-hero-panel { display: block; }
.geom-lesson-hero-panel .geom-hero-copy,
.geom-lesson-hero-panel .geom-lead { width: 100%; max-width: none; }
.geom-title, .geom-section-title, .geom-category-title, .geom-topic-title { color: var(--ink) !important; }
.geom-lead, .geom-section-copy, .geom-topic-copy, .geom-definition,
.geom-example-copy, .geom-copy-card p {
  color: var(--ink-soft) !important;
}
.geom-chip {
  border-color: var(--ink) !important;
  border-radius: 0 !important;
  background: transparent !important;
  font-family: var(--font-mono) !important;
  font-size: .85rem;
}
.geom-studio-guide h2 { margin: 10px 0 18px; }
.geom-studio-guide h3 { margin: 28px 0 8px; color: var(--ink); font-size: 1.2rem; line-height: 1.3; }
.geom-studio-guide p, .geom-studio-guide li { max-width: 78ch; color: var(--ink-soft); }
.geom-studio-guide ol { margin: 12px 0 18px; padding-left: 24px; }
.geom-tool-btn {
  border: 1px solid var(--ink);
  border-radius: 0;
  background: transparent;
  color: var(--ink);
  font-family: var(--font-mono);
  font-size: .85rem;
  padding: 6px 12px;
  cursor: pointer;
  transition: all .2s;
}
.geom-tool-btn:hover, .geom-tool-btn.active { background: var(--ink); color: var(--paper); }
.geom-tool-btn-danger:hover { background: var(--red-ink); border-color: var(--red-ink); }
.geom-studio-footer { border-top: 1px dashed var(--ink-faint); margin-top: 18px; padding-top: 14px; }
.geom-studio-status { color: var(--ink); font-family: var(--font-mono); font-size: .85rem; }
.geom-studio-hint { color: var(--ink-soft); font-size: .95rem; margin-top: 6px; }
.geom-breadcrumbs { display: flex; gap: 9px; margin: 0 0 14px; color: var(--ink-soft); font-family: var(--font-mono); font-size: .85rem; }

/* Studio toolbar, mode buttons & controls — notebook style, no amber/navy gradients. */
.geom-mode-btn,
.geom-tool-btn,
.geom-studio-panel .geom-tool-btn,
.geom-studio-panel .geom-toolbar-secondary .chip {
  min-height: 40px;
  padding: 0 14px;
  border: 1px solid var(--ink);
  border-radius: 0;
  background: transparent;
  color: var(--ink);
  font-family: var(--font-mono);
  font-size: .85rem;
  font-weight: 400;
  box-shadow: none;
}
.geom-mode-btn:not(.active):is(:hover, :focus-visible),
.geom-tool-btn:not(.active):is(:hover, :focus-visible),
.geom-studio-panel .geom-tool-btn:not(.active):is(:hover, :focus-visible),
.geom-studio-panel .geom-toolbar-secondary .chip:not(.active):is(:hover, :focus-visible) {
  background: var(--red-ink);
  color: var(--paper);
  border-color: var(--red-ink);
  transform: none;
}
.geom-mode-btn.active,
.geom-tool-btn.active,
.geom-studio-panel .geom-tool-btn.active,
.geom-studio-panel .geom-toolbar-secondary .chip.active {
  background: var(--ink);
  color: var(--paper);
  border-color: var(--ink);
  box-shadow: none;
}
.geom-tool-btn-danger,
.geom-studio-panel .geom-tool-btn-danger {
  color: var(--red-ink);
  border-color: var(--red-ink);
  background: transparent;
}
.geom-tool-btn-danger:hover,
.geom-studio-panel .geom-tool-btn-danger:hover {
  background: var(--red-ink);
  color: var(--paper);
}
.geom-studio-panel .geom-studio-footer {
  border-color: var(--ink-faint);
  border-radius: 0;
  background: rgba(250, 247, 239, .5);
}
.geom-studio-panel .geom-studio-status { color: var(--ink); }
.geom-studio-panel .geom-studio-hint { color: var(--ink-soft); }

/* Keep the construction studio controls in deliberate, balanced rows. */
.geom-studio-panel {
  container-type: inline-size;
}
.geom-studio-panel .geom-toolbar-primary {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 10px;
}
.geom-studio-panel .geom-toolbar-primary .geom-tool-btn,
.geom-studio-panel .geom-toolbar-secondary .chip {
  width: 100%;
  min-width: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  white-space: nowrap;
}
.geom-studio-panel .geom-toolbar-secondary {
  display: grid;
  gap: 10px;
  margin-top: 12px;
  margin-bottom: 12px;
}
.geom-studio-panel .geom-toolbar-row {
  display: grid;
  gap: 10px;
}
.geom-studio-panel .geom-toolbar-view-row {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}
.geom-studio-panel .geom-toolbar-action-row {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}
@container (min-width: 1850px) {
  .geom-studio-panel .geom-toolbar-primary {
    grid-template-columns: repeat(10, minmax(0, 1fr));
  }
  .geom-studio-panel .geom-toolbar-view-row {
    grid-template-columns: repeat(6, minmax(0, 1fr));
  }
}
@container (max-width: 699px) {
  .geom-studio-panel .geom-toolbar-primary,
  .geom-studio-panel .geom-toolbar-view-row,
  .geom-studio-panel .geom-toolbar-action-row {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .geom-studio-panel .geom-toolbar-primary .geom-tool-btn,
  .geom-studio-panel .geom-toolbar-secondary .chip {
    white-space: normal;
  }
}
@media (max-width: 680px) {
  .geom-studio-panel .geom-toolbar-primary,
  .geom-studio-panel .geom-toolbar-view-row,
  .geom-studio-panel .geom-toolbar-action-row {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}
.geom-control-stack,
.geom-lab-note {
  border: 1px solid var(--ink-faint);
  border-radius: 0;
  background: rgba(250, 247, 239, .5);
  color: var(--ink);
}
.geom-main .geom-toolbar-secondary button[data-download-svg] {
  border: 1px solid var(--ink);
  border-radius: 0;
  background: transparent;
  color: var(--ink);
  box-shadow: none;
}
.geom-main .geom-toolbar-secondary button[data-download-svg]::before {
  background: var(--paper-deep);
  color: var(--ink);
}
.geom-main .geom-toolbar-secondary button[data-download-svg]:hover {
  background: var(--ink);
  color: var(--paper);
  border-color: var(--ink);
}

/* Geometry SVGs stay on light notebook paper — never white. */
body .geom-hero-svg,
body .geom-example-svg {
  border-color: var(--ink-faint) !important;
  background:
    linear-gradient(rgba(44, 43, 41, .045) 1px, transparent 1px),
    linear-gradient(90deg, rgba(44, 43, 41, .045) 1px, transparent 1px),
    rgba(250, 247, 239, .7) !important;
  background-size: 26px 26px, 26px 26px, auto !important;
  box-shadow: 3px 4px 0 rgba(44, 43, 41, .1) !important;
}
body .geom-hero-svg > rect:first-child {
  fill: rgba(250, 247, 239, .5) !important;
  stroke: rgba(44, 43, 41, .2) !important;
}
body .geom-hero-svg > g { stroke: rgba(44, 43, 41, .12) !important; }
body .geom-hero-svg rect[fill="rgba(255,255,255,.05)"] { fill: rgba(44, 43, 41, .045) !important; }
body .geom-hero-text,
body .geom-example-svg .geom-stage-label,
body .geom-example-svg .geom-stage-note { fill: var(--ink) !important; }
body .geom-example-svg .geom-stage-faint { fill: var(--ink-soft) !important; }
body .geom-stage-card,
body .geom-studio-stage {
  border-color: var(--ink-faint) !important;
  background:
    linear-gradient(rgba(44, 43, 41, .045) 1px, transparent 1px),
    linear-gradient(90deg, rgba(44, 43, 41, .045) 1px, transparent 1px),
    rgba(250, 247, 239, .66) !important;
  background-size: 40px 40px, 40px 40px, auto !important;
  box-shadow: var(--shadow-note) !important;
}
body .geom-stage-svg, body .geom-studio-svg { background: transparent !important; }
body .geom-stage-svg .geom-grid-line,
body .geom-example-svg .geom-grid-line,
body .geom-studio-svg .geom-studio-grid-line { stroke: rgba(44, 43, 41, .13) !important; }
body .geom-stage-svg .geom-axis-line,
body .geom-example-svg .geom-axis-line,
body .geom-studio-svg .geom-studio-axis-line { stroke: var(--ink) !important; stroke-width: 2 !important; }
body .geom-stage-svg .geom-guide-line { stroke: rgba(44, 43, 41, .3) !important; }
body .geom-stage-svg .geom-altitude-line,
body .geom-example-svg .geom-altitude-line { stroke: var(--ink) !important; stroke-width: 3 !important; stroke-dasharray: 10 8 !important; }
body .geom-stage-svg .geom-stage-label,
body .geom-stage-svg .geom-stage-note,
body .geom-studio-svg .geom-studio-label,
body .geom-studio-svg .geom-studio-measure { fill: var(--ink) !important; }
body .geom-stage-svg .geom-stage-faint,
body .geom-studio-svg .geom-studio-faint { fill: var(--ink-soft) !important; }
body .geom-studio-svg .geom-studio-board-bg { fill: var(--paper) !important; }
body .geom-main .geom-explorer-shell,
body .geom-main .geom-simple-panel,
body .geom-main .geom-copy-card,
body .geom-main .geom-example-card { background: rgba(250, 247, 239, .8) !important; }
body .geom-main .geom-copy-card { padding: 28px 30px !important; }
body .geom-main .geom-article-grid--draft { display: none !important; }

/* --- MOBILE KEYPAD / DRAWER --- */
.drawer-card {
  background: var(--paper) !important;
  color: var(--ink);
  border: 1px solid var(--ink);
  border-top-left-radius: 0;
  border-top-right-radius: 0;
  box-shadow: 0 -8px 24px rgba(44, 43, 41, .18);
}
.drawer-top { border-bottom: 1px dashed var(--ink-faint); }
.drawer-title { color: var(--ink); }
.kp-grid { align-items: stretch; }
.kbtn, .kbtn.kback, .kbtn.kplay, .kbtn.kenter {
  display: grid;
  place-items: center;
  align-content: center;
  padding: 0;
  line-height: 1;
  border: 1px solid var(--ink);
  border-radius: 0;
  background: rgba(250, 247, 239, .7);
  color: var(--ink);
  box-shadow: none;
}
.kbtn:hover { background: var(--ink); color: var(--paper); }
.kbtn.kback { background: var(--paper-deep); color: var(--ink); }
.kbtn.kenter { background: var(--blue-ink); color: var(--paper); }
.kbtn.kplay { background: #16845a; color: var(--paper); }
.kbtn svg { display: block; width: 26px; height: 26px; margin: 0; }
.kbtn sub { line-height: 1; }

/* --- FOOTER --- */
.footerbar {
  width: min(var(--max), calc(100% - 32px));
  max-width: none;
  margin: 34px auto 24px;
  border: 0;
  border-top: 1px solid var(--ink);
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  text-align: center;
  font-family: var(--font-mono);
  font-size: .9rem;
  color: var(--ink-soft);
}
.fb-inner { padding: 22px 14px; color: var(--ink-soft); flex-wrap: wrap; }
.fb-inner a { color: var(--red-ink); background: transparent; padding: 3px 6px; border-radius: 0; text-decoration: none; }
.fb-inner a:hover { color: var(--ink); background: transparent; border-color: transparent; transform: none; }
.fb-inner .footer-required {
  display: inline-flex !important;
  visibility: visible !important;
  opacity: 1 !important;
}

/* --- MISC --- */
body button[data-download-svg],
body .geom-main button[data-download-svg],
body .loan-pdf-btn {
  display: inline-flex !important;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 38px !important;
  padding: 8px 13px !important;
  border: 1px solid var(--ink) !important;
  border-radius: 0 !important;
  background: transparent !important;
  color: var(--ink) !important;
  box-shadow: none !important;
  font-family: var(--font-mono) !important;
  font-size: .85rem !important;
}
body button[data-download-svg]::before,
body .loan-pdf-btn::before {
  content: "↓" !important;
  display: inline-grid;
  place-items: center;
  width: 19px;
  height: 19px;
  border-radius: 50%;
  background: var(--paper-deep) !important;
  color: var(--ink) !important;
}
body button[data-download-svg]:hover,
body button[data-download-svg]:focus-visible,
body .loan-pdf-btn:hover,
body .loan-pdf-btn:focus-visible {
  background: var(--ink) !important;
  color: var(--paper) !important;
  transform: translateY(-1px);
}
body #studioFullscreenToggle {
  min-height: 38px !important;
  padding: 8px 13px !important;
  border: 1px solid var(--ink) !important;
  border-radius: 0 !important;
  background: transparent !important;
  color: var(--ink) !important;
  box-shadow: none !important;
}

/* The long-form writing is page-specific; remove the card treatment around it. */
body .help-grid { display: block !important; }
body .help-box {
  margin: 0 0 28px !important;
  padding: 0 0 24px !important;
  border: 0 !important;
  border-bottom: 1px dashed var(--ink-faint) !important;
  border-radius: 0 !important;
  background: transparent !important;
  box-shadow: none !important;
}
body .help-box:last-child { margin-bottom: 0 !important; border-bottom: 0 !important; }

body .geom-article-grid,
body .geom-example-grid,
body .geom-card-grid { display: block !important; }

body .geom-copy-card,
body .geom-example-card,
body .geom-feature-card,
body .geom-topic-grid .geom-topic-card {
  margin: 0 0 26px !important;
  padding: 0 0 24px !important;
  border: 0 !important;
  border-bottom: 1px dashed var(--ink-faint) !important;
  border-radius: 0 !important;
  background: transparent !important;
  box-shadow: none !important;
}
body .geom-copy-card:last-child,
body .geom-example-card:last-child,
body .geom-feature-card:last-child,
body .geom-topic-grid .geom-topic-card:last-child {
  margin-bottom: 0 !important;
  border-bottom: 0 !important;
}

body .help-panel,
body .faq-panel,
body .math-lessons-hero,
body .math-geometry-preview {
  background: rgba(250, 247, 239, .85) !important;
}

/* Mobile keypad page dots — ink, not white. */
.dot {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  border: 1px solid var(--ink-faint);
  background: transparent;
  cursor: pointer;
}
.dot.active {
  background: var(--ink);
  border-color: var(--ink);
}

/* MathQuill's hidden input textarea — keep it invisible on paper. */
.mq-editable-field .mq-textarea,
.mq-math-mode .mq-textarea {
  background: transparent !important;
  color: transparent !important;
}

/* Toast */
.toast {
  border: 1px solid var(--ink);
  border-radius: 0;
  background: var(--paper);
  color: var(--ink);
  box-shadow: var(--shadow-note);
}

/* Loan / amortization tables stay on paper — never white. */
.loan-table-shell {
  border: 1px solid var(--ink);
  border-radius: 0;
  background: rgba(250, 247, 239, .6);
}
.loan-table th,
.loan-table td {
  border-top: 1px solid var(--ink-faint);
  color: var(--ink);
}
.loan-table thead th {
  background: var(--ink);
  color: var(--paper);
}
.loan-table tbody tr:nth-child(even) td {
  background: rgba(236, 228, 208, .4);
}
.loan-table-break {
  background: var(--paper-deep) !important;
  color: var(--ink);
}

/* OCR strip, results & stage widgets — paper theme, no white/gradients. */
.upload-strip {
  border: 1px solid var(--ink);
  border-radius: 0;
  background: rgba(250, 247, 239, .7);
}
.upload-title { color: var(--ink); font-weight: 600; }
.upload-sub { color: var(--ink-soft); }
.spinner {
  border: 2px solid var(--ink-faint);
  border-top-color: var(--red-ink);
}
.ocr-tip {
  background: rgba(250, 247, 239, .8);
  border: 1px dashed var(--ink-faint);
  border-radius: 0;
  color: var(--ink);
}
.calc-result-summary {
  border: 1px solid var(--ink);
  border-radius: 0;
  background: rgba(250, 247, 239, .6);
}
.calc-result-label {
  color: var(--red-ink);
  font-family: var(--font-mono);
  letter-spacing: 1px;
  text-transform: uppercase;
  font-weight: 400;
}
.calc-result-value { color: var(--blue-ink); font-weight: 600; }
.calc-stage-title, .calc-section-title { color: var(--ink); font-weight: 600; }
.calc-dice-row { color: var(--ink); }

/* MathQuill caret + selection on paper — ink, not white. */
.mq-editable-field .mq-cursor {
  border-left: 2px solid var(--ink) !important;
}
.mq-editable-field .mq-cursor.mq-blink {
  animation: mq-blink 1.2s infinite;
}
@keyframes mq-blink {
  0%, 50% { opacity: 1; }
  50.01%, 100% { opacity: 0; }
}
.mq-editable-field .mq-cursor:only-child::after,
.mq-editable-field .mq-textarea + .mq-cursor:last-child::after,
.mq-editable-field .mq-text-mode .mq-cursor:only-child::after {
  color: var(--ink-soft) !important;
}
.mq-editable-field ::selection {
  background: rgba(156, 59, 53, .18) !important;
}

/* Shared calculator results: one clean notebook surface instead of stacked
   rounded gradient containers. This covers every generic calculator and the
   richer loan/schedule result layouts built by generic-calculator.js. */
body .inline-answer-wrap {
  display: grid;
  gap: 12px;
  padding: 18px 0 0 !important;
  border: 0 !important;
  border-top: 1px dashed var(--ink-faint) !important;
  border-radius: 0 !important;
  background: transparent !important;
  box-shadow: none !important;
}
body .inline-answer-box {
  min-height: 0;
  padding: 0 !important;
  border: 0 !important;
  border-radius: 0 !important;
  background: transparent !important;
  color: var(--ink) !important;
  box-shadow: none !important;
}
body .loan-result-shell { gap: 16px; }
body .loan-result-hero,
body .calc-result-summary {
  width: 100%;
  max-width: none;
  box-sizing: border-box;
  padding: 16px 0 !important;
  border: 0 !important;
  border-bottom: 1px dashed var(--ink-faint) !important;
  border-radius: 0 !important;
  background: transparent !important;
  box-shadow: none !important;
}
body .loan-result-kicker,
body .calc-result-label,
body .loan-export-label {
  color: var(--red-ink) !important;
  font-family: var(--font-mono) !important;
  font-size: 12px !important;
  font-weight: 400 !important;
  letter-spacing: .7px !important;
  text-transform: uppercase;
}
body .loan-result-amount,
body .calc-result-value {
  color: var(--ink) !important;
  font-family: var(--font-text);
  font-weight: 600 !important;
}
body .loan-result-actions { max-width: 520px; }
body .loan-export-row { gap: 12px; }
body .loan-metric-card {
  padding: 12px 0;
  border: 0;
  border-bottom: 1px dashed var(--ink-faint);
  border-radius: 0;
  background: transparent;
}
body .loan-table-shell {
  border: 1px solid var(--ink-faint);
  border-radius: 0;
  background: var(--paper-card);
  box-shadow: none;
}
body .loan-schedule-tabs {
  gap: 0;
  border: 1px solid var(--ink);
}
body .loan-tab-btn {
  min-height: 38px;
  padding: 8px 13px;
  border: 0;
  border-right: 1px solid var(--ink);
  border-radius: 0;
  background: transparent;
  color: var(--ink-soft);
  box-shadow: none;
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 400;
  text-decoration: none;
}
body .loan-tab-btn:last-child { border-right: 0; }
body .loan-tab-btn.is-active,
body .loan-tab-btn:hover {
  border-color: var(--ink);
  background: var(--ink);
  color: var(--paper);
  box-shadow: none;
}
body .loan-pdf-btn {
  border: 1px solid var(--ink) !important;
  background: var(--ink) !important;
  color: var(--paper) !important;
}
body .loan-pdf-btn::before {
  width: auto;
  height: auto;
  border-radius: 0;
  background: transparent !important;
  color: inherit !important;
}
body .loan-pdf-btn:hover,
body .loan-pdf-btn:focus-visible {
  border-color: var(--red-ink) !important;
  background: var(--red-ink) !important;
  color: var(--paper) !important;
}

/* Long answers must scroll inside their own reading area. The surrounding
   calculator panels intentionally hide decorative overflow, so both the
   immediate result and the step-by-step response need explicit scroll roots. */
body .inline-answer-wrap,
body .inline-answer-box,
body .answer-box-inline,
body .calc-result-stack,
body .calc-result-body,
body .output-panel,
body .response,
body .answer-box {
  min-width: 0;
  max-width: 100%;
  box-sizing: border-box;
}
body .inline-answer-box,
body .calc-result-value,
body .response,
body .answer-box {
  overflow-x: auto !important;
  overflow-y: visible;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-x: contain;
  scrollbar-width: thin;
  scrollbar-color: var(--ink-faint) transparent;
}
body .inline-answer-box::-webkit-scrollbar,
body .calc-result-value::-webkit-scrollbar,
body .response::-webkit-scrollbar,
body .answer-box::-webkit-scrollbar { height: 8px; }
body .inline-answer-box::-webkit-scrollbar-thumb,
body .calc-result-value::-webkit-scrollbar-thumb,
body .response::-webkit-scrollbar-thumb,
body .answer-box::-webkit-scrollbar-thumb { background: var(--ink-faint); }
body .inline-answer-box::-webkit-scrollbar-track,
body .calc-result-value::-webkit-scrollbar-track,
body .response::-webkit-scrollbar-track,
body .answer-box::-webkit-scrollbar-track { background: transparent; }
body .inline-answer-box mjx-container[jax="CHTML"][display="true"],
body .response mjx-container[jax="CHTML"][display="true"],
body .answer-box mjx-container[jax="CHTML"][display="true"] {
  max-width: none !important;
  overflow: visible !important;
}
body .inline-answer-box pre,
body .response pre,
body .answer-box pre,
body .inline-answer-box table,
body .response table,
body .answer-box table {
  width: max-content;
  min-width: 100%;
  max-width: none;
}
body .inline-answer-box pre,
body .response pre,
body .answer-box pre {
  overflow: visible;
  white-space: pre;
}

/* Formula callouts inherited dark-theme inline backgrounds in a few legacy
   calculators, which left the notebook theme's dark prose unreadable. Keep
   every highlighted formula on one shared, high-contrast paper treatment. */
body .formula-highlight,
body .help-note[style*="background-color"] {
  display: block;
  max-width: 100%;
  box-sizing: border-box;
  margin-block: 16px !important;
  padding: 10px 14px !important;
  border: 1px solid var(--line) !important;
  border-left: 3px solid var(--red-ink) !important;
  border-radius: 0 !important;
  background: var(--paper-deep) !important;
  color: var(--ink) !important;
  font-family: var(--font-mono) !important;
  font-size: 13px !important;
  line-height: 1.65;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
  scrollbar-color: var(--ink-faint) transparent;
}
body .formula-highlight *,
body .help-note[style*="background-color"] * {
  color: inherit !important;
}

/* Only the main input worksheet is outlined. Other content sections should
   sit directly on the notebook paper, even when legacy geometry/card rules
   above carry stronger border and background declarations. */
body .panel:not(.input-panel) {
  border: 0 !important;
  background: transparent !important;
  box-shadow: none !important;
}
body .panel:not(.input-panel)::before,
body .panel:not(.input-panel)::after {
  content: none !important;
  display: none !important;
}
body .panel.input-panel {
  border: 1px solid var(--ink) !important;
  background: var(--paper-card) !important;
  box-shadow: 8px 8px 0 rgba(44, 43, 41, .05) !important;
}

/* Keep page and section headings direct. These decorative eyebrow labels
   duplicated the heading hierarchy and sometimes surfaced awkward generated
   phrases such as "Count to ten" above otherwise clear lesson titles. */
.geom-kicker,
.geom-section-kicker,
.geom-topic-number,
.calc-suite-kicker {
  display: none !important;
}

/* Win over page-specific legacy prose rules without changing headings,
   labels, controls, or mathematical notation. */
html body .panel p {
  font-size: 15px !important;
  color: var(--prose-ink) !important;
}

@media (max-width: 760px) {
  body { font-size: 18px; }
  body p,
  html body .panel p { font-size: 15px !important; }
  .topbar { width: 100%; padding-inline: 10px; }
  .wrap, .bottom-help, .bottom-faq, .bottom-tools, .footerbar { width: 100%; padding-inline: 14px; }
  .input-panel, .calc-suite-panel, .calculator-directory-panel, .help-panel, .tools-panel, .faq-panel { padding: 24px 18px; }
  body .output-panel {
    width: 95vw;
    max-width: 95vw;
    margin-left: calc(50% - 47.5vw);
    margin-right: calc(50% - 47.5vw);
    padding: 24px 0;
  }
  body .output-panel > .panel-head,
  body .output-panel > .response {
    width: 100%;
    padding-left: 0;
    padding-right: 0;
    box-sizing: border-box;
  }
  .calc-suite-hero-with-icon { grid-template-columns: 58px minmax(0, 1fr); gap: 12px; }
  .calc-hero-icon { width: 58px; height: 58px; font-size: 22px; }
  .calc-suite-title { font-size: 38px; }
  .calc-suite-sub, .help-lead { font-size: 18px; }
  .instrument { grid-template-columns: 40px 1fr 20px; gap: 10px; }
  .grid-toggle { font-size: 14px; padding-inline: 8px; }
}

@media (max-width: 520px) {
  .site-brand-logo { height: 34px; max-width: 150px; }
  .brand-sub, .action-btn .ab-txt { display: none; }
  .top-actions { padding: 0 2px; }
  .solver-page-title { font-size: 46px; }
  .calc-suite-title { font-size: 34px; }
  .help-title { font-size: 34px; }
  .calculator-card-grid { grid-template-columns: 1fr; }
  .index-grid { grid-template-columns: 1fr; }
  .calc-fields-grid { grid-template-columns: 1fr; }
  .calc-field-full { grid-column: auto; }
  .primary-row .primary { width: 100%; }
  .search-ledger { flex-direction: column; gap: 0; }
  .search-ledger label { border-right: 0; border-bottom: 1px dashed var(--ink-faint); padding: 8px 12px; }
  .site-search-wrap { padding-inline: 10px; }
  .site-search-panel { padding: 18px 14px; max-height: calc(100dvh - 24px); }
  .site-search-head h2 { font-size: 1.65rem; }
  .site-search-form { grid-template-columns: auto minmax(0, 1fr); }
  .site-search-submit { grid-column: 1 / -1; min-height: 42px; border-left: 0; border-top: 1px solid var(--ink); }
  .site-search-results { grid-template-columns: 1fr; }
  .tabs-container { align-items: stretch; }
  .tabs { width: 100%; }
  .tabs .tab { flex: 1 1 0; }
  .input-actions {
    width: 100%;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
  }
  .sample-math-btn { grid-column: 1 / -1; width: 100%; }
  .input-actions .ibtn { justify-self: center; }
}

/* Compact sharing panel, placed in the article flow before related content. */
.site-share-panel {
  position: relative;
  z-index: 1;
  width: min(var(--max), calc(100% - 32px));
  margin: 28px auto 22px;
  padding: 0 14px;
  box-sizing: border-box;
  color: var(--ink);
}
.wrap > .site-share-panel,
.main-col > .site-share-panel {
  width: 100%;
  margin-left: 0;
  margin-right: 0;
  padding-inline: 0;
}
.site-share-inner {
  width: 100%;
  min-height: 0;
  margin: 0;
  padding: 16px 18px;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 18px;
  position: relative;
  box-sizing: border-box;
  border: 1px solid var(--line);
  border-left: 4px solid var(--red-ink);
  background: rgba(250, 247, 239, .82);
  box-shadow: var(--shadow-note);
}
.site-share-title {
  margin: 0;
  color: var(--ink);
  font-family: var(--font-text);
  font-size: 22px;
  font-weight: 600;
  line-height: 1.15;
  white-space: nowrap;
}
.site-share-actions {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  flex-wrap: wrap;
  gap: 8px;
}
.site-share-button {
  --share-color: #111620;
  appearance: none;
  width: 44px;
  height: 44px;
  margin: 0;
  padding: 0;
  display: inline-grid;
  place-items: center;
  box-sizing: border-box;
  border: 1px solid rgba(255, 255, 255, .92);
  border-radius: 9px;
  background: var(--share-color);
  color: #fff;
  box-shadow: 2px 3px 0 rgba(44, 43, 41, .28);
  cursor: pointer;
  text-decoration: none;
  transition: transform .16s ease, filter .16s ease, box-shadow .16s ease;
}
.site-share-button:hover,
.site-share-button:focus-visible {
  transform: translateY(-2px);
  filter: brightness(1.08);
  box-shadow: 3px 4px 0 rgba(44, 43, 41, .24);
}
.site-share-button:active {
  transform: translateY(1px);
  box-shadow: 1px 1px 0 rgba(44, 43, 41, .26);
}
.site-share-button svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.site-share-facebook { --share-color: #2f65bd; }
.site-share-reddit { --share-color: #e64a13; }
.site-share-telegram { --share-color: #2399c8; }
.site-share-whatsapp { --share-color: #148a4b; }
.site-share-email { --share-color: #7443b7; }
.site-share-native { --share-color: #ed4a0b; }
.site-share-status {
  position: static;
  min-height: 18px;
  margin: 0 0 0 2px;
  color: var(--blue-ink) !important;
  font: 12px/1.4 var(--font-mono, monospace) !important;
}
.site-share-status:empty { display: none; }
@media (max-width: 760px) {
  .site-share-panel {
    width: 100%;
    margin-top: 22px;
    padding-inline: 14px;
  }
  .site-share-inner {
    padding: 15px 14px;
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
  }
  .site-share-title { white-space: normal; text-align: left; }
  .site-share-actions { gap: 8px; }
  .site-share-button { width: 42px; height: 42px; border-radius: 8px; }
  .site-share-button svg { width: 21px; height: 21px; }
  .site-share-status { margin-left: 0; text-align: left; }
}
