/* Editorial fragments accompany spoken narration; full captions remain optional. */
#narrative {
  left: 11%;
  top: 30%;
  width: min(25vw, 24rem);
  max-width: calc(100vw - 2rem);
}
#narrative-title {
  font-size: clamp(1.35rem, 2.2vw, 2.3rem);
  line-height: 1.14;
  max-width: 16ch;
  margin-bottom: 0.6rem;
}
#narrative-keywords {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.45rem;
  padding: 0;
  margin: 0.8rem 0 0;
  border: 0;
  font: var(--es-display-weight) clamp(1.5rem, 2.9vw, 3rem) / 1.12
    var(--es-font-display);
  text-transform: none;
  letter-spacing: -0.04em;
  color: var(--es-ink);
}
#narrative-keywords > span {
  display: block;
  max-width: 15ch;
  transform-origin: left center;
  text-wrap: balance;
  animation-duration: 7s;
  animation-timing-function: ease-in-out;
  animation-iteration-count: infinite;
  animation-direction: alternate;
  animation-play-state: paused;
}
#narrative-keywords > span:nth-child(n + 4) {
  display: none;
}
#narrative-keywords > span:nth-child(2) {
  animation-delay: -2.1s;
  color: var(--es-muted);
}
#narrative-keywords > span:nth-child(3) {
  animation-delay: -4.2s;
}
body.is-narrating:not(.is-paused) #narrative-keywords > span {
  animation-play-state: running;
}
#narrative[data-sense="smell"] #narrative-keywords > span {
  animation-name: narrative-vapor;
}
#narrative[data-sense="taste"] #narrative-keywords > span {
  animation-name: narrative-flow;
}
#narrative[data-sense="view"] #narrative-keywords > span {
  animation-name: narrative-focus;
}
#narrative[data-sense="hear"] #narrative-keywords > span {
  animation-name: narrative-wave;
}
#narrative[data-sense="touch"] #narrative-keywords > span {
  animation-name: narrative-ripple;
}
#narrative[data-sense="move"] #narrative-keywords > span {
  animation-name: narrative-progress;
}
#narrative-body {
  margin-top: 1.2rem;
  font-size: var(--es-text-small);
  line-height: 1.7;
}
#narrative-body[hidden] {
  display: none !important;
}
@keyframes narrative-vapor {
  from {
    transform: translateY(0);
    opacity: 0.72;
  }
  to {
    transform: translateY(-0.3rem);
    opacity: 1;
  }
}
@keyframes narrative-flow {
  from {
    transform: translateX(0);
  }
  to {
    transform: translateX(0.4rem);
  }
}
@keyframes narrative-focus {
  from {
    letter-spacing: -0.04em;
    opacity: 0.78;
  }
  to {
    letter-spacing: -0.025em;
    opacity: 1;
  }
}
@keyframes narrative-wave {
  from {
    transform: translateY(-0.13rem);
  }
  to {
    transform: translateY(0.13rem);
  }
}
@keyframes narrative-ripple {
  from {
    transform: scale(1);
  }
  to {
    transform: scale(1.015);
  }
}
@keyframes narrative-progress {
  from {
    transform: translateX(0);
    opacity: 0.8;
  }
  to {
    transform: translateX(0.45rem);
    opacity: 1;
  }
}
@media (max-width: 700px) {
  #narrative {
    left: 4.5%;
    right: 4.5%;
    top: auto;
    bottom: 5rem;
    width: auto;
    max-height: 16rem;
    padding: 0;
    background: transparent;
    overflow-y: auto;
  }
  body.scene-focused #scene {
    left: 0;
    right: auto;
    width: 100%;
    top: 5rem;
    bottom: 21rem;
  }
  body.scene-focused .sequence-status {
    display: none;
  }
  #narrative-title {
    font-size: clamp(1rem, 4vw, 1.4rem);
    max-width: none;
  }
  #narrative-kicker {
    font-size: var(--es-text-small);
  }
  #narrative-keywords {
    flex-direction: row;
    flex-wrap: wrap;
    font-size: clamp(1rem, 4.4vw, 1.35rem);
    gap: 0.4rem 0.85rem;
    margin-top: 0.6rem;
  }
  #narrative-body {
    font-size: var(--es-text-small);
  }
  #research-toggle {
    font-size: var(--es-text-small);
    max-width: none;
    text-align: left;
  }
}
@media (prefers-reduced-motion: reduce) {
  #narrative-keywords > span {
    animation: none;
    transform: none;
  }
}

#narrative-body {
  font-size: var(--es-text-body);
  line-height: var(--es-line-body);
}
@media (max-width: 700px) {
  #narrative {
    bottom: var(--es-bottom-clearance);
    max-height: 19rem;
  }
  body.scene-focused #scene {
    bottom: calc(var(--es-bottom-clearance) + 20rem);
  }
  #protocol .protocol-orbits {
    flex-wrap: wrap;
    justify-content: flex-start;
    gap: 0.75rem 1rem;
  }
  #protocol .protocol-orbits button {
    min-height: 2.5rem;
  }
}

/* Enlarged chapter text reflows below the anatomical view instead of clipping. */
@media (max-width: 700px) {
  body.scene-focused:not(.text-only):not(.research-open) main {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: minmax(12rem, 35svh) auto;
    align-content: start;
    min-height: 100svh;
    padding: 5rem 0 var(--es-bottom-clearance);
    overflow: visible;
  }
  body.scene-focused:not(.text-only):not(.research-open) #scene {
    min-width: 0;
    position: relative;
    grid-row: 1;
    inset: auto;
    height: 100%;
    width: 100%;
  }
  body.scene-focused:not(.text-only):not(.research-open) #narrative {
    position: relative;
    grid-row: 2;
    inset: auto;
    width: auto;
    max-height: none;
    margin: 1.5rem 5% 0;
    overflow: visible;
  }
}

