/* FilamentMath — build-plate grey, graphite ink, one saffron "print". */
:root {
  --plate: #eceff2;
  --paper: #ffffff;
  --ink: #1b222c;
  --muted: #586372;
  --rule: #c9d0d8;
  --pla: #f2be22;
  --pla-line: rgba(120, 82, 0, 0.13);
  --ok: #1f7a4d;
  --warn: #8a5a00;
  --bad: #b3261e;

  --display: "Bahnschrift", "DIN Alternate", "DIN Condensed", "Arial Narrow", sans-serif-condensed, system-ui, sans-serif;
  --body: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;

  --wrap: 1120px;
  --measure: 68ch;
  --radius-s: 6px;
  --radius-l: 14px;
  --layer: 6px; /* one printed layer in the texture */
  --pla-ink: #1b222c;   /* text on the saffron print, both themes */
  --field-2: #f6f7f9;
  --edge: #d5dbe1;
  /* cost breakdown, validated on the saffron surface */
  --s1: #1f6fd0; --s2: #d63b3c; --s3: #5f43d4; --s4: #007f2a; --s5: #c4457e;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --plate: #12161c;
    --paper: #1b2129;
    --ink: #e7ebf0;
    --muted: #9ba6b4;
    --rule: #303945;
    --field-2: #232a33;
    --edge: #262e38;
  }
}

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

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--plate);
  color: var(--ink);
  font: 17px/1.55 var(--body);
  font-variant-numeric: tabular-nums;
}

img, svg { display: block; max-width: 100%; }

a { color: var(--ink); text-decoration-thickness: 1px; text-underline-offset: 3px; }
a:hover { text-decoration-thickness: 2px; }

:focus-visible {
  outline: 3px solid var(--ink);
  outline-offset: 2px;
  border-radius: 2px;
}

.wrap { width: min(100% - 2.5rem, var(--wrap)); margin-inline: auto; }

.skip {
  position: absolute; left: -999px; top: 0.5rem;
  background: var(--ink); color: var(--paper); padding: 0.5rem 0.9rem; z-index: 10;
}
.skip:focus { left: 0.5rem; }

/* Header ---------------------------------------------------------------- */
.site-header { border-bottom: 1px solid var(--rule); background: var(--plate); }
.site-header .wrap {
  display: flex; align-items: center; justify-content: space-between;
  gap: 1rem 2rem; flex-wrap: wrap; padding-block: 1rem;
}
.brand {
  display: inline-flex; align-items: center; gap: 0.6rem;
  font: 600 1.375rem/1 var(--display); letter-spacing: 0.01em;
  text-decoration: none;
}
.site-nav { display: flex; gap: 0.25rem 1.5rem; flex-wrap: wrap; }
.site-nav a {
  text-decoration: none; color: var(--muted);
  padding: 0.35rem 0; border-bottom: 2px solid transparent;
}
.site-nav a:hover { color: var(--ink); }
.site-nav a[aria-current="page"] { color: var(--ink); border-bottom-color: var(--pla); }

/* Type ------------------------------------------------------------------ */
h1, h2, h3 { font-family: var(--display); font-weight: 600; line-height: 1.1; margin: 0; }
h1 { font-size: clamp(2.25rem, 1.4rem + 3.6vw, 3.75rem); letter-spacing: -0.01em; }
h2 { font-size: 1.5rem; margin-top: 2.75rem; }
h3 { font-size: 1.125rem; margin-top: 1.75rem; }
p, ul, ol, dl, table { margin: 0.9rem 0 0; }
.lead { font-size: 1.1875rem; color: var(--muted); max-width: 58ch; margin-top: 1rem; }
.prose { max-width: var(--measure); }
.prose li + li { margin-top: 0.35rem; }
.small { font-size: 0.875rem; color: var(--muted); }

.page-head { padding-block: 2.75rem 2rem; }

main { padding-bottom: 4rem; }

/* Tool layout ----------------------------------------------------------- */
.tool {
  display: grid; gap: 2rem;
  grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr);
  align-items: start;
}
@media (max-width: 860px) { .tool { grid-template-columns: minmax(0, 1fr); } }

.panel {
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: var(--radius-l);
  padding: 1.5rem;
}

