:root {
  color-scheme: light;
  --paper: #ffffff;
  --ink: #373737;
  --muted: #666666;
  --line: #dedede;
  --action: #373737;
  --action-hover: #515151;
  --control-hover: #f2f2f2;
  --disabled-fill: #f3f3f3;
  --disabled-ink: #737373;
  --phone-surface: #fff;
  font: 16px/1.6 "Helvetica Neue", "PingFang SC", system-ui, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
}

.shell {
  max-width: 1200px;
  margin-inline: auto;
  padding: 0 clamp(16px, 4vw, 48px) 28px;
}

header {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 4px 20px;
  padding: 20px 0 16px;
  border-bottom: 1px solid var(--line);
}

header h1, header p, h2, p, dl, dd { margin: 0; }
header h1 { font-size: 18px; font-weight: 700; }
header p { color: var(--muted); font-size: 13px; }
.header-identity { margin-left: auto; text-align: right; }
.header-category { letter-spacing: .04em; }
header .header-author { font-weight: 700; }

.stage {
  display: grid;
  grid-template-columns: minmax(300px, 1fr) minmax(340px, 1fr);
}

.phone-bay {
  display: grid;
  place-items: center;
  padding: 16px;
}

.phone {
  position: relative;
  width: min(390px, 100%, max(260px, calc((100svh - 112px) * 390 / 844)));
  aspect-ratio: 390 / 844;
  --phone-radius: 20px;
  overflow: clip;
  border-radius: var(--phone-radius);
  clip-path: inset(0 round var(--phone-radius));
  background: var(--phone-surface);
}

iframe {
  display: block;
  width: 390px;
  height: 844px;
  border: 0;
  transform: scale(var(--phone-scale, 1));
  transform-origin: top left;
}

.narrative {
  align-self: start;
  padding: 0 clamp(24px, 4vw, 52px) 24px;
}

.chapters {
  display: flex;
  flex-wrap: wrap;
  gap: 0 16px;
  margin-bottom: clamp(24px, 4vw, 48px);
  border-bottom: 1px solid var(--line);
}

.chapters button {
  min-height: 42px;
  margin-bottom: -1px;
  padding: 6px 0;
  border: 0;
  border-bottom: 2px solid transparent;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}

.chapters button:hover,
.chapters button[aria-selected="true"] { color: var(--ink); }

.chapters button[aria-selected="true"] {
  border-bottom-color: var(--ink);
  font-weight: 700;
}

:focus-visible { outline: 2px solid var(--ink); outline-offset: 3px; }

h2 {
  margin-bottom: 12px;
  font-size: clamp(27px, 3.4vw, 40px);
  font-weight: 700;
  line-height: 1.2;
}

.intro { color: var(--ink); }
.instruction { color: var(--muted); }

dl {
  margin-top: 24px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

dt { font-weight: 700; }
dd { margin-top: 2px; }
dd + dt { margin-top: 14px; }

.instruction {
  margin-top: 24px;
  padding-top: 13px;
  border-top: 1px solid var(--line);
  font-size: 13px;
}

@media (max-width: 710px) {
  .stage { grid-template-columns: minmax(0, 1fr); }
}

.demo-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 20px;
}

