/* Keep chapter text and artwork together; use ordinary chapters when pinning cannot fit. */
.story-layout {
  --story-visual-space: 660px;
  grid-template-columns: minmax(0, .95fr) minmax(0, 1.15fr);
  gap: clamp(28px, 4vw, 64px);
  padding-block: 104px 94px;
}
.story-copy {
  display: grid;
  grid-template-rows: minmax(0, 1fr);
  height: auto;
  flex: none;
}
.story-panel {
  position: relative;
  inset: auto;
  grid-area: 1 / 1;
  align-self: center;
  padding-top: 0;
}
.story-panel h1, .story-panel h2 {
  font-size: clamp(38px, 4.2vw, 60px);
  margin-block: 21px 18px;
}
.story-panel p { line-height: 1.7; }
.story-actions { margin-top: 25px; }
.story-visual-frame {
  --scene-aspect: 4 / 3;
  flex: none;
  width: min(100%, calc(var(--story-visual-space) * var(--scene-aspect)));
  aspect-ratio: var(--scene-aspect);
  max-height: none;
  justify-self: end;
}
.story-visual-frame[data-scene="0"] { --scene-aspect: 16 / 9; }
.historical-scene .visual-img { object-fit: contain; object-position: center; }
.fallback-figure img { aspect-ratio: auto; height: auto; object-fit: contain; }

@media (max-width: 960px) {
  html.js-story .story-layout {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    justify-content: flex-start;
    gap: 28px;
    padding-block: 99px 94px;
  }
  .story-copy { height: auto; }
  .story-panel { justify-content: flex-start; }
  .story-panel { align-self: start; }
  .story-panel h1, .story-panel h2 {
    font-size: clamp(32px, 6.5vw, 48px);
    margin-block: 15px 12px;
  }
  .story-panel p { font-size: 13px; line-height: 1.6; }
  .story-actions { margin-top: 16px; }
  .story-visual-frame { align-self: center; border-radius: 13px; }
}
@media (max-width: 780px) {
  html.js-story .story-layout { padding-block: 89px 77px; }
  .story-visual-frame[data-scene="1"] { --scene-aspect: 1; }
}
@media (max-width: 540px) {
  .story-panel h1, .story-panel h2 { font-size: clamp(31px, 8.4vw, 42px); }
}

/* Flow mode retains the actual scenes and interactive terminal, without a pinned viewport. */
html.js-story.flow-story .story-track { height: auto; }
html.js-story.flow-story .story-sticky {
  position: relative;
  height: auto;
  min-height: 0;
  overflow: visible;
}
html.js-story.flow-story .story-layout {
  display: grid;
  height: auto;
  align-items: center;
  row-gap: 80px;
  padding-bottom: 48px;
}
html.flow-story .story-copy, html.flow-story .story-visual-frame { display: contents; }
html.flow-story .story-panel {
  grid-column: 1;
  opacity: 1;
  pointer-events: auto;
  transform: none;
  scroll-margin-top: 100px;
}
html.flow-story .visual-layer {
  grid-column: 2;
  position: relative;
  inset: auto;
  width: 100%;
  aspect-ratio: 4 / 3;
  opacity: 1;
  transform: none;
  pointer-events: auto;
  border: 1px solid rgba(148,211,231,.28);
  border-radius: 18px;
  overflow: hidden;
  background-color: #123140;
}
html.flow-story .historical-scene { aspect-ratio: 16 / 9; }
html.flow-story [data-step="0"] { grid-row: 1; }
html.flow-story [data-step="1"] { grid-row: 2; }
html.flow-story [data-step="2"] { grid-row: 3; }
html.flow-story [data-step="3"] { grid-row: 4; }
html.js-story.flow-story .story-floor { position: relative; }
@media (max-width: 960px) {
  html.js-story.flow-story .story-layout { grid-template-columns: minmax(0, 1fr); row-gap: 28px; }
  html.flow-story .story-panel, html.flow-story .visual-layer { grid-column: 1; }
  html.flow-story .story-panel[data-step="0"] { grid-row: 1; }
  html.flow-story .visual-layer[data-step="0"] { grid-row: 2; }
  html.flow-story .story-panel[data-step="1"] { grid-row: 3; }
  html.flow-story .visual-layer[data-step="1"] { grid-row: 4; }
  html.flow-story .story-panel[data-step="2"] { grid-row: 5; }
  html.flow-story .visual-layer[data-step="2"] { grid-row: 6; }
  html.flow-story .story-panel[data-step="3"] { grid-row: 7; }
  html.flow-story .visual-layer[data-step="3"] { grid-row: 8; }
  html.flow-story .story-panel:not(:first-child) { margin-top: 36px; }
  html.flow-story .work-scene { min-height: 340px; }
  html.flow-story .terminal-filter { display: flex; }
  html.flow-story .terminal-filter button { display: block; }
  html.flow-story .terminal-task:nth-child(3) { display: flex; }
}
.terminal-task[hidden] { display: none !important; }
.terminal-shell { transform: none; left: 3%; width: 94%; top: 3%; height: 94%; }
.terminal-content { overflow: auto; }
@media (max-width: 780px) {
  .terminal-filter { display: flex; }
  .terminal-filter button:not(.terminal-filter-active) { display: block; }
  .terminal-task:nth-child(3) { display: flex; }
}
@media (min-width: 781px) and (max-width: 1020px) {
  .terminal-content { padding: 10px 14px 8px; }
  .terminal-heading { margin-bottom: 6px; }
  .terminal-tasklist { gap: 5px; }
  .terminal-task { min-height: 46px; }
  .terminal-action { padding: 8px 12px; }
}
@media (min-width: 1021px) {
  .terminal-content { padding: 14px 18px 10px; }
  .terminal-heading { margin-bottom: 12px; }
  .terminal-tasklist { gap: 6px; }
  .terminal-task { min-height: 56px; }
}
