/* ============ Tokens ============ */
:root {
  --bg: #f6f4ee;
  --bg-grid: rgba(35, 58, 122, 0.05);
  --surface: #ffffff;
  --surface-2: #faf9f5;
  --ink: #1b2130;
  --ink-2: #3a4252;
  --muted: #687082;
  --line: #e4e0d5;
  --line-2: #d6d1c3;
  --accent: #233a7a;
  --accent-ink: #ffffff;
  --accent-soft: #e8ecf8;
  --danger: #b4232c;
  --danger-soft: #fdecec;
  --shadow: 0 1px 2px rgba(27, 33, 48, 0.05), 0 4px 18px rgba(27, 33, 48, 0.05);
  --radius: 14px;
  --serif: 'KaTeX_Main', 'Iowan Old Style', 'Palatino Linotype', Palatino, Georgia, serif;
  --sans: ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --mono: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;

  --c-foundation: #5b6577;
  --c-basic: #2350c8;
  --c-technique: #7442c8;
  --c-explog: #0f7a55;
  --c-trig: #b86200;
  --c-invtrig: #c0352b;
  --c-hyp: #0b7c76;
  --c-invhyp: #1f6fa8;
  --c-algebraic: #b8336a;
  --c-intbasic: #7a6a00;
  --c-inttable: #9a3aa6;
  --c-inttech: #3c6e1f;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #12151c; --bg-grid: rgba(143, 168, 255, 0.04); --surface: #1a1e27; --surface-2: #161a22;
    --ink: #e7e9ee; --ink-2: #c5cad4; --muted: #949cab; --line: #2a303c; --line-2: #363d4b;
    --accent: #9db4ff; --accent-ink: #10162a; --accent-soft: #232c45; --danger: #ff8a8a; --danger-soft: #3a1f23;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 6px 22px rgba(0,0,0,.25);
    --c-foundation: #a3adbf; --c-basic: #7ea2ff; --c-technique: #b693ff; --c-explog: #4fd1a0;
    --c-trig: #ffb35c; --c-invtrig: #ff8a7f; --c-hyp: #4fd6cc; --c-invhyp: #6dbdf5; --c-algebraic: #ff8fbd;
    --c-intbasic: #e3cf4d; --c-inttable: #e49cf0; --c-inttech: #97d97a;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #12151c; --bg-grid: rgba(143, 168, 255, 0.04); --surface: #1a1e27; --surface-2: #161a22;
  --ink: #e7e9ee; --ink-2: #c5cad4; --muted: #949cab; --line: #2a303c; --line-2: #363d4b;
  --accent: #9db4ff; --accent-ink: #10162a; --accent-soft: #232c45; --danger: #ff8a8a; --danger-soft: #3a1f23;
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 6px 22px rgba(0,0,0,.25);
  --c-foundation: #a3adbf; --c-basic: #7ea2ff; --c-technique: #b693ff; --c-explog: #4fd1a0;
  --c-trig: #ffb35c; --c-invtrig: #ff8a7f; --c-hyp: #4fd6cc; --c-invhyp: #6dbdf5; --c-algebraic: #ff8fbd;
  --c-intbasic: #e3cf4d; --c-inttable: #e49cf0; --c-inttech: #97d97a;
  color-scheme: dark;
}
.cat-foundation { --cat: var(--c-foundation); }
.cat-basic { --cat: var(--c-basic); }
.cat-technique { --cat: var(--c-technique); }
.cat-explog { --cat: var(--c-explog); }
.cat-trig { --cat: var(--c-trig); }
.cat-invtrig { --cat: var(--c-invtrig); }
.cat-hyp { --cat: var(--c-hyp); }
.cat-invhyp { --cat: var(--c-invhyp); }
.cat-algebraic { --cat: var(--c-algebraic); }
.cat-intbasic { --cat: var(--c-intbasic); }
.cat-inttable { --cat: var(--c-inttable); }
.cat-inttech { --cat: var(--c-inttech); }

/* ============ Base ============ */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--sans);
  font-size: 15.5px;
  line-height: 1.55;
  color: var(--ink);
  background-color: var(--bg);
  background-image:
    linear-gradient(var(--bg-grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--bg-grid) 1px, transparent 1px);
  background-size: 28px 28px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
