/* ==========================================================================
   Post-Quantum Cryptography — Interactive Visual Guide (explorable.page)
   Editorial Paper → Stark Noir (Act III) → Editorial Paper
   ========================================================================== */

:root {
  --bg: #FAF8F3;
  --ink: #141412;
  --muted: #66645E;
  --hairline: rgba(20, 20, 18, 0.10);
  --hairline-strong: rgba(20, 20, 18, 0.18);

  --caption-bg: rgba(250, 248, 243, 0.92);
  --caption-border: rgba(20, 20, 18, 0.09);
  --caption-shadow: 0 10px 30px rgba(20, 20, 18, 0.06);

  /* Ink-like restrained accents */
  --ochre: #B4690E;
  --slate: #2B5B84;
  --teal: #0E7C7B;
  --indigo: #4338CA;
  --crimson: #E11D48;
  --emerald: #047857;
  --blue: #1D4ED8;
  --terracotta: #C2410C;

  --progress-color: #141412;

  --font-serif: 'Newsreader', Georgia, 'Times New Roman', serif;
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
}

/* Act III: Stark Obsidian Noir */
body[data-act="3"] {
  --bg: #0E0C0D;
  --ink: #F4F1EA;
  --muted: #9D9794;
  --hairline: rgba(244, 241, 234, 0.11);
  --hairline-strong: rgba(244, 241, 234, 0.22);

  --caption-bg: rgba(18, 15, 16, 0.88);
  --caption-border: rgba(225, 29, 72, 0.26);
  --caption-shadow: 0 14px 36px rgba(0, 0, 0, 0.45);
  --progress-color: #E11D48;
}

/* Subtle progress accent per act */
body[data-act="1"] { --progress-color: var(--ochre); }
body[data-act="2"] { --progress-color: var(--teal); }
body[data-act="4"] { --progress-color: var(--emerald); }

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

body {
  margin: 0;
  background-color: var(--bg);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.55;
  overflow-x: clip;
  transition: background-color 650ms ease, color 650ms ease;
}

a {
  color: inherit;
  text-decoration: none;
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
}

:focus-visible {
  outline: 1.5px solid var(--progress-color);
  outline-offset: 3px;
}

/* ==========================================================================
   Razor-Thin Top Reading Progress Hairline
   ========================================================================== */
.progress-hairline {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 2px;
  z-index: 60;
  pointer-events: none;
  background: transparent;
}

.progress-hairline-fill {
  height: 100%;
  width: 0%;
  background-color: var(--progress-color);
  transition: background-color 500ms ease;
  will-change: width;
}

/* ==========================================================================
   Barely-There Fixed Micro-Nav
   ========================================================================== */
.micro-nav {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 24px;
  pointer-events: none;
}

.micro-brand {
  pointer-events: auto;
  display: inline-flex;
  align-items: center;
  color: var(--ink);
  opacity: 0.58;
  transition: opacity 220ms ease, color 650ms ease;
}

.micro-brand:hover,
.micro-brand:focus-visible {
  opacity: 1;
}

.micro-brand-text {
  font-family: var(--font-sans);
  font-size: 0.85rem;
  font-weight: 600;
  letter-spacing: -0.03em;
  line-height: 1;
}

.chapter-dots {
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: 12px;
}

.chapter-dot {
  position: relative;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background-color: var(--ink);
  opacity: 0.22;
  transition: opacity 260ms ease, transform 260ms ease, background-color 500ms ease;
}

.chapter-dot::before {
  /* Generous touch/click target without clutter */
  content: '';
  position: absolute;
  inset: -8px;
}

.chapter-dot::after {
  content: attr(data-label);
  position: absolute;
  top: calc(100% + 10px);
  right: 0;
  white-space: nowrap;
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  opacity: 0;
  transform: translateY(-2px);
  pointer-events: none;
  transition: opacity 180ms ease, transform 180ms ease;
}

.chapter-dot:hover,
.chapter-dot:focus-visible {
  opacity: 0.72;
  transform: scale(1.2);
}

.chapter-dot:hover::after,
.chapter-dot:focus-visible::after {
  opacity: 1;
  transform: translateY(0);
}

