/* Dice 10k — dice, tray and kept-rail styles.
 * Tailwind utilities come from the Play CDN; this file adds the things
 * Tailwind doesn't provide: pip layouts, the felt tray, the kept rail
 * and the roll-in animation.
 */

/* --- Die ----------------------------------------------------------------- */

.die {
  position: relative;
  width: 4rem;
  height: 4rem;
  border-radius: 0.9rem;
  background: linear-gradient(145deg, #ffffff 0%, #e2e8f0 55%, #cbd5e1 100%);
  box-shadow:
    inset 0 -3px 6px rgba(15, 23, 42, 0.22),
    inset 0 2px 3px rgba(255, 255, 255, 0.9),
    0 6px 14px rgba(0, 0, 0, 0.45);
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  padding: 0.55rem;
  gap: 0.15rem;
  transform: rotate(var(--rot, 0deg));
  transition: transform 0.15s ease-out, box-shadow 0.15s ease-out;
}

/* Gloss highlight. */
.die::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: linear-gradient(155deg, rgba(255, 255, 255, 0.65) 0%, rgba(255, 255, 255, 0) 42%);
  pointer-events: none;
}

.die .pip {
  width: 0.6rem;
  height: 0.6rem;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #334155, #0f172a 70%);
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.6);
  align-self: center;
  justify-self: center;
  opacity: 0;
  transition: opacity 0.15s;
}

