:root {
  color-scheme: dark;
  --bg: #171713;
  --panel: #f7f0df;
  --ink: #201b16;
  --muted: #6f675d;
  --line: rgba(255, 255, 255, 0.18);
  --button: #f7f0df;
  --button-ink: #201b16;
  --shadow: 0 18px 45px rgba(0, 0, 0, 0.35);
  --circle-size: clamp(78px, 21vmin, 116px);
  --bump-w: clamp(58px, 15vmin, 82px);
  --bump-h: clamp(40px, 10vmin, 54px);
  --bottom-edge-gap: max(clamp(18px, 4vh, 34px), env(safe-area-inset-bottom));
  --label-edge-gap: clamp(22px, 5vmin, 34px);
  --history-edge-align: 0.1rem;
  --history-corner-inset: clamp(18px, 4.8vmin, 24px);
  --bump-edge-x: calc((var(--bump-w) / 2) + var(--label-edge-gap) - var(--history-edge-align));
  --bump-edge-y: calc((var(--bump-h) / 2) + var(--label-edge-gap) - var(--history-edge-align));
  --bump-bottom-edge-y: calc(
    (var(--bump-h) / 2) + var(--label-edge-gap) + var(--bottom-edge-gap) - var(--history-edge-align)
  );
  --bottom-current-drop: clamp(20px, 5vmin, 27px);
  --bottom-current-name-drop: clamp(13px, 3.4vmin, 18px);
  --circle-edge-x: calc((var(--circle-size) / 2) + var(--label-edge-gap));
  --circle-edge-y: calc((var(--circle-size) / 2) + var(--label-edge-gap));
  --circle-bottom-edge-y: calc((var(--circle-size) / 2) + var(--label-edge-gap) + var(--bottom-edge-gap));
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
  margin: 0;
}

body {
  background: var(--bg);
  color: #fffdf5;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  overflow: hidden;
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
}

.app {
  min-height: 100vh;
  min-height: 100svh;
  min-height: 100dvh;
}

.screen {
  min-height: 100vh;
  min-height: 100svh;
  min-height: 100dvh;
}

.orientation-notice {
  position: fixed;
  top: max(0.55rem, env(safe-area-inset-top));
  left: max(0.75rem, env(safe-area-inset-left));
  z-index: 50;
  display: none;
  align-items: center;
  gap: 0.42rem;
  min-height: 2.15rem;
  padding: 0 0.78rem;
  color: #fffdf5;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 999px;
  background: #c82124;
  box-shadow: 0 0.6rem 1.4rem rgba(0, 0, 0, 0.36);
  font-size: clamp(0.78rem, 2.4vmin, 0.95rem);
  font-weight: 950;
  line-height: 1;
  pointer-events: none;
}

.orientation-icon {
  width: 1.08rem;
  height: 1.08rem;
  flex: 0 0 auto;
}

.orientation-icon path {
  fill: none;
  stroke: currentColor;
  stroke-width: 2.3;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.setup-screen {
  display: grid;
  place-items: center;
  overflow: auto;
  padding:
    max(1rem, env(safe-area-inset-top))
    max(1rem, env(safe-area-inset-right))
    max(1rem, env(safe-area-inset-bottom))
    max(1rem, env(safe-area-inset-left));
  background: #000;
}

.setup-panel {
  width: calc(100vw - 2rem);
  max-width: 42rem;
  color: var(--ink);
  background: var(--panel);
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: 0.5rem;
  box-shadow: var(--shadow);
  padding: clamp(1rem, 4vmin, 1.6rem);
}

.setup-header {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
}

.setup-title {
  margin: 0;
  font-size: clamp(1.9rem, 8vmin, 3.6rem);
  line-height: 0.9;
}

.rules-panel {
  min-height: min(38rem, calc(100svh - 2rem));
  display: flex;
  flex-direction: column;
  gap: clamp(1rem, 3vmin, 1.4rem);
  color: #fffdf5;
  background: transparent;
  border: 0;
  box-shadow: none;
}

.rules-header {
  display: grid;
  gap: 0.35rem;
  justify-items: center;
}

.rules-logo {
  display: block;
  width: min(100%, 32rem);
  height: auto;
  filter:
    drop-shadow(0 0 0.08rem rgba(255, 255, 255, 0.72))
    drop-shadow(0 0.45rem 0.65rem rgba(0, 0, 0, 0.7));
}

.rules-list {
  display: grid;
  gap: 0.7rem;
  margin: 0;
  padding-left: 1.35rem;
  color: #fffdf5;
  font-size: clamp(0.95rem, 3.7vmin, 1.08rem);
  font-weight: 750;
  line-height: 1.25;
}

.rules-list li::marker {
  color: #8f8f8f;
  font-weight: 950;
}

.start-button.rules-start-button {
  margin-top: auto;
  color: #000;
  background: #fffdf5;
}

.setup-count-readout {
  min-width: 3.2rem;
  text-align: center;
  font-size: clamp(1.8rem, 8vmin, 3rem);
  font-weight: 900;
  line-height: 1;
}

.count-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 0.45rem;
  margin-bottom: 1rem;
}

