:root {
  --bg: #f6f4ef;
  --surface: #ffffff;
  --surface-2: #faf9f6;
  --ink: #1d2320;
  --ink-2: #4a524e;
  --muted: #6b726e;
  --line: #e3e0d8;
  --accent: #0f5c4d;
  --accent-ink: #ffffff;
  --accent-soft: #e4f0ec;
  --warn: #8a5a00;
  --warn-soft: #fbf1dc;
  --bad: #a3361f;
  --ok: #1f6b45;
  --ok-soft: #e3f2e9;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(20, 30, 25, 0.06), 0 4px 16px rgba(20, 30, 25, 0.05);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121614;
    --surface: #1a201d;
    --surface-2: #161b19;
    --ink: #e8ece9;
    --ink-2: #bcc5c0;
    --muted: #8f9993;
    --line: #2c3430;
    --accent: #5cc3a6;
    --accent-ink: #0b1411;
    --accent-soft: #1d3a32;
    --warn: #f0c060;
    --warn-soft: #3a2f17;
    --bad: #ff8a70;
    --ok: #7fd3a4;
    --ok-soft: #1c3527;
    --shadow: none;
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #121614;
  --surface: #1a201d;
  --surface-2: #161b19;
  --ink: #e8ece9;
  --ink-2: #bcc5c0;
  --muted: #8f9993;
  --line: #2c3430;
  --accent: #5cc3a6;
  --accent-ink: #0b1411;
  --accent-soft: #1d3a32;
  --warn: #f0c060;
  --warn-soft: #3a2f17;
  --bad: #ff8a70;
  --ok: #7fd3a4;
  --ok-soft: #1c3527;
  --shadow: none;
  color-scheme: dark;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.55 var(--font);
}

a {
  color: var(--accent);
}

.wrap {
  max-width: 1180px;
  margin: 0 auto;
  padding: 0 16px;
}

.skip {
  position: absolute;
  left: -9999px;
}

.skip:focus {
  left: 16px;
  top: 8px;
  background: var(--surface);
  padding: 8px 12px;
  z-index: 10;
}

/* Header */
.site-header {
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 56px;
  flex-wrap: wrap;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--ink);
  text-decoration: none;
  font-weight: 650;
}

.brand svg {
  color: var(--accent);
}

nav {
  display: flex;
  gap: 18px;
  flex-wrap: wrap;
}

nav a {
  color: var(--ink-2);
  text-decoration: none;
  font-size: 15px;
}

nav a:hover {
  color: var(--accent);
}

/* Hero */
.hero {
  padding-top: 36px;
  padding-bottom: 20px;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--accent);
  font-weight: 600;
  font-size: 14px;
  letter-spacing: 0.02em;
}

h1 {
  font-family: var(--serif);
  font-weight: 600;
  font-size: clamp(28px, 4.2vw, 44px);
  line-height: 1.12;
  margin: 0 0 12px;
  max-width: 30ch;
  text-wrap: balance;
}

.lede {
  font-size: 18px;
  color: var(--ink-2);
  max-width: 62ch;
  margin: 0 0 16px;
}

.rules-chip {
  display: inline-flex;
  align-items: baseline;
  gap: 8px;
  margin: 0;
  padding: 8px 12px;
  border-radius: 14px;
  background: var(--accent-soft);
  color: var(--ink);
  font-size: 14px;
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  flex: none;
  align-self: center;
}

/* Calculator layout */
.calc {
  display: grid;
  grid-template-columns: minmax(300px, 400px) 1fr;
  gap: 24px;
  align-items: start;
  padding-top: 12px;
  padding-bottom: 40px;
}

.inputs {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 2px 18px 18px;
  position: sticky;
  top: 12px;
  max-height: calc(100vh - 24px);
  overflow: auto;
  scrollbar-width: thin;
}

fieldset {
  border: 0;
  border-bottom: 1px solid var(--line);
  margin: 0;
  padding: 18px 0 14px;
  min-width: 0;
}

/* A floated legend sits inside the fieldset's padding instead of on its top edge. */
legend {
  float: left;
  width: 100%;
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 650;
  font-size: 15px;
  padding: 0;
  margin-bottom: 12px;
}

