:root {
  --paper: #FAFAF8;
  --ink: #1D1D1F;
  --ink-soft: #6E6E73;
  --pine: #2C5F4F;
  --pine-soft: #E4ECE8;
  --amber: #C4622D;
  --amber-soft: #F5E4D9;
  --red: #B3261E;
  --red-soft: #FBEAE9;
  --line: #E8E6DE;
  --line-strong: #D8D5CB;
  --white: #FFFFFF;

  --font-display: 'Fraunces', Georgia, serif;
  --font-body: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, monospace;

  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --shadow-soft: 0 1px 2px rgba(29,29,31,0.04), 0 8px 24px rgba(29,29,31,0.06);
  --shadow-float: 0 4px 12px rgba(29,29,31,0.08), 0 16px 40px rgba(29,29,31,0.12);
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0;
  background: var(--paper); color: var(--ink);
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
}

/* ===== TOPBAR (shared shell) ===== */
.topbar {
  height: 64px; display: flex; align-items: center;
  justify-content: space-between; padding: 0 24px;
  border-bottom: 1px solid var(--line); background: var(--white);
  position: sticky; top: 0; z-index: 30;
}
.topbar__brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--ink); }
.topbar__mark { color: var(--pine); width: 26px; height: 26px; flex-shrink: 0; }
.topbar__name { font-family: var(--font-display); font-size: 19px; font-weight: 600; }
.topbar__actions { display: flex; align-items: center; gap: 6px; }

.btn { font-size: 14px; font-weight: 600; border-radius: 100px; border: none; cursor: pointer; white-space: nowrap; display: inline-flex; align-items: center; text-decoration: none; transition: background 0.15s, color 0.15s, opacity 0.15s; }
.btn--primary { background: var(--ink); color: var(--white); padding: 10px 18px; }
.btn--primary:hover { opacity: 0.88; }
.btn--ghost { background: none; color: var(--ink-soft); padding: 9px 14px; }
.btn--ghost:hover { background: var(--paper); color: var(--ink); }
.btn--current { color: var(--pine); background: var(--pine-soft); }
.btn:focus-visible { outline: 2px solid var(--pine); outline-offset: 2px; }

/* ===== PAGE LAYOUT ===== */
.page-shell { max-width: 760px; margin: 0 auto; padding: 48px 24px 80px; }

.eyebrow {
  display: inline-flex; align-items: center; gap: 8px;
  font-size: 12.5px; font-weight: 600; color: var(--pine);
  text-transform: uppercase; letter-spacing: 0.04em; margin-bottom: 16px;
}
.eyebrow__dot { width: 6px; height: 6px; border-radius: 50%; background: var(--amber); }

.page-shell h1 {
  font-family: var(--font-display); font-size: 36px; line-height: 1.15;
  font-weight: 600; letter-spacing: -0.01em; margin: 0 0 14px;
}
.page-dek {
  font-size: 17px; line-height: 1.55; color: var(--ink-soft);
  margin: 0 0 36px;
}

/* ===== CROSS SETUP ===== */
.setup-card {
  background: var(--white); border: 1px solid var(--line);
  border-radius: var(--radius-lg); padding: 28px;
  box-shadow: var(--shadow-soft); margin-bottom: 28px;
}
.setup-card__title {
  font-family: var(--font-display); font-size: 17px; font-weight: 600;
  margin: 0 0 20px;
}

.cross-type-row {
  display: flex; gap: 8px; margin-bottom: 24px;
}
.cross-type-btn {
  flex: 1; padding: 10px 14px; border: 1.5px solid var(--line-strong);
  border-radius: var(--radius-sm); background: var(--white);
  font-family: var(--font-body); font-size: 14px; font-weight: 600;
  color: var(--ink); cursor: pointer; transition: border-color 0.15s, background 0.15s;
  text-align: center;
}
.cross-type-btn:hover { border-color: var(--pine); background: var(--pine-soft); }
.cross-type-btn.is-active { border-color: var(--pine); background: var(--pine-soft); color: var(--pine); }

.parent-inputs { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }

.parent-col label {
  display: block; font-size: 12.5px; font-weight: 600;
  color: var(--ink-soft); text-transform: uppercase; letter-spacing: 0.04em;
  margin-bottom: 8px;
}

.genotype-input {
  width: 100%; padding: 10px 14px; border: 1.5px solid var(--line-strong);
  border-radius: var(--radius-sm); font-family: var(--font-mono);
  font-size: 18px; text-align: center; background: var(--white);
  color: var(--ink); transition: border-color 0.15s;
}
.genotype-input:focus { outline: none; border-color: var(--pine); }
.genotype-input.is-invalid { border-color: var(--red); background: var(--red-soft); }

.input-hint {
  font-size: 12.5px; color: var(--ink-soft); margin-top: 6px; text-align: center;
}
.input-error {
  font-size: 12.5px; color: var(--red); margin-top: 6px; text-align: center;
  display: none;
}
.input-error.is-visible { display: block; }

