/* Simulation viewer. Builds on /styles.css tokens; the stage is always a dark chapter. */

/* The dark section runs up under the sticky bar, so the bar turns dark with it. */
.page-viewer .vw { margin-top: calc(-1 * var(--nav-h)); padding-block: calc(var(--nav-h) + 40px) 72px; background: var(--bg); color: var(--ink); }
.vw-head { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.25fr); gap: 12px 48px; align-items: end; margin-bottom: 28px; }
.vw-head .lede { margin-top: 0; font-size: 17px; line-height: 1.47; max-width: 36em; }

.vw-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 24px;
  align-items: start;
}

/* ---------- Stage ---------- */
.stage-col { display: grid; gap: 14px; min-width: 0; }
/* Never taller than the window below the bar, so the page can always be scrolled past it,
   even zoomed in. A vertical swipe scrolls the page; a sideways one turns the model. */
.stage {
  position: relative;
  height: max(240px, min(clamp(420px, calc(100vh - 250px), 720px), calc(100vh - var(--nav-h) - 64px)));
  height: max(240px, min(clamp(420px, calc(100svh - 250px), 720px), calc(100svh - var(--nav-h) - 64px)));
  border-radius: var(--r-media);
  background: radial-gradient(120% 90% at 50% 38%, #1A2226 0%, #111618 60%, #0C0F11 100%);
  box-shadow: inset 0 0 0 1px var(--line);
  overflow: hidden;
  touch-action: pan-y;
  user-select: none;
  -webkit-user-select: none;
}
.stage canvas { display: block; width: 100%; height: 100%; outline: none; cursor: grab; }
.stage canvas:active { cursor: grabbing; }
.stage canvas:focus-visible { box-shadow: inset 0 0 0 2px var(--focus); border-radius: var(--r-media); }

.stage-designs { position: absolute; top: 16px; left: 16px; z-index: 2; background: rgba(237, 241, 242, 0.1); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); }

.stage-status {
  position: absolute; inset: 0; display: grid; place-items: center;
  margin: 0; padding: 24px; text-align: center; font-size: 15px; color: var(--ink-3); pointer-events: none;
  transition: opacity .4s var(--ease);
}
.stage-status.is-done { opacity: 0; }

