.theory-story {
  --ink: #181818;
  --graphite: #303030;
  --muted: #515151;
  --line: #d5d5d5;
  background: #fff;
  color: var(--ink);
  padding-bottom: clamp(44px, 7vh, 84px);
}

.theory-entry {
  display: grid;
  place-items: center;
  min-height: clamp(100px, 19vh, 175px);
  padding-bottom: 12px;
}

.theory-entry a {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border: 1px solid var(--line);
  border-radius: 50%;
  color: var(--graphite);
  font-size: 23px;
  text-decoration: none;
}

.theory-entry a:hover { background: #f2f2f2; }

.theory-curtain {
  position: fixed;
  inset: 0;
  z-index: 85;
  background: #fff;
  opacity: 0;
  pointer-events: none;
}

.theory-board { width: min(1320px, 100%); margin-inline: auto; }

.theory-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.theory-heading h2 {
  margin: 0;
  font: 650 clamp(27px, 3.3vw, 47px)/1.05 var(--sans);
  letter-spacing: -.045em;
}

.theory-replay {
  display: grid;
  flex: none;
  place-items: center;
  width: 38px;
  height: 38px;
  padding: 0;
  border: 1px solid #ddc59d;
  border-radius: 50%;
  background: #fbf5e8;
  color: #805423;
  cursor: pointer;
}
.theory-replay[hidden] { display: none; }
.theory-replay:hover { background: #f3e5ca; }

.theory-layout {
  display: grid;
  position: relative;
  grid-template-columns: minmax(0, 44fr) minmax(36px, 11fr) minmax(0, 45fr);
  grid-template-rows: repeat(3, minmax(218px, auto));
  align-items: center;
  column-gap: clamp(12px, 2.1vw, 30px);
  --row-gap: clamp(24px, 4.2vw, 58px);
  row-gap: var(--row-gap);
  padding-top: 20px;
}

.theory-diagrams { display: contents; }

.theory-stack {
  opacity: 0;
  position: absolute;
  width: min(29%, 300px);
  height: auto;
  top: 20px;
  left: 35%;
  translate: -50% 0;
  mix-blend-mode: multiply;
  filter: grayscale(1) brightness(1.16);
  pointer-events: none;
}

.theory-morph {
  position: absolute;
  opacity: 0;
  background-image: var(--world-image);
  background-repeat: no-repeat;
  filter: grayscale(1) brightness(1.13) contrast(1.1);
  mix-blend-mode: multiply;
  transform-origin: center;
  pointer-events: none;
}

.theory-visual { min-width: 0; grid-column: 1; margin: 0; text-align: center; }

.theory-art {
  position: relative;
  isolation: isolate;
  width: min(100%, calc(clamp(170px, 24vw, 236px) * 1.8333));
  margin-inline: auto;
  overflow: hidden;
  --spark-path: ellipse(43% 14% at 50% 53%);
  --spark-period: 7s;
}

.theory-visual--time .theory-art {
  --spark-path: ellipse(44% 16% at 50% 64%);
  --spark-period: 8s;
}

.theory-visual--agency .theory-art {
  --spark-path: ellipse(45% 15% at 50% 55%);
  --spark-period: 9s;
}

.theory-visual img {
  display: block;
  width: 100%;
  height: auto;
  filter: grayscale(1) sepia(.12) contrast(1.13);
}

.theory-visual--agency img { filter: saturate(.82) contrast(1.08); }

.theory-art::after {
  content: "";
  position: absolute;
  inset: 6% 4%;
  pointer-events: none;
  background:
    radial-gradient(ellipse 9% 14% at 37% 59%, #fff5cd, #f7a83d9c 55%, transparent),
    radial-gradient(ellipse 15% 18% at 46% 63%, #aabaffd9, #8d78f866 42%, transparent),
    radial-gradient(ellipse 18% 22% at 62% 55%, #ffd780b3, #b1d8fa4f 54%, transparent);
  background-size: 176% 100%;
  background-repeat: no-repeat;
  mask-image: radial-gradient(ellipse 48% 37% at 50% 58%, #000 45%, transparent 100%);
  mix-blend-mode: screen;
  opacity: 0;
}

.theory-sparks { position: absolute; inset: 0; pointer-events: none; }
.theory-sparks i { display: none; }

@supports (offset-path: ellipse(20% 10% at 50% 50%)) {
  .theory-playing .theory-sparks i {
    display: block;
    position: absolute;
    top: 0;
    left: 0;
    width: clamp(12px, 2.4vw, 25px);
    height: 5px;
    offset-path: var(--spark-path);
    background: radial-gradient(ellipse, #fff9e6 10%, var(--spark-color, #e7a64b) 37%, transparent 72%);
    filter: drop-shadow(0 0 3px var(--spark-color, #e7a64b));
    animation: theory-orbit var(--spark-period) calc(4.42s + var(--beat) + var(--spark-shift, 0s)) linear infinite backwards;
  }

  .theory-sparks i:nth-child(2) { --spark-color: #73aee7; --spark-shift: -5.9s; }
  .theory-sparks i:nth-child(3) { --spark-color: #ae7cdf; --spark-shift: -7.4s; }
  .theory-sparks i:nth-child(4) { --spark-color: #f3b971; --spark-shift: -9.3s; }
}

.theory-visual figcaption {
  margin-top: 9px;
  color: var(--ink);
  font: 700 clamp(15px, 1.7vw, 23px)/1.25 var(--sans);
  text-wrap: balance;
}

.theory-arrow {
  grid-column: 2;
  position: relative;
  align-self: stretch;
  display: grid;
  place-items: center;
  min-height: 62px;
}

.theory-arrow span {
  z-index: 1;
  max-width: 11ch;
  padding: 7px 5px;
  border: 1px solid #eee2cd;
  border-radius: 9px;
  background: #fcf8ef;
  color: var(--graphite);
  font: 720 clamp(13px, 1.4vw, 19px)/1.14 var(--sans);
  text-align: center;
}

.theory-arrow i {
  position: absolute;
  inset: calc(50% - 1px) 0 auto 0;
  height: 2px;
  background: #a6a19b;
}

.theory-arrow i::after {
  position: absolute;
  top: -3px;
  right: 0;
  width: 7px;
  height: 7px;
  border: solid #a48349;
  border-width: 1px 1px 0 0;
  transform: rotate(45deg);
  content: "";
}

.theory-arrow::before {
  content: "";
  position: absolute;
  left: calc(50% - 1px);
  width: 2px;
  inset-block: 0 calc(-1 * var(--row-gap));
  background: #d0c6b9;
}
.theory-arrow--state::before { top: 50%; }
.theory-arrow--agency::before { bottom: 50%; }
.theory-arrow:not(.theory-arrow--state)::after {
  content: "";
  position: absolute;
  top: calc(50% - 38px);
  left: calc(50% - 4px);
  width: 7px;
  height: 7px;
  border: solid #a48349;
  border-width: 0 1px 1px 0;
  transform: rotate(45deg);
}

.theory-row {
  --panel-gold: #735322;
  --panel-text: #232322;
  --panel-muted: #56524e;
  --panel-line: #dfdbd4;
  --panel-unroll: 1.38s;
  grid-column: 3;
  align-self: center;
  position: relative;
  isolation: isolate;
  min-width: 0;
  border: 1px solid #dedbd5;
  border-radius: 15px;
  padding: clamp(15px, 1.85vw, 25px);
  background:
    radial-gradient(ellipse at 2% 0, #f5efe473, transparent 63%), #fff;
  color: var(--panel-text);
  box-shadow: 0 12px 28px -22px #51413255;
}

.theory-row::before {
  content: "";
  position: absolute;
  inset: 0 10% auto;
  height: 1px;
  background: linear-gradient(90deg, transparent 38%, #d8a456 46%, #fbe3ac 50%, #bd8b4b 54%, transparent 62%) 100% 0 / 260% 100%;
  filter: drop-shadow(0 0 3px #f3bf6199);
  pointer-events: none;
}

.theory-visual--state, .theory-arrow--state, .theory-row--state { grid-row: 1; --beat: 0s; }
.theory-visual--time, .theory-arrow--time, .theory-row--time { grid-row: 2; --beat: .24s; }
.theory-visual--agency, .theory-arrow--agency, .theory-row--agency { grid-row: 3; --beat: .48s; }

.theory-mobile-bridge { display: none; }

.theory-row-title h3 {
  margin: 0 0 13px;
  color: var(--panel-text);
  font: 700 clamp(20px, 2.3vw, 31px)/1.13 var(--sans);
  overflow-wrap: anywhere;
}

.theory-transitions {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 5px;
  margin: 11px 0 0;
  padding: 0;
  list-style: none;
}

.theory-transitions li {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 6px 5px;
  border: 1px solid color-mix(in srgb, var(--transition-color) 36%, white);
  border-radius: 6px;
  background: color-mix(in srgb, var(--transition-color) 12%, white);
  color: var(--panel-text);
  font: 650 clamp(11px, 1.1vw, 14px)/1.28 var(--sans);
}
.theory-transitions span { color: var(--transition-color); font-size: 15px; }
.theory-transitions li:nth-child(1) { --transition-color: #517739; }
.theory-transitions li:nth-child(2) { --transition-color: #4b709d; }
.theory-transitions li:nth-child(3) { --transition-color: #77598d; }
.theory-transitions li:nth-child(4) { --transition-color: #786377; }

.theory-details .theory-symbols {
  display: grid;
  grid-template-columns: max-content minmax(0, 1fr);
  column-gap: 10px;
  row-gap: 5px;
  border-top: 1px solid var(--panel-line);
  margin: 13px 0 0;
  padding-top: 10px;
  color: var(--panel-muted);
  font: 500 13px/1.42 var(--sans);
}
.theory-details .theory-symbols dt { margin: 0; color: var(--panel-gold); }
.theory-details .theory-symbols dd { margin: 0; }

.theory-details { margin-top: 14px; font: 500 15px/1.45 var(--sans); }
.theory-details summary { width: fit-content; color: var(--panel-gold); font-weight: 650; cursor: pointer; }
.theory-details summary:focus-visible { outline: 2px solid var(--panel-gold); outline-offset: 4px; }
.theory-details dl { margin: 10px 0 0; }
.theory-details dt { margin-top: 8px; font-weight: 700; }
.theory-details dd { margin: 2px 0 0; color: var(--panel-muted); }

.theory-state-flow,
.theory-timeline,
.theory-capabilities {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  align-items: stretch;
  gap: 12px;
}

.theory-state-flow {
  grid-template-columns: minmax(0, 1.12fr) 19px minmax(0, 1fr);
  align-items: center;
  gap: 0;
}
.theory-state-inputs {
  display: grid;
  gap: 11px;
  margin: 0;
  padding: 0;
  list-style: none;
}
.theory-reconstruction-link, .theory-state-inputs > li + li::before {
  width: 100%;
  height: 7px;
  background: #b58b52;
  clip-path: polygon(0 41%, 72% 41%, 72% 0, 100% 50%, 72% 100%, 72% 59%, 0 59%);
}
.theory-state-inputs > li + li::before {
  content: "";
  position: absolute;
  top: -10px;
  left: calc(50% - 5px);
  width: 10px;
  transform: rotate(90deg);
}

.theory-timeline-label {
  margin: 0 0 5px;
  color: var(--panel-gold);
  font: 650 14px/1.25 var(--sans);
}

.theory-timeline {
  position: relative;
  grid-template-columns: minmax(0, .9fr) minmax(0, .95fr) minmax(0, 1.15fr);
  padding: 14px 7px;
  border-radius: 9px;
  background: linear-gradient(150deg, #4a4948, #2b2b2c);
}
.theory-timeline::before, .theory-timeline::after {
  content: "";
  position: absolute;
  inset-inline: 8px;
  height: 4px;
  background: repeating-linear-gradient(90deg, #fff9 0 6px, transparent 6px 12px);
  border-radius: 2px;
}
.theory-timeline::before { top: 5px; }
.theory-timeline::after { bottom: 5px; }
.theory-timeline .theory-node {
  --still-x: 20%;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  min-height: 76px;
  gap: 0;
  padding: 0;
  border: 1px solid #c5c0b7;
  background: #f6f5f2;
  text-align: center;
  font-size: clamp(12px, 1.18vw, 16px);
}
.theory-timeline .theory-node:nth-child(2) {
  --still-x: 51%;
  background: #fff4df;
  border-color: #e9ba70;
  box-shadow: 0 0 10px #eab85c7a;
}
.theory-timeline .theory-node:nth-child(3) { --still-x: 83%; }
.theory-timeline .theory-node::after {
  content: "";
  order: -1;
  flex: auto;
  min-height: 35px;
  border-radius: 6px 6px 0 0;
  background: url("./assets/theory-story/trajectory.webp") var(--still-x) 47% / 410% auto;
  filter: grayscale(1) contrast(.86) brightness(1.2);
}
.theory-timeline .theory-node:nth-child(2)::after { filter: grayscale(1) sepia(.55) brightness(1.2); }
.theory-timeline .theory-node strong { padding: 4px 3px; }

.theory-levels {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 6px;
  margin: 0 0 13px;
  padding: 0;
  list-style: none;
  text-align: center;
}
.theory-levels li {
  display: grid;
  justify-items: center;
  align-content: start;
  gap: 6px;
  color: var(--panel-muted);
  font: 550 12px/1.2 var(--sans);
  overflow-wrap: anywhere;
  position: relative;
}
.theory-levels strong {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 1px solid #d7d4cf;
  background: #f8f7f4;
  color: var(--panel-text);
  font-size: 14px;
}
.theory-levels li:nth-last-child(-n+2) strong {
  border-color: #d3a75e;
  background: #fae9c5;
  box-shadow: 0 0 10px #f0c47865;
  color: var(--panel-gold);
}

@media (min-width: 821px) {
  .theory-levels li:not(:last-child)::after {
    content: "";
    position: absolute;
    top: 14px;
    left: calc(50% + 18px);
    width: calc(100% - 30px);
    height: 7px;
    background: linear-gradient(90deg, #d0b487, #987044);
    clip-path: polygon(0 43%, 79% 43%, 73% 0, 100% 50%, 73% 100%, 79% 57%, 0 57%);
  }
  .theory-levels li:nth-child(n+4)::after { background: linear-gradient(90deg, #e5bc72, #be8936); }
}

.theory-node {
  position: relative;
  display: grid;
  align-content: center;
  gap: 3px;
  min-width: 0;
  padding: 11px 9px;
  border: 1px solid var(--panel-line);
  border-radius: 7px;
  background: #fbfaf8;
  color: var(--panel-text);
  font: 600 clamp(14px, 1.27vw, 17px)/1.26 var(--sans);
  overflow-wrap: anywhere;
}

.theory-node > span { color: var(--panel-muted); font-size: .91em; }
.theory-node--scene { background: #f9f3e6; border-color: #e7d8b6; color: #5c451f; }
.theory-node--event { background: #eef3f3; border-color: #cedddd; color: #294b4c; }
.theory-node--latent { background: #f4eff8; border-color: #ded1eb; color: #4f3b62; }
.theory-capabilities .theory-node:nth-child(1) { background: #eef3f9; border-color: #c7d8eb; }
.theory-capabilities .theory-node:nth-child(2) { background: #f3edf7; border-color: #ddcde8; }
.theory-node--outcome, .theory-capabilities .theory-node:last-child {
  border-color: #e0ccaa;
  background: #fbf4e7;
  color: var(--panel-gold);
}
.theory-node--future { border-style: dashed; }

.theory-timeline > * + *,
.theory-capabilities > * + * { position: relative; }

.theory-timeline > * + *::before,
.theory-capabilities > * + *::before {
  content: "";
  position: absolute;
  top: calc(50% - 3px);
  right: 100%;
  width: 12px;
  height: 6px;
  background: #d5a665;
  clip-path: polygon(0 40%, 65% 40%, 65% 0, 100% 50%, 65% 100%, 65% 60%, 0 60%);
}

@media (prefers-reduced-motion: no-preference) {
  .theory-ready:not(.theory-playing) .theory-board { visibility: hidden; }
  .theory-cued .theory-entry a span { animation: theory-pull 1.55s ease-in-out 2; }
  .theory-entering.theory-playing .theory-curtain { animation: theory-white 1.05s ease-in-out both; }
  .theory-playing .theory-stack { animation: theory-stack-in 2.12s ease-out both; }
  .theory-playing .theory-visual { animation: theory-develop .78s calc(3.55s + var(--beat)) ease-out both; }
  .theory-playing .theory-art img { animation: theory-relight 1.45s calc(3.7s + var(--beat)) both; }
  .theory-playing .theory-art::after { animation: theory-light-scan 5.2s calc(4.25s + var(--beat)) ease-in-out infinite; }
  .theory-playing .theory-visual--agency img { animation-name: theory-relight-agency; }
  .theory-playing .theory-arrow { animation: theory-develop .52s calc(4.36s + var(--beat)) both; }
  .theory-playing .theory-arrow i {
    background: linear-gradient(90deg, #a6a19b 45%, #ffc461 49%, #ffe7a4 51%, #a6a19b 55%) 100% 50% / 250% 100%;
    animation: theory-across 3.6s calc(4.55s + var(--beat)) linear infinite;
  }
  .theory-playing .theory-arrow::before {
    background: linear-gradient(#d0c6b9 45%, #ffc461 49%, #ffe7a4 51%, #d0c6b9 55%) 50% 100% / 100% 250%;
    animation: theory-down 3.6s calc(4.55s + var(--beat)) linear infinite;
  }
  .theory-playing .theory-art {
    animation: theory-unroll .82s calc(3.73s + var(--beat)) cubic-bezier(.25,.65,.25,1) both;
  }
  .theory-playing .theory-art::before {
    content: "";
    position: absolute;
    z-index: 1;
    inset-block: 9%;
    width: 4%;
    background: radial-gradient(ellipse at right, #fff6d5, #d5a86090 48%, transparent 75%);
    pointer-events: none;
    animation: theory-roll-edge .82s calc(3.73s + var(--beat)) cubic-bezier(.25,.65,.25,1) both;
  }
  .theory-playing .theory-row {
    animation: theory-unroll var(--panel-unroll) calc(4.78s + var(--beat)) cubic-bezier(.25,.65,.25,1) both;
  }
  .theory-playing .theory-row::before {
    animation: theory-across 5.2s calc(6.18s + var(--beat)) linear infinite;
  }
  .theory-playing .theory-row::after {
    content: "";
    position: absolute;
    inset-block: -1px;
    width: clamp(9px, 4%, 20px);
    border-radius: 45%;
    background: linear-gradient(90deg, transparent, #e5bc753d, #d4a45eb8 82%, #fff2ce);
    filter: drop-shadow(0 0 5px #e5bd7480);
    pointer-events: none;
    animation: theory-roll-edge var(--panel-unroll) calc(4.78s + var(--beat)) cubic-bezier(.25,.65,.25,1) both;
  }
}

@keyframes theory-pull {
  0%, 100% { transform: translateY(-3px); }
  55% { transform: translateY(5px); }
}
@keyframes theory-white {
  0% { opacity: 1; transform: translateY(100%); }
  34%, 57% { opacity: 1; transform: translateY(0); }
  100% { opacity: 0; transform: translateY(0); visibility: hidden; }
}
@keyframes theory-stack-in {
  0%, 24%, 100% { opacity: 0; }
  46%, 69% { opacity: .78; }
}
@keyframes theory-develop { from { opacity: 0; } to { opacity: 1; } }
@keyframes theory-relight {
  0%, 24% { filter: grayscale(1) contrast(1.66); }
  100% { filter: grayscale(1) sepia(.12) contrast(1.13); }
}
@keyframes theory-relight-agency {
  0%, 24% { filter: grayscale(1) contrast(1.66); }
  100% { filter: saturate(.82) contrast(1.08); }
}
@keyframes theory-orbit {
  0% { offset-distance: 0%; opacity: .18; }
  26% { opacity: .86; }
  54% { opacity: .35; }
  77% { opacity: 1; }
  100% { offset-distance: 100%; opacity: .18; }
}
@keyframes theory-light-scan {
  0% { opacity: 0; background-position: 100% 50%; }
  13% { opacity: .3; }
  29% { opacity: .93; }
  52% { opacity: .61; }
  77%, 100% { opacity: 0; background-position: 0 50%; }
}
@keyframes theory-across { 0% { background-position: 100% 50%; } 76%, 100% { background-position: 0 50%; } }
@keyframes theory-down { 0% { background-position: 50% 100%; } 76%, 100% { background-position: 50% 0; } }
@keyframes theory-unroll {
  0% { clip-path: inset(-3px 100% -3px -3px); visibility: hidden; }
  100% { clip-path: inset(-3px -3px -3px -3px); visibility: visible; }
}
@keyframes theory-roll-edge {
  0% { left: -4%; opacity: 0; }
  10%, 60% { opacity: 1; }
  100% { left: 96%; opacity: 0; }
}

@media (prefers-reduced-motion: reduce) {
  .theory-playing .theory-sparks i { display: none; animation: none; }
}

@media (max-width: 820px) {
  .theory-layout {
    grid-template-columns: minmax(0, .94fr) 19px minmax(0, 1.06fr);
    grid-template-rows: repeat(3, auto);
    --row-gap: 29px;
    gap: var(--row-gap) 9px;
  }
  .theory-row { padding: 10px; }
  .theory-stack { width: 34%; left: 43%; }
  .theory-arrow span, .theory-arrow::before, .theory-arrow::after { display: none; }
  .theory-mobile-bridge { display: block; margin: 0 0 6px; color: var(--panel-gold); font: 650 13px/1.25 var(--sans); }
  .theory-art { width: 100%; }
  .theory-row-title h3 { font-size: clamp(17px, 4.1vw, 23px); }
  .theory-transitions { grid-template-columns: 1fr; }
  .theory-state-flow, .theory-timeline, .theory-capabilities { grid-template-columns: 1fr; gap: 6px; }
  .theory-reconstruction-link { justify-self: center; width: 9px; transform: rotate(90deg); }
  .theory-levels { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .theory-levels li { font-size: 11px; }
  .theory-levels strong { width: 27px; height: 27px; }
  .theory-timeline > * + *::before, .theory-capabilities > * + *::before {
    right: auto;
    left: 50%;
    top: -6px;
    width: 6px;
    height: 6px;
    transform: rotate(90deg);
  }
}
