/* Trading Research Suite portfolio page, version 2.
   A light, calm page: a mist-coloured ground, white objects for the five parts of the
   system, one teal accent for evidence above the baseline. Newsreader carries the
   narration, IBM Plex Sans carries the product. */

@font-face {
  font-family: 'Newsreader Variable';
  font-style: normal;
  font-display: swap;
  font-weight: 200 800;
  src: url(../vendor/fonts/newsreader-latin-opsz-normal.woff2) format('woff2-variations');
}
@font-face {
  font-family: 'IBM Plex Sans Variable';
  font-style: normal;
  font-display: swap;
  font-weight: 100 700;
  src: url(../vendor/fonts/ibm-plex-sans-latin-wght-normal.woff2) format('woff2-variations');
}

:root {
  --ground: #e9eef1;
  --stage: #e1e8ec;
  --surface: #ffffff;
  --tint: #f2f5f7;
  --ink: #17212b;
  --ink-2: #44525f;
  --ink-3: #5c6a77;
  --line: #d2dbe1;
  --line-strong: #a9b7c1;
  --accent: #0e7c6b;
  --accent-deep: #0a5f52;
  --accent-soft: #d3ece6;
  --warm: #a8641d;
  --warm-soft: #f3e3cf;
  --down: #c4513a;

  --serif: 'Newsreader Variable', 'Iowan Old Style', Georgia, serif;
  --sans: 'IBM Plex Sans Variable', system-ui, -apple-system, 'Segoe UI', sans-serif;

  --bar-h: 56px;
  --gutter: clamp(16px, 4vw, 56px);
  --radius: 18px;
  --ease-out: cubic-bezier(0.23, 1, 0.32, 1);
  --ease-in-out: cubic-bezier(0.65, 0, 0.35, 1);
  --rise: 14px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}
html {
  background: var(--ground);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 100%;
  line-height: 1.55;
  -webkit-text-size-adjust: 100%;
}
body {
  margin: 0;
  min-width: 320px;
  overflow-x: clip;
  font-variant-numeric: tabular-nums;
}
h1, h2, p, dl, dd, ol, ul {
  margin: 0;
}
ol, ul {
  padding: 0;
  list-style: none;
}
a {
  color: inherit;
}
button {
  font: inherit;
  color: inherit;
}
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
  border-radius: 6px;
}
::selection {
  background: var(--accent-soft);
}

.skip-link {
  position: fixed;
  left: 12px;
  top: 8px;
  z-index: 50;
  padding: 10px 14px;
  border-radius: 8px;
  background: var(--ink);
  color: #fff;
  font-weight: 600;
  text-decoration: none;
  transform: translateY(-200%);
}
.skip-link:focus {
  transform: none;
}

/* ---------- Bar ---------- */

.bar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 24px;
  height: var(--bar-h);
  padding-inline: var(--gutter);
  background: var(--ground);
}
.bar__name {
  margin-right: auto;
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
}
.bar__nav {
  display: flex;
  gap: clamp(14px, 2.4vw, 28px);
}
.bar__nav a {
  padding-block: 8px;
  color: var(--ink-2);
  text-decoration: none;
}
@media (hover: hover) and (pointer: fine) {
  .bar__nav a:hover {
    color: var(--ink);
  }
}
@media (max-width: 440px) {
  .bar {
    gap: 12px;
  }
  .bar__name {
    font-size: 0.875rem;
  }
  .bar__nav {
    gap: 12px;
    font-size: 0.875rem;
  }
}

/* ---------- Hero ---------- */

.hero {
  position: relative;
  max-width: 1320px;
  margin-inline: auto;
  padding: clamp(56px, 12vh, 140px) var(--gutter) clamp(48px, 10vh, 120px);
}
.hero > :not(.motif) {
  position: relative;
  z-index: 1;
}

