/* ==========================================================================
   layout.css — page shell, header, footer, ad slots, related tools, prose
   Requires tokens.css + base.css.

   AD SLOT / CLS DOCTRINE  (the important part of this file)
   --------------------------------------------------------------------------
   Every slot reserves its exact box in the FIRST paint, before any ad script
   runs. Fill, no-fill, blocked and slow-network all produce identical layout,
   so CLS contribution is 0 in every case.

   Rules, all enforced below:
     1. Reserved height is a fixed px value from tokens.css, not a percentage,
        not aspect-ratio, not min-height on a growable flex child.
     2. The reserved box includes the "Advertisement" label line and its gap,
        so the label cannot push content either.
     3. `contain: size layout` stops a mis-sized creative from resizing the
        reservation. `overflow: clip` stops it painting outside.
     4. A slot that is not shown at a breakpoint is `display: none`, which
        reserves nothing at all. It never reserves space it will not use.
     5. Slots NEVER sit between the H1 and the result on mobile. The top slot
        is desktop-only for exactly this reason — see Design-System.md.

   Slot inventory:
     .ad-slot--top       970x90 / 728x90 leaderboard   >=1024px only
     .ad-slot--sidebar   300x600 half page, sticky     >=1120px only
     .ad-slot--result    300x250 -> 336x280            all widths, below result
     .ad-slot--article   300x250 -> 336x280            all widths, mid-article
   ========================================================================== */

:root {
  --header-h: 3.5rem;
}

/* --------------------------------------------------------------------------
   1. SHELL
   -------------------------------------------------------------------------- */
.container {
  width: 100%;
  max-width: var(--w-page);
  margin-inline: auto;
  padding-inline: var(--gutter);
}

@media (min-width: 48em) {
  .container {
    padding-inline: var(--gutter-lg);
  }
}

.page {
  display: flex;
  flex-direction: column;
  min-height: 100svh;
}

.page__body {
  flex: 1 0 auto;
  /* Tight on mobile: every pixel above the tool is a pixel the answer
     does not get above the fold on a 375x667 phone. */
  padding-block: var(--sp-3) var(--sp-10);
}

@media (min-width: 48em) {
  .page__body {
    padding-block: var(--sp-6) var(--sp-12);
  }
}

/* Main column + optional sticky ad rail. Single column until 1120px, so the
   rail never squeezes the calculator on a tablet. */
.shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: var(--sp-8);
  align-items: start;
}

@media (min-width: 70em) {
  .shell--with-rail {
    grid-template-columns: minmax(0, 1fr) var(--ad-w-skyscraper);
    gap: var(--sp-10);
  }
}

.main {
  min-width: 0;
  max-width: var(--w-main);
  width: 100%;
}

.shell--with-rail .main {
  max-width: none;
}

.rail {
  display: none;
}

@media (min-width: 70em) {
  .rail {
    display: block;
    position: sticky;
    top: calc(var(--header-h) + var(--sp-4));
    width: var(--ad-w-skyscraper);
  }
}

.section {
  margin-top: var(--sp-10);
}

.section__title {
  font-size: var(--fs-2xl);
  margin-bottom: var(--sp-4);
}

.section__title--rule {
  padding-bottom: var(--sp-3);
  border-bottom: var(--bw-thick) solid var(--accent-line);
}

/* --------------------------------------------------------------------------
   2. HEADER
   -------------------------------------------------------------------------- */
.site-header {
  position: sticky;
  top: 0;
  z-index: var(--z-header);
  min-height: var(--header-h);
  background-color: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(180%) blur(10px);
  border-bottom: var(--bw) solid var(--border);
}

@supports not (backdrop-filter: blur(1px)) {
  .site-header {
    background-color: var(--bg);
  }
}

.site-header__inner {
  display: flex;
  align-items: center;
  gap: var(--sp-4);
  min-height: var(--header-h);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  font-weight: var(--fw-bold);
  font-size: var(--fs-lg);
  letter-spacing: var(--tracking-tight);
  color: var(--text-strong);
  text-decoration: none;
  white-space: nowrap;
}

.brand:hover {
  color: var(--text-strong);
}

/* Identity mark: a 3px accent bar. No logo file, no image request, and it is
   the one place the site's colour appears unconditionally in the chrome. */
.brand__mark {
  width: 0.5rem;
  height: 1.35rem;
  border-radius: var(--r-pill);
  background: linear-gradient(
    to bottom,
    var(--a-400),
    var(--accent-fill)
  );
  flex: none;
}

.brand__accent {
  color: var(--accent);
}

.site-nav {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: var(--sp-1);
}

