:root {
  color-scheme: dark;
  --ink: #f1e8d5;
  --muted: #b9b6bc;
  --gold: #dfc38d;
  --edge: #55505c;
  --panel: #191a25;
  --focus: #e8cf97;
  font-family: ui-sans-serif, system-ui, sans-serif;
  background: #101119;
  color: var(--ink);
}
* {
  box-sizing: border-box;
}
body {
  margin: 0;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
button {
  font: inherit;
  color: inherit;
}
button {
  min-height: 44px;
  border: 1px solid var(--edge);
  border-radius: 5px;
  background: #252632;
  padding: 8px 13px;
  cursor: pointer;
}
button:hover {
  border-color: var(--gold);
  background: #353342;
}
button:disabled {
  opacity: 0.4;
  cursor: default;
}
button[aria-pressed="true"] {
  border-color: var(--gold);
  box-shadow: inset 0 0 0 1px var(--gold);
  background: #3f3940;
}
button:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 3px;
}
.primary {
  background: var(--gold);
  color: #1a1a24;
  border-color: var(--gold);
  font-weight: 750;
  min-width: 88px;
}
.primary:hover {
  background: #f3d9a6;
}
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 20px;
  min-height: 58px;
  background: #14151d;
  flex: none;
}
.brand {
  letter-spacing: 0.16em;
  font-size: 12px;
  font-weight: 750;
}
.brand span {
  letter-spacing: 0;
  font-family: Georgia, serif;
  font-weight: 400;
  font-size: 18px;
  margin-left: 18px;
  color: var(--muted);
}
.top-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}
#turn {
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
  padding: 0 8px;
}
.top-actions button {
  font-size: 12px;
}
@media (max-width: 380px) {
  .topbar .brand {
    display: none;
  }
  .topbar .top-actions {
    width: 100%;
    justify-content: space-between;
  }
}
.music-controls {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 16px;
}
.music-controls input {
  min-height: 44px;
  width: 150px;
  accent-color: var(--gold);
}
.music-status {
  color: var(--muted);
  font-size: 14px;
}
.notice {
  padding: 8px 16px;
  margin: 0;
  background: #564525;
  font-size: 13px;
  flex: none;
}
main {
  min-height: 0;
  display: flex;
  flex: 1;
  flex-direction: column;
}
.stage {
  position: relative;
  min-height: 0;
  flex: 1;
  isolation: isolate;
  /* Keep focus and reply scrolling inside the dialogue, with the scene fixed. */
  overflow: clip;
  background: #232330;
  container-type: size;
}
.backdrop,
.scene-shade {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  z-index: -2;
}
.scene-shade {
  z-index: -1;
  background: linear-gradient(
    180deg,
    #10111bc4,
    transparent 38%,
    #10111b22 65%,
    #10111b8c
  );
}
.cast {
  position: absolute;
  inset: 58px 7% 250px;
  pointer-events: none;
}
.portrait {
  position: absolute;
  left: var(--stage-x);
  bottom: var(--stage-floor);
  height: var(--stage-size);
  aspect-ratio: 2 / 3;
  transform: translateX(-50%);
  pointer-events: none;
  transition:
    left 0.85s ease-in-out,
    bottom 0.85s ease-in-out,
    height 0.85s ease-in-out;
}
.portrait[data-depth="foreground"] {
  z-index: 3;
}
.portrait[data-depth="middle"] {
  z-index: 2;
}
.portrait[data-depth="back"] {
  z-index: 1;
}
.portrait-body {
  position: relative;
  width: 100%;
  height: 100%;
  transform-origin: 50% 99%;
  transition:
    filter 0.22s,
    transform 0.22s;
}
.portrait.active .portrait-body {
  filter: brightness(1.08);
  transform: translateY(-2px) rotate(var(--lean));
}
.portrait img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: bottom;
  filter: drop-shadow(0 8px 14px #08091390);
}
.portrait img[data-flip="true"] {
  transform: scaleX(-1);
}
/* Hand positions follow the original 2:3 character artwork. The prop shares
   the body's movement and scales with it at every viewport size. */
