/* ===================== Design tokens ===================== */
:root {
  --bg: #fafafa;
  --bg-alt: #f2f2f6;
  --surface: #ffffff;
  --border: #e6e6ee;
  --text: #16161f;
  --text-muted: #6b6b7d;
  --text-faint: #9c9cae;

  --row-color: #6366f1;   /* indigo, row / user layer */
  --row-color-soft: #e6e5fd;
  --col-color: #0d9488;   /* teal, column / movie layer */
  --col-color-soft: #dcf5f1;
  --warn-color: #d97706;
  --warn-soft: #fdf0dc;

  --line-soft: #d8d8e4;

  --radius-lg: 20px;
  --radius-md: 14px;
  --radius-sm: 9px;

  --shadow-sm: 0 1px 2px rgba(20, 20, 40, 0.04);
  --shadow-md: 0 8px 24px rgba(20, 20, 40, 0.06);
  --shadow-lg: 0 20px 48px rgba(20, 20, 40, 0.10);

  --font-sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, "SF Mono", monospace;

  --maxw: 1080px;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 { font-weight: 700; letter-spacing: -0.02em; margin: 0 0 0.5em; }
h1 { font-size: clamp(2.2rem, 4.5vw, 3.4rem); line-height: 1.05; }
h2 { font-size: clamp(1.5rem, 2.6vw, 2rem); }
h3 { font-size: 1.15rem; margin-bottom: 0.6em; }
h4 { font-size: 1rem; margin-bottom: 0.4em; }

p { margin: 0 0 1em; }
p:last-child { margin-bottom: 0; }

.mono { font-family: var(--font-mono); }

a { color: var(--row-color); }

.muted { color: var(--text-muted); }
.small { font-size: 0.88rem; }

/* ===================== Layout shells ===================== */

main { max-width: var(--maxw); margin: 0 auto; padding: 0 24px; }

.section { padding: 88px 0; border-top: 1px solid var(--border); }
.section:first-of-type { border-top: none; }

.section-head { max-width: 680px; margin-bottom: 36px; }
.section-intro { color: var(--text-muted); font-size: 1.05rem; }

.eyebrow {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--row-color);
  margin: 0 0 0.9em;
  font-weight: 500;
}

/* ===================== Nav ===================== */

.topnav {
  position: sticky;
  top: 0;
  z-index: 50;
  background: rgba(250, 250, 250, 0.82);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}

.topnav-inner {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 14px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--text);
  text-decoration: none;
}

.topnav-links { display: flex; gap: 28px; }
.topnav-links a {
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.92rem;
  font-weight: 500;
  transition: color 0.15s ease;
}
.topnav-links a:hover { color: var(--text); }

/* ===================== Hero ===================== */

.hero {
  display: grid;
  grid-template-columns: 1.1fr 0.9fr;
  gap: 40px;
  align-items: center;
  padding: 84px 0 64px;
}

.hero-text .lede {
  font-size: 1.15rem;
  color: var(--text-muted);
  max-width: 52ch;
}

.hero-cta { display: flex; gap: 12px; margin-top: 28px; flex-wrap: wrap; }

.hero-art svg { width: 100%; height: auto; }

/* ===================== Buttons & controls ===================== */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 11px 20px;
  border-radius: 999px;
  font-weight: 600;
  font-size: 0.92rem;
  text-decoration: none;
  border: 1px solid transparent;
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.12s ease, background 0.12s ease;
  font-family: inherit;
}
.btn:active { transform: translateY(1px); }

.btn-primary {
  background: var(--text);
  color: #fff;
  box-shadow: var(--shadow-sm);
}
.btn-primary:hover { box-shadow: var(--shadow-md); }

.btn-ghost {
  background: transparent;
  color: var(--text);
  border-color: var(--line-soft);
}
.btn-ghost:hover { background: var(--bg-alt); }

.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border);
  box-shadow: var(--shadow-sm);
}
.btn-secondary:hover { border-color: var(--row-color); }

.toolbar {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  margin-bottom: 28px;
}

.pillset {
  display: inline-flex;
  background: var(--bg-alt);
  border-radius: 999px;
  padding: 3px;
  gap: 2px;
}

.pill {
  border: none;
  background: transparent;
  padding: 8px 16px;
  border-radius: 999px;
  font-family: inherit;
  font-size: 0.86rem;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.15s ease;
}
.pill.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-sm);
}

.inline-slider {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.86rem;
  color: var(--text-muted);
  font-weight: 500;
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 8px 16px;
  border-radius: 999px;
}
.inline-slider.wide { min-width: 320px; }
.inline-slider input[type="range"] { width: 130px; }
.inline-slider.wide input[type="range"] { flex: 1; }

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  height: 4px;
  border-radius: 999px;
  background: var(--line-soft);
  outline: none;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: var(--row-color);
  cursor: pointer;
  border: 2px solid #fff;
  box-shadow: 0 0 0 1px var(--row-color);
}
input[type="range"]::-moz-range-thumb {
  width: 14px; height: 14px;
  border-radius: 50%;
  background: var(--row-color);
  cursor: pointer;
  border: 2px solid #fff;
  box-shadow: 0 0 0 1px var(--row-color);
}

