:root {
  --serif: 'Source Serif 4', Georgia, serif;
  --sans: 'Manrope', -apple-system, BlinkMacSystemFont, sans-serif;
  --mono: 'IBM Plex Mono', monospace;
  --bg: #fdfcf9; --paper: #ffffff; --text: #2f2a22; --muted: #6e665b;
  --border: #e2d8c6; --accent: #2c6fb7; --accent-hover: #1e528a;
  --slot-empty: #fafaf5;
  --slot-tomb: #ddd6c6;
  --slot-filled: #2c6fb7;
  --slot-active: #d9622b;
  --slot-prob: #f2cf6a;
  --slot-rich: #b86b2a;
}
*, *::before, *::after { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body { margin: 0; font-family: var(--serif); color: var(--text); background: var(--bg); line-height: 1.65; }
.article { max-width: 1040px; margin: 0 auto; padding: 2.5rem 1.5rem 5rem; }
.back-link { display: inline-block; margin-bottom: 1.5rem; color: var(--muted); text-decoration: none; font-family: var(--sans); font-size: 0.9rem; }
.back-link:hover { color: var(--text); }
.article-header { margin-bottom: 3rem; text-align: center; }
.kicker { margin: 0 0 0.75rem; font-family: var(--sans); font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.14em; color: var(--muted); }
h1 { margin: 0 auto 1rem; font-size: clamp(2.4rem, 5vw, 3.5rem); line-height: 1.1; letter-spacing: -0.02em; color: #1a1815; max-width: 18ch; }
.abstract { margin: 0 auto 1rem; max-width: 64ch; font-size: 1.15rem; color: #4d463d; }
.byline { display: flex; gap: 1rem; justify-content: center; flex-wrap: wrap; margin-top: 1.4rem; padding-top: 1rem; border-top: 1px solid var(--border); color: var(--muted); font-family: var(--sans); font-size: 0.92rem; }

.step-section {
  position: relative; margin-top: 4rem; padding: 3rem 2.5rem;
  background: var(--paper); border: 1px solid var(--border);
  border-radius: 24px; box-shadow: 0 8px 30px rgba(0, 0, 0, 0.03);
}
.step-badge {
  position: absolute; top: -16px; left: 32px;
  background: var(--accent); color: white;
  font-family: var(--sans); font-weight: 700; font-size: 0.85rem;
  text-transform: uppercase; letter-spacing: 0.08em;
  padding: 0.4rem 1.2rem; border-radius: 999px;
  box-shadow: 0 4px 12px rgba(44, 111, 183, 0.25);
}
h2 { margin: 0 0 1rem; font-size: clamp(1.6rem, 3.5vw, 2.2rem); line-height: 1.15; color: #1a1815; }
p, ul { max-width: 68ch; font-size: 1.08rem; }
li { margin-bottom: 0.5rem; }
.explanation-list { padding-left: 1.5rem; margin: 1rem 0; }
.math-block { margin: 1.2rem 0; padding: 0.6rem 0.8rem; overflow-x: auto; background: rgba(0,0,0,0.02); border-radius: 12px; text-align: center; }

.callout {
  margin: 1.6rem 0; padding: 1.1rem 1.3rem;
  border-left: 4px solid var(--accent);
  background: rgba(44, 111, 183, 0.04);
  border-radius: 0 12px 12px 0; font-size: 1rem;
}
.callout strong { font-family: var(--sans); font-size: 0.9rem; }
.callout--warn { border-left-color: #b86b2a; background: rgba(184,107,42,0.05); }
.callout--key   { border-left-color: #1e7770; background: rgba(30,119,112,0.05); }
.callout--think { border-left-color: #d9622b; background: rgba(217,98,43,0.04); }

@media (max-width: 640px) {
  .article { padding-inline: 1rem; }
  .step-section { padding: 2rem 1.5rem; }
}

/* ===== Controls ===== */
.controls {
  display: flex; align-items: center; gap: 0.7rem; flex-wrap: wrap;
  margin: 0.8rem 0 0.8rem; font-family: var(--sans);
}
.controls label { display: flex; align-items: center; gap: 0.45rem; font-size: 0.92rem; }
.controls input[type=text], .controls input[type=number] {
  font: 500 0.9rem var(--mono);
  padding: 0.4rem 0.55rem; border: 1px solid var(--border);
  border-radius: 8px; background: white; width: 120px;
}
.controls select {
  font: 600 0.88rem var(--sans);
  padding: 0.4rem 0.55rem; border: 1px solid var(--border);
  border-radius: 8px; background: white;
}
.btn {
  border: 1px solid var(--accent); background: var(--accent); color: white;
  padding: 0.4rem 0.85rem; border-radius: 999px;
  font: 600 0.85rem var(--sans); cursor: pointer;
}
.btn:hover { background: var(--accent-hover); }
.btn--ghost { background: white; color: var(--text); border-color: var(--border); }
.btn--ghost:hover { border-color: var(--accent); color: var(--accent); }
.btn--warn { background: #b86b2a; border-color: #b86b2a; }
.btn--warn:hover { background: #8d4f1d; }
.btn[disabled] { opacity: 0.55; cursor: not-allowed; }

.ht-status {
  font-family: var(--mono); font-size: 0.85rem; color: var(--muted);
  background: rgba(0,0,0,0.03); padding: 0.5rem 0.8rem; border-radius: 8px;
  margin: 0.4rem 0 0.6rem; min-height: 1.7em;
}
.ht-status strong { color: var(--text); font-weight: 600; }

/* ===== Table ===== */
.ht-table {
  display: grid; grid-template-columns: repeat(16, 1fr);
  gap: 4px;
  margin: 0.5rem 0;
}
@media (max-width: 720px) { .ht-table { grid-template-columns: repeat(8, 1fr); } }

.ht-slot {
  aspect-ratio: 1/1;
  background: var(--slot-empty);
  border: 1px solid var(--border);
  border-radius: 6px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  position: relative; font-family: var(--mono); font-size: 0.78rem;
  transition: background-color 120ms ease, transform 120ms ease;
}
.ht-slot.filled { background: rgba(44,111,183,0.20); border-color: var(--slot-filled); }
.ht-slot.tomb   { background: var(--slot-tomb); }
.ht-slot.active { background: var(--slot-active); color: white; transform: scale(1.06); z-index: 2; }
.ht-slot.probing { background: var(--slot-prob); }
.ht-slot.rich { background: var(--slot-rich); color: white; }
.ht-slot-idx { font-size: 0.6rem; color: var(--muted); position: absolute; top: 2px; left: 4px; }
.ht-slot.filled .ht-slot-idx,
.ht-slot.active .ht-slot-idx { color: rgba(255,255,255,0.8); }
.ht-slot-key { font-weight: 600; font-size: 0.78rem; }
.ht-slot-dist { font-size: 0.6rem; opacity: 0.8; }

/* Chain view */
.ht-chain {
  background: var(--slot-empty);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 5px;
  font-family: var(--mono); font-size: 0.7rem;
  min-height: 3.2rem;
  display: flex; flex-wrap: wrap; gap: 3px;
  align-items: flex-start;
}
.ht-chain.has-items { background: rgba(44,111,183,0.10); border-color: var(--slot-filled); }
.ht-chain-idx { display: block; width: 100%; color: var(--muted); font-size: 0.6rem; margin-bottom: 2px; }
.ht-chain-node {
  background: white;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 5px;
  font-size: 0.72rem;
  white-space: nowrap;
}
.ht-chain-node.active { background: var(--slot-active); color: white; border-color: var(--slot-active); }
.ht-chain-node.found  { background: rgba(30,119,112,0.20); border-color: #1e7770; color: #1e7770; }

/* Stats bar */
.ht-stats {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 0.5rem;
  margin: 0.6rem 0 0.4rem; font-family: var(--sans);
}
@media (max-width: 720px) { .ht-stats { grid-template-columns: repeat(2, 1fr); } }
.stat-card {
  background: rgba(44, 111, 183, 0.05);
  border: 1px solid rgba(44, 111, 183, 0.18);
  border-radius: 10px;
  padding: 0.45rem 0.7rem;
  display: flex; flex-direction: column; gap: 0.1rem;
}
.stat-card .s-label { font-size: 0.74rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; }
.stat-card .s-value { font-family: var(--mono); font-size: 1.05rem; color: var(--text); font-weight: 600; }
.stat-card.is-warn { background: rgba(184,107,42,0.08); border-color: rgba(184,107,42,0.32); }
.stat-card.is-bad  { background: rgba(217,98,43,0.12); border-color: rgba(217,98,43,0.36); }

.legend { display: flex; flex-wrap: wrap; gap: 0.7rem; font-family: var(--sans); font-size: 0.8rem; color: var(--muted); margin: 0.3rem 0 0.5rem; }
.legend-sw { display: inline-block; width: 0.85rem; height: 0.85rem; border-radius: 3px; border: 1px solid var(--border); margin-right: 0.3rem; vertical-align: middle; }

/* Table comparison */
.ht-cmp-table {
  width: 100%; border-collapse: collapse; margin: 1rem 0;
  font-family: var(--sans); font-size: 0.92rem;
}
.ht-cmp-table th, .ht-cmp-table td {
  border: 1px solid var(--border); padding: 0.55rem 0.7rem;
  text-align: left; vertical-align: top;
}
.ht-cmp-table th { background: rgba(44, 111, 183, 0.06); font-weight: 600; }
.ht-cmp-table code { font-family: var(--mono); font-size: 0.85rem; background: rgba(0,0,0,0.04); padding: 0.1rem 0.35rem; border-radius: 4px; }
