:root {
  --paper: #f2eee5;
  --paper-raised: #fbf9f4;
  --ink: #17211c;
  --ink-soft: #59635d;
  --line: #c9c7bd;
  --line-strong: #9e9f96;
  --forest: #173d31;
  --forest-deep: #102f27;
  --mint: #bfe4ce;
  --lime: #d6f27b;
  --error: #a52c2c;
  --focus: #0d6e55;
  --radius-small: 8px;
  --radius-medium: 18px;
  --shadow: 0 24px 70px rgba(22, 33, 28, 0.12);
  --page: 1120px;
  --gutter: clamp(1rem, 4vw, 2.5rem);
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --sans: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  scroll-behavior: smooth;
  background: var(--paper);
}

body {
  min-width: 0;
  margin: 0;
  color: var(--ink);
  background:
    linear-gradient(90deg, transparent calc(50% - 0.5px), rgba(23, 33, 28, 0.045) 50%, transparent calc(50% + 0.5px)),
    var(--paper);
  font-family: var(--sans);
  font-size: 1rem;
  line-height: 1.55;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

button,
input {
  font: inherit;
}

button,
a,
summary,
input {
  -webkit-tap-highlight-color: transparent;
}

button {
  color: inherit;
}

a {
  color: inherit;
  text-underline-offset: 0.2em;
}

h1,
h2,
h3,
p,
dl,
dd,
ol {
  margin-top: 0;
}

.page-width {
  width: min(100%, calc(var(--page) + (2 * var(--gutter))));
  margin-inline: auto;
  padding-inline: var(--gutter);
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: fixed;
  top: max(0.75rem, env(safe-area-inset-top));
  left: max(0.75rem, env(safe-area-inset-left));
  z-index: 100;
  padding: 0.75rem 1rem;
  border-radius: var(--radius-small);
  color: white;
  background: var(--forest);
  transform: translateY(-160%);
}

.skip-link:focus {
  transform: translateY(0);
}

:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 3px;
}

.site-header {
  padding-top: env(safe-area-inset-top);
  border-bottom: 1px solid rgba(23, 33, 28, 0.14);
}

.header-inner {
  min-height: 72px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.wordmark {
  display: inline-flex;
  align-items: center;
  gap: 0.7rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  text-decoration: none;
}

.wordmark-mark {
  display: grid;
  width: 32px;
  height: 32px;
  place-items: center;
  border-radius: 50%;
  color: var(--paper-raised);
  background: var(--ink);
  font-family: var(--serif);
  font-size: 1.15rem;
}

.wordmark-muted {
  color: var(--ink-soft);
  font-weight: 500;
}

.header-link {
  min-height: 48px;
  display: inline-flex;
  align-items: center;
  font-size: 0.875rem;
  font-weight: 700;
  text-decoration: none;
}

.header-link::after {
  content: " ↓";
  margin-left: 0.35rem;
}

.hero {
  display: grid;
  grid-template-columns: minmax(0, 1.45fr) minmax(18rem, 0.55fr);
  gap: clamp(2rem, 7vw, 7rem);
  align-items: end;
  padding-top: clamp(3.5rem, 8vw, 7.5rem);
  padding-bottom: clamp(3rem, 6vw, 5.25rem);
}

.eyebrow {
  margin-bottom: 1.1rem;
  color: var(--ink-soft);
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0.13em;
  text-transform: uppercase;
}

h1,
h2 {
  font-family: var(--serif);
  font-weight: 500;
  letter-spacing: -0.045em;
  line-height: 0.98;
}

h1 {
  max-width: 15ch;
  margin-bottom: 0;
  font-size: clamp(3rem, 7.2vw, 6.6rem);
}

.hero-intro {
  max-width: 31rem;
  margin-bottom: 0.3rem;
  color: var(--ink-soft);
  font-size: clamp(1rem, 1.7vw, 1.2rem);
}

.tool-section {
  padding-bottom: clamp(4rem, 8vw, 7.5rem);
}

.tool-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 0.95fr);
  border: 1px solid var(--ink);
  border-radius: var(--radius-medium);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.calculator-form,
.result-panel {
  min-width: 0;
  padding: clamp(1.35rem, 4.2vw, 3.5rem);
}

.calculator-form {
  background: var(--paper-raised);
}

