/* DICE LINKED website: dice styles. Loaded after site.css. See DESIGN.md.
   Live 3D dice come from /dist/site-dice.js (src/client/siteDice.ts). Every stage keeps
   a static fallback; the canvas fades in over it once the first frame is drawn. */

/* ---------- Shared stage ---------- */

/* Zero specificity: a page's own positioning of a stage always wins. */
:where([data-dice]) { position: relative; }

/* Out of flow, sized to the stage's padding box: the canvas never sizes its container. */
.dice-stage__canvas {
  position: absolute;
  inset: 0;
  z-index: 1;
  display: block;
  width: 100%;
  height: 100%;
  pointer-events: none;
  opacity: 0;
  transition: opacity 600ms var(--ease-out);
}
.is-live > .dice-stage__canvas { opacity: 1; }

/* Fallbacks keep their space and fade out under the live dice. */
:is([data-dice-fallback], .dice-fallback) { transition: opacity 500ms var(--ease-out), visibility 0s 500ms; }
.is-live :is([data-dice-fallback], .dice-fallback),
:is([data-dice="rack"], [data-dice="single"]).is-live:not(:has(:is([data-dice-fallback], .dice-fallback))) > :not([data-dice-result], .dice-stage__canvas, .dice-stage__die, .sr-only) {
  opacity: 0;
  visibility: hidden;
}
/* Page fallbacks drawn in CSS 3D (404, About) leave entirely once the real die is drawn. */
.dice-stage.is-live > .dice-fallback { display: none; }

