:root {
  --ink: #10151f;
  --blue: #147fc0;
  --deep: #05385f;
  --paper: #fffdf3;
  --red: #f23d31;
  --yellow: #ffd83b;
  --green: #62c646;
  --cream: #fffbed;
  --shadow: 0 24px 70px rgba(1, 20, 37, 0.38);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  overflow: hidden;
  font-family: Arial, Helvetica, sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at 16% 10%, rgba(255, 216, 59, 0.22), transparent 24rem),
    radial-gradient(circle at 88% 80%, rgba(98, 198, 70, 0.18), transparent 24rem),
    linear-gradient(135deg, #0e8ed0 0%, #09609d 48%, #052b4e 100%);
}

button,
input {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.58;
}

.game {
  width: min(100vw, 1240px);
  height: 100dvh;
  margin: 0 auto;
  padding: 8px;
  display: grid;
  grid-template-rows: auto auto;
  align-content: center;
  gap: 8px;
  overflow: hidden;
}

.board {
  position: relative;
  width: min(calc(100dvh - 120px), calc(100vw - 16px), 760px);
  aspect-ratio: 1;
  margin: 0 auto;
  overflow: hidden;
  border-radius: 8px;
  background: var(--paper);
  box-shadow: var(--shadow);
  user-select: none;
}

.board::after {
  content: "";
  position: absolute;
  inset: 0;
  border: 7px solid #052944;
  border-radius: 8px;
  pointer-events: none;
  z-index: 7;
}

.cells {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-columns: repeat(10, 1fr);
  grid-template-rows: repeat(10, 1fr);
  border: 2px solid rgba(0, 0, 0, 0.72);
  z-index: 1;
}

.cell {
  position: relative;
  padding: clamp(4px, 0.72vw, 8px);
  border-right: 1px solid rgba(0, 0, 0, 0.52);
  border-bottom: 1px solid rgba(0, 0, 0, 0.52);
  background:
    linear-gradient(140deg, rgba(255, 255, 255, 0.2), rgba(0, 0, 0, 0.05)),
    var(--cell);
}

.cell:nth-child(10n) {
  border-right: 0;
}

.cell:nth-last-child(-n + 10) {
  border-bottom: 0;
}

.cell.red {
  --cell: #ef3b34;
  color: #fff;
}

.cell.yellow {
  --cell: #f4d936;
  color: #111827;
}

.cell.green {
  --cell: #62c646;
  color: #fff;
}

.cell.blue {
  --cell: #208fc9;
  color: #fff;
}

.cell.cream {
  --cell: #fffbed;
  color: #111827;
}

.num {
  position: relative;
  z-index: 3;
  display: block;
  font-size: clamp(0.95rem, 2.65vw, 1.92rem);
  line-height: 1;
  font-weight: 900;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.2);
}

.cell.win::after {
  content: "WIN";
  position: absolute;
  right: 7px;
  bottom: 7px;
  padding: 2px 6px;
  border-radius: 6px;
  color: #754500;
  background: #ffe068;
  font-size: clamp(0.56rem, 1.3vw, 0.82rem);
  font-weight: 900;
  box-shadow: inset 0 -2px 0 rgba(0, 0, 0, 0.18);
}

.art {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
  pointer-events: none;
  z-index: 3;
}

.ladder-rail {
  stroke: #80470e;
  stroke-width: 1.22;
  stroke-linecap: round;
  filter: drop-shadow(0 0.8px 0 rgba(0, 0, 0, 0.45));
}

.ladder-rung {
  stroke: #ffdb55;
  stroke-width: 0.86;
  stroke-linecap: round;
}

.snake-path {
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
  filter: drop-shadow(0 1px 0 rgba(0, 0, 0, 0.48));
}

.snake-shine {
  fill: none;
  stroke: rgba(255, 255, 255, 0.32);
  stroke-linecap: round;
}

.snake-head {
  stroke: rgba(0, 0, 0, 0.54);
  stroke-width: 0.35;
}

.snake-eye {
  fill: #fff;
  stroke: rgba(0, 0, 0, 0.56);
  stroke-width: 0.22;
}

.snake-pupil {
  fill: #111827;
}

.snake-tongue {
  fill: none;
  stroke: #d81721;
  stroke-width: 0.36;
  stroke-linecap: round;
  opacity: 0;
}

.snake-bite .snake-head,
.snake-bite .snake-tongue {
  animation: bite 520ms ease;
}

.flash {
  position: absolute;
  width: 10%;
  height: 10%;
  border: 3px solid rgba(255, 255, 255, 0.95);
  border-radius: 8px;
  transform: translate(-50%, -50%);
  opacity: 0;
  pointer-events: none;
  box-shadow: 0 0 0 4px rgba(0, 0, 0, 0.16);
  z-index: 4;
}

