#diceModal [hidden] { display: none !important; }
#diceModal { padding: max(12px, env(safe-area-inset-top, 0px)) 12px max(12px, env(safe-area-inset-bottom, 0px)); }
#diceModal .dice-panel { display: flex; flex-direction: column; width: 100%; max-width: 600px; max-height: calc(100vh - 48px); max-height: calc(100dvh - 48px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px)); padding: 0; margin: 12px auto; overflow: hidden; animation: none; transform: none; }
#diceModal .modal-header { flex: 0 0 auto; position: static; margin: 0; padding: 16px 20px; gap: 16px; }
#diceModal .modal-header h2 { font-size: 21px; line-height: 1.4; }
#dice-close { width: 44px; height: 44px; flex: 0 0 44px; padding: 0; background: #21373b; }
.dice-content { min-height: 0; padding: 20px; overflow-y: auto; overscroll-behavior: contain; scrollbar-width: thin; }
.dice-play-modes { display: flex; align-items: stretch; gap: 5px; padding: 4px; border: 1px solid #48605f; border-radius: 10px; background: #12262d; }
.dice-play-modes > span, .dice-play-modes > button { display: flex; align-items: center; justify-content: center; flex: 1; min-height: 44px; gap: 9px; padding: 8px 10px; border-radius: 7px; font-size: 12px; line-height: 1.5; text-align: center; word-break: keep-all; }
.dice-play-modes .is-current { color: #392c23; background: #f4bd95; font-weight: 700; }
.dice-play-modes button { color: #c8d9d2; }
.dice-play-modes button:hover { background: #2b4248; }
.dice-play-modes button span:last-child { font-size: 18px; }
.dice-intro { margin: 17px 0 20px; color: #b7c8c3; font-size: 13px; line-height: 1.8; word-break: keep-all; }
.dice-settings { display: grid; grid-template-columns: 1fr 1fr; gap: 16px 12px; }
.dice-field { min-width: 0; }
.dice-field label { display: block; margin-bottom: 7px; color: #deeadf; font-size: 12px; font-weight: 600; }
.dice-rule-field { grid-column: 1 / -1; }
#diceModal select, #diceModal input { display: block; width: 100%; min-width: 0; min-height: 46px; padding: 10px 12px; border: 1px solid #4a6264; border-radius: 8px; background: #11262d; color: #f0f3e9; font: inherit; font-size: 16px; box-shadow: none; color-scheme: dark; }
#diceModal select { cursor: pointer; }
#diceModal :is(select,input):focus-visible { border-color: #f4bd95; outline: 2px solid #f4bd95; outline-offset: 2px; }
.dice-hint { margin-top: 10px; color: #a8bdb6; font-size: 11px; line-height: 1.7; overflow-wrap: anywhere; }
.dice-card-guide { margin-top: 14px; padding: 12px; border: 1px solid #546051; border-radius: 8px; color: #d1d7b8; font-size: 12px; line-height: 1.8; }
.dice-card-guide summary { display: flex; align-items: center; min-height: 44px; cursor: pointer; }
.dice-card-guide p { margin-top: 10px; }
.dice-roll-stage { position: relative; isolation: isolate; display: flex; align-items: center; justify-content: center; flex-wrap: wrap; gap: 8px; min-height: 128px; margin-bottom: 14px; padding: 20px 8px; border: 1px solid #426661; border-radius: 18px; background: radial-gradient(ellipse at center,#33584e,#122c2c); overflow: hidden; }
.dice-roll-stage:not([hidden]) { animation: dice-stage-breathe 1100ms ease-out both; }
.dice-roll-stage:not([hidden])::before {
  content: '';
  position: absolute;
  z-index: -1;
  inset: -35%;
  background: radial-gradient(circle at 50% 55%,#d5ef9629 0 18%,transparent 52%);
  transform: scale(.65);
  opacity: 0;
  animation: dice-stage-glow 1100ms ease-out both;
  pointer-events: none;
}
.dice-result.is-hwatu .dice-result-top { flex-wrap: wrap; gap: 5px 10px; }
.dice-result.is-hwatu .dice-result-score { max-width: 100%; }
.dice-names-title { margin: 24px 0 0; color: #e3ebdc; font-size: 14px; }
.dice-names { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; margin-top: 12px; }
.dice-name-field { display: flex; align-items: center; gap: 9px; min-width: 0; padding: 0 10px; border: 1px solid #3e575b; border-radius: 8px; background: #14272f; }
.dice-name-number { color: #bfbd9f; font: 11px ui-monospace, monospace; }
#diceModal .dice-name-field input { border: 0; padding-left: 0; padding-right: 0; background: none; }
#diceModal .dice-name-field input::placeholder { color: #90a8a7; font-size: 13px; }
.dice-name-field:focus-within { border-color: #f4bd95; }
.dice-actions { flex: 0 0 auto; display: grid; grid-template-columns: 1fr; gap: 9px; padding: 14px 20px max(14px,env(safe-area-inset-bottom,0px)); border-top: 1px solid #3d5559; background: #182a31; }
.dice-actions .btn-primary { width: 100%; min-height: 48px; background: #f4bd95; color: #392c23; border-color: #f4bd95; border-radius: 9px; }
.dice-actions .btn-primary:hover { background: #ffd2b2; }
.dice-actions .btn-secondary { width: 100%; min-height: 44px; padding: 10px 16px; border-radius: 9px; font-size: 12px; }
.dice-actions .dice-hint { margin: 0; text-align: center; font-size: 10px; }
.dice-result-heading { display: flex; align-items: center; justify-content: space-between; gap: 15px; margin-top: 20px; }
#dice-round { margin-bottom: 4px; color: #c8bca8; font-size: 11px; }
#dice-results-title { color: #f0f3e9; font-size: 21px; line-height: 1.5; }
.dice-local-badge { flex-shrink: 0; padding: 5px 8px; color: #c8dac9; background: #2b4644; border-radius: 5px; font-size: 10px; }
#dice-status { min-height: 1.7em; margin: 14px 0 12px; color: #c9d7c8; font-size: 12px; line-height: 1.7; }
#dice-results { display: grid; gap: 9px; margin: 0; padding: 0; list-style: none; }
.dice-result { display: flex; gap: 12px; padding: 13px 12px; border: 1px solid #3e5659; border-radius: 12px; background: #142930; }
.dice-result.is-reveal { animation: dice-result-arrive 480ms cubic-bezier(.18,.78,.25,1.12) both; }
.dice-result.is-reveal .dice-result-score { animation: dice-result-score-pop 620ms cubic-bezier(.18,.78,.25,1.25) both; }
.dice-result.is-winner { border-color: #d5ef96; background: #30483b; box-shadow: inset 0 0 24px #d5ef9610, 0 0 12px #d5ef961f; }
.dice-result-rank { flex: 0 0 34px; padding-top: 1px; color: #c5ceb0; font-size: 12px; font-weight: 700; }
.dice-result-main { flex: 1; min-width: 0; }
.dice-result-top { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; margin-bottom: 10px; }
.dice-result-name { min-width: 0; color: #e3ebdc; font-size: 13px; overflow-wrap: anywhere; }
.dice-winner-badge { flex: 0 0 auto; margin-left: auto; padding: 3px 7px; border: 1px solid #d5ef9680; border-radius: 999px; color: #ecffc2; background: #455a38; font-size: 9px; font-style: normal; font-weight: 800; letter-spacing: .04em; line-height: 1.4; }
.dice-result-score { flex-shrink: 0; max-width: 46%; color: #f4cd9d; font-size: 15px; line-height: 1.5; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.dice-faces { display: flex; gap: 8px; flex-wrap: wrap; }
.dice-face { display: grid; place-items: center; width: 38px; height: 38px; border: 1px solid #f6f1e0; border-radius: 9px; color: #2e453c; background: #e9eed9; box-shadow: 0 3px 0 #738d7b; font: 700 20px/1 ui-monospace, monospace; }
#dice-error:empty { display: none; }
#dice-error { margin-top: 16px; padding: 12px; border: 1px solid #a58262; border-radius: 9px; color: #ffdbb5; font-size: 12px; line-height: 1.7; }
#party-local { width: 100%; margin: 0 0 20px; font-size: 12px !important; }
@media (max-width: 420px) {
  .dice-content { padding: 16px; }
  .dice-settings > .dice-field:first-child { grid-column: 1 / -1; }
  #diceModal .modal-header { padding: 14px 16px; }
  .dice-actions { padding-left: 16px; padding-right: 16px; }
  .dice-play-modes > span, .dice-play-modes > button { padding: 8px 6px; font-size: 11px; }
  .dice-names { grid-template-columns: 1fr; gap: 7px; }
  .dice-result { gap: 8px; padding: 12px 9px; }
  .dice-result-rank { flex-basis: 29px; }
  .dice-result-top { gap: 8px; }
  .dice-result-score { font-size: 13px; }
  .dice-face { width: 32px; height: 32px; font-size: 18px; border-radius: 7px; }
}

@keyframes dice-stage-breathe {
  0% { border-color: #426661; box-shadow: inset 0 0 0 transparent; }
  42% { border-color: #8eaa78; box-shadow: inset 0 0 34px #d5ef9614; }
  100% { border-color: #426661; box-shadow: inset 0 0 0 transparent; }
}
@keyframes dice-stage-glow {
  0% { opacity: 0; transform: scale(.65); }
  28% { opacity: 1; }
  72% { opacity: .45; transform: scale(1.05); }
  100% { opacity: 0; transform: scale(1.2); }
}
@keyframes dice-result-arrive {
  0% { opacity: .35; transform: translateY(8px) scale(.985); }
  58% { opacity: 1; transform: translateY(-1px) scale(1.006); }
  100% { opacity: 1; transform: none; }
}
@keyframes dice-result-score-pop {
  0%,30% { opacity: .45; transform: scale(.82); }
  62% { opacity: 1; transform: scale(1.08); }
  100% { opacity: 1; transform: none; }
}
@media (prefers-reduced-motion: reduce) {
  .dice-roll-stage:not([hidden]),
  .dice-roll-stage:not([hidden])::before,
  .dice-result.is-reveal,
  .dice-result.is-reveal .dice-result-score {
    animation: none;
  }
}


/* Tactile 3D dice table: a throw skitters, tumbles, hits the felt and settles.
   The real result is chosen by DiceRules before this visual animation begins. */
#diceModal .dice-roll-stage.is-dice-arena {
  display: block;
  min-height: 292px;
  margin: 15px 0 19px;
  padding: 0;
  border: 1px solid #a78e6d;
  border-radius: 25px;
  background: #173f35;
  box-shadow: 0 18px 38px #07171470, inset 0 0 0 5px #071f20,
              inset 0 0 0 7px #b79a6955;
  overflow: hidden;
  animation: none;
}
#diceModal .dice-roll-stage.is-dice-arena::before { display: none; }
.dice-arena-board {
  position: relative;
  display: flex;
  flex-direction: column;
  min-height: 292px;
  padding: 20px 16px 16px;
  overflow: hidden;
  isolation: isolate;
  background:
    radial-gradient(ellipse 65% 70% at 50% 70%,#4e876447,transparent 95%),
    radial-gradient(ellipse 85% 45% at 60% -20%,#e3dfb32b,transparent 95%),
    repeating-linear-gradient(110deg,transparent 0 7px,#e5d2a803 8px 10px),
    linear-gradient(155deg,#265447,#164438 65%,#10392f);
}
.dice-arena-board::before {
  content: '';
  position: absolute;
  z-index: -1;
  inset: 10px;
  border: 1px solid #e2d2a51a;
  border-radius: 18px;
  pointer-events: none;
}
.dice-arena-board::after {
  content: '';
  position: absolute;
  z-index: -1;
  inset: 0;
  background: radial-gradient(circle at 50% 85%, transparent 26%, #031b1e62 100%);
  pointer-events: none;
}
.dice-arena-caption {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 26px;
  color: #ffebbf;
  text-shadow: 0 2px 4px #09221c;
  font-weight: 750;
  font-size: 13px;
  letter-spacing: .01em;
}
.dice-arena-caption-name { overflow-wrap: anywhere; }
.dice-arena-caption-result { color: #fff5d8; font-size: 19px; font-variant-numeric: tabular-nums; }
.dice-arena-field {
  display: flex;
  flex: 1 1 auto;
  align-items: center;
  justify-content: center;
  flex-wrap: nowrap;
  gap: clamp(12px,5vw,46px);
  max-width: 600px;
  width: 100%;
  margin: 2px auto 8px;
  perspective: 720px;
}
.dice-arena-slot {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 1 79px;
  width: 79px;
  height: 110px;
  min-width: 0;
  --arena-x: 0px;
  --arena-z: 0deg;
  --arena-spin: 1;
}
.dice-arena-slot--1 { --arena-x: -60px; --arena-z: -33deg; --arena-spin: 1; }
.dice-arena-slot--2 { --arena-x: 65px; --arena-z: 31deg; --arena-spin: -1; }
.dice-arena-slot--3 { --arena-x: -42px; --arena-z: 23deg; --arena-spin: -1; }
.dice-arena-slot--4 { --arena-x: 75px; --arena-z: -28deg; --arena-spin: 1; }
.dice-arena-board--2 .dice-arena-slot:nth-child(odd) { --arena-x: 75px; --arena-z: 27deg; }
.dice-arena-board--2 .dice-arena-slot:nth-child(even) { --arena-x: -65px; --arena-z: -35deg; }
.dice-arena-board--3 .dice-arena-slot:nth-child(odd) { --arena-x: -90px; --arena-z: -25deg; }
.dice-arena-board--3 .dice-arena-slot:nth-child(even) { --arena-x: 50px; --arena-z: 42deg; }
.dice-arena-slot .game-die {
  --die-size: 68px;
  --die-half: 34px;
  margin: 0;
  perspective: 480px;
  filter: drop-shadow(0 8px 5px #031c1988);
}
.dice-arena-slot .game-die .game-die-face {
  border: 2px solid #fffdf3;
  border-radius: 9px;
  background: linear-gradient(140deg,#fffef5 3%,#f2f3e4 55%,#d0d8be);
  box-shadow: inset 2px 3px 7px #ffffffba, inset -2px -3px 8px #7c87774b,0 2px 2px #112a2499;
  padding: 11px;
  gap: 3px;
}
.dice-arena-slot .game-die .game-die-pip {
  max-width: 12px;
  background: radial-gradient(circle at 35% 30%,#33474a,#091c25);
  box-shadow: inset 0 2px 2px #0009,0 1px 1px #fff8;
}
/* The arena has its own dark pip style; override it for face 1. */
.dice-arena-slot .game-die .game-die-face--one .game-die-pip {
  background: radial-gradient(circle at 35% 30%, #f56762, #b82129 78%);
  box-shadow: inset 0 2px 2px #73121980, 0 1px 1px #fff8;
}
.dice-arena-slot .game-die .game-die-face--front { transform: translateZ(var(--die-half)); }
.dice-arena-slot .game-die.is-rolling .game-die-motion {
  animation: dice-arena-hop 2220ms cubic-bezier(.2,.6,.24,1) both;
  animation-delay: calc(var(--piece-index) * 78ms);
}
.dice-arena-slot .game-die.is-rolling .game-die-cube {
  animation: dice-arena-tumble 2220ms cubic-bezier(.14,.56,.24,1) both;
  animation-delay: calc(var(--piece-index) * 78ms);
}
.dice-arena-slot .game-die.is-rolling::after {
  animation: dice-arena-shadow 2220ms ease both;
  animation-delay: calc(var(--piece-index) * 78ms);
  background: #051510a8;
  filter: blur(6px);
}
.dice-arena-slot .game-die.is-rolling::before {
  animation: dice-arena-ring 2220ms ease both;
  animation-delay: calc(var(--piece-index) * 78ms);
  border-color: #f1e7b9bd;
}
@keyframes dice-arena-hop {
  0%   { transform: translate3d(var(--arena-x),-100px,0) rotateZ(var(--arena-z)) scale(.66); }
  17%  { transform: translate3d(-20px,-38px,0) rotateZ(-18deg) scale(1.11); }
  32%  { transform: translate3d(13px,23px,0) rotateZ(13deg) scale(1.07,.88); }
  47%  { transform: translate3d(-10px,-52px,0) rotateZ(-12deg) scale(1.03); }
  63%  { transform: translate3d(8px,12px,0) rotateZ(6deg) scale(1.05,.94); }
  74%  { transform: translate3d(-3px,-23px,0) rotateZ(-4deg) scale(1); }
  85%  { transform: translate3d(2px,5px,0) rotateZ(2deg) scale(1.03,.97); }
  94%  { transform: translate3d(0,-5px,0) rotateZ(-1deg); }
  100% { transform: none; }
}
@keyframes dice-arena-tumble {
  0% { transform: rotateX(990deg) rotateY(-760deg) rotateZ(210deg); }
  25% { transform: rotateX(710deg) rotateY(-500deg) rotateZ(-145deg); }
  48% { transform: rotateX(470deg) rotateY(-340deg) rotateZ(120deg); }
  65% { transform: rotateX(245deg) rotateY(-177deg) rotateZ(-62deg); }
  79% { transform: rotateX(85deg) rotateY(-53deg) rotateZ(20deg); }
  90% { transform: rotateX(-14deg) rotateY(9deg) rotateZ(-4deg); }
  96% { transform: rotateX(5deg) rotateY(-3deg) rotateZ(2deg); }
  100% { transform: none; }
}
@keyframes dice-arena-shadow {
  0% { opacity: .12; transform: scale(.3); filter: blur(12px); }
  32% { opacity: .95; transform: scale(1.3); filter: blur(2px); }
  47% { opacity: .17; transform: scale(.5); filter: blur(10px); }
  63% { opacity: .8; transform: scale(1.08); filter: blur(3px); }
  74% { opacity: .3; transform: scale(.7); filter: blur(7px); }
  100% { opacity: .82; transform: scale(1); filter: blur(4px); }
}
@keyframes dice-arena-ring {
  0%,27% { opacity: 0; transform: translateX(-50%) scale(.2); }
  32% { opacity: .8; transform: translateX(-50%) scale(.6); }
  43% { opacity: 0; transform: translateX(-50%) scale(1.7); }
  60% { opacity: 0; transform: translateX(-50%) scale(.2); }
  64% { opacity: .55; transform: translateX(-50%) scale(.7); }
  76%,100% { opacity: 0; transform: translateX(-50%) scale(1.7); }
}
/* Finished dice stay on the table, showing exactly the scored face. */
.dice-roll-stage.is-arena-finished .game-die.is-rolling .game-die-motion,
.dice-roll-stage.is-arena-finished .game-die.is-rolling .game-die-cube,
.dice-roll-stage.is-arena-finished .game-die.is-rolling::after,
.dice-roll-stage.is-arena-finished .game-die.is-rolling::before {
  animation: none;
  transform: none;
}
.dice-roll-stage.is-arena-finished .game-die.is-rolling::after { transform: scaleX(.9); opacity: .8; }
.dice-arena-floor-line {
  position: absolute;
  left: 12%; right: 12%; bottom: 14px;
  height: 1px;
  background: linear-gradient(90deg,transparent,#d2b77e51,transparent);
}
@media (max-width: 510px) {
  #diceModal .dice-roll-stage.is-dice-arena,.dice-arena-board { min-height: 245px; }
  .dice-arena-board { padding: 15px 12px; }
  .dice-arena-slot { flex-basis: 60px; height: 90px; }
  .dice-arena-field { gap: clamp(2px,2vw,12px); }
  .dice-arena-slot .game-die { --die-size: 50px; --die-half: 25px; }
  .dice-arena-slot .game-die .game-die-face { padding: 8px; gap: 2px; border-radius: 6px; }
  .dice-arena-slot .game-die .game-die-pip { max-width: 8px; }
  .dice-arena-caption { font-size: 12px; }
  .dice-arena-caption-result { font-size: 15px; }
}
@media (prefers-reduced-motion: reduce) {
  .dice-arena-slot .game-die.is-rolling .game-die-motion,
  .dice-arena-slot .game-die.is-rolling .game-die-cube,
  .dice-arena-slot .game-die.is-rolling::before,
  .dice-arena-slot .game-die.is-rolling::after { animation: none !important; transform: none; }
  .dice-arena-slot .game-die.is-rolling::after { transform: scaleX(.9); opacity: .8; }
}

/* Multi-player dice arena: every participant has an independent 3D throw. */
#diceModal .dice-roll-stage.is-dice-arena {
  min-height: 0;
  padding: 11px;
}
.dice-arena-grid {
  display: grid;
  grid-template-columns: repeat(2,minmax(0,1fr));
  align-items: stretch;
  gap: 11px;
  width: 100%;
  padding: 3px;
  isolation: isolate;
}
.dice-arena-grid--solo { grid-template-columns: minmax(0,1fr); max-width: 510px; margin: 0 auto; }
.dice-arena-grid--medium { grid-template-columns: repeat(3,minmax(0,1fr)); }
.dice-arena-grid--packed { grid-template-columns: repeat(4,minmax(0,1fr)); gap: 8px; }
.dice-arena-participant {
  --tile-die-size: 60px;
  --tile-die-half: 30px;
  --tile-face-pad: 8px;
  --tile-pip-size: 9px;
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  min-width: 0;
  min-height: 161px;
  padding: 13px 14px 9px;
  overflow: hidden;
  isolation: isolate;
  border: 1px solid #91b59b65;
  border-radius: 16px;
  background: radial-gradient(ellipse at 48% 62%,#7ca16a36,transparent 67%),linear-gradient(155deg,#295849,#173d34 74%,#0f312b);
  box-shadow: inset 0 0 0 1px #ffffff08,0 8px 18px #0319145c;
}
.dice-arena-participant::before {
  content: '';
  position: absolute;
  inset: 7px;
  border: 1px solid #e3d8aa14;
  border-radius: 11px;
  pointer-events: none;
}
.dice-arena-participant--2 { background: radial-gradient(ellipse at 48% 62%,#8ea97b33,transparent 67%),linear-gradient(155deg,#32564d,#1e3e3f 74%,#132f35); }
.dice-arena-participant--3 { background: radial-gradient(ellipse at 48% 62%,#9faa6b2e,transparent 67%),linear-gradient(155deg,#345749,#284239 74%,#172d31); }
.dice-arena-participant--4 { background: radial-gradient(ellipse at 48% 62%,#7cbca02d,transparent 67%),linear-gradient(155deg,#29564a,#153c3a 74%,#102e35); }
.dice-arena-participant.is-winner {
  border-color: #ffe5a8;
  box-shadow: inset 0 0 0 1px #ffd987a6, 0 0 22px #ffe5a738, 0 9px 18px #0319145c;
}
.dice-arena-participant .dice-arena-caption {
  min-height: 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding-bottom: 5px;
  border-bottom: 1px solid rgba(255, 239, 196, 0.14);
  font-size: 12px;
  position: relative;
  z-index: 1;
}
.dice-arena-participant .dice-arena-caption-name {
  min-width: 0;
  font-weight: 850;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.dice-arena-participant .dice-arena-caption-result {
  flex-shrink: 0;
  font-size: 14px;
  font-weight: 850;
  padding: 1px 7px;
  border-radius: 999px;
  background: rgba(8, 28, 23, 0.48);
  border: 1px solid rgba(255, 235, 191, 0.28);
}
.dice-arena-participant .dice-arena-caption-result:empty {
  display: none;
}
.dice-arena-participant.is-winner .dice-arena-caption-result {
  background: rgba(255, 224, 140, 0.24);
  border-color: rgba(255, 229, 168, 0.72);
  color: #fff6d6;
}
.dice-arena-participant .dice-arena-field {
  flex: 0 0 auto;
  width: 100%;
  min-height: 82px;
  max-width: none;
  margin: 0 auto;
  justify-content: center;
  flex-wrap: nowrap;
  gap: 8px;
  perspective: 540px;
}
.dice-arena-participant .dice-arena-slot {
  flex: 0 0 var(--tile-die-size);
  width: var(--tile-die-size);
  height: 76px;
  --arena-x: -20px;
  --arena-z: -27deg;
}
.dice-arena-participant .dice-arena-slot:nth-child(even) { --arena-x: 23px; --arena-z: 29deg; }
.dice-arena-participant .dice-arena-slot:nth-child(3) { --arena-x: -15px; --arena-z: 19deg; }
.dice-arena-participant .dice-arena-slot:nth-child(4) { --arena-x: 16px; --arena-z: -17deg; }
.dice-arena-participant .dice-arena-slot .game-die {
  --die-size: var(--tile-die-size);
  --die-half: var(--tile-die-half);
  margin: 0;
  perspective: 380px;
}
.dice-arena-participant .dice-arena-slot .game-die .game-die-face {
  border-radius: 8px;
  padding: var(--tile-face-pad);
  gap: 2px;
}
.dice-arena-participant .dice-arena-slot .game-die .game-die-pip { max-width: var(--tile-pip-size); }
.dice-arena-placement {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  align-self: center;
  position: relative;
  z-index: 1;
  min-height: 20px;
  padding: 2px 10px;
  border-radius: 999px;
  background: rgba(8, 28, 23, 0.45);
  border: 1px solid rgba(227, 216, 170, 0.22);
  color: #acc7b4;
  text-align: center;
  font-size: 11px;
  font-weight: 850;
}
.dice-arena-placement:empty {
  visibility: hidden;
}
.dice-arena-participant.is-settled .dice-arena-placement { color: #e3e8be; }
.dice-arena-participant.is-winner .dice-arena-placement {
  color: #fff3c4;
  background: rgba(255, 221, 133, 0.22);
  border-color: rgba(255, 229, 168, 0.68);
}
.dice-arena-grid--medium .dice-arena-participant { --tile-die-size: 43px; --tile-die-half: 21.5px; --tile-face-pad: 7px; --tile-pip-size: 7px; }
.dice-arena-grid--packed .dice-arena-participant { --tile-die-size: 36px; --tile-die-half: 18px; --tile-face-pad: 6px; --tile-pip-size: 6px; min-height: 138px; padding: 9px; }
.dice-arena-grid--packed .dice-arena-field { min-height: 73px; gap: 5px; }
.dice-arena-grid--packed .dice-arena-caption { font-size: 11px; }
.dice-arena-grid--packed .dice-arena-caption-result { font-size: 13px; }
.dice-arena-grid--packed .dice-arena-slot { height: 64px; }
.dice-arena-grid--solo .dice-arena-participant { min-height: 235px; --tile-die-size: 66px; --tile-die-half: 33px; --tile-face-pad: 10px; --tile-pip-size: 11px; }
.dice-arena-grid--solo .dice-arena-field { min-height: 165px; gap: 17px; }
.dice-arena-grid--solo .dice-arena-slot { height: 124px; }
.dice-arena-participant .game-die.is-rolling .game-die-motion {
  animation: dice-arena-hop 1950ms cubic-bezier(.2,.6,.24,1) both;
  animation-delay: calc(var(--arena-player-delay,0ms) + var(--piece-index) * 48ms);
}
.dice-arena-participant .game-die.is-rolling .game-die-cube {
  animation: dice-arena-tumble 1950ms cubic-bezier(.14,.56,.24,1) both;
  animation-delay: calc(var(--arena-player-delay,0ms) + var(--piece-index) * 48ms);
}
.dice-arena-participant .game-die.is-rolling::after {
  animation: dice-arena-shadow 1950ms ease both;
  animation-delay: calc(var(--arena-player-delay,0ms) + var(--piece-index) * 48ms);
}
.dice-arena-participant .game-die.is-rolling::before {
  animation: dice-arena-ring 1950ms ease both;
  animation-delay: calc(var(--arena-player-delay,0ms) + var(--piece-index) * 48ms);
}
@media (max-width: 800px) {
  .dice-arena-grid--medium, .dice-arena-grid--packed { grid-template-columns: repeat(2,minmax(0,1fr)); }
  .dice-arena-grid--medium .dice-arena-participant { --tile-die-size: 40px; --tile-die-half: 20px; }
}
@media (max-width: 560px) {
  #diceModal .dice-roll-stage.is-dice-arena { padding: 8px; border-radius: 17px; }
  .dice-arena-grid { gap: 8px; padding: 1px; }
  .dice-arena-grid--small, .dice-arena-grid--medium, .dice-arena-grid--packed { grid-template-columns: repeat(2,minmax(0,1fr)); }
  .dice-arena-participant, .dice-arena-grid--medium .dice-arena-participant, .dice-arena-grid--packed .dice-arena-participant {
    --tile-die-size: 32px; --tile-die-half: 16px; --tile-face-pad: 5px; --tile-pip-size: 5.5px;
    min-height: 136px; padding: 10px 8px 8px;
    border-radius: 12px;
  }
  .dice-arena-grid:not(.dice-arena-grid--solo)[data-dice-count="1"] .dice-arena-participant,
  .dice-arena-grid:not(.dice-arena-grid--solo)[data-dice-count="2"] .dice-arena-participant {
    --tile-die-size: 38px; --tile-die-half: 19px; --tile-face-pad: 6px; --tile-pip-size: 6.5px;
  }
  .dice-arena-participant .dice-arena-caption { min-height: 24px; font-size: 11px; gap: 5px; }
  .dice-arena-participant .dice-arena-caption-name { line-height: 1.3; }
  .dice-arena-participant .dice-arena-caption-result { font-size: 12px; padding: 1px 6px; }
  .dice-arena-participant .dice-arena-field { gap: 5px; min-height: 68px; }
  .dice-arena-participant .dice-arena-slot, .dice-arena-grid--packed .dice-arena-slot { height: 60px; }
  .dice-arena-participant .dice-arena-slot .game-die .game-die-face { border-radius: 6px; gap: 1.5px; }
  .dice-arena-placement { min-height: 18px; font-size: 10.5px; padding: 2px 8px; }
  .dice-arena-grid--solo .dice-arena-participant { --tile-die-size: 58px; --tile-die-half: 29px; --tile-face-pad: 9px; --tile-pip-size: 10px; min-height: 220px; }
  .dice-arena-grid--solo .dice-arena-field { min-height: 140px; gap: 13px; }
  .dice-arena-grid--solo .dice-arena-slot { height: 110px; }
}
@media (max-width: 380px) {
  .dice-arena-participant, .dice-arena-grid--medium .dice-arena-participant, .dice-arena-grid--packed .dice-arena-participant {
    --tile-die-size: 27px; --tile-die-half: 13.5px; --tile-face-pad: 4px; --tile-pip-size: 4.5px;
    padding-inline: 6px;
  }
  .dice-arena-grid:not(.dice-arena-grid--solo)[data-dice-count="1"] .dice-arena-participant,
  .dice-arena-grid:not(.dice-arena-grid--solo)[data-dice-count="2"] .dice-arena-participant {
    --tile-die-size: 34px; --tile-die-half: 17px; --tile-face-pad: 5px; --tile-pip-size: 6px;
  }
  .dice-arena-participant .dice-arena-field { gap: 4px; }
}

/* Ladder-style roster on dice only: editable name, cycling avatar, per-row
   removal and a single accessible add action. Does not alter Hwatu's UI. */
#diceModal .dice-names.dice-roster {
  display: grid;
  grid-template-columns: repeat(2,minmax(0,1fr));
  gap: 10px;
  margin-top: 12px;
}
#diceModal .dice-roster .dice-player-field {
  display: flex;
  align-items: center;
  gap: 7px;
  min-width: 0;
  padding: 7px 8px;
  border: 1px solid #557476;
  border-radius: 12px;
  background: #192f38;
  transition: border-color .15s ease,background .15s ease;
}
#diceModal .dice-roster .dice-player-field:focus-within { border-color: #d5ef96; background: #203b44; }
#diceModal .dice-roster .dice-name-number {
  flex: 0 0 18px;
  min-width: 18px;
  text-align: center;
  color: #b7cda6;
  font-size: 11px;
  font-weight: 750;
}
#diceModal .dice-roster .dice-player-avatar {
  display: grid;
  place-items: center;
  flex: 0 0 44px;
  width: 44px;
  height: 44px;
  min-height: 44px;
  padding: 0;
  border: 1px solid #658681;
  border-radius: 11px;
  background: #35545b;
  color: #fff;
  font: 25px/1 system-ui,sans-serif;
  cursor: pointer;
}
#diceModal .dice-roster .dice-player-field input {
  flex: 1;
  min-width: 0;
  width: 100%;
  min-height: 40px;
  padding: 6px 2px;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: #f8fff1;
  font-size: 16px;
  font-weight: 750;
  text-overflow: ellipsis;
}
#diceModal .dice-roster .dice-player-field input:focus-visible { outline: none; }
#diceModal .dice-roster .dice-player-remove {
  flex: 0 0 44px;
  width: 44px;
  min-width: 44px;
  min-height: 44px;
  padding: 0;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: #d1dfd9;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
}
#diceModal .dice-roster .dice-player-remove:not(:disabled):hover { background: #65434b; color: #fff; }
#diceModal .dice-roster .dice-player-remove:disabled { opacity: .25; cursor: not-allowed; }
#diceModal .dice-roster :is(.dice-player-avatar,.dice-player-remove,.dice-player-add):focus-visible {
  outline: 2px solid #d5ef96;
  outline-offset: 2px;
}
#diceModal .dice-roster .dice-player-controls {
  grid-column: 1 / -1;
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
  margin-top: 5px;
}
#diceModal .dice-roster .dice-player-add {
  min-height: 42px;
  padding: 9px 15px;
  border: 1px solid #d7f497;
  border-radius: 10px;
  background: #d7f497;
  color: #1c362d;
  font-size: 13px;
  font-weight: 800;
  cursor: pointer;
}
#diceModal .dice-roster .dice-player-add:disabled { opacity: .45; cursor: not-allowed; }
#diceModal .dice-roster .dice-member-count { color: #bad0c5; font-size: 12px; }
@media(max-width:600px) {
  #diceModal .dice-names.dice-roster { grid-template-columns: minmax(0,1fr); gap: 8px; }
}
@media(prefers-reduced-motion:reduce) {
  #diceModal .dice-roster .dice-player-field { transition: none; }
}

/* Lay out by the actual arena width, not only the device viewport: the same
   dice controller also runs inside a narrower homepage modal. */
#diceModal .dice-roll-stage.is-dice-arena { container: dice-arena / inline-size; }
@container dice-arena (max-width: 850px) {
  .dice-arena-grid--packed { grid-template-columns:repeat(2,minmax(0,1fr)); }
  .dice-arena-grid--small[data-dice-count="4"] { grid-template-columns: repeat(2,minmax(0,1fr)); }
  .dice-arena-grid:not(.dice-arena-grid--solo)[data-dice-count="1"] .dice-arena-participant,
  .dice-arena-grid:not(.dice-arena-grid--solo)[data-dice-count="2"] .dice-arena-participant {
    --tile-die-size: 42px; --tile-die-half: 21px; --tile-face-pad: 6px; --tile-pip-size: 7px;
  }
}
@container dice-arena (max-width: 650px) {
  .dice-arena-grid[data-dice-count="4"] { grid-template-columns: minmax(0,1fr); }
  .dice-arena-grid[data-dice-count="4"] .dice-arena-participant {
    --tile-die-size: 52px; --tile-die-half: 26px; --tile-face-pad: 8px; --tile-pip-size: 9px;
    min-height: 165px; padding: 11px 12px;
  }
  .dice-arena-grid[data-dice-count="4"] .dice-arena-field { min-height: 102px; gap: 8px; }
  .dice-arena-grid[data-dice-count="4"] .dice-arena-slot { height: 88px; }
}
@container dice-arena (max-width: 290px) {
  .dice-arena-grid[data-dice-count="4"] .dice-arena-participant {
    --tile-die-size: 42px; --tile-die-half: 21px; --tile-face-pad: 6px; --tile-pip-size: 7px;
  }
  .dice-arena-grid[data-dice-count="4"] .dice-arena-field { gap: 5px; }
}