.count-button,
.start-button,
.action-button,
.restart-button,
.reset-button {
  border: 0;
  border-radius: 0.45rem;
  color: var(--button-ink);
  background: var(--button);
  font-weight: 850;
  min-height: 2.85rem;
  transition:
    transform 140ms ease,
    opacity 140ms ease,
    background 140ms ease;
}

.count-button {
  background: #fff9ea;
  border: 1px solid rgba(32, 27, 22, 0.16);
}

.count-button[aria-pressed="true"] {
  color: #fffdf5;
  background: #201b16;
}

.player-form {
  display: grid;
  gap: 0.55rem;
  max-height: min(48vh, 24rem);
  overflow: auto;
  padding-right: 0.1rem;
}

.player-row {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 0.65rem;
}

.color-chip {
  width: clamp(2.25rem, 10vmin, 3rem);
  aspect-ratio: 1;
  border-radius: 50%;
  border: 0.18rem solid rgba(32, 27, 22, 0.18);
}

.player-input {
  width: 100%;
  min-height: 2.95rem;
  border: 1px solid rgba(32, 27, 22, 0.18);
  border-radius: 0.45rem;
  background: rgba(255, 255, 255, 0.6);
  color: var(--ink);
  padding: 0 0.8rem;
  font-size: 1rem;
}

.start-button {
  width: 100%;
  margin-top: 1rem;
  color: #fffdf5;
  background: #1f7a6f;
}

.setup-board-screen {
  position: relative;
  width: 100vw;
  height: 100vh;
  height: 100svh;
  height: 100dvh;
  overflow: hidden;
  background:
    linear-gradient(180deg, rgba(247, 240, 223, 0.08), transparent 32%),
    radial-gradient(circle at center, rgba(255, 255, 255, 0.08), transparent 42%),
    #171713;
  touch-action: manipulation;
  user-select: none;
}

.setup-player-layer {
  z-index: 4;
}

.setup-player-node {
  cursor: default;
}

.setup-player-node .curved-name {
  width: 148%;
  height: 148%;
}

.setup-player-node .curved-name text {
  font-size: 8.4px;
}

.setup-player-edit {
  position: absolute;
  top: 50%;
  left: 50%;
  z-index: 4;
  width: clamp(2.35rem, 10vmin, 3rem);
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  padding: 0;
  color: #fffdf5;
  border: 1px solid rgba(255, 255, 255, 0.26);
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.2);
  box-shadow:
    0 0.45rem 0.9rem rgba(0, 0, 0, 0.22),
    inset 0 0 0 1px rgba(255, 255, 255, 0.08);
  transform: translate(-50%, -50%) rotate(var(--label-rotation));
  backdrop-filter: blur(10px);
}

.setup-pencil-icon {
  width: 56%;
  height: 56%;
}

.setup-pencil-icon path {
  fill: none;
  stroke: currentColor;
  stroke-width: 2.3;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.setup-count-hub {
  position: absolute;
  top: 50%;
  left: 50%;
  z-index: 9;
  display: grid;
  place-items: center;
  transform: translate(-50%, -50%);
}

.setup-count-trigger {
  position: relative;
  width: clamp(5.2rem, 22vmin, 7rem);
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 0.05rem;
  padding: 0;
  color: #201b16;
  border: 1px solid rgba(255, 255, 255, 0.42);
  border-radius: 50%;
  background: #f7f0df;
  box-shadow:
    0 1rem 2.2rem rgba(0, 0, 0, 0.34),
    inset 0 0 0 1px rgba(32, 27, 22, 0.08);
}

.setup-count-caret {
  position: absolute;
  top: 8%;
  left: 50%;
  display: block;
  width: 0;
  height: 0;
  border-right: clamp(0.28rem, 1.3vmin, 0.42rem) solid transparent;
  border-left: clamp(0.28rem, 1.3vmin, 0.42rem) solid transparent;
  border-bottom: clamp(0.44rem, 1.8vmin, 0.6rem) solid currentColor;
  transform: translateX(-50%);
}

.setup-count-number {
  display: block;
  font-size: clamp(2.25rem, 10vmin, 3.55rem);
  font-weight: 950;
  line-height: 0.78;
}

.setup-count-label {
  display: block;
  font-size: clamp(0.68rem, 2.6vmin, 0.86rem);
  font-weight: 900;
  line-height: 1;
}

.setup-count-popover {
  position: absolute;
  bottom: calc(100% + 0.7rem);
  left: 50%;
  width: min(88vw, 22rem);
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 0.36rem;
  padding: 0.45rem;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 999px;
  background: rgba(247, 240, 223, 0.94);
  box-shadow: 0 1rem 2rem rgba(0, 0, 0, 0.32);
  transform: translateX(-50%);
}

.setup-count-option {
  min-width: 0;
  aspect-ratio: 1;
  padding: 0;
  color: #201b16;
  border: 1px solid rgba(32, 27, 22, 0.14);
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.62);
  font-size: clamp(0.88rem, 3.5vmin, 1rem);
  font-weight: 950;
}

