:root {
  --brick: #9E331E;
  --brick-dark: #7A2413;
  --gold: #8A5A10;
  --gold-bg: #F6ECD8;
  --cream: #FAF6EE;
  --paper: #FFFDF9;
  --panel: #F3ECE0;
  --ink: #1C1814;
  --muted: #574E45;
  --line: #DED3C1;
  --pass: #185C37;
  --pass-bg: #E7F4EC;
}
* { box-sizing: border-box; }
html { scroll-behavior: smooth; -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--cream);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  font-size: 17px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}
h1, h2, h3, .serif {
  font-family: Georgia, 'Times New Roman', serif;
  line-height: 1.22;
  color: var(--ink);
}
a {
  color: var(--brick);
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
}
a:hover { color: var(--brick-dark); }
a:focus-visible, button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, summary:focus-visible {
  outline: 3px solid var(--brick);
  outline-offset: 2px;
}
.skip {
  position: absolute;
  left: -9999px;
  top: 8px;
  background: var(--brick);
  color: #FFFFFF;
  padding: 10px 16px;
  border-radius: 6px;
  z-index: 100;
  font-weight: 700;
  text-decoration: none;
}
.skip:focus { left: 12px; color: #FFFFFF; }
img, svg { max-width: 100%; height: auto; }
.wrap {
  max-width: 1120px;
  margin: 0 auto;
  padding-left: 20px;
  padding-right: 20px;
}
.narrow { max-width: 820px; }

/* Header & Nav — preserves horizontal .wrap padding at 390px */
.site-header {
  background: var(--cream);
  border-bottom: 2px solid var(--ink);
  position: sticky;
  top: 0;
  z-index: 40;
}
.header-in {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding-top: 12px;
  padding-bottom: 10px;
  flex-wrap: wrap;
}
.logo {
  display: inline-flex;
  align-items: center;
  text-decoration: none;
}
.logo img {
  display: block;
  width: 164px;
  height: 40px;
}
.main-nav {
  display: flex;
  align-items: center;
  gap: 18px;
  flex-wrap: wrap;
}
.main-nav a {
  color: var(--ink);
  text-decoration: none;
  font-weight: 600;
  font-size: 15px;
  padding: 4px 2px;
}
.main-nav a:hover, .main-nav a[aria-current="page"] {
  color: var(--brick);
  text-decoration: underline;
  text-Thickness: 2px;
}
.sub-nav {
  border-top: 1px solid var(--line);
  padding-top: 8px;
  padding-bottom: 8px;
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  font-size: 13.5px;
  align-items: center;
}
.sub-nav span {
  color: var(--muted);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 12px;
}
.sub-nav a {
  color: var(--ink);
  text-decoration: none;
  font-weight: 600;
}
.sub-nav a:hover { color: var(--brick); }

/* Hero & Sections */
.hero {
  padding-top: 44px;
  padding-bottom: 36px;
  border-bottom: 1px solid var(--line);
}
.kicker {
  display: inline-block;
  font-size: 12.5px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--brick);
  margin-bottom: 8px;
}
.hero h1 {
  font-size: clamp(30px, 4.6vw, 48px);
  margin: 4px 0 14px;
  font-weight: 700;
  max-width: 18em;
}
.lede {
  font-size: 19px;
  color: var(--muted);
  max-width: 42em;
  margin: 0 0 22px;
}
.section {
  padding-top: 38px;
  padding-bottom: 38px;
  border-bottom: 1px solid var(--line);
}
.section:last-of-type { border-bottom: none; }
.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}
.section h2 {
  font-size: 28px;
  margin: 0 0 6px;
}
.section .sub {
  color: var(--muted);
  margin: 0;
  max-width: 46em;
  font-size: 16px;
}