.portrait {
  --hand-x: 83%;
  --hand-y: 32.5%;
  --held-offset: -100%;
}
.portrait[data-avatar="mara"] {
  --hand-x: 91%;
  --hand-y: 28%;
}
.portrait[data-avatar="ash"] {
  --hand-x: 90%;
  --hand-y: 38%;
}
.portrait[data-avatar="nell"] {
  --hand-x: 88%;
  --hand-y: 41%;
}
.portrait[data-avatar="tavi"] {
  --hand-x: 92%;
  --hand-y: 20%;
  --held-offset: -20%;
}
.portrait[data-avatar="rue"] {
  --hand-x: 83%;
  --hand-y: 24%;
  --held-offset: -50%;
}
.portrait[data-avatar="orin"] {
  --hand-x: 51%;
  --hand-y: 24%;
  --held-offset: -50%;
}
.portrait[data-avatar="ada"] {
  --hand-x: 88%;
  --hand-y: 22%;
  --held-offset: -15%;
}
.portrait-held-item {
  position: absolute;
  left: var(--hand-x);
  top: var(--hand-y);
  width: 30%;
  aspect-ratio: 1;
  transform: translate(-50%, var(--held-offset));
  pointer-events: none;
}
.portrait[data-flip="true"] .portrait-held-item {
  left: calc(100% - var(--hand-x));
}
.portrait-held-item img {
  position: absolute;
  inset: 0;
  object-position: center bottom;
  filter: drop-shadow(0 2px 3px #08091390);
}
.portrait-held-item[data-lit="true"] > img:first-child {
  filter: drop-shadow(0 0 7px #e0a94a99);
}
.portrait-held-item[data-lit="false"] > img:first-child {
  filter: saturate(0.35) brightness(0.48);
}
.portrait-held-item[data-covered="true"] > img:first-child {
  opacity: 0.35;
}
.portrait-held-item .object-cover {
  filter: brightness(0.65);
}
.portrait-held-item[data-ringing="true"] > img:first-child {
  animation: sounding 0.5s ease-in-out infinite alternate;
  transform-origin: 50% 20%;
}
/* Things lying in this place stand on the painted floor as cutouts, behind the
   cast and clear of the dialogue. Wide stages set them beside the dialogue;
   narrower ones stand fewer, smaller props on the floor above it, and short
   ones set them beside the hand at the front of the floor. */
.floor-items {
  position: absolute;
  z-index: 0;
  inset: 0;
  pointer-events: none;
}
.floor-item {
  --x: var(--wide-x);
  --lift: var(--wide-lift);
  --prop-size: clamp(56px, 10cqh, 104px);
  --floor-line: calc(var(--dock-height) + 6px);
  position: absolute;
  left: clamp(
    calc(var(--prop-size) / 2 + 4px),
    var(--x),
    calc(100% - var(--prop-size) / 2 - 4px)
  );
  bottom: calc(var(--floor-line) + var(--lift) * 1.2cqh);
  width: calc(var(--prop-size) * (1 - var(--lift) * 0.04));
  aspect-ratio: 1;
  transform: translateX(-50%);
  pointer-events: none;
}
@media (max-width: 1299px) {
  .floor-item {
    --x: var(--narrow-x);
    --lift: var(--narrow-lift);
    --prop-size: clamp(34px, 8cqh, 72px);
    --floor-line: calc(var(--dock-height) + var(--dialogue-reserve, 140px));
  }
  .floor-item[data-narrow="false"] {
    display: none;
  }
}
@media (max-width: 1299px) and (max-height: 640px) {
  .floor-item {
    --x: var(--short-x);
    --lift: var(--short-lift);
    --floor-line: 10px;
  }
  .floor-item[data-narrow] {
    display: block;
  }
  .floor-item[data-short="false"] {
    display: none;
  }
}
.floor-item img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: center bottom;
  filter: drop-shadow(0 5px 5px #08091399);
}
.floor-item[data-lit="true"] > img:first-child {
  filter: drop-shadow(0 5px 5px #08091399) drop-shadow(0 0 9px #e0a94a99);
}
.floor-item[data-lit="false"] > img:first-child {
  filter: drop-shadow(0 5px 5px #08091399) saturate(0.35) brightness(0.48);
}
.floor-item[data-covered="true"] > img:first-child {
  opacity: 0.35;
}
.floor-item .object-cover {
  filter: brightness(0.65);
}
.floor-item[data-ringing="true"] > img:first-child {
  animation: sounding 0.5s ease-in-out infinite alternate;
  transform-origin: 50% 20%;
}
.dialogue {
  position: absolute;
  z-index: 4;
  bottom: 14px;
  left: 50%;
  transform: translateX(-50%);
  width: min(860px, calc(100% - 40px));
  border: 1px solid #a38b64;
  border-radius: 7px;
  background: #181925ed;
  box-shadow: 0 10px 35px #08091470;
  padding: 10px 18px;
  backdrop-filter: blur(12px);
}
.dialogue-heading {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
}
.movement-caption {
  margin: 0 0 6px;
  color: #d8cbb3;
  font:
    13px/1.4 Georgia,
    serif;
}
#speaker {
  color: var(--gold);
  font-family: Georgia, serif;
  font-size: 18px;
}
.line-controls {
  margin-left: auto;
  display: flex;
  gap: 4px;
}
.line-controls button {
  min-height: 44px;
  min-width: 44px;
  padding: 0 9px;
  font-size: 22px;
  border-color: transparent;
  background: transparent;
}
#dialogue-text {
  display: block;
  position: relative;
  text-align: left;
  font:
    16px/1.4 Georgia,
    serif;
  height: 68px;
  padding-right: 1em;
  overflow-x: hidden;
  overflow-y: auto;
  scrollbar-gutter: stable;
  margin: 5px 0 12px;
}
.speech-line {
  display: block;
  width: 100%;
  padding: 0;
  border: 0;
  background: transparent;
  text-align: left;
}
.speech-line:hover {
  background: transparent;
}
.speech-letter {
  visibility: hidden;
  position: relative;
}
.speech-letter.revealed {
  visibility: visible;
}
.speech-letter.cursor::after {
  content: "";
  visibility: visible;
  position: absolute;
  left: 100%;
  bottom: 0;
  width: 0.5em;
  border-bottom: 2px solid var(--gold);
  animation: speech-blink 0.9s steps(1) infinite;
}
[data-revealing="true"] .speech-letter.cursor::after {
  width: 0;
  height: 1em;
  border-bottom: 0;
  border-left: 2px solid var(--gold);
  animation: none;
}
.speech-hint {
  display: block;
  height: 12px;
  line-height: 12px;
  text-align: right;
  font-size: 10px;
  color: var(--muted);
  margin-top: -5px;
}
#story-status {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 14px;
}
#story-status[hidden] {
  display: none;
}
.thinking-orbit {
  width: 15px;
  height: 15px;
  border: 2px solid #a48d6340;
  border-top-color: var(--gold);
  border-radius: 50%;
  animation: thinking-orbit 1.2s linear 12;
}
@keyframes thinking-orbit {
  to {
    transform: rotate(360deg);
  }
}
@media (prefers-reduced-motion: reduce) {
  .thinking-orbit {
    animation: none;
  }
}
body .dialogue-heading #story-retry {
  width: 28px;
  height: 28px;
  min-width: 28px;
  min-height: 28px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
  font-size: 18px;
  line-height: 1;
}
body .dialogue-heading #story-retry:hover,
body .dialogue-heading #story-retry:focus-visible {
  color: var(--ink);
}
@keyframes speech-blink {
  50% {
    opacity: 0;
  }
}
dialog {
  color: var(--ink);
  background: #1d1e2a;
  border: 1px solid #817053;
  border-radius: 9px;
  width: min(600px, calc(100% - 28px));
  max-height: 85dvh;
  padding: 22px;
  box-shadow: 0 20px 90px #0008;
}
dialog::backdrop {
  background: #090b16ab;
  backdrop-filter: blur(5px);
}
dialog p {
  font-size: 14px;
  line-height: 1.6;
}
h2 {
  font:
    normal 25px Georgia,
    serif;
  margin: 0;
}
.modal-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
}
.messages {
  max-height: 55dvh;
  overflow: auto;
  margin-bottom: 16px;
}
.message {
  border-bottom: 1px solid #ffffff15;
  padding: 10px 0;
}
.message p {
  margin: 6px 0;
  font-size: 13px;
}
.speaker {
  font-weight: 650;
  color: var(--gold);
  font-size: 12px;
  display: flex;
  justify-content: space-between;
}
.speaker span {
  font-weight: 400;
  color: var(--muted);
  font-size: 10px;
}
.sr-only {
  position: absolute;
  top: 0;
  left: 0;
  margin: -1px;
  padding: 0;
  border: 0;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
}
[hidden] {
  display: none !important;
}
@media (min-width: 1400px) {
  .hand {
    gap: 16px;
  }
  .card-frame {
    flex-basis: 194px;
    width: 194px;
  }
}
@media (max-width: 700px) {
  .topbar {
    padding: 5px 10px;
    min-height: 52px;
  }
  .brand {
    font-size: 10px;
  }
  .brand span {
    display: none;
  }
  .top-actions {
    gap: 4px;
  }
  .top-actions button {
    padding: 5px 9px;
  }
  .cast {
    inset: 65px 4% 235px;
  }
  .cast:not([data-shared="true"])[data-count="3"]
    .portrait[data-depth="foreground"] {
    left: 19%;
  }
  .cast:not(
      [data-shared="true"]
    )[data-count="3"][data-layout="foreground-right"]
    .portrait[data-depth="foreground"] {
    left: 81%;
  }
  .dialogue {
    width: calc(100% - 20px);
    bottom: 9px;
    padding: 8px 11px;
  }
  .dialogue-heading {
    gap: 8px;
  }
  #speaker {
    font-size: 16px;
  }
  #dialogue-text {
    font-size: 14px;
    height: 60px;
    margin: 2px 0 8px;
  }
  .play-dock {
    padding: 0 8px 4px;
  }
  .hand {
    gap: 8px;
  }
  .card-frame {
    flex-basis: 174px;
    width: 174px;
    height: 262px;
  }
  .card {
    grid-template-rows: auto 66px auto auto 1fr auto;
    padding: 7px 8px;
  }
  .card .art svg {
    width: 34px;
    height: 42px;
  }
  .card .name {
    font-size: 15px;
  }
  .card .state {
    font-size: 11px;
  }
}
@media (max-height: 740px) {
  .topbar {
    min-height: 48px;
    padding-top: 2px;
    padding-bottom: 2px;
  }
  .cast {
    top: 55px;
    bottom: 175px;
  }
  .dialogue {
    bottom: 7px;
    padding: 5px 10px;
  }
  #speaker {
    font-size: 14px;
  }
  #dialogue-text {
    font-size: 12px;
    line-height: 1.3;
    height: 32px;
    margin: 3px 0 6px;
  }
}
/* Frame the group from the scene height, even on a very wide screen. Keep
   their feet above the full two-line exchange, with room for the title. */
