:root {
  color-scheme: light;
  --bg: #f3efe6;
  --bg-raise: #fffdf8;
  --ink: #1c1915;
  --muted: #5e584e;
  --line: #e3d9c8;
  --accent: #0f6e56;
  --accent-ink: #f4fff9;
  --danger: #9f2d2d;
  --danger-bg: #fdecec;
  --pay: #0f6e56;
  --save: #c46a2b;
  --base: #3d6f8f;
  --extra: #8a5a2a;
  --shadow: 0 16px 40px rgba(48, 36, 18, 0.06);
  --header: rgba(243, 239, 230, 0.92);
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #121614;
  --bg-raise: #1b211e;
  --ink: #eef3ef;
  --muted: #b4c0b8;
  --line: #2d3833;
  --accent: #3dbea0;
  --accent-ink: #06231c;
  --danger: #ffb4b0;
  --danger-bg: #3a2020;
  --pay: #3dbea0;
  --save: #e0a06a;
  --base: #8eb7d4;
  --extra: #d7b089;
  --shadow: none;
  --header: rgba(18, 22, 20, 0.92);
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(1200px 400px at 10% -10%, rgba(15, 110, 86, 0.08), transparent 50%),
    var(--bg);
  color: var(--ink);
  font-family: "Segoe UI", system-ui, sans-serif;
  font-size: 16px;
  line-height: 1.5;
}

:root[data-theme="dark"] body {
  background:
    radial-gradient(900px 320px at 0% -10%, rgba(61, 190, 160, 0.12), transparent 46%),
    var(--bg);
}

a { color: var(--accent); }
a:hover { text-decoration: none; }

.skip {
  position: absolute;
  left: 12px;
  top: -40px;
  background: var(--accent);
  color: var(--accent-ink);
  padding: 8px 12px;
  z-index: 5;
}
.skip:focus { top: 12px; }

.site-header, .site-footer, .wrap { width: min(1120px, calc(100% - 32px)); margin-inline: auto; }

.site-header {
  display: flex;
  align-items: center;
  gap: 16px;
  min-height: 64px;
  position: sticky;
  top: 0;
  z-index: 3;
  background: var(--header);
  backdrop-filter: blur(10px);
  width: min(1120px, calc(100% - 32px));
}

.logo {
  color: var(--ink);
  text-decoration: none;
  font-family: Georgia, "Iowan Old Style", Palatino, serif;
  font-size: 22px;
  letter-spacing: -0.03em;
}

.site-header nav { display: flex; gap: 14px; flex-wrap: wrap; }
.site-header nav a { color: var(--muted); text-decoration: none; font-size: 14px; }
.site-header nav a[aria-current="page"], .site-header nav a:hover { color: var(--ink); }

.theme-btn, .btn {
  border: 1px solid var(--line);
  background: var(--bg-raise);
  color: var(--ink);
  border-radius: 999px;
  min-height: 40px;
  padding: 0 14px;
  font: inherit;
  cursor: pointer;
}

.theme-btn { margin-left: auto; }

.btn-primary {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: transparent;
}

.btn-ghost { background: transparent; }

.btn:disabled { opacity: 0.45; cursor: not-allowed; }

.wrap { padding: 12px 0 64px; }

.crumbs { color: var(--muted); font-size: 13px; margin-bottom: 18px; }
.crumbs a { color: inherit; }

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(280px, 0.75fr);
  gap: 28px 36px;
  align-items: start;
}

.layout > div:first-child { grid-column: 1; grid-row: 1; }
.result { grid-column: 2; grid-row: 1 / span 2; }
.text-col { grid-column: 1; grid-row: 2; }

.layout-single { grid-template-columns: 1fr; }

h1, h2, h3 {
  font-family: Georgia, "Iowan Old Style", Palatino, serif;
  font-weight: 600;
  letter-spacing: -0.03em;
  line-height: 1.15;
}

h1 { font-size: clamp(32px, 5vw, 48px); margin: 0 0 12px; }
h2 { font-size: 28px; margin: 36px 0 12px; }
h3 { font-size: 20px; margin: 0 0 8px; }