.flash.show {
  opacity: 1;
}

.pawn {
  position: absolute;
  width: clamp(20px, 3.4vw, 36px);
  aspect-ratio: 1;
  border: 3px solid rgba(0, 0, 0, 0.74);
  border-radius: 50%;
  transform: translate(-50%, -50%);
  box-shadow:
    inset -6px -7px 0 rgba(0, 0, 0, 0.18),
    inset 5px 5px 0 rgba(255, 255, 255, 0.42),
    0 9px 16px rgba(0, 0, 0, 0.28);
  transition:
    left 340ms cubic-bezier(0.19, 0.95, 0.26, 1),
    top 340ms cubic-bezier(0.19, 0.95, 0.26, 1);
  z-index: 6;
}

.pawn::after {
  content: "";
  position: absolute;
  top: 18%;
  left: 22%;
  width: 28%;
  aspect-ratio: 1;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.42);
}

.pawn-red {
  background: linear-gradient(145deg, #ff5b4b, #ce1818);
}

.pawn-yellow {
  background: linear-gradient(145deg, #ffe766, #d9a700);
}

.pawn.step {
  animation: hop 320ms ease;
}

.pawn.climb {
  animation: climb 620ms ease;
}

.pawn.bitten {
  animation: bitten 650ms ease;
}

.pawn.win {
  animation: win 850ms ease infinite;
}

.bar {
  width: min(100%, 980px);
  min-height: 82px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: minmax(190px, 1fr) minmax(250px, 360px) minmax(190px, 1fr);
  gap: 8px;
}

.player,
.roll {
  border-radius: 8px;
  box-shadow: 0 12px 28px rgba(2, 24, 45, 0.22);
}

.player {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.92), rgba(255, 251, 237, 0.84)),
    var(--paper);
  border: 3px solid transparent;
  backdrop-filter: blur(10px);
}

.player.active {
  border-color: #25aef2;
  box-shadow:
    0 12px 28px rgba(2, 24, 45, 0.22),
    0 0 0 4px rgba(37, 174, 242, 0.18);
}

.dot {
  flex: 0 0 auto;
  width: 28px;
  aspect-ratio: 1;
  border-radius: 50%;
  border: 2px solid rgba(0, 0, 0, 0.68);
  box-shadow:
    inset -4px -5px 0 rgba(0, 0, 0, 0.15),
    inset 3px 3px 0 rgba(255, 255, 255, 0.38);
}

.dot.red {
  background: var(--red);
}

.dot.yellow {
  background: var(--yellow);
}

.player-copy {
  min-width: 0;
  display: grid;
  gap: 2px;
}

