:root {
  --paper: #eef1f4;
  --sheet: #fbfcfd;
  --ink: #152033;
  --muted: #5a6573;
  --rule: #c9d1db;
  --teal: #0b6e6b;
  --teal-ink: #085754;
  --teal-soft: #e6f3f2;
  --band: #e8edf2;
  --stamp: #8a3a32;
  --focus: #0b6e6b;
  --rail: 13.5rem;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html {
  scroll-behavior: smooth;
  scroll-padding-top: 1.25rem;
  overflow-x: clip;
  max-width: 100%;
}

body {
  background: var(--paper);
  color: var(--ink);
  font-family: Figtree, sans-serif;
  font-size: 1.05rem;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  overflow-x: clip;
  max-width: 100%;
}

img, video, iframe { max-width: 100%; display: block; }

a { color: var(--teal-ink); }
a:hover { color: var(--ink); }

:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 3px;
}

.skip {
  position: absolute;
  left: -999px;
  top: 0;
  background: var(--ink);
  color: #fff;
  padding: 0.5rem 0.75rem;
}
.skip:focus { left: 0.5rem; top: 0.5rem; z-index: 20; }

.shell {
  display: grid;
  grid-template-columns: var(--rail) minmax(0, 46rem);
  gap: 2.5rem;
  width: 100%;
  max-width: 64rem;
  margin: 0 auto;
  padding: 1.75rem 1.5rem 4rem;
  padding-left: max(1.5rem, env(safe-area-inset-left));
  padding-right: max(1.5rem, env(safe-area-inset-right));
}

.main,
.well,
.flow,
.player {
  min-width: 0;
  max-width: 100%;
}

.rail {
  position: sticky;
  top: 1.25rem;
  align-self: start;
  height: calc(100vh - 2.5rem);
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  border-right: 1px solid var(--rule);
  padding-right: 1.25rem;
}

.wordmark {
  font-family: "Instrument Serif", serif;
  font-size: 1.55rem;
  letter-spacing: -0.02em;
  line-height: 1.1;
  color: var(--ink);
  text-decoration: none;
}

.rail-kicker {
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.68rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
  margin-top: 0.2rem;
}

.rail-kicker a {
  color: inherit;
  text-decoration: none;
}

.rail-kicker a:hover { color: var(--teal); }

.toc {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  overflow: auto;
}

.toc a {
  display: grid;
  grid-template-columns: 1.6rem 1fr;
  gap: 0.35rem;
  text-decoration: none;
  color: var(--muted);
  font-size: 0.92rem;
  padding: 0.28rem 0.35rem;
  border-left: 2px solid transparent;
}

.toc a .ex {
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.7rem;
  letter-spacing: 0.04em;
  color: var(--teal);
}

.toc a.is-active,
.toc a:hover {
  color: var(--ink);
  border-left-color: var(--teal);
  background: var(--teal-soft);
}

.main { min-width: 0; }

.hero {
  padding: 0.2rem 0 1.75rem;
  border-bottom: 1.5px solid var(--ink);
  margin-bottom: 2rem;
}

.hero h1 {
  font-family: "Instrument Serif", serif;
  font-size: clamp(1.85rem, 3.4vw, 2.55rem);
  font-weight: 400;
  line-height: 1.18;
  letter-spacing: -0.02em;
  max-width: 22ch;
  margin: 0.4rem 0 0.9rem;
}

.lede { color: var(--ink); max-width: 42rem; }
.lede + .lede { margin-top: 0.75rem; }

section {
  padding: 1.75rem 0 2rem;
  border-bottom: 1px solid var(--rule);
}

section > h2 {
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.72rem;
  font-weight: 500;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 0.7rem;
}

h3 {
  font-family: "Instrument Serif", serif;
  font-size: 1.55rem;
  font-weight: 400;
  letter-spacing: -0.015em;
  line-height: 1.2;
  margin-bottom: 0.65rem;
}

p + p, p + ul, ul + p { margin-top: 0.7rem; }

.prose { max-width: 42rem; }

.cards {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 0.75rem;
  margin-top: 1.1rem;
}

.card {
  background: var(--sheet);
  border: 1px solid var(--rule);
  padding: 0.9rem 0.95rem 1rem;
}

.card h4 { font-size: 0.98rem; margin-bottom: 0.35rem; }
.card p { font-size: 0.92rem; color: var(--muted); }

.flow {
  display: grid;
  grid-template-columns: 10.5rem 4.2rem 1fr 4.2rem 9.5rem;
  gap: 0;
  background: var(--band);
  border: 1px solid var(--rule);
  padding: 0.9rem;
  margin-top: 1rem;
}