/* One square that opens into the 18 configurations of the story. */
.motif {
  display: none;
}
@media (min-width: 1100px) {
  .motif {
    position: absolute;
    right: var(--gutter);
    bottom: clamp(64px, 12vh, 140px);
    display: block;
    width: 240px;
    height: 150px;
  }
}
.motif i {
  position: absolute;
  left: 0;
  top: 0;
  width: 30px;
  height: 34px;
  border-radius: 7px;
  background: #cdd7de;
  transform: translate(var(--cx), var(--cy)) scale(0.9);
  opacity: 0;
  transition: transform 900ms var(--ease-in-out), opacity 400ms ease, background-color 600ms ease;
  transition-delay: calc(var(--i) * 40ms);
}
.motif i:first-child {
  opacity: 1;
  background: var(--ink);
}
.motif.is-open i {
  opacity: 1;
  transform: translate(var(--x), var(--y));
}
.motif.is-open i.is-strong {
  background: var(--accent);
}
.motif.is-open i:first-child {
  background: #cdd7de;
}
.motif.is-open i:first-child.is-strong {
  background: var(--accent);
}
.hero h1 {
  font-family: var(--serif);
  font-weight: 380;
  font-size: clamp(2.6rem, 6.4vw + 0.6rem, 7rem);
  line-height: 1;
  letter-spacing: -0.025em;
}
.hero__lede {
  max-width: 34ch;
  margin-top: clamp(24px, 4vh, 40px);
  color: var(--ink-2);
  font-size: clamp(1.125rem, 0.6vw + 1rem, 1.375rem);
  line-height: 1.5;
}
.demo-note {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
  max-width: 60ch;
  margin-top: 28px;
  color: var(--ink-3);
  font-size: 0.9375rem;
}
.demo-tag,
.stage-tag {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--warm-soft);
  color: #7a4610;
  font-size: 0.8125rem;
  font-weight: 600;
  white-space: nowrap;
}
.motion-note {
  max-width: 60ch;
  margin-top: 14px;
  color: var(--ink-3);
  font-size: 0.875rem;
}
.motion-note button {
  margin-left: 6px;
  padding: 5px 12px;
  border: 0;
  border-radius: 999px;
  background: var(--surface);
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
}

/* ---------- Story layout: steps beside a sticky stage ---------- */

.story {
  position: relative;
  display: grid;
  grid-template-columns: minmax(300px, 4fr) minmax(0, 7fr);
  column-gap: clamp(24px, 3vw, 48px);
  max-width: 1480px;
  margin-inline: auto;
  padding-inline: var(--gutter);
}
.stage {
  position: sticky;
  top: calc(var(--bar-h) + 8px);
  grid-column: 2;
  grid-row: 1;
  align-self: start;
  height: calc(100vh - var(--bar-h) - 32px);
  border-radius: 24px;
  background: var(--stage);
  overflow: hidden;
  isolation: isolate;
}
.steps {
  grid-column: 1;
  grid-row: 1;
}
.step {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 14px;
  min-height: 137vh;
  padding-block: 12vh;
}
.step:first-child {
  min-height: 103vh;
  padding-top: 8vh;
}
.step--end {
  min-height: 110vh;
}
.step h2 {
  max-width: 14em;
  font-family: var(--serif);
  font-weight: 400;
  font-size: clamp(1.9rem, 1.6vw + 1.1rem, 2.75rem);
  line-height: 1.08;
  letter-spacing: -0.015em;
}
.step > p {
  max-width: 30ch;
  color: var(--ink-2);
  font-size: 1.125rem;
}
.step .decision {
  max-width: 34ch;
  margin-top: 8px;
  color: var(--ink);
  font-size: 1rem;
}
.step .decision b {
  display: block;
  font-weight: 600;
}
.step .btn {
  align-self: flex-start;
  margin-top: 10px;
}

.btn {
  display: inline-flex;
  align-items: center;
  min-height: 46px;
  padding: 10px 22px;
  border: 0;
  border-radius: 999px;
  background: var(--ink);
  color: #fff;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  transition: transform 140ms var(--ease-out), background-color 160ms ease;
}
.btn:active {
  transform: scale(0.97);
}
@media (hover: hover) and (pointer: fine) {
  .btn:hover {
    background: #26343f;
  }
}

/* Progressive disclosure */
.more {
  max-width: 34ch;
  margin-top: 6px;
}
.more summary {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 36px;
  color: var(--accent-deep);
  font-size: 0.9375rem;
  font-weight: 600;
  cursor: pointer;
  list-style: none;
}
.more summary::-webkit-details-marker {
  display: none;
}
.more summary::before {
  content: '';
  width: 7px;
  height: 7px;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(-45deg);
  transition: transform 180ms var(--ease-out);
}
.more[open] summary::before {
  transform: rotate(45deg);
}
.more p {
  padding: 4px 0 6px 15px;
  color: var(--ink-2);
  font-size: 0.9375rem;
}

/* ---------- The world: five objects, connected ---------- */

.world {
  position: absolute;
  left: 0;
  top: 0;
  transform-origin: 0 0;
  will-change: transform;
}
.paths {
  position: absolute;
  left: 0;
  top: 0;
  overflow: visible;
}
.path {
  fill: none;
  stroke: var(--line-strong);
  stroke-width: 2;
  stroke-linecap: round;
  stroke-dasharray: 2 7;
  vector-effect: non-scaling-stroke;
  transition: stroke 300ms ease;
}
.path.is-on {
  stroke: var(--accent);
  stroke-width: 2.5;
  stroke-dasharray: none;
}
.path[data-path='back'].is-on {
  stroke-dasharray: 9 6;
}