.form-heading,
.result-topline {
  display: flex;
  align-items: flex-start;
  gap: 1rem;
  margin-bottom: clamp(2rem, 5vw, 3.75rem);
}

.section-number {
  flex: 0 0 auto;
  margin: 0.15rem 0 0;
  color: var(--ink-soft);
  font-size: 0.65rem;
  font-weight: 800;
  letter-spacing: 0.12em;
}

.form-heading h3 {
  margin: 0 0 0.25rem;
  font-family: var(--serif);
  font-size: clamp(1.5rem, 3vw, 2rem);
  font-weight: 500;
  letter-spacing: -0.03em;
}

.form-heading p:last-child {
  margin-bottom: 0;
  color: var(--ink-soft);
  font-size: 0.875rem;
}

.field {
  position: relative;
}

.field label {
  display: block;
  margin-bottom: 0.55rem;
  font-size: 0.8rem;
  font-weight: 800;
  letter-spacing: 0.03em;
}

.input-wrap {
  position: relative;
}

.input-wrap input {
  width: 100%;
  min-height: 66px;
  padding: 1.15rem 8.2rem 1.15rem 1rem;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-small);
  color: var(--ink);
  background: white;
  font-variant-numeric: tabular-nums;
  font-size: 1.2rem;
  font-weight: 650;
  transition: border-color 140ms ease, box-shadow 140ms ease;
}

.input-wrap input:hover {
  border-color: var(--ink);
}

.input-wrap input:focus {
  border-color: var(--focus);
  outline: none;
  box-shadow: 0 0 0 3px rgba(13, 110, 85, 0.18);
}

.input-wrap input[aria-invalid="true"] {
  border-color: var(--error);
  box-shadow: 0 0 0 2px rgba(165, 44, 44, 0.1);
}

.input-caption {
  position: absolute;
  top: 50%;
  right: 1rem;
  color: var(--ink-soft);
  font-size: 0.72rem;
  font-weight: 700;
  transform: translateY(-50%);
  pointer-events: none;
}

.field-error {
  min-height: 1.25rem;
  margin: 0.4rem 0 0;
  color: var(--error);
  font-size: 0.78rem;
}

.swap-button {
  width: fit-content;
  min-height: 48px;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin: -0.1rem 0 -0.1rem auto;
  padding: 0.55rem 0.2rem;
  border: 0;
  color: var(--ink-soft);
  background: transparent;
  font-size: 0.78rem;
  font-weight: 750;
  cursor: pointer;
}

.swap-button span {
  display: grid;
  width: 24px;
  height: 24px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--paper);
}

.swap-button:disabled {
  opacity: 0.4;
  cursor: default;
}

.example-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.45rem;
  margin-top: 1.4rem;
  color: var(--ink-soft);
  font-size: 0.75rem;
}

.example-button {
  min-height: 36px;
  padding: 0.35rem 0.65rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: transparent;
  font-variant-numeric: tabular-nums;
  font-size: 0.75rem;
  cursor: pointer;
}

.example-button:hover {
  border-color: var(--ink);
  background: white;
}

.form-actions,
.result-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.form-actions {
  margin-top: clamp(1.75rem, 5vw, 3rem);
}

.button {
  min-height: 50px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.75rem 1.05rem;
  border: 1px solid transparent;
  border-radius: var(--radius-small);
  font-size: 0.84rem;
  font-weight: 800;
  cursor: pointer;
}

.button-primary {
  flex: 1 1 11rem;
  color: white;
  background: var(--ink);
}

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

.button-quiet {
  color: var(--ink-soft);
  background: transparent;
  border-color: var(--line);
}

.result-panel {
  display: flex;
  flex-direction: column;
  color: #eef5ef;
  background:
    radial-gradient(circle at 100% 0, rgba(191, 228, 206, 0.16), transparent 32%),
    var(--forest);
}

.result-panel :focus-visible {
  outline-color: white;
}

.section-number-light,
.result-kicker {
  color: rgba(238, 245, 239, 0.68);
}

.result-kicker {
  margin-bottom: 0;
  font-size: 0.8rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.result-primary {
  min-width: 0;
  margin-bottom: 1rem;
}

#percentChange {
  display: block;
  max-width: 100%;
  color: var(--lime);
  font-family: var(--serif);
  font-size: clamp(3.8rem, 8.5vw, 7rem);
  font-variant-numeric: tabular-nums;
  font-weight: 500;
  letter-spacing: -0.065em;
  line-height: 0.9;
  overflow-wrap: anywhere;
}