.site-nav__link {
  display: inline-flex;
  align-items: center;
  min-height: 2.5rem;
  padding-inline: var(--sp-3);
  border-radius: var(--r-sm);
  font-size: var(--fs-sm);
  font-weight: var(--fw-medium);
  color: var(--text-muted);
  text-decoration: none;
}

.site-nav__link:hover {
  background-color: var(--surface-sunken);
  color: var(--text-strong);
}

.site-nav__link[aria-current="page"] {
  color: var(--accent);
  font-weight: var(--fw-semibold);
}

/* Hide secondary nav labels on very small phones; the brand and toggle stay. */
@media (max-width: 26em) {
  .site-nav__link--optional {
    display: none;
  }
}

.theme-toggle {
  display: inline-grid;
  place-items: center;
  width: 2.5rem;
  height: 2.5rem;
  border-radius: var(--r-sm);
  color: var(--text-muted);
  cursor: pointer;
  flex: none;
}

.theme-toggle:hover {
  background-color: var(--surface-sunken);
  color: var(--text-strong);
}

.theme-toggle svg {
  width: 1.15rem;
  height: 1.15rem;
}

/* Show sun in dark theme, moon in light. Both icons ship; CSS picks. */
.theme-toggle .icon-sun {
  display: none;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-toggle .icon-sun {
    display: block;
  }
  :root:not([data-theme="light"]) .theme-toggle .icon-moon {
    display: none;
  }
}
:root[data-theme="dark"] .theme-toggle .icon-sun {
  display: block;
}
:root[data-theme="dark"] .theme-toggle .icon-moon {
  display: none;
}
:root[data-theme="light"] .theme-toggle .icon-sun {
  display: none;
}
:root[data-theme="light"] .theme-toggle .icon-moon {
  display: block;
}

/* --------------------------------------------------------------------------
   3. BREADCRUMBS
   -------------------------------------------------------------------------- */
.breadcrumbs {
  font-size: var(--fs-xs);
  color: var(--text-subtle);
  margin-bottom: var(--sp-2);
}

.breadcrumbs ol {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--sp-1) var(--sp-2);
  list-style: none;
  padding: 0;
  margin: 0;
}

.breadcrumbs li {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
}

.breadcrumbs li + li::before {
  content: "/";
  color: var(--border-strong);
}

.breadcrumbs a {
  /* padding-block takes the hit box to ~28px. WCAG 2.2 target-size (2.5.8)
     wants 24px; measured 20px without it. */
  display: inline-block;
  padding-block: var(--sp-1);
  color: var(--text-muted);
  text-decoration: none;
}

.breadcrumbs a:hover {
  color: var(--accent);
  text-decoration: underline;
}

.breadcrumbs [aria-current="page"] {
  color: var(--text);
}

/* --------------------------------------------------------------------------
   4. PAGE HEAD (h1 + one-line description)
   Kept short on purpose: on a 667px-tall phone the H1 block plus the
   calculator plus the result must all fit above the fold.
   -------------------------------------------------------------------------- */
.page-head {
  margin-bottom: var(--sp-4);
}

.page-head__title {
  margin-bottom: var(--sp-2);
}

.page-head__desc {
  color: var(--text-muted);
  font-size: var(--fs-sm);
  max-width: var(--w-prose);
}

@media (min-width: 48em) {
  .page-head__desc {
    font-size: var(--fs-base);
  }
}

.page-head__meta {
  margin-top: var(--sp-3);
  font-size: var(--fs-xs);
  color: var(--text-subtle);
}

/* --------------------------------------------------------------------------
   5. AD SLOTS
   -------------------------------------------------------------------------- */
.ad-slot {
  /* --slot-h is the ad box; the outer height adds the label line + gap. */
  --slot-h: var(--ad-h-rect);
  --slot-w: var(--ad-w-rect);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--ad-gap);
  height: calc(var(--slot-h) + var(--ad-label-h) + var(--ad-gap));
  margin-block: var(--sp-8);
  contain: layout size;
}

.ad-slot__label {
  display: block;
  height: var(--ad-label-h);
  line-height: var(--ad-label-h);
  font-size: var(--fs-2xs);
  letter-spacing: var(--tracking-caps);
  text-transform: uppercase;
  color: var(--ad-label);
  flex: none;
}

.ad-slot__inner {
  width: 100%;
  max-width: var(--slot-w);
  height: var(--slot-h);
  flex: none;
  overflow: clip;
  background-color: var(--ad-bg);
  border: var(--bw) solid var(--ad-border);
  border-radius: var(--r-md);
  contain: strict;
}