main { flex: 1; width: 100%; max-width: 1200px; margin: 0 auto; padding: 22px 16px 40px; }
h1, h2, h3 { font-family: var(--serif); font-weight: 400; line-height: 1.2; margin: 0; }
code { font-family: var(--mono); font-size: 0.86em; background: var(--surface-2); border: 1px solid var(--line); padding: 1px 5px; border-radius: 5px; }
button { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.katex { font-size: 1.12em; }
.katex-display { margin: 0.4em 0; overflow-x: auto; overflow-y: hidden; padding: 2px 0; }

/* ============ Header ============ */
.top {
  position: sticky; top: 0; z-index: 20;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(10px);
  -webkit-backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--line);
}
.top-inner { max-width: 1200px; margin: 0 auto; padding: 10px 16px; display: flex; align-items: center; gap: 18px; }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: inherit; flex-shrink: 0; }
.brand-mark {
  width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center;
  background: var(--accent); color: var(--accent-ink);
  font-family: var(--serif); font-style: italic; font-size: 24px; line-height: 1;
}
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-name { font-family: var(--serif); font-size: 19px; }
.brand-sub { font-size: 12px; color: var(--muted); }
.tabs { display: flex; gap: 2px; margin-left: auto; background: var(--surface); border: 1px solid var(--line); border-radius: 11px; padding: 3px; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab-btn { border: 0; background: transparent; padding: 6px 12px; border-radius: 8px; cursor: pointer; color: var(--ink-2); white-space: nowrap; font-size: 14px; }
.tab-btn:hover { background: var(--surface-2); color: var(--ink); }
.tab-btn[aria-selected="true"] { background: var(--accent); color: var(--accent-ink); }
.soon { font-size: 10px; text-transform: uppercase; letter-spacing: .06em; opacity: .7; margin-left: 2px; }
.icon-btn {
  border: 1px solid var(--line); background: var(--surface); width: 34px; height: 34px; border-radius: 9px;
  display: inline-grid; place-items: center; cursor: pointer; color: var(--ink-2); flex-shrink: 0; font-size: 16px; line-height: 1;
}
.icon-btn:hover { color: var(--ink); border-color: var(--line-2); }

/* ============ Cards & panels ============ */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.section-title { font-size: 28px; }
.section-sub { color: var(--muted); margin: 6px 0 0; max-width: 62ch; }

/* ============ Calculator ============ */
.calc { padding: 18px 18px 14px; }
.input-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.ddx { font-size: 1.25em; flex-shrink: 0; min-width: 56px; }
.ddx .katex { font-size: 1.3em; }
.input-wrap { flex: 1 1 200px; min-width: 0; position: relative; }
#fxText {
  width: 100%; font-family: var(--mono); font-size: 18px; padding: 12px 70px 12px 14px; min-height: 58px;
  border: 1.5px solid var(--line-2); border-radius: 11px; background: var(--surface-2); color: var(--ink);
  transition: border-color .15s, box-shadow .15s;
}
#fxText:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 16%, transparent); background: var(--surface); }
#fxText.err { border-color: var(--danger); }
#fxText[hidden], .mf[hidden] { display: none; }
.mode-btn {
  position: absolute; right: 9px; top: 50%; transform: translateY(-50%); z-index: 2;
  border: 1px solid var(--line); background: var(--surface); color: var(--muted); border-radius: 7px;
  font-family: var(--sans); font-size: 10.5px; font-weight: 600; letter-spacing: .07em; text-transform: uppercase;
  padding: 4px 8px; cursor: pointer;
}
.mode-btn:hover { color: var(--accent); border-color: var(--accent); }