.setup-count-option[aria-pressed="true"] {
  color: #fffdf5;
  background: #201b16;
}

.setup-play-button {
  position: absolute;
  top: calc(50% + clamp(4.4rem, 12vmin, 5rem));
  left: 50%;
  z-index: 7;
  min-width: min(72vw, 16rem);
  min-height: 3rem;
  padding: 0 1.35rem;
  color: #fffdf5;
  border: 1px solid rgba(255, 255, 255, 0.24);
  border-radius: 999px;
  background: #1f7a6f;
  box-shadow: 0 0.8rem 1.6rem rgba(0, 0, 0, 0.3);
  font-weight: 950;
  transform: translateX(-50%);
}

.setup-editor-backdrop {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding:
    max(1rem, env(safe-area-inset-top))
    max(1rem, env(safe-area-inset-right))
    max(1rem, env(safe-area-inset-bottom))
    max(1rem, env(safe-area-inset-left));
  background: rgba(0, 0, 0, 0.48);
  backdrop-filter: blur(8px);
}

.setup-editor {
  width: min(100%, 25rem);
  display: grid;
  gap: 0.65rem;
  padding: 0.85rem;
  color: #201b16;
  border: 1px solid rgba(255, 255, 255, 0.32);
  border-radius: 0.55rem;
  background: #f7f0df;
  box-shadow: var(--shadow);
}

.setup-editor-label {
  font-size: 0.9rem;
  font-weight: 950;
}

.setup-editor-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 0.5rem;
}

.setup-name-input {
  width: 100%;
  min-height: 3rem;
  border: 1px solid rgba(32, 27, 22, 0.18);
  border-radius: 0.45rem;
  background: rgba(255, 255, 255, 0.72);
  color: #201b16;
  padding: 0 0.8rem;
  font-size: 1rem;
  font-weight: 800;
}

.setup-editor-save {
  min-height: 3rem;
  padding: 0 0.9rem;
  color: #fffdf5;
  border: 0;
  border-radius: 0.45rem;
  background: #1f7a6f;
  font-weight: 950;
}

.board-screen {
  position: relative;
  width: 100vw;
  height: 100vh;
  height: 100svh;
  height: 100dvh;
  overflow: hidden;
  background:
    linear-gradient(180deg, rgba(247, 240, 223, 0.08), transparent 32%),
    radial-gradient(circle at center, rgba(255, 255, 255, 0.08), transparent 42%),
    #171713;
  touch-action: manipulation;
  user-select: none;
}

.reset-button {
  position: absolute;
  top: max(0.75rem, env(safe-area-inset-top));
  left: max(0.75rem, env(safe-area-inset-left));
  z-index: 8;
  min-height: 2.25rem;
  padding: 0 0.75rem;
  color: #fffdf5;
  background: rgba(255, 255, 255, 0.14);
  border: 1px solid rgba(255, 255, 255, 0.2);
  backdrop-filter: blur(14px);
}

.board-core {
  position: absolute;
  top: 50%;
  left: 50%;
  z-index: 2;
  width: 288px;
  width: min(70vw, 288px);
  transform: translate(-50%, -50%);
  display: grid;
  justify-items: center;
  gap: clamp(10px, 2.4vmin, 16px);
}

.roll-count {
  position: absolute;
  right: calc(100% + clamp(7px, 2vmin, 12px));
  bottom: 0;
  z-index: 4;
  min-width: 24px;
  display: grid;
  place-items: center;
  padding: 0.7rem 0.25rem;
  color: rgba(255, 253, 245, 0.86);
  font-size: clamp(0.78rem, 3.4vmin, 0.98rem);
  font-weight: 850;
  line-height: 1;
  writing-mode: vertical-rl;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  box-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.18);
  transform: rotate(180deg);
  white-space: nowrap;
}

.square-grid-frame {
  position: relative;
  z-index: 1;
  width: 140px;
  width: min(36vw, 140px);
  max-width: 100%;
  display: grid;
  justify-items: center;
}

.square-grid {
  position: relative;
  z-index: 1;
  width: 100%;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: clamp(6px, 1.6vmin, 10px);
}

