/* ==========================================================================
   Calcora — site stylesheet
   Design: a precision instrument that's friendly. Aluminium, graphite,
   an LCD-tinted display window for every answer, one saffron "equals" accent.
   ========================================================================== */

@font-face { font-family: "Barlow"; font-style: normal; font-weight: 400; font-display: swap; src: url("../fonts/barlow-latin-400-normal.woff2") format("woff2"); }
@font-face { font-family: "Barlow"; font-style: normal; font-weight: 500; font-display: swap; src: url("../fonts/barlow-latin-500-normal.woff2") format("woff2"); }
@font-face { font-family: "Barlow"; font-style: normal; font-weight: 600; font-display: swap; src: url("../fonts/barlow-latin-600-normal.woff2") format("woff2"); }
@font-face { font-family: "Barlow Condensed"; font-style: normal; font-weight: 500; font-display: swap; src: url("../fonts/barlow-condensed-latin-500-normal.woff2") format("woff2"); }
@font-face { font-family: "Barlow Condensed"; font-style: normal; font-weight: 600; font-display: swap; src: url("../fonts/barlow-condensed-latin-600-normal.woff2") format("woff2"); }

/* ---------- Tokens ---------- */
:root {
  color-scheme: light;
  --page: #edf0f3;
  --panel: #ffffff;
  --panel-2: #f6f8fa;
  --ink: #1c222a;
  --ink-2: #4f5965;
  --muted: #667180;
  --line: #d9dee5;
  --line-strong: #b8c0ca;
  --display: #e3eae4;
  --display-edge: #ccd6cf;
  --display-ink: #1c222a;
  --accent: #f0b31a;
  --accent-ink: #1c222a;
  --link: #22598f;
  --error: #b3261e;
  --error-bg: #fbeceb;
  --good: #1b7a3a;

  --series-1: #2b66a8;
  --series-2: #db9c00;
  --grid: #e5e9ee;
  --axis: #b8c0ca;

  --body: #262c34;          /* instrument body */
  --body-rim: #3a414b;
  --key: #3b424c;
  --key-ink: #eef1f4;
  --key-2: #59626e;
  --key-3: #c9cfd6;
  --key-3-ink: #1c222a;

  --font: "Barlow", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-cond: "Barlow Condensed", "Barlow", system-ui, sans-serif;

  --r-body: 28px;
  --r-panel: 16px;
  --r-field: 10px;
  --r-pill: 999px;

  --wrap: 1200px;
  --gutter: clamp(16px, 4vw, 40px);
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --page: #14181d;
    --panel: #1f252c;
    --panel-2: #192026;
    --ink: #e9edf1;
    --ink-2: #b4bdc7;
    --muted: #919ba7;
    --line: #313943;
    --line-strong: #46505b;
    --display: #232d29;
    --display-edge: #34413b;
    --display-ink: #dfe9e1;
    --link: #8db8e8;
    --error: #ff8a80;
    --error-bg: #3a2220;
    --good: #5fcf86;
    --series-1: #4a86cc;
    --series-2: #b98400;
    --grid: #2a3139;
    --axis: #46505b;
    --body: #2a3139;
    --body-rim: #3d4651;
    --key: #3c4550;
    --key-2: #58626e;
    --key-3: #aeb6bf;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #14181d;
  --panel: #1f252c;
  --panel-2: #192026;
  --ink: #e9edf1;
  --ink-2: #b4bdc7;
  --muted: #919ba7;
  --line: #313943;
  --line-strong: #46505b;
  --display: #232d29;
  --display-edge: #34413b;
  --display-ink: #dfe9e1;
  --link: #8db8e8;
  --error: #ff8a80;
  --error-bg: #3a2220;
  --good: #5fcf86;
  --series-1: #4a86cc;
  --series-2: #b98400;
  --grid: #2a3139;
  --axis: #46505b;
  --body: #2a3139;
  --body-rim: #3d4651;
  --key: #3c4550;
  --key-2: #58626e;
  --key-3: #aeb6bf;
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font-family: var(--font);
  font-size: 1.0625rem;
  line-height: 1.55;
  font-weight: 400;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
img, svg { display: block; max-width: 100%; }
a { color: var(--link); text-decoration-thickness: 1px; text-underline-offset: 3px; }
a:hover { text-decoration-thickness: 2px; }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0; line-height: 1.15; font-weight: 600; }
p { margin: 0 0 1em; }
:focus-visible { outline: 2px solid var(--ink); outline-offset: 3px; border-radius: 4px; }
::selection { background: var(--accent); color: var(--accent-ink); }