.lead { font-size: 18px; color: var(--muted); margin-top: 0; max-width: 62ch; }

.panel, .result, .catalog a, .faq details {
  background: var(--bg-raise);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
}

.panel { padding: 18px; }

.fields, .item-grid { display: grid; gap: 12px; }
.fields { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }

label.field, .stack-field { display: flex; flex-direction: column; gap: 6px; font-size: 14px; }
.field-name { font-weight: 650; }
.hint, .field-error { min-height: 1.1em; margin: 0; font-size: 12px; color: var(--muted); }
.field-error:empty { display: none; }
.field-error { color: var(--danger); display: block; min-height: 0; }

input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--ink);
  border-radius: 12px;
  min-height: 44px;
  padding: 10px 12px;
  font: inherit;
}

textarea { min-height: 110px; resize: vertical; }

input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--accent);
  border-color: transparent;
}

input.invalid, textarea.invalid, select.invalid {
  border-color: var(--danger);
  background: var(--danger-bg);
}

.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }

.item { padding-top: 12px; margin-top: 12px; border-top: 1px solid var(--line); }
.item:first-child { border-top: 0; margin-top: 0; padding-top: 0; }
.item-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.item-grid { grid-template-columns: 1.4fr repeat(3, minmax(0, 1fr)); }

.result {
  position: sticky;
  top: 80px;
  padding: 18px 18px 8px;
}

.result-kicker { margin: 0; color: var(--muted); font-size: 13px; text-transform: uppercase; letter-spacing: 0.06em; }
.result-main {
  margin: 6px 0;
  font-family: Georgia, "Iowan Old Style", Palatino, serif;
  font-size: clamp(32px, 4vw, 44px);
  letter-spacing: -0.04em;
  font-variant-numeric: tabular-nums;
}
.result-main.is-fresh { animation: rise 240ms ease; }
.result-formula, .result-note, .result-idle, .result-bad { color: var(--muted); }
.result-bad { color: var(--danger); }
.result-lines { margin: 12px 0; }
.result-lines div { display: flex; justify-content: space-between; gap: 12px; padding: 8px 0; border-top: 1px dashed var(--line); }
.result-lines dt { color: var(--muted); }
.result-lines dd { margin: 0; font-variant-numeric: tabular-nums; text-align: right; }

.bar { display: flex; height: 10px; border-radius: 999px; overflow: hidden; background: var(--line); margin: 8px 0 4px; }
.bar-pay { background: var(--pay); }
.bar-save { background: var(--save); }
.bar-base { background: var(--base); }
.bar-extra { background: var(--extra); }

.steps { width: 100%; border-collapse: collapse; font-size: 14px; margin: 8px 0 16px; }
.steps th, .steps td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--line); }
.steps td:not(:first-child), .steps th:not(:first-child) { text-align: right; font-variant-numeric: tabular-nums; }

.prose p { max-width: 68ch; }
.faq { display: grid; gap: 10px; }
.faq details { padding: 12px 16px; box-shadow: none; }
.faq summary { cursor: pointer; font-weight: 650; }
.related { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 10px; }
.related a, .catalog a {
  display: block;
  padding: 14px 16px;
  text-decoration: none;
  color: var(--ink);
}
.related a span, .catalog a span { display: block; color: var(--muted); font-size: 14px; margin-top: 4px; }
.catalog { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 12px; }

.site-footer { padding: 28px 0 48px; color: var(--muted); font-size: 14px; }
.footer-links { display: flex; flex-wrap: wrap; gap: 8px 14px; margin-bottom: 12px; }
.footer-links a { color: inherit; }

@keyframes rise {
  from { opacity: 0.35; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; }
  .layout > div:first-child,
  .result,
  .text-col { grid-column: auto; grid-row: auto; }
  .result { position: static; order: 2; }
  .text-col { order: 3; }
  .item-grid { grid-template-columns: 1fr 1fr; }
  .site-header { flex-wrap: wrap; padding: 10px 0; }
  .theme-btn { margin-left: 0; }
}