/* Cards & Grids */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(290px, 1fr));
  gap: 18px;
}
.cat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 16px;
}
.card {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  transition: border-color 0.15s ease;
}
.card:hover { border-color: var(--brick); }
.card .cat-tag {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--brick);
}
.card h3 {
  margin: 0;
  font-size: 20px;
}
.card h3 a {
  color: var(--ink);
  text-decoration: none;
}
.card h3 a:hover { color: var(--brick); }
.card p {
  margin: 0;
  color: var(--muted);
  font-size: 15px;
  flex: 1;
}
.card-foot {
  margin-top: 8px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--brick);
}
.cat-card {
  background: var(--paper);
  border: 1px solid var(--line);
  border-left: 5px solid var(--brick);
  border-radius: 10px;
  padding: 18px;
  text-decoration: none;
  color: var(--ink);
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.cat-card:hover { background: var(--panel); }
.cat-card strong {
  font-family: Georgia, serif;
  font-size: 21px;
  color: var(--ink);
}
.cat-card span {
  font-size: 14.5px;
  color: var(--muted);
}

/* Buttons & Pills */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: var(--brick);
  color: #FFFFFF;
  font-weight: 700;
  font-size: 15px;
  padding: 10px 18px;
  border-radius: 8px;
  border: 1.5px solid var(--brick);
  text-decoration: none;
  cursor: pointer;
  font-family: inherit;
}
.btn:hover {
  background: var(--brick-dark);
  border-color: var(--brick-dark);
  color: #FFFFFF;
}
.btn.ghost {
  background: transparent;
  color: var(--brick);
}
.btn.ghost:hover {
  background: var(--gold-bg);
  color: var(--brick-dark);
}
.chip {
  display: inline-block;
  background: var(--panel);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 13px;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  text-align: left;
}
.chip:hover {
  border-color: var(--brick);
  color: var(--brick);
  background: var(--gold-bg);
}

/* Interactive Tool Workbench */
.workbench {
  display: grid;
  grid-template-columns: 1.05fr 0.95fr;
  gap: 24px;
  margin: 24px 0 32px;
  align-items: start;
}
.panel {
  background: var(--paper);
  border: 1.5px solid var(--line);
  border-radius: 12px;
  padding: 24px;
}
.panel-results {
  background: var(--paper);
  border: 2px solid var(--ink);
  border-radius: 12px;
  padding: 24px;
}
.preset-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 18px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--line);
}
.preset-label {
  width: 100%;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin-bottom: 2px;
}
.field-grid {
  display: flex;
  flex-direction: column;
  gap: 15px;
}
.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
}
.field label {
  font-size: 14.5px;
  font-weight: 700;
  color: var(--ink);
}
.field input, .field select, .field textarea {
  width: 100%;
  padding: 10px 12px;
  font-size: 16px;
  font-family: inherit;
  color: var(--ink);
  background: #FFFFFF;
  border: 1.5px solid #94887B;
  border-radius: 7px;
}
.field textarea {
  min-height: 98px;
  resize: vertical;
  line-height: 1.5;
}
.primary-result {
  background: var(--gold-bg);
  border-left: 5px solid var(--brick);
  padding: 16px 18px;
  border-radius: 0 10px 10px 0;
  margin-bottom: 18px;
}
.primary-result .pr-label {
  font-size: 12.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--brick);
}
.primary-result .pr-val {
  font-family: Georgia, serif;
  font-size: clamp(24px, 3.2vw, 34px);
  font-weight: 700;
  color: var(--ink);
  margin: 4px 0;
  word-break: break-word;
}
.primary-result .pr-sub {
  font-size: 14px;
  color: var(--muted);
}
.metrics-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 18px;
}
.metric-box {
  background: var(--cream);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px 14px;
}
.metric-box .m-label {
  font-size: 12.5px;
  color: var(--muted);
  font-weight: 600;
}
.metric-box .m-val {
  font-size: 17px;
  font-weight: 700;
  color: var(--ink);
  margin-top: 2px;
  word-break: break-word;
}
.breakdown-list {
  border-top: 1px solid var(--line);
  padding-top: 12px;
  margin-bottom: 18px;
}
.breakdown-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 7px 0;
  border-bottom: 1px dashed var(--line);
  font-size: 14.5px;
}
.breakdown-row span:first-child { color: var(--muted); }
.breakdown-row strong {
  color: var(--ink);
  text-align: right;
  word-break: break-word;
}

