/* =========================================================================
   Reading Rail — sticky summary + progressive CTA
   Consumes tokens from screen.css (Intercepta Ink v1.2 DS). See spec §5.
   Reserves grid before JS runs so we don't cause CLS.
   ========================================================================= */

/* Grid wrapper on rail posts. Column 1 = post body, column 2 = rail. */
.ix-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 2.5rem;
  max-width: var(--container-max);
  margin-inline: auto;
  padding-inline: 1.5rem;
}
@media (min-width: 1100px) {
  .ix-grid {
    grid-template-columns: minmax(0, 45rem) 260px;
    gap: 2.5rem;
    padding-inline: 2rem;
  }
}
@media (min-width: 1240px) {
  .ix-grid {
    grid-template-columns: minmax(0, 45rem) 300px;
    gap: 4rem;
  }
}

/* .gh-content sub-grid so Koenig .kg-width-wide / .kg-width-full still work.
   Values match Casper's convention; wide/full get their own tracks. */
.ix-body.gh-content {
  display: grid;
  grid-template-columns:
    [full-start] minmax(0, auto)
    [wide-start] minmax(0, 60px)
    [main-start] minmax(0, 720px) [main-end]
    minmax(0, 60px) [wide-end]
    minmax(0, auto) [full-end];
}
.ix-body.gh-content > * { grid-column: main-start / main-end; }
.ix-body.gh-content > .kg-width-wide { grid-column: wide-start / wide-end; }
.ix-body.gh-content > .kg-width-full { grid-column: full-start / full-end; }
.ix-body.gh-content > .kg-width-full img { border-radius: 0; }

/* Under the rail breakpoint the sub-grid collapses to a single column. */
@media (max-width: 1099px) {
  .ix-body.gh-content { display: block; }
}

/* --- Rail column -------------------------------------------------------
   The outer <aside> must span the grid row (default `align-self: stretch`)
   so its sticky child has vertical space to travel through. */
.ix-rail { display: none; }
@media (min-width: 1100px) {
  .ix-rail {
    display: block;
    position: relative;
    height: 100%;
  }
  .ix-rail[hidden] { display: none; }
  .ix-rail.is-ready { display: block; }

  .ix-rail-inner {
    position: sticky;
    top: 96px;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
  }
}

/* Progress meter */
.ix-progress {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}
.ix-progress-track {
  flex: 1;
  height: 3px;
  background: var(--border);
  border-radius: 999px;
  overflow: hidden;
}
.ix-progress-fill {
  height: 100%;
  width: 0;
  background: var(--accent);
  border-radius: 999px;
  transition: width 120ms linear;
}
.ix-progress-pct {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: var(--weight-medium);
  letter-spacing: 0.08em;
  color: var(--ink-muted);
  font-variant-numeric: tabular-nums;
  min-width: 3ch;
  text-align: right;
}

/* Eyebrow + list */
.ix-toc { display: flex; flex-direction: column; gap: 0.5rem; }
.ix-eyebrow {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: var(--weight-medium);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-muted);
  margin: 0;
}
.ix-toc ol {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.ix-toc li {
  border-left: 3px solid transparent;
  padding-left: 12px;
  transition: border-color 120ms;
}
.ix-toc a {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow: hidden;
  font-family: var(--font-sans);
  font-size: 14px;
  font-weight: var(--weight-regular);
  letter-spacing: -0.011em;
  line-height: 1.45;
  color: var(--ink-muted);
  transition: color 120ms;
}
.ix-toc li.is-active { border-left-color: var(--accent); }
.ix-toc li.is-active a { color: var(--ink); font-weight: var(--weight-medium); }
.ix-toc li.is-read a { color: var(--ink-muted); opacity: 0.6; }
.ix-toc a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 2px;
}