.demo-actions button {
  min-height: 42px;
  padding: 7px 14px;
  border: 1px solid var(--muted);
  background: var(--paper);
  color: var(--ink);
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

.demo-actions .primary-action {
  border-color: var(--action);
  background: var(--action);
  color: var(--paper);
}

.demo-actions button:not(:disabled):hover {
  border-color: var(--ink);
  background: var(--control-hover);
}

.demo-actions .primary-action:not(:disabled):hover {
  background: var(--action-hover);
}

.demo-actions button:disabled {
  border-color: var(--line);
  background: var(--disabled-fill);
  color: var(--disabled-ink);
  cursor: default;
}

.demo-status {
  margin-top: 10px;
  min-height: 2.6em;
  color: var(--muted);
  font-size: 13px;
}

.housing-playback { margin-top: 8px; }
.housing-playback[hidden] { display: none; }

.action-cards { margin-top: 24px; }
.chapter-footer { margin-top: 16px; padding-bottom: 8px; }
[role="tabpanel"] { min-height: var(--chapter-base-height, 0px); }

.chapter-footer [hidden] { display: none; }
.chapter-footer .demo-actions { margin: 0; align-items: center; }
.chapter-footer .card-status { margin: 0; }
.chapter-finish { color: var(--muted); font-size: 13px; padding: 9px 0; }

.action-card {
  border-top: 1px solid var(--line);
}

.action-cards { border-bottom: 1px solid var(--line); }

.action-card > summary {
  position: relative;
  display: block;
  padding: 16px 44px 16px 0;
  list-style: none;
  cursor: pointer;
}

.action-card > summary::-webkit-details-marker {
  display: none;
}

.action-card > summary::after {
  position: absolute;
  top: 16px;
  right: 5px;
  color: var(--muted);
  font-size: 20px;
  line-height: 1.2;
  content: "+";
}

.action-card[open] > summary::after {
  content: "−";
}

.action-card > summary:hover .card-title {
  text-decoration: underline;
  text-underline-offset: 4px;
}

.card-title {
  display: block;
  font-size: 18px;
  font-weight: 700;
}

.card-summary {
  display: block;
  margin-top: 3px;
  color: var(--ink);
  font-size: 14px;
}

.card-body {
  padding: 0 0 20px;
}

.card-body h3 {
  margin: 0 0 4px;
  font-size: 14px;
  font-weight: 700;
}

.card-body p:not(.card-status) {
  max-width: 36em;
  font-size: 14px;
}

.card-body .demo-actions {
  margin-top: 14px;
}

.card-status {
  margin-top: 8px;
  color: var(--muted);
  font-size: 13px;
}

.card-status:empty {
  margin: 0;
}

.card-response {
  margin-top: 13px;
  padding: 12px 14px;
  border-inline-start: 2px solid var(--ink);
  background: #f6f6f6;
}

@media (min-width: 711px) {
  html, body {
    height: 100%;
    overflow: hidden;
  }

  .shell {
    display: grid;
    grid-template-rows: auto minmax(0, 1fr);
    height: 100svh;
    overflow: clip;
  }

  .stage {
    grid-template-rows: minmax(0, 1fr);
    min-height: 0;
  }

  .phone-bay {
    align-self: start;
  }

  .phone {
    width: min(390px, 100%, max(0px, calc((100svh - 134px) * 390 / 844)));
  }

  .narrative {
    align-self: stretch;
    min-height: 0;
    max-height: 100%;
    display: flex;
    flex-direction: column;
    padding-bottom: 20px;
  }

  .narrative-content {
    min-height: 0;
    padding-bottom: 4px;
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior-y: contain;
    scrollbar-gutter: stable;
  }
}

.stage[hidden], .finale[hidden] { display:none; }
.finale[data-preparing] {
  position: fixed;
  inset: 0;
  visibility: hidden;
  pointer-events: none;
}

.finale {
  min-height: 0;
  overflow: auto;
  padding: clamp(20px, 4vh, 44px) 4px 6px;
}

.finale > h1, .finale-viewer h2 {
  margin: 0;
  font-size: clamp(25px, 4vw, 42px);
  line-height: 1.2;
}

.finale > .intro { margin-top: 8px; }

.finale-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: clamp(10px, 2vw, 24px);
  margin-top: 22px;
}

.finale-tile {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  justify-items: center;
  gap: 8px;
  min-width: 0;
  margin: 0;
}

.finale-tile figcaption {
  font-size: 13px;
  font-weight: 600;
  text-align: center;
}

.finale-phone {
  position: relative;
  width: 100%;
  aspect-ratio: 390 / 844;
  overflow: clip;
  border-radius: clamp(8px, 1.5vw, 16px);
  clip-path: inset(0 round clamp(8px, 1.5vw, 16px));
  background: #f5f5f5;
  transform-origin: top left;
}

.finale-phone iframe {
  position: absolute;
  inset: 0 auto auto 0;
  pointer-events: none;
  transform: scale(var(--finale-scale, 0));
}

 .finale-tile {
  transform-origin: center;
  transition: transform 300ms ease-out, filter 300ms ease-out;
}
.finale-tile:hover, .finale-tile:focus-within {
  z-index: 10;
  transform: translateY(-8px) scale(1.32);
  filter: drop-shadow(0 14px 18px rgb(0 0 0 / .12));
}
.finale-tile:first-child { transform-origin: left center; }
.finale-tile:last-child { transform-origin: right center; }
.finale-grid { padding-block: 65px; }
.finale-phone iframe { pointer-events: auto; }
.finale-tile:focus-visible { outline: 2px solid var(--ink); outline-offset: 5px; }
@media(prefers-reduced-motion: reduce) {
 .finale-tile { transition: none; }
}
@media (min-width: 711px) {
  .finale-tile .finale-phone {
    max-width: max(116px, calc((100svh - 258px) * 390 / 844));
  }
}