.chapter-dot.is-active {
  opacity: 1;
  transform: scale(1.28);
  background-color: var(--progress-color);
}

/* ==========================================================================
   HERO — Full-Viewport Editorial Opening
   ========================================================================== */
.hero {
  position: relative;
  min-height: 100svh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 80px 24px 96px;
  text-align: center;
  overflow: hidden;
}

.hero-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.hero-inner {
  position: relative;
  z-index: 2;
  max-width: 740px;
  margin: 0 auto;
}

.hero-title {
  margin: 0;
  font-family: var(--font-serif);
  font-size: clamp(2.55rem, 6.2vw, 4.75rem);
  font-weight: 400;
  line-height: 1.06;
  letter-spacing: -0.025em;
  color: var(--ink);
}

.hero-subtitle {
  margin: 22px auto 0;
  max-width: 520px;
  font-family: var(--font-serif);
  font-style: italic;
  font-size: clamp(1.12rem, 2vw, 1.38rem);
  line-height: 1.48;
  color: var(--muted);
}

.hero-scroll {
  position: absolute;
  bottom: 30px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 2;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
  opacity: 0.72;
  transition: opacity 220ms ease, color 220ms ease;
}

.hero-scroll:hover {
  opacity: 1;
  color: var(--ink);
}

.hero-scroll-arrow {
  display: inline-block;
  animation: quietBob 2.4s ease-in-out infinite;
}

@keyframes quietBob {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(3px); }
}

/* ==========================================================================
   SCROLLYTELLING — Full-Bleed Sticky Canvas + Floating Captions
   ========================================================================== */
.scrolly {
  position: relative;
}

.sticky-stage {
  position: sticky;
  top: 0;
  width: 100%;
  height: 100svh;
  z-index: 1;
}

.stage-canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: pan-y;
}

.stage-hint {
  position: absolute;
  right: 22px;
  bottom: 18px;
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  opacity: 0;
  pointer-events: none;
  transition: opacity 320ms ease, color 650ms ease;
}

.stage-hint.is-visible {
  opacity: 0.56;
}

.steps-layer {
  position: relative;
  z-index: 2;
  margin-top: -100svh;
  pointer-events: none;
}

.step {
  min-height: 105svh;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 0 18px 5vh;
  pointer-events: none;
}

.step:last-child {
  min-height: 110svh;
  padding-bottom: 8vh;
}

.caption {
  pointer-events: auto;
  width: 100%;
  max-width: 550px;
  margin: 0;
  padding: 18px 22px;
  background-color: var(--caption-bg);
  border: 1px solid var(--caption-border);
  border-radius: 3px;
  box-shadow: var(--caption-shadow);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);

  font-family: var(--font-sans);
  font-size: clamp(0.95rem, 1.28vw, 1.04rem);
  font-weight: 400;
  line-height: 1.58;
  color: var(--ink);
  letter-spacing: -0.005em;

  opacity: 0.78;
  transform: translateY(6px);
  transition:
    opacity 360ms ease,
    transform 360ms ease,
    background-color 650ms ease,
    border-color 650ms ease,
    color 650ms ease;
}

.step.is-active .caption {
  opacity: 1;
  transform: translateY(0);
}

.caption strong {
  font-weight: 600;
  color: var(--ink);
}

.caption em {
  font-family: var(--font-serif);
  font-style: italic;
  font-size: 1.06em;
}

.caption code,
.finale-dek code {
  font-family: var(--font-mono);
  font-size: 0.88em;
  font-weight: 500;
  padding: 0.06em 0.3em;
  border-radius: 2px;
  background-color: rgba(20, 20, 18, 0.055);
  color: var(--ink);
}

body[data-act="3"] .caption code {
  background-color: rgba(244, 241, 234, 0.09);
}

/* Restrained inline ink accents matching the graphic — zero boxed pills */
.ink-ochre,
.ink-slate,
.ink-teal,
.ink-emerald,
.ink-blue,
.ink-terracotta,
.ink-crimson {
  font-weight: 600;
  text-decoration-line: underline;
  text-decoration-thickness: 1.5px;
  text-underline-offset: 3px;
}

