:root {
  --bg: #f7f6f3;
  --surface: #ffffff;
  --surface-2: #f0eee9;
  --text: #1d1c1a;
  --text-2: #55524c;
  --muted: #7a766e;
  --border: #e3e0d9;
  --accent: #0f766e;
  --accent-ink: #ffffff;
  --accent-soft: #e0f2ef;
  --focus: #2563eb;
  --teal: #0f766e;   --teal-soft: #ddf1ee;
  --amber: #b45309;  --amber-soft: #fbeedc;
  --purple: #6d28d9; --purple-soft: #ede7fb;
  --coral: #c2410c;  --coral-soft: #fde8de;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 4px 16px rgba(0,0,0,.04);
  --radius: 14px;
  --maxw: 1120px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #141413; --surface: #1d1c1a; --surface-2: #262522; --text: #f1efe9; --text-2: #c4c0b6; --muted: #9a958b;
    --border: #34322e; --accent: #2dd4bf; --accent-ink: #0b1f1d; --accent-soft: #173330;
    --teal: #2dd4bf; --teal-soft: #173330; --amber: #fbbf24; --amber-soft: #3a2e14;
    --purple: #a78bfa; --purple-soft: #2b2342; --coral: #fb923c; --coral-soft: #3b2418;
    --shadow: none; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #141413; --surface: #1d1c1a; --surface-2: #262522; --text: #f1efe9; --text-2: #c4c0b6; --muted: #9a958b;
  --border: #34322e; --accent: #2dd4bf; --accent-ink: #0b1f1d; --accent-soft: #173330;
  --teal: #2dd4bf; --teal-soft: #173330; --amber: #fbbf24; --amber-soft: #3a2e14;
  --purple: #a78bfa; --purple-soft: #2b2342; --coral: #fb923c; --coral-soft: #3b2418;
  --shadow: none; color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.6 system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
a { color: var(--accent); text-underline-offset: 2px; }
a:hover { text-decoration-thickness: 2px; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 6px; }
img, svg { max-width: 100%; }
h1, h2, h3 { line-height: 1.25; margin: 0 0 .5em; letter-spacing: -0.01em; }
h1 { font-size: clamp(1.7rem, 4vw, 2.4rem); }
h2 { font-size: 1.4rem; margin-top: 1.6em; }
h3 { font-size: 1.1rem; margin-top: 1.2em; }
p { margin: 0 0 1em; }
.wrap { max-width: var(--maxw); margin: 0 auto; padding: 0 16px; }
.skip { position: absolute; left: -999px; }
.skip:focus { left: 16px; top: 8px; background: var(--surface); padding: 8px 12px; z-index: 100; }

/* header */
.site-header { background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 20; }
.hdr { display: flex; align-items: center; gap: 16px; height: 64px; }
.logo { display: flex; align-items: center; gap: 10px; font-weight: 700; color: var(--text); text-decoration: none; font-size: 1.1rem; white-space: nowrap; }
.logo svg { width: 32px; height: 32px; flex: none; }
.logo b { color: var(--accent); font-weight: 700; }
.main-nav { display: flex; gap: 4px; }
.main-nav a { color: var(--text-2); text-decoration: none; padding: 8px 12px; border-radius: 10px; font-size: .95rem; white-space: nowrap; }
.main-nav a:hover, .main-nav a[aria-current] { background: var(--surface-2); color: var(--text); }
.hdr-search { margin-left: auto; flex: 0 1 300px; }
.icon-btn { background: none; border: 1px solid var(--border); color: var(--text-2); width: 40px; height: 40px; border-radius: 10px; display: grid; place-items: center; cursor: pointer; flex: none; }
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn svg { width: 20px; height: 20px; }
#menu-toggle { display: none; }
@media (max-width: 860px) {
  .main-nav { display: none; position: absolute; top: 64px; left: 0; right: 0; background: var(--surface); border-bottom: 1px solid var(--border); flex-direction: column; padding: 8px 16px 16px; }
  .nav-open .main-nav { display: flex; }
  #menu-toggle { display: grid; }
  .hdr-search { flex: 1 1 auto; }
  .logo span { display: none; }
}

/* search */
.search { position: relative; }
.search input {
  width: 100%; height: 40px; border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
  border-radius: 10px; padding: 0 12px 0 36px; font: inherit; font-size: .95rem;
}
.search input:focus { background: var(--surface); border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px var(--accent-soft); }
.search .s-ico { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); width: 16px; height: 16px; color: var(--muted); pointer-events: none; }
.search-results { position: absolute; top: calc(100% + 6px); left: 0; right: 0; min-width: 260px; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; box-shadow: 0 8px 30px rgba(0,0,0,.12); list-style: none; margin: 0; padding: 6px; z-index: 30; }
.search-results a { display: flex; justify-content: space-between; gap: 12px; padding: 8px 10px; border-radius: 8px; text-decoration: none; color: var(--text); }
.search-results a:hover, .search-results a.active { background: var(--surface-2); }
.sr-c { color: var(--muted); font-size: .8rem; white-space: nowrap; }
.sr-none { padding: 8px 10px; color: var(--muted); }
.search.big input { height: 56px; font-size: 1.1rem; border-radius: 14px; padding-left: 46px; background: var(--surface); box-shadow: var(--shadow); }
.search.big .s-ico { left: 16px; width: 20px; height: 20px; }