legend + * {
  clear: both;
}

.step {
  display: inline-grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 12px;
  font-weight: 700;
}

.grid2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0 12px;
  align-items: end;
}

.grid2.top {
  align-items: start;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 10px;
  font-size: 14px;
  color: var(--ink-2);
  min-width: 0;
}

.field > span:first-child {
  font-weight: 550;
}

.field small {
  color: var(--muted);
  font-size: 12.5px;
  line-height: 1.4;
}

input[type="number"],
input[type="email"],
select {
  width: 100%;
  min-width: 0;
  font: inherit;
  font-size: 16px;
  color: var(--ink);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  min-height: 40px;
}

input:focus-visible,
select:focus-visible,
button:focus-visible,
summary:focus-visible,
a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.affix {
  display: flex;
  align-items: stretch;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
  overflow: hidden;
}

.affix:focus-within {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.affix input {
  border: 0;
  border-radius: 0;
  background: transparent;
  outline: none;
}

.affix > span {
  display: grid;
  place-items: center;
  padding: 0 10px;
  color: var(--muted);
  background: var(--surface);
  font-size: 14px;
}

.check {
  display: flex;
  gap: 10px;
  align-items: center;
  font-size: 14.5px;
  margin: 2px 0 12px;
  cursor: pointer;
}

.check input {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
  flex: none;
}

[hidden],
.is-hidden {
  display: none !important;
}

.form-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
  padding-top: 14px;
}

.btn {
  font: inherit;
  font-size: 14.5px;
  font-weight: 600;
  border-radius: 8px;
  padding: 9px 14px;
  min-height: 40px;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: var(--accent-ink);
  cursor: pointer;
}

.btn.ghost {
  background: transparent;
  color: var(--accent);
}

.btn:hover {
  filter: brightness(1.05);
}

/* Results */
.results {
  min-width: 0;
}

.results-h {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin: 22px 0 10px;
  font-weight: 650;
}

.results-h:first-of-type {
  margin-top: 0;
}

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 12px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px 16px 16px;
  min-width: 0;
}

.card h3 {
  font-size: 14px;
  font-weight: 600;
  color: var(--ink-2);
  margin: 0 0 6px;
}

.num {
  font-size: 30px;
  line-height: 1.15;
  font-weight: 700;
  margin: 0 0 8px;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
}

.hero-card {
  border-color: color-mix(in srgb, var(--accent) 45%, var(--line));
  background: linear-gradient(180deg, var(--accent-soft), var(--surface) 70%);
}

.hero-card .num {
  color: var(--accent);
}

.explain {
  margin: 0;
  font-size: 14px;
  color: var(--ink-2);
  line-height: 1.5;
}

.explain.sub {
  margin-top: 8px;
  color: var(--muted);
  font-size: 13px;
}

.warnings {
  background: var(--warn-soft);
  border: 1px solid color-mix(in srgb, var(--warn) 35%, transparent);
  color: var(--ink);
  border-radius: var(--radius);
  padding: 10px 14px;
  margin-bottom: 16px;
  font-size: 14px;
}

.warnings ul {
  margin: 0;
  padding-left: 18px;
}

.table-scroll {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  margin: 10px 0;
}

table {
  border-collapse: collapse;
  width: 100%;
  font-size: 14px;
}

th,
td {
  text-align: left;
  padding: 9px 12px;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}

thead th {
  background: var(--surface-2);
  font-weight: 600;
  color: var(--ink-2);
  font-size: 13px;
}

tbody tr:last-child td {
  border-bottom: 0;
}

