:root {
  --bg: #fbfaf7;
  --surface: #ffffff;
  --surface-strong: #f2efe8;
  --ink: #17211d;
  --muted: #5f6d65;
  --line: #ddd7cc;
  --accent: #137c5a;
  --accent-strong: #0d5c43;
  --accent-soft: #dff3ec;
  --gold: #b7791f;
  --gold-soft: #f6ead7;
  --radius: 8px;
  --shadow: 0 18px 50px rgba(27, 37, 31, 0.09);
  --max: 1160px;
  --header: 72px;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

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

a {
  color: inherit;
  text-decoration-color: rgba(19, 124, 90, 0.35);
  text-underline-offset: 0.18em;
}

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

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

button,
input,
select {
  font: inherit;
}

.sr-only {
  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: absolute;
  left: 1rem;
  top: -100px;
  z-index: 20;
  padding: 0.6rem 0.8rem;
  color: #fff;
  background: var(--accent-strong);
  border-radius: var(--radius);
}

.skip-link:focus {
  top: 1rem;
}

.site-header {
  position: sticky;
  top: 0;
  z-index: 10;
  border-bottom: 1px solid rgba(221, 215, 204, 0.8);
  background: rgba(251, 250, 247, 0.92);
  backdrop-filter: blur(14px);
}

.header-inner,
.container {
  width: min(var(--max), calc(100% - 40px));
  margin-inline: auto;
}

.header-inner {
  min-height: var(--header);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1.25rem;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.65rem;
  font-weight: 800;
  text-decoration: none;
}

.brand-mark {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: #fff;
  background: var(--accent);
  box-shadow: inset 0 -7px 0 rgba(0, 0, 0, 0.11);
}

.brand-mark svg {
  width: 22px;
  height: 22px;
}

.site-nav {
  display: flex;
  align-items: center;
  gap: 0.2rem;
  overflow-x: auto;
  scrollbar-width: none;
}

.site-nav::-webkit-scrollbar {
  display: none;
}

.site-nav a {
  white-space: nowrap;
  padding: 0.45rem 0.7rem;
  border-radius: 999px;
  color: var(--muted);
  font-size: 0.92rem;
  font-weight: 700;
  text-decoration: none;
}

.site-nav a:hover,
.site-nav a.active {
  color: var(--accent-strong);
  background: var(--accent-soft);
}

.search-row {
  width: min(var(--max), calc(100% - 40px));
  margin: -0.55rem auto 0.85rem;
}

.formula-search {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 0.5rem;
  max-width: 680px;
}

.formula-search input {
  min-height: 42px;
  padding: 0.55rem 0.75rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
}

.formula-search button {
  min-height: 42px;
  padding: 0.55rem 0.85rem;
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  color: #fff;
  background: var(--accent);
  font-weight: 800;
  cursor: pointer;
}

.search-results {
  position: absolute;
  top: calc(100% + 0.35rem);
  left: 0;
  z-index: 30;
  width: min(100%, 560px);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.search-results:empty {
  display: none;
}

.search-results a,
.search-results span {
  display: block;
  padding: 0.7rem 0.85rem;
  border-top: 1px solid rgba(221, 215, 204, 0.72);
  color: var(--ink);
  text-decoration: none;
}

.search-results a:first-child,
.search-results span:first-child {
  border-top: 0;
}

.search-results a:hover {
  color: var(--accent-strong);
  background: var(--accent-soft);
}

.breadcrumbs {
  padding: 1.1rem 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.breadcrumbs ol {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  padding: 0;
  margin: 0;
  list-style: none;
}

.breadcrumbs li:not(:last-child)::after {
  content: "/";
  margin-left: 0.45rem;
  color: #a49686;
}

.page-hero {
  padding: 3.2rem 0 2.7rem;
  background:
    linear-gradient(110deg, rgba(19, 124, 90, 0.1), transparent 48%),
    linear-gradient(180deg, #fffdfa, var(--bg));
  border-bottom: 1px solid var(--line);
}

.hero-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.04fr) minmax(300px, 0.72fr);
  gap: 3rem;
  align-items: center;
}

.eyebrow,
.section-kicker {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  margin: 0 0 0.75rem;
  color: var(--accent-strong);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
}

.eyebrow::before,
.section-kicker::before {
  content: "";
  width: 0.55rem;
  height: 0.55rem;
  border-radius: 50%;
  background: var(--gold);
}

h1,
h2,
h3 {
  line-height: 1.15;
  margin: 0;
}

h1 {
  max-width: 780px;
  font-size: clamp(2.5rem, 5vw, 5.25rem);
}

h2 {
  font-size: clamp(1.65rem, 3vw, 2.35rem);
}

h3 {
  font-size: 1.15rem;
}

.hero-copy {
  max-width: 720px;
  margin: 1rem 0 0;
  color: var(--muted);
  font-size: clamp(1.05rem, 2vw, 1.22rem);
}

.hero-actions,
.button-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-top: 1.5rem;
}

.button,
button.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 0.7rem 1rem;
  border: 1px solid transparent;
  border-radius: var(--radius);
  color: #fff;
  background: var(--accent);
  font-weight: 800;
  text-decoration: none;
  cursor: pointer;
  transition: transform 160ms ease, background 160ms ease, box-shadow 160ms ease;
}