.square {
  position: relative;
  z-index: 0;
  overflow: hidden;
  aspect-ratio: 1;
  container-type: size;
  display: grid;
  place-items: center;
  border: clamp(2px, 0.7vmin, 3px) solid rgba(247, 240, 223, 0.78);
  border-radius: 0.35rem;
  background: rgba(247, 240, 223, 0.05);
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.18);
  transition:
    background 220ms ease,
    transform 220ms ease,
    border-color 220ms ease;
}

.square::after {
  position: absolute;
  inset: -24%;
  content: "";
  background: linear-gradient(
    110deg,
    transparent 30%,
    rgba(255, 255, 255, 0.72) 48%,
    rgba(255, 255, 255, 0.16) 58%,
    transparent 72%
  );
  opacity: 0;
  transform: translateX(-135%) rotate(12deg);
  pointer-events: none;
}

.square.filled {
  border-color: rgba(255, 255, 255, 0.86);
  background: var(--square-color);
  transform: scale(0.94);
}

.square.action-target {
  border-style: dashed;
}

.square.square-move-fill {
  animation: squareMoveFill 180ms ease-out both;
  animation-delay: var(--move-delay);
}

.square.square-move-empty {
  animation: squareMoveEmpty 180ms ease-in both;
  animation-delay: var(--move-delay);
}

.square-number {
  --square-number-x: 0;
  position: absolute;
  inset: 0;
  z-index: 0;
  display: grid;
  place-items: center;
  color: rgba(255, 253, 245, 0.12);
  font-family: "Chakra Petch", Inter, ui-sans-serif, system-ui, sans-serif;
  font-size: 146cqb;
  font-weight: 700;
  line-height: 0.82;
  letter-spacing: 0;
  transform: translate(var(--square-number-x), -0.04em);
  pointer-events: none;
  user-select: none;
}

.square-number.is-ten {
  --square-number-x: -0.14em;
}

.square-bonus {
  position: relative;
  z-index: 1;
  display: inline-grid;
  place-items: center;
  min-width: clamp(1.35rem, 5.5vmin, 1.65rem);
  min-height: clamp(1.05rem, 4.2vmin, 1.28rem);
  padding: 0 0.18rem;
  color: #201b16;
  border: 1px solid rgba(32, 27, 22, 0.18);
  border-radius: 999px;
  background: rgba(255, 253, 245, 0.94);
  box-shadow:
    0 0.22rem 0.45rem rgba(0, 0, 0, 0.24),
    inset 0 0 0 1px rgba(255, 255, 255, 0.54);
  font-size: clamp(0.72rem, 3vmin, 0.9rem);
  font-weight: 950;
  line-height: 1;
  letter-spacing: 0;
}

.board-core.score-empty .square {
  animation: emptySquarePulse 980ms ease both;
  animation-delay: var(--square-delay);
}

.board-core.score-empty .square::after,
.board-core.score-full .square::after,
.board-core.score-impossible .square::after,
.board-core.score-bonus .square::after {
  animation: squareShimmer 960ms ease both;
  animation-delay: var(--square-delay);
}

.board-core.score-full .square.filled {
  animation: fullSquareFade 1650ms ease-in forwards;
  animation-delay: var(--square-delay);
}

.board-core.score-impossible .square-grid {
  animation: impossibleBoardShake 680ms ease both;
}

.board-core.score-impossible .square.filled {
  animation: impossibleSquareClear 1180ms ease-in forwards;
  animation-delay: 640ms;
}

.action-slot {
  width: 100%;
  min-height: 46px;
  display: grid;
  align-items: center;
}

.action-slot.is-hidden {
  pointer-events: none;
  opacity: 0;
}

.action-button {
  width: 100%;
  min-height: 46px;
  color: #fffdf5;
  background: var(--active-player-color);
  border: 1px solid rgba(255, 255, 255, 0.24);
  box-shadow: 0 0.6rem 1.3rem rgba(0, 0, 0, 0.24);
  text-shadow: 0 0.08rem 0 rgba(0, 0, 0, 0.32);
}

.action-button.empty {
  background: var(--active-player-color);
}

.action-button:disabled {
  opacity: 0.38;
  box-shadow: none;
}

.pass-note {
  min-height: 46px;
  display: grid;
  place-items: center;
  color: #fffdf5;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 0.45rem;
  background: rgba(255, 255, 255, 0.12);
}

.score-toast {
  --score-rotation: 0deg;
  position: absolute;
  top: 50%;
  left: 50%;
  z-index: 20;
  width: min(86vw, 24rem);
  transform: translate(-50%, -50%);
  pointer-events: none;
}

.score-toast-inner {
  width: 100%;
  display: grid;
  justify-items: center;
  gap: 0.5rem;
  transform: rotate(var(--score-rotation)) scale(0.86);
  transform-origin: 50% 50%;
  animation: scoreMessagePop 2200ms ease both;
}