.preset-row {
  margin-top: 20px; padding-top: 18px; border-top: 1px solid var(--line);
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
}
.preset-row__label {
  font-size: 12.5px; font-weight: 600; color: var(--ink-soft);
  text-transform: uppercase; letter-spacing: 0.04em; flex-shrink: 0;
}
.preset-btn {
  padding: 6px 12px; border: 1px solid var(--line-strong); border-radius: 100px;
  background: var(--white); font-size: 12.5px; font-weight: 500;
  color: var(--ink); cursor: pointer; transition: border-color 0.15s, background 0.15s;
  font-family: var(--font-body);
}
.preset-btn:hover { border-color: var(--pine); background: var(--pine-soft); color: var(--pine); }

.cross-btn {
  width: 100%; margin-top: 22px; padding: 13px; font-size: 15px;
}

/* ===== PUNNETT GRID ===== */
.results-area { display: none; }
.results-area.is-visible { display: block; }

.punnett-grid-wrap {
  background: var(--white); border: 1px solid var(--line);
  border-radius: var(--radius-lg); padding: 28px;
  box-shadow: var(--shadow-soft); margin-bottom: 24px; overflow-x: auto;
}

.punnett-table {
  border-collapse: collapse; width: 100%; table-layout: fixed;
  font-family: var(--font-mono); font-size: 17px;
}
.punnett-table th {
  font-family: var(--font-body); font-size: 13px; font-weight: 600;
  color: var(--ink-soft); letter-spacing: 0.04em;
  padding: 10px 8px;
}
.punnett-table .corner { background: none; border: none; }
.punnett-table .parent-allele {
  background: var(--pine-soft); color: var(--pine); font-family: var(--font-mono);
  font-size: 18px; font-weight: 500; text-align: center; padding: 12px 8px;
  border: 1px solid var(--line);
}
.punnett-table .parent-allele--col { border-top-left-radius: var(--radius-sm); border-top-right-radius: var(--radius-sm); }
.punnett-table .parent-allele--row { border-top-left-radius: var(--radius-sm); border-bottom-left-radius: var(--radius-sm); }

.punnett-table td.cell {
  border: 1px solid var(--line); text-align: center; padding: 14px 8px;
  vertical-align: middle; transition: background 0.15s;
  position: relative;
}
.punnett-table td.cell:hover { background: var(--paper); }