/* The AdSense <ins> must not be allowed to resize the reservation. */
.ad-slot__inner > ins,
.ad-slot__inner > iframe,
.ad-slot__inner > div {
  display: block;
  width: 100%;
  height: 100%;
}

/* -- top leaderboard: DESKTOP ONLY ---------------------------------------
   Reserving 90-100px above the tool on a phone would push the result below
   the fold on a 667px viewport. The measured business here is "arrive from
   Google, read one number, leave" — burying the number to gain one mobile
   impression trades the whole product for ~$0.30 page RPM. Mobile therefore
   carries two slots (result + article), desktop carries four. */
.ad-slot--top {
  display: none;
}

@media (min-width: 64em) {
  .ad-slot--top {
    display: flex;
    --slot-h: var(--ad-h-leaderboard);
    --slot-w: 970px;
    margin-block: var(--sp-4) var(--sp-6);
  }
}

/* -- sidebar half page: >=1120px only ------------------------------------ */
.ad-slot--sidebar {
  display: none;
}

@media (min-width: 70em) {
  .ad-slot--sidebar {
    display: flex;
    --slot-h: var(--ad-h-skyscraper);
    --slot-w: var(--ad-w-skyscraper);
    margin-block: 0;
  }
}

/* -- below the result: the highest-value unit on mobile -------------------
   Placed after the result card, never before it. */
.ad-slot--result {
  --slot-h: var(--ad-h-rect);
  --slot-w: var(--ad-w-rect);
  margin-block: var(--sp-6);
}

@media (min-width: 48em) {
  .ad-slot--result {
    --slot-h: var(--ad-h-rect-lg);
    --slot-w: var(--ad-w-rect-lg);
  }
}

/* -- in-article ----------------------------------------------------------- */
.ad-slot--article {
  --slot-h: var(--ad-h-rect);
  --slot-w: var(--ad-w-rect);
}

@media (min-width: 48em) {
  .ad-slot--article {
    --slot-h: var(--ad-h-rect-lg);
    --slot-w: var(--ad-w-rect-lg);
  }
}

/* Debug helper: build with ADS_PLACEHOLDER=1 to see the reservations. */
.ad-slot--placeholder .ad-slot__inner {
  display: grid;
  place-items: center;
  color: var(--ad-label);
  font-size: var(--fs-xs);
  background-image: repeating-linear-gradient(
    45deg,
    transparent 0 8px,
    color-mix(in srgb, var(--ad-label) 12%, transparent) 8px 9px
  );
}

/* --------------------------------------------------------------------------
   6. RELATED TOOLS
   The single most important non-ad element after the result: it is the whole
   internal-linking and session-depth strategy on one component.
   -------------------------------------------------------------------------- */
.related-tools {
  margin-top: var(--sp-10);
}

.related-tools__grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--sp-3);
  list-style: none;
  padding: 0;
  margin: 0;
}

@media (min-width: 34em) {
  .related-tools__grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (min-width: 64em) {
  .related-tools__grid--3 {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

.tool-card {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: var(--sp-1);
  height: 100%;
  padding: var(--sp-4);
  background-color: var(--surface);
  border: var(--bw) solid var(--border);
  border-radius: var(--r-lg);
  transition: border-color var(--dur) var(--ease),
    box-shadow var(--dur) var(--ease), transform var(--dur) var(--ease);
}

.tool-card:hover {
  border-color: var(--accent-line);
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}

.tool-card:has(a:focus-visible) {
  outline: 3px solid var(--focus-ring);
  outline-offset: 2px;
}

.tool-card__title {
  font-size: var(--fs-base);
  font-weight: var(--fw-semibold);
  line-height: var(--lh-snug);
}

.tool-card__title a {
  color: var(--text-strong);
  text-decoration: none;
}

/* Whole card clickable, one tab stop, real link semantics. */
.tool-card__title a::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
}

.tool-card:hover .tool-card__title a {
  color: var(--accent);
}

.tool-card__title a:focus-visible {
  outline: none;
}

.tool-card__blurb {
  font-size: var(--fs-sm);
  color: var(--text-muted);
}

/* --------------------------------------------------------------------------
   7. CLUSTER / INDEX LISTS
   -------------------------------------------------------------------------- */
.cluster-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--sp-4);
}