#direction-label {
  margin: 0.8rem 0 0;
  color: var(--mint);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.09em;
  text-transform: uppercase;
}

.result-sentence {
  min-height: 3.1em;
  max-width: 34rem;
  margin: 1.2rem 0 2rem;
  color: rgba(238, 245, 239, 0.82);
  font-size: clamp(1rem, 2vw, 1.16rem);
}

.result-details {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin: auto 0 0;
  border-top: 1px solid rgba(238, 245, 239, 0.22);
  border-bottom: 1px solid rgba(238, 245, 239, 0.22);
}

.result-details div {
  min-width: 0;
  padding: 1.2rem 0;
}

.result-details div + div {
  padding-left: 1rem;
  border-left: 1px solid rgba(238, 245, 239, 0.22);
}

.result-details dt {
  margin-bottom: 0.3rem;
  color: rgba(238, 245, 239, 0.6);
  font-size: 0.68rem;
  font-weight: 750;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.result-details dd {
  min-width: 0;
  margin: 0;
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  overflow-wrap: anywhere;
}

.result-formula {
  margin: 1.1rem 0 0;
  color: rgba(238, 245, 239, 0.6);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.72rem;
  overflow-wrap: anywhere;
}

.result-actions {
  margin-top: 1.75rem;
}

.button-light {
  color: var(--forest-deep);
  background: var(--lime);
}

.button-light:hover {
  background: white;
}

.button-outline-light {
  color: white;
  border-color: rgba(255, 255, 255, 0.45);
  background: transparent;
}

.button-outline-light:hover {
  border-color: white;
}

.structured-result {
  margin-top: 1.4rem;
  border-top: 1px solid rgba(238, 245, 239, 0.16);
  padding-top: 0.8rem;
}

.structured-result summary {
  min-height: 44px;
  display: flex;
  align-items: center;
  color: rgba(238, 245, 239, 0.72);
  font-size: 0.75rem;
  font-weight: 750;
  cursor: pointer;
}

.structured-result pre {
  max-width: 100%;
  margin: 0.5rem 0;
  padding: 0.9rem;
  border: 1px solid rgba(238, 245, 239, 0.15);
  border-radius: var(--radius-small);
  background: rgba(0, 0, 0, 0.12);
  font-size: 0.7rem;
  overflow-x: auto;
}

.text-button {
  min-height: 44px;
  padding: 0;
  border: 0;
  color: var(--mint);
  background: transparent;
  font-size: 0.75rem;
  font-weight: 800;
  text-decoration: underline;
  text-underline-offset: 0.2em;
  cursor: pointer;
}

.copy-status {
  min-height: 1.25rem;
  margin: 0.65rem 0 -0.4rem;
  color: var(--mint);
  font-size: 0.72rem;
}

.noscript-message {
  padding: 0.8rem 1rem;
  color: white;
  background: var(--error);
}

.ad-slot {
  position: relative;
  display: grid;
  place-items: center;
  margin-top: 0;
  margin-bottom: clamp(4rem, 9vw, 8rem);
}

.ad-slot::after {
  content: "";
  position: absolute;
  inset-inline: var(--gutter);
  top: 0;
  border-top: 1px solid rgba(23, 33, 28, 0.1);
}

.ad-label {
  position: absolute;
  top: 0.75rem;
  color: var(--ink-soft);
  font-size: 0.62rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.ad-slot-inner {
  width: 100%;
  max-width: 970px;
  min-height: 116px;
}

.ad-slot-secondary .ad-slot-inner {
  min-height: 138px;
}

.method-section,
.reference-section {
  padding-bottom: clamp(4.5rem, 10vw, 9rem);
}

.method-heading {
  display: grid;
  grid-template-columns: minmax(0, 0.6fr) minmax(0, 1.4fr);
  gap: 2rem;
  margin-bottom: clamp(2.5rem, 6vw, 5rem);
}

.method-heading h2,
.reference-intro h2,
.worked-example h2 {
  max-width: 14ch;
  margin-bottom: 0;
  font-size: clamp(2.5rem, 5.4vw, 5rem);
}

.method-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.18fr) minmax(17rem, 0.82fr);
  gap: clamp(2rem, 7vw, 6rem);
}