.button:hover,
button.button:hover {
  color: #fff;
  background: var(--accent-strong);
  transform: translateY(-1px);
  box-shadow: 0 10px 24px rgba(19, 124, 90, 0.18);
}

.button.secondary {
  color: var(--accent-strong);
  background: transparent;
  border-color: rgba(19, 124, 90, 0.35);
}

.button.secondary:hover {
  color: var(--accent-strong);
  background: var(--accent-soft);
  box-shadow: none;
}

.hero-visual,
.diagram-panel,
.calculator,
.result-box,
.note-panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.hero-visual {
  min-height: 330px;
  padding: 1rem;
  display: block;
  overflow: visible;
}

.hero-visual svg {
  width: min(420px, 100%);
}

.hero-formula-math {
  color: #17211d;
  font-size: 15px;
  font-weight: 800;
  line-height: 1;
}

.hero-formula-math .katex {
  font-size: 1em;
}

.hero-visual .diagram-panel {
  width: 100%;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  box-shadow: none;
}

.hero-tool-stack {
  display: grid;
  gap: 0.85rem;
}

.hero-tool-stack .diagram-panel {
  max-height: 230px;
}

.hero-tool-stack .diagram-panel svg {
  max-height: 190px;
}

.section {
  padding: 3.2rem 0;
}

.section + .section {
  border-top: 1px solid rgba(221, 215, 204, 0.72);
}

.section-head {
  max-width: 790px;
  margin-bottom: 1.4rem;
}

.section-head p,
.section-block > p,
.lead {
  color: var(--muted);
}

.prose-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 280px;
  gap: 3rem;
  align-items: start;
}

.prose-main {
  min-width: 0;
}

.section-block {
  scroll-margin-top: 96px;
  margin-bottom: 2.5rem;
}

.section-block > h2 {
  margin-bottom: 0.75rem;
}

.direct-answer-section {
  padding: 1.4rem 0 0;
}

.direct-answer {
  padding: 1rem 1.15rem;
  border-left: 4px solid var(--accent);
  border-radius: var(--radius);
  background: var(--accent-soft);
}

.direct-answer h2 {
  font-size: clamp(1.25rem, 2vw, 1.65rem);
}

.direct-answer p {
  max-width: 74ch;
  color: var(--ink);
  font-size: 1.04rem;
}

.direct-answer .formula {
  background: #fffdfa;
}

.aside {
  position: sticky;
  top: calc(var(--header) + 1.2rem);
  padding: 1.1rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.72);
}

.aside h2,
.aside h3 {
  font-size: 1rem;
  margin-bottom: 0.7rem;
}

.aside a {
  display: block;
  padding: 0.55rem 0;
  border-top: 1px solid rgba(221, 215, 204, 0.7);
  color: var(--accent-strong);
  font-weight: 750;
  text-decoration: none;
}

