/* 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 {
  position: relative;
  height: clamp(420px, calc(100vh - 250px), 720px);
  height: clamp(420px, calc(100svh - 250px), 720px);
  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: none;
  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-reset {
  position: absolute; top: 16px; right: 16px; z-index: 2;
  min-height: 38px; padding: 0 16px; border: 0; border-radius: 980px;
  background: rgba(237, 241, 242, 0.1); color: var(--ink);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  font: 500 14px/1 var(--font); letter-spacing: -0.01em; cursor: pointer;
  transition: background-color .2s var(--ease-out);
}
.stage-reset:hover { background: rgba(237, 241, 242, 0.16); }
.stage-reset:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

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

.tip {
  position: absolute; z-index: 3; left: 0; top: 0;
  min-width: 150px; 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 { font-family: var(--mono); font-size: 12px; color: var(--ink-2); word-break: break-all; }

/* ---------- 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; }

.pane { display: grid; gap: 20px; }
.pane[hidden] { display: none; }
.pane-lede { font-size: 15px; line-height: 1.47; color: var(--ink-2); letter-spacing: -0.009em; }

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

.vw-legend { display: flex; flex-wrap: wrap; gap: 8px 18px; font-size: 13px; color: var(--ink-2); }
.vw-legend[hidden] { display: none; }
.vw-legend span { display: inline-flex; align-items: center; gap: 8px; }
.sw { display: inline-block; width: 12px; height: 12px; border-radius: 50%; }
.sw-scaf { background: var(--scaf); }
.sw-mix { background: conic-gradient(var(--data-teal) 0 25%, var(--data-sky) 0 50%, var(--data-pink) 0 75%, var(--data-amber) 0); }
.vw-legend-ramp { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 0; }
.vw-legend-ramp[hidden] { display: none; }
.ramp { grid-column: 1 / -1; display: block; height: 8px; border-radius: 4px; background: linear-gradient(90deg, #E0A954, #D98FA8 35%, #7CC3F0 65%, #23A89B); }
.ramp-hi { justify-self: end; }
.vw-legend-ramp .small { grid-column: 1 / -1; margin-top: 4px; }

.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; }
.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: 0; 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 dt { font-size: 13px; color: var(--ink-3); }
.facts dd { 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); }

@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: 56vh; height: 56svh; min-height: 340px; border-radius: 20px; margin-inline: calc(-1 * var(--gutter) + 8px); }
  .stage-designs { top: 12px; left: 12px; }
  .stage-reset { top: auto; bottom: 12px; right: 12px; min-height: 34px; padding: 0 14px; font-size: 13px; }
  .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; }
}