/* The ace is the money die — paint it red. */
.face-1 .pip { background: radial-gradient(circle at 35% 30%, #f87171, #b91c1c 70%); }

.face-1 .p5 { opacity: 1; }
.face-2 .p1 { opacity: 1; } .face-2 .p9 { opacity: 1; }
.face-3 .p1 { opacity: 1; } .face-3 .p5 { opacity: 1; } .face-3 .p9 { opacity: 1; }
.face-4 .p1 { opacity: 1; } .face-4 .p3 { opacity: 1; } .face-4 .p7 { opacity: 1; } .face-4 .p9 { opacity: 1; }
.face-5 .p1 { opacity: 1; } .face-5 .p3 { opacity: 1; } .face-5 .p5 { opacity: 1; } .face-5 .p7 { opacity: 1; } .face-5 .p9 { opacity: 1; }
.face-6 .p1 { opacity: 1; } .face-6 .p3 { opacity: 1; } .face-6 .p4 { opacity: 1; } .face-6 .p6 { opacity: 1; } .face-6 .p7 { opacity: 1; } .face-6 .p9 { opacity: 1; }

/* Pip grid: 3x3 with named positions */
.die .p1 { grid-area: 1 / 1; }
.die .p2 { grid-area: 1 / 2; }
.die .p3 { grid-area: 1 / 3; }
.die .p4 { grid-area: 2 / 1; }
.die .p5 { grid-area: 2 / 2; }
.die .p6 { grid-area: 2 / 3; }
.die .p7 { grid-area: 3 / 1; }
.die .p8 { grid-area: 3 / 2; }
.die .p9 { grid-area: 3 / 3; }

@media (min-width: 640px) {
  .die { width: 4.6rem; height: 4.6rem; }
  .die .pip { width: 0.7rem; height: 0.7rem; }
}

/* --- Play area: kept rail on the left, tray on the right ------------------ */

.play-area {
  display: flex;
  gap: 0.9rem;
  align-items: stretch;
}

/* Kept rail — picked dice line up here, top to bottom. */
.dice-rail {
  flex: 0 0 auto;
  width: 6rem;
  display: flex;
  flex-direction: column;
  border-radius: 1.25rem;
  border: 1px dashed rgba(148, 163, 184, 0.35);
  background: rgba(2, 6, 23, 0.55);
  box-shadow: inset 0 2px 12px rgba(0, 0, 0, 0.5);
  padding: 0.6rem 0.45rem;
}

.rail-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 0.2rem 0.5rem;
}

.rail-title {
  font-size: 0.62rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: #94a3b8;
}

.rail-count {
  min-width: 1.4rem;
  text-align: center;
  font-size: 0.72rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: #0f172a;
  background: #38bdf8;
  border-radius: 9999px;
  padding: 0.05rem 0.35rem;
}

.rail-stack {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.55rem;
  overflow-y: auto;
  padding: 0.15rem;
}

.rail-hint {
  padding-top: 0.5rem;
  text-align: center;
  font-size: 0.62rem;
  line-height: 1.25;
  color: #64748b;
}

/* Dice in the rail are smaller and straightened. */
.dice-rail .die {
  width: 3.3rem;
  height: 3.3rem;
  padding: 0.45rem;
  border-radius: 0.7rem;
  transform: rotate(0deg);
}
.dice-rail .die .pip { width: 0.48rem; height: 0.48rem; }

/* A die label that has been moved into the rail flows in the column. */
.die-label { display: block; cursor: pointer; }
.die-label.in-rail { position: static; transform: none; }

.kept-die { animation: kept-in 0.35s ease-out backwards; }
@keyframes kept-in {
  from { transform: scale(0.4); opacity: 0; }
}

/* --- Tray ------------------------------------------------------------------ */

.dice-tray {
  position: relative;
  flex: 1 1 auto;
  min-width: 0;
  height: clamp(280px, 46vh, 430px);
  border-radius: 1.5rem;
  background:
    radial-gradient(120% 90% at 50% 28%, rgba(74, 222, 128, 0.18), rgba(0, 0, 0, 0) 55%),
    radial-gradient(100% 100% at 50% 50%, #166534 0%, #14532d 55%, #052e16 100%);
  box-shadow:
    inset 0 2px 18px rgba(0, 0, 0, 0.55),
    inset 0 0 60px rgba(0, 0, 0, 0.35),
    0 0 0 6px #78350f,
    0 0 0 8px #451a03,
    0 18px 36px rgba(0, 0, 0, 0.45);
}

/* Felt fibre. */
.dice-tray::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  pointer-events: none;
  background-image: repeating-linear-gradient(45deg, rgba(255, 255, 255, 0.018) 0 2px, transparent 2px 4px);
}

/* Idle tray (waiting for a roll) centres its call-to-action. */
.dice-tray-idle {
  display: flex;
  align-items: center;
  justify-content: center;
}
.tray-cta { text-align: center; }

/* Dice rest scattered over the felt; left/top are the die's centre. */
.dice-tray .die-label {
  position: absolute;
  transform: translate(-50%, -50%);
  z-index: 1;
}

/* Lift on hover to show it's clickable. */
.dice-tray .die-label:hover .die {
  transform: rotate(var(--rot, 0deg)) translateY(-4px) scale(1.04);
  box-shadow:
    inset 0 -3px 6px rgba(15, 23, 42, 0.22),
    inset 0 2px 3px rgba(255, 255, 255, 0.9),
    0 12px 22px rgba(0, 0, 0, 0.55);
}

/* --- Roll-in animation ------------------------------------------------------ */

.dice-tray .die-label .die {
  animation: dice-in 0.6s cubic-bezier(0.2, 0.85, 0.3, 1.15) backwards;
}

/* No 100% keyframe on purpose: the die settles into its natural computed
 * style, i.e. the random resting rotation set inline via --rot. */
@keyframes dice-in {
  0% {
    transform: translateY(-240px) rotate(var(--spin, -540deg)) scale(0.8);
    opacity: 0;
  }
  55% { opacity: 1; }
  80% {
    transform: translateY(10px) rotate(var(--rot, 0deg)) scale(1.03);
  }
}

@media (prefers-reduced-motion: reduce) {
  .dice-tray .die-label .die,
  .dice-tray .bust-die .die,
  .kept-die { animation: none; }
}

/* --- Bust reveal -------------------------------------------------------------- */

.bust-wrap { position: relative; }

/* Busted dice rest in the tray like a normal throw... */
.dice-tray .bust-die {
  position: absolute;
  transform: translate(-50%, -50%);
  z-index: 1;
}
.dice-tray .bust-die .die {
  animation: dice-in 0.6s cubic-bezier(0.2, 0.85, 0.3, 1.15) backwards;
}

/* ...but they look dead. */
.bust-normal .bust-die .die { filter: grayscale(0.8) brightness(0.72); }
.bust-severe .bust-die .die {
  filter: brightness(0.82) sepia(0.55) hue-rotate(-48deg) saturate(2.4);
}

/* The overlay holds the drama for 3s, then melts away to reveal the
 * busted throw and the next player's roll button. */
.bust-overlay {
  position: absolute;
  inset: -0.35rem;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 1.5rem;
  animation: bust-overlay 3s ease forwards;
}

@keyframes bust-overlay {
  0%, 80% { opacity: 1; visibility: visible; }
  100%    { opacity: 0; visibility: hidden; pointer-events: none; }
}

.bust-card {
  text-align: center;
  animation: bust-stamp 0.5s cubic-bezier(0.2, 1.4, 0.4, 1) 0.45s backwards;
}

/* Rubber-stamp entrance, delayed until the dice have landed. */
@keyframes bust-stamp {
  0%   { transform: scale(2.6) rotate(-14deg); opacity: 0; }
  60%  { transform: scale(0.94) rotate(2deg);  opacity: 1; }
  100% { transform: scale(1) rotate(-2deg); }
}

.bust-title {
  display: inline-block;
  font-size: clamp(2.2rem, 6vw, 4rem);
  font-weight: 900;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  border: 0.32rem solid currentColor;
  border-radius: 0.9rem;
  padding: 0.05em 0.4em;
  transform: rotate(-2deg);
}

.bust-amount {
  margin-top: 0.6rem;
  font-size: clamp(2.4rem, 7vw, 4.2rem);
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  animation: bust-amount-in 0.45s ease-out 0.75s backwards, bust-amount-pulse 0.9s ease-in-out 1.25s 2;
}

@keyframes bust-amount-in {
  from { transform: translateY(1.5rem); opacity: 0; }
}

@keyframes bust-amount-pulse {
  50% { transform: scale(1.14); }
}

.bust-sub {
  margin-top: 0.7rem;
  font-size: 0.95rem;
  font-weight: 600;
  animation: bust-amount-in 0.45s ease-out 0.95s backwards;
}

/* -- Variant: normal bust (<6 dice, 0 points) — cold and grey, dice sink. */
.bust-normal .bust-overlay {
  background: rgba(2, 6, 23, 0.78);
  backdrop-filter: blur(2px);
}
.bust-normal .bust-title { color: #94a3b8; text-shadow: 0 4px 14px rgba(0, 0, 0, 0.6); }
.bust-normal .bust-amount { color: #cbd5e1; }
.bust-normal .bust-sub { color: #94a3b8; }
.bust-normal .bust-tray { animation: bust-sink 0.7s ease-in-out 0.5s; }

@keyframes bust-sink {
  0%, 100% { transform: translateY(0); }
  40%      { transform: translateY(10px); }
  70%      { transform: translateY(4px); }
}

/* -- Variant: severe bust, -1,000 — red stamp, tray rattles once. */
.bust-severe .bust-overlay {
  background: radial-gradient(90% 90% at 50% 45%, rgba(127, 29, 29, 0.82), rgba(2, 6, 23, 0.92));
}
.bust-severe .bust-title {
  color: #f87171;
  text-shadow: 0 0 26px rgba(239, 68, 68, 0.65), 0 4px 0 rgba(0, 0, 0, 0.4);
}
.bust-severe .bust-amount {
  color: #ef4444;
  text-shadow: 0 0 30px rgba(239, 68, 68, 0.55);
}
.bust-severe .bust-sub { color: #fca5a5; }
.bust-severe .bust-tray { animation: bust-rattle 0.55s linear 0.5s; }

@keyframes bust-rattle {
  0%, 100% { transform: translate(0, 0) rotate(0deg); }
  15%      { transform: translate(-9px, 4px) rotate(-0.6deg); }
  30%      { transform: translate(8px, -5px) rotate(0.5deg); }
  45%      { transform: translate(-7px, -4px) rotate(-0.5deg); }
  60%      { transform: translate(6px, 5px) rotate(0.4deg); }
  75%      { transform: translate(-4px, 2px) rotate(-0.3deg); }
  90%      { transform: translate(3px, -2px) rotate(0.2deg); }
}

/* -- Variant: severe bust, -2,000 — double rattle, angrier glow, screen flash. */
.bust-extreme .bust-tray { animation: bust-rattle 0.55s linear 0.45s 2; }
.bust-extreme .bust-overlay {
  background: radial-gradient(90% 90% at 50% 45%, rgba(153, 27, 27, 0.88), rgba(24, 4, 4, 0.95));
  animation: bust-overlay 3s ease forwards, bust-flash 0.28s linear 0.5s 3;
}
.bust-extreme .bust-title {
  color: #fbbf24;
  text-shadow: 0 0 32px rgba(245, 158, 11, 0.8), 0 4px 0 rgba(0, 0, 0, 0.45);
}
.bust-extreme .bust-amount {
  color: #fb923c;
  text-shadow: 0 0 38px rgba(249, 115, 22, 0.75);
}
.bust-extreme .bust-sub { color: #fdba74; }

@keyframes bust-flash {
  0%, 100% { box-shadow: inset 0 0 0 rgba(248, 113, 113, 0); }
  50%      { box-shadow: inset 0 0 90px rgba(248, 113, 113, 0.55); }
}

@media (prefers-reduced-motion: reduce) {
  /* Skip the movement, keep the message: the overlay still holds for
   * 3s (opacity-only fade) so the result is readable. */
  .bust-tray,
  .bust-card,
  .bust-amount,
  .bust-sub,
  .dice-tray .bust-die .die { animation: none !important; }
}

/* --- Buttons ---------------------------------------------------------------- */

.roll-btn {
  display: inline-block;
  font-weight: 700;
  font-size: 1.05rem;
  color: #f0f9ff;
  border-radius: 0.9rem;
  padding: 0.8rem 1.6rem;
  background: linear-gradient(180deg, #38bdf8 0%, #0284c7 100%);
  box-shadow:
    0 10px 24px rgba(2, 132, 199, 0.35),
    inset 0 1px 0 rgba(255, 255, 255, 0.35);
  transition: transform 0.12s ease-out, box-shadow 0.12s ease-out, filter 0.12s ease-out;
}
.roll-btn:hover {
  transform: translateY(-2px);
  filter: brightness(1.08);
  box-shadow:
    0 14px 28px rgba(2, 132, 199, 0.45),
    inset 0 1px 0 rgba(255, 255, 255, 0.35);
}
.roll-btn:active { transform: translateY(0); }

/* Stat chips above the tray. */
.stat-chip {
  background: rgba(2, 6, 23, 0.45);
  border: 1px solid rgba(148, 163, 184, 0.15);
  border-radius: 0.9rem;
  padding: 0.55rem 1rem;
}