.ink-ochre      { color: var(--ochre);      text-decoration-color: rgba(180, 105, 14, 0.34); }
.ink-slate      { color: var(--slate);      text-decoration-color: rgba(43, 91, 132, 0.34); }
.ink-teal       { color: var(--teal);       text-decoration-color: rgba(14, 124, 123, 0.34); }
.ink-emerald    { color: var(--emerald);    text-decoration-color: rgba(4, 120, 87, 0.34); }
.ink-blue       { color: var(--blue);       text-decoration-color: rgba(29, 78, 216, 0.34); }
.ink-terracotta { color: var(--terracotta); text-decoration-color: rgba(194, 65, 12, 0.34); }
.ink-crimson    { color: var(--crimson);    text-decoration-color: rgba(225, 29, 72, 0.42); }

body[data-act="3"] .ink-crimson {
  color: #FB3B64;
  text-decoration-color: rgba(251, 59, 100, 0.48);
}

/* ==========================================================================
   MINIMAL EDITORIAL FINALE — Landscape Table & Sources
   ========================================================================== */
.finale {
  position: relative;
  z-index: 3;
  background-color: var(--bg);
  border-top: 1px solid var(--hairline);
  transition: background-color 650ms ease, color 650ms ease;
}

.finale-inner {
  max-width: 960px;
  margin: 0 auto;
  padding: 12vh 24px 10vh;
}

.finale-header {
  max-width: 620px;
  margin-bottom: 42px;
}

.finale-title {
  margin: 0;
  font-family: var(--font-serif);
  font-size: clamp(1.95rem, 3.8vw, 2.75rem);
  font-weight: 400;
  line-height: 1.12;
  letter-spacing: -0.02em;
  color: var(--ink);
}

.finale-dek {
  margin: 12px 0 0;
  font-size: 1rem;
  line-height: 1.58;
  color: var(--muted);
}

/* Minimal Controls Row */
.table-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 16px 24px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--hairline);
  margin-bottom: 8px;
}

.filter-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 20px;
}

.tab-btn {
  position: relative;
  padding: 4px 0;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--muted);
  transition: color 180ms ease;
}

.tab-btn:hover {
  color: var(--ink);
}

.tab-btn.is-active {
  color: var(--ink);
}

.tab-btn.is-active::after {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  bottom: -17px;
  height: 1.5px;
  background-color: var(--ink);
}

.threat-toggle {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 2px;
  border: 1px solid var(--hairline-strong);
  border-radius: 3px;
}

.toggle-btn {
  padding: 4px 10px;
  border-radius: 2px;
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.03em;
  color: var(--muted);
  transition: background-color 180ms ease, color 180ms ease;
}

.toggle-btn:hover {
  color: var(--ink);
}

.toggle-btn.is-active {
  background-color: var(--ink);
  color: var(--bg);
}

/* Hairline Table (Pudding / NYT Style) */
.table-scroll {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.landscape-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  font-size: 0.9rem;
}

.landscape-table th {
  padding: 14px 14px 12px 0;
  font-family: var(--font-mono);
  font-size: 10.5px;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  border-bottom: 1px solid var(--hairline-strong);
  white-space: nowrap;
}

.landscape-table th:last-child,
.landscape-table td:last-child {
  padding-right: 0;
}

.landscape-table td {
  padding: 16px 14px 16px 0;
  border-bottom: 1px solid var(--hairline);
  vertical-align: top;
}

.landscape-table tbody tr {
  transition: background-color 160ms ease;
}

.landscape-table tbody tr:hover {
  background-color: rgba(20, 20, 18, 0.025);
}

/* Column visibility driven by threat toggle */
.landscape-table[data-threat="classical"] [data-col="quantum"],
.landscape-table[data-threat="quantum"] [data-col="classical"] {
  display: none;
}

.algo-name {
  display: block;
  font-weight: 600;
  color: var(--ink);
  white-space: nowrap;
}

.algo-role {
  display: block;
  margin-top: 2px;
  font-size: 0.78rem;
  color: var(--muted);
}

.algo-family {
  display: block;
  color: var(--ink);
  white-space: nowrap;
}

