:root {
  color-scheme: light dark;
  --bg: #f6f8f7;
  --surface: #ffffff;
  --ink: #17211d;
  --muted: #4f5d57;
  --line: #d3dcd8;
  --accent: #1d6b4f;
  --accent-ink: #ffffff;
  --error: #a3211b;
  --warn-bg: #fdf1d3;
  --removed-bg: #fbe2df;
  --kept-bg: #fff3c4;
  --code-bg: #eef3f1;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111614;
    --surface: #1a211e;
    --ink: #ecf3ef;
    --muted: #a8b8b0;
    --line: #34413b;
    --accent: #7fd3ad;
    --accent-ink: #0d1a14;
    --error: #ff9a92;
    --warn-bg: #3d3216;
    --removed-bg: #4a2420;
    --kept-bg: #433a14;
    --code-bg: #232c28;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }

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;
  overflow-x: hidden;
}

a { color: var(--accent); }
img { max-width: 100%; height: auto; }
code, pre, textarea.paste, textarea.fallback { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
code { background: var(--code-bg); border-radius: 4px; padding: 1px 4px; font-size: 0.9em; overflow-wrap: anywhere; }
.wrap { max-width: 1040px; margin: 0 auto; padding: 0 16px; }
.site-header { padding: 16px 0; }
.logo { color: var(--ink); font-weight: 750; text-decoration: none; display: inline-flex; gap: 8px; align-items: center; min-height: 44px; }

h1 { font-size: clamp(28px, 6vw, 42px); line-height: 1.12; letter-spacing: -0.02em; margin: 8px 0 12px; }
h2 { font-size: 23px; line-height: 1.2; margin: 40px 0 10px; }
h3 { font-size: 18px; margin: 24px 0 4px; }
.lead { color: var(--muted); max-width: 66ch; margin: 0 0 20px; }
.small { font-size: 14px; color: var(--muted); margin: 0; }

/* Tool */
.tool { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 16px; display: grid; gap: 16px; min-width: 0; }
.settings, .options { display: grid; gap: 12px; min-width: 0; }
.field { display: grid; gap: 4px; min-width: 0; align-content: start; }
.field label, legend { font-size: 15px; font-weight: 600; }
.field input, textarea {
  width: 100%; min-height: 44px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--bg); color: var(--ink); font: inherit;
}
.field input { max-width: 320px; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
textarea.paste, textarea.fallback { font-size: 14px; resize: vertical; white-space: pre; overflow: auto; }
textarea.fallback { white-space: pre-wrap; word-break: break-all; }
[aria-invalid] { border-color: var(--error) !important; outline: 2px solid var(--error); outline-offset: 0; }
.group { border: 0; margin: 0; padding: 0; min-width: 0; display: grid; gap: 0; }
.group.inline { display: flex; flex-wrap: wrap; gap: 0 20px; }
.group.inline legend { width: 100%; }
.columns { display: flex; flex-wrap: wrap; gap: 0 20px; min-width: 0; }
.check { display: flex; gap: 10px; align-items: center; min-height: 44px; min-width: 0; }
.check input { width: 22px; height: 22px; flex: none; accent-color: var(--accent); margin: 0; }
.check input:disabled + label { color: var(--muted); }
.check label { overflow-wrap: anywhere; }
.error { color: var(--error); margin: 0; font-size: 15px; font-weight: 600; }
.warning { background: var(--warn-bg); padding: 8px 10px; border-radius: 8px; margin: 0; font-size: 15px; }
.status { margin: 0; color: var(--muted); font-weight: 600; }
.privacy-line { margin: 0; font-size: 15px; font-weight: 600; }

.button {
  display: inline-flex; align-items: center; justify-content: center; min-height: 44px; padding: 0 20px;
  border: 0; border-radius: 8px; background: var(--accent); color: var(--accent-ink);
  font: inherit; font-weight: 650; cursor: pointer; text-decoration: none;
}
.button.secondary { background: transparent; color: var(--accent); border: 2px solid var(--accent); }
input:focus-visible, button:focus-visible, textarea:focus-visible, .table-scroll:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.copy-row { display: flex; flex-wrap: wrap; gap: 10px; }

.result { display: grid; gap: 12px; min-width: 0; }
.formula {
  margin: 0; padding: 12px; background: var(--code-bg); border-radius: 8px; font-size: 15px;
  white-space: pre-wrap; overflow-wrap: anywhere; word-break: break-all;
}
.formula code { background: none; padding: 0; font-size: inherit; }
.apply { margin: 0; }
.steps { list-style: none; padding: 0; margin: 0; }
.summary-line { margin: 0; font-size: 19px; font-weight: 700; }

/* Preview */
.table-scroll { overflow: auto; max-height: 70vh; border: 1px solid var(--line); border-radius: 8px; overscroll-behavior: contain; }
table { border-collapse: collapse; width: 100%; font-size: 14px; }
th, td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--line); vertical-align: top; white-space: pre-wrap; max-width: 24ch; overflow-wrap: anywhere; }
th { position: sticky; top: 0; background: var(--surface); }
.num { text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
tr.removed td { background: var(--removed-bg); text-decoration: line-through; }
tr.kept td { background: var(--kept-bg); }
.key-removed { background: var(--removed-bg); text-decoration: line-through; padding: 0 4px; }
.key-kept { background: var(--kept-bg); padding: 0 4px; }
.prefer { border-top: 1px solid var(--line); padding-top: 4px; }
.prefer h2 { font-size: 19px; margin: 12px 0 6px; }
.prefer p { margin: 6px 0; }

/* Text pages */
ul, ol { padding-left: 22px; }
li { margin: 6px 0; }
.examples code { display: inline-block; margin-top: 4px; }
.legal { max-width: 760px; }

.site-footer { margin-top: 56px; padding: 20px 0 32px; border-top: 1px solid var(--line); }
.footer-row { display: grid; gap: 12px; }
.footer-note { font-size: 14px; color: var(--muted); margin: 0; }
.site-footer nav { display: flex; flex-wrap: wrap; gap: 4px 16px; }
.site-footer nav a { min-height: 44px; display: inline-flex; align-items: center; }

@media (min-width: 720px) {
  .tool { padding: 24px; }
}