/* A soft reading lane keeps focused copy legible over pale skin and bedding.
   It is part of the atmosphere, with no panel edge or pointer interception. */
@media (min-width: 701px) {
  /* The chapter already identifies its sense and protocol; overview hints are redundant here. */
  body.scene-focused .scene-caption,
  body.scene-focused .sequence-status {
    display: none;
  }
  body.scene-focused:not(.text-only) #scene {
    isolation: isolate;
  }
  body.scene-focused:not(.text-only) #scene::after {
    content: "";
    position: fixed;
    z-index: 1;
    inset: 0 auto 0 0;
    width: calc(11vw + min(25vw, 24rem) + 9rem);
    background: linear-gradient(
      90deg,
      color-mix(in srgb, var(--es-ground) var(--es-reading-tint), transparent) 0,
      color-mix(
          in srgb,
          var(--es-ground) var(--es-reading-edge-tint),
          transparent
        )
        calc(100% - 9rem),
      transparent 100%
    );
    pointer-events: none;
  }
}

/* Sense close-up: product label, one statement, three fact rows and explicit
   Overview / Next navigation, set in a right-hand reading panel. */
#narrative-kicker {
  color: var(--es-pore);
  font: 400 var(--es-text-small) / 1.4 var(--es-font-body);
  letter-spacing: 0.02em;
  text-transform: none;
}
#narrative-title {
  font-weight: 300;
  letter-spacing: -0.035em;
}
#narrative-title:focus {
  outline: none;
}
#narrative .editorial-rule {
  width: 2rem;
  margin: 1.1rem 0 1.4rem;
}
#narrative-keywords {
  display: grid;
  gap: 0.7rem;
  margin: 0;
  font: 400 var(--es-text-small) / 1.45 var(--es-font-body);
  letter-spacing: 0.01em;
  color: var(--es-ink);
}
#narrative-keywords > span,
#narrative-keywords > span:nth-child(2) {
  display: grid;
  grid-template-columns: minmax(0, 7.2rem) minmax(0, 1fr);
  column-gap: 0.9rem;
  max-width: none;
  color: var(--es-ink);
  animation: none;
}
.spec-value {
  min-width: 0;
  overflow-wrap: anywhere;
}
/* Narrow or enlarged text: each fact stacks its label above its value. */
@media (max-width: 700px) {
  #narrative-keywords > span,
  #narrative-keywords > span:nth-child(2) {
    grid-template-columns: minmax(0, 1fr);
    row-gap: 0.1rem;
  }
  .spec-label {
    justify-content: flex-start;
    gap: 0.5rem;
  }
}
.spec-label {
  display: flex;
  justify-content: space-between;
  color: var(--es-muted);
  font-family: var(--es-font-data);
  letter-spacing: 0.14em;
  text-transform: uppercase;
}
.spec-label::after {
  content: "/" / "";
  color: var(--es-line);
}
#narrative-status {
  margin: 1.3rem 0 0;
  color: var(--es-muted);
  font: 400 var(--es-text-small) / 1.5 var(--es-font-body);
  letter-spacing: 0.01em;
  text-transform: none;
}
.narrative-nav {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  margin-top: 1.4rem;
  padding-top: 0.6rem;
  border-top: 1px solid var(--es-glass-line);
}
.narrative-nav button {
  appearance: none;
  min-height: 2.75rem;
  padding: 0.4rem 0;
  border: 0;
  background: transparent;
  color: var(--es-ink);
  font: 400 var(--es-text-small) / 1.3 var(--es-font-body);
  cursor: pointer;
  pointer-events: auto;
}
.narrative-nav button:hover,
.narrative-nav button:focus-visible {
  color: var(--es-pore);
}
@media (min-width: 701px) {
  #narrative {
    left: auto;
    right: 4.5%;
    top: max(6.5rem, 18vh);
    width: min(26vw, 25rem);
    max-height: calc(100svh - max(6.5rem, 18vh) - 5rem);
    overflow-y: auto;
    overscroll-behavior: contain;
    scrollbar-width: none;
  }
  #narrative-title {
    font-size: clamp(1.8rem, 2.5vw, 2.7rem);
    line-height: 1.1;
    max-width: 14ch;
  }
  body.scene-focused:not(.text-only):not(.research-open) #scene::after {
    inset: 0 0 0 auto;
    width: calc(4.5vw + min(26vw, 25rem) + 9rem);
    background: linear-gradient(
      270deg,
      color-mix(in srgb, var(--es-ground) var(--es-reading-tint), transparent) 0,
      color-mix(
          in srgb,
          var(--es-ground) var(--es-reading-edge-tint),
          transparent
        )
        calc(100% - 9rem),
      transparent 100%
    );
  }
}
@media (min-width: 701px) {
  /* The close-up panel carries its own labels; the room status line steps out. */
  body.scene-focused .ai-indicator {
    visibility: hidden;
  }
}
@media (min-width: 701px) and (max-height: 820px) {
  #narrative {
    top: max(5.75rem, 12vh);
    max-height: calc(100svh - max(5.75rem, 12vh) - 4.5rem);
  }
  #narrative-title {
    font-size: clamp(1.5rem, 2.2vw, 2.1rem);
  }
  #narrative .editorial-rule {
    margin: 0.7rem 0 0.9rem;
  }
  #narrative-keywords {
    gap: 0.4rem;
  }
  #narrative-status {
    margin-top: 0.8rem;
  }
  #narrative .protocol {
    margin-top: 0.9rem;
  }
  .narrative-nav {
    margin-top: 0.6rem;
    padding-top: 0.2rem;
  }
}
