/* ==========================================================
   Fraction & Whole Number Calculator
   ========================================================== */

:root {
  --bg: #f6f4ef;
  --bg-grad: radial-gradient(1200px 600px at 10% -10%, #e9e6ff 0%, transparent 60%),
             radial-gradient(900px 500px at 100% 0%, #ffe6dc 0%, transparent 55%);
  --surface: #ffffff;
  --surface-2: #faf9f6;
  --ink: #1d1b26;
  --ink-2: #4a4757;
  --muted: #8a8696;
  --line: #e7e3da;
  --line-strong: #cfc9bc;
  --focus: #5b5bd6;

  --a: #5b5bd6;        /* first number  */
  --a-soft: #e6e6fb;
  --b: #e2613f;        /* second number */
  --b-soft: #fde4dc;
  --r: #0f9b74;        /* answer        */
  --r-soft: #d5f3e8;
  --d: #c98a0b;
  --d-soft: #fbeccb;
  --p: #c2418f;
  --p-soft: #fbe0ef;
  --err: #c2373a;

  --shadow: 0 1px 2px rgba(29, 27, 38, .04), 0 8px 24px -8px rgba(29, 27, 38, .10);
  --shadow-lg: 0 2px 4px rgba(29, 27, 38, .04), 0 24px 48px -16px rgba(29, 27, 38, .18);
  --radius: 20px;
  --radius-sm: 12px;

  --font-display: var(--font-body);
  --font-body: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121118;
    --bg-grad: radial-gradient(1200px 600px at 10% -10%, #22204a 0%, transparent 60%),
               radial-gradient(900px 500px at 100% 0%, #3a1f1a 0%, transparent 55%);
    --surface: #1b1a23;
    --surface-2: #22212c;
    --ink: #f1eff7;
    --ink-2: #c3c0cf;
    --muted: #8d8a9b;
    --line: #2e2c3a;
    --line-strong: #43404f;
    --focus: #9b9bff;
    --a: #8e8eff;
    --a-soft: #2a2950;
    --b: #ff8a68;
    --b-soft: #46261d;
    --r: #3fd3a4;
    --r-soft: #133d31;
    --d: #f2b84b;
    --d-soft: #45361a;
    --p: #f07cc0;
    --p-soft: #45203a;
    --err: #ff6b6e;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 24px -8px rgba(0,0,0,.5);
    --shadow-lg: 0 2px 4px rgba(0,0,0,.3), 0 24px 48px -16px rgba(0,0,0,.6);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #121118;
  --bg-grad: radial-gradient(1200px 600px at 10% -10%, #22204a 0%, transparent 60%),
             radial-gradient(900px 500px at 100% 0%, #3a1f1a 0%, transparent 55%);
  --surface: #1b1a23;
  --surface-2: #22212c;
  --ink: #f1eff7;
  --ink-2: #c3c0cf;
  --muted: #8d8a9b;
  --line: #2e2c3a;
  --line-strong: #43404f;
  --focus: #9b9bff;
  --a: #8e8eff;
  --a-soft: #2a2950;
  --b: #ff8a68;
  --b-soft: #46261d;
  --r: #3fd3a4;
  --r-soft: #133d31;
  --d: #f2b84b;
  --d-soft: #45361a;
  --p: #f07cc0;
  --p-soft: #45203a;
  --err: #ff6b6e;
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 24px -8px rgba(0,0,0,.5);
  --shadow-lg: 0 2px 4px rgba(0,0,0,.3), 0 24px 48px -16px rgba(0,0,0,.6);
  color-scheme: dark;
}

/* ---------- base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { scroll-behavior: smooth; -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.55;
  color: var(--ink);
  background: var(--bg-grad), var(--bg);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}
h1, h2, h3, .h2, .h3 { font-family: var(--font-display); line-height: 1.1; margin: 0; letter-spacing: -0.02em; }
p { margin: 0; }
.h2, .h3 { color: var(--ink); }
button { font: inherit; color: inherit; cursor: pointer; }
svg { display: block; }
:focus-visible { outline: 2.5px solid var(--focus); outline-offset: 2px; border-radius: 8px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.wrap { width: min(1200px, 100% - 32px); margin-inline: auto; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; flex: none; }
.dot-a { background: var(--a); }
.dot-b { background: var(--b); }
.dot-r { background: var(--r); }

/* ---------- header ---------- */
.site-header {
  position: sticky; top: 0; z-index: 20;
  backdrop-filter: saturate(1.4) blur(12px);
  -webkit-backdrop-filter: saturate(1.4) blur(12px);
  background: color-mix(in srgb, var(--bg) 78%, transparent);
  border-bottom: 1px solid color-mix(in srgb, var(--line) 70%, transparent);
}
.header-inner { display: flex; align-items: center; gap: 24px; height: 64px; }
.brand {
  display: flex; align-items: center; gap: 10px;
  font-family: var(--font-display); font-weight: 700; font-size: 17px;
  color: var(--ink); text-decoration: none; letter-spacing: -0.02em;
}
.brand-mark { width: 30px; height: 30px; color: var(--ink); }
.header-nav { display: flex; gap: 4px; margin-left: auto; }
.header-nav a {
  color: var(--ink-2); text-decoration: none; font-size: 14px; font-weight: 500;
  padding: 8px 12px; border-radius: 999px; transition: background .2s, color .2s;
}
.header-nav a:hover { background: var(--surface); color: var(--ink); }
.icon-btn {
  width: 40px; height: 40px; border-radius: 50%;
  border: 1px solid var(--line); background: var(--surface);
  display: grid; place-items: center; transition: transform .2s;
}
.icon-btn:hover { transform: rotate(-15deg); }
.icon-btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; }
.icon-btn .i-moon { display: none; }
:root[data-theme="dark"] .icon-btn .i-sun { display: none; }
:root[data-theme="dark"] .icon-btn .i-moon { display: block; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .icon-btn .i-sun { display: none; }
  :root:not([data-theme="light"]) .icon-btn .i-moon { display: block; }
}

/* ---------- hero ---------- */
.hero { padding: 48px 0 28px; text-align: center; }
.hero h1 { font-size: clamp(32px, 5.2vw, 56px); font-weight: 700; }

/* ---------- calculator ---------- */
.calc { padding: 28px; box-shadow: var(--shadow-lg); }
.calc-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr) auto minmax(0, 1.15fr);
  align-items: stretch;
  gap: 18px;
}

.operand {
  margin: 0; padding: 18px 18px 14px;
  border: 1.5px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  min-width: 0;
  transition: border-color .2s, box-shadow .2s;
}
.operand[data-key="a"]:focus-within { border-color: var(--a); box-shadow: 0 0 0 4px var(--a-soft); }
.operand[data-key="b"]:focus-within { border-color: var(--b); box-shadow: 0 0 0 4px var(--b-soft); }
.operand legend {
  display: flex; align-items: center; gap: 8px;
  padding: 0 6px; margin-left: -6px;
  font-size: 13px; font-weight: 600; color: var(--ink-2);
  text-transform: uppercase; letter-spacing: .06em;
}
.operand-body { display: flex; align-items: center; justify-content: center; gap: 12px; margin-top: 6px; }

.sign-btn {
  width: 34px; height: 34px; flex: none;
  border-radius: 10px; border: 1.5px solid var(--line-strong);
  background: var(--surface); font-family: var(--font-mono); font-weight: 600; font-size: 18px;
  display: grid; place-items: center; line-height: 1;
  transition: background .2s, color .2s, border-color .2s;
}
.sign-btn[aria-pressed="true"] { background: var(--ink); color: var(--surface); border-color: var(--ink); }

.field { position: relative; display: block; }
.field input {
  width: 100%;
  font-family: var(--font-mono); font-weight: 600;
  color: var(--ink); text-align: center;
  background: var(--surface);
  border: 1.5px solid var(--line);
  border-radius: 10px;
  outline: none;
  transition: border-color .15s, background .15s;
  -moz-appearance: textfield;
}
.field input::placeholder { color: var(--line-strong); }
.field input:focus { border-color: var(--ink-2); }
.field input.is-invalid { border-color: var(--err); background: color-mix(in srgb, var(--err) 8%, var(--surface)); }
.whole input { width: 76px; height: 76px; font-size: 32px; }
.field-hint {
  position: absolute; left: 0; right: 0; bottom: -18px;
  text-align: center; font-size: 11px; color: var(--muted); letter-spacing: .04em;
}
.frac-input { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.frac-input input { width: 70px; height: 44px; font-size: 22px; }
.frac-bar { width: 78px; height: 3px; border-radius: 3px; background: var(--ink); }
.operand[data-key="a"] .frac-bar { background: var(--a); }
.operand[data-key="b"] .frac-bar { background: var(--b); }

.operand-readout {
  margin-top: 22px; min-height: 20px;
  text-align: center; font-size: 13px; color: var(--muted);
}
.operand-readout.is-error { color: var(--err); }
.operand-readout .frac { font-size: .9em; }

.ops { display: grid; grid-template-columns: 1fr; gap: 8px; align-content: center; }
.op {
  width: 52px; height: 52px; border-radius: 14px;
  border: 1.5px solid var(--line);
  background: var(--surface);
  font-family: var(--font-mono); font-size: 24px; font-weight: 600;
  display: grid; place-items: center; line-height: 1;
  transition: transform .15s, background .2s, color .2s, border-color .2s, box-shadow .2s;
}
.op:hover { transform: translateY(-1px); border-color: var(--line-strong); }
.op[aria-checked="true"] {
  background: var(--ink); color: var(--surface); border-color: var(--ink);
  box-shadow: 0 6px 16px -6px color-mix(in srgb, var(--ink) 60%, transparent);
}

.equals {
  align-self: center;
  font-family: var(--font-mono); font-size: 36px; color: var(--muted); font-weight: 500;
}

.result {
  position: relative;
  display: flex; flex-direction: column;
  padding: 18px 20px;
  border-radius: var(--radius-sm);
  background: linear-gradient(160deg, var(--r-soft), color-mix(in srgb, var(--r-soft) 30%, var(--surface)));
  border: 1.5px solid color-mix(in srgb, var(--r) 35%, transparent);
  min-width: 0;
}
.result-label {
  display: flex; align-items: center; gap: 8px;
  font-size: 13px; font-weight: 600; color: var(--ink-2);
  text-transform: uppercase; letter-spacing: .06em;
}
.result-main {
  flex: 1;
  display: flex; align-items: center; justify-content: center;
  min-height: 92px; padding: 6px 0;
  font-family: var(--font-display); font-weight: 700; color: var(--ink);
  font-size: 54px;
}
.result-main .num-big { animation: pop .35s cubic-bezier(.2,.9,.3,1.3); display: inline-flex; align-items: center; gap: .14em; }
@keyframes pop { from { transform: scale(.92); opacity: .4; } to { transform: scale(1); opacity: 1; } }
.result-error { color: var(--err); font-weight: 600; text-align: center; padding: 18px 0; }

/* typeset fraction */
.frac {
  display: inline-flex; flex-direction: column; align-items: center;
  vertical-align: middle; line-height: 1; font-size: .62em; margin: 0 .04em;
}
.frac > span { padding: 0 .12em; }
.frac .n { border-bottom: .09em solid currentColor; padding-bottom: .08em; }
.frac .d { padding-top: .08em; }
.minus { margin-right: .04em; }
.mixed { display: inline-flex; align-items: center; white-space: nowrap; }

.result-forms {
  margin: 8px 0 0; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px;
}
.result-forms > div {
  background: color-mix(in srgb, var(--surface) 75%, transparent);
  border-radius: 10px; padding: 8px 10px; min-width: 0;
}
.result-forms dt { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; font-weight: 600; }
.result-forms dd {
  margin: 2px 0 0; font-family: var(--font-mono); font-weight: 600; font-size: 15px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.result-forms .frac { font-size: .82em; }
.ovl { text-decoration: overline; text-decoration-thickness: 1.5px; }

.copy-btn {
  margin-top: 10px; align-self: flex-end;
  display: inline-flex; align-items: center; gap: 6px;
  border: 0; background: transparent; color: var(--ink-2);
  font-size: 13px; font-weight: 600; padding: 6px 8px; border-radius: 8px;
}
.copy-btn:hover { background: color-mix(in srgb, var(--surface) 70%, transparent); color: var(--ink); }
.copy-btn svg, .ghost-btn svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.calc-foot {
  display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap;
  margin-top: 22px; padding-top: 18px; border-top: 1px dashed var(--line);
}
.examples { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.examples-label { font-size: 13px; color: var(--muted); font-weight: 600; margin-right: 2px; }
.chip {
  border: 1px solid var(--line); background: var(--surface-2);
  padding: 6px 12px; border-radius: 999px; font-size: 14px; font-weight: 500;
  transition: background .2s, border-color .2s, transform .15s;
}
.chip:hover { border-color: var(--line-strong); background: var(--surface); transform: translateY(-1px); }
.foot-actions { display: flex; gap: 8px; }
.ghost-btn {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid var(--line); background: transparent;
  padding: 7px 12px; border-radius: 10px; font-size: 14px; font-weight: 500; color: var(--ink-2);
}
.ghost-btn:hover { background: var(--surface-2); color: var(--ink); }

/* ---------- sections ---------- */
.section-head { margin: 56px 0 20px; }
.section-head .h2 { font-size: clamp(26px, 3vw, 34px); font-weight: 700; }
.section-head p:not(.h2) { color: var(--ink-2); margin-top: 6px; }

.vis-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.25fr);
  gap: 20px;
}
.line-card { grid-column: 1 / -1; }
.vis-card { padding: 22px; min-width: 0; }
.vis-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.vis-head .h3 { font-size: 19px; font-weight: 700; }
.vis-sub { font-size: 13px; color: var(--muted); }

/* pies */
.pie-rows { display: grid; gap: 14px; }
.pie-row {
  display: grid; grid-template-columns: 96px minmax(0, 1fr); align-items: center; gap: 12px;
  padding: 10px 12px; border-radius: 14px; background: var(--surface-2);
}
.pie-row.is-result { background: color-mix(in srgb, var(--r-soft) 60%, var(--surface-2)); }
.pie-tag { display: flex; align-items: center; gap: 8px; font-family: var(--font-display); font-weight: 700; font-size: 22px; min-width: 0; }
.pie-tag .frac { font-size: .7em; }
.pies { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; min-height: 56px; }
.pie { width: 56px; height: 56px; flex: none; animation: pieIn .35s ease both; }
@keyframes pieIn { from { transform: scale(.6); opacity: 0; } to { transform: none; opacity: 1; } }
.pie .bg { fill: var(--surface); stroke: var(--line-strong); stroke-width: 1; }
.pie .fill { fill: none; transition: stroke-dasharray .45s cubic-bezier(.3,.8,.3,1); }
.pie .div { stroke: var(--surface); stroke-width: 1.2; }
.pie .rim { fill: none; stroke: var(--line-strong); stroke-width: 1; }
.pie-row[data-pies="a"] .fill { stroke: var(--a); }
.pie-row[data-pies="b"] .fill { stroke: var(--b); }
.pie-row[data-pies="r"] .fill { stroke: var(--r); }
.pie-row.is-neg .pie .fill { stroke-dasharray: 3 2; }
.pie-more {
  font-family: var(--font-mono); font-size: 13px; font-weight: 600; color: var(--ink-2);
  padding: 6px 10px; border-radius: 999px; background: var(--surface);
  border: 1px solid var(--line);
}
.pie-note { font-size: 13px; color: var(--muted); }

/* op visual */
.op-visual { min-height: 200px; display: grid; place-items: center; overflow-x: auto; overscroll-behavior-x: contain; }
.op-visual svg { width: 100%; min-width: 560px; height: auto; overflow: visible; }
.op-visual .empty { color: var(--muted); font-size: 14px; text-align: center; max-width: 360px; padding: 24px; }
.op-caption { margin-top: 12px; font-size: 14px; color: var(--ink-2); text-align: center; min-height: 22px; }
.op-caption .frac { font-size: .8em; }
@media (max-width: 640px) { .op-visual { place-items: start; min-height: 0; } }
.op-caption strong { color: var(--ink); }

.cell-a { fill: var(--a); }
.cell-b { fill: var(--b); }
.cell-r { fill: var(--r); }
.cell-gap { stroke: var(--surface); stroke-width: 1.4; }
.unit-frame { fill: none; stroke: var(--ink); stroke-width: 1.6; }
.unit-bg { fill: var(--surface-2); stroke: var(--line-strong); stroke-width: 1; stroke-dasharray: 4 3; }
.svg-label { font-family: var(--font-body); font-size: 13px; font-weight: 600; fill: var(--ink-2); }
.svg-label-strong { font-family: var(--font-display); font-size: 15px; font-weight: 700; fill: var(--ink); }
.svg-label-muted { font-family: var(--font-body); font-size: 12px; fill: var(--muted); }
.svg-mono { font-family: var(--font-mono); font-size: 12px; font-weight: 600; fill: var(--ink-2); }
.hatch-line { stroke: var(--b); stroke-width: 2; }
.grow { transform-box: fill-box; transform-origin: left center; animation: growX .5s cubic-bezier(.3,.8,.3,1) both; }
@keyframes growX { from { transform: scaleX(0); } to { transform: none; } }
.fade { animation: fadeIn .4s ease both; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

/* number line */
.numline-wrap { overflow-x: auto; overscroll-behavior-x: contain; }
.numline { width: 100%; min-width: 640px; height: auto; overflow: visible; }
.numline .axis { stroke: var(--ink); stroke-width: 2; }
.numline .tick { stroke: var(--ink); stroke-width: 1.6; }
.numline .tick-minor { stroke: var(--line-strong); stroke-width: 1; }
.numline .tick-label { font-family: var(--font-mono); font-size: 14px; font-weight: 600; fill: var(--ink-2); text-anchor: middle; }
.numline .marker { transition: transform .5s cubic-bezier(.3,.8,.3,1), opacity .3s; }
.numline .marker text { font-family: var(--font-display); font-size: 15px; font-weight: 700; text-anchor: middle; }
.numline .m-a circle, .numline .m-a path { fill: var(--a); }
.numline .m-b circle, .numline .m-b path { fill: var(--b); }
.numline .m-r circle, .numline .m-r path { fill: var(--r); }
.numline .m-a text { fill: var(--a); }
.numline .m-b text { fill: var(--b); }
.numline .m-r text { fill: var(--r); }
.numline .m-stem { stroke-width: 1.5; stroke-dasharray: 3 3; }
.numline .m-a .m-stem { stroke: var(--a); }
.numline .m-b .m-stem { stroke: var(--b); }
.numline .m-r .m-stem { stroke: var(--r); }
.numline .m-halo { fill: var(--surface) !important; }
.numline .jump { fill: none; stroke: var(--b); stroke-width: 2.2; stroke-dasharray: 6 5; animation: dash 1s linear infinite; }
.numline .jump-head { fill: var(--b); }
.numline .jump-label { font-family: var(--font-mono); font-size: 13px; font-weight: 600; fill: var(--b); text-anchor: middle; }
@keyframes dash { to { stroke-dashoffset: -22; } }
.legend { display: flex; gap: 18px; justify-content: center; flex-wrap: wrap; margin-top: 8px; font-size: 13px; color: var(--ink-2); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }

/* steps */
.steps-section { margin-top: 20px; }
.steps-layout { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 20px; align-items: start; }
.steps-card, .history-card { padding: 22px; }
.steps { list-style: none; margin: 0; padding: 0; counter-reset: step; display: grid; gap: 4px; }
.steps li {
  counter-increment: step;
  display: grid; grid-template-columns: 32px minmax(0, 1fr); gap: 14px;
  padding: 12px 0; border-top: 1px solid var(--line);
  animation: fadeIn .35s ease both;
}
.steps li:first-child { border-top: 0; }
.steps li::before {
  content: counter(step);
  width: 30px; height: 30px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--surface-2); border: 1px solid var(--line);
  font-family: var(--font-mono); font-weight: 600; font-size: 13px; color: var(--ink-2);
}
.steps li:last-child::before { background: var(--r); border-color: var(--r); color: #fff; }
.step-title { font-weight: 600; font-size: 15px; }
.step-note { font-size: 14px; color: var(--muted); margin-top: 2px; }
.step-math {
  margin-top: 8px; font-family: var(--font-display); font-size: 24px; font-weight: 600;
  display: flex; align-items: center; flex-wrap: wrap; gap: .3em; line-height: 1.2;
}
.step-math .frac { font-size: .72em; }
.step-math .sym { color: var(--muted); font-weight: 500; font-family: var(--font-mono); font-size: .8em; }
.step-math .ca { color: var(--a); }
.step-math .cb { color: var(--b); }
.step-math .cr { color: var(--r); }
.step-math .hl { background: color-mix(in srgb, var(--focus) 14%, transparent); border-radius: 6px; padding: 0 .15em; }

.history { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.history button {
  width: 100%; text-align: left;
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
  border: 1px solid var(--line); background: var(--surface-2);
  border-radius: 10px; padding: 8px 12px;
  font-family: var(--font-mono); font-size: 13px; font-weight: 500;
  transition: border-color .2s, background .2s;
}
.history button:hover { border-color: var(--line-strong); background: var(--surface); }
.history .h-ans { color: var(--r); font-weight: 600; white-space: nowrap; }
.history-empty { font-size: 14px; color: var(--muted); }
.link-btn { border: 0; background: none; color: var(--muted); font-size: 13px; font-weight: 600; padding: 4px 6px; border-radius: 6px; }
.link-btn:hover { color: var(--ink); }

/* guide */
.rules { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; }
.rule {
  --rc: var(--a); --rc-soft: var(--a-soft);
  padding: 22px; position: relative; overflow: hidden;
  display: flex; flex-direction: column;
  transition: transform .2s, box-shadow .2s, border-color .2s;
}
.rule::before {
  content: ""; position: absolute; inset: 0 0 auto 0; height: 4px;
  background: linear-gradient(90deg, var(--rc), color-mix(in srgb, var(--rc) 35%, transparent));
}
.rule::after {
  content: ""; position: absolute; width: 180px; height: 180px; border-radius: 50%;
  top: -90px; inset-inline-end: -70px;
  background: radial-gradient(circle, var(--rc-soft), transparent 70%);
  opacity: .9; pointer-events: none;
}
.rule:hover { transform: translateY(-3px); box-shadow: var(--shadow-lg); border-color: color-mix(in srgb, var(--rc) 35%, var(--line)); }
.rule-sub2 { --rc: var(--b); --rc-soft: var(--b-soft); }
.rule-mul { --rc: var(--r); --rc-soft: var(--r-soft); }
.rule-div { --rc: var(--d); --rc-soft: var(--d-soft); }
.rule-top { position: relative; z-index: 1; display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.rule-icon {
  width: 48px; height: 48px; border-radius: 14px;
  display: grid; place-items: center; color: var(--surface);
  background: linear-gradient(145deg, color-mix(in srgb, var(--rc) 80%, #fff), var(--rc));
  box-shadow: 0 8px 18px -8px var(--rc), inset 0 1px 0 rgba(255,255,255,.35);
}
.rule-icon svg { fill: none; stroke: currentColor; stroke-width: 2.6; stroke-linecap: round; }
.rule-num { font-family: var(--font-mono); font-size: 13px; font-weight: 600; color: var(--muted); letter-spacing: .08em; }
.rule .h3 { position: relative; z-index: 1; font-size: 19px; font-weight: 700; margin-bottom: 8px; }
.rule p:not(.h3) { position: relative; z-index: 1; font-size: 14px; color: var(--ink-2); }
.rule-example {
  margin-top: auto; padding-top: 16px;
  display: flex; align-items: center; flex-wrap: wrap; gap: .32em;
  font-size: 22px; font-weight: 700; line-height: 1.2;
}
.rule-example::before {
  content: ""; flex-basis: 100%; height: 1px; margin-bottom: 12px;
  background: repeating-linear-gradient(90deg, var(--line-strong) 0 4px, transparent 4px 8px);
}
.rule-example .frac { font-size: .72em; }
.rule-example .mixed .frac { margin-inline-start: .06em; }
.rule-example .sym { color: var(--muted); font-weight: 500; font-family: var(--font-mono); font-size: .78em; }
.rule-example .ca { color: var(--a); }
.rule-example .cb { color: var(--b); }
.rule-example .cr { color: var(--r); background: var(--r-soft); border-radius: 8px; padding: 2px 6px; }
.faq { margin-top: 24px; display: grid; gap: 10px; }
.faq details {
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 0 20px;
}
.faq summary {
  cursor: pointer; list-style: none; padding: 16px 0; font-weight: 600;
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
}
.faq summary::-webkit-details-marker { display: none; }
.faq summary::after { content: "+"; font-family: var(--font-mono); font-size: 20px; color: var(--muted); transition: transform .2s; }
.faq details[open] summary::after { transform: rotate(45deg); }
.faq details p { padding-bottom: 16px; color: var(--ink-2); font-size: 15px; }

.site-footer { margin-top: 64px; padding: 28px 0 40px; border-top: 1px solid var(--line); color: var(--muted); font-size: 14px; text-align: center; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px);
  background: var(--ink); color: var(--surface);
  padding: 10px 16px; border-radius: 999px; font-size: 14px; font-weight: 600;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 50;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- responsive ---------- */
@media (max-width: 1080px) {
  .calc-row { grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); }
  .equals { display: none; }
  .result { grid-column: 1 / -1; }
  .rules { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 860px) {
  .vis-grid { grid-template-columns: minmax(0, 1fr); }
  .steps-layout { grid-template-columns: minmax(0, 1fr); }
  .header-nav { display: none; }
  .header-inner { justify-content: space-between; gap: 12px; }
  .brand { font-size: 15px; min-width: 0; }
  .brand span { line-height: 1.2; }
}
@media (max-width: 640px) {
  .hero { padding: 32px 0 20px; }
  .calc { padding: 16px; }
  .calc-row { grid-template-columns: minmax(0, 1fr); gap: 12px; }
  .ops { grid-template-columns: repeat(4, 1fr); justify-items: center; }
  .op { width: 100%; max-width: 72px; height: 48px; }
  .operand-body { gap: 10px; }
  .whole input { width: 68px; height: 68px; font-size: 28px; }
  .result-main { font-size: 44px; min-height: 76px; }
  .result-forms dd { font-size: 13px; }
  .vis-card, .steps-card, .history-card { padding: 16px; }
  .pie-row { grid-template-columns: 64px minmax(0, 1fr); gap: 8px; padding: 10px; }
  .pie-tag { font-size: 19px; }
  .pie { width: 46px; height: 46px; }
  .rules { grid-template-columns: minmax(0, 1fr); }
  .step-math { font-size: 20px; }
  .section-head { margin-top: 40px; }
  .calc-foot { flex-direction: column; align-items: stretch; }
  .foot-actions { justify-content: flex-end; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
  html { scroll-behavior: auto; }
}

/* ==========================================================
   Site pages, footer, i18n
   ========================================================== */
.skip-link {
  position: absolute; left: 16px; top: -60px; z-index: 100;
  background: var(--ink); color: var(--surface);
  padding: 10px 16px; border-radius: 10px; font-weight: 600; text-decoration: none;
  transition: top .15s;
}
.skip-link:focus { top: 12px; }
main:focus { outline: none; }

/* footer */
.site-footer { text-align: start; padding: 40px 0 28px; }
.footer-grid {
  display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(0, .8fr) minmax(0, 1.6fr); gap: 32px;
}
.footer-brand .brand { font-size: 16px; }
.footer-brand p { margin-top: 10px; max-width: 320px; }
.footer-h {
  font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em;
  color: var(--ink-2); margin-bottom: 10px;
}
.footer-nav ul, .lang-list { list-style: none; margin: 0; padding: 0; }
.footer-nav li + li { margin-top: 6px; }
.site-footer a { color: var(--ink-2); text-decoration: none; }
.site-footer a:hover { color: var(--ink); text-decoration: underline; text-underline-offset: 3px; }
.lang-list { display: flex; flex-wrap: wrap; gap: 6px; }
.lang-list a {
  display: inline-block; padding: 4px 10px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--surface); font-size: 13px;
}
.lang-list a:hover { text-decoration: none; border-color: var(--line-strong); }
.lang-list a[aria-current="true"] { background: var(--ink); color: var(--surface); border-color: var(--ink); }
.footer-bottom { margin-top: 28px; padding-top: 18px; border-top: 1px solid var(--line); font-size: 13px; }

/* home supporting content + FAQ section */
.about-tool { margin-top: 16px; padding: 22px; }
.about-tool .h3 { font-size: 19px; font-weight: 700; margin-bottom: 8px; }
.about-tool p:not(.h3) { color: var(--ink-2); font-size: 15px; max-width: 900px; }
.about-tool p + p { margin-top: 10px; }

/* text pages */
.page-hero { padding-bottom: 20px; }
.page-hero h1 { font-size: clamp(30px, 4.4vw, 46px); }
.page-lead { color: var(--ink-2); font-size: 17px; max-width: 680px; margin: 14px auto 0; }
.page-updated { color: var(--muted); font-size: 14px; margin-top: 8px; }
.breadcrumbs ol {
  list-style: none; margin: 0 0 16px; padding: 0;
  display: flex; justify-content: center; gap: 8px; font-size: 14px; color: var(--muted);
}
.breadcrumbs li + li::before { content: "/"; margin-inline-end: 8px; color: var(--line-strong); }
.breadcrumbs a { color: var(--ink-2); text-decoration: none; }
.breadcrumbs a:hover { text-decoration: underline; }
.page-body { max-width: 860px; }
.prose { padding: 28px 32px; }
.prose h2 { font-size: 22px; font-weight: 700; margin: 28px 0 10px; }
.prose h2:first-child { margin-top: 0; }
.prose h3 { font-size: 17px; font-weight: 600; margin: 18px 0 6px; }
.prose p, .prose li { color: var(--ink-2); }
.prose p + p { margin-top: 10px; }
.prose ul { padding-inline-start: 22px; margin: 10px 0; }
.prose li + li { margin-top: 6px; }
.prose a, .text-link { color: var(--a); text-underline-offset: 3px; }
.prose strong { color: var(--ink); }
.prose kbd, .prose code {
  font-family: var(--font-mono); font-size: .85em; color: var(--ink);
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 6px; padding: 1px 6px;
}
.prose kbd { border-bottom-width: 2px; }

.sitemap-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 20px; }
.sitemap-grid .prose { padding: 24px; }
.sm-langs { columns: 1; }

.notfound { text-align: center; }
.notfound ul { display: inline-block; text-align: start; }
.notfound-code {
  font-size: 72px; font-weight: 700; letter-spacing: -0.04em; color: var(--ink) !important; line-height: 1; margin-bottom: 16px;
}
.notfound-code span { color: var(--r); }

/* contact */
.page-body:has(.contact-layout) { max-width: 1000px; }
.contact-layout { display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr); gap: 20px; align-items: start; }
.contact-form { padding: 28px; display: grid; gap: 18px; }
.form-field { display: grid; gap: 6px; }
.form-field label { font-weight: 600; font-size: 14px; }
.form-field input, .form-field textarea {
  font: inherit; color: var(--ink); background: var(--surface-2);
  border: 1.5px solid var(--line); border-radius: 10px; padding: 10px 12px; width: 100%;
  transition: border-color .15s, box-shadow .15s;
}
.form-field textarea { resize: vertical; min-height: 140px; }
.form-field input:focus, .form-field textarea:focus { outline: none; border-color: var(--a); box-shadow: 0 0 0 4px var(--a-soft); }
.form-hint { font-size: 13px; color: var(--muted); }
.form-hp { position: absolute; left: -9999px; width: 1px; height: 1px; overflow: hidden; }
.primary-btn {
  justify-self: start; border: 0; border-radius: 12px; padding: 12px 22px;
  background: var(--ink); color: var(--surface); font-weight: 600; font-size: 15px;
  transition: transform .15s, opacity .2s;
}
.primary-btn:hover { transform: translateY(-1px); }
.primary-btn:disabled { opacity: .6; cursor: progress; transform: none; }
.form-status { font-size: 14px; min-height: 20px; }
.form-status.is-sending { color: var(--ink-2); }
.form-status.is-success { color: var(--r); font-weight: 600; }
.form-status.is-error { color: var(--err); }
.form-status a { color: inherit; font-weight: 600; }
.contact-aside { padding: 24px; }
.contact-aside h2 { font-size: 17px; font-weight: 700; margin-bottom: 6px; }
.contact-aside h2 + p { color: var(--ink-2); }
.contact-aside p + h2 { margin-top: 20px; }
.contact-aside p { color: var(--ink-2); font-size: 15px; }
.contact-aside .text-link { font-weight: 600; word-break: break-all; }

/* RTL: mirror layout but keep maths left-to-right */
[dir="rtl"] .operand legend { margin-left: 0; margin-right: -6px; }
[dir="rtl"] .copy-btn { align-self: flex-start; }
[dir="rtl"] .operand-body, [dir="rtl"] .examples button { direction: ltr; }
.mixed, .frac { direction: ltr; unicode-bidi: isolate; }
[dir="rtl"] .step-math { direction: ltr; justify-content: flex-end; }
.ltr-math { direction: ltr; unicode-bidi: isolate; display: inline-block; }
[dir="rtl"] .icon-btn:hover { transform: rotate(15deg); }

@media (max-width: 860px) {
  .footer-grid { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .footer-lang { grid-column: 1 / -1; }
  .contact-layout, .sitemap-grid { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 640px) {
  .footer-grid { grid-template-columns: minmax(0, 1fr); gap: 24px; }
  .prose, .contact-form { padding: 20px; }
}

/* ==========================================================
   Sub-calculator pages
   ========================================================== */
.page-body:has(.sub-wrap) { max-width: none; }
.sub-wrap { display: grid; gap: 20px; }
.sub-calc .calc-row--single { grid-template-columns: minmax(0, 1fr) auto minmax(0, 1.2fr); }
.calc-row.reversed > .operand[data-key="a"] { order: 3; }
.calc-row.reversed > .ops { order: 2; }
.calc-row.reversed > .operand[data-key="b"] { order: 1; }
.calc-row.reversed > .equals { order: 4; }
.calc-row.reversed > .result { order: 5; }
.order-switch { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 18px; }
.order-switch .chip[aria-checked="true"] { background: var(--ink); color: var(--surface); border-color: var(--ink); }
.op-static { cursor: default; background: var(--ink); color: var(--surface); border-color: var(--ink); }
.op-static:hover { transform: none; }
.op-word { font-family: var(--font-body); font-size: 15px; width: auto; min-width: 52px; padding: 0 10px; }
.unit-one {
  width: 70px; height: 44px; display: grid; place-items: center;
  font-family: var(--font-mono); font-weight: 600; font-size: 22px;
  border: 1.5px dashed var(--line-strong); border-radius: 10px; color: var(--ink-2);
}
.sub-vis .vis-head h2 { font-size: 19px; font-weight: 700; }
.sub-visual { min-height: 180px; }
.sub-grid { display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); gap: 20px; align-items: start; }
.sub-grid .steps-card .vis-head h2 { font-size: 19px; font-weight: 700; }
.sub-how ol, .sub-how ul { padding-inline-start: 22px; }
.related { padding: 22px; }
.related h2 { font-size: 19px; font-weight: 700; margin-bottom: 12px; }
.related-list { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 8px; }
.related-list a {
  display: inline-block; padding: 7px 12px; border-radius: 999px; font-size: 14px;
  border: 1px solid var(--line); background: var(--surface-2); color: var(--ink-2); text-decoration: none;
}
.related-list a:hover { border-color: var(--line-strong); color: var(--ink); }
.related-more { margin-top: 14px; }
.related-more summary { cursor: pointer; font-weight: 600; font-size: 14px; color: var(--ink-2); margin-bottom: 10px; }

/* sub-calculator picture parts */
.sub-visual svg { width: 100%; min-width: 560px; height: auto; overflow: visible; }
.pie-bg { fill: var(--surface); stroke: var(--line-strong); stroke-width: 1; }
.pie-line { stroke: var(--surface); stroke-width: 1.3; }
.pie-rim { fill: none; stroke: var(--line-strong); stroke-width: 1; }
.cell-a-soft { fill: var(--a-soft); }
.cell-d { fill: var(--d); }
.cell-b-soft { fill: var(--b-soft); }
.cell-r-soft { fill: color-mix(in srgb, var(--r) 45%, var(--surface)); }
.cell-a-alt { fill: color-mix(in srgb, var(--a) 60%, var(--surface)); }
.cell-b-alt { fill: color-mix(in srgb, var(--b) 60%, var(--surface)); }
.take { fill: url(#hatch); }
.hatch-bg { fill: var(--b-soft); }
.hatch-ln { stroke: var(--b); stroke-width: 2.2; }
.dashed-r { fill: none; stroke: var(--r); stroke-width: 1.6; stroke-dasharray: 5 4; }
.dot-empty { fill: var(--surface); stroke: var(--line-strong); stroke-width: 1.2; }
.nl-axis { stroke: var(--ink); stroke-width: 2; }
.nl-tick { stroke: var(--ink); stroke-width: 1.6; }
.nl-minor { stroke: var(--line-strong); stroke-width: 1; }
.unit-ln { stroke: var(--ink); stroke-width: 1.6; }
.col-ln { stroke: var(--ink-2); stroke-width: 1; opacity: .5; }
.row-ln { stroke: var(--b); stroke-width: 2; stroke-dasharray: 6 4; }
.dim-a { stroke: var(--a); stroke-width: 3; stroke-linecap: round; }
.dim-b { stroke: var(--b); stroke-width: 3; stroke-linecap: round; }
.guide-a { stroke: var(--a); stroke-width: 1.4; stroke-dasharray: 3 3; }
.guide-r { stroke: var(--r); stroke-width: 1.4; stroke-dasharray: 3 3; }
.guide-b { stroke: var(--b); stroke-width: 2; }
.jump-arc { fill: none; stroke: var(--a); stroke-width: 2.4; }
.jump-arc.alt { stroke: var(--b); }
.stretch-arrow { fill: none; stroke: var(--ink-2); stroke-width: 1.8; stroke-dasharray: 5 4; }
.seg-a { stroke: var(--a); stroke-width: 10; stroke-linecap: round; opacity: .35; }
.seg-r { stroke: var(--r); stroke-width: 10; stroke-linecap: round; }
.part-tick { stroke: var(--b); stroke-width: 2.4; }
.brace, .brace-a, .brace-b { fill: none; stroke-width: 1.8; }
.brace { stroke: var(--ink-2); }
.brace-a { stroke: var(--a); }
.brace-b { stroke: var(--b); }
.plate { fill: var(--surface-2); stroke: var(--line-strong); stroke-width: 1; }
.neg-zone { fill: var(--b-soft); opacity: .6; }
.grid-major { stroke: var(--line-strong); stroke-width: 1; }
.grid-minor { stroke: var(--line); stroke-width: 1; }
.ruler-body { fill: var(--d-soft); stroke: var(--d); stroke-width: 1.5; }
.ruler-tick { stroke: var(--ink); stroke-width: 1.3; }
.on-color { fill: #fff; font-weight: 600; }
.a-text { fill: var(--a); }
.b-text { fill: var(--b); }
.r-text { fill: var(--r); }
.d-text { fill: var(--d); }
/* keep, change, flip cards */
.kcf-card { fill: var(--surface-2); stroke: var(--line-strong); stroke-width: 1.4; }
.kcf-card.a { fill: var(--a-soft); stroke: var(--a); }
.kcf-card.b { fill: var(--b-soft); stroke: var(--b); }
.kcf-card.r { fill: var(--r-soft); stroke: var(--r); stroke-width: 2; }
.kcf-card.flipped { fill: color-mix(in srgb, var(--r-soft) 55%, var(--surface)); stroke: var(--r); stroke-dasharray: 6 4; }
.kcf-card.ghost { fill: none; stroke-dasharray: 5 5; }
.kcf-num { font-family: var(--font-display); font-weight: 700; fill: var(--ink); }
.kcf-bar { stroke: var(--ink); stroke-width: 2.4; stroke-linecap: round; }
.kcf-op { font-family: var(--font-display); font-size: 34px; font-weight: 700; fill: var(--ink); }
.kcf-op.muted { fill: var(--muted); }
.kcf-chip { fill: var(--d-soft); stroke: var(--d); stroke-width: 1.6; }
.kcf-arrow { fill: none; stroke: var(--ink-2); stroke-width: 2; }
.kcf-arrow.change { stroke: var(--d); stroke-dasharray: 4 4; }
.kcf-arrow.flip { stroke: var(--r); }
.kcf-head { fill: var(--ink-2); }
.grow-up { transform-box: fill-box; transform-origin: center bottom; animation: growY .5s cubic-bezier(.3,.8,.3,1) both; }
@keyframes growY { from { transform: scaleY(0); } to { transform: none; } }

@media (max-width: 1080px) {
  .sub-calc .calc-row--single { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 860px) {
  .sub-grid { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 640px) {
  .sub-visual { place-items: start; }
}

/* homepage: more calculators */
.calc-groups { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.calc-group:last-child:nth-child(odd) { grid-column: 1 / -1; }
.calc-group:last-child:nth-child(odd) ul { grid-template-columns: repeat(2, minmax(0, 1fr)); column-gap: 16px; }
@media (max-width: 640px) {
  .calc-groups, .calc-group:last-child:nth-child(odd) ul { grid-template-columns: minmax(0, 1fr); }
}
.calc-group {
  --gc: var(--a); --gc-soft: var(--a-soft);
  padding: 22px 18px 16px; position: relative; overflow: hidden;
  display: flex; flex-direction: column;
  transition: transform .2s, box-shadow .2s, border-color .2s;
}
.calc-group::before {
  content: ""; position: absolute; inset: 0 0 auto 0; height: 4px;
  background: linear-gradient(90deg, var(--gc), color-mix(in srgb, var(--gc) 30%, transparent));
}
.calc-group::after {
  content: ""; position: absolute; width: 170px; height: 170px; border-radius: 50%;
  top: -95px; inset-inline-end: -75px;
  background: radial-gradient(circle, var(--gc-soft), transparent 70%);
  pointer-events: none;
}
.calc-group:hover { transform: translateY(-3px); box-shadow: var(--shadow-lg); border-color: color-mix(in srgb, var(--gc) 35%, var(--line)); }
.calc-group--mul { --gc: var(--r); --gc-soft: var(--r-soft); }
.calc-group--div { --gc: var(--d); --gc-soft: var(--d-soft); }
.calc-group--addsub { --gc: var(--a); --gc-soft: var(--a-soft); }
.calc-group--mixed { --gc: var(--b); --gc-soft: var(--b-soft); }
.calc-group--convert { --gc: var(--p); --gc-soft: var(--p-soft); }
.calc-group-head { position: relative; z-index: 1; display: flex; align-items: center; gap: 12px; padding: 0 4px; margin-bottom: 14px; min-height: 56px; }
.calc-group-icon {
  flex: none; width: 44px; height: 44px; border-radius: 13px;
  display: grid; place-items: center; color: var(--surface);
  background: linear-gradient(145deg, color-mix(in srgb, var(--gc) 78%, #fff), var(--gc));
  box-shadow: 0 8px 18px -8px var(--gc), inset 0 1px 0 rgba(255,255,255,.35);
}
.calc-group-icon svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2.5; stroke-linecap: round; stroke-linejoin: round; }
.calc-group .h3 { font-size: 17px; font-weight: 700; line-height: 1.2; }
.calc-group-count { display: block; margin-top: 3px; font-family: var(--font-mono); font-size: 11.5px; font-weight: 600; letter-spacing: .04em; color: var(--gc); }
.calc-group ul { position: relative; z-index: 1; list-style: none; margin: 0; padding: 10px 0 0; display: grid; gap: 2px; border-top: 1px solid var(--line); }
.calc-group a {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 8px 6px 8px 10px; border-radius: 10px;
  color: var(--ink-2); text-decoration: none; font-size: 14.5px; line-height: 1.4;
  transition: background-color .15s, color .15s;
}
.calc-arrow { flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; color: var(--gc); opacity: 0; transform: translateX(-4px); transition: opacity .15s, transform .15s; }
.calc-group a:hover, .calc-group a:focus-visible { background: color-mix(in srgb, var(--gc-soft) 75%, transparent); color: var(--ink); }
.calc-group a:hover .calc-arrow, .calc-group a:focus-visible .calc-arrow { opacity: 1; transform: none; }
@media (prefers-reduced-motion: reduce) { .calc-group, .calc-group:hover, .calc-arrow { transition: none; transform: none; } }
.sitemap-grid .sm-calcs { grid-column: 1 / -1; }
.sm-calcs ul { columns: 2; column-gap: 32px; }
@media (max-width: 640px) { .sm-calcs ul { columns: 1; } }

/* ==========================================================
   Homepage explainer sections (English)
   ========================================================== */

.lead-answer { font-size: 17px; color: var(--ink-2); max-width: 900px; margin: -6px 0 20px; }
.lead-answer strong { color: var(--ink); font-weight: 600; }
.rules-lead { margin: 24px 0 14px; color: var(--ink-2); font-size: 15px; }

/* 5-step flow */
.flow {
  list-style: none; margin: 0 0 20px; padding: 0;
  display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 14px; counter-reset: none;
}
.flow-step {
  position: relative; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-sm);
  box-shadow: var(--shadow); padding: 18px 16px 16px; display: flex; flex-direction: column; gap: 6px;
}
.flow-step:not(:last-child)::after {
  content: ""; position: absolute; top: 34px; inset-inline-end: -14px; width: 14px; height: 2px; background: var(--line-strong);
}
.flow-num {
  width: 32px; height: 32px; border-radius: 10px; display: grid; place-items: center;
  font-family: var(--font-mono); font-weight: 600; font-size: 14px; color: var(--surface); background: var(--ink);
}
.flow-step:nth-child(2) .flow-num { background: var(--a); }
.flow-step:nth-child(3) .flow-num { background: var(--b); }
.flow-step:nth-child(4) .flow-num { background: var(--d); }
.flow-step:nth-child(5) .flow-num { background: var(--r); }
.flow-title { font-weight: 700; font-size: 16px; margin-top: 4px; }
.flow-body { font-size: 14px; color: var(--ink-2); }
.flow-math {
  margin-top: auto; padding-top: 10px; border-top: 1px dashed var(--line);
  display: flex; align-items: center; flex-wrap: wrap; gap: .3em; font-weight: 700; font-size: 18px;
}
.flow-math .frac { font-size: .72em; }
.flow-math .sym, .formula-table .sym { color: var(--muted); font-weight: 500; font-family: var(--font-mono); }
.explain { margin-bottom: 8px; }
.explain .h3 { font-size: 18px; font-weight: 700; margin: 18px 0 6px; }

/* content sections */
.content-section { margin-top: 8px; }
.content-grid { display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr); gap: 20px; align-items: start; margin-bottom: 20px; }
.content-grid .vis-card .h3 { font-size: 18px; font-weight: 700; margin-bottom: 12px; }
.content-grid .prose { padding: 24px; }
.vis-note { margin-top: 10px; font-size: 14px; color: var(--ink-2); text-align: center; }
.static-vis { display: block; width: 100%; height: auto; overflow: visible; }
.static-vis--sm { max-width: 520px; margin: 12px 0; }
.anat-big { font-family: var(--font-display); font-weight: 700; font-size: 120px; fill: var(--b); }
.anat-num { font-family: var(--font-display); font-weight: 700; font-size: 62px; fill: var(--a); }
.anat-den { fill: var(--r); }
.anat-bar { stroke: var(--ink); stroke-width: 6; stroke-linecap: round; }
.anat-call { fill: none; stroke: var(--line-strong); stroke-width: 1.5; stroke-dasharray: 4 3; }

/* tables */
.table-wrap { overflow-x: auto; border-radius: var(--radius-sm); border: 1px solid var(--line); background: var(--surface); box-shadow: var(--shadow); }
.data-table { width: 100%; border-collapse: collapse; font-size: 15px; }
.data-table caption { text-align: start; padding: 14px 18px; font-weight: 700; font-size: 16px; color: var(--ink); }
.data-table th, .data-table td { padding: 10px 18px; text-align: start; border-top: 1px solid var(--line); vertical-align: middle; }
.data-table thead th { font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); background: var(--surface-2); }
.data-table tbody th { font-weight: 600; }
.data-table tbody tr:hover { background: var(--surface-2); }
.data-table .frac { font-size: .82em; }
.data-table td strong { color: var(--r); }
.formula-table td { font-size: 17px; }

/* FAQ answers */
.faq-answer { padding-bottom: 16px; color: var(--ink-2); font-size: 15px; }
.faq-answer p + p, .faq-answer ul + p { margin-top: 10px; }
.faq-answer ul { margin: 10px 0; padding-inline-start: 22px; }
.faq-answer li + li { margin-top: 4px; }
.faq-answer strong { color: var(--ink); }
.faq-section .faq { margin-top: 0; }

@media (max-width: 1080px) {
  .flow { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .flow-step::after { display: none; }
}
@media (max-width: 860px) {
  .content-grid { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 640px) {
  .flow { grid-template-columns: minmax(0, 1fr); }
  .data-table th, .data-table td { padding: 8px 12px; }
}

.static-vis .svg-label, .static-vis .svg-mono { font-size: 18px; }
.static-vis .svg-label-strong { font-size: 20px; }
.static-vis .svg-label-muted { font-size: 15px; }

/* ==========================================================
   Sub-calculator explainer sections
   ========================================================== */
.sub-section { display: grid; gap: 16px; }
.sub-section > h2 { font-size: clamp(24px, 2.8vw, 30px); font-weight: 700; margin-top: 16px; }
.sub-section .lead-answer { margin: 0; }
.sub-note { color: var(--ink-2); font-size: 15px; max-width: 900px; }
.flow-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.formula-card { padding: 26px 28px; display: grid; gap: 18px; }
.formula-main {
  display: flex; align-items: center; flex-wrap: wrap; gap: .35em; justify-content: center;
  font-size: clamp(24px, 3.4vw, 34px); font-weight: 700; padding: 18px; border-radius: 14px;
  background: var(--surface-2); border: 1px dashed var(--line-strong);
}
.formula-main .frac { font-size: .66em; }
.formula-main .sym, .formula-example .sym { color: var(--muted); font-weight: 500; font-family: var(--font-mono); font-size: .8em; }
.formula-sep { flex-basis: 100%; height: 0; }
.formula-note { flex-basis: 100%; text-align: center; font-size: 14px; font-weight: 500; color: var(--muted); }
.fv { font-family: var(--font-mono); font-weight: 700; }
.fv.ca { color: var(--a); } .fv.cb { color: var(--b); } .fv.cr { color: var(--r); }
.formula-legend { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 10px 22px; justify-content: center; font-size: 15px; color: var(--ink-2); }
.formula-legend .fv { padding: 2px 8px; border-radius: 6px; background: var(--surface-2); border: 1px solid var(--line); }
.formula-example { display: flex; align-items: center; flex-wrap: wrap; gap: .35em; justify-content: center; font-size: 22px; font-weight: 600; }
.formula-example .frac { font-size: .7em; }
.formula-example strong { color: var(--r); }
.formula-tag { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin-inline-end: 10px; }
.chart-table td, .chart-table th { white-space: nowrap; }
.chart-table td.heat { background: color-mix(in srgb, var(--r) calc(var(--p) * 30%), transparent); font-weight: 600; }
.chart-table td.heat.neg { background: color-mix(in srgb, var(--b) calc(var(--p) * 30%), transparent); color: var(--b); }
.chart-table td small { display: block; font-size: 12px; font-weight: 500; color: var(--muted); }
.chart-table .mixed .frac { font-size: .78em; }
@media (max-width: 1080px) { .flow-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 640px) { .flow-4 { grid-template-columns: minmax(0, 1fr); } .formula-card { padding: 18px; } }

/* ==========================================================
   FAQ list (always open, numbered, highlighted answers)
   ========================================================== */
.faq-list { display: grid; gap: 14px; }
.faq-item {
  display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 18px; align-items: start;
  padding: 22px 26px; border: 1px solid var(--line); border-radius: 16px;
  background: linear-gradient(180deg, var(--surface) 0%, color-mix(in srgb, var(--a-soft) 30%, var(--surface)) 100%);
  box-shadow: var(--shadow);
}
.faq-badge {
  width: 30px; height: 30px; border-radius: 8px; display: grid; place-items: center; margin-top: 1px;
  background: var(--a-soft); color: var(--a);
  font-family: var(--font-mono); font-size: 11px; font-weight: 700;
}
.faq-q { margin: 0 0 8px; font-family: var(--font-body); font-size: 16.5px; font-weight: 700; line-height: 1.35; color: var(--ink); letter-spacing: -0.01em; }
.faq-a { font-size: 14.5px; line-height: 1.7; color: var(--ink-2); }
.faq-a p + p, .faq-a ul + p, .faq-a p + ul { margin-top: 10px; }
.faq-a ul { margin: 8px 0; padding-inline-start: 20px; }
.faq-a li + li { margin-top: 4px; }
.faq-a strong {
  color: var(--ink); font-weight: 600;
  background: color-mix(in srgb, var(--a) 13%, transparent);
  padding: 1px 5px; border-radius: 4px;
  -webkit-box-decoration-break: clone; box-decoration-break: clone;
}
.faq-a .static-vis--sm { margin: 14px 0 4px; }
@media (max-width: 640px) {
  .faq-item { padding: 16px; gap: 12px; }
  .faq-q { font-size: 15.5px; }
}

.static-vis--sm .svg-label { font-size: 14px; }