.visually-hidden {
  position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.skip-link {
  position: absolute; left: 12px; top: -60px; z-index: 50;
  background: var(--ink); color: var(--page); padding: 10px 14px; border-radius: 8px;
}
.skip-link:focus { top: 12px; }

.wrap { width: 100%; max-width: var(--wrap); margin: 0 auto; padding: 0 var(--gutter); }
.num { font-variant-numeric: tabular-nums; }

/* ---------- Header ---------- */
.site-header { border-bottom: 1px solid var(--line); background: var(--page); }
.site-header__bar { display: flex; align-items: center; gap: 24px; min-height: 68px; }
.brand { display: inline-flex; align-items: center; gap: 10px; color: var(--ink); text-decoration: none; font-weight: 600; font-size: 1.3125rem; letter-spacing: -0.01em; }
.brand__key { width: 30px; height: 30px; border-radius: 50%; background: var(--accent); display: grid; place-items: center; box-shadow: inset 0 -2px 0 rgba(0,0,0,.18); }
.brand__key svg { width: 14px; height: 14px; }
.nav { display: flex; gap: 4px; margin-left: 8px; }
.nav a { color: var(--ink-2); text-decoration: none; padding: 8px 12px; border-radius: var(--r-pill); font-weight: 500; }
.nav a:hover { color: var(--ink); background: var(--panel); }
.nav a[aria-current="page"] { color: var(--ink); background: var(--panel); box-shadow: inset 0 0 0 1px var(--line); }
.header-tools { margin-left: auto; display: flex; align-items: center; gap: 8px; }

.search { position: relative; }
.search__input {
  width: 260px; height: 40px; padding: 0 14px 0 38px;
  border: 1px solid var(--line); border-radius: var(--r-pill);
  background: var(--panel); color: var(--ink);
}
.search__input::placeholder { color: var(--muted); }
.search__input:focus { outline: none; border-color: var(--ink); box-shadow: 0 0 0 3px color-mix(in srgb, var(--ink) 14%, transparent); }
.search__icon { position: absolute; left: 13px; top: 50%; transform: translateY(-50%); width: 16px; height: 16px; color: var(--muted); pointer-events: none; }
.search__list {
  position: absolute; z-index: 40; top: calc(100% + 6px); left: 0; right: 0; min-width: 300px;
  margin: 0; padding: 6px; list-style: none;
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px;
  box-shadow: 0 12px 32px -12px rgba(20, 26, 33, .28);
  max-height: 60vh; overflow: auto;
}
.search__list[hidden] { display: none; }
.search__item a { display: block; padding: 8px 10px; border-radius: 9px; color: var(--ink); text-decoration: none; }
.search__item small { display: block; color: var(--muted); font-size: .8125rem; line-height: 1.3; }
.search__item[aria-selected="true"] a, .search__item a:hover { background: var(--panel-2); }
.search__empty { padding: 10px; color: var(--muted); font-size: .9375rem; }

.icon-btn {
  width: 40px; height: 40px; border-radius: 50%; border: 1px solid var(--line);
  background: var(--panel); color: var(--ink); display: grid; place-items: center; cursor: pointer;
}
.icon-btn:hover { border-color: var(--line-strong); }
.icon-btn svg { width: 18px; height: 18px; }
.menu-btn { display: none; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 8px; height: 40px; padding: 0 16px;
  border-radius: var(--r-pill); border: 1px solid var(--line-strong); background: var(--panel);
  color: var(--ink); font-weight: 500; cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn:hover { border-color: var(--ink); }
.btn svg { width: 16px; height: 16px; }
.btn--quiet { border-color: transparent; background: transparent; color: var(--ink-2); }
.btn--quiet:hover { color: var(--ink); border-color: var(--line); background: var(--panel); }
.btn--solid { background: var(--ink); color: var(--page); border-color: var(--ink); }
.btn--solid:hover { background: color-mix(in srgb, var(--ink) 86%, var(--page)); }

/* ---------- Home: hero ---------- */
.hero { padding: clamp(36px, 7vw, 88px) 0 clamp(40px, 6vw, 72px); }
.hero__grid { display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(0, .85fr); gap: clamp(32px, 6vw, 88px); align-items: center; }
.hero__title {
  font-family: var(--font-cond); font-weight: 600;
  font-size: clamp(3.5rem, 9vw, 6.5rem); line-height: .92; letter-spacing: -0.02em;
  margin-bottom: 22px;
}
.hero__lede { font-size: 1.3125rem; line-height: 1.45; color: var(--ink-2); max-width: 30em; margin-bottom: 28px; }
.hero .search__input { width: 100%; max-width: 460px; height: 54px; font-size: 1.0625rem; padding-left: 46px; }
.hero .search { max-width: 460px; }
.hero .search__icon { left: 17px; width: 18px; height: 18px; }
.quick { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 18px; padding: 0; list-style: none; }
.quick a {
  display: inline-block; padding: 6px 12px; border-radius: var(--r-pill);
  background: var(--panel); border: 1px solid var(--line); color: var(--ink); text-decoration: none; font-size: .9375rem; font-weight: 500;
}
.quick a:hover { border-color: var(--ink); }
.hero__instrument { justify-self: end; width: 100%; max-width: 340px; }
.hero__more { margin-top: 14px; text-align: center; font-size: .9375rem; text-wrap: balance; }

/* ---------- Instrument (keypad calculator) ---------- */
.instrument {
  background: var(--body);
  border-radius: var(--r-body);
  padding: 22px 20px 24px;
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,.08),
    inset 0 -3px 0 rgba(0,0,0,.25),
    0 1px 2px rgba(20,26,33,.2),
    0 24px 48px -24px rgba(20,26,33,.55);
  user-select: none; -webkit-user-select: none;
}
.instrument__display {
  background: var(--display);
  color: var(--display-ink);
  border-radius: 12px;
  padding: 14px 16px 12px;
  min-height: 104px;
  box-shadow: inset 0 2px 6px rgba(0,0,0,.16), inset 0 0 0 1px var(--display-edge);
  display: flex; flex-direction: column; justify-content: flex-end; text-align: right;
  margin-bottom: 18px; overflow: hidden;
}
:root[data-theme="dark"] .instrument__display { --display: #2c3833; }
.instrument__expr { font-size: .9375rem; color: color-mix(in srgb, var(--display-ink) 62%, transparent); min-height: 1.4em; white-space: nowrap; overflow-x: auto; scrollbar-width: none; direction: ltr; }
.instrument__expr::-webkit-scrollbar { display: none; }
.instrument__value {
  font-family: var(--font-cond); font-weight: 500; font-size: 3rem; line-height: 1.05;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.instrument__value[data-size="m"] { font-size: 2.4rem; }
.instrument__value[data-size="s"] { font-size: 1.9rem; }
.instrument--basic .instrument__status span[data-mode-label] { visibility: hidden; }
.instrument__status { display: flex; justify-content: space-between; font-size: .75rem; color: color-mix(in srgb, var(--display-ink) 55%, transparent); margin-bottom: 2px; }
.keys { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.keys--sci { grid-template-columns: repeat(5, 1fr); gap: 10px; }
.key {
  aspect-ratio: 1; border-radius: 50%; border: 0; cursor: pointer;
  background: var(--key); color: var(--key-ink);
  font-family: var(--font); font-size: 1.375rem; font-weight: 500; line-height: 1;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.10), inset 0 -3px 0 rgba(0,0,0,.28), 0 1px 1px rgba(0,0,0,.25);
  display: grid; place-items: center;
  transition: transform .06s ease, box-shadow .06s ease, filter .1s ease;
  touch-action: manipulation;
}
.key:hover { filter: brightness(1.08); }
.key:active, .key.is-pressed { transform: translateY(1px); box-shadow: inset 0 1px 0 rgba(255,255,255,.06), inset 0 -1px 0 rgba(0,0,0,.28); }
.key:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: 50%; }
.key--op { background: var(--key-2); font-size: 1.75rem; font-weight: 400; }
.key--fn { background: var(--key-3); color: var(--key-3-ink); font-size: 1.125rem; }
.key--eq { background: var(--accent); color: var(--accent-ink); font-size: 1.625rem; }
.key--sm { font-size: .9375rem; }

.keys--sci .key--sm { font-size: .8125rem; }
.key--wide { grid-column: span 2; aspect-ratio: auto; border-radius: var(--r-pill); }
.key[aria-pressed="true"] { box-shadow: inset 0 0 0 2px var(--accent), inset 0 -3px 0 rgba(0,0,0,.28); }
.instrument--sci { max-width: 520px; margin: 0 auto; }

/* ---------- Home: directory ---------- */
.directory { padding: 0 0 clamp(48px, 8vw, 96px); }
.directory__head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 16px; border-top: 1px solid var(--line-strong); padding-top: 28px; margin-bottom: 28px; }
.directory__head h2 { font-family: var(--font-cond); font-size: 2.25rem; letter-spacing: -0.01em; }
.directory__head p { margin: 0; color: var(--ink-2); }
.directory__grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 40px 32px; }
.cat h3 { font-size: 1.3125rem; display: flex; align-items: center; gap: 10px; padding-bottom: 12px; border-bottom: 1px solid var(--line); margin-bottom: 6px; }
.cat h3 a { color: var(--ink); text-decoration: none; }
.cat__glyph { width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; background: var(--panel); border: 1px solid var(--line); font-size: .9375rem; font-weight: 600; color: var(--ink-2); flex: none; }
.cat ul { list-style: none; margin: 0; padding: 0; }
.cat li a { display: block; padding: 10px 0; border-bottom: 1px solid var(--line); text-decoration: none; color: var(--ink); }
.cat li a:hover .cat__name { text-decoration: underline; text-underline-offset: 3px; }
.cat__name { display: block; font-weight: 500; }
.cat__desc { display: block; color: var(--muted); font-size: .9375rem; line-height: 1.35; }
.cat li[hidden] { display: none; }
.directory__empty { color: var(--ink-2); }