fieldset { border: 0; padding: 0; margin: 0; min-width: 0; }
fieldset + fieldset { margin-top: 1.75rem; padding-top: 1.5rem; border-top: 1px solid var(--rule); }
legend { float: left; width: 100%; font: 600 1.125rem/1.2 var(--display); padding: 0; margin-bottom: 0.75rem; }
legend + * { clear: both; }
legend + .grid, legend + .check { margin-top: 0; }
.legend-note { margin: 0 0 0.5rem; font-size: 0.875rem; color: var(--muted); }

.grid { display: grid; gap: 1rem 1.25rem; grid-template-columns: repeat(2, minmax(0, 1fr)); margin-top: 0.75rem; }
.grid--3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid .span-2 { grid-column: span 2; }
@media (max-width: 520px) {
  .grid, .grid--3 { grid-template-columns: minmax(0, 1fr); }
  .grid .span-2 { grid-column: auto; }
}

.field--top { max-width: 13rem; margin-bottom: 1.5rem; }
.field label, .field .label { display: block; font-size: 0.9375rem; font-weight: 600; margin-bottom: 0.35rem; }
.field .hint { display: block; font-size: 0.8125rem; color: var(--muted); margin-top: 0.3rem; }

.input {
  display: flex; align-items: stretch;
  border: 1.5px solid var(--rule); border-radius: var(--radius-s);
  background: var(--paper);
}
.input:focus-within { border-color: var(--ink); box-shadow: 0 0 0 3px rgba(242, 190, 34, 0.55); }
.input input, .input select {
  flex: 1; min-width: 0; width: 100%; border: 0; background: transparent; color: var(--ink);
  font: inherit; padding: 0.6rem 0.7rem; outline: none;
}
.input select { cursor: pointer; width: 100%; text-overflow: ellipsis; }
.input .unit {
  display: flex; align-items: center; padding: 0 0.75rem;
  color: var(--muted); font-size: 0.9375rem; border-left: 1px solid var(--rule);
  background: var(--field-2); border-radius: 0 var(--radius-s) var(--radius-s) 0; white-space: nowrap;
}
.input .unit--pre { border-left: 0; border-right: 1px solid var(--rule); border-radius: var(--radius-s) 0 0 var(--radius-s); }
input[type=number] { -moz-appearance: textfield; appearance: textfield; }
input::-webkit-outer-spin-button, input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

.check { display: flex; gap: 0.6rem; align-items: flex-start; margin-top: 0.75rem; font-weight: 600; }
.check input { width: 1.15rem; height: 1.15rem; margin-top: 0.2rem; accent-color: var(--ink); }

