/* Dice on the table: the dice night of a made-up board game bar. A felt table seen from above, with a walnut rail;
   two ivory dice are thrown from a leather cup, roll, knock into each other and into the rail, and settle. */
:root {
  --page: #15110e;          /* the bar, around the table */
  --page-glow: #2a1f17;     /* the warm lamp over the table */
  --ink: #f3e9d6;           /* the words */
  --muted: #b9a88f;         /* the small words */
  --brass: #e0a94a;         /* the sum and the button */
  --brass-ink: #1d140c;
  --felt: #1e5745;          /* the cloth */
  --felt-dark: #123a2e;
  --walnut: #5b3420;        /* the rail */
  --walnut-light: #8a5634;
  --ivory: #f4ecdc;         /* the dice */
  --ivory-shade: #d8cbb2;
  --pip: #1c1612;           /* the pips */
  --pip-one: #b4242c;       /* the single pip */
  --leather: #8c4b25;       /* the cup */
  --leather-light: #b46a37;
  --leather-dark: #5e2f15;
  --leather-deep: #3f1e0c;
  --stitch: #ecd9b4;
  --s: 56px;                /* a die (the script sets it) */
  --w: 780px;               /* the felt (the script sets it) */
  --d: 470px;
  --rail: 30px;
  --wall: 20px;
  --tilt: 48deg;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  overflow-x: clip;
}