/* hero */
.hero { padding: 48px 0 24px; text-align: center; }
.hero p { color: var(--text-2); font-size: 1.1rem; max-width: 640px; margin: 0 auto 24px; }
.hero .search { max-width: 560px; margin: 0 auto; text-align: left; }

/* cards */
.grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
.card {
  display: flex; gap: 12px; align-items: flex-start; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; text-decoration: none; color: var(--text); box-shadow: var(--shadow); transition: border-color .15s, transform .15s;
}
.card:hover { border-color: var(--c, var(--accent)); transform: translateY(-1px); }
.card .ic { width: 40px; height: 40px; border-radius: 10px; display: grid; place-items: center; background: var(--cs, var(--accent-soft)); color: var(--c, var(--accent)); flex: none; }
.card .ic svg { width: 22px; height: 22px; }
.card h3 { margin: 0 0 2px; font-size: 1rem; }
.card p { margin: 0; color: var(--text-2); font-size: .9rem; line-height: 1.45; }
.c-teal { --c: var(--teal); --cs: var(--teal-soft); }
.c-amber { --c: var(--amber); --cs: var(--amber-soft); }
.c-purple { --c: var(--purple); --cs: var(--purple-soft); }
.c-coral { --c: var(--coral); --cs: var(--coral-soft); }

.cat-cards { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); margin: 8px 0 8px; }
.cat-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); border-top: 4px solid var(--c); }
.cat-card h2 { margin: 0 0 6px; font-size: 1.2rem; display: flex; gap: 10px; align-items: center; }
.cat-card h2 a { color: var(--text); text-decoration: none; }
.cat-card h2 svg { width: 22px; height: 22px; color: var(--c); }
.cat-card p { color: var(--text-2); font-size: .92rem; }
.cat-card ul { list-style: none; padding: 0; margin: 0 0 12px; }
.cat-card li { padding: 3px 0; }
.cat-card li a { color: var(--text); text-decoration: none; }
.cat-card li a:hover { color: var(--c); text-decoration: underline; }
.more { font-weight: 600; text-decoration: none; color: var(--c, var(--accent)); }

.section { margin: 40px 0; }
.section > h2 { margin-top: 0; }

/* breadcrumbs */
.crumbs { font-size: .88rem; color: var(--muted); margin: 20px 0 12px; }
.crumbs a { color: var(--text-2); text-decoration: none; }
.crumbs a:hover { text-decoration: underline; }
.crumbs span[aria-hidden] { margin: 0 6px; }

/* tool page */
.page-head { margin-bottom: 18px; }
.page-head .lead { color: var(--text-2); font-size: 1.1rem; max-width: 760px; margin: 0; }
.tool-layout { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 28px; align-items: start; }
@media (max-width: 980px) { .tool-layout { grid-template-columns: minmax(0, 1fr); } .sidebar { display: none; } }
.tool { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); }
.tool-bar { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.tool-bar h2 { margin: 0; font-size: 1rem; color: var(--text-2); font-weight: 600; }
.unit-toggle { display: inline-flex; background: var(--surface-2); border-radius: 10px; padding: 3px; }
.unit-toggle button { border: 0; background: none; padding: 6px 12px; border-radius: 8px; font: inherit; font-size: .88rem; color: var(--text-2); cursor: pointer; }
.unit-toggle button[aria-pressed="true"] { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.12); font-weight: 600; }
.fields { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 14px 16px; }
.field { display: flex; flex-direction: column; gap: 5px; }
.field[hidden] { display: none; }
.field .lbl { font-size: .9rem; font-weight: 600; color: var(--text-2); }
.field .help { color: var(--muted); font-size: .8rem; line-height: 1.35; }
.inp { display: flex; align-items: stretch; border: 1px solid var(--border); border-radius: 10px; background: var(--bg); overflow: hidden; }
.inp:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.inp input { flex: 1; min-width: 0; border: 0; background: none; padding: 10px 12px; font: inherit; color: var(--text); }
.inp input:focus { outline: none; }
.inp .unit { padding: 0 12px; display: grid; place-items: center; color: var(--muted); background: var(--surface-2); font-size: .88rem; white-space: nowrap; }
select, .field textarea, .txt { border: 1px solid var(--border); border-radius: 10px; background: var(--bg); color: var(--text); padding: 10px 12px; font: inherit; width: 100%; }
.field textarea { min-height: 160px; resize: vertical; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .9rem; }
select:focus, textarea:focus, .txt:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px var(--accent-soft); }

