:root {
  --bg: #f7f5ef;
  --surface: #fffdf8;
  --surface-strong: #ffffff;
  --ink: #24231f;
  --muted: #656158;
  --line: #ded8cb;
  --teal: #1f6f68;
  --teal-dark: #164f4a;
  --gold: #b5812b;
  --rose: #a9473f;
  --green: #497a3d;
  --shadow: 0 18px 48px rgba(54, 45, 31, 0.12);
  --radius: 8px;
  --focus: 0 0 0 3px rgba(31, 111, 104, 0.22);
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.5;
}

button,
input,
select,
textarea {
  font: inherit;
}

button,
a,
input,
select,
textarea,
summary {
  outline-color: var(--teal);
}

button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
summary:focus-visible {
  box-shadow: var(--focus);
}

.site-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 20px;
  padding: 14px clamp(16px, 4vw, 44px);
  border-bottom: 1px solid var(--line);
  background: rgba(247, 245, 239, 0.94);
  backdrop-filter: blur(14px);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--ink);
  font-weight: 750;
  text-decoration: none;
}

.brand-mark {
  width: 28px;
  height: 28px;
  border: 2px solid var(--teal);
  background:
    linear-gradient(90deg, transparent 44%, var(--teal) 45%, var(--teal) 55%, transparent 56%),
    linear-gradient(0deg, transparent 44%, var(--gold) 45%, var(--gold) 55%, transparent 56%);
}

.site-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
}

.site-nav a {
  min-height: 36px;
  display: inline-flex;
  align-items: center;
  color: var(--muted);
  text-decoration: none;
  font-weight: 650;
}

.site-nav a:hover {
  color: var(--teal-dark);
}

main {
  width: min(1220px, calc(100% - 28px));
  margin: 0 auto;
}

main > *,
.form-panel,
.results-panel,
.content-stack,
.content-section,
.project-card,
.toc-panel,
.mini-tool,
.field,
.field-grid {
  min-width: 0;
}

.hero {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 28px;
  align-items: end;
  padding: 42px 0 24px;
}

.hero h1 {
  max-width: 760px;
  margin: 0;
  font-size: clamp(40px, 8vw, 86px);
  line-height: 0.95;
  letter-spacing: 0;
}

.lede {
  max-width: 720px;
  color: var(--muted);
  font-size: clamp(18px, 2vw, 22px);
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--teal-dark);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.hero-panel,
.results-card,
.form-panel,
.project-card,
.content-section {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.hero-panel {
  padding: 22px;
}

.snapshot-label {
  display: block;
  color: var(--muted);
  font-weight: 700;
}

.hero-panel strong {
  display: block;
  margin: 8px 0;
  font-size: 42px;
}

.hero-panel span:last-child {
  color: var(--muted);
}

.calculator-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 390px;
  gap: 20px;
  align-items: start;
}

.form-panel {
  padding: clamp(16px, 2.5vw, 28px);
}

.results-panel {
  position: sticky;
  top: 82px;
  display: grid;
  gap: 16px;
}

.results-card {
  padding: 18px;
}

.section-heading {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: center;
  margin-bottom: 16px;
}

.section-heading h2,
.section-heading h3 {
  margin: 0;
}

.section-heading.compact {
  margin-bottom: 12px;
}

form {
  display: grid;
  gap: 18px;
}

.control-group {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  background: var(--surface-strong);
}

fieldset.control-group {
  margin: 0;
}

.control-group legend,
.control-group summary {
  font-size: 18px;
  font-weight: 800;
}

details.control-group summary {
  cursor: pointer;
}

.field-grid {
  display: grid;
  gap: 14px;
  margin-top: 12px;
}