/* AI Advisor Drawer */
.advisor-box {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 2px solid var(--line);
}
.advisor-panel {
  margin-top: 14px;
  background: var(--cream);
  border: 1.5px solid var(--brick);
  border-radius: 10px;
  padding: 16px;
}
.advisor-output {
  margin-top: 12px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  font-size: 15px;
  white-space: pre-wrap;
  line-height: 1.6;
}

/* Editorial Content & Formula Blocks */
.editorial h2 {
  font-size: 26px;
  margin: 34px 0 12px;
}
.editorial p, .editorial li {
  font-size: 16.5px;
  color: var(--ink);
}
.formula-card {
  background: var(--ink);
  color: var(--cream);
  border-radius: 10px;
  padding: 20px 22px;
  margin: 18px 0;
}
.formula-card code {
  display: block;
  font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
  font-size: 16px;
  color: #F7C86A;
  margin-bottom: 12px;
  word-break: break-word;
}
.formula-vars {
  margin: 0;
  padding-left: 18px;
  font-size: 14.5px;
  color: #EAE0D0;
}
.formula-vars li {
  color: #EAE0D0;
  margin: 5px 0;
}
.example-card {
  background: var(--gold-bg);
  border: 1px solid var(--line);
  border-left: 5px solid var(--gold);
  border-radius: 8px;
  padding: 18px 20px;
  margin: 18px 0;
}
.tips-list {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 18px 22px 18px 38px;
}
.tips-list li { margin: 8px 0; }
details {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 13px 16px;
  margin: 10px 0;
}
summary {
  font-weight: 700;
  cursor: pointer;
  font-family: Georgia, serif;
  font-size: 18px;
}
details p {
  margin: 10px 0 2px;
  color: var(--muted);
}

/* Zero-CLS Reserved Ad Slot (hidden until Worker env.ADSENSE_CLIENT activates) */
.ad-slot {
  min-height: 280px;
  margin: 28px 0;
  background: var(--paper);
  border: 1px dashed var(--line);
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  padding: 12px;
}
.ad-slot[hidden] {
  display: none !important;
}
.ad-slot-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--muted);
  margin-bottom: 6px;
}

/* Search Bar on Home */
.search-bar {
  display: flex;
  gap: 10px;
  max-width: 560px;
  margin: 18px 0 8px;
  flex-wrap: wrap;
}
.search-bar input {
  flex: 1;
  min-width: 220px;
  padding: 11px 14px;
  font-size: 16px;
  border: 1.5px solid var(--ink);
  border-radius: 8px;
  background: var(--paper);
}

/* Footer */
.site-footer {
  border-top: 2px solid var(--ink);
  margin-top: 56px;
  background: #F2E9D8;
}
.footer-in {
  padding-top: 36px;
  padding-bottom: 28px;
  display: grid;
  grid-template-columns: 1.8fr 1fr 1fr;
  gap: 28px;
}
.site-footer h4 {
  margin: 0 0 10px;
  font-size: 13.5px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink);
}
.site-footer ul {
  list-style: none;
  margin: 0;
  padding: 0;
}
.site-footer li { margin: 7px 0; }
.site-footer a {
  color: var(--ink);
  text-decoration: none;
  font-size: 15px;
}
.site-footer a:hover { color: var(--brick); text-decoration: underline; }
.footer-disc {
  border-top: 1px solid var(--line);
  padding-top: 16px;
  padding-bottom: 26px;
  font-size: 13.5px;
  color: var(--muted);
}

@media (max-width: 820px) {
  .workbench { grid-template-columns: 1fr; }
  .footer-in { grid-template-columns: 1fr; }
}
@media (max-width: 520px) {
  .metrics-grid { grid-template-columns: 1fr; }
  .hero { padding-top: 28px; padding-bottom: 24px; }
  body { font-size: 16px; }
}