/* View controls under the stage: help on the left, buttons on the right. */
.stage-bar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px 24px; }
.stage-help { flex: 1 1 18em; max-width: 34em; margin: 0; font-size: 13px; line-height: 1.45; color: var(--ink-3); }
.tools { display: flex; flex: none; align-items: center; gap: 8px; }
.tool-group { display: inline-flex; border-radius: 980px; background: var(--seg-bg); }
.tool {
  display: grid; place-items: center; flex: none;
  width: 36px; height: 36px; padding: 0; border: 0; border-radius: 50%;
  background: var(--seg-bg); color: var(--ink-2); cursor: pointer;
  transition: background-color .2s var(--ease-out), color .2s var(--ease-out), transform .12s var(--ease-out);
  -webkit-tap-highlight-color: transparent;
}
.tool-group .tool { background: transparent; }
.tool:hover { color: var(--ink); background: rgba(237, 241, 242, 0.14); }
.tool:active { transform: scale(0.94); }
.tool:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.tool svg { width: 16px; height: 16px; fill: currentColor; }
.tool .i-line, .tool .i-back { fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.tool .i-back { opacity: 0.45; }
.tool .i-orbit { width: 18px; height: 18px; overflow: visible; }
.tool .i-flip { transform: scaleX(-1); }
.tool .i-pause { display: none; }
.tool[aria-pressed="true"] .i-play { display: none; }
.tool[aria-pressed="true"] .i-pause { display: inline; }

/* Strand details sit in a fixed corner of the stage rather than following the pointer. */
.tip {
  position: absolute; z-index: 3; left: 16px; bottom: 16px;
  min-width: 150px; max-width: calc(100% - 32px); padding: 10px 12px; border-radius: 12px;
  background: rgba(23, 28, 31, 0.92); box-shadow: 0 0 0 1px var(--line-strong), 0 8px 24px rgba(0, 0, 0, 0.35);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  font-size: 13px; line-height: 1.4; color: var(--ink-2); pointer-events: none;
}
.tip b { display: block; font-weight: 600; color: var(--ink); font-size: 14px; }
.tip code { display: block; margin-top: 4px; font-family: var(--mono); font-size: 11px; color: var(--ink-3); word-break: break-all; }

.tip[hidden] { display: none; }

/* ---------- Panel ---------- */
.panel { display: grid; gap: 24px; }
.seg-full { display: grid; width: 100%; }
.seg-full label { padding: 0 8px; }
.seg-sm label { min-height: 32px; padding: 0 14px; font-size: 14px; }

/* What the selected design is, in plain words; stays while the views change under it. */
.about { display: grid; gap: 6px; }
.about-title { margin: 0; font-size: 19px; font-weight: 600; line-height: 1.25; letter-spacing: -0.018em; color: var(--ink); }
.about-text { font-size: 15px; line-height: 1.47; color: var(--ink-2); letter-spacing: -0.009em; }

.pane { display: grid; gap: 20px; }
.pane[hidden] { display: none; }
.pane-lede { font-size: 14px; line-height: 1.47; color: var(--ink-3); }

.field { display: grid; gap: 8px; justify-items: start; }
.style-grid { display: grid; gap: 18px; }
.field-label { font-size: 13px; font-weight: 500; color: var(--ink-3); }

/* Key: what each mark in the drawing is. Rows follow the drawing and color choices. */
.key { display: grid; gap: 9px; margin: 0; padding: 0; list-style: none; font-size: 13px; line-height: 1.4; color: var(--ink-2); }
.key li { display: grid; grid-template-columns: 22px minmax(0, 1fr); gap: 0 10px; align-items: start; }
.key b { margin-right: 3px; font-weight: 600; color: var(--ink); }
.key[data-rep="helix"] [data-show="nuc"], .key[data-rep="nuc"] [data-show="helix"],
.key[data-color="strand"] [data-show="tm"], .key[data-color="tm"] [data-show="strand"],
.key:not(.is-machine) [data-show="rx"] { display: none; }
.sw { display: block; width: 12px; height: 12px; margin: 3px 5px 0; border-radius: 50%; }
.sw-tube { width: 22px; height: 10px; margin: 3px 0 0; border-radius: 5px; background: linear-gradient(180deg, #D6E3E8, #9FB2BA 55%, #6C7E86); }
.sw-bead { width: 22px; height: 8px; margin: 4px 0 0; border-radius: 0;
  background: radial-gradient(circle, #B4C2C8 3px, transparent 3.5px) 0 50% / 7.33px 8px repeat-x; }
.sw-scaf { background: #8C999F; }
.sw-mix { background: conic-gradient(#23A89B 0 25%, #7CC3F0 0 50%, #F4A6CC 0 75%, #E0A954 0); }
.is-machine .sw-mix { background: conic-gradient(#A5D2CA 0 25%, #AFCFE6 0 50%, #E3C9DF 0 75%, #DCD3C0 0); }
.sw-ramp { width: 22px; height: 8px; margin: 4px 0 0; border-radius: 4px; background: linear-gradient(90deg, #E0A954, #D98FA8 35%, #7CC3F0 65%, #23A89B); }
.sw-rx { background: conic-gradient(#FFB547 0 33.3%, #FF6F8E 0 66.6%, #9C8CFF 0); }

/* Reactants (machines) */
.rx { display: grid; gap: 14px; padding-top: 22px; border-top: 1px solid var(--line); }
.rx[hidden] { display: none; }
/* Room for the reactants of the default design before its data arrives. */
.rx.is-pending { min-height: 311px; }
.rx-title { margin: 0; font-size: 13px; font-weight: 500; letter-spacing: 0; color: var(--ink-3); }
.rx-list { display: flex; flex-wrap: wrap; gap: 8px 20px; margin: 0; padding: 0; list-style: none; font-size: 14px; color: var(--ink-2); }
.rx-list li { display: inline-flex; align-items: center; gap: 7px; }
.rx-list b, .rx-label b { font-weight: 600; color: var(--ink); }
.rx i { display: inline-block; flex: none; width: 10px; height: 10px; border-radius: 50%; }
.rx-pairs { display: grid; gap: 14px; margin: 0; }
.rx-pairs div { display: grid; grid-template-columns: 96px minmax(0, 1fr); gap: 0 12px; align-items: baseline; }
.rx-pairs dt { display: inline-flex; align-items: center; gap: 4px; font-size: 14px; color: var(--ink-2); }
.rx-pairs dt i:nth-child(2) { margin: 0 4px 0 -7px; box-shadow: 0 0 0 2px var(--bg); }
.rx-pairs dd { margin: 0; font-size: 15px; font-weight: 500; letter-spacing: -0.01em; color: var(--ink); font-variant-numeric: tabular-nums; }
.rx-pairs dd small { display: block; margin-top: 3px; font-size: 12px; font-weight: 400; line-height: 1.4; letter-spacing: 0; color: var(--ink-3); }

.stage-labels { position: absolute; inset: 0; z-index: 1; overflow: hidden; pointer-events: none; }
.rx-label {
  position: absolute; left: 0; top: 0;
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 10px 5px 8px; border-radius: 980px;
  background: rgba(17, 22, 24, 0.74); box-shadow: 0 0 0 1px rgba(237, 241, 242, 0.14);
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  font-size: 12px; line-height: 1; color: var(--ink-2); white-space: nowrap;
  opacity: 0; transition: opacity .25s var(--ease); will-change: transform;
}
.rx-label i { display: inline-block; width: 8px; height: 8px; border-radius: 50%; }
.rx-dist { padding: 5px 9px; background: rgba(247, 247, 245, 0.92); box-shadow: none; color: #111618; font-weight: 600; font-variant-numeric: tabular-nums; }

.transport { display: flex; align-items: center; gap: 14px; }
.play {
  flex: none; display: grid; place-items: center;
  width: 44px; height: 44px; border: 0; border-radius: 50%;
  background: var(--btn-bg); color: var(--btn-fg); cursor: pointer;
  transition: background-color .2s var(--ease-out), transform .12s var(--ease-out);
  -webkit-tap-highlight-color: transparent;
}
.play:hover { background: var(--btn-hover); }
.play:active { transform: scale(0.95); }
.play:focus-visible { outline: 2px solid var(--focus); outline-offset: 3px; }
.play svg { width: 16px; height: 16px; fill: currentColor; }
.play .i-pause { display: none; }
.play[aria-pressed="true"] .i-play { display: none; }
.play[aria-pressed="true"] .i-pause { display: inline; }
.readout { display: grid; gap: 2px; font-size: 13px; color: var(--ink-3); }
.readout b { font-size: 22px; line-height: 1.15; font-weight: 500; letter-spacing: -0.02em; color: var(--ink); font-variant-numeric: tabular-nums; }
.readout span { font-variant-numeric: tabular-nums; }

.curve { position: relative; margin: 0; }
.curve svg { display: block; width: 100%; height: 96px; overflow: visible; }
.curve .c-area { fill: color-mix(in srgb, var(--data-teal) 22%, transparent); }
.curve .c-line { fill: none; stroke: var(--data-teal); stroke-width: 1.75; vector-effect: non-scaling-stroke; stroke-linejoin: round; }
.curve .c-grid { stroke: var(--line); stroke-width: 1; vector-effect: non-scaling-stroke; }
.curve .c-cursor { stroke: var(--ink); stroke-width: 1.25; vector-effect: non-scaling-stroke; }
/* The curve rises from none to all staples in place; its label sits in the empty top left. */
.curve-y { display: block; height: 16px; margin: 0 0 8px; font-size: 12px; line-height: 16px; color: var(--ink-3); }
.curve-axis { display: flex; justify-content: space-between; gap: 8px; margin-top: 8px; font-size: 12px; color: var(--ink-3); font-variant-numeric: tabular-nums; }

/* The range sits over the chart so the whole chart is the scrubber. */
.curve input[type="range"] {
  position: absolute; left: 0; right: 0; top: 24px; height: 96px; width: 100%;
  margin: 0; background: transparent; cursor: ew-resize;
  -webkit-appearance: none; appearance: none;
}
.curve input[type="range"]::-webkit-slider-runnable-track { height: 96px; background: transparent; }
.curve input[type="range"]::-moz-range-track { height: 96px; background: transparent; }
.curve input[type="range"]::-webkit-slider-thumb { -webkit-appearance: none; width: 14px; height: 96px; background: transparent; border: 0; }
.curve input[type="range"]::-moz-range-thumb { width: 14px; height: 96px; background: transparent; border: 0; }
.curve input[type="range"]:focus-visible { outline: 2px solid var(--focus); outline-offset: 4px; border-radius: 4px; }

.facts {
  display: grid; grid-template-columns: 1fr 1fr; gap: 18px 16px;
  margin: 0; padding-top: 22px; border-top: 1px solid var(--line);
}
.facts-wide { grid-column: 1 / -1; }
.facts dt { font-size: 13px; color: var(--ink-3); }
/* Room for a value and two lines of caption before the data arrives, so nothing jumps. */
.facts dd { min-height: 62px; margin: 3px 0 0; font-size: 17px; font-weight: 500; letter-spacing: -0.015em; color: var(--ink); font-variant-numeric: tabular-nums; }
.facts dd small { display: block; margin-top: 1px; font-size: 12px; font-weight: 400; letter-spacing: 0; color: var(--ink-3); }
.caveat { margin-top: -6px; }

/* ---------- Notes ---------- */
.vw-notes { background: var(--bg); }
.notes-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 2fr); gap: 24px 48px; }
.notes-body { display: grid; gap: 16px; max-width: 40em; font-size: var(--fs-body); line-height: 1.53; color: var(--ink-2); }
.notes-links { display: grid; gap: 6px; margin: 8px 0 0; padding: 0; list-style: none; }
.notes-links .more { display: inline-flex; align-items: center; min-height: 36px; }

/* Without JavaScript nothing here would work, so only the noscript message shows.
   Without WebGL the numbers still fill in, but the view controls are hidden. */
html:not(.js) #status, html:not(.js) .stage-designs, html:not(.js) .stage-bar, html:not(.js) .panel { display: none; }
.no-gl .stage-bar, .no-gl .stage-labels, .no-gl .transport, .no-gl .curve, .no-gl .pane .field, .no-gl .style-grid { display: none; }

@media (max-width: 1068px) {
  .vw-head { grid-template-columns: 1fr; }
  .vw-grid { grid-template-columns: 1fr; }
  .panel { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 24px 40px; align-items: start; }
  .panel > .seg-full { grid-column: 1 / -1; max-width: 420px; }
  .facts { grid-row: span 2; }
}
@media (max-width: 734px) {
  .page-viewer .vw { padding-block: calc(var(--nav-h) + 24px) 48px; }
  .vw-head { grid-template-columns: 1fr; margin-bottom: 20px; }
  .stage {
    height: max(240px, min(max(340px, 56vh), calc(100vh - var(--nav-h) - 64px)));
    height: max(240px, min(max(340px, 56svh), calc(100svh - var(--nav-h) - 64px)));
    border-radius: 20px; margin-inline: calc(-1 * var(--gutter) + 8px);
  }
  .stage-designs { top: 12px; left: 12px; }
  .tip { left: 12px; bottom: 12px; }
  .stage-bar { flex-direction: column-reverse; align-items: stretch; }
  .tools { justify-content: space-between; }
  .panel { grid-template-columns: 1fr; }
  .panel > .seg-full { max-width: none; }
  .facts { grid-row: auto; }
  .notes-grid { grid-template-columns: 1fr; }
}

@media (forced-colors: active) {
  .stage { outline: 1px solid CanvasText; }
  .play { outline: 1px solid ButtonText; }
}
