:root {
  --bg: #f6f4ee;
  --surface: #ffffff;
  --surface-2: #f0eee6;
  --ink: #15231e;
  --muted: #5b6b63;
  --brand: #0e5c3f;
  --brand-dark: #0a4630;
  --brand-soft: #e7f0e9;
  --accent: #b45309;
  --line: #e3dfd3;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(21, 35, 30, 0.04), 0 8px 24px rgba(21, 35, 30, 0.06);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 17px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
}

img, svg { max-width: 100%; }

a { color: var(--brand); text-decoration-thickness: 1px; text-underline-offset: 2px; }
a:hover { color: var(--brand-dark); }

:focus-visible {
  outline: 3px solid #c48a3a;
  outline-offset: 2px;
  border-radius: 4px;
}

.wrap {
  width: 100%;
  max-width: 1060px;
  margin: 0 auto;
  padding: 0 18px;
}

/* ---------- header ---------- */

.site-header {
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 20;
}

.site-header .wrap {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 64px;
  flex-wrap: wrap;
  padding-top: 8px;
  padding-bottom: 8px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  font-weight: 750;
  font-size: 1.15rem;
  letter-spacing: -0.02em;
  color: var(--ink);
  text-decoration: none;
}

.brand:hover { color: var(--ink); }

.brand-mark {
  width: 30px;
  height: 30px;
  flex: none;
}

.nav {
  display: flex;
  align-items: center;
  gap: 18px;
  font-size: 0.95rem;
  flex-wrap: wrap;
}

.nav a {
  color: var(--muted);
  text-decoration: none;
  font-weight: 550;
}

.nav a:hover, .nav a[aria-current="page"] { color: var(--brand); }

/* ---------- hero ---------- */

.hero {
  padding: 38px 0 8px;
}

.kicker {
  display: inline-block;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--brand);
  background: var(--brand-soft);
  border-radius: 999px;
  padding: 4px 10px;
  margin-bottom: 12px;
}

h1 {
  font-size: clamp(1.75rem, 1.15rem + 2.4vw, 2.7rem);
  line-height: 1.15;
  letter-spacing: -0.025em;
  margin: 0 0 12px;
}

.lede {
  font-size: clamp(1rem, 0.95rem + 0.3vw, 1.15rem);
  color: var(--muted);
  max-width: 62ch;
  margin: 0 0 22px;
}

/* ---------- tool ---------- */

.tool {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  margin: 8px 0 26px;
}

.tool-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.mode-tabs {
  display: inline-flex;
  background: var(--surface-2);
  border-radius: 999px;
  padding: 4px;
  gap: 2px;
}

.mode-btn {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 0.9rem;
  font-weight: 650;
  padding: 7px 15px;
  border-radius: 999px;
  cursor: pointer;
}

.mode-btn:hover { color: var(--ink); }

.mode-btn.active {
  background: var(--surface);
  color: var(--brand);
  box-shadow: 0 1px 3px rgba(21, 35, 30, 0.12);
}

.state-field {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.9rem;
  color: var(--muted);
  font-weight: 600;
}

.state-field select { min-width: 190px; }

.panel { margin-bottom: 4px; }

.fields {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

@media (min-width: 720px) {
  .fields.cols-2 { grid-template-columns: 1fr 1fr; }
  .fields.cols-3 { grid-template-columns: 1.1fr 1fr 1.1fr; }
  .fields.with-swap { grid-template-columns: 1fr auto 1fr; align-items: end; }
}

.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
  min-width: 0;
}

.field > span {
  font-size: 0.82rem;
  font-weight: 650;
  color: var(--muted);
  letter-spacing: 0.01em;
}

input[type="number"], select {
  width: 100%;
  font: inherit;
  font-size: 1rem;
  color: var(--ink);
  background: #fff;
  border: 1px solid #cfcabc;
  border-radius: 10px;
  padding: 11px 12px;
  min-height: 46px;
}

input[type="number"]:focus, select:focus {
  border-color: var(--brand);
  outline: 3px solid rgba(14, 92, 63, 0.16);
  outline-offset: 0;
}

.swap {
  width: 46px;
  height: 46px;
  border-radius: 10px;
  border: 1px solid #cfcabc;
  background: var(--surface-2);
  color: var(--brand);
  font-size: 1.2rem;
  cursor: pointer;
  line-height: 1;
  margin-bottom: 1px;
}

.swap:hover { background: var(--brand-soft); }

.state-note {
  margin: 10px 0 0;
  font-size: 0.84rem;
  color: var(--muted);
  background: var(--surface-2);
  border-radius: 8px;
  padding: 8px 10px;
}

.hidden { display: none !important; }

/* ---------- result ---------- */

.result {
  margin-top: 16px;
  border-top: 1px dashed var(--line);
  padding-top: 16px;
}

.result-head {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  font-size: 0.85rem;
  font-weight: 650;
  color: var(--muted);
  margin-bottom: 6px;
}

.result-head select {
  width: auto;
  min-width: 150px;
  min-height: 40px;
  padding: 7px 10px;
  font-size: 0.92rem;
}

.result-main {
  display: flex;
  align-items: baseline;
  gap: 8px;
  flex-wrap: wrap;
  margin: 2px 0 2px;
}

#resultValue {
  font-size: clamp(2rem, 1.4rem + 2.6vw, 2.9rem);
  font-weight: 800;
  letter-spacing: -0.03em;
  line-height: 1.05;
  color: var(--brand);
  word-break: break-word;
}

#resultUnit {
  font-size: 1.02rem;
  font-weight: 650;
  color: var(--muted);
}

#resultNote {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 0.92rem;
}

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