/* CTA card */
.ix-cta {
  background: var(--surface-card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 20px;
  box-shadow: 0 12px 32px -16px rgba(10, 14, 26, 0.18);
  min-height: 220px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.ix-cta[hidden] { display: none; }
.ix-trio {
  display: inline-flex;
  gap: 7px;
  align-items: center;
  margin-bottom: 8px;
}
.ix-trio i {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: block;
}
.ix-trio i:nth-child(1) { background: var(--signal-fail); }
.ix-trio i:nth-child(2) { background: var(--signal-warn); }
.ix-trio i:nth-child(3) { background: var(--signal-pass); }
.ix-cta-head {
  font-family: var(--font-display);
  font-size: 19px;
  font-weight: var(--weight-semibold);
  letter-spacing: -0.02em;
  line-height: 1.25;
  color: var(--ink);
  margin: 0;
}
.ix-cta-body {
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: var(--weight-regular);
  letter-spacing: -0.011em;
  line-height: 1.5;
  color: var(--ink-muted);
  margin: 0;
}
.ix-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 44px;
  padding: 0 18px;
  background: var(--accent);
  color: var(--white);
  font-family: var(--font-sans);
  font-size: 15px;
  font-weight: var(--weight-semibold);
  letter-spacing: -0.011em;
  border-radius: 10px;
  transition: background 120ms;
  margin-top: auto;
}
.ix-btn:hover { background: var(--accent-hover); color: var(--white); }
.ix-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.ix-trust {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-muted);
  margin: 8px 0 0 0;
  min-height: 12px;
}

/* =========================================================================
   MOBILE PATH (< 1100px)
   ========================================================================= */

/* Top progress bar, fixed to viewport */
.ix-top-progress {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: transparent;
  z-index: 500;
  pointer-events: none;
  display: none;
}
.ix-top-progress-fill {
  height: 100%;
  width: 0;
  background: var(--accent);
  transition: width 120ms linear;
}
@media (max-width: 1099px) {
  .ix-top-progress.is-ready { display: block; }
}

/* Collapsed <details> "On this page" injected above the post body on mobile */
.ix-toc-details {
  margin: 0 0 1.5rem 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface-card);
  padding: 0.75rem 1rem;
  font-family: var(--font-sans);
}
.ix-toc-details summary {
  cursor: pointer;
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-muted);
  font-weight: var(--weight-medium);
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}
.ix-toc-details summary::after {
  content: "▾";
  font-size: 10px;
  transition: transform 150ms;
}
.ix-toc-details[open] summary::after { transform: rotate(180deg); }
.ix-toc-details summary::-webkit-details-marker { display: none; }
.ix-toc-details ol {
  list-style: none;
  padding: 0.75rem 0 0 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.ix-toc-details a {
  color: var(--ink);
  font-size: 15px;
  line-height: 1.4;
  display: inline-block;
  padding: 0.25rem 0;
}

/* Sticky bottom CTA bar */
.ix-bottom-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 400;
  background: var(--surface-card);
  border-top: 1px solid var(--border);
  padding: 12px 20px;
  padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  transform: translateY(100%);
  transition: transform 220ms cubic-bezier(0.22, 1, 0.36, 1);
  display: none;
}
.ix-bottom-bar[hidden] { display: none; }
.ix-bottom-bar.is-ready { display: block; }
.ix-bottom-bar.is-visible { transform: translateY(0); }
.ix-bottom-bar-inner {
  max-width: var(--container-max);
  margin-inline: auto;
  display: grid;
  grid-template-columns: 1fr auto 32px;
  align-items: center;
  gap: 12px;
}
.ix-bottom-bar-copy {
  font-family: var(--font-sans);
  font-size: 14px;
  color: var(--ink);
  margin: 0;
  line-height: 1.3;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.ix-bottom-bar-btn { height: 40px; padding: 0 16px; font-size: 14px; margin-top: 0; }
.ix-bottom-bar-close {
  width: 32px;
  height: 32px;
  border-radius: 6px;
  color: var(--ink-muted);
  font-size: 20px;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.ix-bottom-bar-close:hover { background: var(--surface-sunken); color: var(--ink); }
body.ix-bottom-bar-active { padding-bottom: 88px; }
@media (max-width: 639px) {
  .ix-bottom-bar-copy { display: none; }
  .ix-bottom-bar-inner { grid-template-columns: 1fr 32px; }
  .ix-bottom-bar-btn { width: 100%; }
}

/* --- Reduced motion --------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  .ix-progress-fill,
  .ix-top-progress-fill,
  .ix-bottom-bar,
  .ix-toc li,
  .ix-toc a { transition: none; }
  html { scroll-behavior: auto; }
}