@media (max-width: 710px) {
  .finale-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

.action-card[data-pinned] .card-title {
  text-decoration: underline;
  text-underline-offset: 4px;
}

/* Equal breathing space between the header rule and the tab rule. */
.chapters { padding-top: 0; }
.chapters button { padding-top: 8px; padding-bottom: 6px; }

.finale { padding: 16px 4px 8px; }
.finale-grid { padding-block: 24px; margin-top: 14px; }
@media (min-width: 711px) {
  .finale-grid { align-items: start; }
  .finale-tile .finale-phone {
    max-width: max(78px, calc((100svh - 300px) * 390 / 844));
  }
  .finale > .demo-actions { margin-top: 8px; }
}

/* Shadows may extend beyond the gallery's original content width. */
@media (min-width: 711px) {
  .shell:has(.finale:not([hidden])) { overflow: visible; }
  .finale { overflow: visible; }
}

.phone {
  flex-shrink: 0;
  isolation: isolate;
  -webkit-mask-image: -webkit-radial-gradient(white, black);
}
@media (min-width:711px) {
  .phone { max-height: calc(100svh - 134px); }
}

/* Keep the replay action above every enlarged phone. */
.finale > .demo-actions {
  position: relative;
  z-index: 30;
  isolation: isolate;
}
#finale-restart { position: relative; z-index: 1; }

/* Copy-only v1.1.1: paragraph spacing for the supplied case-study narrative. */
[role="tabpanel"] > .intro + .intro,
.card-body p + p { margin-top: 10px; }
.chapter-transition { margin-top: 20px; font-size: 14px; }
.chapter-transition h3 { margin: 0 0 6px; font-size: 18px; }
.chapter-transition p + p { margin-top: 6px; }
/* Finale uses the v1.1.0 gallery sizing with the selected v1.1.1 copy. */
.finale-restart-note { font-size: 13px; color: var(--muted); }
.finale > .demo-actions { align-items: center; gap: 12px; }
@media (min-width: 711px) {
  /* On shorter windows, let the page scroll without clipping enlarged phones. */
  html:has(#finale:not([hidden])), body:has(#finale:not([hidden])) {
    height: auto;
    overflow-y: auto;
  }
  .shell:has(#finale:not([hidden])) { height: auto; min-height: 100svh; }
}

/* Hover signals clickability; only a deliberate click changes the open card. */
.action-card > summary::after {
  z-index: 2;
  pointer-events: none;
  transform: scale(1);
  transform-origin: right center;
  transition: transform 200ms ease-in;
}
.action-card > summary:hover::after,
.action-card.card-introduction > summary::after {
  transform: scale(2);
  transition-timing-function: ease-out;
}
@media (prefers-reduced-motion: reduce) {
  .action-card > summary::after { transition: none; }
}

/* v1.1.4: keep chapter actions visible while the explanation scrolls. */
@media (min-width: 711px) {
  .narrative-content { flex: 1; }
  [role="tabpanel"] { min-height: 0; }
  .chapter-footer {
    flex: 0 0 auto;
    position: relative;
    z-index: 3;
    margin-top: 16px;
    padding-bottom: 0;
    background: var(--paper);
  }
}

/* Replay keeps the response in place while its controls and status change. */
.card-body .demo-actions { min-height: 42px; align-items: start; }
.action-card[data-response-revealed] .card-status { min-height: 3.2em; }

/* Finale supporting copy. */
.finale > .intro { font-size: 14px; }

/* Group Finale supporting paragraphs beneath the heading. */
.finale > h1 + .intro { margin-top: 16px; }
.finale > .intro + .intro { margin-top: 2px; }

/* Navigation headings receive focus for reading order, without a selection frame. */
#portfolio-title:focus, #finale-title:focus { outline: none; }

/* Keep preloaded gallery App layouts measurable without showing or focusing them. */
.finale[hidden] {
  display: block;
  position: fixed;
  top: 0;
  left: -20000px;
  width: min(calc(100vw - 2 * clamp(16px, 4vw, 48px)), 1104px);
  visibility: hidden;
  pointer-events: none;
}

/* The static first chapter shares the action cards' need/response typography. */
.chapter-context {
  margin-top: 24px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}