.obj {
  position: absolute;
  display: grid;
  place-items: center;
  border-radius: 16px;
  background: var(--surface);
  box-shadow: 0 1px 2px rgba(23, 33, 43, 0.06), 0 10px 30px rgba(23, 33, 43, 0.06);
  transition: opacity 400ms ease;
}
.obj svg {
  width: 72%;
  height: 72%;
  opacity: var(--glyph, 1);
}
.obj--mcp {
  border-radius: 50%;
}
.obj.is-dim {
  opacity: 0.5;
}
.obj.is-lit::after {
  content: '';
  position: absolute;
  inset: -5px;
  border: 2px solid var(--accent);
  border-radius: 20px;
}
.obj--mcp.is-lit::after {
  border-radius: 50%;
}
.g-ink {
  fill: var(--ink);
}
.g-soft {
  fill: #cdd7de;
}
.g-mid {
  fill: #8d9daa;
}
.g-line {
  fill: #8d9daa;
}
.g-paper {
  fill: #fff;
}
.g-up {
  fill: var(--accent);
}
.g-down {
  fill: var(--down);
}

/* Names stay crisp: they live outside the zoomed world. */
.labels {
  position: absolute;
  inset: 0;
  pointer-events: none;
}
.label {
  position: absolute;
  left: 0;
  top: 0;
  display: grid;
  justify-items: center;
  text-align: center;
  white-space: nowrap;
  will-change: transform, opacity;
}
.label b {
  font-size: 0.9375rem;
  font-weight: 600;
}
.label span {
  color: var(--ink-3);
  font-size: 0.8125rem;
}
.packet {
  position: absolute;
  left: 0;
  top: 0;
  padding: 6px 14px;
  border-radius: 999px;
  background: var(--ink);
  color: #fff;
  font-size: 0.8125rem;
  font-weight: 600;
  white-space: nowrap;
  opacity: 0;
  will-change: transform, opacity;
}
.packet--back {
  background: var(--accent);
}

.minimap {
  position: absolute;
  left: 20px;
  top: 18px;
  z-index: 4;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px 6px 10px;
  border-radius: 999px;
  background: var(--tint);
  opacity: 0;
  transition: opacity 250ms ease;
  pointer-events: none;
}
.minimap.is-on {
  opacity: 1;
}
.minimap i {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--line-strong);
}
.minimap i.is-here {
  background: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.minimap span {
  margin-left: 6px;
  color: var(--ink-2);
  font-size: 0.8125rem;
  font-weight: 600;
}
.stage-tag {
  position: absolute;
  right: 18px;
  top: 16px;
  z-index: 4;
}

/* Scene rail: where you are in the story, and a way back. */
.rail {
  position: absolute;
  right: 12px;
  top: 50%;
  z-index: 4;
  transform: translateY(-50%);
}
.rail ol {
  display: grid;
  gap: 2px;
}
.rail button {
  position: relative;
  display: grid;
  place-items: center;
  width: 24px;
  height: 22px;
  padding: 0;
  border: 0;
  background: transparent;
  cursor: pointer;
}
.rail button::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 3px;
  background: var(--line-strong);
  transition: height 260ms var(--ease-out), background-color 200ms ease;
}
.rail button[aria-current='step']::before {
  height: 16px;
  background: var(--accent);
}
.rail span {
  position: absolute;
  right: 28px;
  top: 50%;
  padding: 4px 10px;
  border-radius: 8px;
  background: var(--ink);
  color: #fff;
  font-size: 0.8125rem;
  white-space: nowrap;
  opacity: 0;
  transform: translate(4px, -50%);
  transition: opacity 140ms ease, transform 160ms var(--ease-out);
  pointer-events: none;
}
.rail button:focus-visible span {
  opacity: 1;
  transform: translate(0, -50%);
}
@media (hover: hover) and (pointer: fine) {
  .rail button:hover span {
    opacity: 1;
    transform: translate(0, -50%);
  }
  .rail button:hover::before {
    background: var(--ink-3);
  }
}

/* ---------- Details: what the camera finds inside an object ---------- */

.detail {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: flex;
  flex-direction: column;
  padding: 64px clamp(20px, 4vw, 56px) clamp(20px, 3vw, 40px);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}
.detail.is-live {
  pointer-events: auto;
}
.detail__where {
  position: absolute;
  left: 20px;
  top: 18px;
  display: none;
}