@media (min-width: 40em) {
  .cluster-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (min-width: 64em) {
  .cluster-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

.cluster-card {
  padding: var(--sp-5);
  background-color: var(--surface);
  border: var(--bw) solid var(--border);
  border-left: 3px solid var(--accent-line);
  border-radius: var(--r-lg);
}

.cluster-card__title {
  font-size: var(--fs-lg);
  margin-bottom: var(--sp-2);
}

.link-list {
  display: grid;
  gap: var(--sp-1);
  list-style: none;
  padding: 0;
  margin: 0;
}

.link-list a {
  display: block;
  padding: var(--sp-2) 0;
  color: var(--text);
  text-decoration: none;
  font-size: var(--fs-sm);
  border-bottom: var(--bw) solid var(--divider);
}

.link-list a:hover {
  color: var(--accent);
}

/* Permutation index ("30 days from today", "31 days...") — dense chip grid. */
.chip-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(9.5rem, 1fr));
  gap: var(--sp-2);
  list-style: none;
  padding: 0;
  margin: 0;
}

.chip {
  display: block;
  padding: var(--sp-2) var(--sp-3);
  background-color: var(--surface);
  border: var(--bw) solid var(--border);
  border-radius: var(--r-sm);
  font-size: var(--fs-sm);
  color: var(--text);
  text-decoration: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chip:hover {
  border-color: var(--accent-line);
  color: var(--accent);
}

/* --------------------------------------------------------------------------
   8. PROSE — the supporting article under every calculator
   -------------------------------------------------------------------------- */
.prose {
  max-width: var(--w-prose);
  font-size: var(--fs-md);
  line-height: var(--lh-prose);
  color: var(--text);
}

.prose > * + * {
  margin-top: var(--sp-5);
}

.prose h2 {
  margin-top: var(--sp-10);
  font-size: var(--fs-2xl);
  scroll-margin-top: calc(var(--header-h) + var(--sp-4));
}

.prose h3 {
  margin-top: var(--sp-8);
  font-size: var(--fs-xl);
  scroll-margin-top: calc(var(--header-h) + var(--sp-4));
}

.prose h2 + *,
.prose h3 + * {
  margin-top: var(--sp-3);
}

.prose ul,
.prose ol {
  padding-left: var(--sp-6);
}

.prose li + li {
  margin-top: var(--sp-2);
}

.prose li::marker {
  color: var(--accent-line);
}

.prose .table-wrap,
.prose figure {
  margin-block: var(--sp-6);
}

/* An ad inside .prose must not inherit the prose max-width and jump when the
   article width changes at a breakpoint. */
.prose .ad-slot {
  max-width: 100%;
}

/* --------------------------------------------------------------------------
   9. FAQ
   -------------------------------------------------------------------------- */
.faq {
  margin-top: var(--sp-10);
}

.faq__list {
  display: grid;
  gap: var(--sp-3);
}

.faq__item {
  background-color: var(--surface);
}

.faq__q {
  font-size: var(--fs-base);
}

.faq__a {
  padding: 0 var(--sp-4) var(--sp-4);
  color: var(--text-muted);
  font-size: var(--fs-md);
  line-height: var(--lh-prose);
}

.faq__a > * + * {
  margin-top: var(--sp-3);
}

/* --------------------------------------------------------------------------
   10. FOOTER
   -------------------------------------------------------------------------- */
.site-footer {
  flex: none;
  margin-top: var(--sp-16);
  padding-block: var(--sp-8);
  border-top: var(--bw) solid var(--border);
  background-color: var(--surface);
  font-size: var(--fs-sm);
  color: var(--text-muted);
}

.site-footer__inner {
  display: grid;
  gap: var(--sp-6);
}

@media (min-width: 48em) {
  .site-footer__inner {
    grid-template-columns: minmax(0, 1.4fr) repeat(2, minmax(0, 1fr));
    gap: var(--sp-8);
  }
}

.site-footer h2,
.site-footer__heading {
  font-size: var(--fs-xs);
  text-transform: uppercase;
  letter-spacing: var(--tracking-caps);
  color: var(--text-subtle);
  margin-bottom: var(--sp-3);
}

.site-footer ul {
  list-style: none;
  padding: 0;
  display: grid;
  gap: var(--sp-2);
}

.site-footer a {
  /* Same reason as breadcrumbs: list links are not "inline in a sentence",
     so the 24px minimum applies. Measured 19-21px without the padding. */
  display: inline-block;
  padding-block: var(--sp-1);
  color: var(--text-muted);
  text-decoration: none;
}

.site-footer a:hover {
  color: var(--accent);
  text-decoration: underline;
}

.site-footer__legal {
  margin-top: var(--sp-8);
  padding-top: var(--sp-5);
  border-top: var(--bw) solid var(--divider);
  font-size: var(--fs-xs);
  color: var(--text-subtle);
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-2) var(--sp-4);
  align-items: center;
}