.player b,
.player small {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.player b {
  font-size: 1.1rem;
  line-height: 1.1;
}

.player small {
  color: #5b6472;
  font-weight: 900;
  font-size: 0.92rem;
}

.roll {
  min-width: 0;
  display: grid;
  grid-template-columns: 72px minmax(0, 1fr);
  align-items: center;
  gap: 14px;
  padding: 10px 14px;
  color: #fff;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.14), transparent),
    linear-gradient(135deg, #075792, #1494dd);
  font-weight: 900;
  text-align: left;
  border: 2px solid rgba(255, 255, 255, 0.16);
}

.roll .dice {
  justify-self: center;
}

.roll:not(:disabled):active .dice {
  transform: translateY(4px);
}

.dice {
  width: 60px;
  aspect-ratio: 1;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  gap: 4px;
  padding: 9px;
  border-radius: 8px;
  background: #fff;
  box-shadow:
    inset -4px -5px 0 rgba(0, 0, 0, 0.14),
    0 8px 15px rgba(0, 0, 0, 0.22);
}

.roll-copy {
  min-width: 0;
  display: grid;
  gap: 2px;
}

.roll-copy b,
.roll-copy small {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.roll-copy b {
  font-size: 1.1rem;
  line-height: 1.1;
}

.roll-copy small {
  color: rgba(255, 255, 255, 0.84);
  font-size: 0.92rem;
  font-weight: 900;
}

.dice.rollit {
  animation: dice 700ms cubic-bezier(0.2, 0.85, 0.2, 1);
}

.dice i {
  border-radius: 50%;
  background: transparent;
}

.dice[data-face="1"] i:nth-child(5),
.dice[data-face="2"] i:nth-child(1),
.dice[data-face="2"] i:nth-child(9),
.dice[data-face="3"] i:nth-child(1),
.dice[data-face="3"] i:nth-child(5),
.dice[data-face="3"] i:nth-child(9),
.dice[data-face="4"] i:nth-child(1),
.dice[data-face="4"] i:nth-child(3),
.dice[data-face="4"] i:nth-child(7),
.dice[data-face="4"] i:nth-child(9),
.dice[data-face="5"] i:nth-child(1),
.dice[data-face="5"] i:nth-child(3),
.dice[data-face="5"] i:nth-child(5),
.dice[data-face="5"] i:nth-child(7),
.dice[data-face="5"] i:nth-child(9),
.dice[data-face="6"] i:nth-child(1),
.dice[data-face="6"] i:nth-child(3),
.dice[data-face="6"] i:nth-child(4),
.dice[data-face="6"] i:nth-child(6),
.dice[data-face="6"] i:nth-child(7),
.dice[data-face="6"] i:nth-child(9) {
  background: #111827;
}

.gate {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 16px;
  background: linear-gradient(135deg, #0e8ed0 0%, #09609d 48%, #052b4e 100%);
}

.gate[hidden],
.bar[hidden],
.share[hidden],
#notice[hidden] {
  display: none !important;
}

.panel {
  width: min(410px, 100%);
  display: grid;
  gap: 10px;
  padding: 18px;
  border-radius: 8px;
  background: var(--paper);
  box-shadow: var(--shadow);
}

.panel h1 {
  margin: 0 0 2px;
  color: #f6ca1d;
  font-size: clamp(2.2rem, 9vw, 3.25rem);
  line-height: 0.92;
  text-shadow:
    2px 2px 0 #10151f,
    0 5px 0 #1171aa;
}

.panel input {
  width: 100%;
  min-height: 48px;
  padding: 0 12px;
  border: 2px solid rgba(5, 56, 95, 0.22);
  border-radius: 8px;
  outline: 0;
}

.panel input:focus {
  border-color: #169ce2;
  box-shadow: 0 0 0 4px rgba(22, 156, 226, 0.16);
}

.panel button {
  min-height: 48px;
  border-radius: 8px;
  font-weight: 900;
}

#playFriend,
#practice {
  color: #13200f;
  background: linear-gradient(135deg, #8dec55, #4bb52f);
  box-shadow: 0 7px 0 #2c741c;
}

#practice {
  color: #05385f;
  background: #eaf7ff;
  box-shadow: inset 0 0 0 2px rgba(5, 56, 95, 0.18);
}

.share {
  display: grid;
  gap: 8px;
}

#copyLink {
  color: #fff;
  background: linear-gradient(135deg, #147fc0, #05385f);
}

#notice {
  margin: 0;
  color: #5b6472;
  font-weight: 800;
}

@keyframes dice {
  0% {
    transform: translateX(0) rotate(0deg) scale(1);
  }

  25% {
    transform: translateX(18px) rotate(95deg) scale(1.06);
  }

  50% {
    transform: translateX(-8px) rotate(205deg) scale(0.98);
  }

  78% {
    transform: translateX(8px) rotate(310deg) scale(1.04);
  }

  100% {
    transform: translateX(0) rotate(360deg) scale(1);
  }
}

@keyframes hop {
  0%,
  100% {
    margin-top: 0;
  }

  50% {
    margin-top: -12px;
  }
}

@keyframes climb {
  0%,
  100% {
    filter: brightness(1);
  }

  45% {
    filter: brightness(1.35);
  }
}

@keyframes bitten {
  0%,
  100% {
    transform: translate(-50%, -50%) rotate(0deg);
  }

  18% {
    transform: translate(-46%, -47%) rotate(18deg);
  }

  38% {
    transform: translate(-55%, -55%) rotate(-22deg);
  }

  62% {
    transform: translate(-48%, -46%) rotate(12deg);
  }
}

@keyframes win {
  0%,
  100% {
    filter: brightness(1);
  }

  50% {
    filter: brightness(1.45) drop-shadow(0 0 12px rgba(255, 216, 59, 0.8));
  }
}

@keyframes bite {
  0%,
  100% {
    transform: scale(1);
    opacity: 1;
  }

  50% {
    transform: scale(1.2);
    opacity: 1;
  }
}

@media (max-width: 860px) {
  .game {
    grid-template-rows: auto auto;
  }

  .board {
    width: min(calc(100dvh - 220px), calc(100vw - 16px));
  }

  .bar {
    grid-template-columns: 1fr 1fr;
  }

  .roll {
    min-height: 62px;
  }

  .roll {
    grid-template-columns: 72px minmax(0, 1fr);
  }
}

@media (max-width: 520px) {
  .bar {
    grid-template-columns: 1fr;
  }

  .board {
    width: min(calc(100dvh - 320px), calc(100vw - 16px));
  }
}