.results { margin-top: 18px; display: grid; gap: 8px; min-height: 80px; }
.result { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; padding: 10px 14px; border-radius: 10px; background: var(--surface-2); }
.result .r-label { color: var(--text-2); font-size: .92rem; }
.result .r-value { font-weight: 700; font-variant-numeric: tabular-nums; text-align: right; }
.result .r-unit { color: var(--text-2); font-weight: 500; font-size: .9rem; }
.result.primary { background: var(--accent-soft); }
.result.primary .r-value { font-size: 1.5rem; color: var(--accent); }
.notes { margin: 4px 0 0; padding-left: 18px; color: var(--text-2); font-size: .88rem; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--border); background: var(--surface); color: var(--text); padding: 8px 14px; border-radius: 10px; font: inherit; font-size: .92rem; cursor: pointer; text-decoration: none; }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
.btn.primary:hover { filter: brightness(1.07); }
.btn svg { width: 16px; height: 16px; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }

.content { max-width: 760px; }
.content ul, .content ol { padding-left: 22px; }
.content li { margin: 4px 0; }
.formula { background: var(--surface-2); border-radius: 10px; padding: 12px 14px; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .9rem; overflow-x: auto; }
.faq details { border-bottom: 1px solid var(--border); padding: 12px 0; }
.faq summary { cursor: pointer; font-weight: 600; }
.faq details p { margin: 8px 0 0; color: var(--text-2); }
.related { margin-top: 32px; }
.sidebar { position: sticky; top: 84px; display: grid; gap: 16px; }
.side-box { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; }
.side-box h2 { font-size: .95rem; margin: 0 0 8px; }
.side-box ul { list-style: none; padding: 0; margin: 0; }
.side-box li { padding: 4px 0; font-size: .92rem; }
.side-box a { color: var(--text); text-decoration: none; }
.side-box a:hover { color: var(--accent); text-decoration: underline; }

/* ads */
.ad { margin: 24px 0; min-height: 280px; display: block; text-align: center; }
.ad::before { content: "Advertisement"; display: block; font-size: .7rem; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; margin-bottom: 4px; }
.sidebar .ad { min-height: 600px; margin: 0; }

/* group headings on category pages */
.group { margin: 28px 0; }
.group h2 { font-size: 1.15rem; margin: 0 0 12px; }

/* custom tool widgets */
.row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 999px; background: var(--surface-2); font-size: .85rem; }
.big-num { font-size: 3rem; font-weight: 800; color: var(--accent); line-height: 1; font-variant-numeric: tabular-nums; }
.list-plain { list-style: none; padding: 0; margin: 0; }
table.data { width: 100%; border-collapse: collapse; font-size: .92rem; }
table.data th, table.data td { padding: 8px 10px; border-bottom: 1px solid var(--border); text-align: left; }
table.data th { color: var(--text-2); font-weight: 600; }
.preview { width: 100%; height: 520px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface-2); margin-top: 16px; }
@media (max-width: 600px) { .preview { height: 380px; } }

/* footer */
.site-footer { margin-top: 64px; background: var(--surface); border-top: 1px solid var(--border); padding: 32px 0 24px; font-size: .92rem; color: var(--text-2); }
.ftr { display: grid; gap: 24px; grid-template-columns: 2fr 1fr 1fr 1fr; }
@media (max-width: 760px) { .ftr { grid-template-columns: 1fr 1fr; } .ftr > div:first-child { grid-column: 1 / -1; } }
.ftr h2 { font-size: .9rem; margin: 0 0 8px; color: var(--text); }
.ftr ul { list-style: none; padding: 0; margin: 0; }
.ftr li { padding: 3px 0; }
.ftr a { color: var(--text-2); text-decoration: none; }
.ftr a:hover { color: var(--text); text-decoration: underline; }
.copy { margin-top: 24px; font-size: .82rem; color: var(--muted); }

#toast { position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; opacity: 0; transition: .2s; pointer-events: none; z-index: 50; font-size: .92rem; }
#toast.show { opacity: 1; transform: translate(-50%, 0); }

@media print {
  .site-header, .site-footer, .sidebar, .ad, .actions, .unit-toggle, .related, .crumbs, .faq, .no-print { display: none !important; }
  body { background: #fff; color: #000; }
  .tool { border: 0; box-shadow: none; padding: 0; }
  .tool-layout { display: block; }
}