/* ============ Math field ============ */
.mf {
  position: relative; display: flex; align-items: center; width: 100%; min-height: 58px;
  padding: 6px 70px 6px 16px; cursor: text; overflow-x: auto; overflow-y: hidden; scrollbar-width: thin;
  border: 1.5px solid var(--line-2); border-radius: 11px; background: var(--surface-2); color: var(--ink);
  font-family: 'KaTeX_Main', var(--serif); font-size: 23px; line-height: 1.25;
  transition: border-color .15s, box-shadow .15s, background .15s;
  -webkit-user-select: none; user-select: none; -webkit-tap-highlight-color: transparent;
}
.mf.mf-focus { border-color: var(--accent); box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 16%, transparent); background: var(--surface); }
.mf.err { border-color: var(--danger); }
.mf.err.mf-focus { box-shadow: 0 0 0 4px color-mix(in srgb, var(--danger) 14%, transparent); }
.mf-ta {
  position: absolute; left: 0; top: 0; width: 1px; height: 1px; opacity: 0; padding: 0; margin: 0; border: 0;
  resize: none; overflow: hidden; font-size: 16px; pointer-events: none; white-space: pre;
}
.mf-view { white-space: nowrap; padding: 6px 0; flex-shrink: 0; }
.mf-blank .mf-view::after {
  content: attr(data-ph); font-family: var(--sans); font-size: 15px; color: var(--muted); margin-left: 2px;
}
.mf-row { display: inline-block; white-space: nowrap; border-radius: 4px; padding: 0 .04em; }
.mf-view > .mf-row { padding: 0; }
.mf-here { background: color-mix(in srgb, var(--accent) 9%, transparent); box-shadow: 0 0 0 1px color-mix(in srgb, var(--accent) 22%, transparent); }
.mf-all .mf-view > .mf-row { background: color-mix(in srgb, var(--accent) 22%, transparent); }

.mf-var { font-family: 'KaTeX_Math', var(--serif); font-style: italic; }
.mf-num, .mf-sym, .mf-punct { font-family: 'KaTeX_Main', var(--serif); }
.mf-punct { margin-right: .2em; }
.mf-bin { margin: 0 .24em; }
.mf-dot { margin: 0 .1em; }
.mf-sp { display: inline-block; width: .2em; }
.mf-gap { margin-right: .14em; }
.mf-e { color: var(--cat); }

/* function names: a tinted, category-colored token */
.mf-fn {
  font-family: 'KaTeX_Main', var(--serif); font-style: normal; color: var(--cat);
  background: color-mix(in srgb, var(--cat) 11%, transparent);
  box-shadow: 0 1.5px 0 0 color-mix(in srgb, var(--cat) 55%, transparent);
}
.mf-fn-s { border-top-left-radius: 4px; border-bottom-left-radius: 4px; padding-left: .07em; }
.mf-fn-e { border-top-right-radius: 4px; border-bottom-right-radius: 4px; padding-right: .07em; }

/* fractions */
.mf-frac { display: inline-flex; flex-direction: column; align-items: stretch; vertical-align: middle; margin: 0 .1em; text-align: center; }
.mf-frac .mf-frac { font-size: .88em; }
.mf-fnum, .mf-fden { display: block; padding: 0 .12em; line-height: 1.12; }
.mf-fnum { padding-bottom: .06em; }
.mf-fden { border-top: 1.5px solid currentColor; padding-top: .1em; }

/* powers and log bases */
.mf-sup { display: inline-block; font-size: .7em; vertical-align: .72em; margin-left: .02em; }
.mf-sub { display: inline-block; font-size: .7em; vertical-align: -.42em; margin-left: .02em; }
.mf-sup .mf-sup, .mf-sub .mf-sub, .mf-sup .mf-sub, .mf-sub .mf-sup { font-size: .85em; }

/* brackets and roots are stretchy SVGs laid over padding, so the contents alone set the height */
.mf-grp, .mf-root { display: inline-block; position: relative; }
.mf-grp { padding: 0 .36em; }
.mf-abs { padding: 0 .26em; }
.mf-br, .mf-radix { position: absolute; top: 0; bottom: 0; height: 100%; overflow: visible; }
.mf-br { width: .34em; }
.mf-br:first-of-type { left: 0; }
.mf-br:last-of-type { right: 0; }
.mf-abs .mf-br { width: .24em; }
.mf-br path, .mf-radix path { fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }
.mf-arg > .mf-br, .mf-abs > .mf-br { color: var(--cat); }
.mf-root { margin: 0 .05em; padding-left: .62em; }
.mf-radix { left: 0; width: .62em; color: var(--cat); }
.mf-rad { display: inline-block; border-top: 1.5px solid var(--cat); padding: .1em .1em 0 .06em; }
.mf-index { position: absolute; left: .02em; top: .05em; font-size: .48em; color: var(--cat); line-height: 1; }