.aside a:first-of-type {
  border-top: 0;
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.formula-table {
  width: 100%;
  min-width: 650px;
  border-collapse: collapse;
}

.formula-table th,
.formula-table td {
  padding: 0.86rem 0.95rem;
  text-align: left;
  vertical-align: top;
  border-bottom: 1px solid rgba(221, 215, 204, 0.75);
}

.formula-table th {
  color: var(--ink);
  background: var(--surface-strong);
  font-size: 0.9rem;
}

.formula-table tr:last-child td {
  border-bottom: 0;
}

.formula {
  display: inline-flex;
  max-width: 100%;
  align-items: center;
  overflow-x: auto;
  padding: 0.16rem 0.4rem;
  border-radius: 6px;
  color: #111a16;
  background: var(--gold-soft);
  vertical-align: middle;
}

.formula .katex {
  font-size: 1.03em;
  line-height: 1.25;
  white-space: nowrap;
}

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

.formula-card {
  padding: 1rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  box-shadow: var(--shadow);
}

.formula-card h2 {
  font-size: clamp(1.25rem, 2vw, 1.7rem);
}

.formula-card-head {
  margin-bottom: 0.85rem;
}

.formula-card-list {
  display: grid;
  gap: 0.45rem;
}

.formula-card-row {
  display: grid;
  grid-template-columns: minmax(110px, 0.7fr) minmax(0, 1fr);
  gap: 0.75rem;
  align-items: center;
  padding: 0.55rem 0;
  border-top: 1px solid rgba(221, 215, 204, 0.72);
}

.formula-card-row span {
  color: var(--muted);
  font-size: 0.92rem;
  font-weight: 800;
}

.formula-card-row strong {
  font-size: 1.05rem;
  color: var(--ink);
  overflow-x: auto;
}

.formula-card-row strong .katex {
  font-size: 1.08em;
  line-height: 1.25;
  white-space: nowrap;
}

.formula-tools,
.result-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.9rem;
}

.tool-button {
  min-height: 38px;
  padding: 0.48rem 0.65rem;
  border: 1px solid rgba(19, 124, 90, 0.35);
  border-radius: var(--radius);
  color: var(--accent-strong);
  background: #fff;
  font-size: 0.86rem;
  font-weight: 800;
  text-decoration: none;
  cursor: pointer;
}

.tool-button:hover {
  color: var(--accent-strong);
  background: var(--accent-soft);
}

.tool-button.link {
  display: inline-flex;
  align-items: center;
}

.tool-status {
  min-height: 1.3rem;
  margin: 0.55rem 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.diagram-panel {
  padding: 1rem;
  margin: 1rem 0 1.2rem;
}

.diagram-panel figcaption {
  margin-top: 0.8rem;
  color: var(--muted);
  font-size: 0.94rem;
}

.diagram-svg text {
  fill: #22312b;
  font-size: 13px;
  font-weight: 700;
}

.diagram-svg .shape-fill {
  fill: #e6f4ef;
}

.diagram-svg .shape-line {
  stroke: #137c5a;
  stroke-width: 3;
  fill: none;
}

.diagram-svg .guide-line {
  stroke: #b7791f;
  stroke-width: 2;
  stroke-dasharray: 5 5;
  fill: none;
}

.diagram-svg .thin-line {
  stroke: #243a31;
  stroke-width: 2;
  fill: none;
}

.grid-2,
.grid-3,
.related-grid,
.calculator-grid {
  display: grid;
  gap: 1rem;
}

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

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

.link-tile,
.example,
.mistake,
.faq-card,
.practice-item {
  padding: 1rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.link-tile {
  min-height: 100%;
  text-decoration: none;
  transition: border-color 160ms ease, transform 160ms ease, background 160ms ease;
}

.link-tile:hover {
  color: var(--ink);
  border-color: rgba(19, 124, 90, 0.5);
  background: #fff;
  transform: translateY(-2px);
}

.link-tile strong {
  display: block;
  margin-bottom: 0.3rem;
}

.link-tile span,
.example p,
.mistake p,
.faq-card p {
  color: var(--muted);
}

.example ol,
.clean-list,
.mistake-list {
  padding-left: 1.25rem;
}

.example li + li,
.clean-list li + li,
.mistake-list li + li {
  margin-top: 0.35rem;
}

.calculator-section {
  padding: 1.2rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: linear-gradient(180deg, rgba(223, 243, 236, 0.62), rgba(255, 255, 255, 0.9));
}

.calculator {
  padding: 1.1rem;
  box-shadow: none;
}

.calculator-fields {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.8rem;
}

.calculator label {
  display: grid;
  gap: 0.35rem;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 750;
}

.calculator input,
.calculator select {
  width: 100%;
  min-height: 44px;
  padding: 0.6rem 0.7rem;
  border: 1px solid #cfc8bc;
  border-radius: var(--radius);
  color: var(--ink);
  background: #fff;
}

.calculator input:focus,
.calculator select:focus {
  outline: 3px solid rgba(19, 124, 90, 0.16);
  border-color: var(--accent);
}

.calculator-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
  margin-top: 1rem;
}

.calculator-result {
  display: block;
  margin-top: 1rem;
}

.result-box {
  padding: 1rem;
  box-shadow: none;
}

.result-box.error {
  border-color: #c2410c;
  background: #fff7ed;
}

.result-box h3 {
  margin-bottom: 0.6rem;
}

.result-table {
  width: 100%;
  border-collapse: collapse;
  margin: 0.7rem 0;
}

.result-table td {
  padding: 0.42rem 0;
  border-bottom: 1px solid rgba(221, 215, 204, 0.75);
}

.result-table td:last-child {
  text-align: right;
  font-weight: 800;
}

.steps {
  margin-bottom: 0;
}

.practice-list {
  display: grid;
  gap: 0.7rem;
}

.practice-item {
  padding: 0;
}

.practice-item summary {
  padding: 0.85rem 1rem;
}

.practice-item p {
  padding: 0 1rem 1rem;
}

details {
  border-top: 1px solid var(--line);
  padding: 0.9rem 0;
}

details:first-of-type {
  border-top: 0;
}

summary {
  cursor: pointer;
  font-weight: 800;
}

details p {
  margin-bottom: 0;
  color: var(--muted);
}

.note-panel {
  padding: 1.1rem;
  box-shadow: none;
  background: var(--gold-soft);
}

.site-footer {
  padding: 2.4rem 0;
  border-top: 1px solid var(--line);
  color: var(--muted);
  background: #f5f1e9;
}

.footer-grid {
  display: grid;
  grid-template-columns: minmax(240px, 0.85fr) minmax(0, 1.4fr);
  gap: 2rem;
  align-items: start;
}

.footer-about p {
  margin-bottom: 0.7rem;
}

.footer-company {
  font-size: 0.94rem;
}

.footer-links {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 1.25rem;
}

.footer-links div {
  display: grid;
  gap: 0.4rem;
}

.footer-links strong {
  color: var(--ink);
}

.footer-links a,
.footer-company a,
.info-aside a {
  color: var(--accent-strong);
  font-weight: 800;
}

.info-hero {
  min-height: auto;
}

.info-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 1.5rem;
  align-items: start;
}