/* ---------- Page head ---------- */
.page-head { padding: clamp(24px, 4vw, 40px) 0 clamp(20px, 3vw, 28px); }
.crumbs { display: flex; flex-wrap: wrap; gap: 6px; list-style: none; margin: 0 0 14px; padding: 0; font-size: .9375rem; color: var(--muted); }
.crumbs li + li::before { content: "/"; margin-right: 6px; color: var(--line-strong); }
.crumbs a { color: var(--ink-2); text-decoration: none; }
.crumbs a:hover { text-decoration: underline; }
.page-title { font-family: var(--font-cond); font-weight: 600; font-size: clamp(2.5rem, 5.5vw, 3.75rem); letter-spacing: -0.015em; line-height: .98; margin-bottom: 12px; }
.page-lede { font-size: 1.1875rem; color: var(--ink-2); max-width: 40em; margin: 0; line-height: 1.5; }

/* ---------- Calculator panel ---------- */
.calc {
  display: grid; grid-template-columns: minmax(0, 5fr) minmax(0, 6fr);
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--r-panel);
}
.calc--stack { grid-template-columns: minmax(0, 1fr); }
.calc__inputs { padding: clamp(20px, 3vw, 32px); border-right: 1px solid var(--line); }
.calc--stack .calc__inputs { border-right: 0; border-bottom: 1px solid var(--line); }
.calc__output { padding: clamp(16px, 2.4vw, 24px); background: var(--panel-2); border-radius: 0 var(--r-panel) var(--r-panel) 0; min-width: 0; }
.calc--stack .calc__output { border-radius: 0 0 var(--r-panel) var(--r-panel); }
.calc__toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 24px; padding-top: 18px; border-top: 1px solid var(--line); }
.calc__toolbar .pref { margin-left: auto; }