.formula-card {
  padding: clamp(1.4rem, 4vw, 3rem);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-medium);
  background: var(--paper-raised);
}

.formula-label {
  margin-bottom: 1.5rem;
  color: var(--ink-soft);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.09em;
  text-transform: uppercase;
}

.display-formula {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  margin-bottom: 2rem;
  font-family: var(--serif);
  font-size: clamp(1.35rem, 3.8vw, 2.5rem);
  line-height: 1.05;
}

.fraction {
  display: inline-flex;
  flex-direction: column;
  text-align: center;
}

.fraction span:first-child {
  padding: 0 0.45rem 0.45rem;
  border-bottom: 1px solid currentColor;
}

.fraction span:last-child {
  padding-top: 0.45rem;
}

.formula-card > p:last-child {
  max-width: 52ch;
  margin-bottom: 0;
  color: var(--ink-soft);
}

.method-notes {
  display: grid;
  gap: 2rem;
}

.method-notes article {
  display: grid;
  grid-template-columns: 2rem 1fr;
  column-gap: 1rem;
  border-top: 1px solid var(--line-strong);
  padding-top: 1.3rem;
}

.note-number {
  grid-row: span 2;
  color: var(--ink-soft);
  font-family: var(--serif);
  font-style: italic;
}

.method-notes h3 {
  margin-bottom: 0.5rem;
  font-family: var(--serif);
  font-size: 1.35rem;
  font-weight: 500;
}

.method-notes p:last-child {
  margin-bottom: 0;
  color: var(--ink-soft);
}

.worked-example {
  display: grid;
  grid-template-columns: minmax(13rem, 0.65fr) minmax(0, 1.35fr);
  gap: clamp(2rem, 7vw, 7rem);
  padding-top: clamp(3.5rem, 8vw, 7rem);
  padding-bottom: clamp(3.5rem, 8vw, 7rem);
  border-top: 1px solid var(--ink);
}

.steps {
  margin-bottom: 0;
  padding: 0;
  list-style: none;
  counter-reset: steps;
}

.steps li {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 1rem;
  padding: 1.2rem 0;
  border-bottom: 1px solid var(--line);
  counter-increment: steps;
}

.steps li::before {
  content: "0" counter(steps);
  grid-row: 1;
  color: var(--ink-soft);
  font-size: 0.68rem;
  font-weight: 800;
}

.steps span {
  grid-column: 1;
  color: var(--ink-soft);
}