/* cursor, empty slots, suggestions */
.mf-cursor { display: inline-block; width: 0; height: 1.15em; vertical-align: -.25em; margin: 0 -1px 0 0; border-left: 2px solid var(--accent); visibility: hidden; }
.mf-focus .mf-cursor { visibility: visible; animation: mf-blink 1.06s steps(1) infinite; }
@keyframes mf-blink { 50% { opacity: 0; } }
.mf-ph {
  display: inline-block; width: .56em; height: .78em; vertical-align: -.04em; margin: 0 .04em;
  border: 1.3px dashed color-mix(in srgb, var(--muted) 70%, transparent); border-radius: 3px;
}
.mf-here > .mf-ph { border-color: var(--accent); border-style: solid; background: color-mix(in srgb, var(--accent) 10%, transparent); }
.mf-ghost { color: var(--muted); opacity: .75; font-family: 'KaTeX_Main', var(--serif); }
.mf-ghost .mf-ph { border-color: var(--muted); }
.mf-key {
  display: inline-block; margin-left: .45em; vertical-align: .25em; font-family: var(--sans); font-size: 10px; line-height: 1;
  text-transform: uppercase; letter-spacing: .06em; padding: 2px 5px; border: 1px solid var(--line-2); border-bottom-width: 2px;
  border-radius: 4px; color: var(--muted); background: var(--surface);
}

/* parse errors */
.mf-err { background: var(--danger-soft); border-radius: 3px; box-shadow: 0 2px 0 0 var(--danger); }
.mf-err .mf-ph { border-color: var(--danger); border-style: solid; }
.mf-err-end .mf-view > .mf-row::after {
  content: ''; display: inline-block; width: .5em; height: .78em; margin-left: .12em; vertical-align: -.04em;
  border: 1.5px solid var(--danger); border-radius: 3px; background: var(--danger-soft);
}

