/* Viewport-first layout: preserve the complete illustration and allocate it all remaining space. */
html, body {
  display: block;
  min-height: 100%;
}

#guideView:not(.hidden) {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  min-height: 0;
}

#guideView .cpr-header {
  position: relative;
  flex: none;
  box-sizing: border-box;
  height: calc(42px + env(safe-area-inset-top, 0px));
  padding: calc(4px + env(safe-area-inset-top, 0px)) 16px 4px;
}
.cpr-header .logo { height: 34px; }

#guideView .container {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 8px;
  width: 100%;
  max-width: 1120px;
  margin: 0 auto !important;
  padding: 10px max(12px, env(safe-area-inset-right, 0px)) 10px max(12px, env(safe-area-inset-left, 0px)) !important;
}

#guideView #step-title {
  margin: 0 !important;
  font-size: clamp(18px, 2.6vmin, 24px);
  line-height: 1.15;
}

#guideView .step.active {
  display: grid;
  grid-template-rows: minmax(0, 1fr);
  min-height: 0;
  min-width: 0;
  gap: 8px;
}
#guideView #step3.active { grid-template-rows: minmax(0, 1fr) auto; }

#guideView .step-content {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  grid-template-columns: minmax(0, 1fr);
  gap: 8px;
  min-height: 0;
  min-width: 0;
  margin: 0;
  align-items: stretch;
  overflow: visible;
}

#guideView .step-text {
  display: grid;
  align-content: start;
  gap: 4px;
  min-width: 0;
  overflow: visible;
}
#guideView .step p:not(.timeline-text):not(.time-remaining) {
  font-size: clamp(14px, 1.9vmin, 17px);
  line-height: 1.3;
  margin: 0;
  overflow-wrap: anywhere;
}

/* Grow copy into measured whitespace; never let it consume the illustration's
   layout space. Without JS, the previously approved compact layout still works. */
.adaptive-title-text { display: block; }
#guideView.adaptive-copy #step-title {
  height: var(--copy-title-slot);
  min-height: 0;
  font-size: var(--copy-title-size);
}
#guideView.adaptive-copy .step.active .step-text {
  height: var(--copy-body-slot);
  min-height: 0;
  grid-auto-rows: max-content;
  transform: translateY(var(--copy-body-offset));
}
#guideView.adaptive-copy .step.active .step-text p {
  font-size: var(--copy-body-size);
}

#guideView .step-media {
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
  width: 100%;
  gap: 6px;
  margin: 0;
  overflow: visible;
}
.illustration-fit {
  flex: 1;
  min-height: 0;
  min-width: 0;
  display: grid;
  place-items: center;
  container-type: size;
}

.illustration-stage {
  display: grid;
  position: relative;
  isolation: isolate;
  width: min(100cqw, 100cqh);
  aspect-ratio: 1;
  margin: 0 auto;
  overflow: hidden;
  border-radius: 18px;
  background: #eeeae5;
  box-shadow: 0 5px 24px #3630250a;
}

.step .illustration-stage > img {
  position: absolute;
  inset: 0;
  grid-area: 1 / 1;
  width: 100%;
  height: 100%;
  max-height: none;
  object-fit: contain;
  margin: 0;
  border-radius: 0;
  transition: opacity 320ms ease;
}

.illustration-second {
  opacity: 0;
}

/* Keep the original step-3 video's wide side-view composition, without cropping. */
#guideView #step3 .step-media {
  display: grid;
  place-items: center;
  container-type: size;
}
.compression-presentation {
  width: min(100cqw, calc((100cqh - 42px) * 1.7768331562));
  display: flex;
  flex-direction: column;
  gap: 6px;
}
#step3 .illustration-fit {
  flex: none;
  container-type: normal;
  display: block;
}
#compressionStage {
  width: 100%;
  aspect-ratio: 1672 / 941;
}

.compression-canvas,
.compression-overlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}
.compression-canvas { z-index: 2; opacity: 0; }
.renderer-ready .compression-canvas { opacity: 1; }
.compression-overlay { z-index: 3; }
.depth-measurement {
  position: absolute;
  z-index: 4;
  left: 89.71%;
  top: 40%;
  transform: translate(-50%, -100%);
  color: #12452e;
  font-size: clamp(12px, 2.2vw, 19px);
  font-weight: 700;
  white-space: nowrap;
  pointer-events: none;
  line-height: 1.2;
}
.compression-controls {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: none;
  min-height: 36px;
}
.compression-rhythm {
  flex: 1;
  height: 8px;
  margin: 0;
  overflow: hidden;
  border-radius: 999px;
  background: #dae7df;
}
.compression-rhythm-fill {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #176343, #30986b);
  transform: scaleX(0);
  transform-origin: left center;
}
.animation-footer { display: flex; justify-content: flex-end; }
#compressionToggle {
  min-height: 36px;
  padding: 8px 10px;
  border: 1px solid #adbbb0;
  border-radius: 7px;
  color: #174c30;
  background: #fff;
  font: inherit;
  font-size: 12px;
  white-space: nowrap;
  cursor: pointer;
}
#compressionToggle[hidden] { display: none; }

[data-phase="second"] .illustration-first {
  opacity: 0;
}

[data-phase="second"] .illustration-second {
  opacity: 1;
}