/* Cards float over the map rather than replacing it. */
.detail--card {
  inset: auto clamp(16px, 3vw, 32px) clamp(16px, 3vw, 32px);
  width: auto;
  max-width: 460px;
  margin-inline: auto;
  padding: 22px 24px;
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: 0 2px 6px rgba(23, 33, 43, 0.06), 0 18px 40px rgba(23, 33, 43, 0.1);
  transform: translateY(calc(var(--rise) * (1 - var(--w, 1))));
}
.card__kicker {
  color: var(--accent-deep);
  font-size: 0.8125rem;
  font-weight: 600;
}
.card__title {
  margin-top: 2px;
  font-size: 1.1875rem;
  font-weight: 600;
  line-height: 1.3;
}
.card__list {
  display: grid;
  gap: 6px;
  margin-top: 14px;
}
.card__list > div {
  display: grid;
  grid-template-columns: 7.5rem 1fr;
  gap: 12px;
  font-size: 0.9375rem;
}
.card__list dt {
  color: var(--ink-3);
}
.sim-stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}
.sim-stats dt {
  color: var(--ink-3);
  font-size: 0.8125rem;
  line-height: 1.3;
}
.sim-stats dd {
  margin-top: 2px;
  font-size: 1.375rem;
  font-weight: 600;
  line-height: 1.2;
}
.sim-note {
  margin-top: 10px;
  color: var(--ink-2);
  font-size: 0.875rem;
}