@media (min-width: 701px) {
  .cast {
    --cast-top: 18px;
    --cast-bottom: 242px;
    inset: auto 0 var(--cast-bottom);
    height: min(
      580px,
      45vw,
      calc(100cqh - var(--cast-top) - var(--cast-bottom))
    );
    margin-inline: auto;
    width: min(
      90%,
      1200px,
      calc((100cqh - var(--cast-top) - var(--cast-bottom)) * 2.8)
    );
  }
}
@media (min-width: 701px) and (max-height: 740px) {
  .cast {
    --cast-bottom: 168px;
  }
}
/* Frame the cast close. One or two avatars stand waist-deep behind the
   exchange, three stand knee-deep, so faces read large on a wide screen. */
@media (min-width: 701px) {
  .cast[data-count="1"],
  .cast[data-count="2"] {
    --cast-bottom: 0px;
    height: min(
      980px,
      70vw,
      calc(100cqh - var(--cast-top) - var(--cast-bottom))
    );
  }
  .cast[data-count="3"] {
    --cast-bottom: 40px;
    height: min(
      820px,
      60vw,
      calc(100cqh - var(--cast-top) - var(--cast-bottom))
    );
  }
}
@media (max-width: 700px) {
  .cast[data-count="1"],
  .cast[data-count="2"] {
    bottom: 70px;
  }
  .cast[data-count="3"] {
    bottom: 130px;
  }
}
/* Short windows keep a readable scene; the same card row follows below. */
@media (max-height: 640px) {
  body {
    overflow-y: auto;
  }
  .stage {
    min-height: 460px;
  }
}
/* Labels for the reveal and the travel veil, shown at every width. */
.kicker {
  margin: 0;
  font-size: 11px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--gold);
}