.segmented { display: inline-flex; border: 1.5px solid var(--rule); border-radius: var(--radius-s); overflow: hidden; margin-top: 0.35rem; }
.segmented label { margin: 0; font-weight: 500; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented span { display: block; padding: 0.5rem 0.9rem; cursor: pointer; }
.segmented label + label span { border-left: 1px solid var(--rule); }
.segmented input:checked + span { background: var(--ink); color: var(--paper); }
.segmented input:focus-visible + span { outline: 3px solid var(--pla); outline-offset: -3px; }

.actions { display: flex; gap: 0.75rem; flex-wrap: wrap; margin-top: 1.5rem; }
.btn {
  font: 600 0.9375rem/1 var(--body); color: var(--ink); background: transparent;
  border: 1.5px solid var(--ink); border-radius: var(--radius-s);
  padding: 0.65rem 1rem; cursor: pointer;
}
.btn:hover { background: var(--ink); color: var(--paper); }
.btn--quiet { border-color: var(--rule); color: var(--muted); }
.btn--quiet:hover { background: var(--plate); color: var(--ink); }

/* The print: saffron result block with layer lines ---------------------- */
.print {
  position: sticky; top: 1.25rem;
  background:
    repeating-linear-gradient(to bottom, transparent 0 calc(var(--layer) - 1px), var(--pla-line) calc(var(--layer) - 1px) var(--layer)),
    var(--pla);
  border-radius: var(--radius-s) var(--radius-s) var(--radius-l) var(--radius-l);
  padding: 1.5rem 1.5rem 1.25rem;
  box-shadow: inset 0 -4px 0 rgba(120, 82, 0, 0.18);
}
@media (max-width: 860px) { .print { position: static; } }
.print-label { font-weight: 600; margin: 0; }
.print-total {
  font: 600 clamp(2.75rem, 2rem + 3vw, 3.75rem)/1 var(--display);
  margin: 0.4rem 0 0; letter-spacing: -0.01em; word-break: break-word;
}
.print-sub { margin: 0.5rem 0 0; font-size: 0.9375rem; }
.print dl { display: grid; grid-template-columns: 1fr auto; gap: 0.45rem 1rem; margin-top: 1.25rem; padding-top: 1rem; border-top: 1.5px solid rgba(27, 34, 44, 0.35); }
.print dt { margin: 0; }
.print dd { margin: 0; text-align: right; font-weight: 600; }
.print .second {
  margin-top: 1.1rem; padding-top: 1rem; border-top: 1.5px solid rgba(27, 34, 44, 0.35);
  display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; flex-wrap: wrap;
}
.print .second strong { font: 600 1.75rem/1 var(--display); }
.print .msg { background: rgba(255, 255, 255, 0.7); border-radius: var(--radius-s); padding: 0.75rem 0.9rem; margin-top: 1rem; font-size: 0.9375rem; }
.print .msg:empty { display: none; }
.verdict { display: inline-block; font-weight: 700; padding: 0.15rem 0.5rem; border-radius: 4px; background: var(--paper); }
.verdict--enough { color: var(--ok); }
.verdict--tight { color: var(--warn); }
.verdict--short { color: var(--bad); }

/* Code to paste ------------------------------------------------------- */
.code-wrap { margin-top: 1rem; }
.code-head { display: flex; justify-content: space-between; align-items: center; gap: 1rem; font-weight: 600; font-size: 0.9375rem; }
.code-head button { font: 600 0.875rem/1 var(--body); background: var(--pla-ink); color: #fff; border: 0; border-radius: var(--radius-s); padding: 0.5rem 0.8rem; cursor: pointer; }
pre.code { margin: 0.5rem 0 0; background: #fff; color: var(--pla-ink); border-radius: var(--radius-s); padding: 0.75rem 0.9rem; font-size: 0.9375rem; overflow-x: auto; white-space: pre; }
.group-title { font-size: 1.125rem; margin-top: 2rem; color: var(--ink); }
.group-title + .stack { margin-top: 0.9rem; }

/* Saved spools ---------------------------------------------------------- */
.saved { list-style: none; padding: 0; margin: 0.75rem 0 0; }
.saved li { display: flex; justify-content: space-between; align-items: center; gap: 1rem; padding: 0.45rem 0; border-bottom: 1px solid var(--rule); }
.saved button { font: inherit; font-size: 0.875rem; color: var(--muted); background: none; border: 0; text-decoration: underline; cursor: pointer; padding: 0.25rem; }
.saved button:hover { color: var(--bad); }

/* Content below the tool ------------------------------------------------ */
.content { margin-top: 1rem; }
.formula {
  background: var(--paper); border-left: 4px solid var(--pla);
  padding: 0.9rem 1.1rem; border-radius: 0 var(--radius-s) var(--radius-s) 0;
  max-width: var(--measure);
}
.formula p { margin: 0.2rem 0; }

table { border-collapse: collapse; width: 100%; max-width: 760px; background: var(--paper); border: 1px solid var(--rule); border-radius: var(--radius-s); overflow: hidden; }
caption { text-align: left; font-size: 0.875rem; color: var(--muted); padding-bottom: 0.5rem; }
th, td { text-align: left; padding: 0.55rem 0.8rem; border-bottom: 1px solid var(--rule); }
th { font-weight: 600; background: var(--field-2); }
td.n, th.n { text-align: right; }
tr:last-child td { border-bottom: 0; }
.table-scroll { overflow-x: auto; }

details { border-bottom: 1px solid var(--rule); max-width: var(--measure); }
details:first-of-type { border-top: 1px solid var(--rule); margin-top: 1rem; }
summary { cursor: pointer; font-weight: 600; padding: 0.85rem 0; list-style-position: outside; }
details p { margin: 0 0 0.9rem; }

/* Home: the stepped stack of tools -------------------------------------- */
.section-title { font-size: clamp(1.75rem, 1.4rem + 1.4vw, 2.25rem); margin-top: 1.5rem; }
.section-title a { text-decoration: none; }
.section-title a:hover { text-decoration: underline; text-decoration-thickness: 2px; text-underline-offset: 5px; }
.section-note { color: var(--muted); margin-top: 0.5rem; max-width: 60ch; }
.section-note + .stack { margin-top: 1.5rem; }
.hero { padding-block: 3rem 1rem; }
.hero h1 { max-width: 16ch; }
.stack { display: flex; flex-direction: column; gap: 3px; margin-top: 2.5rem; }
.layer {
  display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 0.5rem 1.5rem;
  text-decoration: none; color: var(--ink);
  background:
    repeating-linear-gradient(to bottom, transparent 0 calc(var(--layer) - 1px), var(--pla-line) calc(var(--layer) - 1px) var(--layer)),
    var(--pla);
  padding: 1.4rem 1.6rem; border-radius: var(--radius-s);
  transform-origin: left center;
}
.layer { width: var(--w, 100%); }
.layer:last-child { border-radius: var(--radius-s) var(--radius-s) var(--radius-l) var(--radius-l); box-shadow: inset 0 -4px 0 rgba(120, 82, 0, 0.18); }
.layer-name { font: 600 clamp(1.5rem, 1.1rem + 1.6vw, 2.25rem)/1.05 var(--display); }
.layer-does { margin: 0.35rem 0 0; font-size: 0.9375rem; }
.layer-fact { font: 600 1rem/1.2 var(--display); text-align: right; }
.layer:hover .layer-name { text-decoration: underline; text-decoration-thickness: 2px; text-underline-offset: 4px; }
.layer:hover { filter: brightness(1.03); }
@media (max-width: 720px) {
  .layer { width: 100%; }
  .layer { grid-template-columns: 1fr; }
  .layer-fact { text-align: left; }
}
.plate-edge { height: 10px; background: var(--edge); border-radius: 0 0 var(--radius-s) var(--radius-s); margin-top: 3px; }

@media (prefers-reduced-motion: no-preference) {
  .stack .layer { animation: lay 520ms cubic-bezier(.2, .7, .2, 1) both; animation-delay: var(--d, 0ms); }
}
@keyframes lay { from { transform: scaleX(0.04); opacity: 0.4; } to { transform: none; opacity: 1; } }

.cols { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 2rem 3rem; margin-top: 1rem; }
@media (max-width: 720px) { .cols { grid-template-columns: 1fr; } }

/* Footer ---------------------------------------------------------------- */
.site-footer { border-top: 1px solid var(--rule); padding-block: 2rem 2.5rem; font-size: 0.9375rem; color: var(--muted); }
.site-footer .wrap { display: flex; justify-content: space-between; gap: 1rem 2rem; flex-wrap: wrap; }
.site-footer nav { display: flex; gap: 1.25rem; flex-wrap: wrap; }
.site-footer a { color: var(--muted); }
.site-footer p { margin: 0; max-width: 60ch; }

/* Mobile: keep the main result in view while typing --------------------- */
.minibar { display: none; }
@media (max-width: 860px) {
  main { padding-bottom: 6rem; }
  .minibar {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
    display: flex; justify-content: space-between; align-items: baseline; gap: 1rem;
    padding: 0.8rem 1.25rem calc(0.8rem + env(safe-area-inset-bottom));
    background:
      repeating-linear-gradient(to bottom, transparent 0 calc(var(--layer) - 1px), var(--pla-line) calc(var(--layer) - 1px) var(--layer)),
      var(--pla);
    border-top: 1.5px solid rgba(27, 34, 44, 0.35);
    color: var(--ink); text-decoration: none; font-weight: 600;
    transition: transform 180ms ease;
  }
  .minibar strong { font: 600 1.5rem/1 var(--display); }
  .minibar[data-hidden="true"] { transform: translateY(110%); }
}
@media (prefers-reduced-motion: reduce) { .minibar { transition: none; } }

/* Saffron surfaces keep dark ink in both themes ------------------------ */
.print, .layer, .minibar, .print a { color: var(--pla-ink); }
.print .msg { color: var(--pla-ink); }
.print :focus-visible, .layer:focus-visible, .minibar:focus-visible { outline-color: var(--pla-ink); }
.verdict { background: #fff; }

/* Result header with a picture beside the number ----------------------- */
.print-top { display: flex; justify-content: space-between; align-items: flex-end; gap: 1rem; }
.print-top .print-total { margin-top: 0.4rem; }

/* Cost split: one whole, split into parts (thin segmented bar) ---------- */
.split { display: flex; gap: 2px; margin-top: 1.1rem; }
.split .seg { display: flex; align-items: center; height: 20px; min-width: 3px; cursor: default; }
.split .seg i { display: block; width: 100%; height: 8px; background: var(--c); }
.split .seg:first-child i { border-radius: 4px 0 0 4px; }
.split .seg:last-child i { border-radius: 0 4px 4px 0; }
.split .seg:only-child i { border-radius: 4px; }
.sw { display: inline-block; width: 10px; height: 10px; border-radius: 3px; background: var(--c); margin-right: 0.5rem; }

/* Spool picture -------------------------------------------------------- */
.spool { width: 96px; height: 96px; flex: none; }
.spool .flange { fill: rgba(255, 255, 255, 0.45); stroke: var(--pla-ink); stroke-width: 2; }
.spool .wound { fill: var(--s1); }
.spool .hub { fill: #f2be22; stroke: var(--pla-ink); stroke-width: 2; }
.spool .hole { fill: var(--pla-ink); }
@media (prefers-reduced-motion: no-preference) { .spool .wound { transition: r 260ms ease; } }

/* Home hero with the printing scene ------------------------------------ */
.hero--home { display: grid; grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr); gap: 1.5rem 2.5rem; align-items: center; }
.hero--home h1 { max-width: 14ch; }
@media (max-width: 860px) { .hero--home { grid-template-columns: minmax(0, 1fr); } }
.hero-cta {
  display: inline-block; margin-top: 1.6rem; text-decoration: none;
  background: var(--pla); color: var(--pla-ink); font-weight: 700;
  padding: 0.85rem 1.15rem; border-radius: var(--radius-s);
  box-shadow: inset 0 -3px 0 rgba(120, 82, 0, 0.25);
}
.hero-cta:hover { filter: brightness(1.04); }
.hero-cta:focus-visible { outline-color: var(--ink); }
.scene { width: 100%; max-width: 520px; justify-self: end; cursor: pointer; }
@media (max-width: 860px) { .scene { justify-self: start; max-width: 420px; } }
.scene .plate { fill: var(--edge); }
.scene .plate-top { fill: var(--rule); }
.scene .lyr { fill: #f2be22; }
.scene .lyr-shade { fill: rgba(120, 82, 0, 0.16); }
.scene .gantry { fill: var(--rule); }
.scene .fil { stroke: var(--muted); stroke-width: 2; fill: none; }
.scene .hotend { fill: var(--ink); }
.scene .heater { fill: #3a4452; }
.scene .tip { fill: #b8860b; }
.scene .glow { fill: #ff8a1f; opacity: 0; }
.scene-caption { font-size: 0.8125rem; color: var(--muted); text-align: right; margin-top: 0.25rem; }
@media (max-width: 860px) { .scene-caption { text-align: left; } }

/* Guides --------------------------------------------------------------- */
.article { max-width: 72ch; }
.crumbs { margin: 0 0 0.75rem; font-size: 0.9375rem; }
.crumbs a { color: var(--muted); }
.article .page-head .small { margin-top: 0.75rem; }
.prose ol li + li { margin-top: 0.45rem; }
.prose code { font-size: 0.92em; background: var(--field-2); border-radius: 4px; padding: 0.05rem 0.3rem; }
.callout {
  margin-top: 2rem; padding: 1.1rem 1.3rem; border-radius: var(--radius-s) var(--radius-s) var(--radius-l) var(--radius-l);
  background:
    repeating-linear-gradient(to bottom, transparent 0 calc(var(--layer) - 1px), var(--pla-line) calc(var(--layer) - 1px) var(--layer)),
    var(--pla);
  color: var(--pla-ink);
}
.callout a { color: var(--pla-ink); font-weight: 600; }
.callout-title { margin: 0; font: 600 1.125rem/1.2 var(--display); }
.callout ul { margin-top: 0.5rem; }
.guide-list { list-style: none; padding: 0; margin: 0; max-width: 72ch; }
.guide-list li { padding: 1.1rem 0; border-bottom: 1px solid var(--rule); }
.guide-list li:first-child { border-top: 1px solid var(--rule); }
.guide-list a { font: 600 1.3rem/1.2 var(--display); text-decoration: none; }
.guide-list a:hover { text-decoration: underline; }
.guide-list p { margin: 0.35rem 0 0; color: var(--muted); }
.guide-links { margin-top: 0.75rem; padding-left: 1.2rem; }
.guide-links li + li { margin-top: 0.35rem; }