/* Chat */
.detail--chat {
  align-items: center;
}
.chat {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 14px;
  width: 100%;
  max-width: 620px;
  height: 100%;
  overflow: hidden;
}
.chat.is-full {
  justify-content: flex-end;
  -webkit-mask-image: linear-gradient(to bottom, transparent 0, #000 56px);
  mask-image: linear-gradient(to bottom, transparent 0, #000 56px);
}
.msg {
  max-width: 88%;
  padding: 14px 18px;
  border-radius: 18px;
  font-size: 1.0625rem;
  line-height: 1.5;
  transition: opacity 360ms var(--ease-out), transform 420ms var(--ease-out);
}
.msg p + p {
  margin-top: 8px;
}
.msg--you {
  align-self: flex-end;
  border-bottom-right-radius: 6px;
  background: var(--ink);
  color: #fff;
}
.msg--ai {
  align-self: flex-start;
  border-bottom-left-radius: 6px;
  background: var(--tint);
}
.msg.is-hidden {
  display: none;
}
.msg.is-new {
  opacity: 0;
  transform: translateY(var(--rise));
}
.msg.is-typing > * {
  visibility: hidden;
}
.msg.is-typing {
  position: relative;
  width: 72px;
  height: 48px;
  padding: 0;
}
.msg.is-typing::after {
  content: '';
  position: absolute;
  left: 20px;
  top: 21px;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--ink-3);
  box-shadow: 12px 0 0 var(--ink-3), 24px 0 0 var(--ink-3);
  animation: typing 0.45s ease-in-out 4 alternate;
}
@keyframes typing {
  to {
    opacity: 0.35;
  }
}
.cite {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}
.cite button {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 34px;
  padding: 4px 12px 4px 8px;
  border: 0;
  border-radius: 999px;
  background: var(--surface);
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 140ms var(--ease-out), background-color 160ms ease;
}
.cite button:active {
  transform: scale(0.97);
}
.cite i {
  width: 14px;
  height: 14px;
  border-radius: 4px;
  background: var(--accent-soft);
}
.cite button[data-tone='strong'] i {
  background: var(--accent);
}
@media (hover: hover) and (pointer: fine) {
  .cite button:hover {
    background: var(--accent-soft);
  }
}

/* Engine */
.detail--engine {
  justify-content: center;
}
.factors {
  display: grid;
  gap: clamp(18px, 3.4vh, 34px);
  width: 100%;
  max-width: 640px;
  margin-inline: auto;
}
.factor {
  display: grid;
  grid-template-columns: minmax(0, 13rem) 1fr;
  grid-template-rows: auto auto;
  column-gap: 20px;
  align-items: center;
}
.factor__name {
  font-size: 1.125rem;
  font-weight: 600;
}
.factor__hint {
  grid-row: 2;
  color: var(--ink-3);
  font-size: 0.875rem;
}
.chips {
  grid-column: 2;
  grid-row: 1 / 3;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.chips li {
  min-width: 64px;
  padding: 8px 14px;
  border-radius: 12px;
  background: var(--accent-soft);
  color: var(--accent-deep);
  font-weight: 600;
  text-align: center;
  transition: opacity 420ms var(--ease-out), transform 480ms var(--ease-out);
  transition-delay: calc(var(--i, 0) * 70ms + 120ms);
}
.fixed {
  max-width: 640px;
  margin: clamp(22px, 4vh, 40px) auto 0;
  color: var(--ink-3);
  font-size: 0.9375rem;
  transition: opacity 300ms ease;
}
.fixed b {
  margin-right: 6px;
  color: var(--ink-2);
}
.grid-run {
  position: absolute;
  inset: 64px clamp(20px, 4vw, 56px) clamp(20px, 3vw, 40px);
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 16px;
  opacity: 0;
  visibility: hidden;
  transition: opacity 360ms ease, visibility 0s linear 360ms;
}
.grid-run__count {
  color: var(--ink-2);
  font-weight: 600;
  text-align: center;
}
.detail--engine[data-mode='grid'] .grid-run {
  opacity: 1;
  visibility: visible;
  transition: opacity 420ms ease 120ms;
}
.detail--engine[data-mode='grid'] .factors,
.detail--engine[data-mode='grid'] .fixed {
  opacity: 0;
  transition: opacity 240ms ease;
}
.detail--engine[data-mode='factors'] .chips li {
  opacity: 1;
  transform: none;
}
.detail--engine:not([data-mode='factors']) .chips li,
.detail--engine.is-fresh .chips li {
  opacity: 0;
  transform: translateY(8px);
}

/* Matrix (used by the engine run and by the saved results) */
.matrix {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: clamp(16px, 2.4vw, 36px);
  width: 100%;
  max-width: 820px;
  margin-inline: auto;
}
.panel__title {
  margin-bottom: 8px;
  font-weight: 600;
}
.panel__grid {
  display: grid;
  grid-template-columns: 3.2rem repeat(3, minmax(0, 1fr));
  gap: 6px;
}
.panel__grid .hd {
  align-self: end;
  color: var(--ink-3);
  font-size: 0.8125rem;
  text-align: center;
}
.panel__grid .rh {
  align-self: center;
  color: var(--ink-2);
  font-size: 0.875rem;
  font-weight: 600;
}
.cell {
  position: relative;
  display: grid;
  align-content: center;
  justify-items: center;
  min-height: clamp(54px, 8.4vh, 84px);
  padding: 6px 4px;
  border: 0;
  border-radius: 12px;
  background: var(--tint);
  text-align: center;
  transition: background-color 500ms ease, transform 160ms var(--ease-out), box-shadow 200ms ease;
  transition-delay: calc(var(--i, 0) * 45ms), 0s, 0s;
}
.cell b {
  font-size: clamp(1rem, 0.6vw + 0.75rem, 1.25rem);
  font-weight: 600;
  line-height: 1.2;
}
.cell small {
  color: var(--ink-3);
  font-size: 0.75rem;
}
.matrix--results .cell {
  background: var(--bg, var(--tint));
  cursor: pointer;
}
.detail--results.is-fresh .matrix--results .cell {
  background: var(--tint);
  transition: none;
}
.matrix--results .cell:active {
  transform: scale(0.97);
}
.matrix--results .cell[aria-expanded='true'] {
  box-shadow: inset 0 0 0 2px var(--ink);
}
.cell.is-flash {
  box-shadow: inset 0 0 0 2px var(--accent);
}
@media (hover: hover) and (pointer: fine) {
  .matrix--results .cell:hover {
    box-shadow: inset 0 0 0 2px var(--line-strong);
  }
}
/* Engine run: cells fill as the configurations complete. */
.matrix--run .cell {
  min-height: clamp(46px, 7vh, 70px);
  background: var(--tint);
  color: var(--ink-3);
  transition: background-color 260ms ease, color 260ms ease;
  transition-delay: 0s;
}
.matrix--run .cell b {
  font-size: 0.875rem;
  font-weight: 500;
}
.matrix--run .cell.is-done {
  background: var(--accent-soft);
  color: var(--accent-deep);
}
.matrix--run .cell.is-done::after {
  content: '';
  position: absolute;
  right: 9px;
  top: 9px;
  width: 9px;
  height: 5px;
  border-left: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(-45deg);
}

.legend {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 6px 10px;
  margin-top: 16px;
  color: var(--ink-3);
  font-size: 0.8125rem;
}
.legend__item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}
.legend__swatch {
  width: 14px;
  height: 14px;
  border-radius: 4px;
}
.legend__swatch--up {
  background: #5fb3a4;
}
.legend__swatch--flat {
  background: var(--tint);
  box-shadow: inset 0 0 0 1px var(--line);
}

.detail--results {
  justify-content: center;
}
.view {
  position: absolute;
  inset: 64px clamp(20px, 4vw, 56px) clamp(20px, 3vw, 40px);
  display: flex;
  flex-direction: column;
  justify-content: center;
  opacity: 0;
  visibility: hidden;
  transition: opacity 320ms ease, visibility 0s linear 320ms;
}
.detail--results[data-mode='matrix'] .view--matrix,
.detail--results[data-mode='validation'] .view--validation {
  opacity: 1;
  visibility: visible;
  transition: opacity 420ms ease 100ms;
}

.cell-card {
  position: absolute;
  left: 50%;
  top: 50%;
  z-index: 2;
  width: min(380px, calc(100% - 16px));
  padding: 20px 22px 18px;
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: 0 2px 6px rgba(23, 33, 43, 0.08), 0 24px 48px rgba(23, 33, 43, 0.16);
  transform: translate(-50%, -50%);
  animation: card-in 220ms var(--ease-out);
}
@keyframes card-in {
  from {
    opacity: 0;
    transform: translate(-50%, calc(-50% + 8px)) scale(0.98);
  }
}
.cell-card[hidden] {
  display: none;
}
@media (min-width: 900px) {
  .cell-card[data-side='left'] {
    left: 25%;
  }
  .cell-card[data-side='right'] {
    left: 75%;
  }
}
.cell-card__title {
  font-weight: 600;
  font-size: 1.0625rem;
}
.cell-card__q {
  margin-top: 6px;
  color: var(--ink-2);
  font-size: 0.9375rem;
}
.cell-card__stats {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px 16px;
  margin-top: 14px;
}
.cell-card__stats dt {
  color: var(--ink-3);
  font-size: 0.8125rem;
}
.cell-card__stats dd {
  font-weight: 600;
}
.cell-card__stats .wide {
  grid-column: 1 / -1;
  padding-top: 10px;
  border-top: 1px solid var(--line);
}
.cell-card__close {
  margin-top: 14px;
  padding: 7px 14px;
  border: 0;
  border-radius: 999px;
  background: var(--tint);
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
}

/* Validation */
.val__title {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-bottom: 18px;
  color: var(--ink-2);
  font-weight: 600;
}
.val__key {
  width: 12px;
  height: 12px;
  border-radius: 50%;
}
.val__key--res {
  box-shadow: inset 0 0 0 2px var(--ink-3);
}
.val__key--val {
  background: var(--accent);
}
.val__arrow {
  width: 26px;
  height: 2px;
  background: var(--ink-3);
  position: relative;
}
.val__arrow::after {
  content: '';
  position: absolute;
  right: -1px;
  top: -4px;
  width: 8px;
  height: 8px;
  border-right: 2px solid var(--ink-3);
  border-top: 2px solid var(--ink-3);
  transform: rotate(45deg);
}
.val {
  display: grid;
  gap: clamp(14px, 2.6vh, 24px);
  width: 100%;
  max-width: 760px;
  margin-inline: auto;
}
.val li {
  display: grid;
  grid-template-columns: minmax(0, 12rem) minmax(0, 1fr) 6.5rem;
  gap: 4px 18px;
  align-items: center;
}
.val__name {
  font-weight: 600;
  font-size: 0.9375rem;
}
.val__name small {
  display: block;
  color: var(--ink-3);
  font-size: 0.8125rem;
  font-weight: 400;
}
.val__track {
  position: relative;
  height: 34px;
}
.val__track::before {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  top: 16px;
  height: 2px;
  background: var(--line);
}
.val__span {
  position: absolute;
  top: 16px;
  height: 2px;
  background: var(--ink-3);
  transition: left 700ms var(--ease-in-out) 200ms, width 700ms var(--ease-in-out) 200ms;
}
.val__dot {
  position: absolute;
  top: 9px;
  width: 16px;
  height: 16px;
  margin-left: -8px;
  border-radius: 50%;
}
.val__dot--res {
  background: var(--surface);
  box-shadow: inset 0 0 0 2px var(--ink-3);
}
.val__dot--val {
  background: var(--accent);
  transition: left 700ms var(--ease-in-out) 200ms;
}
.val li[data-status='weakened'] .val__dot--val,
.val li[data-status='faded'] .val__dot--val {
  background: var(--warm);
}
.val__status {
  font-size: 0.875rem;
  font-weight: 600;
  text-align: right;
}
.val__status small {
  display: block;
  color: var(--ink-3);
  font-weight: 400;
}
.val__axis {
  display: grid;
  grid-template-columns: minmax(0, 12rem) auto 1fr auto 6.5rem;
  gap: 0 18px;
  width: 100%;
  max-width: 760px;
  margin: 8px auto 0;
  color: var(--ink-3);
  font-size: 0.75rem;
}
.val__axis span:first-child {
  grid-column: 2;
}
.val__axis span:nth-child(2) {
  text-align: center;
}
.ledger {
  margin-top: clamp(18px, 3vh, 30px);
  color: var(--ink-3);
  font-size: 0.875rem;
  text-align: center;
}
.ledger b {
  color: var(--ink);
}

/* Trade Explorer */
.detail--explorer {
  gap: 12px;
  padding-top: 58px;
}
.xp__head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 4px 14px;
}
.xp__config {
  font-weight: 600;
}
.xp__chart {
  position: relative;
  flex: 1;
  min-height: 0;
  border-radius: 14px;
  background: var(--tint);
  overflow: hidden;
}
.xp__canvas {
  position: absolute;
  inset: 0;
}
.xp__readout {
  position: absolute;
  left: 12px;
  top: 10px;
  z-index: 2;
  color: var(--ink-2);
  font-size: 0.8125rem;
  pointer-events: none;
}
.xp__pick {
  display: flex;
  align-items: center;
  gap: 10px;
}
.round {
  flex: none;
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 50%;
  background: var(--tint);
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  transition: transform 140ms var(--ease-out), background-color 160ms ease;
}
.round:active {
  transform: scale(0.94);
}
.round[disabled] {
  opacity: 0.4;
  cursor: default;
}
.trade-strip {
  position: relative;
  flex: 1;
  display: flex;
  align-items: stretch;
  gap: 2px;
  height: 52px;
  overflow-x: auto;
  scrollbar-width: none;
}
.trade-strip::before {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  top: 50%;
  height: 1px;
  background: var(--line-strong);
}
.trade-strip::-webkit-scrollbar {
  display: none;
}
.bar-t {
  position: relative;
  flex: 1 0 6px;
  min-width: 6px;
  padding: 0;
  border: 0;
  background: transparent;
  cursor: pointer;
}
.bar-t i {
  position: absolute;
  left: 1px;
  right: 1px;
  border-radius: 2px;
  background: #8fcbbf;
}
.bar-t.is-neg i {
  background: #e6b0a4;
}
.bar-t[aria-checked='true'] i {
  background: var(--ink);
}
.bar-t:focus-visible {
  outline-offset: 1px;
}
.xp__trade {
  min-height: 3em;
  color: var(--ink-2);
  font-size: 0.9375rem;
}
.xp__trade b {
  color: var(--ink);
  font-weight: 600;
}