/* A change of place dips the scene to dark with the destination's name. */
.travel {
  position: absolute;
  inset: 0;
  z-index: 6;
  display: grid;
  place-content: center;
  gap: 6px;
  text-align: center;
  background: radial-gradient(circle at 50% 45%, #1b1c28f2, #06070c);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.36s ease-in-out;
}
.travel.travelling {
  opacity: 1;
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation: none !important;
    transition: none !important;
    scroll-behavior: auto !important;
  }
}

/* Let the farewell finish before the cutout leaves its existing slot. */
.portrait.departed {
  opacity: 0;
  translate: var(--exit-x) 0;
}
.hand[aria-busy="true"] .card,
#card-actions[aria-busy="true"] button {
  opacity: 0.7;
}
.hand[aria-busy="true"] .card:hover {
  transform: none;
}

@media (prefers-reduced-motion: reduce) {
  .portrait,
  .portrait-body {
    transition: none;
  }
  .portrait.active .portrait-body {
    transform: none;
  }
  .portrait.departed {
    translate: 0 0;
  }
}

.portrait.entering {
  visibility: hidden;
}

/* Image-first cards. The illustration is the face, not a banner above a report. */
:root {
  --card-width: clamp(174px, 15.5vw, 224px);
  --card-height: clamp(224px, 31dvh, 310px);
  --dock-height: calc(var(--card-height) * 0.75 + 12px);
}
body {
  background: #090d12;
}
.topbar {
  position: absolute;
  inset: 0 0 auto;
  z-index: 10;
  min-height: 58px;
  border: 0;
  background: linear-gradient(#090d12bc, #090d1200);
}
.top-actions button {
  background: #0e121888;
  border-color: #c7af7955;
  border-radius: 22px;
}
main {
  position: relative;
}
.stage {
  min-height: 0;
  flex: 1;
}
.play-dock {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 5;
  padding: 0 22px env(safe-area-inset-bottom);
  background: linear-gradient(#090d1200, #090d12bd 55%, #090d12f5);
  border: 0;
  pointer-events: none;
}
.hand-wrap {
  position: relative;
  pointer-events: auto;
}
.hand {
  display: flex;
  justify-content: safe center;
  gap: 14px;
  flex-wrap: nowrap;
  overflow-x: auto;
  overflow-y: hidden;
  padding: 12px 16px 0;
  height: calc(var(--card-height) * 0.75 + 12px);
  transition: height 220ms ease-out;
  scrollbar-width: none;
  scrollbar-color: #ad97744d transparent;
  scroll-padding-inline: 5px;
  scroll-snap-type: x proximity;
}
/* Keep the chosen card at the position set by revealHandCard. */
.hand:has(.card-frame[data-raised="true"]) {
  scroll-snap-type: none;
}
.hand-wrap::before,
.hand-wrap::after {
  display: none;
}
body .card-frame {
  position: relative;
  flex: 0 0 var(--card-width);
  width: var(--card-width);
  height: var(--card-height);
  scroll-snap-align: start;
  transition: transform 0.16s;
}
body .card-frame[data-raised="true"] {
  transform: translateY(-10px);
}
/* Lift the full stack while the face keeps its shadow on the same layer. */
#hand:not([aria-busy="true"]) .card-frame:has(> .card:hover) {
  top: -2px;
}
body .card {
  position: relative;
  width: 100%;
  height: 100%;
  display: block;
  padding: 0;
  overflow: hidden;
  border: 1px solid #a48d63b3;
  border-radius: 13px;
  text-align: center;
  background: #181b22;
  touch-action: pan-x;
  box-shadow: 0 6px 20px #0006;
}
body .card:hover {
  background: #181b22;
}
body .card[aria-pressed="true"] {
  border-color: #f2dba6;
  background: #181b22;
  box-shadow:
    0 0 0 1px #f2dba677,
    0 0 22px #f2dba61a;
}
body .card .art {
  position: absolute;
  inset: 0;
  display: block;
  overflow: hidden;
  border-radius: inherit;
  background: radial-gradient(ellipse at 50% 66%, #70543c6e, #141b2499);
}
body .card .art img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}
body .card.item .art img {
  inset: 6% 3% 12%;
  width: 94%;
  height: 82%;
  object-fit: contain;
  filter: drop-shadow(0 8px 10px #0009);
}
body .card.avatar .art img {
  --shown: calc(var(--figure-height, 1) * 0.78);
  inset: auto;
  top: calc(6% - 100% * var(--figure-top, 0) / var(--shown));
  left: 50%;
  width: auto;
  height: calc(100% / var(--shown));
  translate: calc(-100% * var(--head-x, 0.5)) 0;
  object-fit: fill;
}
body .card .name {
  position: absolute;
  inset: auto 0 calc(var(--card-height) * 0.25);
  z-index: 1;
  margin: 0;
  padding: 36px 8px 14px;
  background: linear-gradient(transparent, #080b12eb 65%);
  font:
    18px/1.2 Georgia,
    serif;
  color: #f2e3c4;
  white-space: normal;
  text-wrap: balance;
  text-shadow: 0 2px 5px #000;
}
/* Carry the label's shade to the card's edge, wherever the hand clips it. */
body .card .name::after {
  content: "";
  position: absolute;
  inset: 100% 0 auto;
  height: var(--card-height);
  background: #080b12eb;
}
body .card[data-lit="true"] .art {
  background: radial-gradient(ellipse at 50% 60%, #e0a94a66, #151b24 76%);
}
body .card[data-lit="false"] .art > img:first-child {
  filter: saturate(0.35) brightness(0.48);
}
body .card[data-covered="true"] .art > img:first-child {
  opacity: 0.35;
}
body .card.item .art .object-cover {
  inset: 10% 3% 12%;
  height: 80%;
  filter: brightness(0.65);
}
body .card[data-ringing="true"] .art > img:first-child {
  animation: sounding 0.5s ease-in-out infinite alternate;
  transform-origin: 50% 20%;
}
@keyframes sounding {
  from {
    rotate: -2deg;
  }
  to {
    rotate: 2deg;
  }
}
body .card-frame[hidden] {
  display: none;
}
.card-frame .card {
  z-index: 1;
}
.held-preview {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  padding: 8px;
  border: 1px solid #a48d6380;
  border-radius: 13px;
  background: #25252c;
  transform: translate(7px, -4px) rotate(3deg);
  pointer-events: none;
}
.held-preview:nth-child(2) {
  transform: translate(12px, -6px) rotate(5deg);
}
.card-frame[data-expanded="true"] .held-preview {
  display: none;
}
.card-frame[data-holder] .card {
  border-color: #a48d6370;
}
.action-panel {
  pointer-events: auto;
  text-align: center;
  overflow: clip;
}
#card-actions {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 3px 1px;
  scrollbar-width: thin;
}
#card-actions:empty {
  padding: 0;
}
#card-actions button {
  flex: 0 0 auto;
  max-width: min(260px, 85vw);
  min-height: 44px;
  padding: 8px 16px;
  background: #171920ee;
  border: 1px solid #baa37c;
  border-radius: 24px;
  color: #f2e3c4;
  font:
    15px/1.25 Georgia,
    serif;
  white-space: normal;
}
#card-actions button:first-child {
  margin-left: auto;
}
#card-actions button:last-child {
  margin-right: auto;
}
#card-actions button:hover {
  background: #3c3325;
}
#card-actions button[data-queued="true"],
#card-actions button[data-sent] {
  border-color: var(--gold);
  background: #3c3325;
}
body .card.drag-over {
  outline: 2px solid var(--gold);
}
.stage.ready::after {
  content: attr(data-play);
  position: absolute;
  inset: 60px 15% var(--dock-height);
  border: 1px solid #dfc38d55;
  border-radius: 20px;
  display: grid;
  place-items: center;
  background: #13161a44;
  color: var(--gold);
  font:
    24px Georgia,
    serif;
  pointer-events: none;
  z-index: 8;
}
body .dialogue {
  bottom: calc(var(--dock-height) + 2px);
  max-width: 720px;
  width: calc(100% - 28px);
  background: #10151ddd;
  border-color: #b09a6a55;
}
body .cast {
  --cast-bottom: calc(var(--dock-height) - 70px);
  bottom: var(--cast-bottom);
  top: 64px;
  height: auto;
  width: min(92%, 1100px);
  inset-inline: 0;
  margin-inline: auto;
}
body .cast[data-count] {
  bottom: var(--cast-bottom);
  height: auto;
}
.controls-help {
  margin-bottom: 20px;
}
.controls-help summary {
  min-height: 44px;
  display: flex;
  align-items: center;
  cursor: pointer;
}
@media (max-width: 700px) {
  :root {
    --card-width: 154px;
    --card-height: clamp(196px, 28dvh, 246px);
  }
  .topbar {
    min-height: 50px;
    padding: 4px 10px;
  }
  .top-actions button {
    padding: 5px 10px;
    font-size: 12px;
  }
  .play-dock {
    padding-inline: 16px;
  }
  .hand {
    gap: 10px;
  }
  body .card .name {
    font-size: 16px;
    padding-bottom: 12px;
  }
  body .cast {
    top: 54px;
    width: 98%;
  }
  body .cast .portrait[data-framing="wide"] {
    height: min(calc(var(--stage-size) * 0.74), 93vw);
    left: clamp(34%, var(--stage-x), 66%);
    z-index: 4;
  }
  /* A solo human's 2:3 frame fits the phone, including outstretched hands. */
  body .cast[data-count="1"] .portrait:is(
      [data-avatar="vale"],
      [data-avatar="mara"],
      [data-avatar="ash"],
      [data-avatar="nell"],
      [data-avatar="tavi"],
      [data-avatar="rue"],
      [data-avatar="orin"],
      [data-avatar="ada"]
    ) {
    max-height: 144vw;
  }
  body .cast[data-shared="true"]:not([data-count="1"]):not([data-count="2"]) {
    --bust-drop: clamp(
      0%,
      min(calc((var(--cast-count) - 2) * 12%), calc(100% - 380px)),
      42%
    );
  }
  body
    .cast[data-shared="true"]:not([data-count="1"]):not([data-count="2"])
    .portrait[data-depth="foreground"] {
    bottom: calc(100% - var(--stage-size) - var(--bust-drop));
  }
  body .cast[data-shared="true"] .portrait[data-depth="back"] {
    left: calc(10% + var(--stage-x) * 0.8);
    bottom: calc(86% - var(--stage-size));
  }
  body .dialogue {
    bottom: calc(var(--dock-height) + 2px);
    padding: 8px 12px;
  }
}
@media (max-height: 640px) {
  :root {
    --card-height: 176px;
    --card-width: 128px;
    --dock-height: 144px;
  }
}
@media (max-height: 440px) {
  :root {
    --card-height: 140px;
    --card-width: 112px;
  }
}

