/* คิดไว — stylesheet
   Layout: หน้าสมุดกราฟ (graph-paper sheet) มีเส้นกั้นหน้าสีแดงแบบสมุดนักเรียน
   ผลลัพธ์แสดงบนจอ LCD แบบเครื่องคิดเลข ปากกาน้ำเงินเป็นสีหลัก */
:root {
  --paper: #f3f5fa;      /* พื้นหลังหน้าเว็บ */
  --sheet: #ffffff;      /* แผ่นกระดาษ */
  --ink: #161b2e;        /* ตัวอักษรหลัก */
  --ink-2: #4b5472;      /* ตัวอักษรรอง */
  --ink-3: #7a83a1;      /* คำอธิบายเล็ก */
  --line: #dde3ef;       /* เส้นขอบ */
  --grid: rgba(38, 71, 196, .065);
  --pen: #2647c4;        /* น้ำเงินปากกาลูกลื่น */
  --pen-2: #1b3497;
  --pen-soft: #e7ecfb;
  --on-pen: #ffffff;
  --margin: #d6475b;     /* เส้นกั้นหน้าสีแดง */
  --lcd: #c7d2b9;
  --lcd-ink: #1b2417;
  --lcd-dim: #56654d;
  --lcd-edge: #a9b69a;
  --good: #1d7a4b; --good-bg: #e2f3ea;
  --warn: #9a5a00; --warn-bg: #fbefd9;
  --bad: #b3243a;  --bad-bg: #fbe4e7;
  --info: #2647c4; --info-bg: #e7ecfb;
  --s0: #2647c4; --s1: #d6475b; --s2: #1d7a4b; --s3: #9a5a00;
  --shadow: 0 1px 0 rgba(22, 27, 46, .04), 0 8px 24px -12px rgba(22, 27, 46, .18);
  --f-display: 'Chakra Petch', 'Anuphan', system-ui, sans-serif;
  --f-body: 'Anuphan', 'Noto Sans Thai', 'Leelawadee UI', 'Thonburi', system-ui, sans-serif;
  --f-mono: 'IBM Plex Mono', ui-monospace, 'SFMono-Regular', Menlo, Consolas, monospace;
  --r: 10px;
  --wrap: 1140px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #0d1120; --sheet: #141a2c; --ink: #e5e9f6; --ink-2: #a3acc8; --ink-3: #7881a0; --line: #263050;
    --grid: rgba(125, 150, 255, .06); --pen: #8aa0ff; --pen-2: #b2c0ff; --pen-soft: #1d2647; --on-pen: #0d1120;
    --margin: #e4707f; --lcd: #18221b; --lcd-ink: #d5e8c6; --lcd-dim: #8fa685; --lcd-edge: #2b3a2d;
    --good: #5fcf94; --good-bg: #13301f; --warn: #f0b45a; --warn-bg: #33260f; --bad: #f08a99; --bad-bg: #3a1720; --info: #8aa0ff; --info-bg: #1d2647;
    --s0: #8aa0ff; --s1: #e4707f; --s2: #5fcf94; --s3: #f0b45a;
    --shadow: 0 1px 0 rgba(0, 0, 0, .3), 0 10px 30px -14px rgba(0, 0, 0, .7);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --paper: #0d1120; --sheet: #141a2c; --ink: #e5e9f6; --ink-2: #a3acc8; --ink-3: #7881a0; --line: #263050;
  --grid: rgba(125, 150, 255, .06); --pen: #8aa0ff; --pen-2: #b2c0ff; --pen-soft: #1d2647; --on-pen: #0d1120;
  --margin: #e4707f; --lcd: #18221b; --lcd-ink: #d5e8c6; --lcd-dim: #8fa685; --lcd-edge: #2b3a2d;
  --good: #5fcf94; --good-bg: #13301f; --warn: #f0b45a; --warn-bg: #33260f; --bad: #f08a99; --bad-bg: #3a1720; --info: #8aa0ff; --info-bg: #1d2647;
  --s0: #8aa0ff; --s1: #e4707f; --s2: #5fcf94; --s3: #f0b45a;
  --shadow: 0 1px 0 rgba(0, 0, 0, .3), 0 10px 30px -14px rgba(0, 0, 0, .7);
  color-scheme: dark;
}