.score-player-badge {
  max-width: min(78vw, 18rem);
  min-height: 2rem;
  display: grid;
  place-items: center;
  padding: 0.38rem 0.85rem;
  color: #fffdf5;
  text-align: center;
  font-size: clamp(0.86rem, 3.8vmin, 1.05rem);
  font-weight: 950;
  line-height: 1;
  overflow-wrap: anywhere;
  border: 1px solid rgba(255, 255, 255, 0.34);
  border-radius: 999px;
  background: var(--score-player-color);
  box-shadow: 0 0.65rem 1.4rem rgba(0, 0, 0, 0.32);
  text-shadow: 0 0.08rem 0 rgba(0, 0, 0, 0.32);
}

.score-total {
  color: #fffdf5;
  text-align: center;
  font-size: clamp(4rem, 20vmin, 7.2rem);
  font-weight: 950;
  line-height: 0.86;
  letter-spacing: 0;
  text-shadow:
    0 0.08rem 0 rgba(0, 0, 0, 0.36),
    0 0.7rem 1.6rem rgba(0, 0, 0, 0.42);
}

.score-breakdown {
  max-width: 100%;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.35rem;
}

.score-breakdown-stacked {
  flex-direction: column;
  flex-wrap: nowrap;
  align-items: center;
}

.score-pill {
  min-height: 1.85rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.28rem;
  padding: 0.34rem 0.62rem;
  color: #fffdf5;
  font-size: clamp(0.72rem, 3.1vmin, 0.92rem);
  font-weight: 950;
  line-height: 1;
  border: 1px solid rgba(255, 255, 255, 0.26);
  border-radius: 0.34rem;
  box-shadow: 0 0.45rem 1rem rgba(0, 0, 0, 0.26);
  text-shadow: 0 0.07rem 0 rgba(0, 0, 0, 0.34);
  white-space: nowrap;
}

.score-pill strong {
  font: inherit;
}

.score-pill-board {
  background: #1f7a6f;
}

.score-pill-rolls {
  background: #2b7bd6;
}

.score-pill-landing {
  background: #d89a00;
}

.score-pill-dice {
  background: #7857d8;
}

.score-dice-icons {
  display: inline-flex;
  align-items: center;
  gap: 0.08rem;
}

.score-die {
  display: block;
  width: clamp(0.82rem, 3.3vmin, 1.08rem);
  height: auto;
  filter: drop-shadow(0 0.07rem 0.08rem rgba(0, 0, 0, 0.38));
}

.player-layer {
  position: absolute;
  inset: 0;
  z-index: 5;
  pointer-events: none;
}

.player-node {
  --label-rotation: 0deg;
  position: absolute;
  width: var(--bump-w);
  height: var(--bump-h);
  display: grid;
  place-items: center;
  padding: 0;
  color: #fffdf5;
  background: var(--player-color);
  border: 0;
  border-radius: 999px;
  box-shadow:
    0 0.6rem 1.2rem rgba(0, 0, 0, 0.3),
    inset 0 0 0 1px rgba(255, 255, 255, 0.22);
  pointer-events: auto;
  transition:
    width 320ms ease,
    height 320ms ease,
    top 320ms ease,
    left 320ms ease,
    transform 320ms ease,
    border-radius 320ms ease,
    box-shadow 320ms ease;
}

.player-node:disabled {
  opacity: 1;
}

.player-node:not(.is-current) {
  cursor: default;
}

.player-node.is-current {
  width: var(--circle-size);
  height: var(--circle-size);
  border-radius: 50%;
  z-index: 7;
  box-shadow:
    0 1rem 2.8rem rgba(0, 0, 0, 0.42),
    inset 0 0 0 2px rgba(255, 255, 255, 0.24);
}

.player-node.spot-B {
  top: calc(100% - var(--bump-bottom-edge-y));
  left: 50%;
  transform: translate(-50%, -50%);
}

.player-node.spot-B.is-current {
  top: calc(100% - var(--circle-bottom-edge-y));
}

.board-screen .player-node.spot-B.is-current,
.setup-board-screen .player-node.spot-B.is-current {
  top: calc(100% - var(--circle-bottom-edge-y) + var(--bottom-current-drop));
}

.player-node.spot-T {
  top: var(--bump-edge-y);
  left: 50%;
  transform: translate(-50%, -50%);
  --label-rotation: 180deg;
}

.player-node.spot-T.is-current {
  top: var(--circle-edge-y);
}

.player-node.spot-R {
  top: 50%;
  left: calc(100% - var(--bump-edge-x));
  transform: translate(-50%, -50%);
  --label-rotation: -90deg;
}

.player-node.spot-R.is-current {
  left: calc(100% - var(--circle-edge-x));
}

.player-node.spot-L {
  top: 50%;
  left: var(--bump-edge-x);
  transform: translate(-50%, -50%);
  --label-rotation: 90deg;
}