/* Fields */
.fields { display: grid; gap: 18px; }
.fields--2 { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px 16px; }
.field { min-width: 0; }
.field > label, .field > .label, .seg legend {
  display: block; font-weight: 500; margin-bottom: 6px; font-size: 1rem; padding: 0;
}
.field__help { display: block; color: var(--muted); font-size: .875rem; margin-top: 5px; line-height: 1.35; }
.input {
  display: flex; align-items: stretch; height: 48px;
  border: 1px solid var(--line-strong); border-radius: var(--r-field); background: var(--panel);
  transition: border-color .12s ease, box-shadow .12s ease;
}
.input:focus-within { border-color: var(--ink); box-shadow: 0 0 0 3px color-mix(in srgb, var(--ink) 12%, transparent); }
.input input, .input select {
  flex: 1; min-width: 0; border: 0; background: transparent; padding: 0 12px; height: 100%;
  font-size: 1.0625rem; font-variant-numeric: tabular-nums; outline: none;
}
.input select { cursor: pointer; padding-right: 32px; appearance: none; -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5l5 5 5-5' fill='none' stroke='%23667180' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center; }
.input input[type="date"] { font-variant-numeric: tabular-nums; }
.affix { display: grid; place-items: center; padding: 0 12px; color: var(--muted); font-weight: 500; white-space: nowrap; }
.affix--pre { padding-right: 0; }
.affix--post { padding-left: 0; }
.input--split { gap: 0; }
.input--split input + .affix + input { border-left: 1px solid var(--line); }
textarea.textarea {
  width: 100%; min-height: 132px; resize: vertical; padding: 12px; line-height: 1.5;
  border: 1px solid var(--line-strong); border-radius: var(--r-field); background: var(--panel);
  font-variant-numeric: tabular-nums;
}
textarea.textarea:focus { outline: none; border-color: var(--ink); box-shadow: 0 0 0 3px color-mix(in srgb, var(--ink) 12%, transparent); }
.field.is-invalid .input, .field.is-invalid .textarea { border-color: var(--error); }
.field__error { display: block; color: var(--error); font-size: .875rem; margin-top: 5px; }
.field__error:empty { display: none; }

/* Segmented control */
.seg { border: 0; margin: 0; padding: 0; min-width: 0; }
.seg__opts { display: flex; flex-wrap: wrap; gap: 4px; padding: 4px; background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--r-field); }
.seg__opts label { flex: 1 1 auto; position: relative; }
.seg__opts input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.seg__opts span {
  display: block; text-align: center; padding: 8px 10px; border-radius: 7px; font-weight: 500; font-size: .9375rem;
  color: var(--ink-2); cursor: pointer; white-space: nowrap;
}
.seg__opts input:checked + span { background: var(--panel); color: var(--ink); box-shadow: 0 0 0 1px var(--line-strong), 0 1px 2px rgba(20,26,33,.08); }
.seg__opts input:focus-visible + span { outline: 2px solid var(--ink); outline-offset: 1px; }
[data-unit][hidden], [data-when][hidden] { display: none !important; }

.check { display: flex; align-items: center; gap: 10px; font-weight: 500; cursor: pointer; }
.check input { width: 20px; height: 20px; accent-color: var(--ink); }