.algo-nist {
  display: block;
  margin-top: 2px;
  font-family: var(--font-mono);
  font-size: 0.74rem;
  color: var(--muted);
}

.algo-sizes {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  white-space: nowrap;
}

.durability-cell {
  min-width: 140px;
}

.durability-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-family: var(--font-mono);
  font-size: 0.78rem;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.durability-status {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 0.72rem;
  letter-spacing: 0.02em;
}

.status-dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  flex-shrink: 0;
}

.durability-status.is-safe {
  color: var(--emerald);
}
.durability-status.is-safe .status-dot {
  background-color: var(--emerald);
}

.durability-status.is-broken {
  color: var(--crimson);
}
.durability-status.is-broken .status-dot {
  background-color: var(--crimson);
}

.durability-track {
  margin-top: 7px;
  width: 100%;
  height: 3px;
  background-color: var(--hairline);
  border-radius: 2px;
  overflow: hidden;
}

.durability-bar {
  height: 100%;
  border-radius: 2px;
}

.durability-bar.is-safe {
  background-color: var(--emerald);
}

.durability-bar.is-broken {
  background-color: var(--crimson);
}

/* ==========================================================================
   Quiet Numbered Sources Bibliography
   ========================================================================== */
.sources {
  margin-top: 84px;
}

.sources-heading {
  margin: 0 0 18px;
  font-family: var(--font-serif);
  font-size: 1.4rem;
  font-weight: 400;
  color: var(--ink);
}

.sources-list {
  list-style: none;
  margin: 0;
  padding: 0;
  border-top: 1px solid var(--hairline);
}

.sources-list li {
  display: grid;
  grid-template-columns: 30px 1fr auto;
  align-items: baseline;
  gap: 6px 14px;
  padding: 13px 0;
  border-bottom: 1px solid var(--hairline);
  font-size: 0.88rem;
}

.src-num {
  font-family: var(--font-mono);
  font-size: 0.76rem;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
}

.sources-list a {
  color: var(--ink);
  transition: color 180ms ease;
}

.sources-list a:hover {
  color: var(--ochre);
  text-decoration: underline;
  text-underline-offset: 3px;
}

.src-meta {
  font-family: var(--font-mono);
  font-size: 0.74rem;
  color: var(--muted);
  white-space: nowrap;
}

/* ==========================================================================
   Minimal Colophon Footer
   ========================================================================== */
.colophon {
  margin-top: 64px;
  padding-top: 24px;
  border-top: 1px solid var(--hairline);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  font-family: var(--font-mono);
  font-size: 0.76rem;
  color: var(--muted);
}

.colophon-back {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--ink);
  opacity: 0.78;
  transition: opacity 180ms ease;
}

.colophon-back:hover {
  opacity: 1;
}

.colophon-meta {
  text-align: right;
}

.colophon-author {
  color: var(--ink);
  opacity: 0.85;
  transition: opacity 180ms ease;
}

.colophon-author:hover {
  opacity: 1;
  text-decoration: underline;
  text-underline-offset: 3px;
}

/* ==========================================================================
   Responsive Refinements (Mobile 390×844 & Narrow Viewports)
   ========================================================================== */
@media (max-width: 680px) {
  .micro-nav {
    padding: 14px 16px;
  }

  .chapter-dots {
    gap: 10px;
  }

  .step {
    min-height: 102svh;
    padding: 0 14px 4.2vh;
  }

  .caption {
    padding: 14px 16px;
    font-size: 0.91rem;
    line-height: 1.5;
  }

  .stage-hint {
    right: 14px;
    bottom: 12px;
    font-size: 9px;
  }

  .finale-inner {
    padding: 9vh 18px 8vh;
  }

  .tab-btn.is-active::after {
    bottom: -6px;
  }

  .sources-list li {
    grid-template-columns: 26px 1fr;
  }

  .src-meta {
    grid-column: 2;
    margin-top: -2px;
  }
}

/* ==========================================================================
   Reduced Motion
   ========================================================================== */
@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  body,
  .caption,
  .finale,
  .micro-brand,
  .chapter-dot {
    transition: none;
  }

  .hero-scroll-arrow {
    animation: none;
  }
}