/* The speech box follows the line length; long replies scroll. */
.speech-row {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr);
  gap: 10px;
  align-items: start;
}
.speaker-portrait {
  position: relative;
  height: 48px;
  margin-top: 4px;
  overflow: hidden;
  border-radius: 8px;
  border: 1px solid #b09a6a66;
  background: #252832;
}
.speaker-portrait img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.speaker-portrait[data-kind="avatar"] img {
  --shown: calc(var(--figure-height, 1) * var(--portrait-crop, 0.3));
  position: absolute;
  width: auto;
  max-width: none;
  height: calc(100% / var(--shown));
  top: calc(6% - 100% * var(--figure-top, 0) / var(--shown));
  left: 50%;
  translate: calc(-100% * var(--head-x, 0.5)) 0;
}
.speech-content {
  min-width: 0;
}
body .dialogue-heading {
  gap: 4px;
  min-height: 28px;
}
body #speaker {
  font-size: 16px;
}
body .speech-line {
  min-height: 24px;
}
body #dialogue-text {
  font:
    16px/1.4 Georgia,
    serif;
  height: auto;
  max-height: 4.2em;
  margin: 2px 0 0;
  padding-right: 4px;
}
body .movement-caption {
  margin: 0 0 4px;
}
body .line-controls {
  gap: 0;
}
body .line-controls button {
  min-height: 28px;
  min-width: 32px;
  padding: 0 6px;
}
.play-dock[data-selected="true"] .hand {
  height: calc(var(--card-height) + 16px);
}
.play-dock[data-selected="true"] .card .name {
  bottom: 0;
}
/* A resting hand shares the bottom edge with the dialogue on wide screens. */
@media (min-width: 1100px) and (min-aspect-ratio: 3/2) {
  :root {
    --resting-hand-width: calc(var(--card-width) * 2 + 46px);
  }
  body[data-hand-expanded="false"] .play-dock {
    left: auto;
    width: calc(var(--resting-hand-width) + 44px);
  }
  body[data-hand-expanded="false"] .dialogue {
    left: 22px;
    bottom: max(22px, env(safe-area-inset-bottom));
    transform: none;
    width: calc(100% - var(--resting-hand-width) - 110px);
    max-width: 620px;
  }
}
@media (max-width: 700px) {
  .speech-row {
    grid-template-columns: 38px minmax(0, 1fr);
    gap: 8px;
  }
  .speaker-portrait {
    height: 44px;
  }
  body #dialogue-text {
    font-size: 15px;
  }
}

