.scene-roll {
  grid-template-columns: minmax(0, 1fr);
  align-items: stretch;
  width: min(100%, 760px);
  gap: 12px;
}

.scene-roll .scene-main { display: grid; gap: 12px; }
.scene-roll .scene-header { grid-area: auto; }
.scene-roll .stage-progress { grid-area: auto; }
.scene-roll .stage-progress .roll-waiting { flex: 1 1 100%; color: var(--muted); font-size: .89rem; }

.roll-workspace,
.role-review { display: grid; gap: 14px; min-width: 0; }

.roll-workspace .secret-card { grid-area: auto; }
.roll-workspace .secret-card:not(.is-concealed) {
  box-shadow: 0 2px 0 #372719, 0 12px 26px #080b07b0, inset 0 0 0 2px #f4deaf48;
  border-color: #a3855c;
}

.roll-workspace .role-art { object-position: 50% 34%; }
.roll-workspace .role-copy { padding: 10px 13px; gap: 6px; }
.roll-workspace .secret-card.is-concealed { min-height: 98px; }
.roll-workspace .secret-card.is-concealed .role-copy { padding: 10px 14px; }
.roll-workspace .private-toggle { min-height: 44px; }

.cup-inspection {
  --cup-size: clamp(97px, 33vw, 128px);
  --tray-height: clamp(124px, 38vw, 177px);
  --model-size: 38px;
  --cup-apex: -28px;
  --die-apex: -48px;
  display: grid;
  position: relative;
  grid-template-rows: var(--tray-height) 51px;
  gap: 0;
  width: 100%;
  min-width: 0;
  isolation: isolate;
  overflow: hidden;
  border: 1px solid #85714e;
  border-radius: 8px;
  background: #202b21;
  box-shadow: 0 5px 0 #101914, 0 18px 29px #080a06a6;
}