.book-table td,
.book-table th {
  text-align: right;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.book-table td:first-child,
.book-table th:first-child {
  text-align: left;
}

.book-table th {
  white-space: normal;
  min-width: 90px;
}

.book-table tbody th,
.book-table thead th:first-child {
  position: sticky;
  left: 0;
  background: var(--surface);
  min-width: 70px;
}

.book-table thead th:first-child {
  background: var(--surface-2);
}

/* Email / save */
.capture {
  margin-top: 24px;
  background: var(--surface);
  border: 1px dashed color-mix(in srgb, var(--accent) 40%, var(--line));
  border-radius: var(--radius);
  padding: 16px 18px;
}

.capture h2 {
  font-family: var(--serif);
  font-size: 22px;
  margin: 0 0 4px;
}

.capture p {
  margin: 4px 0;
}

.email-row {
  display: flex;
  gap: 10px;
  align-items: flex-end;
  flex-wrap: wrap;
  margin-top: 14px;
}

.email-row .grow {
  flex: 1 1 240px;
  margin-bottom: 0;
}

.muted {
  color: var(--muted);
  font-size: 14px;
}

.small {
  font-size: 13px;
}

/* Prose sections */
.prose {
  padding-top: 28px;
  padding-bottom: 28px;
  border-top: 1px solid var(--line);
}

.prose h2 {
  font-family: var(--serif);
  font-size: clamp(24px, 3vw, 32px);
  margin: 0 0 10px;
}

.prose h3 {
  font-size: 17px;
  margin: 24px 0 8px;
}

.prose > p,
.prose li {
  max-width: 78ch;
}

.formulas {
  padding-left: 20px;
}

.formulas li {
  margin-bottom: 6px;
}

.rules td:nth-child(2) {
  white-space: nowrap;
}

.badge {
  display: inline-block;
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: 0.02em;
  border-radius: 999px;
  padding: 1px 8px;
  vertical-align: 1px;
}

.badge.ok {
  background: var(--ok-soft);
  color: var(--ok);
}

.badge.assume {
  background: var(--warn-soft);
  color: var(--warn);
}

details {
  border-bottom: 1px solid var(--line);
  padding: 12px 0;
  max-width: 82ch;
}

summary {
  cursor: pointer;
  font-weight: 600;
}

details p {
  margin: 8px 0 2px;
  color: var(--ink-2);
}

.site-footer {
  border-top: 1px solid var(--line);
  background: var(--surface);
  color: var(--muted);
  font-size: 13.5px;
  padding: 18px 0 28px;
}

.mobile-bar,
.swipe-hint {
  display: none;
}

/* Tablet & phone */
@media (max-width: 900px) {
  .calc {
    grid-template-columns: 1fr;
  }

  .inputs {
    position: static;
    max-height: none;
    overflow: visible;
  }

  .mobile-bar {
    display: flex;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 5;
    gap: 16px;
    align-items: center;
    justify-content: space-between;
    padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
    background: var(--surface);
    border-top: 1px solid var(--line);
    box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.08);
    font-size: 13px;
    transition: transform 0.2s;
  }

  .mobile-bar.away {
    transform: translateY(110%);
  }

  .mobile-bar div {
    display: flex;
    flex-direction: column;
    line-height: 1.2;
  }

  .mobile-bar span {
    color: var(--muted);
  }

  .mobile-bar strong {
    font-size: 18px;
    font-variant-numeric: tabular-nums;
  }

  .mobile-bar a {
    font-weight: 600;
    text-decoration: none;
  }

  .site-footer {
    padding-bottom: 90px;
  }
}

@media (max-width: 720px) {
  .swipe-hint {
    display: block;
    margin-top: 4px;
    font-size: 13px;
    color: var(--muted);
  }
}

@media (max-width: 340px) {
  .grid2 {
    grid-template-columns: 1fr;
  }

  nav {
    gap: 12px;
  }

  .num {
    font-size: 27px;
  }
}

.nowrap {
  white-space: nowrap;
}

/* Cookie banner (built by consent.js) */
.consent {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: calc(16px + env(safe-area-inset-bottom));
  z-index: 20;
  max-width: 680px;
  margin: 0 auto;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px 16px;
  padding: 14px 16px;
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.18);
  font-size: 14px;
}

.consent p {
  margin: 0;
  flex: 1 1 280px;
}

.consent-actions {
  display: flex;
  gap: 8px;
}

.link-btn {
  background: none;
  border: 0;
  padding: 0;
  font: inherit;
  color: var(--accent);
  text-decoration: underline;
  cursor: pointer;
}