.player-node.spot-L.is-current {
  left: var(--circle-edge-x);
}

.player-node.spot-BL {
  top: calc(100% - var(--bump-bottom-edge-y));
  left: var(--bump-edge-x);
  transform: translate(-50%, -50%);
  --label-rotation: 45deg;
}

.player-node.spot-BL.is-current {
  top: calc(100% - var(--circle-bottom-edge-y));
  left: var(--circle-edge-x);
}

.player-node.spot-BR {
  top: calc(100% - var(--bump-bottom-edge-y));
  left: calc(100% - var(--bump-edge-x));
  transform: translate(-50%, -50%);
  --label-rotation: -45deg;
}

.player-node.spot-BR.is-current {
  top: calc(100% - var(--circle-bottom-edge-y));
  left: calc(100% - var(--circle-edge-x));
}

.player-node.spot-TL {
  top: var(--bump-edge-y);
  left: var(--bump-edge-x);
  transform: translate(-50%, -50%);
  --label-rotation: 135deg;
}

.player-node.spot-TL.is-current {
  top: var(--circle-edge-y);
  left: var(--circle-edge-x);
}

.player-node.spot-TR {
  top: var(--bump-edge-y);
  left: calc(100% - var(--bump-edge-x));
  transform: translate(-50%, -50%);
  --label-rotation: -135deg;
}

.player-node.spot-TR.is-current {
  top: var(--circle-edge-y);
  left: calc(100% - var(--circle-edge-x));
}

.curved-name {
  position: absolute;
  top: 50%;
  left: 50%;
  width: calc(var(--bump-w) + 78px);
  height: calc(var(--bump-h) + 54px);
  overflow: visible;
  pointer-events: none;
  transform: translate(-50%, -50%) rotate(var(--label-rotation));
  transform-origin: 50% 50%;
  transition:
    width 320ms ease,
    height 320ms ease,
    transform 320ms ease;
}

.player-node.is-current .curved-name {
  width: 148%;
  height: 148%;
}

.board-screen .player-node.spot-B.is-current .curved-name,
.setup-board-screen .player-node.spot-B.is-current .curved-name {
  transform: translate(-50%, calc(-50% + var(--bottom-current-name-drop))) rotate(var(--label-rotation));
}

.curved-name text {
  fill: #fffdf5;
  font-size: 8px;
  font-weight: 900;
  letter-spacing: 0;
  paint-order: stroke;
  stroke: rgba(0, 0, 0, 0.28);
  stroke-width: 0.9px;
}

.player-node.is-current .curved-name text {
  font-size: 8.4px;
}

.player-score {
  position: absolute;
  --score-local-y: 0px;
  top: 50%;
  left: 50%;
  z-index: 2;
  color: #fffdf5;
  font-size: clamp(1rem, 4.4vmin, 1.25rem);
  font-weight: 950;
  line-height: 1;
  letter-spacing: 0;
  text-shadow: 0 0.08rem 0 rgba(0, 0, 0, 0.3);
  transform: translate(-50%, -50%) rotate(var(--label-rotation)) translateY(var(--score-local-y));
  pointer-events: none;
}

.player-node.is-current .player-score {
  --score-local-y: clamp(26px, 7.1vmin, 39px);
  z-index: 4;
  font-size: clamp(0.86rem, 3.6vmin, 1.02rem);
}

.player-roll-history {
  --history-gap: 0.68rem;
  --history-x: 50%;
  --history-y: calc(100% + var(--history-gap));
  position: absolute;
  top: var(--history-y);
  left: var(--history-x);
  z-index: 5;
  min-width: max-content;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.16rem;
  color: rgba(255, 253, 245, 0.86);
  font-size: clamp(0.48rem, 1.9vmin, 0.64rem);
  font-weight: 900;
  line-height: 1;
  text-shadow: 0 0.07rem 0 rgba(0, 0, 0, 0.34);
  transform: translate(-50%, -50%) rotate(var(--label-rotation));
  pointer-events: none;
}

.player-roll-history.has-faded-old-rolls {
  -webkit-mask-image: linear-gradient(
    90deg,
    #000 0%,
    #000 54%,
    rgba(0, 0, 0, 0.96) 78%,
    rgba(0, 0, 0, 0.92) 100%
  );
  mask-image: linear-gradient(
    90deg,
    #000 0%,
    #000 54%,
    rgba(0, 0, 0, 0.96) 78%,
    rgba(0, 0, 0, 0.92) 100%
  );
}

.player-roll-history span {
  min-width: 0.42rem;
  text-align: center;
}

.player-roll-history .is-faded-roll {
  opacity: 0.98;
}

.player-roll-history .is-faded-roll:last-child {
  opacity: 0.95;
}

.player-roll-history .is-match-two {
  color: #f7d84d;
  text-shadow:
    0 0 0.35rem rgba(247, 216, 77, 0.35),
    0 0.07rem 0 rgba(0, 0, 0, 0.45);
}