/* ---------- Display (results window) ---------- */
.display {
  background: var(--display); color: var(--display-ink);
  border-radius: 12px; padding: clamp(16px, 2.2vw, 22px) clamp(16px, 2.4vw, 24px);
  box-shadow: inset 0 2px 5px rgba(0,0,0,.08), inset 0 0 0 1px var(--display-edge);
}
.display__label { display: flex; align-items: center; gap: 8px; font-weight: 500; color: color-mix(in srgb, var(--display-ink) 78%, transparent); }
.display__label::before { content: ""; width: 18px; height: 18px; border-radius: 50%; flex: none;
  background: var(--accent) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 18 18'%3E%3Cpath d='M5.5 7.2h7M5.5 10.8h7' stroke='%231c222a' stroke-width='1.6' stroke-linecap='round'/%3E%3C/svg%3E") center/18px no-repeat; }
.display__value {
  font-family: var(--font-cond); font-weight: 600; font-size: clamp(2.75rem, 6vw, 4rem);
  line-height: 1.02; letter-spacing: -0.01em; margin: 4px 0 2px; overflow-wrap: anywhere;
}
.display__value small { font-size: .45em; font-weight: 500; letter-spacing: 0; margin-left: 4px; color: color-mix(in srgb, var(--display-ink) 70%, transparent); }
.display__sub { color: color-mix(in srgb, var(--display-ink) 80%, transparent); font-size: 1rem; margin: 0; }
.display__empty { color: color-mix(in srgb, var(--display-ink) 70%, transparent); margin: 0; padding: 18px 0; }
.display__error { display: flex; gap: 10px; align-items: flex-start; margin: 0; padding: 8px 0; color: var(--display-ink); }
.display__error::before { content: "!"; flex: none; width: 22px; height: 22px; border-radius: 50%; background: var(--error); color: #fff; display: grid; place-items: center; font-weight: 600; font-size: .875rem; margin-top: 1px; }

.figures { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin-top: 16px; }
.figure { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; min-width: 0; }
.figure__label { display: block; font-size: .875rem; color: var(--ink-2); line-height: 1.3; }
.figure__value { display: block; font-family: var(--font-cond); font-weight: 600; font-size: 1.75rem; line-height: 1.15; overflow-wrap: anywhere; }
.figure__note { display: block; font-size: .8125rem; color: var(--muted); }

/* Tape: the working, printed like a till roll */
.tape { margin: 16px 0 0; padding: 4px 16px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; }
.tape__row { display: flex; justify-content: space-between; gap: 16px; padding: 9px 0; border-bottom: 1px dashed var(--line); font-size: 1rem; }
.tape__row:last-child { border-bottom: 0; }
.tape__row dt { color: var(--ink-2); }
.tape__row dd { margin: 0; font-variant-numeric: tabular-nums; font-weight: 500; text-align: right; }
.tape__row--total { border-top: 1px solid var(--ink); border-bottom: 0; margin-top: 2px; padding-top: 11px; }
.tape__row--total dt { color: var(--ink); font-weight: 600; }
.tape__row--total dd { font-weight: 600; }
.note { font-size: .9375rem; color: var(--ink-2); margin: 14px 0 0; }
.note--warn { padding: 10px 12px; border-radius: 10px; background: var(--panel); border: 1px solid var(--line); }

/* Peek bar (mobile): keeps the answer visible while typing */
.peek {
  position: fixed; left: 12px; right: 12px; bottom: 12px; z-index: 30;
  display: none; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 14px; border-radius: 14px;
  background: var(--display); color: var(--display-ink);
  box-shadow: inset 0 0 0 1px var(--display-edge), 0 10px 30px -10px rgba(20,26,33,.45);
  text-decoration: none; font-weight: 500;
}
.peek strong { font-family: var(--font-cond); font-size: 1.5rem; font-weight: 600; }
.peek.is-visible { display: flex; }

/* ---------- Sections below the calculator ---------- */
.section { margin-top: clamp(28px, 4vw, 44px); }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r-panel); padding: clamp(18px, 3vw, 28px); }
.section__title { font-size: 1.5rem; margin-bottom: 4px; }
.section__sub { color: var(--ink-2); margin: 0 0 16px; }

/* Charts */
.chart { position: relative; margin-top: 8px; }
.chart svg { width: 100%; height: auto; overflow: visible; font-family: var(--font); }
.chart text { fill: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }
.chart .grid line { stroke: var(--grid); stroke-width: 1; shape-rendering: crispEdges; }
.chart .baseline { stroke: var(--axis); stroke-width: 1; shape-rendering: crispEdges; }
.chart .crosshair { stroke: var(--ink-2); stroke-width: 1; opacity: .5; }
.chart .hit { fill: transparent; cursor: crosshair; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 18px; list-style: none; margin: 0 0 6px; padding: 0; font-size: .9375rem; color: var(--ink-2); }
.legend li { display: inline-flex; align-items: center; gap: 8px; }
.legend i { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }
.legend i.line { height: 3px; width: 16px; border-radius: 2px; }
.tooltip {
  position: absolute; z-index: 5; pointer-events: none; min-width: 150px;
  background: var(--panel); color: var(--ink); border: 1px solid var(--line); border-radius: 10px;
  padding: 8px 10px; font-size: .875rem; line-height: 1.4; box-shadow: 0 8px 24px -10px rgba(20,26,33,.35);
  transform: translate(-50%, calc(-100% - 12px)); white-space: nowrap;
}
.tooltip[hidden] { display: none; }
.tooltip b { display: block; font-weight: 600; margin-bottom: 2px; }
.tooltip span { display: flex; align-items: center; gap: 6px; justify-content: space-between; }
.tooltip span em { font-style: normal; color: var(--ink-2); display: inline-flex; align-items: center; gap: 6px; }
.tooltip span em i { width: 8px; height: 8px; border-radius: 2px; display: inline-block; }
.tooltip span strong { font-weight: 600; font-variant-numeric: tabular-nums; }