/* ───────── base ───────── */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0; background: var(--paper); color: var(--ink);
  font: 400 1rem/1.75 var(--f-body);
  -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
}
img, svg { max-width: 100%; }
a { color: var(--pen); text-decoration-thickness: 1px; text-underline-offset: 3px; }
a:hover { color: var(--pen-2); }
:focus-visible { outline: 2px solid var(--pen); outline-offset: 2px; border-radius: 4px; }
h1, h2, h3, h4 { font-family: var(--f-display); line-height: 1.3; text-wrap: balance; margin: 0; color: var(--ink); }
h1 { font-size: clamp(1.6rem, 1.15rem + 1.9vw, 2.45rem); font-weight: 600; letter-spacing: -.01em; }
h2 { font-size: clamp(1.25rem, 1.1rem + .6vw, 1.5rem); font-weight: 600; }
h3 { font-size: 1.1rem; font-weight: 600; }
p { margin: 0; }
code, kbd, .mx { font-family: var(--f-mono); font-size: .92em; }
.mx { background: var(--pen-soft); color: var(--ink); padding: .05em .4em; border-radius: 5px; white-space: nowrap; }
.wrap { width: 100%; max-width: var(--wrap); margin-inline: auto; padding-inline: 16px; }
@media (min-width: 720px) { .wrap { padding-inline: 24px; } }
.skip { position: absolute; left: -999px; top: 8px; background: var(--pen); color: var(--on-pen); padding: 8px 14px; border-radius: 8px; z-index: 50; }
.skip:focus { left: 12px; }
.vh { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; scroll-behavior: auto !important; } }

/* ───────── header ───────── */
.site-head {
  position: sticky; top: env(safe-area-inset-top, 0px); z-index: 30;
  background: color-mix(in srgb, var(--sheet) 92%, transparent);
  backdrop-filter: saturate(1.4) blur(10px); -webkit-backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--line);
}
.head-row { display: flex; align-items: center; gap: 12px; padding-block: 10px; }
.logo { display: inline-flex; align-items: center; gap: 10px; text-decoration: none; color: var(--ink); flex: none; }
.logo-key {
  width: 34px; height: 34px; border-radius: 9px; display: grid; place-items: center;
  background: var(--pen); color: var(--on-pen); font: 700 1.25rem/1 var(--f-display);
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, .22);
}
.logo-text { font: 700 1.3rem/1 var(--f-display); letter-spacing: .01em; }
.logo-text small { display: block; font: 500 .62rem/1.2 var(--f-body); color: var(--ink-3); letter-spacing: .02em; margin-top: 2px; }
.search { position: relative; flex: 1; min-width: 0; max-width: 460px; margin-left: auto; }
.search input {
  width: 100%; height: 40px; border-radius: 999px; border: 1px solid var(--line); background: var(--paper);
  color: var(--ink); font: inherit; font-size: .95rem; padding: 0 16px 0 38px;
}
.search input::placeholder { color: var(--ink-3); }
.search svg { position: absolute; left: 13px; top: 50%; translate: 0 -50%; width: 16px; height: 16px; color: var(--ink-3); pointer-events: none; }
.search-list {
  position: absolute; left: 0; right: 0; top: calc(100% + 6px); margin: 0; padding: 6px; list-style: none;
  background: var(--sheet); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); z-index: 40; max-height: 70vh; overflow: auto;
}
.search-list a { display: flex; justify-content: space-between; gap: 12px; padding: 8px 10px; border-radius: 8px; text-decoration: none; color: var(--ink); }
.search-list li[aria-selected="true"] a, .search-list a:hover { background: var(--pen-soft); }
.sr-c { color: var(--ink-3); font-size: .82rem; white-space: nowrap; }
.sr-empty { padding: 10px; color: var(--ink-3); font-size: .9rem; }
.icon-btn {
  width: 40px; height: 40px; flex: none; display: grid; place-items: center; border-radius: 10px; border: 1px solid var(--line);
  background: var(--sheet); color: var(--ink-2); cursor: pointer;
}
.icon-btn:hover { color: var(--pen); border-color: var(--pen); }
.icon-btn svg { width: 18px; height: 18px; }
.menu-btn { display: none; }
.cat-nav { border-top: 1px solid var(--line); }
.cat-nav ul { display: flex; gap: 4px; list-style: none; margin: 0; padding: 6px 0; overflow-x: auto; scrollbar-width: none; }
.cat-nav ul::-webkit-scrollbar { display: none; }
.cat-nav a {
  display: inline-flex; align-items: center; gap: 6px; padding: 5px 12px; border-radius: 999px; white-space: nowrap;
  color: var(--ink-2); text-decoration: none; font-size: .9rem;
}
.cat-nav a:hover, .cat-nav a[aria-current="page"] { background: var(--pen-soft); color: var(--pen); }
.cat-nav .g { font-family: var(--f-display); font-weight: 700; color: var(--pen); width: 1.2em; text-align: center; }
@media (max-width: 640px) {
  .logo-text small { display: none; }
  .search { max-width: none; }
}