.btn {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font: inherit;
  font-size: 0.9rem;
  font-weight: 650;
  padding: 9px 14px;
  min-height: 42px;
  border-radius: 10px;
  border: 1px solid #cfcabc;
  background: var(--surface);
  color: var(--ink);
  text-decoration: none;
  cursor: pointer;
}

.btn:hover { background: var(--surface-2); color: var(--ink); }

.btn-primary {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
}

.btn-primary:hover { background: var(--brand-dark); color: #fff; }

/* ---------- breakdown table ---------- */

.breakdown {
  margin-top: 16px;
  border-top: 1px solid var(--line);
  padding-top: 10px;
}

.breakdown summary {
  cursor: pointer;
  font-size: 0.88rem;
  font-weight: 650;
  color: var(--muted);
  padding: 4px 0;
}

.table-wrap { overflow-x: auto; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.95rem;
}

th, td {
  text-align: left;
  padding: 9px 10px;
  border-bottom: 1px solid var(--line);
}

thead th {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  background: var(--surface-2);
}

tbody th { font-weight: 550; }
tbody td { text-align: right; font-variant-numeric: tabular-nums; }

/* ---------- plot ---------- */

.plot {
  margin-top: 16px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fbfaf6;
  padding: 6px;
}

.plot svg { display: block; width: 100%; height: auto; }

.plot-caption {
  text-align: center;
  font-size: 0.78rem;
  color: var(--muted);
  margin: 0 0 6px;
}

/* ---------- content ---------- */

.content { padding-bottom: 20px; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 22px;
  margin: 0 0 18px;
}

.prose h2 {
  font-size: clamp(1.3rem, 1.1rem + 0.9vw, 1.65rem);
  letter-spacing: -0.02em;
  line-height: 1.25;
  margin: 0 0 10px;
}

.prose h3 {
  font-size: 1.08rem;
  margin: 22px 0 6px;
}

.prose p { margin: 0 0 12px; }
.prose ul, .prose ol { margin: 0 0 14px; padding-left: 22px; }
.prose li { margin-bottom: 5px; }

.prose .table-wrap { margin: 14px 0 18px; }

.prose table { background: #fff; border: 1px solid var(--line); }

.prose thead th { white-space: nowrap; }

@media (max-width: 560px) {
  .prose table { font-size: 0.82rem; }
  .prose th, .prose td { padding: 7px 6px; }
  .prose thead th { white-space: normal; }
}

.note {
  border-left: 3px solid var(--accent);
  background: #fdf6ec;
  padding: 12px 14px;
  border-radius: 0 8px 8px 0;
  font-size: 0.93rem;
  color: #5a4526;
  margin: 14px 0;
}

.answer {
  background: var(--brand-soft);
  border: 1px solid #cfe2d5;
  border-radius: var(--radius);
  padding: 16px 18px;
  margin: 0 0 18px;
  font-size: 1.02rem;
}

.answer strong { color: var(--brand-dark); }

/* ---------- FAQ ---------- */

.faq details {
  border-bottom: 1px solid var(--line);
  padding: 12px 0;
}

.faq details:last-child { border-bottom: 0; }

.faq summary {
  cursor: pointer;
  font-weight: 650;
  font-size: 1rem;
  list-style: none;
  display: flex;
  justify-content: space-between;
  gap: 14px;
}

.faq summary::-webkit-details-marker { display: none; }

.faq summary::after {
  content: "+";
  color: var(--brand);
  font-weight: 500;
  font-size: 1.25rem;
  line-height: 1;
  flex: none;
}

.faq details[open] summary::after { content: "\2013"; }

.faq p { margin: 8px 0 0; color: var(--muted); }

/* ---------- related ---------- */

.related {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  margin-top: 8px;
}

@media (min-width: 640px) {
  .related { grid-template-columns: repeat(3, 1fr); }
}

.related a {
  display: block;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px 16px;
  text-decoration: none;
  color: var(--ink);
  font-weight: 600;
  font-size: 0.95rem;
}

.related a span {
  display: block;
  font-weight: 450;
  font-size: 0.85rem;
  color: var(--muted);
  margin-top: 2px;
}

.related a:hover { border-color: var(--brand); background: var(--brand-soft); }

/* ---------- footer ---------- */

.site-footer {
  background: #10241c;
  color: #c8d5ce;
  margin-top: 34px;
  padding: 28px 0 34px;
  font-size: 0.9rem;
}

.footer-top {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  flex-wrap: wrap;
  align-items: center;
}

.site-footer a { color: #e6eee9; }

.footer-links {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
}

.footer-note {
  max-width: 62ch;
  color: #9fb2a8;
  margin: 26px 0 0;
  padding-top: 18px;
  border-top: 1px solid rgba(255, 255, 255, 0.12);
  font-size: 0.82rem;
  line-height: 1.6;
}

/* ---------- misc ---------- */

.breadcrumb {
  font-size: 0.85rem;
  color: var(--muted);
  margin: 22px 0 12px;
}

.breadcrumb a { color: var(--muted); }

.updated {
  font-size: 0.82rem;
  color: var(--muted);
  margin: 0 0 20px;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin: 16px 0 4px;
}

@media (min-width: 640px) {
  .stat-grid { grid-template-columns: repeat(4, 1fr); }
}

.stat {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
}

.stat b {
  display: block;
  font-size: 1.15rem;
  color: var(--brand);
  letter-spacing: -0.02em;
}

.stat span {
  font-size: 0.8rem;
  color: var(--muted);
}

/* ---------- print ---------- */

@media print {
  .site-header, .site-footer, .actions, .mode-tabs, .nav, .related, .faq {
    display: none !important;
  }
  body { background: #fff; font-size: 12pt; }
  .tool, .card { box-shadow: none; border: 1px solid #999; }
  #resultValue { color: #000; }
  a { color: #000; text-decoration: none; }
}