.pressure-arrow {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 2;
  fill: #ef1616;
  opacity: 0;
  transform: translateY(-6px);
  transition: opacity 350ms ease, transform 350ms ease;
  pointer-events: none;
}

[data-phase="second"] .pressure-arrow {
  opacity: 1;
  transform: translateY(0);
}

/* Make the welcome screen usable without the fixed header covering its title. */
.welcome {
  padding-top: 125px;
  max-width: 640px;
  margin: 0 auto;
}

#guideView .timeline-banner {
  display: grid !important;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  align-items: center;
  gap: 16px;
  border: 1px solid #dce3de;
  border-radius: 10px;
  padding: 8px 12px;
  overflow: visible;
}
#guideView .timeline-wrapper { margin: 0; padding-top: 10px; min-width: 0; }
#guideView .timeline { height: 6px; }
#guideView .rtw { width: 28px; height: 28px; top: -16px; }
#guideView .timeline-text,
#guideView .time-remaining { font-size: 12px; line-height: 1.25; margin: 0; }
#guideView .time-remaining { margin-top: 4px; }

#guideView .navigation {
  position: relative;
  flex: none;
  flex-wrap: wrap;
  width: 100%;
  gap: 8px;
  padding: 8px 12px calc(8px + env(safe-area-inset-bottom, 0px));
}
#guideView .nav-btn,
#guideView .end-btn {
  flex: 1 1 0;
  max-width: 180px;
  min-height: 44px;
  width: auto;
  min-width: 0;
  padding: 8px 12px;
  font-size: 16px;
}
#guideView .media-unlock-btn {
  position: static;
  flex: 1 1 0;
  max-width: 180px;
  min-height: 44px;
  margin: 0;
  padding: 6px 8px;
  font-size: 14px;
  line-height: 1.2;
  box-shadow: none;
}

/* Closing copy remains readable, with scrolling only as a safety net for extreme zoom/height. */
#guideView #step4,
body.step4-active #guideView #step4 { overflow: visible; padding: 0; }
#guideView #step4 .step-content { display: block; overflow-y: auto; }
#guideView #step4 .step-text { gap: 8px; }
#guideView .ende-banner { margin: 0; padding: 10px 12px; border-radius: 8px; }
#guideView .ende-banner p + p { margin-top: 4px; }

@media (max-height: 600px) {
  #guideView .cpr-header { height: calc(34px + env(safe-area-inset-top, 0px)); }
  .cpr-header .logo { height: 26px; }
  #guideView .container { padding-top: 6px !important; padding-bottom: 6px !important; gap: 6px; }
  #guideView .step-content,
  #guideView .step.active { gap: 6px; }
  #guideView .navigation { padding-top: 6px; padding-bottom: calc(6px + env(safe-area-inset-bottom, 0px)); }
  #guideView #step4 .step-text { gap: 4px; }
  #guideView .ende-banner { padding: 6px 8px; }
}

/* Wide, shallow screens: use their width instead of squeezing the illustration vertically. */
@media (min-aspect-ratio: 4/3) and (max-height: 700px) {
  #guideView .step-content {
    grid-template-columns: minmax(190px, 1fr) minmax(0, 1.5fr);
    grid-template-rows: minmax(0, 1fr);
    column-gap: 16px;
  }
  #guideView #step3.active {
    grid-template-columns: minmax(190px, 1fr) minmax(0, 1.5fr);
    grid-template-rows: minmax(0, 1fr) auto;
    column-gap: 16px;
  }
  #guideView #step3 .step-content { display: contents; }
  #guideView #step3 .step-text { grid-column: 1; grid-row: 1; }
  #guideView #step3 .step-media { grid-column: 2; grid-row: 1 / 3; }
  #guideView #step3 .timeline-banner { grid-column: 1; grid-row: 2; grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr); gap: 8px; padding: 6px 8px; }
  #guideView #step4 .step-text { display: block; columns: 2; column-gap: 24px; }
  #guideView #step4 .step-text > p,
  #guideView #step4 .ende-banner { break-inside: avoid; margin-bottom: 8px; }
}

@media (orientation: landscape) and (max-height: 360px) {
  #guideView .step p:not(.timeline-text):not(.time-remaining) { line-height: 1.25; }
  #guideView .timeline-text,
  #guideView .time-remaining { font-size: 11px; line-height: 1.2; }
  #guideView #step4 p:not(.timeline-text):not(.time-remaining) { font-size: 13px; line-height: 1.2; }
  #guideView #step4 .step-text > p,
  #guideView #step4 .ende-banner { margin-bottom: 4px; }
}

/* Do not clip content on exceptionally small windows or at high accessibility zoom. */
@media (max-height: 280px), (max-width: 279px) {
  #guideView:not(.hidden) { height: auto; min-height: 100dvh; }
  #guideView .container { flex: none; }
  #guideView .illustration-fit { flex: none; height: 180px; }
  #guideView .step-content,
  #guideView #step3.active { display: flex; flex-direction: column; }
  #guideView #step3 .step-media { display: block; container-type: normal; }
  .compression-presentation { width: 100%; }
  #guideView #step3 .illustration-fit { height: auto; }
}

@media (prefers-reduced-motion: reduce) {
  .step .illustration-stage > img,
  .pressure-arrow {
    transition: none;
    transform: none;
  }
}
