/* Shared model-first layout. Model geometry and domain controls stay in page files. */
.model-page-content {
  height: calc(100svh - 80px - 104px - env(safe-area-inset-bottom));
  min-height: 0;
  overflow: auto;
}
.model-stage [hidden] { display: none !important; }
.model-stage {
  --stage-nav-right: max(24px, env(safe-area-inset-right));
  --stage-nav-width: 136px;
  --stage-nav-space: calc(var(--stage-nav-right) + var(--stage-nav-width) + 16px);
  --model-width: 33.333333vw;
  --stage-height: max(640px, calc(100svh - 96px - env(safe-area-inset-bottom)));
  --model-height: calc(var(--stage-height) * .5);
  --stage-top-space: 80px;
  position: relative;
  min-height: calc(var(--stage-height) - var(--stage-top-space));
  isolation: isolate;
}
.model-stage__core {
  position: absolute;
  top: calc(var(--stage-height) * .25 - var(--stage-top-space));
  left: 50%;
  width: var(--model-width);
  height: var(--model-height);
  transform: translateX(-50%);
}
.model-stage__title {
  position: fixed;
  left: 0;
  bottom: max(60px, env(safe-area-inset-bottom));
  z-index: 10;
  width: 100%;
  box-sizing: border-box;
  margin: 0;
  padding: 0 24px;
  text-align: center;
  overflow-wrap: anywhere;
  line-height: 1.3;
  pointer-events: none;
  font-size: clamp(19px, 1.8vw, 27px);
  font-weight: 500;
  letter-spacing: -.02em;
}
.model-stage__core > .model { width: 100%; height: 100%; aspect-ratio: auto; }
.model-stage__core > .model > svg { display: block; width: 100%; height: 100%; }
.model-stage__nav {
  position: fixed;
  top: 50%;
  right: var(--stage-nav-right);
  z-index: 9;
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: var(--stage-nav-width);
  max-height: calc(100svh - 220px - env(safe-area-inset-bottom));
  padding: 8px 0;
  overflow: auto;
  overscroll-behavior: contain;
  transform: translateY(-50%);
}
.model-stage__nav .model-stage__entry {
  position: relative;
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 10px;
  box-sizing: border-box;
  width: 100%;
  min-height: 44px;
  margin: 0;
  padding: 8px 10px;
  border: 0;
  border-radius: var(--radius-control);
  background: transparent;
  box-shadow: none;
  color: var(--muted);
  font: inherit;
  font-size: 15px;
  line-height: 1.5;
  text-align: left;
  overflow-wrap: anywhere;
  cursor: pointer;
  transition: color 180ms ease;
}
.model-stage__entry::before {
  content: "";
  flex: 0 0 5px;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--accent);
  opacity: .3;
  transition: opacity 180ms ease;
}
.model-stage__nav .model-stage__entry:hover,
.model-stage__nav .model-stage__entry[aria-expanded="true"] { color: var(--accent); background: transparent; }
.model-stage__entry:hover::before { opacity: .8; }
.model-stage__nav .model-stage__entry[aria-expanded="true"] { font-weight: 600; }
.model-stage__entry[aria-expanded="true"]::before { opacity: 1; }
.model-stage__nav .model-stage__entry:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: -2px; }
@media (min-width: 1101px) {
  .model-stage:has(> .model-stage__nav) > .model-stage__panel--right {
    --panel-right: max(24px, calc(var(--stage-nav-space) - (100vw - 100%) / 2));
    right: var(--panel-right);
    width: calc((100% - var(--model-width)) / 2 - var(--panel-right) - 24px);
  }
}
.model-stage__caption {
  position: absolute;
  bottom: 12px;
  left: 0;
  width: 100%;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 4px 14px;
  color: var(--muted);
}
.model-stage__caption h2 { font-size: 12px; font-weight: 400; }
.model-stage__caption > span { font: 11px ui-monospace, Consolas, monospace; font-variant-numeric: tabular-nums; }
.model-stage__actions {
  position: absolute;
  top: 100%;
  left: 50%;
  width: min(520px, calc(100vw - 36px));
  transform: translateX(-50%);
  text-align: center;
}
.model-stage__actions .button-row { justify-content: center; }
.model-stage__actions .simulation-status { margin: 10px 0 0; min-height: 44px; }
.model-stage__panel {
  position: absolute;
  top: 16px;
  width: calc((100% - var(--model-width)) / 2 - 132px);
  max-height: calc(var(--stage-height) - var(--stage-top-space) - 40px);
  overflow: auto;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: var(--radius-panel);
  background: var(--surface);
}
.model-stage__panel--left { left: 24px; }
.model-stage__panel--right { right: 24px; }
.model-stage__panel-heading { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 10px; }
.model-stage__close { flex: 0 0 40px; min-height: 40px; padding: 0; border: 0; background: transparent; color: var(--muted); font-size: 22px; }

