:root {
  --bg: #f7f1e8;
  --panel: #fffdf9;
  --ink: #2b1d14;
  --muted: #7a6656;
  --line: #e4d7c5;
  --accent: #b5651d;
  --gold: #d9a441;
  --gold-fill: rgba(217, 164, 65, .28);
  --zone: rgba(120, 90, 60, .05);
  --zone-alt: rgba(120, 90, 60, .10);
  --ratio: #a08a74;
  --ratio-on: #b5651d;
  --point: #8a2f12;
  --grid: #ece2d4;
  --ok: #3f7d3a;
  --warn: #b5651d;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #17110d;
    --panel: #211913;
    --ink: #f1e6d8;
    --muted: #b09c88;
    --line: #3a2d23;
    --accent: #e0954a;
    --gold: #e5b453;
    --gold-fill: rgba(229, 180, 83, .22);
    --zone: rgba(255, 230, 200, .03);
    --zone-alt: rgba(255, 230, 200, .07);
    --ratio: #7d6a58;
    --ratio-on: #e0954a;
    --point: #ffb27a;
    --grid: #2c221a;
    --ok: #8cc47f;
    --warn: #e0954a;
  }
}
:root[data-theme="dark"] {
  --bg: #17110d;
  --panel: #211913;
  --ink: #f1e6d8;
  --muted: #b09c88;
  --line: #3a2d23;
  --accent: #e0954a;
  --gold: #e5b453;
  --gold-fill: rgba(229, 180, 83, .22);
  --zone: rgba(255, 230, 200, .03);
  --zone-alt: rgba(255, 230, 200, .07);
  --ratio: #7d6a58;
  --ratio-on: #e0954a;
  --point: #ffb27a;
  --grid: #2c221a;
  --ok: #8cc47f;
  --warn: #e0954a;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
.wrap { max-width: 1080px; margin: 0 auto; padding: 0 16px; }

.top { border-bottom: 1px solid var(--line); background: var(--panel); }
.top-in { display: flex; align-items: center; justify-content: space-between; height: 56px; }
.logo { display: flex; align-items: center; gap: 8px; font-weight: 700; color: var(--ink); text-decoration: none; }
.logo svg { width: 26px; height: 26px; fill: var(--gold); color: var(--gold); }
.nav { display: flex; align-items: center; gap: 16px; }
.nav a { color: var(--muted); text-decoration: none; font-size: 15px; }
.nav a:hover { color: var(--ink); }
.theme-btn {
  border: 1px solid var(--line); background: transparent; color: var(--ink);
  width: 34px; height: 34px; border-radius: 50%; font-size: 16px; cursor: pointer;
}

.hero { padding: 28px 0 8px; }
.hero h1 { margin: 0 0 8px; font-size: clamp(26px, 5vw, 38px); line-height: 1.15; }
.hero p { margin: 0; color: var(--muted); max-width: 680px; }

.panel {
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 18px;
}
.calc { display: grid; grid-template-columns: 340px 1fr; gap: 16px; margin: 20px 0; align-items: start; }
@media (max-width: 820px) { .calc { grid-template-columns: 1fr; } }

.seg { display: flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.seg button, .mini-seg button {
  flex: 1; border: 0; background: transparent; color: var(--muted); font: inherit; cursor: pointer;
}
.seg button { padding: 9px 4px; font-size: 15px; }
.seg button + button { border-left: 1px solid var(--line); }
.seg button.on, .mini-seg button.on { background: var(--accent); color: #fff; }

.hint { color: var(--muted); font-size: 14px; margin: 8px 0 4px; }
.hint.small { font-size: 13px; margin-top: 10px; }

.field { display: flex; flex-direction: column; gap: 4px; margin-top: 12px; min-width: 0; }
.field > span { font-size: 14px; color: var(--muted); }
.field input, .field select {
  width: 100%; font: inherit; color: var(--ink); background: var(--bg);
  border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px;
}
.field input:focus, .field select:focus { outline: 2px solid var(--gold); outline-offset: -1px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.row3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; }
.mass-head { display: flex; align-items: center; font-size: 14px; color: var(--muted); }
.mini-seg { display: inline-flex; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.mini-seg button { padding: 1px 7px; font-size: 13px; }

.notes { margin-top: 14px; }
.notes summary { cursor: pointer; color: var(--muted); font-size: 14px; }

.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; }
.btn {
  font: inherit; font-size: 15px; border-radius: 8px; padding: 8px 14px; cursor: pointer;
  background: var(--accent); color: #fff; border: 1px solid var(--accent);
}
.btn.ghost { background: transparent; color: var(--muted); border-color: var(--line); }

.results { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-bottom: 10px; }
@media (max-width: 480px) { .results { grid-template-columns: repeat(2, 1fr); } }
.stat { background: var(--bg); border-radius: 10px; padding: 8px 10px; }
.stat b { display: block; font-size: 20px; font-variant-numeric: tabular-nums; }
.stat span { font-size: 12px; color: var(--muted); }

#chart { width: 100%; height: auto; display: block; }
#chart text { font-family: inherit; }

.verdict { margin-top: 10px; border-left: 4px solid var(--gold); padding: 4px 0 4px 12px; }
.verdict h3 { margin: 0 0 4px; font-size: 18px; }
.verdict p { margin: 4px 0; }
.verdict.in { border-color: var(--ok); }
.verdict.out { border-color: var(--warn); }

.history { margin-bottom: 20px; }
.history h2 { margin: 0 0 8px; font-size: 20px; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; font-variant-numeric: tabular-nums; }
th, td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { color: var(--muted); font-weight: 500; }
td.del { text-align: right; }
td.del button { border: 0; background: none; color: var(--muted); cursor: pointer; font-size: 16px; }

.learn { margin: 28px 0 8px; }
.learn h2 { font-size: 26px; margin: 0 0 12px; }
.learn article { max-width: 720px; margin-bottom: 22px; }
.learn h3 { margin: 0 0 6px; font-size: 19px; }
.learn p, .learn li { color: var(--ink); }
.learn ul { padding-left: 20px; }

.foot { border-top: 1px solid var(--line); color: var(--muted); font-size: 14px; padding: 18px 0 28px; margin-top: 20px; }