/* Shared navigation: current page */
nav a[aria-current="page"] {
  color: var(--accent);
  font-weight: 650;
}

.footer-tools a {
  font-weight: 600;
}

.tag {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 1px 7px;
}

/* Hub: tool cards */
.tools {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 16px;
  padding-top: 8px;
  padding-bottom: 32px;
}

.tool-card {
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  color: var(--ink);
  text-decoration: none;
  transition: border-color 0.15s, transform 0.15s;
}

.tool-card:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
}

.tool-card h2 {
  font-family: var(--serif);
  font-size: 22px;
  margin: 0;
}

.tool-card p {
  margin: 0;
  color: var(--ink-2);
  font-size: 15px;
  flex: 1;
}

.tool-icon {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 700;
  font-size: 18px;
}

.tool-link {
  color: var(--accent);
  font-weight: 650;
}

.facts .num {
  font-size: 24px;
}

/* Segmented control (paperback / hardcover) */
.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  margin-bottom: 12px;
}

.segmented label {
  position: relative;
  cursor: pointer;
}

.segmented input {
  position: absolute;
  opacity: 0;
  inset: 0;
}

.segmented span {
  display: block;
  text-align: center;
  padding: 9px 10px;
  font-size: 14.5px;
  font-weight: 600;
  color: var(--ink-2);
  background: var(--surface-2);
}

.segmented input:checked + span {
  background: var(--accent);
  color: var(--accent-ink);
}

.segmented input:focus-visible + span {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

.book-table tr.current th,
.book-table tr.current td {
  background: var(--accent-soft);
  font-weight: 650;
}

/* Cover layout diagram */
.cover-figure {
  margin: 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
}

.cover-figure svg {
  display: block;
  width: 100%;
  height: auto;
  max-height: 420px;
}

.cover-figure figcaption {
  margin-top: 8px;
}

.cd-bleed {
  fill: var(--warn-soft);
}

.cd-panel {
  fill: var(--surface-2);
}

.cd-spine {
  fill: var(--accent-soft);
  stroke: var(--accent);
  stroke-width: 2;
}

.cd-trim {
  fill: none;
  stroke: var(--ink-2);
  stroke-width: 2;
  stroke-dasharray: 10 8;
}

.cd-barcode {
  fill: var(--surface);
  stroke: var(--muted);
  stroke-width: 2;
}

.cd-label,
.cd-dim,
.cd-spine-label {
  text-anchor: middle;
  dominant-baseline: middle;
  font-family: var(--font);
}

.cd-label {
  fill: var(--ink);
  font-weight: 700;
}

.cd-dim {
  fill: var(--muted);
}

.cd-spine-label {
  fill: var(--accent);
  font-weight: 700;
}

/* "Next tool" call-out */
.next-tool {
  margin-top: 24px;
  background: var(--surface);
  border: 1px dashed color-mix(in srgb, var(--accent) 40%, var(--line));
  border-radius: var(--radius);
  padding: 16px 18px;
}

.next-tool h2 {
  font-family: var(--serif);
  font-size: 22px;
  margin: 0 0 4px;
}

.next-tool p {
  margin: 4px 0 12px;
  color: var(--ink-2);
}

.next-tool .btn {
  display: inline-block;
  text-decoration: none;
  margin: 0 8px 8px 0;
}

.brand img {
  display: block;
  border-radius: 6px;
}

/* Email sign-up messages */
.form-consent {
  margin-top: 8px;
}

.form-status:empty {
  display: none;
}

.form-status {
  margin: 10px 0 0;
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 14px;
  border: 1px solid var(--line);
  background: var(--surface-2);
}

.form-status.ok {
  background: var(--ok-soft);
  border-color: color-mix(in srgb, var(--ok) 35%, transparent);
  color: var(--ink);
}

.form-status.warn,
.form-status.error {
  background: var(--warn-soft);
  border-color: color-mix(in srgb, var(--warn) 35%, transparent);
  color: var(--ink);
}

.form-status.error {
  border-color: color-mix(in srgb, var(--bad) 45%, transparent);
}

.signup-section {
  padding-bottom: 8px;
}

.signup-section .capture {
  margin-top: 0;
}