.cup-stage {
  position: relative;
  overflow: hidden;
  perspective: 360px;
  perspective-origin: 50% 70%;
  min-width: 0;
  background:
    radial-gradient(ellipse at 47% 39%, #69613b35, #15201900 79%),
    linear-gradient(0deg, #151e18 0, #314031 80%, #334237 100%);
}

.cup-stage::before {
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(128deg, #d0b77c0b 0 1px, transparent 1px 5px);
  pointer-events: none;
  content: "";
}

.cup-inspection:has(.inspect-cup[aria-disabled="false"]) .cup-stage { cursor: pointer; }

.cup-shadow,
.die-contact {
  position: absolute;
  z-index: 1;
  left: 50%;
  bottom: 11px;
  width: 114px;
  height: 13px;
  transform: translateX(-50%);
  border-radius: 50%;
  background: #0e140ded;
  filter: blur(5px);
}

.cup-inspection .inspect-cup-art {
  position: absolute;
  z-index: 4;
  height: var(--cup-size);
  width: var(--cup-size);
  inset-block-end: 7px;
  left: 50%;
  transform: translateX(-50%);
  background: url("/assets/walnut-cup.webp") center / contain no-repeat;
  filter: drop-shadow(2px 5px 5px #0d120eb8);
  transform-origin: 55% 80%;
  transition: transform 300ms cubic-bezier(.27,.68,.34,1);
}

.cup-inspection[data-open="true"] .inspect-cup-art {
  transform: translate3d(-91%, -8px, 0) rotate(-22deg);
}

.cup-inspection .cup-shadow { transition: transform 300ms ease, opacity 300ms ease; }
.cup-inspection[data-open="true"] .cup-shadow { transform: translateX(-77%) scale(.82); opacity: .68; }

.cup-readout {
  position: absolute;
  z-index: 3;
  inset-inline: 0;
  inset-block-start: 0;
  block-size: var(--tray-height);
  display: grid;
  align-items: end;
  justify-items: center;
  padding-block-end: 11px;
  pointer-events: none;
}

.cup-inspection .secret-die {
  display: grid;
  justify-items: center;
  align-items: end;
  gap: 6px;
  min-height: 0;
  width: max-content;
  max-width: 95%;
  margin: 0;
}

.cup-inspection .secret-watch {
  min-height: 20px;
  padding: 2px 8px;
  border-radius: 3px;
  background: #17261ee6;
  color: #ffe5af;
  font-size: .84rem;
  white-space: nowrap;
}

.cup-actions { display: grid; align-items: stretch; width: 100%; padding: 3px 9px 4px; background: #19281f; }
.cup-actions .button { min-height: 44px; width: 100%; }
.cup-actions .inspect-cup[aria-disabled="true"] { opacity: .86; cursor: progress; }
.cup-idle-label { align-self: center; color: #d4be8e; font-size: .87rem; text-align: center; }
.role-review { margin-block-end: 0 !important; }
.role-review .cup-inspection { --tray-height: 132px; }

.cup-awaiting .inspect-cup-art { animation: cup-rattle 180ms ease-in-out infinite alternate; }

@keyframes cup-rattle {
  from { transform: translate3d(-52%, -2px, 0) rotate(-5deg); }
  to { transform: translate3d(-48%, -3px, 0) rotate(5deg); }
}

@media (prefers-reduced-motion: reduce) {
  .cup-awaiting .inspect-cup-art { animation: none; }
}

html[data-reduce-motion] .cup-awaiting .inspect-cup-art { animation: none; }

.cup-rolling .inspect-cup-art {
  animation: lift-to-roll 1160ms ease-in-out var(--roll-delay) both;
}

.die-travel {
  position: absolute;
  z-index: 3;
  left: calc(50% - var(--model-size) / 2);
  bottom: 22px;
  width: var(--model-size);
  height: var(--model-size);
  transform-style: preserve-3d;
  animation: roll-trajectory 1160ms linear var(--roll-delay) both;
}

.die-travel .tumbling-die {
  position: absolute;
  inset: 0;
  width: var(--model-size);
  height: var(--model-size);
  transform-style: preserve-3d;
  pointer-events: none;
  animation: roll-rotation 1160ms linear var(--roll-delay) both;
}

.die-travel .tumbling-die > .die {
  --half: calc(var(--model-size) / 2);
  position: absolute;
  inset: 0;
  width: var(--model-size);
  height: var(--model-size);
  padding: 4px;
  border-color: #9e723f;
  border-radius: 5px;
  background: radial-gradient(ellipse at 24% 19%, #fff6d8, #dabc83 94%);
  backface-visibility: hidden;
  box-shadow: inset 0 0 5px #ba834a7f;
}

.die-travel .tumbling-die .pip { width: 4px; height: 4px; }
.die-travel .tumbling-die > :nth-child(1) { transform: translateZ(var(--half)); }
.die-travel .tumbling-die > :nth-child(2) { transform: rotateY(90deg) translateZ(var(--half)); filter: brightness(.83); }
.die-travel .tumbling-die > :nth-child(3) { transform: rotateX(-90deg) translateZ(var(--half)); filter: brightness(.99); }
.die-travel .tumbling-die > :nth-child(4) { transform: rotateX(90deg) translateZ(var(--half)); filter: brightness(.92); }
.die-travel .tumbling-die > :nth-child(5) { transform: rotateY(-90deg) translateZ(var(--half)); filter: brightness(.88); }
.die-travel .tumbling-die > :nth-child(6) { transform: rotateY(180deg) translateZ(var(--half)); filter: brightness(.96); }

.die-contact {
  bottom: 15px;
  width: 42px;
  height: 10px;
  animation: roll-contact 1160ms linear var(--roll-delay) both;
}

@keyframes lift-to-roll {
  0%, 100% { transform: translateX(-50%); }
  13%, 75% { transform: translate3d(5px, var(--cup-apex), 0) rotate(18deg); }
  91% { transform: translateX(-50%) rotate(-2deg); }
  96% { transform: translate3d(-50%, 1px, 0) rotate(1deg); }
}

@keyframes roll-trajectory {
  0% { opacity: 0; transform: translate3d(15px,-34px,0); }
  12% { opacity: 1; transform: translate3d(0,var(--die-apex),0); animation-timing-function: cubic-bezier(.3,.03,.8,.37); }
  34% { transform: translate3d(-25px,0,0); animation-timing-function: cubic-bezier(.12,.53,.42,.92); }
  47% { transform: translate3d(-15px,-21px,0); animation-timing-function: cubic-bezier(.46,.06,.89,.57); }
  60% { transform: translate3d(2px,0,0); animation-timing-function: cubic-bezier(.1,.55,.51,.92); }
  69% { transform: translate3d(5px,-8px,0); animation-timing-function: cubic-bezier(.4,.08,.88,.63); }
  79% { transform: translate3d(2px,0,0); }
  86% { opacity: 1; transform: translate3d(0,-1px,0); }
  91%, 100% { opacity: 0; transform: none; }
}

@keyframes roll-rotation {
  0% { transform: rotateX(-24deg) rotateY(24deg) rotateZ(30deg); }
  25% { transform: rotateX(185deg) rotateY(215deg) rotateZ(160deg); }
  48% { transform: rotateX(420deg) rotateY(425deg) rotateZ(282deg); }
  69% { transform: rotateX(calc(600deg + var(--die-x))) rotateY(calc(600deg + var(--die-y))) rotateZ(327deg); }
  83% { transform: rotateX(calc(706deg + var(--die-x))) rotateY(calc(707deg + var(--die-y))) rotateZ(357deg); }
  91%, 100% { transform: rotateX(calc(720deg + var(--die-x))) rotateY(calc(720deg + var(--die-y))) rotateZ(360deg); }
}

@keyframes roll-contact {
  0%, 12% { transform: translateX(-50%) translateX(10px) scale(.55); opacity: .35; }
  34% { transform: translateX(-50%) translateX(-25px) scale(1.08); opacity: .8; }
  47% { transform: translateX(-50%) translateX(-15px) scale(.74); opacity: .48; }
  60% { transform: translateX(-50%) translateX(2px) scale(1.03); opacity: .8; }
  69% { transform: translateX(-50%) translateX(5px) scale(.9); opacity: .6; }
  82% { transform: translateX(-50%) scale(1); opacity: .8; }
  100% { opacity: 0; }
}

@media (min-width: 620px) {
  .roll-workspace { grid-template-columns: minmax(0,1.15fr) minmax(0,.85fr); align-items: stretch; }
  .roll-workspace .secret-card { min-height: 188px; }
  .roll-workspace .cup-inspection { --tray-height: 167px; }
}

@media (max-width: 430px) {
  .roll-workspace .secret-card:not(.is-concealed) .private-toggle {
    position: absolute;
    z-index: 1;
    inset-inline-start: 5px;
    inset-block-end: 5px;
    max-width: calc(33% - 10px);
    padding-inline: 5px;
    border-color: #b29563;
    color: #f9e8c1;
    background: #2a241bd9;
    font-size: .77rem;
    text-align: center;
  }
}

@media (max-width: 360px) {
  .scene-roll, .scene-roll .scene-main { gap: 8px; }
  .roll-workspace .secret-card:not(.is-concealed) .role-copy > .muted { font-size: .92rem; line-height: 1.36; }
}

@media (max-width: 360px) and (max-height: 619px) {
  .scene-roll, .scene-roll .scene-main { gap: 6px; }
  .roll-workspace { gap: 8px; }
  .roll-workspace .secret-card:not(.is-concealed) { min-height: 150px; }
  .roll-workspace .secret-card:not(.is-concealed) .role-copy { padding: 6px 10px; gap: 4px; }
  .roll-workspace .role-copy .secret-role { font-size: 1.5rem; }
  .roll-workspace .cup-inspection {
    --cup-size: 82px;
    --tray-height: 100px;
    --model-size: 34px;
    --cup-apex: -15px;
    --die-apex: -30px;
  }
}

@media (min-width: 600px) and (max-height: 465px) and (orientation: landscape) {
  .scene-roll .round-steps { grid-column: 1; }
  .scene-roll .scene-main { grid-column: 1; gap: 9px; }
  .scene-roll .host-advance-dock { grid-area: auto; }
  .roll-workspace { grid-template-columns: minmax(0,1.15fr) minmax(0,.85fr); }
  .roll-workspace .cup-inspection {
    --tray-height: 71px;
    --cup-size: 60px;
    --model-size: 30px;
    --cup-apex: -12px;
    --die-apex: -26px;
    align-self: start;
  }
  .roll-workspace .secret-card { min-height: 166px; }
}
