:root {
  --red: #ed4656;
  --green: #20bf77;
  --yellow: #f5c82f;
  --blue: #347fe8;
  --cream: #fffdf5;
  --ink: #251849;
  --purple: #2a1262;
  --cell-border: #c9c4d3;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

body {
  margin: 0;
  width: 100%;
  max-width: 100%;
  min-height: 100vh;
  overflow-x: hidden;
  color: #fff;
  font-family: Inter, ui-rounded, "Segoe UI", system-ui, sans-serif;
  background:
    radial-gradient(circle at 50% -10%, #6a43cf 0, transparent 38rem),
    linear-gradient(160deg, #1b0a3d, #30136a 58%, #16072e);
}

button, a { font: inherit; }
button { color: inherit; }

.game-shell {
  width: min(100%, 650px);
  min-height: 100vh;
  margin: 0 auto;
  padding: 12px clamp(10px, 3vw, 20px) 28px;
}

.game-header { height: 62px; display: grid; grid-template-columns: 42px 1fr 42px; align-items: center; }
.back-button, .icon-button {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border: 1px solid #ffffff35;
  border-radius: 13px;
  color: #fff;
  background: #ffffff0c;
  text-decoration: none;
  font-size: 1.8rem;
  cursor: pointer;
}

.icon-button { font-size: 1.2rem; }
.icon-button[aria-pressed="true"] { opacity: .45; text-decoration: line-through; }

.game-title { display: flex; justify-content: center; align-items: center; gap: 8px; text-align: left; }
.game-title .crown { color: var(--yellow); font-size: 1.7rem; }
.game-title strong { display: block; font-size: .93rem; letter-spacing: .08em; }
.game-title small { display: block; margin-top: 1px; color: #bdb3de; font-size: .65rem; letter-spacing: .11em; text-transform: uppercase; }

.players { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 7px; margin: 7px 0 13px; }
.player-card {
  min-width: 0;
  padding: 7px 4px;
  border: 1px solid #ffffff16;
  border-radius: 12px;
  color: #bdb3de;
  background: #ffffff08;
  text-align: center;
  transition: .22s ease;
}
.player-card.active { color: #fff; background: #ffffff18; border-color: #ffffff6b; transform: translateY(-2px); box-shadow: 0 7px 16px #0003; }
.player-dot { display: inline-block; width: 9px; height: 9px; margin-right: 4px; border-radius: 50%; box-shadow: 0 0 0 2px #ffffff2b; }
.player-card strong { font-size: .72rem; white-space: nowrap; }
.player-score { display: block; margin-top: 2px; font-size: .61rem; }

.board-wrap { position: relative; }
.turn-banner {
  position: absolute;
  z-index: 20;
  left: 50%;
  top: -10px;
  padding: 5px 14px;
  border-radius: 999px;
  color: var(--ink);
  background: #fff;
  box-shadow: 0 5px 13px #0004;
  transform: translate(-50%, -50%);
  font-size: .67rem;
  font-weight: 900;
  letter-spacing: .07em;
  text-transform: uppercase;
}

.board {
  position: relative;
  display: grid;
  grid-template-columns: repeat(15, minmax(0, 1fr));
  width: 100%;
  aspect-ratio: 1;
  overflow: hidden;
  border: clamp(5px, 1.7vw, 9px) solid #f8f4ff;
  border-radius: clamp(14px, 4vw, 25px);
  background: var(--cream);
  box-shadow: 0 28px 55px #09001499, 0 0 0 3px #ffffff24;
  isolation: isolate;
}

.cell { position: relative; min-width: 0; border: .5px solid var(--cell-border); background: var(--cream); }
.cell.base { border: 0; }
.cell.base-red { background: color-mix(in srgb, var(--red) 91%, white); }
.cell.base-green { background: color-mix(in srgb, var(--green) 91%, white); }
.cell.base-yellow { background: color-mix(in srgb, var(--yellow) 91%, white); }
.cell.base-blue { background: color-mix(in srgb, var(--blue) 91%, white); }
.cell.base-slot::before { content: ""; position: absolute; inset: 10%; border-radius: 50%; background: #fff; box-shadow: inset 0 0 0 2px #00000016, 0 2px 3px #0002; }
.cell.track.safe::after { content: "★"; position: absolute; inset: 0; display: grid; place-items: center; color: #6b617e; font-size: clamp(8px, 2.4vw, 17px); opacity: .46; }
.cell.start-red, .cell.home-red { background: var(--red); }
.cell.start-green, .cell.home-green { background: var(--green); }
.cell.start-yellow, .cell.home-yellow { background: var(--yellow); }
.cell.start-blue, .cell.home-blue { background: var(--blue); }

.cell.center {
  z-index: 1;
  grid-row: 7 / span 3;
  grid-column: 7 / span 3;
  border: 0;
  background: conic-gradient(var(--green) 0 25%, var(--yellow) 0 50%, var(--blue) 0 75%, var(--red) 0);
}
.cell.center::after { content: "♛"; position: absolute; inset: 26%; display: grid; place-items: center; border-radius: 50%; color: #fff; background: #2b1659; box-shadow: 0 3px 8px #0005; font-size: clamp(13px, 4vw, 27px); }

.token {
  position: absolute;
  z-index: 8;
  left: 50%;
  top: 50%;
  width: 76%;
  aspect-ratio: 1;
  border: clamp(1px, .5vw, 3px) solid #fff;
  border-radius: 50% 50% 45% 45%;
  background: var(--token-color);
  box-shadow: inset 0 -4px 0 #0002, 0 3px 4px #0006;
  transform: translate(-50%, -50%) scale(var(--token-scale, 1));
  cursor: default;
  transition: transform .18s ease, filter .18s ease;
}
.token::after { content: ""; position: absolute; width: 32%; aspect-ratio: 1; left: 20%; top: 12%; border-radius: 50%; background: #ffffffa8; }
.token.red { --token-color: var(--red); }
.token.green { --token-color: var(--green); }
.token.yellow { --token-color: #e8b90d; }
.token.blue { --token-color: var(--blue); }
.token.movable { cursor: pointer; animation: tokenPulse .72s ease-in-out infinite alternate; }
.token.movable:hover { filter: brightness(1.15); }
.token.stack-0 { margin-left: -17%; margin-top: -17%; --token-scale: .68; }
.token.stack-1 { margin-left: 17%; margin-top: -17%; --token-scale: .68; }
.token.stack-2 { margin-left: -17%; margin-top: 17%; --token-scale: .68; }
.token.stack-3 { margin-left: 17%; margin-top: 17%; --token-scale: .68; }
.token.finished { cursor: default; }

@keyframes tokenPulse { to { transform: translate(-50%, -50%) scale(1.14); filter: drop-shadow(0 0 8px #fff); } }

.control-deck {
  margin-top: 14px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 14px;
  padding: 13px 15px;
  border: 1px solid #ffffff20;
  border-radius: 20px;
  background: #ffffff0d;
  box-shadow: inset 0 1px 0 #ffffff20;
}
.status-copy span, .status-copy strong, .status-copy small { display: block; }
.status-copy { min-width: 0; }
.status-copy span { color: var(--yellow); font-size: .62rem; font-weight: 900; letter-spacing: .14em; }
.status-copy strong { margin: 3px 0; font-size: clamp(.92rem, 3vw, 1.15rem); }
.status-copy small { color: #bcb3da; font-size: .68rem; }

.dice-button {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 7px 14px 7px 7px;
  border: 0;
  border-radius: 15px;
  color: var(--ink);
  background: var(--yellow);
  box-shadow: 0 6px 0 #af7f00, 0 10px 18px #0005;
  cursor: pointer;
  font-weight: 950;
  transition: .15s ease;
}
.dice-button:not(:disabled):hover { transform: translateY(2px); box-shadow: 0 4px 0 #af7f00, 0 8px 14px #0004; }
.dice-button:not(:disabled):active { transform: translateY(5px); box-shadow: 0 1px 0 #af7f00; }
.dice-button:disabled { opacity: .48; cursor: not-allowed; filter: grayscale(.3); }
.dice { position: relative; width: 48px; height: 48px; border-radius: 11px; background: #fff; box-shadow: inset 0 0 0 2px #e2dce8; }
.dice::before { content: ""; position: absolute; inset: 0; background-repeat: no-repeat; }
.dice[data-value="1"]::before { background: radial-gradient(circle at 50% 50%, var(--ink) 0 5px, transparent 5.5px); }
.dice[data-value="2"]::before { background: radial-gradient(circle at 27% 27%, var(--ink) 0 4px, transparent 4.5px), radial-gradient(circle at 73% 73%, var(--ink) 0 4px, transparent 4.5px); }
.dice[data-value="3"]::before { background: radial-gradient(circle at 25% 25%, var(--ink) 0 4px, transparent 4.5px), radial-gradient(circle at 50% 50%, var(--ink) 0 4px, transparent 4.5px), radial-gradient(circle at 75% 75%, var(--ink) 0 4px, transparent 4.5px); }
.dice[data-value="4"]::before { background: radial-gradient(circle at 27% 27%, var(--ink) 0 4px, transparent 4.5px), radial-gradient(circle at 73% 27%, var(--ink) 0 4px, transparent 4.5px), radial-gradient(circle at 27% 73%, var(--ink) 0 4px, transparent 4.5px), radial-gradient(circle at 73% 73%, var(--ink) 0 4px, transparent 4.5px); }
.dice[data-value="5"]::before { background: radial-gradient(circle at 25% 25%, var(--ink) 0 4px, transparent 4.5px), radial-gradient(circle at 75% 25%, var(--ink) 0 4px, transparent 4.5px), radial-gradient(circle at 50% 50%, var(--ink) 0 4px, transparent 4.5px), radial-gradient(circle at 25% 75%, var(--ink) 0 4px, transparent 4.5px), radial-gradient(circle at 75% 75%, var(--ink) 0 4px, transparent 4.5px); }
.dice[data-value="6"]::before { background: radial-gradient(circle at 27% 23%, var(--ink) 0 4px, transparent 4.5px), radial-gradient(circle at 73% 23%, var(--ink) 0 4px, transparent 4.5px), radial-gradient(circle at 27% 50%, var(--ink) 0 4px, transparent 4.5px), radial-gradient(circle at 73% 50%, var(--ink) 0 4px, transparent 4.5px), radial-gradient(circle at 27% 77%, var(--ink) 0 4px, transparent 4.5px), radial-gradient(circle at 73% 77%, var(--ink) 0 4px, transparent 4.5px); }
.dice.rolling { animation: diceRoll .42s ease; }
@keyframes diceRoll { 30% { transform: rotate(16deg) scale(.86); } 65% { transform: rotate(-10deg) scale(1.08); } }

.game-actions { display: flex; justify-content: center; gap: 7px; margin-top: 12px; }
.game-actions button { padding: 7px 11px; border: 0; color: #a99fcc; background: none; cursor: pointer; font-size: .7rem; text-decoration: underline; text-underline-offset: 3px; }

dialog { width: min(90vw, 440px); padding: 0; border: 0; border-radius: 25px; color: var(--ink); background: transparent; }
dialog::backdrop { background: #100522d9; backdrop-filter: blur(8px); }
.dialog-card { position: relative; padding: 30px; border-radius: 25px; background: #fff; box-shadow: 0 28px 80px #000a; }
.dialog-close { position: absolute; right: 16px; top: 13px; width: 34px; height: 34px; border: 0; border-radius: 50%; color: var(--ink); background: #eeeaf4; cursor: pointer; font-size: 1.4rem; }
.dialog-kicker { margin: 0 0 7px; color: #7554c4; font-weight: 900; letter-spacing: .12em; text-transform: uppercase; font-size: .67rem; }
.dialog-card h2 { margin: 0 0 16px; font-size: 1.75rem; line-height: 1.05; }
.dialog-card ul { padding-left: 20px; color: #645d74; line-height: 1.6; font-size: .9rem; }
.dialog-card li + li { margin-top: 8px; }
.dialog-primary { width: 100%; margin-top: 8px; padding: 12px; border: 0; border-radius: 13px; color: #fff; background: var(--purple); cursor: pointer; font-weight: 900; }
.winner-card { text-align: center; }
.winner-crown { color: #e4ae00; font-size: 4rem; }
.winner-card p:not(.dialog-kicker) { color: #70677f; }

@media (max-width: 430px) {
  .game-shell { padding-inline: 8px; }
  .players { gap: 4px; }
  .player-card strong { font-size: .63rem; }
  .control-deck { padding: 10px; }
  .roll-label { display: none; }
  .dice-button { padding-right: 7px; }
  .dice { width: 44px; height: 44px; }
}

@media (min-width: 700px) and (min-height: 900px) {
  .game-shell { padding-top: 24px; }
  .game-header { height: 70px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; }
}