/* ===================== Cards & grids ===================== */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 28px;
  box-shadow: var(--shadow-sm);
  margin-bottom: 24px;
}
.card:last-child { margin-bottom: 0; }

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
  align-items: start;
}
.grid-2 .card { margin-bottom: 0; }
.grid-2 + .card { margin-top: 24px; }

.tag {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 3px 9px;
  border-radius: 999px;
  margin-left: 8px;
  font-weight: 500;
  vertical-align: middle;
}
.row-tag { background: var(--row-color-soft); color: var(--row-color); }
.col-tag { background: var(--col-color-soft); color: var(--col-color); }
.warn-tag { background: var(--warn-soft); color: var(--warn-color); }

.caption {
  font-size: 0.85rem;
  color: var(--text-faint);
  margin-top: 14px;
}

/* ===================== Formula blocks ===================== */

.formula {
  background: var(--bg-alt);
  border-radius: var(--radius-md);
  padding: 18px 22px;
  margin: 16px 0;
  font-size: 1.1rem;
  text-align: center;
  overflow-x: auto;
}
.formula .katex-display { margin: 0; }
.formula-small { font-size: 0.95rem; }

/* ===================== Sandbox widget ===================== */

.sandbox-card { display: flex; flex-direction: column; }
.sandbox { margin-top: 8px; }
.sandbox svg { width: 100%; height: auto; display: block; margin-bottom: 12px; }

.sandbox-controls { display: flex; flex-direction: column; gap: 14px; margin-bottom: 16px; }
.slider-row { display: flex; flex-direction: column; gap: 8px; }
.slider-label {
  font-family: var(--font-mono);
  font-size: 0.85rem;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 8px;
}
.slider-label::before {
  content: "";
  width: 9px; height: 9px;
  border-radius: 50%;
  display: inline-block;
}
.row-dot::before { background: var(--row-color); }
.col-dot::before { background: var(--col-color); }

.sandbox-readout {
  background: var(--bg-alt);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  text-align: center;
}
.sandbox-readout .katex-display { margin: 0; }

/* ===================== Matrix grids ===================== */

.matrix-wrap { overflow-x: auto; padding-bottom: 4px; }

.matrix-grid {
  border-collapse: separate;
  border-spacing: 3px;
  margin: 0 auto;
}

.matrix-grid th, .matrix-grid td {
  text-align: center;
  padding: 0;
}

.mx-corner { width: 46px; }

.mx-colhead, .mx-rowhead {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  color: var(--text-muted);
  font-weight: 500;
  white-space: nowrap;
  padding: 4px 2px;
}
.mx-rowhead { text-align: right; padding-right: 8px; }

.mx-cell {
  width: 30px;
  height: 30px;
  border-radius: 7px;
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--bg-alt);
  transition: transform 0.08s ease;
  padding: 0;
}
.mx-cell.editable:hover { transform: scale(1.12); border-color: var(--row-color); z-index: 2; position: relative; }
.mx-cell.on { background: var(--row-color); border-color: var(--row-color); }
.mx-cell:not(.editable) { cursor: default; }

.mx-foot {
  font-family: var(--font-mono);
  font-size: 0.62rem;
  color: var(--text-faint);
  padding-top: 4px;
}

.fitness-bar {
  height: 3px;
  border-radius: 2px;
  background: var(--row-color);
  margin-top: 3px;
  opacity: 0.55;
}
.fitness-bar.col { background: var(--col-color); }

/* ===================== Bipartite graph ===================== */

.bigraph-wrap { width: 100%; }
.bigraph-wrap svg { width: 100%; height: auto; display: block; }
.bigraph-wrap.small { max-width: 340px; margin: 0 auto; }

/* ===================== Chips ===================== */

.chip-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 18px;
}
.chip {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 20px;
}
.chip h4 { color: var(--row-color); }
.chip p { color: var(--text-muted); font-size: 0.9rem; }

/* ===================== Projection summary ===================== */

.summary-line { font-size: 1.05rem; font-weight: 600; }

/* ===================== Footer ===================== */

.site-footer {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 48px 24px 80px;
  color: var(--text-faint);
  font-size: 0.85rem;
  border-top: 1px solid var(--border);
}

/* ===================== Responsive ===================== */

@media (max-width: 860px) {
  .hero { grid-template-columns: 1fr; padding-top: 48px; }
  .hero-art { order: -1; max-width: 280px; margin: 0 auto; }
  .grid-2 { grid-template-columns: 1fr; }
  .topnav-links { gap: 16px; }
  .topnav-links a { font-size: 0.82rem; }
  .section { padding: 56px 0; }
}

@media (max-width: 520px) {
  .topnav-links { display: none; }
  .inline-slider.wide { min-width: 0; width: 100%; }
  .toolbar { gap: 10px; }
}