.field-grid.two {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.field-grid.three {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.field-grid.four {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.field {
  display: grid;
  gap: 6px;
}

.field > span:first-child {
  color: var(--ink);
  font-size: 13px;
  font-weight: 780;
}

input,
select,
textarea {
  width: 100%;
  min-height: 44px;
  border: 1px solid #c9c1b2;
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  padding: 10px 11px;
}

textarea {
  resize: vertical;
}

input:invalid {
  border-color: var(--rose);
}

.input-with-unit {
  display: flex;
  min-height: 44px;
  align-items: center;
  border: 1px solid #c9c1b2;
  border-radius: 6px;
  background: #fff;
  overflow: hidden;
}

.input-with-unit input {
  flex: 1 1 auto;
  width: 0;
  min-width: 0;
  min-height: 42px;
  border: 0;
  border-radius: 0;
}

.input-with-unit span {
  flex: 0 0 auto;
  padding: 0 10px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 760;
}

.segmented {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.segmented label {
  cursor: pointer;
}

.segmented input {
  position: absolute;
  width: 1px;
  min-height: 1px;
  margin: 0;
  opacity: 0;
  pointer-events: none;
}

.segmented span {
  display: inline-flex;
  min-height: 40px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 12px;
  background: #f9f7f1;
  color: var(--muted);
  font-weight: 780;
}

.segmented input:checked + span {
  border-color: var(--teal);
  background: #e6f2ee;
  color: var(--teal-dark);
}

.toolbar-row,
.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 14px;
}

button {
  min-height: 44px;
  border: 0;
  border-radius: 6px;
  padding: 10px 14px;
  cursor: pointer;
  font-weight: 800;
}

.primary-button,
.secondary-button,
.ghost-button {
  text-decoration: none;
}

a.primary-button,
a.secondary-button,
a.ghost-button {
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  padding: 10px 14px;
  font-weight: 800;
}

.primary-button {
  background: var(--teal);
  color: #fff;
}

.primary-button:hover {
  background: var(--teal-dark);
}

.secondary-button {
  border: 1px solid var(--teal);
  background: #fff;
  color: var(--teal-dark);
}

.ghost-button {
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
}

.ghost-button.danger {
  color: var(--rose);
}

.hint {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.status-message {
  min-height: 20px;
  margin: 10px 0 0;
  color: var(--teal-dark);
  font-size: 13px;
  font-weight: 760;
}

.manual-copy {
  margin-top: 10px;
}

.manual-copy textarea {
  font-size: 13px;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  clip-path: inset(50%);
}

.result-summary {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.metric {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 12px;
  background: #fff;
}

.metric span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.metric strong {
  display: block;
  margin-top: 4px;
  font-size: 24px;
}

.badge {
  display: inline-flex;
  min-height: 34px;
  align-items: center;
  border-radius: 999px;
  padding: 6px 10px;
  background: #e6f2ee;
  color: var(--teal-dark);
  font-size: 13px;
  font-weight: 850;
}

.badge.medium {
  background: #fff1d6;
  color: #80580f;
}

.badge.low {
  background: #fbe2df;
  color: #8d332c;
}

.warnings {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.warning {
  border-left: 4px solid var(--gold);
  padding: 8px 10px;
  background: #fff8e8;
  color: #5d4420;
  font-size: 14px;
}

.saved-list {
  display: grid;
  gap: 10px;
}

.saved-tools {
  margin-bottom: 12px;
}

.saved-item {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px;
  background: #fff;
}

.saved-item.active {
  border-color: var(--teal);
  box-shadow: inset 0 0 0 1px var(--teal);
}

.saved-item strong,
.saved-item span {
  display: block;
}

.saved-item span {
  color: var(--muted);
  font-size: 13px;
}

.saved-item p {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 13px;
}

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

.saved-actions button {
  min-height: 36px;
  padding: 6px 10px;
}

.project-card,
.content-section {
  margin: 22px 0;
  padding: clamp(16px, 2.5vw, 28px);
}

.card-content {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.card-field {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px;
  background: #fff;
}

.card-field span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.card-field strong {
  display: block;
  margin-top: 4px;
}

.formula-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.formula {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 12px;
  background: #fff;
}

.formula code {
  display: block;
  white-space: normal;
  color: var(--teal-dark);
  font-size: 14px;
}

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

.guide-grid {
  display: grid;
  grid-template-columns: 0.8fr 1.2fr;
  gap: 20px;
}

.guide-cards {
  display: grid;
  gap: 12px;
}

.guide-cards article {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 14px;
  background: #fff;
}

.page-hero {
  padding: 42px 0 20px;
}

.page-hero h1 {
  max-width: 900px;
  margin: 0;
  font-size: clamp(38px, 6vw, 68px);
  line-height: 1;
  letter-spacing: 0;
}

.page-hero .lede {
  margin-bottom: 0;
}

.content-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 22px;
  align-items: start;
  margin-bottom: 24px;
}

.content-stack {
  display: grid;
  gap: 18px;
}

.toc-panel {
  position: sticky;
  top: 82px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.toc-panel h2,
.toc-panel p {
  margin-top: 0;
}

.toc-panel nav {
  display: grid;
  gap: 8px;
}

.toc-panel a {
  color: var(--teal-dark);
  font-weight: 750;
  text-decoration: none;
}

.callout {
  border-left: 5px solid var(--teal);
  border-radius: var(--radius);
  padding: 14px 16px;
  background: #eaf3f0;
}

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

table {
  width: 100%;
  border-collapse: collapse;
  background: #fff;
}

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

th {
  background: #efe9dc;
  color: var(--ink);
}

.tool-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.tool-card {
  min-height: 132px;
  display: grid;
  align-content: start;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 14px;
  background: #fff;
  color: var(--ink);
  text-decoration: none;
}

.tool-card:hover {
  border-color: var(--teal);
}

.tool-card span {
  color: var(--teal-dark);
  font-size: 13px;
  font-weight: 850;
  text-transform: uppercase;
}

.tool-card strong {
  font-size: 18px;
  line-height: 1.25;
}

.mini-tool {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  background: #fff;
}

.mini-tool-output {
  margin-top: 14px;
  border-radius: 6px;
  padding: 14px;
  background: #eaf3f0;
  color: var(--teal-dark);
  font-weight: 850;
}

.faq-list details {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 12px;
  background: #fff;
}

.faq-list {
  display: grid;
  gap: 10px;
}

.guide-cards h3,
.guide-cards p {
  margin: 0;
}

.guide-cards p {
  margin-top: 6px;
  color: var(--muted);
}

.mobile-result-bar {
  display: none;
}

.site-footer {
  width: min(1220px, calc(100% - 28px));
  margin: 28px auto 80px;
  color: var(--muted);
  font-size: 14px;
}

@media (max-width: 940px) {
  .hero,
  .calculator-shell,
  .guide-grid,
  .content-layout {
    grid-template-columns: 1fr;
  }

  .results-panel,
  .toc-panel {
    position: static;
  }

  .hero {
    padding-top: 28px;
  }
}

@media (max-width: 720px) {
  .site-header {
    position: static;
    align-items: flex-start;
    flex-direction: column;
  }

  .site-nav {
    width: 100%;
    justify-content: space-between;
  }

  .site-nav a {
    min-height: 44px;
  }

  main {
    width: min(100% - 20px, 1220px);
  }

  .field-grid.two,
  .field-grid.three,
  .field-grid.four,
  .result-summary,
  .card-content,
  .formula-grid,
  .tool-grid {
    grid-template-columns: 1fr;
  }

  .control-group {
    padding: 14px;
  }

  .hero h1 {
    font-size: 46px;
  }

  .mobile-result-bar {
    position: fixed;
    left: 10px;
    right: 10px;
    bottom: max(10px, env(safe-area-inset-bottom));
    z-index: 30;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    min-height: 54px;
    border: 1px solid rgba(22, 79, 74, 0.35);
    border-radius: 8px;
    padding: 10px 12px;
    background: var(--teal-dark);
    color: #fff;
    box-shadow: 0 18px 44px rgba(0, 0, 0, 0.24);
  }

  .mobile-result-bar a {
    color: #fff;
    font-weight: 850;
  }

  .site-footer {
    margin-bottom: 96px;
  }
}

@media print {
  body {
    background: #fff;
  }

  .site-header,
  .hero,
  .calculator-shell,
  .content-section,
  .mobile-result-bar,
  .site-footer,
  #copySummary {
    display: none !important;
  }

  main {
    width: 100%;
  }

  .project-card {
    box-shadow: none;
    border: 0;
  }

  .card-content {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}