/* ───────── breadcrumb & page head ───────── */
.crumbs { font-size: .85rem; color: var(--ink-3); padding-block: 14px 6px; }
.crumbs ol { list-style: none; display: flex; flex-wrap: wrap; gap: 4px; margin: 0; padding: 0; }
.crumbs li + li::before { content: '›'; margin-right: 6px; color: var(--ink-3); }
.crumbs a { color: var(--ink-2); text-decoration: none; }
.crumbs a:hover { color: var(--pen); text-decoration: underline; }
.page-head { display: grid; gap: 10px; padding-block: 6px 18px; max-width: 860px; }
.eyebrow { font: 600 .8rem/1.2 var(--f-display); letter-spacing: .06em; color: var(--margin); text-transform: uppercase; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.eyebrow a { color: inherit; text-decoration: none; }
.tag-new { font: 600 .7rem/1 var(--f-display); letter-spacing: .05em; color: var(--on-pen); background: var(--pen); padding: 4px 7px; border-radius: 5px; }
.answer {
  border-left: 3px solid var(--margin); padding: 4px 0 4px 14px; color: var(--ink-2); font-size: 1.02rem; max-width: 72ch;
}
.answer strong { color: var(--ink); }
.meta-line { font-size: .82rem; color: var(--ink-3); display: flex; gap: 14px; flex-wrap: wrap; }

/* ───────── tool sheet ───────── */
.sheet {
  position: relative; background: var(--sheet); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow);
  display: grid; grid-template-columns: minmax(0, 1fr); overflow: clip;
}
.sheet-form {
  position: relative; padding: 22px 18px 20px 30px;
  background-image: linear-gradient(var(--grid) 1px, transparent 1px), linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 22px 22px; background-position: -1px -1px;
}
.sheet-form::before { content: ''; position: absolute; top: 0; bottom: 0; left: 16px; width: 2px; background: var(--margin); opacity: .55; }
.sheet-out { padding: 20px 18px 22px; border-top: 1px dashed var(--line); min-width: 0; }
@media (min-width: 900px) {
  .sheet:not(.is-wide) { grid-template-columns: minmax(0, 1.05fr) minmax(0, .95fr); }
  .sheet:not(.is-wide) .sheet-out { border-top: 0; border-left: 1px dashed var(--line); padding: 26px 26px 26px; }
  .sheet:not(.is-wide) .sheet-out-in { position: sticky; top: 130px; }
  .sheet-form { padding: 26px 26px 24px 44px; }
  .sheet-form::before { left: 26px; }
}
.form-grid { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 14px 14px; }
.f { grid-column: span 6; display: grid; gap: 5px; min-width: 0; align-content: start; }
.f-half { grid-column: span 3; }
.f-third { grid-column: span 2; }
@media (max-width: 480px) { .f-third { grid-column: span 3; } }
.f-sec { grid-column: span 6; font: 600 .95rem/1.3 var(--f-display); color: var(--pen); padding-top: 8px; border-bottom: 1px solid var(--line); padding-bottom: 6px; }
.f-sec small { font: 400 .8rem var(--f-body); color: var(--ink-3); margin-left: 6px; }
.f label, .f legend { font-size: .9rem; font-weight: 500; color: var(--ink); }
.f .help { font-size: .78rem; color: var(--ink-3); line-height: 1.5; }
.inp { position: relative; display: flex; align-items: stretch; }
.inp input, .inp select, .f textarea, .f > select {
  width: 100%; min-width: 0; height: 44px; border-radius: 9px; border: 1px solid var(--line); background: var(--sheet); color: var(--ink);
  font: 500 1rem/1 var(--f-body); padding: 0 12px; transition: border-color .15s, box-shadow .15s;
}
.inp input[data-type="number"], .inp input.num { font-family: var(--f-mono); font-variant-numeric: tabular-nums; }
.f textarea { height: auto; min-height: 96px; padding: 10px 12px; line-height: 1.6; font-family: var(--f-mono); font-size: .95rem; resize: vertical; }
.inp select, .f > select { appearance: none; -webkit-appearance: none; padding-right: 34px; background-image: linear-gradient(45deg, transparent 50%, var(--ink-3) 50%), linear-gradient(135deg, var(--ink-3) 50%, transparent 50%); background-position: calc(100% - 17px) 19px, calc(100% - 12px) 19px; background-size: 5px 5px; background-repeat: no-repeat; }
.inp input:focus, .inp select:focus, .f textarea:focus, .f > select:focus { outline: none; border-color: var(--pen); box-shadow: 0 0 0 3px var(--pen-soft); }
.inp .u {
  display: grid; place-items: center; padding: 0 12px; border: 1px solid var(--line); border-left: 0; border-radius: 0 9px 9px 0;
  background: var(--paper); color: var(--ink-2); font-size: .85rem; white-space: nowrap;
}
.inp.has-u input, .inp.has-u select { border-radius: 9px 0 0 9px; }
input[type="date"] { font-family: var(--f-body); }
input[type="color"] { padding: 4px; height: 44px; cursor: pointer; }
.seg { border: 0; padding: 0; margin: 0; min-width: 0; display: grid; gap: 6px; }
.seg-opts { display: flex; flex-wrap: wrap; gap: 6px; }
.seg-opts label { position: relative; cursor: pointer; }
.seg-opts input { position: absolute; opacity: 0; inset: 0; cursor: pointer; }
.seg-opts span {
  display: inline-block; padding: 7px 13px; border-radius: 8px; border: 1px solid var(--line); background: var(--sheet);
  font-size: .9rem; color: var(--ink-2); transition: all .15s; line-height: 1.4;
}
.seg-opts input:checked + span { background: var(--pen); border-color: var(--pen); color: var(--on-pen); }
.seg-opts input:focus-visible + span { outline: 2px solid var(--pen); outline-offset: 2px; }
.chk { display: flex; align-items: center; gap: 10px; cursor: pointer; font-size: .92rem; }
.chk input { width: 18px; height: 18px; accent-color: var(--pen); }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 18px; align-items: center; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px; height: 44px; padding: 0 18px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--sheet); color: var(--ink); font: 600 .95rem/1 var(--f-body); cursor: pointer; text-decoration: none;
  transition: transform .08s, background .15s, border-color .15s;
}
.btn:hover { border-color: var(--pen); color: var(--pen); }
.btn:active { transform: translateY(1px); }
.btn svg { width: 16px; height: 16px; }
.btn-main { background: var(--pen); border-color: var(--pen); color: var(--on-pen); box-shadow: inset 0 -3px 0 rgba(0, 0, 0, .18); min-width: 120px; }
.btn-main:hover { background: var(--pen-2); border-color: var(--pen-2); color: var(--on-pen); }
.btn-sm { height: 34px; padding: 0 12px; font-size: .85rem; border-radius: 8px; }
.btn-ghost { background: transparent; }
.act-sep { flex: 1; }
.tip { font-size: .8rem; color: var(--ink-3); margin-top: 12px; }
.tip kbd { background: var(--paper); border: 1px solid var(--line); border-radius: 4px; padding: 0 5px; }