.player-roll-history .is-match-hot {
  color: #4dff7a;
  text-shadow:
    0 0 0.35rem rgba(77, 255, 122, 0.38),
    0 0.07rem 0 rgba(0, 0, 0, 0.45);
}

.player-node.is-current .player-roll-history {
  --history-gap: 0.78rem;
  font-size: clamp(0.52rem, 2.1vmin, 0.68rem);
}

.player-node.spot-T .player-roll-history {
  --history-y: calc(0% - var(--history-gap));
}

.player-node.spot-R .player-roll-history {
  --history-x: calc(100% + var(--history-gap));
  --history-y: 50%;
}

.player-node.spot-L .player-roll-history {
  --history-x: calc(0% - var(--history-gap));
  --history-y: 50%;
}

.player-node.spot-BL .player-roll-history {
  --history-x: calc(0% - var(--history-gap) + var(--history-corner-inset));
  --history-y: calc(100% + var(--history-gap) - var(--history-corner-inset));
}

.player-node.spot-BR .player-roll-history {
  --history-x: calc(100% + var(--history-gap) - var(--history-corner-inset));
  --history-y: calc(100% + var(--history-gap) - var(--history-corner-inset));
}

.player-node.spot-TL .player-roll-history {
  --history-x: calc(0% - var(--history-gap) + var(--history-corner-inset));
  --history-y: calc(0% - var(--history-gap) + var(--history-corner-inset));
}

.player-node.spot-TR .player-roll-history {
  --history-x: calc(100% + var(--history-gap) - var(--history-corner-inset));
  --history-y: calc(0% - var(--history-gap) + var(--history-corner-inset));
}

.dice-stage {
  position: absolute;
  top: 50%;
  left: 50%;
  z-index: 3;
  width: 42%;
  aspect-ratio: 1;
  transform: translate(-50%, -50%) rotate(var(--label-rotation));
}

.dice {
  position: absolute;
  inset: 0;
}

.die-box {
  border-radius: 0.38rem;
  background: #fffdf5;
  box-shadow:
    0 0.45rem 1rem rgba(0, 0, 0, 0.25),
    inset 0 0 0 1px rgba(32, 27, 22, 0.12);
}

.die-box.rolling {
  animation: diceRoll 90ms linear infinite;
}

.die-box.fading {
  animation: diceFade 620ms ease forwards;
}

.pip-imprint {
  opacity: 0;
  animation: imprintIn 520ms ease 160ms forwards;
}

.pip {
  position: absolute;
  width: 19%;
  aspect-ratio: 1;
  border-radius: 50%;
  background: var(--pip-color, #201b16);
  transform: translate(-50%, -50%);
}

.die-box .pip {
  --pip-color: var(--player-color);
}

.pip-imprint .pip {
  --pip-color: #fffdf5;
}

.pip.tl {
  top: 24%;
  left: 24%;
}

.pip.tc {
  top: 24%;
  left: 50%;
}

.pip.tr {
  top: 24%;
  left: 76%;
}

.pip.ml {
  top: 50%;
  left: 24%;
}

.pip.mc {
  top: 50%;
  left: 50%;
}

.pip.mr {
  top: 50%;
  left: 76%;
}

.pip.bl {
  top: 76%;
  left: 24%;
}

.pip.bc {
  top: 76%;
  left: 50%;
}

.pip.br {
  top: 76%;
  left: 76%;
}

.end-screen {
  display: grid;
  place-items: center;
  overflow: auto;
  padding:
    max(1rem, env(safe-area-inset-top))
    max(1rem, env(safe-area-inset-right))
    max(1rem, env(safe-area-inset-bottom))
    max(1rem, env(safe-area-inset-left));
  background:
    linear-gradient(145deg, rgba(54, 174, 151, 0.18), transparent 34%),
    linear-gradient(315deg, rgba(247, 207, 90, 0.14), transparent 36%),
    #171713;
}

.leaderboard {
  width: calc(100vw - 2rem);
  max-width: 35rem;
}

.winner-title {
  margin: 0 0 0.9rem;
  color: #fffdf5;
  font-size: clamp(2rem, 11vmin, 4.5rem);
  line-height: 0.9;
  text-align: center;
}

.leaderboard-list {
  display: grid;
  gap: 0.55rem;
}

.leader-row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 0.8rem;
  min-height: 3.65rem;
  padding: 0.6rem 0.8rem;
  color: #fffdf5;
  border-radius: 0.45rem;
  box-shadow: 0 0.6rem 1.3rem rgba(0, 0, 0, 0.24);
}

.leader-rank,
.leader-score {
  font-weight: 950;
  font-size: 1.3rem;
}

