:root {
  --bg: #faf7f2;
  --card: #ffffff;
  --ink: #2f3b35;
  --muted: #66746c;
  --line: #dde4df;
  --accent: #4f7a55;
  --accent-soft: #e4eee5;
  --warn: #b65c5c;
  --radius: 14px;
  color-scheme: light;
}
/* Dark: follows the device unless the theme button picked light; the button can also force dark. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #161b18;
    --card: #1f2622;
    --ink: #e7ece8;
    --muted: #a3b0a8;
    --line: #34403a;
    --accent: #8fc196;
    --accent-soft: #263a2b;
    --warn: #e39494;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #161b18;
  --card: #1f2622;
  --ink: #e7ece8;
  --muted: #a3b0a8;
  --line: #34403a;
  --accent: #8fc196;
  --accent-soft: #263a2b;
  --warn: #e39494;
  color-scheme: dark;
}
.theme-toggle {
  flex: none;
  width: 38px;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--bg);
  color: var(--ink);
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
}
.theme-toggle:hover { border-color: var(--accent); }
.theme-toggle .icon-sun { display: none; }
:root[data-theme="dark"] .theme-toggle .icon-sun { display: inline; }
:root[data-theme="dark"] .theme-toggle .icon-moon { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-toggle .icon-sun { display: inline; }
  :root:not([data-theme="light"]) .theme-toggle .icon-moon { display: none; }
}
* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 17px/1.6 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--accent); }
.wrap { max-width: 1120px; margin: 0 auto; padding: 0 16px; }
.layout { display: grid; grid-template-columns: 220px minmax(0, 1fr); gap: 40px; align-items: start; }
.layout main { max-width: 820px; }
.side { position: sticky; top: 0; max-height: 100vh; overflow-y: auto; padding: 24px 0; }
.side-list h2 {
  margin: 18px 0 6px;
  padding: 0 10px;
  font-size: .74rem;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--muted);
}
.side-list h2:first-child { margin-top: 8px; }
.side-list a {
  display: block;
  padding: 6px 10px;
  border-radius: 8px;
  color: var(--ink);
  font-size: .93rem;
  text-decoration: none;
}
.side-list a:hover { background: var(--accent-soft); }
.side-list a[aria-current="page"] { background: var(--accent-soft); color: var(--accent); font-weight: 700; }
.side-toggle { display: none; }
@media (max-width: 860px) {
  .layout { grid-template-columns: minmax(0, 1fr); gap: 0; }
  .side { position: static; max-height: none; overflow: visible; padding: 16px 0 0; }
  .side-toggle {
    display: flex;
    justify-content: space-between;
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: var(--card);
    color: var(--ink);
    font: inherit;
    font-weight: 600;
    cursor: pointer;
  }
  .side-list { display: none; margin-top: 8px; padding: 4px 8px 10px; border: 1px solid var(--line); border-radius: 10px; background: var(--card); }
  .side.open .side-list { display: block; }
  .side.open .side-toggle span { display: inline-block; transform: rotate(180deg); }
}
header.site { border-bottom: 1px solid var(--line); background: var(--card); }
header.site .wrap { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding-top: 12px; padding-bottom: 12px; }
header.site nav { margin-left: auto; }
.brand { font-weight: 800; font-size: 1.2rem; text-decoration: none; color: var(--ink); }
.brand span { color: var(--accent); }
header.site nav a { margin-left: 16px; text-decoration: none; color: var(--muted); font-size: .95rem; }
.crumbs { margin-top: 20px; font-size: .9rem; color: var(--muted); }
.crumbs + h1 { margin-top: 8px; }
h1 { font-size: clamp(1.7rem, 4vw, 2.3rem); line-height: 1.2; margin: 32px 0 8px; }
.lead { color: var(--muted); margin-top: 0; }
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 22px;
  margin: 24px 0;
}
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 14px; }
label { display: block; font-weight: 600; font-size: .92rem; margin-bottom: 6px; }
input, select {
  width: 100%;
  font: inherit;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
  color: var(--ink);
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.check { display: flex; gap: 8px; align-items: center; font-weight: 400; }
.check input { width: auto; }
.result {
  margin-top: 20px;
  padding: 18px;
  background: var(--accent-soft);
  border-radius: 12px;
}
.result .big { font-size: 1.9rem; font-weight: 800; color: var(--accent); line-height: 1.2; }
.result p { margin: 6px 0 0; }
.result .warn { color: var(--warn); }
.mini + .mini { border-top: 1px solid var(--line); margin-top: 18px; padding-top: 18px; }
.mini .row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.mini .row input { width: 110px; }
.mini .answer { font-weight: 800; color: var(--accent); }
table { width: 100%; border-collapse: collapse; font-size: .95rem; }
th, td { text-align: right; padding: 6px 8px; border-bottom: 1px solid var(--line); }
th:first-child, td:first-child { text-align: left; }
.table-scroll { overflow-x: auto; }
article h2 { margin-top: 36px; font-size: 1.35rem; }
article h3 { font-size: 1.05rem; margin-bottom: 4px; }
.tools { list-style: none; padding: 0; display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 14px; }
.tools a {
  display: block;
  height: 100%;
  padding: 18px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  text-decoration: none;
  color: var(--ink);
}
.tools a:hover { border-color: var(--accent); }
.tools strong { display: block; color: var(--accent); margin-bottom: 4px; }
.tools span { color: var(--muted); font-size: .93rem; }
.promo { border-left: 4px solid var(--accent); }
.speed-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.speed-box { display: flex; flex-direction: column; align-items: center; padding: 16px 8px; border: 1px solid var(--line); border-radius: 12px; background: var(--bg); }
.speed-box span { font-size: .85rem; color: var(--muted); font-weight: 600; }
.speed-box b { font-size: clamp(1.6rem, 6vw, 2.4rem); line-height: 1.2; color: var(--accent); }
.speed-box small { color: var(--muted); }
.start { margin-top: 16px; width: 100%; padding: 14px; border: 0; border-radius: 12px; background: var(--accent); color: #fff; font: inherit; font-weight: 700; font-size: 1.05rem; cursor: pointer; }
.start:disabled { opacity: .6; cursor: wait; }
.ad { position: relative; margin: 24px 0; padding-top: 18px; min-height: 120px; }
.ad-label { position: absolute; top: 0; left: 0; font-size: .7rem; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
footer.site { margin-top: 56px; padding: 28px 0; border-top: 1px solid var(--line); color: var(--muted); font-size: .9rem; }
footer.site a { color: var(--muted); margin-right: 14px; }
@media (max-width: 520px) {
  header.site nav a:not(:last-child) { display: none; }
  .card { padding: 16px; }
}