.steps strong {
  grid-column: 2;
  grid-row: 1 / span 2;
  align-self: center;
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.example-answer {
  grid-column: 2;
  margin: 1rem 0 0;
  font-family: var(--serif);
  font-size: 1.35rem;
}

.reference-section {
  display: grid;
  grid-template-columns: minmax(16rem, 0.75fr) minmax(0, 1.25fr);
  gap: clamp(2.5rem, 8vw, 8rem);
}

.reference-intro > p:last-child {
  max-width: 43ch;
  margin-top: 1.5rem;
  color: var(--ink-soft);
}

.faq-list {
  border-top: 1px solid var(--ink);
}

.faq-list details {
  border-bottom: 1px solid var(--line-strong);
}

.faq-list summary {
  position: relative;
  min-height: 72px;
  display: flex;
  align-items: center;
  padding: 1rem 2.4rem 1rem 0;
  font-family: var(--serif);
  font-size: 1.08rem;
  font-weight: 600;
  cursor: pointer;
  list-style: none;
}

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

.faq-list summary::after {
  content: "+";
  position: absolute;
  right: 0;
  font-family: var(--sans);
  font-size: 1.25rem;
  font-weight: 400;
}

.faq-list details[open] summary::after {
  content: "−";
}

.faq-list details p {
  max-width: 60ch;
  padding: 0 2.4rem 1.4rem 0;
  color: var(--ink-soft);
}

.site-footer {
  padding-bottom: env(safe-area-inset-bottom);
  color: rgba(238, 245, 239, 0.78);
  background: var(--forest-deep);
}

.footer-inner {
  min-height: 150px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1.5rem;
  align-items: center;
  padding-top: 2rem;
  padding-bottom: 2rem;
  font-size: 0.78rem;
}

.footer-inner p {
  margin-bottom: 0;
}

.footer-inner p:nth-child(2) {
  text-align: center;
}

.footer-inner a {
  justify-self: end;
}

.error-page {
  min-height: calc(100dvh - 72px);
  display: grid;
  place-items: center;
  padding-top: 4rem;
  padding-bottom: 4rem;
}

.error-content {
  max-width: 40rem;
}

.error-code {
  margin-bottom: 1rem;
  color: var(--ink-soft);
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0.12em;
}

.error-content h1 {
  margin-bottom: 1.5rem;
}

.error-content > p:not(.error-code) {
  max-width: 40ch;
  color: var(--ink-soft);
}

.error-content .button {
  margin-top: 1rem;
  color: white;
  text-decoration: none;
}

@media (max-width: 820px) {
  body {
    background: var(--paper);
  }

  .hero {
    grid-template-columns: 1fr;
    gap: 1.5rem;
  }

  .hero-intro {
    max-width: 38rem;
  }

  .tool-grid,
  .method-grid,
  .worked-example,
  .reference-section {
    grid-template-columns: 1fr;
  }

  .result-panel {
    min-height: 570px;
  }

  .worked-example {
    gap: 2.5rem;
  }

  .example-answer {
    grid-column: 1;
  }

  .reference-intro > p:last-child {
    max-width: 58ch;
  }
}

@media (max-width: 560px) {
  :root {
    --gutter: 1rem;
    --radius-medium: 14px;
  }

  .header-inner {
    min-height: 64px;
  }

  .wordmark-muted {
    display: none;
  }

  .hero {
    padding-top: 3.25rem;
    padding-bottom: 2.75rem;
  }

  h1 {
    font-size: clamp(2.75rem, 14.5vw, 4.5rem);
  }

  .tool-section {
    padding-inline: 0.6rem;
  }

  .calculator-form,
  .result-panel {
    padding: 1.35rem;
  }

  .result-panel {
    min-height: 540px;
  }

  .form-heading,
  .result-topline {
    margin-bottom: 2rem;
  }

  .input-wrap input {
    min-height: 62px;
    padding-right: 7.3rem;
    font-size: 1rem;
  }

  .input-caption {
    right: 0.8rem;
    font-size: 0.65rem;
  }

  .example-row > span {
    width: 100%;
  }

  .form-actions .button,
  .result-actions .button {
    flex: 1 1 100%;
  }

  #percentChange {
    font-size: clamp(3.25rem, 18vw, 5.2rem);
  }

  .result-details {
    grid-template-columns: 1fr;
  }

  .result-details div + div {
    padding-left: 0;
    border-top: 1px solid rgba(238, 245, 239, 0.22);
    border-left: 0;
  }

  .method-heading {
    grid-template-columns: 1fr;
    gap: 0.75rem;
  }

  .display-formula {
    align-items: center;
    font-size: clamp(1.2rem, 6vw, 1.8rem);
  }

  .steps li {
    grid-template-columns: 1fr;
  }

  .steps strong {
    grid-column: 1;
    grid-row: auto;
    text-align: left;
  }

  .footer-inner {
    grid-template-columns: 1fr;
    gap: 0.65rem;
    align-content: center;
  }

  .footer-inner p:nth-child(2) {
    text-align: left;
  }

  .footer-inner a {
    justify-self: start;
  }
}

@media (max-width: 350px) {
  .tool-section {
    padding-inline: 0;
  }

  .tool-grid {
    border-right: 0;
    border-left: 0;
    border-radius: 0;
  }

  .calculator-form,
  .result-panel {
    padding-inline: 1rem;
  }

  .display-formula {
    gap: 0.45rem;
    font-size: 1.1rem;
  }
}

@media (orientation: landscape) and (max-height: 520px) {
  .hero {
    padding-top: 2.5rem;
    padding-bottom: 2.5rem;
  }

  .result-panel {
    min-height: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}

@media print {
  body {
    background: white;
  }

  .site-header,
  .ad-slot,
  .form-actions,
  .result-actions,
  .structured-result,
  .site-footer {
    display: none !important;
  }

  .tool-grid {
    box-shadow: none;
  }
}