.leader-name {
  min-width: 0;
  overflow-wrap: anywhere;
  font-weight: 850;
}

.restart-button {
  width: 100%;
  margin-top: 1rem;
  color: #201b16;
  background: #fff6df;
}

@keyframes diceRoll {
  0% {
    transform: rotate(-8deg) scale(0.96);
  }

  100% {
    transform: rotate(8deg) scale(1.04);
  }
}

@keyframes diceFade {
  0% {
    opacity: 1;
    transform: scale(1);
  }

  100% {
    opacity: 0;
    transform: scale(1.35);
  }
}

@keyframes imprintIn {
  0% {
    opacity: 0;
    transform: scale(0.7);
  }

  100% {
    opacity: 1;
    transform: scale(1);
  }
}

@keyframes squareShimmer {
  0% {
    opacity: 0;
    transform: translateX(-135%) rotate(12deg);
  }

  26% {
    opacity: 0.95;
  }

  100% {
    opacity: 0;
    transform: translateX(135%) rotate(12deg);
  }
}

@keyframes squareMoveFill {
  0% {
    border-color: rgba(247, 240, 223, 0.78);
    background: rgba(247, 240, 223, 0.05);
    transform: scale(1);
  }

  100% {
    border-color: rgba(255, 255, 255, 0.86);
    background: var(--square-color);
    transform: scale(0.94);
  }
}

@keyframes squareMoveEmpty {
  0% {
    border-color: rgba(255, 255, 255, 0.86);
    background: var(--square-color);
    transform: scale(0.94);
  }

  100% {
    border-color: rgba(247, 240, 223, 0.78);
    background: rgba(247, 240, 223, 0.05);
    transform: scale(1);
  }
}

@keyframes emptySquarePulse {
  0% {
    border-color: rgba(247, 240, 223, 0.78);
    background: rgba(247, 240, 223, 0.05);
  }

  45% {
    border-color: rgba(215, 241, 240, 0.96);
    background: rgba(215, 241, 240, 0.17);
  }

  100% {
    border-color: rgba(247, 240, 223, 0.78);
    background: rgba(247, 240, 223, 0.05);
  }
}

@keyframes fullSquareFade {
  0% {
    border-color: rgba(255, 255, 255, 0.86);
    background: var(--square-color);
  }

  62% {
    border-color: rgba(255, 255, 255, 0.78);
  }

  100% {
    border-color: rgba(247, 240, 223, 0.42);
    background: #050504;
  }
}

@keyframes impossibleBoardShake {
  0%,
  100% {
    transform: translateX(0);
  }

  14% {
    transform: translateX(-7px);
  }

  28% {
    transform: translateX(7px);
  }

  42% {
    transform: translateX(-5px);
  }

  56% {
    transform: translateX(5px);
  }

  70% {
    transform: translateX(-3px);
  }

  84% {
    transform: translateX(3px);
  }
}

@keyframes impossibleSquareClear {
  0% {
    border-color: rgba(255, 255, 255, 0.86);
    background: var(--square-color);
    transform: scale(0.94);
  }

  58% {
    border-color: rgba(255, 255, 255, 0.72);
    background: #302f29;
  }

  100% {
    border-color: rgba(247, 240, 223, 0.78);
    background: rgba(247, 240, 223, 0.05);
    transform: scale(1);
  }
}

@keyframes scoreMessagePop {
  0% {
    transform: rotate(var(--score-rotation)) scale(0.86);
  }

  16%,
  84% {
    transform: rotate(var(--score-rotation)) scale(1);
  }

  100% {
    transform: rotate(var(--score-rotation)) scale(1);
  }
}

@media (prefers-reduced-motion: reduce) {
  .board-core.score-empty .square,
  .board-core.score-full .square.filled,
  .board-core.score-impossible .square-grid,
  .board-core.score-impossible .square.filled,
  .square.square-move-fill,
  .square.square-move-empty,
  .board-core.score-empty .square::after,
  .board-core.score-full .square::after,
  .board-core.score-impossible .square::after,
  .board-core.score-bonus .square::after,
  .score-toast-inner {
    animation-duration: 1ms;
    animation-delay: 0ms;
  }
}

@media (orientation: landscape) {
  .orientation-notice {
    display: inline-flex;
  }

  .board-core {
    width: 448px;
    width: min(54vw, 448px);
  }

  .action-slot {
    min-height: 42px;
  }
}

@media (min-width: 700px) and (min-height: 560px) {
  .setup-play-button {
    top: calc(50% - clamp(6.8rem, 18vmin, 8.6rem));
  }
}

@media (max-height: 680px) and (orientation: portrait) {
  :root {
    --circle-size: clamp(72px, 20vmin, 96px);
  }

  .action-button {
    min-height: 42px;
  }

  .action-slot {
    min-height: 42px;
  }
}

@media (max-width: 480px) {
  .count-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}