/* ───────── result: LCD ───────── */
.res-title { font: 600 .78rem/1 var(--f-display); letter-spacing: .08em; color: var(--ink-3); text-transform: uppercase; margin-bottom: 10px; display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.res-title .res-tools { display: flex; gap: 6px; }
.lcd {
  background: var(--lcd); color: var(--lcd-ink); border-radius: 10px; padding: 14px 16px 16px;
  border: 1px solid var(--lcd-edge);
  box-shadow: inset 0 2px 0 rgba(0, 0, 0, .06), inset 0 0 0 4px color-mix(in srgb, var(--lcd) 70%, var(--lcd-edge));
  display: grid; gap: 4px; min-width: 0;
}
.lcd-label { font-size: .85rem; color: var(--lcd-dim); font-weight: 500; }
.lcd-value { display: flex; align-items: baseline; flex-wrap: wrap; gap: 4px 10px; min-width: 0; }
.lcd-value output {
  font: 500 clamp(1.7rem, 1.2rem + 2vw, 2.4rem)/1.15 var(--f-mono); font-variant-numeric: tabular-nums; letter-spacing: -.01em;
  overflow-wrap: anywhere; min-width: 0;
}
.lcd-unit { font-size: 1rem; color: var(--lcd-dim); }
.lcd-sub { font-size: .9rem; color: var(--lcd-dim); overflow-wrap: anywhere; }
.lcd-badge { margin-top: 4px; }
.lcd-msg { font-size: .98rem; line-height: 1.6; }
.lcd.is-error { background: var(--bad-bg); color: var(--bad); border-color: color-mix(in srgb, var(--bad) 35%, transparent); box-shadow: none; }
.lcd.is-error .lcd-label { color: var(--bad); }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; font-size: .82rem; font-weight: 600; line-height: 1.5; }
.chip::before { content: ''; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.chip-good { color: var(--good); background: var(--good-bg); }
.chip-warn { color: var(--warn); background: var(--warn-bg); }
.chip-bad { color: var(--bad); background: var(--bad-bg); }
.chip-info { color: var(--info); background: var(--info-bg); }
.lcd .chip { background: rgba(255, 255, 255, .55); }
:root[data-theme="dark"] .lcd .chip { background: rgba(0, 0, 0, .25); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .lcd .chip { background: rgba(0, 0, 0, .25); } }
.kv { margin: 14px 0 0; display: grid; gap: 0; }
.kv > div { display: flex; justify-content: space-between; gap: 16px; padding: 8px 2px; border-bottom: 1px dotted var(--line); align-items: baseline; }
.kv dt { color: var(--ink-2); font-size: .92rem; }
.kv dd { margin: 0; font-family: var(--f-mono); font-variant-numeric: tabular-nums; text-align: right; font-weight: 500; overflow-wrap: anywhere; min-width: 0; }
.kv .hl dd { color: var(--pen); font-weight: 600; }
.kv .tot { border-bottom: 2px solid var(--ink); }
.kv .tot dt { color: var(--ink); font-weight: 600; }
.res-more { margin-top: 16px; display: grid; gap: 16px; min-width: 0; }
.res-block { display: grid; gap: 8px; min-width: 0; }
.res-h { font: 600 .98rem/1.3 var(--f-display); color: var(--ink); }
.res-note { margin-top: 12px; font-size: .82rem; color: var(--ink-3); line-height: 1.6; }
.steps { margin: 0; padding-left: 1.4em; display: grid; gap: 6px; font-size: .94rem; }
.steps li::marker { font-family: var(--f-mono); color: var(--pen); font-weight: 600; }
.steps .mx { white-space: normal; }
.history { margin-top: 18px; border-top: 1px dashed var(--line); padding-top: 12px; }
.history summary { cursor: pointer; font-size: .85rem; color: var(--ink-2); font-weight: 500; }
.history ul { list-style: none; margin: 8px 0 0; padding: 0; display: grid; gap: 4px; }
.history button {
  width: 100%; display: flex; justify-content: space-between; gap: 10px; text-align: left; background: transparent; border: 0; padding: 6px 8px;
  border-radius: 7px; color: var(--ink); font: inherit; font-size: .88rem; cursor: pointer;
}
.history button:hover { background: var(--pen-soft); }
.h-v { font-family: var(--f-mono); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.h-t { color: var(--ink-3); font-size: .78rem; white-space: nowrap; }

/* tables, charts, matrices */
.tbl-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 10px; max-width: 100%; }
.tbl-wrap.is-scroll { max-height: 420px; overflow-y: auto; }
.tbl { border-collapse: collapse; width: 100%; font-size: .9rem; font-variant-numeric: tabular-nums; }
.tbl caption { text-align: left; padding: 8px 12px; font-weight: 600; color: var(--ink-2); font-size: .85rem; }
.tbl th, .tbl td { padding: 8px 12px; border-bottom: 1px solid var(--line); text-align: right; white-space: nowrap; }
.tbl th:first-child, .tbl td:first-child { text-align: left; }
.tbl thead th { position: sticky; top: 0; background: var(--paper); font: 600 .82rem/1.3 var(--f-body); color: var(--ink-2); }
.tbl tbody tr:nth-child(even) td { background: color-mix(in srgb, var(--paper) 55%, transparent); }
.tbl td { font-family: var(--f-mono); font-size: .86rem; }
.tbl td.t, .tbl .t { font-family: var(--f-body); text-align: left; white-space: normal; }
.tbl tfoot td { font-weight: 600; border-top: 2px solid var(--ink); border-bottom: 0; }
.tbl tr.hl td { background: var(--pen-soft) !important; color: var(--pen); font-weight: 600; }
.chart-wrap { margin: 0; display: grid; gap: 6px; min-width: 0; }
.chart-wrap figcaption { font-size: .85rem; color: var(--ink-2); font-weight: 500; }
.chart { width: 100%; height: auto; display: block; overflow: visible; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .axis { stroke: var(--ink-3); stroke-width: 1.2; }
.chart .tick { fill: var(--ink-3); font: 11px var(--f-mono); }
.chart .ax-l { fill: var(--ink-2); font: 12px var(--f-body); }
.chart .line { fill: none; stroke-width: 2.4; stroke-linejoin: round; stroke-linecap: round; }
.chart .line.dash { stroke-dasharray: 6 5; stroke-width: 1.8; }
.chart .area { stroke: none; opacity: .14; }
.chart .s0 { stroke: var(--s0); } .chart .area.s0, .chart .bar.s0, .chart .dot.s0 { fill: var(--s0); }
.chart .s1 { stroke: var(--s1); } .chart .area.s1, .chart .bar.s1, .chart .dot.s1 { fill: var(--s1); }
.chart .s2 { stroke: var(--s2); } .chart .area.s2, .chart .bar.s2, .chart .dot.s2 { fill: var(--s2); }
.chart .s3 { stroke: var(--s3); } .chart .area.s3, .chart .bar.s3, .chart .dot.s3 { fill: var(--s3); }
.chart .bar { stroke: none; }
.chart .mark { fill: var(--sheet); stroke: var(--margin); stroke-width: 2.4; }
.chart .mark-l { fill: var(--ink); font: 600 11px var(--f-mono); paint-order: stroke; stroke: var(--sheet); stroke-width: 3px; }
.legend { display: flex; flex-wrap: wrap; gap: 14px; font-size: .82rem; color: var(--ink-2); }
.legend .lg::before { content: ''; display: inline-block; width: 14px; height: 3px; border-radius: 2px; margin-right: 6px; vertical-align: middle; background: var(--s0); }
.legend .lg.s1::before { background: var(--s1); } .legend .lg.s2::before { background: var(--s2); } .legend .lg.s3::before { background: var(--s3); }
.mat { border-collapse: separate; border-spacing: 0; position: relative; margin: 2px 10px; font-family: var(--f-mono); font-variant-numeric: tabular-nums; display: inline-table; vertical-align: middle; }
.mat td { padding: 4px 10px; text-align: center; min-width: 2.2em; }
.mat::before, .mat::after { content: ''; position: absolute; top: 0; bottom: 0; width: 7px; border: 1.5px solid var(--ink-2); }
.mat::before { left: -4px; border-right: 0; border-radius: 4px 0 0 4px; }
.mat::after { right: -4px; border-left: 0; border-radius: 0 4px 4px 0; }
.mat td.aug { border-left: 1px dashed var(--ink-3); }
.fr { display: inline-flex; flex-direction: column; vertical-align: middle; text-align: center; font-size: .82em; line-height: 1.15; margin: 0 1px; }
.fr > span:first-child { border-bottom: 1px solid currentColor; padding: 0 2px; }
.mat-scroll { overflow-x: auto; padding: 6px 4px; max-width: 100%; }
.eq { font-family: var(--f-mono); font-size: 1.05rem; overflow-wrap: anywhere; }
.big-eq { font: 500 1.15rem/1.6 var(--f-mono); overflow-wrap: anywhere; }
.cell-grid { display: grid; gap: 6px; }
.cell-grid input { width: 100%; min-width: 0; height: 40px; text-align: center; border: 1px solid var(--line); border-radius: 8px; background: var(--sheet); color: var(--ink); font: 500 .95rem var(--f-mono); padding: 0 4px; }
.cell-grid input:focus { outline: none; border-color: var(--pen); box-shadow: 0 0 0 3px var(--pen-soft); }
.rows-edit { display: grid; gap: 8px; }
.rows-edit .row { display: grid; gap: 8px; align-items: center; }
.row-del { width: 36px; height: 36px; border-radius: 8px; border: 1px solid var(--line); background: transparent; color: var(--ink-3); cursor: pointer; font-size: 1.1rem; line-height: 1; }
.row-del:hover { color: var(--bad); border-color: var(--bad); }

/* ───────── article content ───────── */
.tool-layout { display: grid; gap: 28px; padding-bottom: 40px; }
.prose { display: grid; gap: 28px; max-width: 780px; }
.prose section { display: grid; gap: 12px; }
.prose p, .prose li { color: var(--ink-2); }
.prose p strong, .prose li strong { color: var(--ink); }
.prose ul, .prose ol { margin: 0; padding-left: 1.3em; display: grid; gap: 6px; }
.prose h2 { padding-top: 6px; }
.prose h2::before { content: ''; display: block; width: 28px; height: 3px; background: var(--margin); border-radius: 2px; margin-bottom: 10px; }
.prose .formula {
  background: var(--sheet); border: 1px solid var(--line); border-radius: 12px; padding: 16px 18px; display: grid; gap: 10px;
  background-image: linear-gradient(var(--grid) 1px, transparent 1px), linear-gradient(90deg, var(--grid) 1px, transparent 1px); background-size: 22px 22px;
}
.prose .formula .big-eq { color: var(--ink); }
.prose .example { background: var(--pen-soft); border-radius: 12px; padding: 16px 18px; display: grid; gap: 8px; }
.prose .example p, .prose .example li { color: var(--ink); }
.prose .note { font-size: .9rem; border-left: 3px solid var(--warn); padding: 6px 0 6px 12px; color: var(--ink-2); }
.howto { counter-reset: s; list-style: none; padding: 0 !important; display: grid; gap: 10px; }
.howto li { counter-increment: s; display: grid; grid-template-columns: 32px 1fr; gap: 12px; align-items: start; }
.howto li::before {
  content: counter(s); width: 28px; height: 28px; border-radius: 8px; display: grid; place-items: center;
  background: var(--sheet); border: 1px solid var(--line); font: 600 .9rem var(--f-mono); color: var(--pen);
}
.faq { display: grid; gap: 8px; }
.faq details { background: var(--sheet); border: 1px solid var(--line); border-radius: 12px; padding: 0 16px; }
.faq summary { cursor: pointer; padding: 14px 0; font-weight: 600; color: var(--ink); list-style: none; display: flex; justify-content: space-between; gap: 16px; }
.faq summary::-webkit-details-marker { display: none; }
.faq summary::after { content: '+'; font: 500 1.2rem/1 var(--f-mono); color: var(--pen); transition: rotate .2s; }
.faq details[open] summary::after { rotate: 45deg; }
.faq .a { padding-bottom: 14px; color: var(--ink-2); display: grid; gap: 8px; }
.sources { font-size: .85rem; color: var(--ink-3); }
.sources ul { padding-left: 1.2em; margin: 6px 0 0; }
.related { display: grid; gap: 12px; }
.tool-links { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 0 24px; list-style: none; padding: 0; margin: 0; }
.tool-links a {
  display: flex; align-items: baseline; justify-content: space-between; gap: 12px; padding: 10px 2px; border-bottom: 1px solid var(--line);
  text-decoration: none; color: var(--ink); min-width: 0;
}
.tool-links a:hover { color: var(--pen); }
.tool-links a:hover .tl-n { text-decoration: underline; text-underline-offset: 3px; }
.tl-n { min-width: 0; }
.tl-e { color: var(--ink-3); font-size: .78rem; font-family: var(--f-mono); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 45%; }
.tl-new { color: var(--pen); font: 600 .68rem var(--f-display); letter-spacing: .05em; margin-left: 6px; vertical-align: 2px; }

/* ───────── home ───────── */
.hero { display: grid; gap: 22px; padding-block: 28px 12px; align-items: center; }
@media (min-width: 900px) { .hero { grid-template-columns: minmax(0, 1.1fr) minmax(0, .9fr); gap: 40px; padding-block: 44px 20px; } }
.hero h1 { font-size: clamp(1.9rem, 1.3rem + 2.6vw, 3.1rem); }
.hero h1 em { font-style: normal; color: var(--pen); }
.hero-lead { color: var(--ink-2); font-size: 1.08rem; max-width: 56ch; }
.hero-stats { display: flex; gap: 22px; flex-wrap: wrap; font-size: .88rem; color: var(--ink-3); }
.hero-stats b { display: block; font: 600 1.4rem/1.2 var(--f-mono); color: var(--ink); }
.quick {
  background: var(--sheet); border: 1px solid var(--line); border-radius: 18px; padding: 16px; box-shadow: var(--shadow); display: grid; gap: 12px;
}
.quick .lcd { padding: 12px 14px; }
.quick-expr { font: 500 1rem/1.4 var(--f-mono); color: var(--lcd-dim); min-height: 1.4em; overflow-wrap: anywhere; text-align: right; }
.quick .lcd-value { justify-content: flex-end; }
.quick input {
  width: 100%; height: 46px; border: 1px solid var(--line); border-radius: 10px; background: var(--paper); color: var(--ink);
  font: 500 1.05rem var(--f-mono); padding: 0 14px;
}
.quick input:focus { outline: none; border-color: var(--pen); box-shadow: 0 0 0 3px var(--pen-soft); }
.keys { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 6px; }
.key {
  height: 42px; border-radius: 9px; border: 1px solid var(--line); background: var(--paper); color: var(--ink); cursor: pointer;
  font: 500 1rem var(--f-mono); box-shadow: inset 0 -2px 0 rgba(0, 0, 0, .06); transition: transform .06s;
}
.key:hover { border-color: var(--pen); }
.key:active { transform: translateY(1px); box-shadow: none; }
.key.op { color: var(--pen); font-weight: 600; }
.key.eq { background: var(--pen); color: var(--on-pen); border-color: var(--pen); }
.key.fn { font-size: .82rem; color: var(--ink-2); }
.key.del { color: var(--margin); }
.quick-foot { display: flex; justify-content: space-between; font-size: .82rem; color: var(--ink-3); gap: 10px; flex-wrap: wrap; }
.cats { display: grid; gap: 34px 40px; padding-block: 18px 40px; }
@media (min-width: 860px) { .cats { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.cat-block { display: grid; gap: 10px; align-content: start; min-width: 0; }
.cat-head { display: flex; align-items: baseline; gap: 12px; }
.cat-head .g { font: 700 1.4rem/1 var(--f-display); color: var(--pen); width: 1.6em; }
.cat-head h2 { font-size: 1.25rem; }
.cat-head h2 a { color: inherit; text-decoration: none; }
.cat-head h2 a:hover { color: var(--pen); }
.cat-head .n { margin-left: auto; font: 500 .82rem var(--f-mono); color: var(--ink-3); }
.cat-desc { font-size: .88rem; color: var(--ink-3); }
.cat-block .tool-links { grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); }
.section-title { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; flex-wrap: wrap; padding-top: 18px; }
.features { display: grid; gap: 18px 28px; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); padding-block: 8px 34px; }
.feature { display: grid; gap: 4px; }
.feature b { font-family: var(--f-display); font-weight: 600; color: var(--ink); }
.feature p { font-size: .9rem; color: var(--ink-2); }
.filter-box { position: relative; max-width: 520px; }
.filter-box input { width: 100%; height: 48px; border-radius: 12px; border: 1px solid var(--line); background: var(--sheet); color: var(--ink); font: inherit; padding: 0 16px; }
.filter-box input:focus { outline: none; border-color: var(--pen); box-shadow: 0 0 0 3px var(--pen-soft); }

/* ───────── footer ───────── */
.site-foot { border-top: 1px solid var(--line); background: var(--sheet); margin-top: 20px; }
.foot-grid { display: grid; gap: 26px; padding-block: 32px 18px; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }
.foot-grid h3 { font-size: .9rem; margin-bottom: 8px; }
.foot-grid ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
.foot-grid a { color: var(--ink-2); text-decoration: none; font-size: .88rem; }
.foot-grid a:hover { color: var(--pen); text-decoration: underline; }
.foot-about p { font-size: .88rem; color: var(--ink-2); margin-top: 8px; }
.foot-base { border-top: 1px solid var(--line); padding-block: 14px 22px; font-size: .8rem; color: var(--ink-3); display: flex; gap: 12px; justify-content: space-between; flex-wrap: wrap; }
.toast {
  position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom, 0px)); translate: -50% 20px; opacity: 0; pointer-events: none;
  background: var(--ink); color: var(--paper); padding: 10px 18px; border-radius: 999px; font-size: .9rem; transition: all .2s; z-index: 60;
}
.toast.on { opacity: 1; translate: -50% 0; }
.static-page { max-width: 760px; padding-block: 10px 50px; display: grid; gap: 22px; }
.static-page .prose { gap: 18px; }
.article-meta { font-size: .85rem; color: var(--ink-3); }
.spec { width: 100%; }
.notfound { text-align: left; padding-block: 50px; display: grid; gap: 16px; max-width: 640px; }
.notfound .code { font: 600 4rem/1 var(--f-mono); color: var(--margin); }

@media print {
  .site-head, .cat-nav, .site-foot, .actions, .history, .related, .res-tools, .crumbs { display: none !important; }
  body { background: #fff; color: #000; }
  .sheet { box-shadow: none; border-color: #999; }
  .sheet-form { background: none; }
  .lcd { background: #fff; border: 1px solid #000; box-shadow: none; }
}
.prose .tbl th, .prose .tbl td { text-align: left; }
.prose .tbl td { font-family: var(--f-body); white-space: normal; }
.prose .tbl td.n, .prose .tbl th.n { font-family: var(--f-mono); text-align: right; white-space: nowrap; }
/* fixes from tool authors */
[hidden] { display: none !important; }
.tool-layout, .prose, .res-more, .res-block, .cat-block, .static-page { grid-template-columns: minmax(0, 1fr); }
.prose > *, .res-more > *, .steps { min-width: 0; }
.steps li, .prose p, .prose li, .kv dd { overflow-wrap: anywhere; }
.prose .tbl-auto { overflow-x: auto; max-width: 100%; }
