:root {
  --bg: #f5f4f0;
  --surface: #ffffff;
  --ink: #1c232b;
  --muted: #5a6470;
  --line: #e1ddd4;
  --steel: #232b35;
  --steel-2: #2f3945;
  --accent: #e35d12;
  --accent-soft: #fdeee4;
  --ok: #1f7a4d;
  --err: #b42318;
  --radius: 10px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "Cascadia Mono", Consolas, Menlo, monospace;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
/* Always reserve the scrollbar's space so short and long pages have the same width (no header jump) */
html { -webkit-text-size-adjust: 100%; overflow-y: scroll; scrollbar-gutter: stable; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.6 var(--font); }
a { color: #b7470b; }
a:hover { color: var(--accent); }
h1, h2, h3 { line-height: 1.25; letter-spacing: -0.01em; }
h1 { font-size: clamp(1.6rem, 3.6vw, 2.2rem); margin: .2em 0 .35em; }
h2 { font-size: 1.35rem; margin: 1.8em 0 .5em; }
h3 { font-size: 1.08rem; margin: 1.4em 0 .4em; }
code { font-family: var(--mono); font-size: .92em; background: #ece9e2; padding: .08em .35em; border-radius: 4px; }

.wrap { max-width: 1140px; margin: 0 auto; padding: 0 16px; }

/* ---- Header / footer ---- */
.site-header { background: var(--steel); color: #fff; border-bottom: 3px solid var(--accent); }
.header-inner { display: flex; align-items: center; gap: 24px; min-height: 60px; flex-wrap: wrap; padding-top: 8px; padding-bottom: 8px; }
.logo { display: flex; align-items: center; gap: 8px; color: #fff; text-decoration: none; font-size: 1.3rem; font-weight: 600; }
.logo b { color: #ff8a47; font-weight: 800; }
.logo:hover { color: #fff; }
.main-nav { display: flex; gap: 6px 18px; flex-wrap: wrap; }
.main-nav a { color: #d6dbe1; text-decoration: none; font-size: .95rem; }
.main-nav a:hover { color: #fff; }

.site-footer { margin-top: 64px; background: var(--steel); color: #b9c1ca; font-size: .92rem; }
.footer-inner { display: flex; justify-content: space-between; gap: 24px; flex-wrap: wrap; padding-top: 28px; padding-bottom: 12px; }
.footer-inner strong { color: #fff; }
.footer-inner p { margin: .3em 0 0; }
.site-footer nav { display: flex; gap: 8px 18px; flex-wrap: wrap; align-items: flex-start; }
.site-footer a { color: #d6dbe1; text-decoration: none; }
.site-footer a:hover { color: #fff; text-decoration: underline; }
.fine { padding-bottom: 24px; font-size: .82rem; color: #8b95a1; }

/* ---- Home / category ---- */
.hero { padding: 36px 0 8px; max-width: 760px; }
.hero p { color: var(--muted); font-size: 1.08rem; margin: 0; }
.cat-block { margin-top: 32px; }
.cat-head h2 { margin: 0; }
.cat-head h2 a { color: var(--ink); text-decoration: none; }
.cat-head p { margin: .25em 0 0; color: var(--muted); }
.lead { color: var(--muted); font-size: 1.05rem; margin-top: 0; max-width: 760px; }
.prose.lead p { margin: 0 0 .7em; }

/* 1 → 2 → 3 columns, so a 6-tool section always fills complete rows (3+3, 2+2+2) */
.tool-cards { list-style: none; padding: 0; margin: 16px 0 0; display: grid; gap: 12px; grid-template-columns: minmax(0, 1fr); }
@media (min-width: 600px) { .tool-cards { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (min-width: 900px) { .tool-cards { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
.tool-cards a { display: block; height: 100%; padding: 16px 18px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); text-decoration: none; color: var(--ink); border-left: 4px solid var(--accent); transition: border-color .15s, transform .15s; }
.tool-cards a:hover { border-color: var(--accent); transform: translateY(-1px); }
.tool-cards strong { display: block; font-size: 1.02rem; }
.tool-cards span { display: block; color: var(--muted); font-size: .9rem; margin-top: 2px; line-height: 1.45; }

.crumbs { font-size: .88rem; color: var(--muted); margin: 18px 0 0; }
.crumbs a { color: var(--muted); }
.crumbs span { margin: 0 4px; opacity: .6; }

/* ---- Tool layout ---- */
.tool-layout { display: grid; gap: 32px; grid-template-columns: minmax(0, 1fr); }
@media (min-width: 1024px) { .tool-layout { grid-template-columns: minmax(0, 1fr) 300px; } }
.tool-side { display: flex; flex-direction: column; gap: 20px; }
@media (min-width: 1024px) { .tool-side { padding-top: 64px; } }
.side-box h2 { font-size: 1rem; margin: 0 0 4px; }
.side-box .tool-cards { grid-template-columns: 1fr; }

/* ---- Calculator ---- */
.calc { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; overflow: hidden; box-shadow: 0 1px 2px rgba(20,25,30,.04), 0 6px 20px rgba(20,25,30,.05); }
.calc-bar { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 10px 16px; background: #faf9f6; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.calc-bar .hint { font-size: .82rem; color: var(--muted); }
.calc-body { display: grid; grid-template-columns: minmax(0, 1fr); }
@media (min-width: 760px) { .calc-body { grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); } }
.calc-inputs { padding: 18px 16px 20px; display: grid; gap: 14px; grid-template-columns: repeat(2, minmax(0, 1fr)); align-content: start; }
.calc-inputs .full { grid-column: 1 / -1; }

.seg { display: inline-flex; background: #ebe8e1; border-radius: 8px; padding: 3px; }
.seg button { border: 0; background: transparent; font: inherit; font-size: .88rem; padding: 5px 14px; border-radius: 6px; color: var(--muted); cursor: pointer; }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--ink); font-weight: 600; box-shadow: 0 1px 2px rgba(0,0,0,.12); }

.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field[hidden] { display: none; }
.field label { font-size: .86rem; font-weight: 600; color: #39424d; }
.input-wrap { display: flex; align-items: stretch; border: 1px solid #cfcac0; border-radius: 8px; background: #fff; overflow: hidden; }
.input-wrap:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(227,93,18,.15); }
.input-wrap input, .input-wrap select { flex: 1; min-width: 0; border: 0; outline: 0; font: inherit; padding: 9px 10px; background: transparent; color: var(--ink); font-variant-numeric: tabular-nums; }
.input-wrap .unit { display: flex; align-items: center; padding: 0 10px; background: #f3f1ec; color: var(--muted); font-size: .85rem; border-left: 1px solid #e3dfd6; white-space: nowrap; }
.input-wrap select.unit-select { flex: 0 0 auto; background: #f3f1ec; border-left: 1px solid #e3dfd6; color: var(--muted); font-size: .85rem; padding: 0 6px; cursor: pointer; }
select.plain { width: 100%; border: 1px solid #cfcac0; border-radius: 8px; font: inherit; padding: 9px 10px; background: #fff; color: var(--ink); }
select.plain:focus { border-color: var(--accent); outline: 0; box-shadow: 0 0 0 3px rgba(227,93,18,.15); }
.field.invalid .input-wrap { border-color: var(--err); }

.shape-picker { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; }
@media (max-width: 420px) { .shape-picker { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
.shape-picker button { border: 1px solid #d6d1c7; background: #fff; border-radius: 8px; padding: 8px 4px 6px; font: inherit; font-size: .76rem; color: var(--muted); cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 4px; line-height: 1.2; }
.shape-picker button svg { width: 30px; height: 30px; }
.shape-picker button[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-soft); color: var(--ink); font-weight: 600; }

.calc-results { background: var(--steel); color: #fff; padding: 20px 18px; display: flex; flex-direction: column; gap: 14px; }
.result-main .label { font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; color: #aab4bf; }
.result-main .value { font-size: clamp(1.9rem, 5vw, 2.5rem); font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.15; color: #fff; }
.result-main .sub { color: #c9d1d9; font-variant-numeric: tabular-nums; }
.result-list { margin: 0; display: grid; gap: 0; border-top: 1px solid var(--steel-2); }
.result-list div { display: flex; justify-content: space-between; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--steel-2); font-size: .93rem; }
.result-list div[hidden] { display: none; }
.result-list dt { color: #aab4bf; }
.result-list dd { margin: 0; font-weight: 600; text-align: right; font-variant-numeric: tabular-nums; }
.formula { font-family: var(--mono); font-size: .8rem; color: #d5dce3; background: var(--steel-2); border-radius: 8px; padding: 10px 12px; line-height: 1.5; word-break: break-word; }
.formula b { color: #ffb07f; font-weight: 600; }
.calc-error { background: #4a1d1a; color: #ffd7d2; border-radius: 8px; padding: 10px 12px; font-size: .9rem; }
.calc-error[hidden] { display: none; }

.field-hint { font-size: .78rem; color: var(--muted); line-height: 1.35; }
.field-hint a { color: inherit; }
.section-label { grid-column: 1 / -1; font-size: .74rem; font-weight: 700; text-transform: uppercase; letter-spacing: .07em; color: #8a8478; border-top: 1px solid var(--line); padding-top: 12px; margin-top: 2px; }
.check { display: flex; align-items: center; gap: 8px; font-size: .9rem; cursor: pointer; }
.check input { width: 17px; height: 17px; accent-color: var(--accent); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 2px; }
.chips button { border: 1px solid #d6d1c7; background: #fff; border-radius: 999px; padding: 3px 10px; font: inherit; font-size: .8rem; color: var(--muted); cursor: pointer; }
.chips button:hover { border-color: var(--accent); color: var(--ink); }
html:not([data-units="metric"]) [data-show="metric"], html[data-units="metric"] [data-show="imperial"] { display: none !important; }

.result-main .value.small { font-size: clamp(1.4rem, 4vw, 1.8rem); }
.result-note { font-size: .88rem; color: #d5dce3; line-height: 1.45; }
.badge { display: inline-block; font-size: .78rem; font-weight: 700; padding: 3px 10px; border-radius: 999px; letter-spacing: .02em; }
.badge.ok { background: #1d4d37; color: #b6f0d0; }
.badge.warn { background: #5a4310; color: #ffe1a3; }
.badge.bad { background: #5a1d18; color: #ffcdc7; }
.stack { display: flex; height: 10px; border-radius: 99px; overflow: hidden; background: var(--steel-2); }
.stack span { display: block; height: 100%; }
.legend-dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 6px; vertical-align: 0; }
.next-link { display: inline-block; color: #ffb07f; font-weight: 600; font-size: .92rem; text-decoration: none; }
.next-link:hover { color: #fff; text-decoration: underline; }

/* ---- Article ---- */
.prose { max-width: 760px; }
.prose p, .prose li { color: #2c343d; }
.prose table { width: 100%; border-collapse: collapse; margin: 1em 0; font-size: .93rem; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; overflow: hidden; display: block; overflow-x: auto; }
.prose th, .prose td { text-align: left; padding: 8px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; font-variant-numeric: tabular-nums; }
.prose th { background: #f3f1ec; font-weight: 600; }
.prose tr:last-child td { border-bottom: 0; }
.prose .eq { font-family: var(--mono); background: var(--surface); border: 1px solid var(--line); border-left: 4px solid var(--accent); border-radius: 6px; padding: 10px 14px; overflow-x: auto; white-space: nowrap; }
.prose .note { background: var(--accent-soft); border-radius: 8px; padding: 12px 16px; }
.page { padding-top: 12px; }

.faq details { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; margin-bottom: 8px; padding: 0 16px; }
.faq summary { cursor: pointer; font-weight: 600; padding: 12px 0; }
.faq details p { margin: 0 0 14px; }

/* ---- Ads ---- */
.ad { margin: 28px 0; text-align: center; }
/* Reserve space so ads loading in don't shift the page (CLS) */
.ad ins.adsbygoogle { min-height: 280px; }
@media (min-width: 760px) { .ad-below_result ins.adsbygoogle, .ad-in_article ins.adsbygoogle { min-height: 250px; } }
.ad-sidebar ins.adsbygoogle { min-height: 600px; }
@media (min-width: 1024px) { .ad-sidebar { position: sticky; top: 16px; } }
@media (max-width: 1023px) { .ad-sidebar { display: none; } }
.ad-label { display: block; font-size: .7rem; text-transform: uppercase; letter-spacing: .08em; color: #9aa3ad; margin-bottom: 4px; }
.ad-placeholder { border: 2px dashed #cdc7bb; border-radius: 8px; padding: 28px 12px; color: #9a9384; font-size: .85rem; }
.ad-sidebar.ad-placeholder { min-height: 250px; display: flex; align-items: center; justify-content: center; margin: 0; }