/* A discovery uses the scene for a moment, then joins the hand. */
.unveil[open] {
  position: fixed;
  inset: 0;
  margin: auto;
  z-index: 8;
  --reveal-height: min(310px, 52dvh);
  display: block;
  width: calc(var(--reveal-height) * 0.7);
  height: var(--reveal-height);
  max-width: none;
  max-height: none;
  padding: 0;
  border: 0;
  background: transparent;
  overflow: visible;
  box-shadow: none;
}
.unveil::backdrop {
  background: #090d1255;
  backdrop-filter: blur(2px);
  transition:
    background 180ms,
    backdrop-filter 180ms;
}
.unveil[data-phase="flight"]::backdrop {
  background: transparent;
  backdrop-filter: none;
}
#unveil-take {
  display: block;
  width: 100%;
  height: 100%;
  padding: 0;
  border: 0;
  border-radius: 13px;
  background: transparent;
  transform-origin: top left;
}
body .unveil .card-frame {
  width: 100%;
  height: 100%;
  transform: none;
}
body .unveil .card {
  display: block;
  transform: none;
  opacity: 1;
  box-shadow: 0 0 35px #e5c78b55;
}
body .unveil .card .name {
  bottom: 0;
}
body .card.new {
  border-color: #f2dba6;
  box-shadow:
    inset 0 0 0 1px #e7ca86aa,
    0 0 14px #e7ca8655;
}

