.late-image { isolation: isolate; overflow: hidden; background: #191e1b; }
.late-image .late-art { position: absolute; inset: 0; display: block; width: 100%; height: 100%; max-height: none; object-fit: cover; }
.late-scroll-history, .late-gallery, .late-sleep { background-color: #18201b; }
.late-scroll-history .late-art { object-fit: contain; }
.late-glimpse .late-art { object-position: var(--crop,50%) 50%; transform: scale(1.12); transform-origin: var(--crop,50%) 50%; }
.late-era-film .late-art { object-position:50% 50%; transform:none; }
@media (min-width: 701px) {
  /* The six-era film places its period names along the right edge. */
  body[data-chapter="4"] .scene-tools { right: max(var(--scene-gutter), 10vw); }
}
.late-panel .late-quote { margin: 0; color: inherit; font-family: var(--serif,serif); }
.late-help, .late-feedback { line-height: 1.65; }
.late-help:empty, .late-feedback:empty { display: none; }
.late-reference { margin: .5rem 0; font-size: .85rem; line-height: 1.6; color: #dfd6bf; }
.late-journey::after, .late-gallery::after {
  content: ""; position: absolute; inset: 0; z-index: 0; pointer-events: none;
  background: linear-gradient(0deg, #111713b8, #151b1740 70%);
}
.late-journey .late-art { object-position: center 38%; }
.late-gallery .late-art { object-position: center 65%; }

.late-era-deck {
  position: absolute; z-index: 2; left: max(7%, 20px); right: max(7%, 20px);
  bottom: calc(var(--late-panel-height, 210px) + clamp(24px, 6vh, 68px));
  display: grid; grid-template-columns: repeat(6, minmax(0, 1fr));
  column-gap: clamp(5px, 3vw, 50px); row-gap: 22px;
}
.late-era-card {
  position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 9px; padding: 10px 5px 20px; min-height: 96px; border: 0;
  background: transparent; color: #f4e7c8; cursor: grab;
  font: 400 clamp(1.3rem, 2.8vw, 2.5rem)/1.35 "KaiTi", "STKaiti", var(--serif, serif);
  text-shadow: 0 2px 18px #060a06, 0 1px 3px #060a06;
  transition: color .2s ease, transform .2s ease;
}
.late-era-card::after {
  content: ""; position: absolute; bottom: 3px; left: 35%; right: 35%; height: 1px;
  background: #e0bd7e; opacity: .3; transition: opacity .2s ease, transform .2s ease;
}
.late-number { font: 400 .75rem/1.4 Georgia,serif; letter-spacing: .1em; color: #c9bda1; }
.late-era-card:hover, .late-era-card[aria-pressed="true"] { color: #fff8e8; transform: translateY(-5px); }
.late-era-card[aria-pressed="true"]::after { opacity: 1; transform: scaleX(1.5); }
.late-history-panel .late-era-card.is-reversed { animation: era-reversed .5s ease-out both; }
@keyframes era-reversed {
  0%,72% { background-color: #ecbc6f32; box-shadow: inset 0 -2px #fdce86; }
  to { background-color: transparent; box-shadow: none; }
}
.late-era-reference[data-hint] .late-history-ref-order { color: #ffe1a4; }
.late-era-reference[data-hint="3"] { border-color: #d9ab645e; }
.late-era-reference, .late-era-inscription { grid-column: 1 / -1; text-align: center; margin: 0; text-shadow: 0 2px 8px #111; }
.late-era-reference { color: #e3d5b7; font-size: .84rem; letter-spacing: .1em; }
.late-era-inscription { color: #f1e0ba; font: 400 clamp(1rem, 2.2vw, 1.8rem)/1.9 var(--serif,serif); }

.sleep-canvas { position: absolute; left: 50%; top: 50%; width: min(100%, 177.777778dvh); transform: translate(-50%,-50%); aspect-ratio: 16 / 9; }
.sleep-layer, .sleep-lights { position: absolute; inset: 0; width: 100%; height: 100%; }
.sleep-layer { display: block; pointer-events: none; }
.sleep-reflection-layer { mix-blend-mode: plus-lighter; }
.sleep-entry-plate { z-index: 4; }
.sleep-lights { z-index: 2; }
.sleep-light { position: absolute; transform: translate(-50%,-50%); min-width: 44px; min-height: 44px; padding: 36px 3px 0; border: 0; background: transparent; color: #eee0c2; font: .85rem/1.4 var(--serif,serif); white-space: nowrap; text-shadow: 0 1px 5px #000; }
.sleep-light.is-found { color: #ffe4ae; }
.sleep-light:first-child { transform: translate(-25%,-50%); }
.sleep-light.is-found::after { content: "·"; padding-left: 3px; }
.sleep-edge { position: absolute; z-index: 3; left: 58.49%; top: 61.3%; width: 31.04%; height: 8.24%; min-height: 30px; border: 0; background: transparent; }
.sleep-edge::after { content: ""; position: absolute; inset: 0; background: #efd8a233; mask: var(--sleep-edge-mask, url("sleep-assets-v2/edge-highlight.png")) center / 100% 100% no-repeat; mask-mode: luminance; opacity: 0; pointer-events: none; }
.sleep-edge:hover::after, .sleep-edge:focus-visible::after { opacity: 1; }
#mediaStage[data-clip="V14"] .scene-visual > video,
#mediaStage[data-clip="V14"] .scene-visual > img { object-fit: contain; }
@media (max-width: 580px) { .sleep-light { font-size: .72rem; } }
.late-box {
  position: absolute; left: 8%; top: 24%; width: 52%; height: 33%;
  transform: perspective(900px) rotateY(12deg) skewY(-3deg);
  background: linear-gradient(110deg,#1e2727b0,#1a1d1de0),url("late-assets/box-grain.webp") center / cover;
  box-shadow: 4px 24px 34px #030a0a85, inset 2px 2px 3px #a89d7830;
}
.late-box::before { content: ""; position: absolute; top: 27%; left: 0; right: 0; height: 2px; background: linear-gradient(90deg,#443b2e,#bd965b,#604f3a); }
.late-silk {
  position: absolute; right: 7%; top: 41%; width: 31%; height: 16%;
  transform: skew(-18deg,-5deg); background: linear-gradient(100deg,#383e37,#9b8f70 28%,#605e4e);
  border-radius: 3% 3% 16% 8%; box-shadow: 0 7px 12px #10161585;
}
.late-sleep::after { display: none; }
.late-sleep.is-awake { --memory-warmth: 1; }
.late-lights { position: absolute; top: 90px; left: 0; right: 0; bottom: calc(var(--late-panel-height, 200px) + 15px); z-index: 2; }
.late-light {
  position: absolute; padding: 12px; min-height: 46px; color: #e4d3b0;
  display: flex; align-items: center; gap: 12px; font: inherit; font-size: .9rem;
  border: 0; background: transparent; text-shadow: 0 2px 9px #000;
}
.late-light::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: #e1b570; box-shadow: 0 0 18px 5px #f0cb7b60; flex-shrink: 0; }
.late-light:hover, .late-light.is-found { color: #fff0d0; }
.late-light.is-found::before { background: #fff3d1; box-shadow: 0 0 22px 8px #f0cb7b65; }
.light-ink { left: 14%; top: 61%; }
.light-city { left: 43%; top: 26%; }
.light-unroll { left: 72%; top: 59%; }
.late-progress { margin-top: 10px; display: flex; align-items: center; justify-content: center; gap: 12px; color: #e7cf9f; font-variant-numeric: tabular-nums; font-size: .82rem; }
.late-progress progress { width: min(220px,66%); height: 3px; appearance: none; border: 0; accent-color: #ddbc83; background: #ffffff20; }
.late-progress progress::-webkit-progress-bar { background: #ffffff20; }
.late-progress progress::-webkit-progress-value { background: #ddbc83; }
.late-progress progress::-moz-progress-bar { background: #ddbc83; }
.late-hold { user-select: none; touch-action: none; }

.late-memory-workspace {
  position: absolute; z-index: 2; left: max(7%,20px); right: max(7%,20px);
  bottom: calc(var(--late-panel-height,180px) + 18px); top: max(140px,24%);
  display: flex; flex-direction: column; justify-content: center; gap: clamp(24px,5vh,60px);
}
.late-slots { display: grid; grid-template-columns: repeat(6,minmax(0,1fr)); gap: 12px; }
.late-slot {
  position: relative; min-height: 64px; padding: 12px 6px; color: #e4d5b7; border: 0;
  background: transparent; text-shadow: 0 2px 12px #090b08, 0 1px 3px #090b08;
  font: 400 clamp(1.18rem,2.2vw,1.9rem)/1.4 "KaiTi","STKaiti",var(--serif,serif);
}
.late-slot::after { content: ""; position: absolute; left: 39%; right: 39%; bottom: 2px; height: 1px; background: #e6cd9b66; }
.late-slot:hover, .late-slot.is-placed { color: #fff4d8; }
.late-slot.is-placed::after { height: 2px; background: #ecd097; box-shadow: 0 0 12px #f0cd8550; }
.late-tray { display: grid; grid-template-columns: repeat(6,minmax(0,1fr)); align-items: start; gap: clamp(8px,2vw,30px); }
.late-piece {
  position: relative; display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 5px;
  border: 0; background: transparent; color: #f3e5cb; text-shadow: 0 2px 9px #000;
  font: 400 .93rem/1.5 var(--sans,sans-serif); cursor: grab; min-height: 44px;
  transition: transform .2s ease,color .2s ease;
}
.late-piece img { width: 100%; max-width: 112px; height: clamp(48px,6vw,74px); object-fit: cover; opacity: .83; box-shadow: 0 9px 22px #080c0990; }
.late-piece:hover, .late-piece[aria-pressed="true"] { color: #fff9e8; transform: translateY(-5px); }
.late-piece[aria-pressed="true"] img { opacity: 1; box-shadow: 0 5px 28px #edc47745; }
.late-gallery::after { display: none; }
.gallery-registered {
  position: absolute;
  left: 50%; top: 50%;
  width: min(100%, 177.777778dvh);
  aspect-ratio: 16 / 9;
  transform: translate(-50%, -50%);
}
.late-gallery .gallery-registered .late-art { object-fit: fill; }
.gallery-memory-strip {
  position: absolute;
  inset: 45.55% 17.4% 49.26% 18.44%;
  display: grid;
  grid-template-columns: repeat(6,minmax(0,1fr));
  pointer-events: none;
  mask-image: linear-gradient(transparent,#000 12%,#000 88%,transparent);
  clip-path: polygon(1.3% 0,98.4% 50%,100% 100%,0 47%);
}
.gallery-memory-region {
  background: #27211b35;
  backdrop-filter: blur(2.5px) saturate(.6);
  mask-image: linear-gradient(90deg,transparent,#000 9%,#000 91%,transparent);
  transition: opacity .4s ease-out;
}
.gallery-memory-region.is-clear { opacity: 0; }
.gallery-memory-region.just-cleared { animation: gallery-restore .4s ease-out both; }
@keyframes gallery-restore { from { opacity:1; } to { opacity:0; } }
.gallery-light {
  position: absolute; inset: 0; pointer-events: none;
  background: radial-gradient(ellipse at 39% 37%, #ffe2a912, transparent 65%);
  animation: gallery-light 10s ease-in-out infinite alternate;
}
@keyframes gallery-light { from { opacity: 0; } to { opacity: .8; } }
body:has(#motionToggle[aria-pressed="false"]) .gallery-light { animation-play-state: paused; }
.late-actions .final-answer-pressed { background: #d3ad6626; color: #fff3ce; }
@media (prefers-reduced-motion: reduce) {
  .gallery-light { animation: none; opacity: 0; }
  .gallery-memory-region { animation: none!important; transition: none; }
}
.late-image button:focus-visible, .late-panel button:focus-visible { outline: 2px solid #e7c282; outline-offset: 3px; }

@media (max-width: 580px) {
  .late-era-deck { grid-template-columns: repeat(3,minmax(0,1fr)); bottom: calc(var(--late-panel-height, 220px) + 24px); row-gap: 14px; }
  .late-era-card { min-height: 70px; padding-bottom: 12px; gap: 4px; font-size: 1.65rem; }
  .late-era-reference { font-size: .72rem; letter-spacing: 0; }
  .late-memory-workspace { top: 135px; left: 6%; right: 6%; gap: 25px; }
  .late-slots, .late-tray { grid-template-columns: repeat(3,minmax(0,1fr)); column-gap: 10px; row-gap: 12px; }
  .late-slot { min-height: 44px; padding: 4px; font-size: 1.4rem; }
  .late-piece { gap: 5px; font-size: .78rem; }
  .late-piece img { max-width: 86px; height: 44px; }
  .late-lights { top: 125px; }
  .late-light { flex-direction: column; gap: 10px; font-size: .85rem; padding: 10px; }
  .light-ink { left: 8%; top: 57%; }
  .light-city { left: 40%; top: 22%; }
  .light-unroll { left: 70%; top: 54%; }
  .late-box { left: 3%; width: 66%; top: 31%; height: 24%; }
  .late-silk { right: 3%; top: 48%; width: 34%; height: 10%; }
}
@media (max-height: 540px) and (min-width: 581px) {
  .late-era-deck { left: 6%; right: 6%; bottom: calc(var(--late-panel-height,130px) + 6px); row-gap: 4px; }
  .late-era-card { min-height: 54px; gap: 0; padding: 0 4px 6px; font-size: 1.55rem; }
  .late-era-reference { font-size: .72rem; }
  .late-memory-workspace { top: 68px; gap: 8px; bottom: calc(var(--late-panel-height,125px) + 5px); }
  .late-slot { min-height: 32px; padding: 1px; font-size: 1.22rem; }
  .late-piece { padding: 0 3px; gap: 3px; font-size: .75rem; }
  .late-piece img { height: 36px; max-width: 74px; }
  .late-light { font-size: .8rem; }
  .late-lights { top: 65px; }
}
@media (max-width: 580px) and (min-height: 700px) and (max-aspect-ratio: 3/4) {
  .late-gallery .late-memory-workspace {
    top: max(120px, calc(50% - 28.125vw - 130px));
    bottom: max(calc(var(--late-panel-height, 150px) + 8px), calc(50% - 28.125vw - 162px));
    justify-content: space-between;
  }
  .late-gallery .late-tray { row-gap: 6px; }
  .late-gallery .late-piece { gap: 5px; }
  .late-gallery .late-piece img { height: 40px; }
}
@media (max-width: 580px) and (max-height: 680px) {
  .late-era-deck { bottom: calc(var(--late-panel-height,200px) + 20px); row-gap: 10px; }
  .late-era-card { min-height: 62px; font-size: 1.2rem; white-space: nowrap; gap: 2px; padding: 4px 2px 10px; }
  .late-memory-workspace { top: 132px; gap: 14px; justify-content: flex-start; overflow-y: auto; overscroll-behavior: contain; scrollbar-width: thin; }
  .late-slots, .late-tray { row-gap: 8px; }
  .late-slot { min-height: 40px; font-size: 1.25rem; }
  .late-piece { gap: 3px; padding: 3px; font-size: .75rem; }
  .late-piece img { height: 34px; max-width: 74px; }
}
@media (prefers-reduced-motion: reduce) {
  .late-era-card, .late-piece { transition: none; }
}
@media (forced-colors: active) {
  .late-era-card[aria-pressed="true"], .late-piece[aria-pressed="true"] { outline: 3px solid Highlight; }
  .late-light::before { border: 2px solid ButtonText; }
}

/* Chapter four is one quiet interaction band below the scene, rather than
   floating labels in the painting. Controls stay out of visual snapshots. */
.late-history-panel {
  isolation:isolate;max-height:none;overflow:visible;
  padding:24px var(--scene-gutter) max(24px,env(safe-area-inset-bottom));
  background:none;
}
.late-history-panel::before {
  content:"";position:absolute;inset:0;z-index:-1;pointer-events:none;
  background:linear-gradient(0deg,#0b100ef5,#0b100ee8 66%,#0b100e9c 88%,transparent);
  opacity:0;transition:opacity .72s ease;
}
.late-history-panel .late-quote {
  font:400 clamp(18px,1.7vw,24px)/1.45 var(--serif);margin:0 0 4px;
}
.late-history-panel .late-help {
  min-height:1.7em;margin:0;color:var(--muted);
  font:400 clamp(12px,1vw,14px)/1.65 var(--sans);
}
.late-history-panel .late-era-deck {
  position:relative;inset:auto;z-index:auto;width:100%;
  display:grid;grid-template-columns:repeat(6,minmax(0,1fr));gap:10px;
  margin:12px 0 0;padding-top:8px;border-top:1px solid #d8bd8733;
}
.late-history-panel .late-era-card {
  min-width:0;min-height:60px;padding:6px 4px 10px;gap:3px;
  font:400 clamp(17px,1.7vw,23px)/1.3 var(--serif);letter-spacing:0;
  color:var(--ink);text-shadow:0 1px 5px #0008;
}
.late-history-panel .late-era-name { display:block;white-space:nowrap; }
.late-history-panel .late-number { font-size:11px;line-height:1.25;letter-spacing:.08em;color:var(--muted); }
.late-history-panel .late-era-card::after { left:32%;right:32%;bottom:1px;opacity:.22; }
.late-history-panel .late-era-card:hover,.late-history-panel .late-era-card[aria-pressed="true"] { transform:translateY(-2px);color:#f7dba4; }
.late-history-panel .late-era-settled { cursor:default; }
.late-history-panel .late-era-settled:hover { transform:none;color:var(--ink); }
.late-history-panel .late-history-footer { display:flex;align-items:center;justify-content:space-between;flex-wrap:wrap;gap:6px 20px;margin-top:8px; }
.late-history-panel .late-era-reference { display:flex;align-items:center;flex-wrap:wrap;gap:2px 10px;margin:0;text-align:left;letter-spacing:0;color:var(--muted);font:400 11px/1.65 var(--sans); }
.late-history-ref-label,.late-history-ref-order { white-space:nowrap; }
.late-history-panel .late-actions { margin:0;gap:4px 18px; }
.late-history-panel .late-actions > button { min-height:44px;font-size:14px;white-space:nowrap; }
.late-history-panel > .late-quote,.late-history-panel > .late-help,
.late-history-panel > .late-era-deck,.late-history-panel > .late-history-footer,.late-history-panel > .late-feedback {
  opacity:0;transform:translateY(4px);transition:opacity .72s ease,transform .72s ease;
}
.late-history-panel.is-ready::before { opacity:1; }
.late-history-panel.is-ready > .late-quote,.late-history-panel.is-ready > .late-help,
.late-history-panel.is-ready > .late-era-deck,.late-history-panel.is-ready > .late-history-footer,.late-history-panel.is-ready > .late-feedback { opacity:1;transform:none; }
.late-history-panel.is-ready > .late-era-deck { transition-delay:.12s; }
.late-history-panel.is-ready > .late-history-footer { transition-delay:.2s; }
body[data-chapter="4"] .experience-heading { opacity:0;transition:opacity .72s ease; }
body[data-chapter="4"][data-fourth-ui="ready"] .experience-heading { opacity:1; }
body.is-media[data-chapter="4"] .experience-heading { opacity:0; }
.scroll-journey-panel .scroll-journey-caption,#mediaStage[data-clip="V09"] .scroll-journey-caption {
  font:400 clamp(14px,1.3vw,18px)/1.8 var(--serif);
  opacity:0;transform:translateY(3px);transition:opacity .6s ease,transform .6s ease;
}
.scroll-journey-panel .scroll-journey-caption.is-visible,#mediaStage[data-clip="V09"] .scroll-journey-caption.is-visible { opacity:1;transform:none; }
body.journey-finishing[data-chapter="3"] .experience-heading { opacity:0;transition:opacity .55s ease; }
@media(max-width:580px) {
  .late-history-panel { padding-top:22px;padding-bottom:max(20px,env(safe-area-inset-bottom)); }
  .late-history-panel .late-quote { font-size:20px; }
  .late-history-panel .late-help { min-height:3.1em;font-size:12px; }
  .late-history-panel .late-era-deck { grid-template-columns:repeat(3,minmax(0,1fr));gap:6px 8px;margin-top:8px; }
  .late-history-panel .late-era-card { min-height:56px;padding:5px 3px 8px;font-size:19px; }
  .late-history-panel .late-history-footer { flex-direction:column;align-items:flex-start;gap:4px 16px;margin-top:6px; }
  .late-history-panel .late-actions > button { font-size:13px; }
}
@media(max-height:540px) and (min-width:581px) {
  .late-history-panel { padding-top:15px;padding-bottom:12px; }
  .late-history-panel .late-quote { font-size:18px; }
  .late-history-panel .late-help { min-height:1.7em;font-size:11px; }
  .late-history-panel .late-era-deck { margin-top:6px;padding-top:4px;gap:8px; }
  .late-history-panel .late-era-card { min-height:48px;padding:3px 2px 7px;font-size:18px; }
  .late-history-panel .late-number { font-size:11px; }
  .late-history-panel .late-history-footer { margin-top:4px; }
  .late-history-panel .late-era-reference { font-size:10px; }
  .late-history-panel .late-actions > button { font-size:13px; }
}
@media(max-width:350px) {
  .late-history-panel { padding-left:20px;padding-right:20px; }
  .late-history-panel .late-era-card { font-size:18px; }
}
@media(prefers-reduced-motion:reduce) {
  .late-history-panel::before,.late-history-panel > .late-quote,.late-history-panel > .late-help,
  .late-history-panel > .late-era-deck,.late-history-panel > .late-history-footer,.late-history-panel > .late-feedback,
  .late-history-panel.is-ready > .late-era-deck,.late-history-panel.is-ready > .late-history-footer,body[data-chapter="4"] .experience-heading,
  .scroll-journey-panel .scroll-journey-caption,#mediaStage[data-clip="V09"] .scroll-journey-caption,
  body.journey-finishing[data-chapter="3"] .experience-heading { transition:none;transition-delay:0s;transform:none; }
}