.up {
  color: var(--accent-deep);
}
.down {
  color: #a8412c;
}

/* ---------- Footer ---------- */

.foot {
  display: grid;
  gap: 6px;
  max-width: 1480px;
  margin: 0 auto;
  padding: 48px var(--gutter) 40px;
  color: var(--ink-3);
  font-size: 0.8125rem;
}
.foot p {
  max-width: 90ch;
}
.noscript {
  padding: 24px var(--gutter);
}

/* ---------- Without the story script: plain reading order ---------- */

html:not(.js) .stage {
  display: none;
}
html:not(.js) .story {
  display: block;
  max-width: 760px;
}
html:not(.js) .step {
  min-height: 0;
  padding-block: 40px;
}

/* ---------- Narrow screens: stage on top, steps beneath ---------- */

@media (max-width: 899px), (max-height: 520px) {
  :root {
    --stage-h: 58svh;
  }
  .story {
    display: block;
    padding-inline: 0;
  }
  .stage {
    top: var(--bar-h);
    z-index: 5;
    height: var(--stage-h);
    margin-inline: 12px;
    border-radius: 20px;
  }
  .steps {
    position: relative;
    z-index: 1;
    padding-inline: var(--gutter);
  }
  .step,
  .step:first-child {
    justify-content: flex-start;
    gap: 10px;
    min-height: calc((100svh - var(--bar-h) - var(--stage-h) + 12svh) * 1.48);
    padding-block: 28px 32px;
  }
  .step--end {
    min-height: 0;
    padding-bottom: 48px;
  }
  .step h2 {
    font-size: clamp(1.6rem, 4vw + 0.8rem, 2.1rem);
  }
  .step > p {
    max-width: 38ch;
    font-size: 1.0625rem;
  }
  .detail {
    padding: 52px 16px 16px;
  }
  .detail--card {
    inset: auto 10px 10px;
    padding: 16px 18px;
  }
  .card__title {
    font-size: 1.0625rem;
  }
  .card__list {
    margin-top: 10px;
    gap: 4px;
  }
  .card__list > div {
    grid-template-columns: 6.2rem 1fr;
    gap: 8px;
    font-size: 0.875rem;
  }
  .sim-stats {
    margin-top: 10px;
    padding-top: 10px;
  }
  .detail--sim .card__list > div:nth-child(1),
  .detail--sim .card__list > div:nth-child(2) {
    display: none;
  }
  .sim-stats dd {
    font-size: 1.125rem;
  }
  .msg {
    font-size: 0.9375rem;
    padding: 11px 14px;
  }
  .factor {
    grid-template-columns: 1fr;
    row-gap: 6px;
  }
  .factor__hint {
    grid-row: auto;
  }
  .chips {
    grid-column: 1;
    grid-row: auto;
  }
  .chips li {
    min-width: 52px;
    padding: 6px 10px;
  }
  .fixed {
    font-size: 0.8125rem;
  }
  .matrix {
    grid-template-columns: 1fr;
    gap: 10px;
  }
  .panel__title {
    margin-bottom: 4px;
    font-size: 0.875rem;
  }
  .panel__grid {
    grid-template-columns: 2.6rem repeat(3, minmax(0, 1fr));
    gap: 4px;
  }
  .panel__grid .hd {
    font-size: 0.75rem;
  }
  .cell,
  .matrix--run .cell {
    min-height: 0;
    height: clamp(30px, 5svh, 46px);
    border-radius: 9px;
  }
  .cell b {
    font-size: 0.9375rem;
  }
  .cell small,
  .matrix--run .cell b {
    font-size: 0.6875rem;
  }
  .matrix--results .cell small {
    display: none;
  }
  .matrix--run .cell.is-done::after {
    right: 6px;
    top: 6px;
  }
  .grid-run,
  .view {
    inset: 50px 14px 14px;
  }
  .legend {
    margin-top: 8px;
  }
  .val__title {
    margin-bottom: 10px;
    font-size: 0.875rem;
  }
  .val li {
    grid-template-columns: minmax(0, 1fr) 5.4rem;
    gap: 0 10px;
  }
  .val__name {
    grid-column: 1 / -1;
    font-size: 0.875rem;
  }
  .val__name small {
    display: inline;
    margin-left: 6px;
  }
  .val__axis {
    grid-template-columns: auto 1fr auto 5.4rem;
    gap: 0 10px;
  }
  .val__axis span:first-child {
    grid-column: 1;
  }
  .ledger {
    margin-top: 10px;
    font-size: 0.8125rem;
  }
  .detail--explorer {
    gap: 8px;
    padding-top: 50px;
  }
  .xp__head .detail__where {
    display: none;
  }
  .xp__config {
    font-size: 0.875rem;
  }
  .trade-strip {
    height: 40px;
  }
  .xp__trade {
    min-height: 0;
    font-size: 0.8125rem;
    line-height: 1.4;
  }
  .minimap {
    left: 12px;
    top: 12px;
  }
  .rail {
    display: none;
  }
  .stage-tag {
    right: 12px;
    top: 12px;
  }
  .label b {
    font-size: 0.875rem;
  }
  .label span {
    display: none;
  }
}