.cell__genotype { font-size: 18px; font-weight: 500; display: block; }
.cell__phenotype {
  font-family: var(--font-body); font-size: 11px; font-weight: 600;
  letter-spacing: 0.03em;
  margin-top: 4px; display: block;
}
.cell__phenotype--dominant { color: var(--pine); }
.cell__phenotype--recessive { color: var(--amber); }
.cell__phenotype--pheno-AB { color: var(--pine); }
.cell__phenotype--pheno-Ab { color: var(--amber); }
.cell__phenotype--pheno-aB { color: #7a5c9e; }
.cell__phenotype--pheno-ab { color: var(--ink-soft); }

.ratio-row__bar--dominant  { background: var(--pine); }
.ratio-row__bar--recessive { background: var(--amber); }
.ratio-row__bar--pheno-AB  { background: var(--pine); }
.ratio-row__bar--pheno-Ab  { background: var(--amber); }
.ratio-row__bar--pheno-aB  { background: #7a5c9e; }
.ratio-row__bar--pheno-ab  { background: var(--line-strong); }

/* Dihybrid cells are tighter */
.punnett-table.is-dihybrid td.cell { padding: 10px 6px; }
.punnett-table.is-dihybrid .cell__genotype { font-size: 15px; }

/* ===== RATIOS SUMMARY ===== */
.ratios-card {
  background: var(--white); border: 1px solid var(--line);
  border-radius: var(--radius-lg); padding: 28px;
  box-shadow: var(--shadow-soft); margin-bottom: 24px;
}
.ratios-card__title {
  font-family: var(--font-display); font-size: 17px; font-weight: 600;
  margin: 0 0 18px;
}

.ratio-section { margin-bottom: 22px; }
.ratio-section:last-child { margin-bottom: 0; }
.ratio-section__label {
  font-size: 12.5px; font-weight: 600; color: var(--ink-soft);
  text-transform: uppercase; letter-spacing: 0.04em; margin-bottom: 10px;
}

.ratio-bar-wrap { display: flex; flex-direction: column; gap: 8px; }

.ratio-row { display: flex; align-items: center; gap: 12px; }
.ratio-row__label {
  font-family: var(--font-mono); font-size: 14px;
  min-width: 80px; text-align: right; flex-shrink: 0;
}
.ratio-row__bar-track {
  flex: 1; height: 26px; background: var(--paper);
  border-radius: 4px; overflow: hidden; border: 1px solid var(--line);
}
.ratio-row__bar { height: 100%; border-radius: 3px; transition: width 0.4s ease; min-width: 2px; }
.ratio-row__pct {
  font-size: 13px; font-weight: 600; min-width: 52px; text-align: left;
  color: var(--ink-soft);
}

/* ===== EXPLANATION ===== */
.explain-card {
  background: var(--white); border: 1px solid var(--line);
  border-radius: var(--radius-lg); padding: 28px;
  box-shadow: var(--shadow-soft); margin-bottom: 24px;
}
.explain-card__title {
  font-family: var(--font-display); font-size: 17px; font-weight: 600;
  margin: 0 0 14px;
}
.explain-card p {
  font-size: 15px; line-height: 1.65; color: var(--ink); margin: 0 0 12px;
}
.explain-card p:last-child { margin-bottom: 0; }

/* ===== CTA ===== */
.cta-card {
  background: var(--white); border: 1px solid var(--line);
  border-radius: var(--radius-lg); padding: 28px;
  box-shadow: var(--shadow-soft); text-align: center; margin-top: 12px;
}
.cta-card h3 { margin: 0 0 8px; font-family: var(--font-display); font-size: 19px; }
.cta-card p { color: var(--ink-soft); font-size: 14.5px; margin: 0 0 18px; }

/* ===== FOOTER ===== */
.disclaimer {
  padding: 18px 24px; border-top: 1px solid var(--line); background: var(--white);
  font-size: 12.5px; line-height: 1.6; color: var(--ink-soft); text-align: center;
}
.disclaimer strong { color: var(--ink); }

/* ===== RESPONSIVE ===== */
@media (max-width: 640px) {
  .topbar { padding: 0 14px; }
  .topbar__name { display: none; }
  .topbar__actions .btn--ghost { padding: 8px 10px; font-size: 12.5px; }
  .page-shell { padding: 32px 16px 60px; }
  .page-shell h1 { font-size: 26px; }
  .page-dek { font-size: 15px; }
  .setup-card, .punnett-grid-wrap, .ratios-card, .explain-card { padding: 20px; }
  .parent-inputs { grid-template-columns: 1fr; gap: 16px; }
  .punnett-table { font-size: 14px; }
  .punnett-table .parent-allele { font-size: 15px; }
  .cell__genotype { font-size: 15px; }
  .punnett-table.is-dihybrid .cell__genotype { font-size: 12px; }
  .ratio-row__label { min-width: 60px; font-size: 12px; }
}

@supports (padding: max(0px)) {
  .topbar { padding-left: max(16px, env(safe-area-inset-left)); padding-right: max(16px, env(safe-area-inset-right)); }
  .disclaimer { padding-bottom: max(9px, env(safe-area-inset-bottom)); }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}

/* ===== SEO CONTENT SECTIONS ===== */
.tool-explainer,
.tool-faq,
.tool-related {
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 28px;
  box-shadow: var(--shadow-soft);
  margin-bottom: 20px;
  max-width: 760px;
  margin-left: auto;
  margin-right: auto;
}
.tool-explainer h2,
.tool-faq h2,
.tool-related h2 {
  font-family: var(--font-display);
  font-size: 19px;
  font-weight: 600;
  margin-bottom: 14px;
}
.tool-explainer h3 {
  font-family: var(--font-display);
  font-size: 16px;
  font-weight: 600;
  margin: 18px 0 8px;
}
.tool-explainer p,
.tool-faq p,
.tool-related p {
  font-size: 15px;
  line-height: 1.7;
  color: var(--ink);
  margin-bottom: 12px;
}
.tool-explainer p:last-child,
.tool-faq p:last-child { margin-bottom: 0; }

/* ===== FAQ ACCORDION ===== */
.faq-item {
  border-bottom: 1px solid var(--line);
}
.faq-item:last-child { border-bottom: none; }

.faq-item summary {
  list-style: none;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 16px 0;
  cursor: pointer;
  user-select: none;
  font-family: var(--font-display);
  font-size: 15.5px;
  font-weight: 600;
  color: var(--ink);
  transition: color 0.15s;
}
.faq-item summary::-webkit-details-marker { display: none; }
.faq-item summary::marker { display: none; }
.faq-item summary:hover { color: var(--pine); }
.faq-item summary:focus-visible { outline: 2px solid var(--pine); outline-offset: 2px; border-radius: 4px; }

.faq-item__chevron {
  width: 18px; height: 18px;
  flex-shrink: 0;
  color: var(--ink-soft);
  transition: transform 0.2s ease, color 0.15s;
}
.faq-item[open] .faq-item__chevron {
  transform: rotate(180deg);
  color: var(--pine);
}
.faq-item[open] summary { color: var(--pine); }

.faq-item p {
  font-size: 14.5px;
  line-height: 1.65;
  color: var(--ink);
  margin: 0 0 16px;
  padding-right: 34px; /* align with summary text, not chevron */
}

.tool-related ul { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 10px; }
.tool-related li { font-size: 14.5px; color: var(--ink-soft); }
.tool-related a { color: var(--pine); font-weight: 600; text-decoration: none; }
.tool-related a:hover { text-decoration: underline; }

@media (max-width: 640px) {
  .tool-explainer, .tool-faq, .tool-related { padding: 20px; }
}
