/* Hesabla v4. Neutral greys, one accent (pomegranate), one bold element:
   the main result figure in a solid accent block. Everything else is quiet:
   hairlines instead of shadows, small radii that differ by role. */

@font-face {
  font-family: "Geologica";
  src: url("/fonts/geologica-latin-wght.woff2") format("woff2");
  font-weight: 100 900;
  font-display: swap;
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Geologica";
  src: url("/fonts/geologica-latin-ext-wght.woff2") format("woff2");
  font-weight: 100 900;
  font-display: swap;
  unicode-range: U+0100-02AF, U+0304, U+0308, U+0329, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

:root {
  color-scheme: light;
  --page: #f4f4f5;
  --surface: #ffffff;
  --sunk: #ececee;
  --ink: #16181b;
  --muted: #61666d;
  --line: #e4e5e7;
  --line-strong: #c9cbcf;
  --accent: #b5173a;
  --accent-ink: #ffffff;
  --accent-text: #a3122f;
  --warn-ink: #7a4a00;
  --warn-bg: #fff4dc;
  --up: #1d7a3e;
  --down: #b42318;
  --focus: #1a73e8;
  --tabbar-h: 0px;
  --r-input: 8px;
  --r-block: 12px;
  --r-sheet: 16px;
  --font: "Geologica", system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", Arial, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #111214; --surface: #1a1b1e; --sunk: #232428; --ink: #ececee; --muted: #a2a6ac;
    --line: #2a2c30; --line-strong: #3d4045; --accent: #b5173a; --accent-ink: #ffffff; --accent-text: #ff7d96;
    --warn-ink: #ffd27a; --warn-bg: #3a2b0c; --up: #6fd393; --down: #ff8f84; --focus: #8ab4f8;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #111214; --surface: #1a1b1e; --sunk: #232428; --ink: #ececee; --muted: #a2a6ac;
  --line: #2a2c30; --line-strong: #3d4045; --accent: #b5173a; --accent-ink: #ffffff; --accent-text: #ff7d96;
  --warn-ink: #ffd27a; --warn-bg: #3a2b0c; --up: #6fd393; --down: #ff8f84; --focus: #8ab4f8;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; overscroll-behavior-y: none; -webkit-tap-highlight-color: transparent; }
body {
  margin: 0; background: var(--page); color: var(--ink);
  font: 400 16.5px/1.5 var(--font); font-synthesis: none;
  overflow-wrap: break-word;
  padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
}
a { color: var(--accent-text); text-underline-offset: 2px; }
h1, h2, h3 { font-weight: 650; letter-spacing: -0.012em; line-height: 1.2; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
[hidden] { display: none !important; }
.sr, .offscreen { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip { position: absolute; left: 8px; top: -200px; background: var(--surface); padding: 8px 12px; z-index: 20; }
.skip:focus { top: 8px; }
.wrap { max-width: 68rem; margin: 0 auto; padding: 0 max(16px, env(safe-area-inset-right)) 0 max(16px, env(safe-area-inset-left)); }
.ic { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* ---------- top bar ---------- */
.top { background: var(--page); position: sticky; top: 0; z-index: 8; padding-top: env(safe-area-inset-top); border-bottom: 1px solid transparent; }
.top.scrolled { border-bottom-color: var(--line); }
.top-in { display: flex; align-items: center; gap: 4px; min-height: 56px; }
.brand { display: inline-flex; align-items: center; gap: 8px; margin-right: auto; padding: 8px 0; color: var(--ink); text-decoration: none; font-weight: 700; font-size: 1.15rem; letter-spacing: -0.02em; }
.logo { width: 22px; height: 22px; }
.logo-star { fill: var(--accent); }
.logo-eq { stroke: #fff; stroke-width: 2.8; stroke-linecap: round; }
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-width: 44px; min-height: 44px; padding: 0 10px;
  border: 0; border-radius: var(--r-input); background: transparent; color: var(--ink); font: inherit; font-size: 0.95rem; cursor: pointer;
}
.icon-btn:hover { background: var(--sunk); }
.theme-btn[data-mode="dark"] .ic path { fill: currentColor; }

/* ---------- home ---------- */
.home-head { padding: 20px 0 8px; }
.home-head h1 { font-size: clamp(1.6rem, 6vw, 2.2rem); margin: 0 0 4px; letter-spacing: -0.02em; }
.home-head .lead { margin: 0 0 18px; color: var(--muted); max-width: 52ch; }
.search { position: relative; }
.search-ic { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); color: var(--muted); }
.search input {
  width: 100%; min-height: 56px; padding: 0 16px 0 46px; border: 1px solid var(--line-strong); border-radius: var(--r-input);
  background: var(--surface); color: var(--ink); font: inherit; font-size: 1.1rem;
}
.search input:focus { border-color: var(--ink); outline: none; }
.search input:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.search-count { min-height: 1.4em; margin: 8px 0 0; color: var(--muted); font-size: 0.92rem; }

.cat-filter { display: flex; gap: 6px; overflow-x: auto; padding: 4px 16px 10px; margin: 0 -16px; scrollbar-width: none; }
.cat-filter::-webkit-scrollbar { display: none; }
.cat-filter button {
  flex: none; min-height: 40px; padding: 0 14px; border-radius: 20px; border: 1px solid var(--line-strong); background: transparent;
  color: var(--ink); font: inherit; font-size: 0.93rem; cursor: pointer;
}
.cat-filter button[aria-pressed="true"] { background: var(--ink); border-color: var(--ink); color: var(--page); }
@media (min-width: 760px) { .cat-filter { display: none; } }

.list-section { margin: 22px 0 0; }
.list-section h2 { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; font-size: 1.05rem; margin: 0 0 6px; }
.list-section h2 .text-btn { font-size: 0.9rem; }
.rows { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--line); }
@media (min-width: 760px) { .rows { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); column-gap: 32px; } }
@media (min-width: 1040px) { .rows { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
.row { display: flex; align-items: center; border-bottom: 1px solid var(--line); min-height: 52px; }
.row a { flex: 1; min-width: 0; display: flex; align-items: center; min-height: 52px; padding: 0 4px; color: var(--ink); text-decoration: none; font-weight: 500; }
.row a:hover { color: var(--accent-text); }
.pin {
  width: 44px; height: 44px; flex: none; display: grid; place-items: center; border: 0; background: transparent; color: var(--line-strong); cursor: pointer; border-radius: var(--r-input);
}
.pin:hover { color: var(--muted); }
.pin[aria-pressed="true"] { color: var(--accent); }
.pin[aria-pressed="true"] .ic path { fill: currentColor; }
.no-results { padding: 24px 0; color: var(--muted); }
.home-foot-actions { margin-top: 28px; }

/* ---------- tool page ---------- */
.page { padding-bottom: 40px; }
.crumbs { display: flex; gap: 6px; flex-wrap: wrap; font-size: 0.9rem; color: var(--muted); padding: 10px 0 0; }
.crumbs a { color: var(--muted); }
.page-head { display: flex; gap: 8px; align-items: flex-start; margin: 6px 0 18px; }
.page-title { flex: 1; min-width: 0; }
.page-head h1 { font-size: clamp(1.5rem, 5.4vw, 2.15rem); margin: 2px 0 4px; letter-spacing: -0.02em; }
.page-head .lead { margin: 0; color: var(--muted); max-width: 60ch; }
.page-head .pin { margin-top: 2px; border: 1px solid var(--line); }
.tool { min-height: 360px; }
.tool-grid { display: grid; gap: 16px; grid-template-columns: minmax(0, 1fr); align-items: start; }
@media (min-width: 900px) {
  .tool-grid { grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr); gap: 28px; }
  .tool-grid .result { position: sticky; top: 72px; }
}

/* inputs */
.fields {
  display: grid; grid-template-columns: 1fr 1fr; gap: 18px 12px; align-content: start;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-block); padding: 16px;
}
.field { grid-column: 1 / -1; min-width: 0; }
.field.half { grid-column: span 1; }
.lbl { display: block; font-weight: 550; font-size: 0.92rem; margin-bottom: 6px; color: var(--ink); }
.hint { margin: 6px 0 0; color: var(--muted); font-size: 0.86rem; }
.err {
  display: flex; gap: 8px; align-items: flex-start; margin: 8px 0 0; padding: 8px 10px; border-radius: 6px;
  color: var(--warn-ink); background: var(--warn-bg); font-size: 0.9rem; font-weight: 500;
}
.err::before { content: ""; flex: none; width: 16px; height: 16px; margin-top: 2px; background: currentColor;
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M8 1l7 13H1z M7.2 6h1.6v4.2H7.2z M7.2 11.2h1.6v1.6H7.2z' fill-rule='evenodd'/%3E%3C/svg%3E") center / contain no-repeat;
          mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M8 1l7 13H1z M7.2 6h1.6v4.2H7.2z M7.2 11.2h1.6v1.6H7.2z' fill-rule='evenodd'/%3E%3C/svg%3E") center / contain no-repeat; }
.num { display: flex; align-items: stretch; border: 1px solid var(--line-strong); border-radius: var(--r-input); background: var(--surface); overflow: hidden; }
.num:focus-within { border-color: var(--ink); }
.num input {
  flex: 1; min-width: 0; width: 100%; min-height: 50px; padding: 0 12px; border: 0; background: transparent; color: var(--ink);
  font: inherit; font-size: 1.15rem; font-weight: 500; font-variant-numeric: tabular-nums;
}
.num input:focus { outline: none; }
.num:has(input:focus-visible) { outline: 2px solid var(--focus); outline-offset: 2px; }
.suffix { display: flex; align-items: center; padding: 0 12px 0 4px; color: var(--muted); font-size: 0.95rem; white-space: nowrap; }
.step { width: 46px; border: 0; background: transparent; color: var(--ink); font: inherit; font-size: 1.35rem; cursor: pointer; flex: none; }
.step:first-child { border-right: 1px solid var(--line); }
.step:last-of-type { border-left: 1px solid var(--line); }
.step:hover { background: var(--sunk); }
.f-int .num input { text-align: center; }
.num:has([aria-invalid="true"]), [aria-invalid="true"] { border-color: var(--warn-ink); }
input[type="date"], select, textarea {
  width: 100%; min-height: 50px; padding: 10px 12px; border: 1px solid var(--line-strong); border-radius: var(--r-input);
  background: var(--surface); color: var(--ink); font: inherit; font-size: 1.05rem;
}
input[type="date"]:focus, select:focus, textarea:focus { border-color: var(--ink); outline: none; }
input[type="date"]:focus-visible, select:focus-visible, textarea:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
textarea { resize: vertical; line-height: 1.5; min-height: 110px; }
select { appearance: none; padding-right: 34px; background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: right 18px center, right 13px center; background-size: 5px 5px; background-repeat: no-repeat; }
input[type="range"] { width: 100%; margin: 12px 0 0; accent-color: var(--ink); height: 28px; }

.seg { display: grid; grid-template-columns: repeat(var(--n, 2), minmax(0, 1fr)); gap: 2px; padding: 3px; background: var(--sunk); border-radius: var(--r-input); }
.seg[data-n="4"], .seg[data-n="6"] { --n: 2; }
@media (min-width: 560px) { .seg[data-n="4"] { --n: 4; } .seg[data-n="6"] { --n: 3; } }
.f-segment.half .seg[data-n="4"] { --n: 2; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg label { display: flex; align-items: center; justify-content: center; text-align: center; min-height: 44px; padding: 4px 8px; border-radius: 6px; cursor: pointer; font-size: 0.92rem; font-weight: 500; line-height: 1.2; color: var(--muted); }
.seg input:checked + label { background: var(--surface); color: var(--ink); box-shadow: 0 0 0 1px var(--line-strong); font-weight: 600; }
.seg input:focus-visible + label { outline: 2px solid var(--focus); outline-offset: 1px; }

.switch { display: flex; align-items: center; gap: 12px; min-height: 44px; cursor: pointer; font-weight: 500; }
.switch input { position: absolute; opacity: 0; }
.track { width: 44px; height: 26px; border-radius: 13px; background: var(--line-strong); position: relative; flex: none; }
.track::after { content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; transition: transform 0.15s; }
.switch input:checked + .track { background: var(--ink); }
.switch input:checked + .track::after { transform: translateX(18px); }
.switch input:focus-visible + .track { outline: 2px solid var(--focus); outline-offset: 2px; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip-btn { min-height: 44px; padding: 0 14px; border-radius: 22px; border: 1px solid var(--line-strong); background: transparent; color: var(--ink); font: inherit; font-size: 0.93rem; cursor: pointer; }
.chip-btn:active { background: var(--sunk); }
.btn-action, .btn-primary {
  width: 100%; min-height: 50px; border: 0; border-radius: var(--r-input); background: var(--ink); color: var(--page);
  font: inherit; font-weight: 600; font-size: 1rem; cursor: pointer;
}
.btn-ghost {
  width: 100%; min-height: 48px; border-radius: var(--r-input); border: 1px solid var(--line-strong); background: transparent;
  color: var(--ink); font: inherit; font-weight: 550; cursor: pointer;
}
.btn-ghost:hover { background: var(--sunk); }
.btn-ghost.big { min-height: 56px; font-size: 1.05rem; }
.text-btn { border: 0; background: none; padding: 10px 4px; min-height: 44px; color: var(--ink); font: inherit; font-weight: 550; text-decoration: underline; text-decoration-color: var(--line-strong); text-underline-offset: 4px; cursor: pointer; }
.text-btn:hover { text-decoration-color: currentColor; }
.form-tools { grid-column: 1 / -1; display: flex; justify-content: flex-end; margin: -8px 0 -6px; }

/* ---------- result: the one bold element ---------- */
.result { min-width: 0; }
.out-hero { background: var(--accent); color: var(--accent-ink); border-radius: var(--r-block); padding: 16px 18px 18px; }
.out-label { margin: 0 0 4px; font-size: 0.95rem; opacity: 0.9; }
.out-main { margin: 0; font-size: clamp(2.6rem, 12vw, 3.9rem); font-weight: 650; line-height: 1.05; letter-spacing: -0.03em; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.out-main.long { font-size: clamp(1.8rem, 8vw, 2.6rem); }
.out-main .unit { font-size: 0.42em; font-weight: 500; letter-spacing: 0; opacity: 0.9; }
.out-text { margin: 2px 0 0; font-size: 1.25rem; font-weight: 550; line-height: 1.45; white-space: pre-wrap; overflow-wrap: anywhere; max-height: 22rem; overflow: auto; }
.out-text.mono { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; letter-spacing: 0.03em; word-break: break-all; }
.result.is-empty .out-hero { background: var(--surface); color: var(--ink); border: 1px solid var(--line); }
.out-wait { margin: 4px 0 0; color: var(--muted); }
.out-detail { padding: 4px 2px 0; }
.out-sub { margin: 12px 0 0; color: var(--ink); font-weight: 500; }
.out-sub.tone-up { color: var(--up); }
.out-sub.tone-down { color: var(--down); }
.out-rows { margin: 10px 0 0; }
.out-rows > div { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: baseline; gap: 12px; padding: 11px 0; border-bottom: 1px solid var(--line); }
.out-rows dt { color: var(--muted); }
.out-rows dd { margin: 0; font-weight: 550; font-variant-numeric: tabular-nums; text-align: right; }
.out-rows .strong dd { font-weight: 700; }
.out-actions { display: flex; flex-wrap: wrap; gap: 4px 16px; margin-top: 6px; }
.btn-copy, .btn-link { border: 0; background: none; padding: 10px 2px; min-height: 44px; color: var(--ink); font: inherit; font-weight: 550; text-decoration: underline; text-decoration-color: var(--line-strong); text-underline-offset: 4px; cursor: pointer; }
.btn-copy.small { padding: 6px 0; }
.done { color: var(--up) !important; }
.blk-note { margin: 12px 0 0; color: var(--muted); font-size: 0.88rem; }
.blk-text { margin-top: 14px; padding-top: 10px; border-top: 1px solid var(--line); }
.blk-label { margin: 0; color: var(--muted); font-size: 0.9rem; }
.blk-body { margin: 4px 0 4px; font-weight: 550; font-size: 1.05rem; }
.blk-table { margin-top: 14px; border-top: 1px solid var(--line); }
.blk-table summary { cursor: pointer; min-height: 48px; display: flex; align-items: center; gap: 10px; list-style: none; font-weight: 550; }
.blk-table summary::-webkit-details-marker { display: none; }
.blk-table summary::before { content: ""; width: 7px; height: 7px; border-right: 1.5px solid currentColor; border-bottom: 1.5px solid currentColor; transform: rotate(-45deg); flex: none; }
.blk-table[open] summary::before { transform: rotate(45deg); }
.scroll { overflow-x: auto; max-height: 26rem; overflow-y: auto; }
.scroll table, table.plain { border-collapse: collapse; width: 100%; font-size: 0.9rem; font-variant-numeric: tabular-nums; }
.scroll th, .scroll td, table.plain th, table.plain td { padding: 8px 10px; text-align: right; white-space: nowrap; border-bottom: 1px solid var(--line); }
.scroll th, table.plain th { position: sticky; top: 0; background: var(--page); color: var(--muted); font-weight: 500; }
.scroll th:first-child, .scroll td:first-child, table.plain th:first-child, table.plain td:first-child { text-align: left; }
tr.hl td { background: var(--sunk); font-weight: 650; }
.blk-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; max-height: 16rem; overflow: auto; }
.nchip { padding: 4px 10px; border-radius: 6px; background: var(--sunk); font-weight: 600; font-variant-numeric: tabular-nums; }
.blk-scale { margin-top: 16px; }
.scale-bar { position: relative; display: flex; height: 10px; border-radius: 5px; background: var(--sunk); }
.scale-bar > span[class^="seg-"] { height: 100%; background: var(--line-strong); }
.scale-bar > span[class^="seg-"] + span[class^="seg-"] { border-left: 2px solid var(--page); }
.scale-bar > span.active { background: var(--ink); }
.scale-bar > span:first-child { border-radius: 5px 0 0 5px; }
.scale-bar > span:nth-last-child(2) { border-radius: 0 5px 5px 0; }
.marker { position: absolute; top: -6px; width: 4px; height: 22px; margin-left: -2px; border-radius: 2px; background: var(--accent); }
.scale-legend { list-style: none; margin: 10px 0 0; padding: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 4px 12px; font-size: 0.84rem; color: var(--muted); }
.scale-legend li.active { color: var(--ink); font-weight: 650; }
.scale-legend .dot { display: none; }
.blk-svg { margin-top: 14px; }
.blk-svg svg { width: 100%; height: auto; display: block; }
.blk-svg .bar { fill: var(--line-strong); }
.blk-svg .curve { fill: none; stroke: var(--accent); stroke-width: 2; }
.blk-svg .axis { fill: var(--muted); font: 11px var(--font); }
.blk-svg .meanline { stroke: var(--ink); stroke-width: 1; stroke-dasharray: 3 3; }
.legend-line { display: flex; gap: 16px; flex-wrap: wrap; margin: 6px 0 0; font-size: 0.85rem; color: var(--muted); }
.legend-line i { display: inline-block; width: 14px; height: 3px; vertical-align: middle; margin-right: 6px; background: var(--accent); }
.legend-line i.b { height: 10px; background: var(--line-strong); }

/* ---------- explanation, sources, related, footer ---------- */
.explain { max-width: 44rem; margin-top: 40px; }
.explain h2, .related h2, .sources h2 { font-size: 1.2rem; margin: 0 0 6px; }
.explain h3 { font-size: 1.02rem; margin: 22px 0 4px; }
.explain p { margin: 0 0 10px; }
.sources { max-width: 44rem; margin-top: 28px; padding-top: 16px; border-top: 1px solid var(--line); }
.sources ul { list-style: none; margin: 0; padding: 0; }
.sources li { padding: 8px 0; border-bottom: 1px solid var(--line); }
.sources .src-meta { display: block; color: var(--muted); font-size: 0.88rem; }
.related { margin-top: 36px; }
.noscript { padding: 16px; background: var(--warn-bg); color: var(--warn-ink); border-radius: var(--r-input); }
.foot { border-top: 1px solid var(--line); color: var(--muted); font-size: 0.9rem; padding: 18px 0 32px; margin-top: 32px; }
.foot p { margin: 4px 0; }
.foot .text-btn { padding-left: 0; }

/* ---------- sheets (search, pinned, recent, install) ---------- */
dialog.sheet {
  width: min(34rem, calc(100vw - 24px)); max-height: min(80vh, 40rem); padding: 0; border: 1px solid var(--line); border-radius: var(--r-sheet);
  background: var(--surface); color: var(--ink); margin-top: 10vh;
}
dialog.sheet::backdrop { background: rgba(0, 0, 0, 0.4); }
.sheet-head { display: flex; gap: 8px; align-items: center; padding: 10px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--surface); }
.sheet-input { flex: 1; min-width: 0; min-height: 48px; padding: 0 12px; font: inherit; font-size: 1.05rem; border: 1px solid var(--line-strong); border-radius: var(--r-input); background: var(--surface); color: var(--ink); }
.sheet-title { margin: 0 0 0 6px; font-size: 1.05rem; flex: 1; }
.sheet-list { list-style: none; margin: 0; padding: 0 12px 12px; overflow: auto; max-height: calc(min(80vh, 40rem) - 70px); }
.sheet-list .row a { font-weight: 500; }
.empty { padding: 16px 4px; color: var(--muted); margin: 0; }
.sheet-body { padding: 16px 18px 20px; }
.sheet-body h2 { font-size: 1.15rem; margin: 0 0 8px; }
.sheet-body p { margin: 0 0 12px; color: var(--muted); }
.sheet-body ol { margin: 0 0 16px; padding-left: 1.3em; }
.sheet-body li { margin: 6px 0; }
.sheet-body .share-ic { display: inline-block; vertical-align: -4px; width: 20px; height: 20px; }
.sheet-actions { display: grid; gap: 8px; }
@media (max-width: 759px) {
  dialog.sheet { margin: auto 0 0; width: 100vw; max-width: 100vw; max-height: 85vh; border-radius: var(--r-sheet) var(--r-sheet) 0 0; border-width: 1px 0 0; padding-bottom: env(safe-area-inset-bottom); }
  .sheet-list { max-height: calc(85vh - 70px); }
}

/* ---------- phone shell ---------- */
.tabbar { display: none; }
@media (max-width: 759px) { :root { --tabbar-h: 60px; } .tabbar { display: grid; } .top .jump-btn { display: none; } }
.standalone { --tabbar-h: 60px; }
.standalone .tabbar { display: grid; }
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 9; grid-template-columns: repeat(4, 1fr);
  height: calc(60px + env(safe-area-inset-bottom)); padding: 0 env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  background: var(--surface); border-top: 1px solid var(--line);
}
.tab { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; min-height: 60px; min-width: 0; border: 0; background: transparent; color: var(--muted); font: inherit; font-size: 0.72rem; font-weight: 500; text-decoration: none; cursor: pointer; }
.tab .ic { width: 23px; height: 23px; }
.tab span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.home .tab[href="/"] { color: var(--ink); font-weight: 650; }
.peek {
  position: fixed; left: 10px; right: 10px; bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 8px); z-index: 7;
  display: flex; align-items: baseline; justify-content: space-between; gap: 12px; padding: 12px 16px; min-height: 52px;
  border: 0; border-radius: 10px; background: var(--accent); color: var(--accent-ink); font: inherit; text-align: left; cursor: pointer;
}
.peek .pk-label { opacity: 0.9; font-size: 0.86rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.peek .pk-value { font-weight: 650; font-size: 1.15rem; font-variant-numeric: tabular-nums; white-space: nowrap; }
@media (min-width: 900px) { .peek { display: none; } }

/* ---------- calculator, stopwatch, rates, budget, letter ---------- */
.tool-grid.single { grid-template-columns: minmax(0, 1fr); }
@media (min-width: 900px) { .tool-grid.single { grid-template-columns: minmax(0, 26rem) minmax(0, 1fr); } }
.calc { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-block); padding: 12px; }
.calc-screen { background: var(--accent); color: var(--accent-ink); border-radius: var(--r-input); padding: 10px 12px; margin-bottom: 10px; }
.calc-input { width: 100%; min-height: 52px; padding: 4px 0; border: 0; background: transparent; color: inherit; font: inherit; font-size: 1.6rem; font-weight: 600; text-align: right; font-variant-numeric: tabular-nums; }
.calc-input:focus { outline: none; }
.calc-preview { min-height: 1.5em; margin: 0; text-align: right; font-size: 1.15rem; opacity: 0.92; font-variant-numeric: tabular-nums; }
.calc-preview.bad { font-size: 0.95rem; }
.calc-copy { display: flex; justify-content: flex-end; }
.calc-copy .btn-copy { color: #fff; }
.keypad { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.key { min-height: 56px; border: 1px solid var(--line); border-radius: var(--r-input); background: var(--surface); color: var(--ink); font: inherit; font-size: 1.35rem; cursor: pointer; }
.key.digit { background: var(--sunk); border-color: transparent; }
.key:active { background: var(--line); }
.key.eq { grid-column: 1 / -1; background: var(--ink); color: var(--page); border-color: var(--ink); font-weight: 650; }
.calc-side h2 { font-size: 1.1rem; margin: 0 0 6px; }
.calc-history { list-style: none; padding: 0; margin: 0 0 8px; border-top: 1px solid var(--line); }
.hist-item { width: 100%; display: flex; justify-content: space-between; gap: 12px; align-items: baseline; min-height: 48px; padding: 8px 2px; border: 0; border-bottom: 1px solid var(--line); background: none; color: var(--ink); font: inherit; text-align: left; cursor: pointer; }
.hist-expr { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.stopwatch { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-block); padding: 16px; display: grid; gap: 14px; }
.sw-display { margin: 0; text-align: center; font-size: clamp(2.8rem, 15vw, 4.5rem); font-weight: 650; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }
.sw-display.done { color: var(--accent-text); }
.sw-buttons { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.tm-set { display: grid; grid-template-columns: auto 1fr auto 1fr; gap: 8px 10px; align-items: center; }
.tm-set label { font-weight: 550; }
.tm-in { min-height: 50px; width: 100%; padding: 0 10px; border: 1px solid var(--line-strong); border-radius: var(--r-input); background: var(--surface); color: var(--ink); font: inherit; font-size: 1.3rem; text-align: center; }
.tm-presets { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 6px; }
.laps { list-style: none; margin: 0; padding: 0; }
.laps li { display: flex; justify-content: space-between; padding: 10px 2px; border-bottom: 1px solid var(--line); font-variant-numeric: tabular-nums; }
.rates-section { margin-top: 32px; }
.rates-section h2 { font-size: 1.2rem; margin: 0 0 10px; }
.rates-section h3 { font-size: 1.02rem; margin: 22px 0 6px; }
.rates-section input[type="search"] { width: 100%; min-height: 48px; padding: 0 12px; border: 1px solid var(--line-strong); border-radius: var(--r-input); background: var(--surface); color: var(--ink); font: inherit; font-size: 1.05rem; margin-bottom: 8px; }
.table-wrap { overflow-x: auto; }
table.rates { width: 100%; border-collapse: collapse; font-size: 0.95rem; }
table.rates th, table.rates td { padding: 10px 6px; text-align: left; border-bottom: 1px solid var(--line); }
table.rates th { color: var(--muted); font-weight: 500; font-size: 0.86rem; }
table.rates .num-cell { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.budget { display: grid; gap: 20px; }
.budget-group { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-block); padding: 14px; }
.budget-group h2 { font-size: 1.05rem; margin: 0 0 8px; }
.bl-row { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr) auto auto; gap: 6px; align-items: center; padding: 6px 0; border-bottom: 1px solid var(--line); }
.bl-row input, .bl-row select { min-height: 44px; padding: 0 8px; border: 1px solid var(--line-strong); border-radius: 6px; background: var(--surface); color: var(--ink); font: inherit; font-size: 1rem; width: 100%; min-width: 0; }
.bl-row .amt { text-align: right; font-variant-numeric: tabular-nums; }
.bl-row select { width: auto; padding-right: 28px; background-position: right 14px center, right 9px center; }
.bl-del { width: 44px; height: 44px; border: 0; background: none; color: var(--muted); cursor: pointer; border-radius: 6px; font-size: 1.2rem; }
.bl-share { grid-column: 1 / -1; font-size: 0.82rem; color: var(--muted); margin-top: -2px; }
@media (max-width: 480px) { .bl-row { grid-template-columns: minmax(0, 1fr) minmax(0, 7.5rem) auto; } .bl-row select { grid-column: 1 / 3; } }
.letter { white-space: pre-wrap; font-family: var(--font); background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-input); padding: 20px; line-height: 1.6; }
@media print {
  body { background: #fff; padding: 0; }
  body * { visibility: hidden; }
  .letter, .letter * { visibility: visible; }
  .letter { position: absolute; left: 0; top: 0; width: 100%; border: 0; padding: 0; font-size: 12pt; color: #000; }
}

/* ---------- narrow phones ---------- */
@media (max-width: 359px) {
  .fields { padding: 12px; gap: 14px 8px; }
  .field.half { grid-column: 1 / -1; }
  .out-rows > div { grid-template-columns: minmax(0, 1fr); gap: 2px; }
  .out-rows dd { text-align: left; }
  .seg label { font-size: 0.85rem; padding: 4px; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; scroll-behavior: auto !important; } }