/* ---------- Motion preferences ---------- */

@media (prefers-reduced-motion: reduce) {
  html:not(.motion-on) {
    --rise: 0px;
  }
  html:not(.motion-on) .msg.is-typing::after {
    animation-duration: 1.4s;
  }
  html:not(.motion-on) .val__span,
  html:not(.motion-on) .val__dot--val,
  html:not(.motion-on) .chips li,
  html:not(.motion-on) .cell {
    transition-property: opacity, background-color;
    transition-duration: 200ms;
    transition-delay: 0s;
  }
  html:not(.motion-on) .detail--engine .chips li {
    transform: none;
  }
  html:not(.motion-on) .cell-card {
    animation: none;
  }
  html:not(.motion-on) .motif i {
    transition-property: opacity, background-color;
    transition-delay: 0s;
  }
}

@media print {
  .stage {
    display: none;
  }
}

/* Short desktop windows: cards get compact so the map keeps room above them. */
@media (min-width: 900px) and (max-height: 820px) {
  .detail--card {
    max-width: 520px;
    padding: 16px 22px;
  }
  .card__title {
    font-size: 1.0625rem;
  }
  .card__list {
    gap: 2px;
    margin-top: 8px;
  }
  .card__list > div {
    font-size: 0.875rem;
  }
  .sim-stats {
    margin-top: 10px;
    padding-top: 8px;
  }
  .sim-stats dd {
    font-size: 1.125rem;
  }
  .sim-note {
    margin-top: 6px;
    font-size: 0.8125rem;
  }
}
@media (min-width: 900px) and (max-height: 700px) {
  /* Very short windows drop the least essential rows, as phones do. */
  .detail--sim .card__list > div:nth-child(1),
  .detail--sim .card__list > div:nth-child(2),
  .detail--return .card__list > div:nth-child(3) {
    display: none;
  }
}

/* Narrow layouts: the card sits under its scene's text instead of over the map. */
.detail.detail--card.is-inline {
  position: static;
  inset: auto;
  max-width: 460px;
  margin: 10px 0 0;
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transform: none;
  box-shadow: none;
}
.detail--card.is-inline .card__list > div {
  display: grid;
}