/* Rack and single: a real button over each die. */
.dice-stage__die {
  position: absolute;
  z-index: 2;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.dice-stage__die:focus-visible { outline: 2px solid var(--brass-hi); outline-offset: 2px; border-radius: 50%; }

/* ---------- Home: the vitrine ---------- */

.case.is-live .specimen img { opacity: 0; animation: none; transition: opacity 600ms var(--ease-out); }
.specimen__spin {
  position: absolute;
  z-index: 2;
  top: 0;
  left: 50%;
  width: min(100%, 9.5rem);
  aspect-ratio: 1;
  translate: -50% 0;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: none;
  cursor: grab;
  touch-action: pan-y; /* sideways drags turn the die, vertical ones scroll the page */
  -webkit-tap-highlight-color: transparent;
}
.specimen__spin:active { cursor: grabbing; }
.specimen__spin:focus-visible { outline: 2px solid var(--brass-hi); outline-offset: 2px; border-radius: 50%; }

/* ---------- Home: the set drawer ---------- */

.dice-stage--set { max-width: 40rem; }
.dice-stage__well { display: grid; place-items: center; aspect-ratio: 5 / 2.45; }
@media (min-width: 560px) { .dice-stage__well { aspect-ratio: 9 / 1.4; } }
.dice-stage__well .dice-set { justify-content: center; }
.dice-stage__plate { margin-top: 0.5rem; transform: rotate(-1.5deg); visibility: hidden; }
.dice-stage--set.is-live .dice-stage__plate { visibility: visible; }
.dice-stage__plate span { min-width: 7.5rem; }
.dice-stage__plate.is-turning { animation: plate-turn 520ms var(--ease-out); }
@keyframes plate-turn {
  from { opacity: 0.25; transform: rotate(-1.5deg) translateY(3px); }
  to { opacity: 1; transform: rotate(-1.5deg); }
}
.dice-stage__hit {
  position: absolute;
  z-index: 2;
  inset: 0;
  padding: 0;
  border: 0;
  border-radius: 1rem;
  background: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.dice-stage__hit:focus-visible { outline: 2px solid var(--brass-hi); outline-offset: 4px; }
.dice-stage--set:not(.is-live) .dice-stage__hit { display: none; }

/* ---------- Home: the exploding dice drawer ---------- */

/* Headroom above the row for the drop, room below for the engraved tags. */
.explode { max-width: 40rem; padding: 2.6rem 0 1.7rem; }
.drawer > .explode { margin-top: 0.2rem; }
.explode__row { display: flex; flex-wrap: wrap; align-items: center; gap: clamp(0.3rem, 1.5vw, 0.75rem); font-family: var(--font-display); }
.explode__slot {
  position: relative;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  width: clamp(2.8rem, 15vw, 4.6rem);
  aspect-ratio: 1;
}
/* Static fallback: flat ivory dice, brass for the ones that exploded. */
.explode__slot b {
  position: relative;
  z-index: 1;
  display: grid;
  place-items: center;
  width: 74%;
  aspect-ratio: 1;
  border-radius: 0.6rem;
  background: radial-gradient(circle at 30% 25%, #fffaf0, #efe4c9 55%, #d3bf8e 100%);
  color: #2a2110;
  font-size: 1.45rem;
  font-weight: 800;
  box-shadow: 0 8px 8px -4px rgba(0, 0, 0, 0.6);
  transition: opacity 400ms var(--ease-out);
}
.explode__slot.is-hot b { background: radial-gradient(circle at 30% 25%, #fff2c9, #e0b561 55%, #a67a2c 100%); }
/* An exploding die lands in a brass ring set into the felt. */
.explode__slot::before {
  content: '';
  position: absolute;
  left: -2%;
  right: -2%;
  bottom: -2%;
  height: 34%;
  border-radius: 50%;
  border: 1.5px solid rgba(244, 216, 156, 0.85);
  background: radial-gradient(closest-side, rgba(244, 216, 156, 0.26), rgba(220, 176, 94, 0.07) 72%, transparent);
  box-shadow: inset 0 1px 0 rgba(255, 244, 214, 0.35), 0 6px 10px -6px rgba(0, 0, 0, 0.8);
  opacity: 0;
  transform: scale(0.55);
}
.explode__slot.is-hot::before { opacity: 1; transform: none; }
.explode__tag {
  position: absolute;
  top: calc(100% + 0.55rem);
  left: 50%;
  translate: -50% 0;
  color: var(--brass-hi);
  font-family: var(--font-engrave);
  font-size: 0.56rem;
  font-weight: 700;
  letter-spacing: 0.16em;
  line-height: 1;
  text-transform: uppercase;
  white-space: nowrap;
}
.explode__op { flex: 0 0 auto; font-style: normal; font-size: 1.3rem; font-weight: 600; color: var(--brass); }
.explode__total { margin-left: 0.25rem; font-size: clamp(2.35rem, 7vw, 2.9rem); font-weight: 800; line-height: 1; color: var(--brass-hi); letter-spacing: -0.04em; font-variant-numeric: tabular-nums; }

/* Live: the canvas draws the dice; ring, tag, operators and total follow the throw. */
.explode.is-live .explode__slot b { opacity: 0; }
.explode.is-live .explode__slot::before { opacity: 0; transform: scale(0.55); transition: opacity 300ms var(--ease-out), transform 300ms var(--ease-out); }
.explode.is-live .explode__slot.is-hot.is-on::before { opacity: 1; transform: none; transition: opacity 180ms var(--ease-out), transform 520ms var(--ease-land); }
.explode.is-live :is(.explode__tag, .explode__op, .explode__total) { opacity: 0; transition: opacity 300ms var(--ease-out); }
.explode.is-live .explode__slot.is-on .explode__tag,
.explode.is-live :is(.explode__op, .explode__total).is-on { opacity: 1; }
.explode.is-live .explode__slot:not(.is-hot) .explode__tag { display: none; }

/* ---------- Toss: live dice around a phone (home hero, landers, About) ---------- */

/* Above the phone, under the roll tag and nameplate. */
[data-dice="toss"] > .dice-stage__canvas { z-index: 4; }
[data-dice="toss"].is-live { cursor: pointer; -webkit-tap-highlight-color: transparent; }
[data-dice="toss"].is-live > .toss { animation: none; opacity: 0; visibility: hidden; transition: opacity 500ms var(--ease-out), visibility 0s 500ms; }

/* ---------- Sync: the same die on three screens ---------- */

.sync-viz > .dice-stage__canvas { z-index: 3; }

@media (prefers-reduced-motion: reduce) {
  .dice-stage__canvas, :is([data-dice-fallback], .dice-fallback), .case.is-live .specimen img, [data-dice="toss"].is-live > .toss { transition: none; }
  .dice-stage__plate.is-turning { animation: none; }
}