.flow-col {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  justify-content: center;
}

.node {
  appearance: none;
  text-align: left;
  background: #fff;
  border: 1px solid var(--rule);
  padding: 0.55rem 0.65rem;
  cursor: pointer;
  font: inherit;
  color: inherit;
  width: 100%;
}

.node:hover, .node:focus-visible { border-color: var(--teal); }

.node .k, .fabriq .k, .writeback .k {
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.65rem;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--muted);
}

.node .v, .fabriq .v, .writeback .v {
  font-weight: 600;
  font-size: 0.92rem;
  margin-top: 0.1rem;
  line-height: 1.3;
}

.edge {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.62rem;
  color: var(--teal);
  line-height: 1.3;
}

.edge .arr { font-size: 1.1rem; }

.fabriq {
  background: var(--teal-soft);
  border: 1px solid var(--teal);
  padding: 0.75rem 0.8rem;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 0.35rem;
}

.badge {
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.65rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #fff;
  background: var(--teal);
  padding: 0.18rem 0.4rem;
  width: fit-content;
}

.writeback {
  background: #fff;
  border: 1px solid var(--teal);
  padding: 0.7rem 0.75rem;
}

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin: 0.85rem 0 0.9rem;
}

.chip {
  appearance: none;
  border: 1px solid var(--rule);
  background: #fff;
  font: inherit;
  font-size: 0.85rem;
  padding: 0.28rem 0.65rem;
  cursor: pointer;
  color: var(--ink);
}

.chip.is-on {
  background: var(--teal);
  border-color: var(--teal);
  color: #fff;
}

.conn-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.55rem;
}

.conn {
  border: 1px solid var(--rule);
  background: #fff;
  padding: 0.7rem 0.8rem;
}

.conn[hidden] { display: none; }

.tag {
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.65rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--teal);
}

.tag.road { color: var(--stamp); }

.conn h4 { margin: 0.2rem 0 0.25rem; font-size: 1rem; }
.conn p { font-size: 0.9rem; color: var(--muted); }

.well {
  margin-top: 1rem;
  display: grid;
  gap: 0.65rem;
}

.player, .placeholder, .still {
  background: #fff;
  border: 1px solid var(--rule);
}

.player {
  width: 100%;
  max-width: 100%;
  position: relative;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  background: #111;
}

.player video,
.player iframe {
  position: absolute;
  inset: 0;
  width: 100% !important;
  height: 100% !important;
  max-width: 100% !important;
  border: 0;
  background: #111;
}

.placeholder {
  aspect-ratio: 16 / 9;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 1.25rem 1.4rem;
  background:
    linear-gradient(var(--band), var(--band)) padding-box,
    repeating-linear-gradient(-45deg, transparent, transparent 8px, rgba(11,110,107,0.06) 8px, rgba(11,110,107,0.06) 9px);
}

.placeholder .play {
  font-family: "Instrument Serif", serif;
  font-size: 1.35rem;
  margin: 0.35rem 0 0.4rem;
}

.placeholder p { font-size: 0.92rem; color: var(--muted); max-width: 36rem; }

.shot-meta {
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.72rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--teal);
}

.stills {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.55rem;
}

.still-btn {
  appearance: none;
  border: 1px solid var(--rule);
  background: #fff;
  padding: 0;
  cursor: zoom-in;
  text-align: left;
  font: inherit;
  color: inherit;
}

.still-btn img {
  width: 100%;
  aspect-ratio: 16 / 10;
  object-fit: cover;
  background: var(--band);
}

.still-btn figcaption {
  font-size: 0.82rem;
  color: var(--muted);
  padding: 0.45rem 0.55rem 0.55rem;
}

.still-ph {
  aspect-ratio: 16 / 10;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  padding: 0.7rem;
  background: var(--band);
  border-bottom: 1px solid var(--rule);
}

.still-ph span {
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.68rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin: 0.9rem 0 0.8rem;
}

.tab {
  appearance: none;
  border: 1px solid var(--rule);
  background: #fff;
  font: inherit;
  padding: 0.35rem 0.7rem;
  cursor: pointer;
}

.tab.is-on {
  background: var(--ink);
  color: #fff;
  border-color: var(--ink);
}

.role-panel[hidden] { display: none; }

.role-panel {
  border: 1px solid var(--rule);
  background: #fff;
  padding: 0.95rem 1.05rem;
}