/* Segmented share bar */
.share { margin-top: 16px; }
.share__bar { display: flex; gap: 2px; height: 28px; }
.share__part { height: 100%; border-radius: 4px; display: flex; align-items: center; padding: 0 8px; font-size: .8125rem; font-weight: 600; overflow: hidden; white-space: nowrap; min-width: 2px; }
.share__part--1 { background: var(--series-1); color: #fff; }
.share__part--2 { background: var(--series-2); color: #1c222a; }
.share .legend { margin-top: 8px; }

/* Scale meter (e.g. BMI) */
.scale { margin-top: 18px; }
.scale__track { position: relative; display: flex; gap: 2px; height: 10px; }
.scale__band { height: 100%; background: color-mix(in srgb, var(--display-ink) 18%, transparent); }
.scale__band:first-child { border-radius: 5px 0 0 5px; }
.scale__band:last-child { border-radius: 0 5px 5px 0; }
.scale__band.is-current { background: var(--display-ink); }
.scale__marker { position: absolute; top: 50%; width: 18px; height: 18px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 3px var(--display); transform: translate(-50%, -50%); }
.scale__labels { position: relative; height: 34px; margin-top: 6px; font-size: .8125rem; color: color-mix(in srgb, var(--display-ink) 75%, transparent); }
.scale__labels span { position: absolute; top: 0; transform: translateX(-50%); text-align: center; line-height: 1.2; white-space: nowrap; }
.scale__labels span:first-child { transform: none; }
.scale__labels span:last-child { transform: translateX(-100%); }

/* Tables */
.table-scroll { overflow: auto; max-height: 520px; border: 1px solid var(--line); border-radius: 12px; background: var(--panel); }
table.data { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; font-size: .9375rem; }
table.data th, table.data td { padding: 9px 14px; text-align: right; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.data th:first-child, table.data td:first-child { text-align: left; }
table.data thead th { position: sticky; top: 0; background: var(--panel-2); font-weight: 600; color: var(--ink-2); z-index: 1; }
table.data tbody tr:hover { background: var(--panel-2); }
details.disclose { margin-top: 18px; }
details.disclose > summary { cursor: pointer; font-weight: 500; list-style: none; display: inline-flex; align-items: center; gap: 8px; padding: 8px 14px; border-radius: var(--r-pill); border: 1px solid var(--line-strong); background: var(--panel); }
details.disclose > summary::-webkit-details-marker { display: none; }
details.disclose > summary::before { content: "+"; font-weight: 600; width: 14px; text-align: center; }
details.disclose[open] > summary::before { content: "−"; }
details.disclose[open] > summary { margin-bottom: 14px; }

/* Lists of output values (e.g. salary table, unit conversions) */
.pills { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.pill-out { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 6px 12px; font-variant-numeric: tabular-nums; font-weight: 500; }
.numbers { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.numbers span { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 8px 14px; font-family: var(--font-cond); font-weight: 600; font-size: 1.5rem; font-variant-numeric: tabular-nums; }

/* Fraction input */
.frac-row { display: grid; grid-template-columns: 1fr auto 1fr; gap: 14px; align-items: center; }
.frac { display: grid; gap: 6px; }
.frac .input { height: 44px; }
.frac__bar { height: 2px; background: var(--ink); border-radius: 2px; }
.frac-op .input { height: 48px; width: 76px; }
.frac-whole { display: grid; grid-template-columns: 64px 1fr; gap: 8px; align-items: center; }
.frac-out { display: inline-grid; grid-template-rows: auto 2px auto; justify-items: center; vertical-align: middle; margin: 0 6px; font-size: .62em; line-height: 1.05; }
.frac-out i { width: 100%; height: 3px; background: currentColor; border-radius: 2px; }

/* ---------- Content (prose + aside) ---------- */
.content { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: clamp(32px, 5vw, 72px); margin-top: clamp(40px, 6vw, 72px); padding-bottom: clamp(48px, 8vw, 96px); }
.prose { max-width: 68ch; }
.prose h2 { font-size: 1.75rem; margin: 1.6em 0 .5em; letter-spacing: -0.005em; }
.prose h2:first-child { margin-top: 0; }
.prose h3 { font-size: 1.1875rem; margin: 1.4em 0 .35em; }
.prose p, .prose li { color: var(--ink); }
.prose ul, .prose ol { padding-left: 1.25em; margin: 0 0 1em; }
.prose li { margin-bottom: .35em; }
.prose li::marker { color: var(--muted); }
.formula {
  display: block; margin: 16px 0 20px; padding: 14px 18px;
  background: var(--display); color: var(--display-ink); border-radius: 10px;
  box-shadow: inset 0 0 0 1px var(--display-edge);
  font-size: 1.125rem; font-weight: 500; overflow-x: auto; white-space: nowrap;
}
.formula var { font-style: italic; }
.prose dl.terms { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; margin: 0 0 1.2em; }
.prose dl.terms dt { font-weight: 600; font-style: italic; }
.prose dl.terms dd { margin: 0; color: var(--ink-2); }
.faq h3 { font-size: 1.125rem; }
.prose .callout { margin: 1.5em 0; }
.callout { padding: 14px 16px; border-radius: 12px; background: var(--panel); border: 1px solid var(--line); color: var(--ink-2); font-size: .9375rem; }

.aside { align-self: start; position: sticky; top: 20px; }
.aside h2 { font-size: 1.125rem; margin-bottom: 8px; }
.aside ul { list-style: none; margin: 0 0 28px; padding: 0; border-top: 1px solid var(--line); }
.aside li a { display: block; padding: 10px 0; border-bottom: 1px solid var(--line); color: var(--ink); text-decoration: none; font-weight: 500; }
.aside li a:hover { text-decoration: underline; text-underline-offset: 3px; }
.aside li a small { display: block; font-weight: 400; color: var(--muted); font-size: .875rem; }

/* ---------- Simple pages ---------- */
.page-body { padding-bottom: clamp(48px, 8vw, 96px); }
.not-found { padding: clamp(48px, 10vw, 120px) 0; display: grid; grid-template-columns: minmax(0, 1fr) 280px; gap: 48px; align-items: center; }
.not-found .instrument__display { margin: 0; min-height: 0; }

/* ---------- Footer ---------- */
.site-footer { border-top: 1px solid var(--line); padding: 40px 0 48px; color: var(--ink-2); font-size: .9375rem; }
.site-footer__grid { display: grid; grid-template-columns: 1.4fr repeat(4, 1fr); gap: 32px; }
.site-footer h2 { font-size: 1rem; color: var(--ink); margin-bottom: 10px; }
.site-footer ul { list-style: none; margin: 0; padding: 0; }
.site-footer li { margin-bottom: 6px; }
.site-footer a { color: var(--ink-2); text-decoration: none; }
.site-footer a:hover { color: var(--ink); text-decoration: underline; }
.site-footer__legal { margin-top: 32px; padding-top: 20px; border-top: 1px solid var(--line); display: flex; flex-wrap: wrap; justify-content: space-between; gap: 12px; font-size: .875rem; color: var(--muted); }
.site-footer__legal p { margin: 0; max-width: 62ch; }

/* Toast */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 12px); z-index: 60;
  background: var(--ink); color: var(--page); padding: 10px 16px; border-radius: var(--r-pill);
  font-weight: 500; opacity: 0; pointer-events: none; transition: opacity .18s ease, transform .18s ease;
}
.toast.is-visible { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Responsive ---------- */
@media (max-width: 1080px) {
  .directory__grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .search__input { width: 200px; }
  .site-footer__grid { grid-template-columns: repeat(3, 1fr); }
  .site-footer__about { grid-column: 1 / -1; }
}
@media (max-width: 900px) {
  .hero__grid { grid-template-columns: minmax(0, 1fr); }
  .hero__instrument { max-width: 360px; }
  .calc { grid-template-columns: minmax(0, 1fr); }
  .calc__inputs { border-right: 0; border-bottom: 1px solid var(--line); }
  .calc__output { border-radius: 0 0 var(--r-panel) var(--r-panel); }
  .content { grid-template-columns: minmax(0, 1fr); }
  .aside { position: static; }
  .nav { display: none; }
  .nav.is-open { display: flex; position: absolute; left: 0; right: 0; top: 68px; z-index: 45; flex-direction: column; gap: 0; padding: 8px var(--gutter) 16px; background: var(--page); border-bottom: 1px solid var(--line); margin: 0; }
  .nav.is-open a { padding: 12px 0; border-radius: 0; border-bottom: 1px solid var(--line); }
  .nav.is-open a:hover, .nav.is-open a[aria-current="page"] { background: transparent; box-shadow: none; }
  .menu-btn { display: grid; }
  .site-header { position: relative; }
  .header-tools .search { display: none; }
  .not-found { grid-template-columns: 1fr; }
}
@media (max-width: 600px) {
  body { font-size: 1rem; }
  .directory__head { flex-direction: column; gap: 6px; }
  .directory__grid { grid-template-columns: minmax(0, 1fr); }
  .fields--2 { grid-template-columns: minmax(0, 1fr); }
  .fields--2.keep { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .site-footer__grid { grid-template-columns: repeat(2, 1fr); }
  .hero__lede { font-size: 1.125rem; }
  .keys { gap: 10px; }
  .keys--sci { gap: 7px; }
  .keys--sci .key { font-size: 1rem; }
  .keys--sci .key--sm { font-size: .75rem; }
  .instrument { padding: 18px 14px 18px; }
  .calc__toolbar .pref { margin-left: 0; width: 100%; }
  table.data th, table.data td { padding: 8px 10px; }
  .page-lede { font-size: 1.0625rem; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}
@media print {
  .site-header, .site-footer, .calc__toolbar, .aside, .peek, .toast { display: none !important; }
  body { background: #fff; }
  .calc, .panel { border-color: #999; }
}
@media (forced-colors: active) {
  .key, .display, .instrument__display { border: 1px solid CanvasText; }
  .share__part { forced-color-adjust: none; }
}

/* ---------- Additions: toolbar prefs, multi-panel pages, scientific layout ---------- */
.pref { display: inline-flex; align-items: center; gap: 8px; color: var(--ink-2); font-size: .9375rem; }
.input--mini { height: 40px; border-radius: var(--r-pill); }
.input--mini select { font-size: .9375rem; padding-left: 14px; }
.calc__title { font-size: 1.3125rem; margin-bottom: 16px; }
.panels { display: grid; gap: 20px; }
.panels .display__value { font-size: clamp(2.25rem, 4.5vw, 3rem); }
.panels .calc__output { display: flex; flex-direction: column; justify-content: center; }
.sci-wrap { display: flex; justify-content: center; padding: 8px 0 0; }
.instrument--sci { width: 100%; max-width: 660px; }
.sci-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.keys--fn { grid-template-columns: repeat(4, 1fr); gap: 12px; }
.keys--fn .key { font-size: 1.0625rem; background: rgba(255,255,255,.05); color: var(--key-ink);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.16), inset 0 -2px 0 rgba(0,0,0,.25); }
.keys--fn .key:active, .keys--fn .key.is-pressed { background: rgba(255,255,255,.12); }
.keys--fn .key--sm { font-size: .9375rem; }
@media (max-width: 700px) {
  .sci-grid { grid-template-columns: 1fr; gap: 12px; }
  .keys--fn { gap: 9px; }
  .keys--fn .key { aspect-ratio: 1.5; border-radius: 14px; }
  .frac-row { grid-template-columns: 1fr; gap: 12px; }
  .frac-op .input { width: 100%; }
}

/* ---------- Page grid with a right-hand rail (ad + related links) ---------- */
.page-grid { display: grid; grid-template-columns: minmax(0, 1fr) 300px; column-gap: clamp(32px, 4vw, 48px); align-items: start; }
.page-grid > * { grid-column: 1; min-width: 0; }
.page-grid > .rail { grid-column: 2; grid-row: 1 / span 12; padding-top: clamp(24px, 4vw, 40px); }
.page-grid .page-prose { margin-top: clamp(40px, 6vw, 64px); padding-bottom: clamp(48px, 8vw, 96px); }
.page-body .page-grid .page-prose { margin-top: 8px; }
.rail .aside { position: static; margin-top: 28px; }
.rail .aside:first-child { margin-top: 0; }

@media (max-width: 1120px) {
  .page-grid { grid-template-columns: minmax(0, 1fr); }
  .page-grid > .rail { display: contents; }
  .page-grid > .page-head { order: 1; }
  .page-grid > .calc, .page-grid > .panels, .page-grid > .sci-wrap { order: 2; }
  .page-grid .ad-slot { order: 3; margin: 28px auto 0; }
  .page-grid > .section { order: 4; }
  .page-grid > .page-prose { order: 5; }
  .page-grid .rail__links { order: 6; margin: 0 0 clamp(48px, 8vw, 96px); position: static; }
}

/* ---------- Ad slots ---------- */
.ad-slot { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.ad-slot__label { font-size: .75rem; color: var(--muted); letter-spacing: .02em; align-self: stretch; text-align: center; }
.ad-slot__box { max-width: 100%; display: grid; place-items: center; overflow: hidden; }
.ad-slot__placeholder {
  width: 100%; height: 100%; display: grid; place-items: center; text-align: center;
  border: 1px dashed var(--line-strong); border-radius: 8px; color: var(--muted); font-size: .875rem; line-height: 1.4;
  background: repeating-linear-gradient(135deg, transparent 0 10px, color-mix(in srgb, var(--line) 35%, transparent) 10px 11px);
}
.ad-top { display: flex; justify-content: flex-end; padding-top: 20px; }
.ad-top + .hero { padding-top: clamp(20px, 3.5vw, 44px); }
.ad-mobile { display: none; }
@media (max-width: 980px) {
  .ad-top { display: none; }
  .ad-top + .hero { padding-top: clamp(36px, 7vw, 88px); }
  .ad-mobile { display: flex; justify-content: center; padding-bottom: 36px; }
}

/* ---------- Language switcher ---------- */
.lang { position: relative; }
.lang > summary {
  list-style: none; display: inline-flex; align-items: center; gap: 6px; height: 40px; padding: 0 12px 0 10px;
  border: 1px solid var(--line); border-radius: var(--r-pill); background: var(--panel); color: var(--ink);
  cursor: pointer; font-weight: 500; font-size: .9375rem; white-space: nowrap; user-select: none;
}
.lang > summary::-webkit-details-marker { display: none; }
.lang > summary:hover { border-color: var(--line-strong); }
.lang > summary svg { width: 17px; height: 17px; color: var(--ink-2); }
.lang[open] > summary { border-color: var(--ink); }
.lang__menu {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 50; min-width: 168px;
  margin: 0; padding: 6px; list-style: none; background: var(--panel);
  border: 1px solid var(--line); border-radius: 14px; box-shadow: 0 12px 32px -12px rgba(20, 26, 33, .28);
}
.lang__menu a { display: flex; justify-content: space-between; align-items: center; padding: 9px 12px; border-radius: 9px; color: var(--ink); text-decoration: none; font-weight: 500; }
.lang__menu a:hover { background: var(--panel-2); }
.lang__menu a[aria-current="true"] { background: var(--panel-2); }
.lang__menu a[aria-current="true"]::after { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); }

/* ---------- Chinese typography: Barlow for Latin and digits, the system CJK face for characters ---------- */
:lang(zh) {
  --font: "Barlow", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", "Noto Sans CJK SC", "Source Han Sans SC", system-ui, sans-serif;
  --font-cond: "Barlow Condensed", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", "Noto Sans CJK SC", system-ui, sans-serif;
}
:lang(zh) body { line-height: 1.7; }
:lang(zh) .hero__title, :lang(zh) .page-title, :lang(zh) .directory__head h2 { letter-spacing: 0; font-weight: 600; }
:lang(zh) .hero__title { font-size: clamp(3rem, 7.5vw, 5.5rem); line-height: 1.05; }
:lang(zh) .page-title { font-size: clamp(2.125rem, 4.6vw, 3.25rem); line-height: 1.15; }
:lang(zh) .prose { max-width: 40em; }
:lang(zh) .display__label, :lang(zh) .figure__label { letter-spacing: .01em; }

/* Brand name on narrow screens: one line, condensed, so the header controls keep their room */
.brand { white-space: nowrap; min-width: 0; }
.brand__key, .lang > summary svg { flex: none; }
@media (max-width: 480px) {
  .brand { font-family: var(--font-cond); font-size: 1.1875rem; letter-spacing: 0; gap: 8px; }
  .brand__key { width: 26px; height: 26px; }
}
@media (max-width: 374px) {
  .brand { font-size: 1.0625rem; }
  .lang > summary svg { display: none; }
}