/* A sheet below the model keeps small screens usable and the model unobstructed. */
@media (max-width: 1100px) {
  .model-stage { --model-width: min(520px, calc(100vw - 160px)); min-height: calc(var(--stage-height) - var(--stage-top-space) + 48px); }
  .model-stage__panel {
    position: relative;
    top: auto;
    left: auto;
    right: auto;
    width: min(680px, calc(100% - 36px));
    max-height: none;
    margin: 0 auto;
    overflow: visible;
    scrollbar-gutter: auto;
  }
  .model-stage:has(.model-stage__panel:not([hidden])) { padding-top: calc(var(--stage-height) - var(--stage-top-space) + 48px); padding-bottom: 24px; }
}
@media (max-width: 720px) {
  .model-page-content { height: calc(100svh - 73px - 120px - env(safe-area-inset-bottom)); }
  .model-stage { --stage-top-space: 73px; }
  .model-stage__title { font-size: 18px; }
}

/* Simulation controls follow the home page's borderless shuffle icon. */
.model-stage__actions .experiment-control {
  display: grid;
  place-items: center;
  flex: 0 0 44px;
  width: 44px;
  height: 44px;
  padding: 10px;
  border: 0;
  background: transparent;
  color: var(--muted);
  box-shadow: none;
  transition: color 180ms ease;
}
.experiment-control svg {
  width: 24px;
  height: 24px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-linejoin: round;
  transition: transform 180ms ease;
}
.model-stage__actions .experiment-control:hover:not(:disabled) { color: var(--ink); }
.experiment-control:hover:not(:disabled) svg { transform: scale(1.1); }
.experiment-control:active:not(:disabled) svg { transform: scale(.94); }
.experiment-control:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 2px; border-radius: var(--radius-control); }
.experiment-control[aria-pressed="false"] .experiment-control__pause,
.experiment-control[aria-pressed="true"] .experiment-control__play { display: none; }
@media (prefers-reduced-motion: reduce) {
  .model-stage__actions .experiment-control, .experiment-control svg { transition: none; }
  .experiment-control:hover:not(:disabled) svg, .experiment-control:active:not(:disabled) svg { transform: none; }
}

/* Reserve the right rail on compact screens, including while panels scroll. */
@media (max-width: 1100px) {
  .model-stage { --stage-nav-right: max(10px, env(safe-area-inset-right)); --stage-nav-width: 112px; }
  .model-stage:has(> .model-stage__nav) > .model-stage__core {
    left: calc((100% - var(--stage-nav-space)) / 2);
    width: min(var(--model-width), calc(100% - var(--stage-nav-space)));
  }
  .model-stage:has(> .model-stage__nav) > .model-stage__panel {
    box-sizing: border-box;
    width: calc(100% - var(--stage-nav-space));
    margin-left: 0;
    margin-right: var(--stage-nav-space);
  }
  .model-stage:has(> .model-stage__nav) .model-stage__actions { width: 100%; }
  .model-stage__nav .model-stage__entry { padding-inline: 6px; gap: 6px; }
}
@media (prefers-reduced-motion: reduce) {
  .model-stage__nav .model-stage__entry, .model-stage__entry::before { transition: none; }
}