.role-panel h4 { margin-bottom: 0.35rem; }

.check {
  list-style: none;
  margin-top: 0.6rem;
}

.check li {
  padding: 0.35rem 0 0.35rem 1.2rem;
  position: relative;
  border-bottom: 1px solid var(--band);
}

.check li::before {
  content: "✓";
  position: absolute;
  left: 0;
  color: var(--teal);
  font-weight: 700;
}

.table-wrap {
  overflow: auto;
  margin-top: 0.8rem;
  -webkit-overflow-scrolling: touch;
  max-width: 100%;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
}

th, td {
  text-align: left;
  padding: 0.5rem 0.6rem;
  border-bottom: 1px solid var(--rule);
  vertical-align: top;
}

th {
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.68rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 500;
}

.live { color: var(--teal-ink); font-weight: 600; }
.soon { color: var(--stamp); font-weight: 600; }

.cta {
  background: var(--ink);
  color: #f4f6f8;
  padding: 1.3rem 1.4rem 1.4rem;
  margin-top: 0.8rem;
}

.cta h3 { color: #fff; }
.cta p { color: #c5ced8; }
.cta .action {
  font-family: "Instrument Serif", serif;
  font-size: 1.35rem;
  color: #fff;
  margin-top: 0.7rem;
}

.cta a { color: #9ee0d8; }

.lightbox {
  border: 0;
  padding: 0;
  background: rgba(21, 32, 51, 0.88);
  width: 100%;
  height: 100%;
  max-width: none;
  max-height: none;
}

.lightbox::backdrop { background: transparent; }

.lightbox-inner {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 1.5rem;
}

.lightbox img {
  max-width: min(92vw, 1100px);
  max-height: 86vh;
  box-shadow: 0 20px 60px rgba(0,0,0,0.4);
}

.lightbox-close {
  position: fixed;
  top: 1rem;
  right: 1rem;
  appearance: none;
  border: 0;
  background: #fff;
  font: inherit;
  padding: 0.4rem 0.7rem;
  cursor: pointer;
}

@media (max-width: 1100px) {
  .shell {
    grid-template-columns: minmax(0, 1fr);
    padding: 1rem 1.15rem 3.5rem;
    gap: 0;
    max-width: 46rem;
  }
  .rail {
    position: sticky;
    top: 0;
    height: auto;
    z-index: 8;
    background: var(--paper);
    border-right: 0;
    border-bottom: 1px solid var(--rule);
    padding: 0.65rem 0 0.45rem;
    margin: 0 -1.15rem 1rem;
    padding-left: 1.15rem;
    padding-right: 1.15rem;
  }
  html { scroll-padding-top: 7.5rem; }
  .toc {
    flex-direction: row;
    flex-wrap: nowrap;
    overflow-x: auto;
    gap: 0.15rem;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .toc::-webkit-scrollbar { display: none; }
  .toc a {
    grid-template-columns: auto;
    white-space: nowrap;
    border-left: 0;
    border-bottom: 2px solid transparent;
    font-size: 0.8rem;
    padding: 0.4rem 0.5rem;
  }
  .toc a .ex { display: none; }
  .toc a.is-active { border-bottom-color: var(--teal); background: transparent; }
  .cards { grid-template-columns: 1fr 1fr; }
  .conn-grid, .stills { grid-template-columns: 1fr 1fr; }
  .flow {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
  }
  .edge {
    flex-direction: row;
    gap: 0.45rem;
    padding: 0.15rem 0;
  }
  .edge .arr { transform: rotate(90deg); }
}

@media (max-width: 640px) {
  body { font-size: 1rem; }
  .shell { padding: 0.75rem 0.9rem 2.75rem; }
  .rail {
    margin-left: -0.9rem;
    margin-right: -0.9rem;
    padding-left: 0.9rem;
    padding-right: 0.9rem;
  }
  .hero { padding-bottom: 1.15rem; margin-bottom: 1.15rem; }
  .hero h1 {
    font-size: 1.7rem;
    max-width: none;
  }
  h3 { font-size: 1.28rem; }
  section { padding: 1.25rem 0 1.4rem; }
  .cards, .conn-grid, .stills { grid-template-columns: 1fr; }
  .node, .chip, .tab {
    min-height: 2.75rem;
  }
  .cta {
    padding: 1.05rem 1rem 1.15rem;
  }
  .cta .action { font-size: 1.2rem; }
  table { font-size: 0.85rem; }
  th, td { padding: 0.45rem 0.5rem; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .edge .arr { transform: none; }
}