/* The attic keeps its mirror in view as the room warms. */
body[data-place="attic"] #backdrop {
  object-position: 64% center;
  filter: brightness(0.55) saturate(0.65);
  transition: filter 650ms ease;
}
body[data-place="attic"][data-lamplit="true"] #backdrop {
  filter: brightness(0.77) saturate(0.8);
}
body[data-place="attic"] .scene-shade::after {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse at 65% 60%, #ce903d26, transparent 65%);
  opacity: 0;
  transition: opacity 650ms ease;
}
body[data-place="attic"][data-lamplit="true"] .scene-shade::after {
  opacity: 1;
}
body[data-place="attic"] .cast[data-count="1"] .portrait[data-avatar="vale"] {
  left: 75%;
}
@media (max-width: 700px) {
  body[data-place="attic"] #backdrop[data-location-variant^="attic-forest-cottage"] {
    object-position: left center;
  }
  body[data-place="attic"] .cast[data-count="1"] .portrait[data-avatar="vale"] {
    left: 50%;
  }
}
body[data-place="attic"] .card {
  background-color: #0d131c;
  border-color: #847961;
}
@media (max-width: 380px) {
  .topbar {
    padding-inline: 6px;
  }
  .topbar .top-actions {
    gap: 4px;
  }
  .topbar .top-actions button {
    padding-inline: 6px;
    font-size: 11px;
  }
}
@media (prefers-reduced-motion: reduce) {
  body[data-place="attic"] #backdrop,
  body[data-place="attic"] .scene-shade::after {
    transition: none;
  }
}