.info-content {
  display: grid;
  gap: 1.3rem;
}

.info-section {
  display: grid;
  gap: 0.65rem;
}

.info-section + .info-section {
  padding-top: 1.2rem;
  border-top: 1px solid var(--line);
}

.info-section h2,
.info-aside h2 {
  font-size: clamp(1.25rem, 2vw, 1.7rem);
}

.info-list {
  margin: 0;
  padding-left: 1.2rem;
  color: var(--muted);
}

.info-list li + li {
  margin-top: 0.35rem;
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition: none !important;
  }
}

@media (max-width: 920px) {
  .header-inner {
    align-items: flex-start;
    flex-direction: column;
    justify-content: center;
    padding: 0.9rem 0;
  }

  .site-nav {
    width: 100%;
    padding-bottom: 0.1rem;
  }

  .search-row {
    margin-top: 0;
  }

  .hero-grid,
  .prose-grid,
  .footer-grid,
  .info-layout {
    grid-template-columns: 1fr;
  }

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

  .aside {
    position: static;
  }

  .grid-3,
  .related-grid,
  .calculator-grid,
  .formula-card-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

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

@media (max-width: 640px) {
  :root {
    --header: 120px;
  }

  .header-inner,
  .container {
    width: min(100% - 28px, var(--max));
  }

  .page-hero {
    padding: 2rem 0;
  }

  h1 {
    font-size: clamp(2.1rem, 13vw, 3.2rem);
  }

  .hero-visual {
    min-height: 240px;
  }

  .section {
    padding: 2.2rem 0;
  }

  .grid-2,
  .grid-3,
  .related-grid,
  .calculator-grid,
  .formula-card-grid,
  .calculator-fields {
    grid-template-columns: 1fr;
  }

  .formula-search {
    grid-template-columns: 1fr;
  }

  .formula-search button {
    width: 100%;
  }

  .footer-links {
    grid-template-columns: 1fr;
  }

  .formula-card-row {
    grid-template-columns: 1fr;
    gap: 0.25rem;
  }

  .formula-table {
    min-width: 560px;
  }
}