/* color key in the syntax help */
.sw { color: var(--cat); background: color-mix(in srgb, var(--cat) 11%, transparent); border-radius: 4px; padding: 0 5px; font-weight: 550; white-space: nowrap; }
kbd {
  font-family: var(--mono); font-size: .82em; padding: 0 5px; border: 1px solid var(--line-2); border-bottom-width: 2px;
  border-radius: 4px; background: var(--surface); color: var(--ink-2);
}
.opts { display: flex; gap: 8px; }
.opt { display: flex; flex-direction: column; font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; gap: 2px; }
.opt select {
  font: inherit; font-size: 14px; text-transform: none; letter-spacing: 0; color: var(--ink);
  border: 1px solid var(--line-2); border-radius: 8px; padding: 6px 8px; background: var(--surface);
}
.preview { min-height: 44px; margin-top: 12px; padding: 6px 2px; color: var(--ink-2); display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.preview .lbl { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.preview .note { font-size: 13px; color: var(--muted); }
.preview.err { color: var(--danger); }
.err-src { font-family: var(--mono); background: var(--danger-soft); padding: 2px 6px; border-radius: 6px; white-space: pre; }
.err-src mark { background: var(--danger); color: #fff; border-radius: 3px; padding: 0 1px; }
.syntax { margin-top: 12px; border-top: 1px solid var(--line); padding-top: 10px; font-size: 13.5px; }
.syntax summary { cursor: pointer; color: var(--muted); width: fit-content; }
.syntax-grid { display: grid; grid-template-columns: 1fr auto; gap: 6px 18px; margin-top: 10px; }
.syntax-grid > div:nth-child(even) { color: var(--muted); text-align: right; }

/* ============ Derivatives layout: work on the left, reference on the right ============ */
.derive-grid {
  display: grid; grid-template-columns: minmax(0, 1fr) 290px; grid-template-rows: auto auto 1fr;
  grid-template-areas: "input side" "answer side" "steps side"; gap: 16px 20px; align-items: start;
}
.derive-grid > .calc { grid-area: input; }
#answer { grid-area: answer; min-width: 0; }
#output { grid-area: steps; min-width: 0; }
#answer:empty, #output:empty { display: none; }
.side {
  grid-area: side; position: sticky; top: 74px; display: flex; flex-direction: column; gap: 14px;
  max-height: calc(100vh - 90px); overflow-y: auto; overscroll-behavior: contain; scrollbar-width: thin;
}
.side-card { overflow: hidden; flex-shrink: 0; }
.side-head {
  display: flex; align-items: baseline; justify-content: space-between; gap: 8px;
  padding: 12px 16px 10px; border-bottom: 1px solid var(--line);
}
.side-head h2 { font-size: 17px; }
.side-meta { font-size: 11.5px; color: var(--muted); }
details.side-card > summary { cursor: pointer; list-style: none; }
details.side-card > summary::-webkit-details-marker { display: none; }
details.side-card > summary h2::after {
  content: ''; display: inline-block; width: 6px; height: 6px; margin-left: 9px; vertical-align: .2em;
  border-right: 1.5px solid var(--muted); border-bottom: 1.5px solid var(--muted); transform: rotate(45deg); transition: transform .15s;
}
details.side-card:not([open]) > summary { border-bottom-color: transparent; }
details.side-card:not([open]) > summary h2::after { transform: rotate(-45deg); }

.rule-list { list-style: none; margin: 0; padding: 6px; }
.rule-item {
  position: relative; display: grid; grid-template-columns: 1fr auto; grid-template-areas: "name n" "cat n";
  width: 100%; text-align: left; border: 0; background: transparent; cursor: pointer;
  padding: 7px 10px 7px 18px; border-radius: 8px; transition: background .12s;
}
.rule-item::before {
  content: ''; position: absolute; left: 7px; top: 9px; bottom: 9px; width: 3.5px; border-radius: 2px; background: var(--cat);
}
.rule-item:hover, .rule-item.hl { background: color-mix(in srgb, var(--cat) 10%, var(--surface)); }
.ri-name { grid-area: name; font-size: 13.5px; font-weight: 600; color: var(--ink); line-height: 1.3; }
.ri-cat { grid-area: cat; font-size: 11.5px; color: color-mix(in srgb, var(--cat) 70%, var(--muted)); line-height: 1.4; }
.ri-n { grid-area: n; align-self: center; font-family: var(--mono); font-size: 11.5px; color: var(--muted); padding-left: 8px; }
.side-empty { list-style: none; padding: 10px 12px; color: var(--muted); font-size: 13px; }

.ex-list { display: flex; flex-direction: column; padding: 4px 0; }
.ex-item {
  position: relative; display: block; width: 100%; text-align: left; border: 0; background: transparent; cursor: pointer;
  padding: 6px 16px; color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; transition: background .12s;
}
.ex-item + .ex-item { border-top: 1px solid color-mix(in srgb, var(--line) 70%, transparent); }
.ex-item .katex { font-size: 1.02em; }
.ex-item:hover { background: var(--surface-2); color: var(--ink); }
.ex-item:hover::before { content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: var(--accent); }

/* ============ Output ============ */
.output { display: flex; flex-direction: column; gap: 16px; }
.answer { padding: 18px 20px; position: relative; overflow: hidden; }
.answer::before { content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; background: var(--accent); }
.eyebrow { font-size: 11.5px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.answer-math { font-size: 1.15em; margin: 4px 0 0; }

.chip {
  display: inline-flex; align-items: center; gap: 6px; cursor: pointer; white-space: nowrap;
  border: 1px solid color-mix(in srgb, var(--cat) 38%, transparent);
  background: color-mix(in srgb, var(--cat) 9%, var(--surface));
  color: color-mix(in srgb, var(--cat) 82%, var(--ink));
  font-size: 12.5px; font-weight: 550; padding: 2px 9px 2px 7px; border-radius: 999px; line-height: 1.6;
  transition: background .12s, transform .12s;
}
.chip::before { content: ''; width: 7px; height: 7px; border-radius: 50%; background: var(--cat); }
.chip:hover { background: color-mix(in srgb, var(--cat) 18%, var(--surface)); }
.chip:active { transform: translateY(1px); }

.steps { padding: 6px 0 10px; }
.steps-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 12px 20px 8px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.steps-head h2 { font-size: 21px; }
.steps-head .actions { display: flex; gap: 6px; }
.btn-ghost { border: 1px solid var(--line); background: var(--surface); border-radius: 8px; padding: 4px 10px; font-size: 13px; cursor: pointer; color: var(--ink-2); }
.btn-ghost:hover { border-color: var(--line-2); color: var(--ink); }
.order-head { padding: 14px 20px 2px; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.order-head h3 { font-size: 17px; }

.tree, .tree ol { list-style: none; margin: 0; padding: 0; }
.tree { padding: 8px 12px 4px; }
.tree ol { margin-left: 15px; padding-left: 14px; border-left: 1.5px dashed var(--line-2); }
.step { margin: 2px 0; }
.step-row { display: flex; align-items: flex-start; gap: 8px; padding: 6px 8px; border-radius: 10px; }
.step-row:hover { background: var(--surface-2); }
.twisty {
  width: 22px; height: 22px; border-radius: 6px; border: 0; background: transparent; cursor: pointer; flex-shrink: 0;
  color: var(--muted); display: grid; place-items: center; margin-top: 3px; transition: transform .15s;
}
.twisty:hover { background: var(--accent-soft); color: var(--accent); }
.twisty svg { width: 12px; height: 12px; transition: transform .15s; }
.step.open > .step-row .twisty svg { transform: rotate(90deg); }
.twisty.leaf { visibility: hidden; }
.step-eq { flex: 1; min-width: 0; overflow-x: auto; overflow-y: hidden; padding: 2px 0; }
.step-tags { display: flex; gap: 3px 12px; flex-wrap: wrap; justify-content: flex-end; max-width: 40%; padding-top: 6px; }
.order-head .step-tags { padding-top: 0; }
.rtag {
  display: inline-flex; align-items: center; gap: 6px; border: 0; background: none; padding: 0; cursor: pointer; white-space: nowrap;
  font-family: var(--sans); font-size: 12px; font-weight: 550; color: color-mix(in srgb, var(--cat) 80%, var(--ink)); opacity: .85;
}
.rtag::before { content: ''; width: 7px; height: 7px; border-radius: 2px; background: var(--cat); }
.rtag:hover { opacity: 1; text-decoration: underline; text-underline-offset: 3px; }
.step-row.hl { background: color-mix(in srgb, var(--hl) 11%, transparent); box-shadow: inset 3px 0 0 var(--hl); }
.step-body { display: none; margin: 0 0 6px 38px; padding: 4px 0 4px; }
.step.open > .step-body { display: block; }
.rule-line { font-size: 13.5px; color: var(--ink-2); background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px; padding: 6px 12px; margin: 2px 0 8px; display: flex; gap: 10px; align-items: baseline; flex-wrap: wrap; overflow-x: auto; }
.rule-line .lbl, .work .lbl { font-size: 11px; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); flex-shrink: 0; }
.rule-line .where { color: var(--muted); }
.work { display: flex; gap: 10px; align-items: baseline; padding: 3px 4px; overflow-x: auto; overflow-y: hidden; }
.work .eq { color: var(--muted); font-family: var(--serif); width: 14px; flex-shrink: 0; text-align: center; }
.work.final { font-weight: 500; }
.work.final .katex { color: var(--accent); }

/* ============ Empty / integrate ============ */
.empty { padding: 48px 24px; text-align: center; }
.empty-mark { font-family: var(--serif); font-size: 72px; line-height: 1; color: var(--accent); font-style: italic; }
.empty h2 { font-size: 26px; margin: 10px 0; }
.empty p { color: var(--muted); max-width: 58ch; margin: 0 auto 18px; }
.btn { border: 0; background: var(--accent); color: var(--accent-ink); padding: 9px 16px; border-radius: 10px; cursor: pointer; font-weight: 550; }
.btn:hover { filter: brightness(1.08); }
.hint { padding: 28px 22px; color: var(--muted); }
.hint h2 { font-size: 22px; color: var(--ink); margin-bottom: 6px; }

/* ============ Library ============ */
.lib-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; margin-bottom: 16px; flex-wrap: wrap; }
#libSearch { font: inherit; padding: 9px 12px; border: 1px solid var(--line-2); border-radius: 10px; background: var(--surface); color: var(--ink); width: min(340px, 100%); }
.lib-cat { margin-bottom: 22px; }
.lib-cat h3 { font-size: 18px; display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.lib-cat h3::before { content: ''; width: 10px; height: 10px; border-radius: 3px; background: var(--cat); }
.lib-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 10px; }
.lib-card {
  text-align: left; cursor: pointer; padding: 12px 14px 10px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--surface); position: relative; overflow: hidden; min-width: 0;
  display: flex; flex-direction: column; justify-content: flex-start;
}
.lib-card::before { content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: var(--cat); opacity: .8; }
.lib-card:hover { border-color: color-mix(in srgb, var(--cat) 45%, var(--line)); box-shadow: var(--shadow); }
.lib-card .nm { font-weight: 600; font-size: 14px; }
.lib-card .st { margin: 4px 0; overflow-x: auto; overflow-y: hidden; font-size: 0.92em; }
.lib-card .sm { color: var(--muted); font-size: 12.5px; line-height: 1.45; }

/* ============ Proof map ============ */
.map-shell { overflow: hidden; }
.map-toolbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 10px 12px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.legend { display: flex; gap: 6px; flex-wrap: wrap; }
.legend .chip { cursor: default; font-weight: 500; }
.zoom { display: flex; gap: 4px; }
.map-canvas { height: min(74vh, 760px); background: var(--surface-2); }
.map-hint { font-size: 12px; color: var(--muted); }
.map-canvas svg { width: 100%; height: 100%; display: block; }
.pmap.interactive { cursor: grab; touch-action: none; }
.pmap.dragging { cursor: grabbing; }
.pmap-edge { fill: none; stroke: var(--line-2); stroke-width: 1.3; transition: stroke .15s, opacity .15s; }
.pmap-arrow { fill: var(--line-2); fill: context-stroke; }
.pmap-node { cursor: pointer; transition: opacity .15s; }
.pmap-node:focus { outline: none; }
.pmap-box { fill: var(--surface); stroke: color-mix(in srgb, var(--cat) 45%, var(--line)); stroke-width: 1.2; transition: fill .15s, stroke .15s; }
.pmap-tick { fill: var(--cat); }
.pmap-label { font-family: var(--sans); font-size: 12.5px; fill: var(--ink); pointer-events: none; }
.pmap-node:hover .pmap-box, .pmap-node:focus .pmap-box { fill: color-mix(in srgb, var(--cat) 12%, var(--surface)); stroke: var(--cat); }
.pmap.tracing .pmap-node { opacity: .22; }
.pmap.tracing .pmap-edge { opacity: .12; }
.pmap.tracing .pmap-node.anc, .pmap.tracing .pmap-node.desc, .pmap.tracing .pmap-node.self { opacity: 1; }
.pmap.tracing .pmap-node.self .pmap-box { fill: var(--cat); stroke: var(--cat); }
.pmap.tracing .pmap-node.self .pmap-label { fill: var(--surface); font-weight: 600; }
.pmap.tracing .pmap-node.self .pmap-tick { fill: var(--surface); }
.pmap.tracing .pmap-edge.anc { opacity: 1; stroke: var(--accent); stroke-width: 1.8; }
.pmap.tracing .pmap-edge.desc { opacity: .9; stroke: var(--c-explog); stroke-width: 1.6; stroke-dasharray: 4 3; }

/* ============ Drawer ============ */
.scrim { position: fixed; inset: 0; background: rgba(10, 14, 24, .35); z-index: 40; opacity: 0; transition: opacity .2s; }
.scrim.show { opacity: 1; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(600px, 100vw); z-index: 50;
  background: var(--surface); border-left: 1px solid var(--line); box-shadow: -10px 0 40px rgba(0,0,0,.12);
  transform: translateX(105%); transition: transform .25s cubic-bezier(.2,.8,.2,1);
  display: flex; flex-direction: column;
}
.drawer.open { transform: none; }
.drawer-bar { display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.cat-badge { font-size: 11.5px; text-transform: uppercase; letter-spacing: .08em; color: var(--cat); font-weight: 650; display: inline-flex; align-items: center; gap: 7px; }
.cat-badge::before { content: ''; width: 9px; height: 9px; border-radius: 3px; background: var(--cat); }
.drawer-body { overflow-y: auto; padding: 18px 22px 40px; flex: 1; overscroll-behavior: contain; }
.drawer-body h2 { font-size: 28px; margin-bottom: 10px; }
.drawer-body h3 { font-size: 17px; margin: 22px 0 8px; padding-top: 14px; border-top: 1px solid var(--line); }
.statement { background: color-mix(in srgb, var(--cat) 7%, var(--surface)); border: 1px solid color-mix(in srgb, var(--cat) 28%, var(--line)); border-radius: 12px; padding: 10px 14px; overflow-x: auto; }
.summary { color: var(--ink-2); margin: 10px 0 0; }
.proof p { margin: 8px 0; }
.proof h4 { font-family: var(--serif); font-weight: 400; font-size: 15.5px; margin: 16px 0 4px; color: var(--accent); }
.proof .katex-display { margin: 8px 0; }
.chip-row { display: flex; gap: 6px; flex-wrap: wrap; }
.none { color: var(--muted); font-size: 13.5px; font-style: italic; }
.mini-map { border: 1px solid var(--line); border-radius: 12px; background: var(--surface-2); overflow: hidden; }
.mini-map svg { width: 100%; height: auto; display: block; }
.drawer-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }

/* ============ Footer ============ */
.foot { text-align: center; color: var(--muted); font-size: 12.5px; padding: 8px 16px 28px; }
.foot p { margin: 0; }

/* ============ Responsive ============ */
@media (max-width: 900px) {
  .derive-grid { grid-template-columns: minmax(0, 1fr); grid-template-rows: none; grid-template-areas: "input" "answer" "side" "steps"; }
  .side { position: static; max-height: none; overflow: visible; }
  .rule-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 0 4px; }
}
@media (max-width: 760px) {
  .top-inner { flex-wrap: wrap; gap: 10px; }
  .brand-sub { display: none; }
  .tabs { order: 3; width: 100%; margin-left: 0; }
  .tab-btn { flex: 1; padding: 6px 6px; font-size: 13px; }
  .soon { display: none; }
  .theme-btn { margin-left: auto; }
  main { padding-top: 16px; }
  .calc { padding: 14px; }
  .ddx { min-width: 0; }
  .opts { width: 100%; }
  .opt { flex-direction: row; align-items: center; gap: 6px; }
  .step-row { flex-wrap: wrap; }
  .step-tags { max-width: 100%; justify-content: flex-start; padding: 0 0 2px 30px; width: 100%; }
  .step-body { margin-left: 18px; }
  .tree ol { margin-left: 8px; padding-left: 10px; }
  .syntax-grid { grid-template-columns: 1fr; }
  .mf { font-size: 21px; padding-left: 12px; }
  .syntax-grid > div:nth-child(even) { text-align: left; margin-bottom: 6px; font-size: 12px; }
  .section-title { font-size: 24px; }
  .drawer-body { padding: 16px 16px 40px; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}

/* ============ Integrals ============ */
.int-sign { font-family: var(--serif); font-size: 2.2em; line-height: 1; min-width: 0; font-style: italic; color: var(--ink-2); padding: 0 2px; }
.int-dx { min-width: 0; }
.steps-note { font-size: 13px; color: var(--muted); margin: 0; padding: 10px 20px 0; }
.step-cap { display: inline-block; font-size: 11px; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); margin-right: 10px; vertical-align: middle; }
.note-line { background: transparent; border-style: dashed; }
.work.back { font-size: 13.5px; color: var(--ink-2); }
.answer .note { font-size: 13px; color: var(--muted); margin: 6px 0 0; }
.check { display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px 12px; margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--line); font-size: 13.5px; overflow-x: auto; }
.check .lbl { font-size: 11px; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); }
.check .ok { color: var(--c-inttech); font-weight: 600; font-size: 12.5px; white-space: nowrap; }
.check .btn-ghost { margin-left: auto; }