body {
  min-height: 100svh;
  background:
    radial-gradient(70% 60% at 62% 48%, var(--page-glow), transparent 75%),
    var(--page);
  color: var(--ink);
  font-family: 'Instrument Sans Variable', system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.sr {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.stage {
  min-height: 100svh;
  display: grid;
  grid-template-columns: minmax(250px, 330px) minmax(0, 1fr);
  gap: clamp(16px, 3vw, 48px);
  align-items: center;
  padding: clamp(20px, 4vh, 44px) clamp(16px, 4vw, 56px);
}

/* ---------------------------------------------------------------- the left column */
.side {
  display: grid;
  gap: clamp(22px, 5vh, 48px);
  align-content: center;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand__mark {
  width: 38px;
  height: 38px;
  flex: none;
}

.brand__mark rect {
  fill: var(--ivory);
}

.brand__mark circle {
  fill: var(--pip);
}

.brand__mark circle:nth-of-type(2) {
  fill: var(--pip-one);
}

.brand__name {
  margin: 0;
  font-family: 'Fraunces Variable', Georgia, serif;
  font-size: 21px;
  font-weight: 600;
  font-variation-settings: 'SOFT' 100, 'opsz' 24;
  line-height: 1.05;
}

.brand__name span {
  display: block;
  margin-top: 3px;
  font-family: 'Instrument Sans Variable', system-ui, sans-serif;
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.score {
  display: grid;
  min-height: clamp(150px, 26vh, 230px);
  align-items: center;
}

.score__intro,
.score__result {
  grid-area: 1 / 1;
}

.score__kicker {
  margin: 0 0 8px;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--brass);
}

.score__title {
  margin: 0;
  font-family: 'Fraunces Variable', Georgia, serif;
  font-size: clamp(34px, 4.2vw, 54px);
  font-weight: 560;
  font-variation-settings: 'SOFT' 100, 'opsz' 72, 'WONK' 1;
  line-height: 0.98;
  letter-spacing: -0.02em;
  text-wrap: balance;
}

.score__result {
  visibility: hidden;
}

.score__sum {
  margin: 0;
  font-family: 'Fraunces Variable', Georgia, serif;
  font-size: clamp(96px, 13vw, 168px);
  font-weight: 700;
  font-variation-settings: 'SOFT' 100, 'opsz' 144, 'WONK' 1;
  line-height: 0.8;
  letter-spacing: -0.05em;
  color: var(--ink);
}

.score__sum span {
  display: inline-block;
  transform-origin: 30% 90%;
}

.score__parts {
  margin: 10px 0 0;
  font-size: 15px;
  font-weight: 500;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.actions {
  display: grid;
  gap: 14px;
  justify-items: start;
}

.rule {
  margin: 0;
  font-size: 13px;
  color: var(--muted);
}

/* the button: the label widens and the brass swells with a bounce */
.roll {
  position: relative;
  display: inline-grid;
  place-items: center;
  height: 54px;
  padding: 0 30px;
  border: 0;
  border-radius: 999px;
  background: none;
  color: var(--brass-ink);
  font: inherit;
  font-size: 16px;
  font-weight: 650;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.roll__fill {
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: linear-gradient(180deg, #f0c36f, var(--brass));
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.18), 0 10px 26px -10px rgba(224, 169, 74, 0.6);
  transition: transform 0.55s cubic-bezier(0.34, 1.8, 0.5, 1);
}

.roll__label {
  position: relative;
  font-stretch: 88%;
  transition: font-stretch 0.45s cubic-bezier(0.34, 1.6, 0.5, 1), letter-spacing 0.45s cubic-bezier(0.34, 1.6, 0.5, 1);
}

.roll:active .roll__fill {
  transform: scale(0.94, 0.88);
  transition-duration: 0.12s;
}

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

@media (hover: hover) {
  .roll:hover .roll__fill {
    transform: scale(1.07, 1.12);
  }

  .roll:hover .roll__label {
    font-stretch: 100%;
    letter-spacing: 0.01em;
  }
}

.roll[aria-busy='true'] {
  cursor: progress;
}

/* ---------------------------------------------------------------- the table */
.scene {
  position: relative;
  height: min(86svh, 720px);
  min-height: 340px;
  display: grid;
  place-items: center;
  perspective: 1500px;
  perspective-origin: 50% 30%;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.jolt {
  transform-style: preserve-3d;
}

.table {
  position: relative;
  width: var(--w);
  height: var(--d);
  transform: translateY(calc(var(--s) * 0.9)) rotateX(var(--tilt));
  transform-style: preserve-3d;
}

.rail {
  position: absolute;
  inset: calc(var(--rail) * -1);
  border: var(--rail) solid var(--walnut);
  border-radius: calc(var(--rail) * 0.9);
  transform: translateZ(var(--wall));
  transform-style: preserve-3d;
  box-shadow:
    inset 0 0 0 1px rgba(255, 220, 180, 0.12),
    inset 0 calc(var(--rail) * 0.25) calc(var(--rail) * 0.4) rgba(255, 210, 170, 0.12),
    0 0 0 1px rgba(0, 0, 0, 0.4);
}

/* the rail is wood all round: a gradient on the border itself */
.rail::before {
  content: '';
  position: absolute;
  inset: calc(var(--rail) * -1);
  border-radius: inherit;
  padding: var(--rail);
  background:
    repeating-linear-gradient(100deg, rgba(0, 0, 0, 0.12) 0 2px, transparent 2px 9px),
    linear-gradient(160deg, var(--walnut-light), var(--walnut) 40%, #3e2213);
  -webkit-mask: linear-gradient(#000 0 0) content-box exclude, linear-gradient(#000 0 0);
  mask: linear-gradient(#000 0 0) content-box exclude, linear-gradient(#000 0 0);
}

.rail::after {
  /* the base under the rail, a dark lip to the bar */
  content: '';
  position: absolute;
  inset: calc(var(--rail) * -1.12);
  border-radius: calc(var(--rail) * 1.1);
  transform: translateZ(calc(var(--wall) * -1 - 1px));
  box-shadow: 0 0 calc(var(--rail) * 0.8) calc(var(--rail) * 0.2) rgba(0, 0, 0, 0.55);
}

.felt {
  position: absolute;
  inset: 0;
  overflow: hidden;
  background:
    radial-gradient(80% 90% at 45% 40%, rgba(255, 255, 255, 0.07), transparent 70%),
    repeating-linear-gradient(45deg, rgba(0, 0, 0, 0.05) 0 1px, transparent 1px 3px),
    linear-gradient(var(--felt), var(--felt-dark));
  box-shadow: inset 0 0 calc(var(--s) * 0.9) rgba(0, 0, 0, 0.45);
}

.felt__print {
  position: absolute;
  left: 50%;
  top: 50%;
  translate: -50% -50%;
  font-family: 'Fraunces Variable', Georgia, serif;
  font-size: calc(var(--s) * 1.25);
  font-weight: 600;
  font-variation-settings: 'SOFT' 100, 'opsz' 96;
  white-space: nowrap;
  color: rgba(255, 255, 255, 0.07);
  letter-spacing: -0.01em;
}

/* the cushions of the rail, standing up round the cloth */
.wall {
  position: absolute;
  background: linear-gradient(var(--felt-dark), #0c2a21);
}

.wall--back {
  left: 0;
  top: 0;
  width: 100%;
  height: var(--wall);
  transform-origin: 50% 0;
  transform: rotateX(90deg);
  background: linear-gradient(#0b271f, var(--felt-dark));
}

.wall--front {
  left: 0;
  bottom: 0;
  width: 100%;
  height: var(--wall);
  transform-origin: 50% 100%;
  transform: rotateX(-90deg);
}

/* ---------------------------------------------------------------- the dice */
.shadow {
  position: absolute;
  left: 0;
  top: 0;
  width: calc(var(--s) * 1.3);
  height: calc(var(--s) * 1.3);
  border-radius: 30%;
  background: radial-gradient(closest-side, rgba(0, 0, 0, 0.62), rgba(0, 0, 0, 0.42) 45%, rgba(0, 0, 0, 0.14) 75%, transparent);
  opacity: 0;
  pointer-events: none;
}

.die {
  position: absolute;
  left: 0;
  top: 0;
  width: var(--s);
  height: var(--s);
  transform-style: preserve-3d;
  pointer-events: none;
  --vis: 0;
}

/* the die fades face by face: an opacity on the box itself would flatten it */
.die > * {
  opacity: var(--vis);
}

.die__core {
  position: absolute;
  inset: 1px;
  background: var(--ivory-shade);
  border-radius: 12%;
}

.die__core--y {
  transform: rotateX(90deg);
}

.die__core--x {
  transform: rotateY(90deg);
}

.face {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template: repeat(3, 1fr) / repeat(3, 1fr);
  padding: 15%;
  border-radius: 19%;
  background:
    radial-gradient(120% 120% at 30% 25%, #fffaf0, var(--ivory) 55%, var(--ivory-shade));
  box-shadow: inset 0 0 calc(var(--s) * 0.07) rgba(120, 95, 60, 0.35);
  backface-visibility: hidden;
}

.face::after {
  /* how much light the face catches: the script sets --dim */
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: #2b1d10;
  opacity: var(--dim, 0);
}

.face--1 { transform: translateZ(calc(var(--s) / 2)); }
.face--6 { transform: rotateY(180deg) translateZ(calc(var(--s) / 2)); }
.face--3 { transform: rotateY(90deg) translateZ(calc(var(--s) / 2)); }
.face--4 { transform: rotateY(-90deg) translateZ(calc(var(--s) / 2)); }
.face--2 { transform: rotateX(90deg) translateZ(calc(var(--s) / 2)); }
.face--5 { transform: rotateX(-90deg) translateZ(calc(var(--s) / 2)); }

.pip {
  width: 64%;
  height: 64%;
  place-self: center;
  border-radius: 50%;
  background: radial-gradient(circle at 50% 60%, #000, var(--pip) 70%);
  box-shadow:
    inset 0 calc(var(--s) * 0.022) calc(var(--s) * 0.02) rgba(0, 0, 0, 0.9),
    0 calc(var(--s) * 0.012) 0 rgba(255, 255, 255, 0.7);
}

.face--1 .pip {
  width: 112%;
  height: 112%;
  background: radial-gradient(circle at 50% 60%, #6d0f15, var(--pip-one) 70%);
}

/* ---------------------------------------------------------------- the cup */
/* the cup is drawn flat over the scene, not inside the 3D table (Chrome sorts a plane that crosses the table
   badly and cuts it): two invisible anchors in the table say where its foot is on screen and how big it is there */
.anchor {
  position: absolute;
  left: 0;
  top: 0;
  width: 0;
  height: 0;
}

.cup-place {
  position: absolute;
  left: 0;
  top: 0;
  width: calc(var(--s) * 2.3);
  height: calc(var(--s) * 2.85);
  transform-origin: 50% 100%;
  pointer-events: none;
}

.cup {
  width: 100%;
  height: 100%;
  transform-origin: 88% 96%;
}

.cup svg {
  display: block;
  width: 100%;
  height: 100%;
  overflow: visible;
}

.cup__stitch {
  fill: none;
  stroke: var(--stitch);
  stroke-width: 1.4;
  stroke-linecap: round;
  stroke-dasharray: 2.6 3.4;
  opacity: 0.85;
}

.cup__seam {
  fill: none;
  stroke: var(--leather-deep);
  stroke-width: 2.4;
  opacity: 0.7;
}

.cup__crest rect {
  fill: none;
  stroke: var(--leather-deep);
  stroke-width: 2.2;
  opacity: 0.75;
}

.cup__crest circle {
  fill: var(--leather-deep);
  opacity: 0.75;
}

.cup__rim {
  fill: none;
  stroke: var(--leather-light);
  stroke-width: 4;
}

.cup__shine {
  fill: none;
  stroke: rgba(255, 230, 200, 0.22);
  stroke-width: 5;
  stroke-linecap: round;
}

.hint {
  position: absolute;
  left: 50%;
  bottom: 0;
  margin: 0;
  translate: -50% 0;
  font-size: 13px;
  color: var(--muted);
  white-space: nowrap;
  pointer-events: none;
}

/* ---------------------------------------------------------------- phone */
@media (max-width: 760px) {
  .stage {
    grid-template-columns: minmax(0, 1fr);
    align-content: center;
    gap: 6px;
    padding: 22px 16px 26px;
  }

  .side {
    display: contents;
  }

  .brand { order: 1; }
  .score { order: 2; margin-top: 14px; }
  .scene { order: 3; }

  .score {
    min-height: 128px;
  }

  .score__title {
    font-size: 38px;
  }

  .score__sum {
    font-size: 104px;
  }

  .actions {
    order: 4;
    justify-items: center;
    text-align: center;
  }

  .scene {
    height: auto;
    aspect-ratio: 0.86;
    min-height: 0;
    perspective: 1100px;
  }

  .hint {
    display: none;
  }
}

/* il telefono basso (la casella dell'anteprima, 341 per 410): la scena appena più alta che larga (il tavolo resta per
   lungo e grande uguale, perché lo limita la larghezza) e i titoli più piccoli, perché tavolo e pulsante stiano
   insieme nella casella; lo script misura il tavolo sulla scena */
@media (max-width: 760px) and (max-height: 720px) {
  .stage {
    gap: 6px;
    padding: 12px 16px 14px;
  }

  .score {
    min-height: 112px;
    margin-top: 8px;
  }

  .score__title {
    font-size: 32px;
  }

  .score__sum {
    font-size: 84px;
  }

  .scene {
    aspect-ratio: 0.97;
  }

  .actions {
    gap: 10px;
  }

  .roll {
    height: 48px;
  }
}
