:root {
  color-scheme: light dark;
  --bg: #f3f5f2;
  --surface: #ffffff;
  --ink: #17201a;
  --muted: #4c5a50;
  --line: #ccd5ce;
  --accent: #1f6b3a;
  --accent-ink: #ffffff;
  --error: #a3211b;
  --ok-bg: #e3f2e7;
  --warn-bg: #fdf1d3;
  --bad-bg: #fbe1de;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111612;
    --surface: #1a221c;
    --ink: #edf3ee;
    --muted: #a9b6ac;
    --line: #34413a;
    --accent: #7fd39b;
    --accent-ink: #111612;
    --error: #ff9a92;
    --ok-bg: #1d3825;
    --warn-bg: #3d3216;
    --bad-bg: #44201d;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 17px/1.55 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

a { color: var(--accent); }
.wrap { max-width: 1040px; margin: 0 auto; padding: 0 16px; }

.site-header { padding: 16px 0; }
.logo { color: var(--ink); font-weight: 750; letter-spacing: -0.01em; text-decoration: none; display: inline-flex; gap: 8px; align-items: center; min-height: 44px; }

h1 { font-size: clamp(30px, 6vw, 44px); line-height: 1.1; letter-spacing: -0.02em; margin: 8px 0 12px; }
h2 { font-size: 24px; line-height: 1.2; margin: 40px 0 10px; letter-spacing: -0.01em; }
h3 { font-size: 18px; margin: 24px 0 4px; }
.lead { color: var(--muted); max-width: 64ch; margin: 0 0 20px; }

/* Инструмент */
.tool { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 20px; display: grid; gap: 20px; min-width: 0; }
.tool h2 { margin: 0 0 14px; }
.tool form { min-width: 0; }
.tool .disclaimer { grid-column: 1 / -1; border-top: 1px solid var(--line); padding-top: 12px; margin: 0; }

.choice { border: 0; padding: 0; margin: 0 0 14px; display: grid; gap: 6px; min-width: 0; }
.choice-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.choice-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.choice legend { font-size: 15px; font-weight: 600; margin-bottom: 4px; padding: 0; }
.choice label { display: block; }
.choice input { position: absolute; opacity: 0; }
.choice span { display: flex; min-height: 44px; height: 100%; align-items: center; justify-content: center; text-align: center; padding: 4px 8px; border: 1px solid var(--line); border-radius: 6px; font-weight: 600; font-size: 15px; line-height: 1.2; cursor: pointer; }
.choice input:checked + span { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.choice input:focus-visible + span { outline: 3px solid var(--ink); outline-offset: 1px; }
.choice .choice-hint { grid-column: 1 / -1; }

.fields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin-bottom: 12px; align-items: start; }
.fields .choice { margin: 0; }
.field { min-width: 0; }
.field label { display: block; font-size: 15px; font-weight: 600; margin-bottom: 4px; }
input[type="text"], select { width: 100%; min-height: 44px; padding: 8px 10px; font: inherit; color: var(--ink); background: var(--bg); border: 1px solid var(--line); border-radius: 6px; font-variant-numeric: tabular-nums; }
input::placeholder { color: var(--muted); opacity: 0.7; }
input[aria-invalid="true"], select[aria-invalid="true"] { border-color: var(--error); }
input:focus-visible, select:focus-visible { outline: 3px solid var(--accent); outline-offset: 1px; }
.error { display: block; color: var(--error); font-size: 14px; margin: 4px 0 0; }

.presets { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.preset { min-width: 44px; padding: 4px 8px; font-size: 14px; font-weight: 600; color: var(--accent); background: none; border: 1px solid var(--line); }
.check { display: flex; gap: 10px; align-items: flex-start; margin: 0 0 14px; font-size: 15px; font-weight: 600; }
.check input { width: 22px; height: 22px; margin: 2px 0 0; flex: none; accent-color: var(--accent); }

.output { border-top: 1px solid var(--line); padding-top: 18px; min-width: 0; }
.hint { color: var(--muted); margin: 0; }
.tool-error { font-size: 16px; font-weight: 600; }
.banner { margin: 0 0 14px; padding: 10px 12px; border-radius: 6px; font-weight: 700; background: var(--ok-bg); }
.banner[data-level="warn"] { background: var(--warn-bg); }
.banner[data-level="bad"] { background: var(--bad-bg); }
.warnings { margin: 0 0 14px; padding-left: 20px; color: var(--error); font-weight: 700; }
.results { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px 16px; margin: 0 0 16px; }
.results dt { font-size: 14px; font-weight: 600; color: var(--muted); }
.results dd { margin: 0; font-size: 22px; font-weight: 750; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.results [data-row="smallest"], .results [data-row="maxLength"] { grid-column: 1 / -1; }
.results [data-row="smallest"] dd, .results [data-row="maxLength"] dd { font-size: 18px; }
.small { color: var(--muted); font-size: 14px; margin: 4px 0 0; }

@media (min-width: 760px) {
  .tool { grid-template-columns: 1fr 1fr; align-items: start; }
  .tool .output { border-top: 0; border-left: 1px solid var(--line); padding: 0 0 0 24px; min-height: 100%; }
}

button { font: inherit; min-height: 44px; border-radius: 6px; cursor: pointer; }
button:focus-visible { outline: 3px solid var(--ink); outline-offset: 2px; }
.secondary { padding: 8px 18px; font-weight: 700; color: var(--accent); background: transparent; border: 2px solid var(--accent); }

/* Статьи */
.table-scroll { overflow-x: auto; margin: 12px 0; }
table { border-collapse: collapse; width: 100%; background: var(--surface); font-variant-numeric: tabular-nums; }
.table-scroll th, .table-scroll td { border: 1px solid var(--line); padding: 8px 10px; text-align: left; }
caption { text-align: left; color: var(--muted); font-size: 15px; padding-bottom: 6px; }
.formula { background: var(--surface); border-left: 4px solid var(--accent); padding: 10px 14px; margin: 10px 0; overflow-wrap: anywhere; }
.related { padding-left: 20px; }
.related li { margin: 6px 0; }
.legal { max-width: 70ch; }

.site-footer { margin-top: 56px; padding: 20px 0 32px; border-top: 1px solid var(--line); color: var(--muted); font-size: 14px; }
.footer-row { display: grid; gap: 8px; }
.footer-note { margin: 0; max-width: 80ch; }
.site-footer nav { display: flex; flex-wrap: wrap; gap: 0 16px; }
.site-footer a { display: inline-block; padding: 10px 0; }

/* Печать (window.print): заголовок, введённые значения, результат и примечание; без статьи и навигации */
@page { size: letter portrait; margin: 0.5in; }

@media print {
  :root { --bg: #ffffff; --surface: #ffffff; --ink: #000000; --muted: #333333; --line: #777777; --accent: #000000; --ok-bg: #ffffff; --warn-bg: #ffffff; --bad-bg: #ffffff; }
  body { font-size: 10pt; }
  .site-header, .site-footer, .print-button, .presets, .tool noscript { display: none !important; }
  .tool-page > :not(h1):not(.tool) { display: none !important; }
  .tool { display: block; border: 0; padding: 0; }
  .tool .output { border: 0; padding: 12pt 0 0; }
  .choice input:not(:checked) + span { display: none; }
  .choice span { justify-content: flex-start; border: 0; padding: 0; min-height: 0; }
  .choice input:checked + span { background: none; color: #000; }
  input[type="text"], select { border: 0; padding: 0; min-height: 0; background: none; appearance: none; }
  .banner { border: 1px solid #000; }
}
