:root {
  --bg-1: #061523;
  --bg-2: #0d3249;
  --bg-3: #20526e;
  --ink: #e8f7ff;
  --muted: #9fc6da;
  --accent: #7cf4d9;
  --accent-2: #ffd58a;
  --danger: #ff8aa0;
  --card: rgba(7, 20, 33, 0.86);
  --border: rgba(138, 205, 236, 0.24);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font-family: "Space Grotesk", "Segoe UI", sans-serif;
  background: radial-gradient(1000px 700px at 7% 0%, #1c6d90 0%, transparent 60%),
    radial-gradient(900px 500px at 92% 8%, #2a607f 0%, transparent 64%),
    linear-gradient(160deg, var(--bg-1) 12%, var(--bg-2) 55%, var(--bg-3) 100%);
}

.shell {
  width: min(1450px, 95vw);
  margin: 0 auto;
  padding: 1rem 0 1.6rem;
}

.hero {
  position: relative;
  padding: 0.95rem 1.1rem;
  padding-right: min(44vw, 360px);
  border-radius: 18px;
  border: 1px solid var(--border);
  background: linear-gradient(130deg, rgba(6, 21, 35, 0.8), rgba(20, 63, 84, 0.52)),
    url("../img/ladder-banner.svg");
  background-size: cover, min(640px, 46vw);
  background-repeat: no-repeat;
  background-position: 0 0, right -8px center;
  box-shadow: 0 16px 35px rgba(4, 11, 18, 0.3);
}

.eyebrow {
  margin: 0;
  color: var(--accent);
  font-size: 0.8rem;
  letter-spacing: 0.15em;
  text-transform: uppercase;
}

h1 {
  margin: 0.1rem 0 0;
  font-family: "Sora", "Space Grotesk", sans-serif;
  font-size: clamp(1.9rem, 4.8vw, 3.1rem);
}

.subtitle {
  margin: 0.45rem 0 0;
  color: var(--muted);
  max-width: 74ch;
  line-height: 1.46;
}

.link-line {
  margin: 0.55rem 0 0;
}

.link-line a {
  color: var(--accent);
  text-decoration: none;
  font-weight: 600;
}

.link-line a:hover {
  text-decoration: underline;
}

.layout {
  margin-top: 1rem;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 390px;
  gap: 1rem;
  align-items: start;
}

.board-card,
.control-card {
  border-radius: 20px;
  border: 1px solid var(--border);
  background: var(--card);
  box-shadow: 0 18px 40px rgba(3, 10, 18, 0.27);
}

.board-card {
  padding: 0.9rem;
  background: linear-gradient(180deg, rgba(8, 24, 40, 0.87), rgba(10, 29, 45, 0.86)),
    url("../img/med-grid.svg");
  background-size: cover, 220px;
  background-repeat: no-repeat, repeat;
}

.board-meta {
  display: flex;
  gap: 0.8rem;
  flex-wrap: wrap;
  margin-bottom: 0.65rem;
}

.board-meta p {
  margin: 0;
  font-size: 0.9rem;
  color: var(--muted);
}

.dice-panel {
  margin-left: auto;
  border-radius: 12px;
  border: 1px solid rgba(146, 213, 242, 0.3);
  background: rgba(7, 24, 39, 0.72);
  padding: 0.4rem 0.5rem;
  min-width: 100px;
  display: grid;
  justify-items: center;
  gap: 0.2rem;
}

.dice-label,
.dice-readout {
  margin: 0;
  font-size: 0.72rem;
  color: var(--muted);
}

.dice-face {
  width: 56px;
  height: 56px;
  border-radius: 13px;
  border: 1px solid rgba(180, 218, 238, 0.5);
  background: linear-gradient(140deg, #e8f7ff, #c9eafd 75%);
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  place-items: center;
  box-shadow: 0 8px 20px rgba(4, 15, 24, 0.35), 0 0 0 1px rgba(7, 32, 49, 0.2) inset;
  transition: transform 130ms ease, filter 130ms ease;
}

.dice-face.tap-roll-ready {
  cursor: pointer;
  box-shadow:
    0 8px 20px rgba(4, 15, 24, 0.35),
    0 0 0 1px rgba(7, 32, 49, 0.2) inset,
    0 0 0 2px rgba(124, 244, 217, 0.58);
}

.dice-face.rolling {
  animation: dice-roll 620ms cubic-bezier(0.24, 0.74, 0.31, 1) infinite;
  filter: saturate(1.06);
}

.pip {
  width: 9px;
  height: 9px;
  border-radius: 999px;
  background: #0a2c42;
  opacity: 0;
  transform: scale(0.7);
}

.dice-face.v1 .p5,
.dice-face.v2 .p1,
.dice-face.v2 .p9,
.dice-face.v3 .p1,
.dice-face.v3 .p5,
.dice-face.v3 .p9,
.dice-face.v4 .p1,
.dice-face.v4 .p3,
.dice-face.v4 .p7,
.dice-face.v4 .p9,
.dice-face.v5 .p1,
.dice-face.v5 .p3,
.dice-face.v5 .p5,
.dice-face.v5 .p7,
.dice-face.v5 .p9,
.dice-face.v6 .p1,
.dice-face.v6 .p3,
.dice-face.v6 .p4,
.dice-face.v6 .p6,
.dice-face.v6 .p7,
.dice-face.v6 .p9 {
  opacity: 1;
  transform: scale(1);
}

.board-stage {
  width: 100%;
  aspect-ratio: 1 / 1;
  position: relative;
  border-radius: 14px;
  overflow: hidden;
  background: radial-gradient(260px 210px at 18% 18%, rgba(124, 244, 217, 0.12), transparent 78%),
    radial-gradient(340px 260px at 82% 84%, rgba(255, 138, 160, 0.13), transparent 76%),
    rgba(5, 17, 29, 0.85);
}

.board-overlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
}

.board-overlay .ladder-rail {
  stroke: #f7e3ba;
  stroke-width: 9;
  stroke-linecap: round;
}

.board-overlay .ladder-rung {
  stroke: #f5cca2;
  stroke-width: 6;
  stroke-linecap: round;
}

.board-overlay .snake-track {
  fill: none;
  stroke-width: 26;
  stroke-linecap: round;
}

.board-overlay .snake-stripe {
  fill: rgba(245, 248, 255, 0.34);
}

.board-overlay .snake-head {
  stroke: rgba(6, 15, 25, 0.6);
  stroke-width: 2;
}

.board-grid {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-columns: repeat(10, minmax(0, 1fr));
  grid-template-rows: repeat(10, minmax(0, 1fr));
  gap: 2px;
  background: rgba(154, 219, 248, 0.18);
  z-index: 2;
}

.board-grid.tap-roll-ready,
.board-overlay.tap-roll-ready {
  cursor: pointer;
}

.cell {
  position: relative;
  background: linear-gradient(180deg, rgba(12, 34, 52, 0.62), rgba(8, 24, 38, 0.66));
  padding: 0.1rem;
}

.cell:nth-child(odd) {
  background: linear-gradient(180deg, rgba(17, 46, 70, 0.6), rgba(11, 30, 47, 0.66));
}

.cell.pulse-step {
  animation: step-cell-pulse 220ms ease;
}

.cell.pulse-ladder {
  animation: ladder-cell-pulse 280ms ease;
}

.cell.pulse-snake {
  animation: snake-cell-pulse 280ms ease;
}

.cell-num {
  position: absolute;
  top: 2px;
  left: 3px;
  font-size: clamp(0.52rem, 1.2vw, 0.72rem);
  color: rgba(238, 246, 252, 0.83);
  text-shadow: 0 1px 1px rgba(4, 11, 18, 0.8);
}

.cell-tag {
  position: absolute;
  right: 3px;
  top: 2px;
  font-size: clamp(0.45rem, 1vw, 0.62rem);
  font-weight: 700;
}

.cell-tag.ladder {
  color: transparent;
  width: 13px;
  height: 13px;
  display: inline-block;
  overflow: hidden;
  text-indent: -9999px;
  background: url("../img/icon-ladder.svg") no-repeat center / contain;
}

.cell-tag.snake {
  color: transparent;
  width: 13px;
  height: 13px;
  display: inline-block;
  overflow: hidden;
  text-indent: -9999px;
  background: url("../img/icon-snake.svg") no-repeat center / contain;
}

.token-wrap {
  position: absolute;
  inset: 0;
  display: flex;
  flex-wrap: wrap;
  align-content: flex-end;
  gap: 2px;
  padding: 2px;
}

.token {
  min-width: 18px;
  height: 18px;
  border-radius: 999px;
  font-size: 0.62rem;
  color: #051523;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
  border: 1px solid rgba(255, 255, 255, 0.55);
  box-shadow: 0 0 0 1px rgba(8, 24, 35, 0.45) inset;
}

.token.moving {
  animation: token-hop 180ms ease;
}

.legend {
  display: flex;
  gap: 0.9rem;
  flex-wrap: wrap;
  margin-top: 0.6rem;
  font-size: 0.84rem;
  color: var(--muted);
}

.legend-chip {
  width: 12px;
  height: 12px;
  border-radius: 3px;
  display: inline-block;
  margin-right: 0.26rem;
}

.legend-chip.ladder {
  width: 14px;
  height: 14px;
  background: url("../img/icon-ladder.svg") no-repeat center / contain;
  border-radius: 0;
}

.legend-chip.snake {
  width: 14px;
  height: 14px;
  background: url("../img/icon-snake.svg") no-repeat center / contain;
  border-radius: 0;
}

.legend-chip.token {
  background: var(--accent-2);
  border-radius: 999px;
}

.control-card {
  padding: 0.9rem;
  display: grid;
  gap: 0.65rem;
  align-content: start;
  position: sticky;
  top: 0.7rem;
  max-height: calc(100dvh - 1.4rem);
  overflow: auto;
  scrollbar-gutter: stable;
  background: linear-gradient(180deg, rgba(8, 24, 40, 0.9), rgba(10, 26, 42, 0.85)),
    url("../img/med-grid.svg");
  background-size: cover, 210px;
  background-repeat: no-repeat, repeat;
}

.control-block {
  border-radius: 14px;
  border: 1px solid rgba(138, 205, 236, 0.2);
  background: rgba(8, 22, 37, 0.62);
  padding: 0.72rem;
}

.control-block h2 {
  margin: 0 0 0.55rem;
  font-family: "Sora", "Space Grotesk", sans-serif;
  font-size: 1.02rem;
}

label {
  display: grid;
  gap: 0.3rem;
  color: var(--muted);
  font-size: 0.84rem;
  margin-bottom: 0.5rem;
}

input,
select,
button {
  font: inherit;
}

input,
select {
  width: 100%;
  border-radius: 10px;
  border: 1px solid rgba(136, 198, 226, 0.32);
  background: rgba(16, 33, 49, 0.84);
  color: var(--ink);
  padding: 0.5rem 0.58rem;
}

.row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.5rem;
}

.join-wrap {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.4rem;
}

button {
  border: 0;
  border-radius: 10px;
  padding: 0.55rem 0.7rem;
  color: #072131;
  background: linear-gradient(120deg, var(--accent), #a8ffd8 80%);
  font-weight: 700;
  cursor: pointer;
  transition: transform 110ms ease, filter 110ms ease;
}

button:hover {
  transform: translateY(-1px);
  filter: brightness(1.04);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
  transform: none;
}

.secondary-btn {
  background: linear-gradient(120deg, var(--accent-2), #ffe7b7 80%);
}

.mode-toggle {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.45rem;
}

.mode-btn {
  background: linear-gradient(120deg, #99e7ff, #c7f4ff 75%);
}

.mode-btn.active {
  box-shadow: 0 0 0 2px rgba(125, 244, 217, 0.42) inset;
}

.sound-btn {
  margin-top: 0.25rem;
  width: 100%;
}

.hidden {
  display: none;
}

body.question-modal-open {
  overflow: hidden;
}

.question-modal {
  position: fixed;
  inset: 0;
  z-index: 1400;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding:
    max(0.85rem, env(safe-area-inset-top))
    max(0.85rem, env(safe-area-inset-right))
    max(0.85rem, env(safe-area-inset-bottom))
    max(0.85rem, env(safe-area-inset-left));
  background: rgba(3, 12, 21, 0.68);
  backdrop-filter: blur(4px);
}

.question-modal.hidden {
  display: none !important;
  pointer-events: none;
}

.question-modal-card {
  width: min(720px, 100%);
  max-height: min(84dvh, 760px);
  overflow: auto;
  border-radius: 16px;
  border: 1px solid rgba(138, 205, 236, 0.38);
  background: linear-gradient(180deg, rgba(8, 24, 40, 0.98), rgba(10, 28, 44, 0.96));
  box-shadow: 0 16px 34px rgba(2, 9, 16, 0.42);
  padding: 0.82rem;
}

.turn-toast {
  position: fixed;
  top: 0.95rem;
  left: 50%;
  transform: translate(-50%, -8px) scale(0.96);
  z-index: 1450;
  display: flex;
  align-items: center;
  gap: 0.52rem;
  border-radius: 12px;
  border: 1px solid rgba(156, 222, 246, 0.45);
  background: linear-gradient(140deg, rgba(7, 24, 40, 0.96), rgba(15, 43, 64, 0.94));
  padding: 0.5rem 0.68rem;
  box-shadow: 0 12px 28px rgba(2, 9, 16, 0.34);
  opacity: 0;
  pointer-events: none;
  transition: opacity 180ms ease, transform 190ms ease;
}

.turn-toast.active {
  opacity: 1;
  transform: translate(-50%, 0) scale(1);
}

.turn-toast.hidden {
  display: none !important;
}

.turn-toast img {
  width: 28px;
  height: 28px;
}

#turn-toast-text {
  margin: 0;
  font-weight: 700;
  color: #dff2ff;
  font-size: 0.9rem;
  letter-spacing: 0.01em;
}

.turn-modal {
  position: fixed;
  inset: 0;
  z-index: 1455;
  display: grid;
  place-items: center;
  background: rgba(2, 10, 18, 0.48);
  backdrop-filter: blur(3px);
  padding:
    max(0.8rem, env(safe-area-inset-top))
    max(0.8rem, env(safe-area-inset-right))
    max(0.8rem, env(safe-area-inset-bottom))
    max(0.8rem, env(safe-area-inset-left));
}

.turn-modal.hidden {
  display: none !important;
  pointer-events: none;
}

.turn-modal-card {
  width: min(360px, 100%);
  border-radius: 14px;
  border: 1px solid rgba(153, 223, 246, 0.48);
  background: linear-gradient(170deg, rgba(8, 24, 40, 0.97), rgba(13, 38, 56, 0.95));
  box-shadow: 0 14px 30px rgba(2, 9, 16, 0.34);
  padding: 0.84rem 0.76rem;
  text-align: center;
}

.turn-modal-card img {
  width: 44px;
  height: 44px;
  display: block;
  margin: 0 auto 0.28rem;
}

#turn-modal-text {
  margin: 0;
  font-weight: 700;
  color: #e3f4ff;
  line-height: 1.4;
}

.winner-modal {
  position: fixed;
  inset: 0;
  z-index: 1460;
  display: grid;
  place-items: center;
  background: rgba(2, 10, 18, 0.66);
  backdrop-filter: blur(4px);
  padding:
    max(0.8rem, env(safe-area-inset-top))
    max(0.8rem, env(safe-area-inset-right))
    max(0.8rem, env(safe-area-inset-bottom))
    max(0.8rem, env(safe-area-inset-left));
}

.winner-modal.hidden {
  display: none !important;
  pointer-events: none;
}

.winner-modal-card {
  width: min(430px, 100%);
  border-radius: 16px;
  border: 1px solid rgba(146, 214, 243, 0.44);
  background: linear-gradient(170deg, rgba(9, 26, 42, 0.97), rgba(13, 35, 53, 0.95));
  box-shadow: 0 18px 36px rgba(2, 9, 16, 0.4);
  padding: 1rem 0.95rem 0.92rem;
  text-align: center;
}

.winner-modal-card img {
  width: 110px;
  height: auto;
  margin: 0 auto 0.42rem;
  display: block;
}

#winner-modal-title {
  margin: 0;
  font-family: "Sora", "Space Grotesk", sans-serif;
}

#winner-modal-text {
  margin: 0.45rem 0 0.8rem;
  color: #d3e9f7;
  line-height: 1.45;
}

.question-modal-head {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  justify-content: space-between;
  margin-bottom: 0.55rem;
}

.question-modal-head h2 {
  margin: 0;
  font-size: 1rem;
}

.question-modal-close {
  width: auto;
  min-width: 94px;
  padding: 0.44rem 0.62rem;
}

#question-modal-text {
  margin: 0 0 0.55rem;
  color: #d6ebf8;
  line-height: 1.44;
}

#room-info,
#status-line {
  margin: 0.3rem 0 0;
  color: var(--muted);
  font-size: 0.84rem;
}

#question-text {
  margin: 0 0 0.52rem;
  color: #d6ebf8;
  line-height: 1.42;
}

.options {
  display: grid;
  gap: 0.4rem;
}

.option-btn {
  width: 100%;
  text-align: left;
  background: linear-gradient(140deg, #9de8ff, #d9f8ff 85%);
}

.option-btn:hover {
  transform: translateY(-1px);
}

.players-list,
.log-list {
  margin: 0;
  padding-left: 1rem;
  color: #d4e9f7;
  font-size: 0.84rem;
  max-height: 140px;
  overflow: auto;
}

.players-list li,
.log-list li {
  margin-bottom: 0.28rem;
}

.powered-by {
  margin-top: 0.9rem;
  text-align: center;
}

.powered-by a {
  color: #99cbe5;
  text-decoration: none;
  font-size: 0.84rem;
  font-weight: 600;
}

.powered-by a:hover {
  text-decoration: underline;
}

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

  .control-card {
    position: static;
    max-height: none;
    overflow: visible;
  }
}

@media (max-width: 740px) {
  .shell {
    width: min(97vw, 100%);
    padding-top: 0.75rem;
  }

  .hero {
    padding: 0.75rem;
    background-position: 0 0, right -80px top -40px;
    padding-right: 0.75rem;
  }

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

  .mode-toggle {
    grid-template-columns: 1fr;
  }

  .cell-tag.ladder,
  .cell-tag.snake {
    width: 11px;
    height: 11px;
  }

  .dice-panel {
    width: 100%;
    grid-template-columns: auto auto auto;
    gap: 0.35rem;
    justify-content: space-between;
    align-items: center;
  }

  .dice-face {
    width: 46px;
    height: 46px;
  }

  .pip {
    width: 7px;
    height: 7px;
  }

  .question-modal {
    align-items: center;
    padding: clamp(0.46rem, 2.8vw, 0.72rem);
  }

  .question-modal-card {
    width: min(94vw, 520px);
    max-height: min(80dvh, 620px);
    border-radius: 14px;
    padding: clamp(0.66rem, 2.7vw, 0.86rem);
  }

  .question-modal-head {
    margin-bottom: 0.46rem;
  }

  .question-modal-head h2 {
    font-size: clamp(0.92rem, 3.8vw, 1rem);
  }

  .question-modal-close {
    min-width: 84px;
    padding: 0.4rem 0.52rem;
  }

  #question-modal-text {
    margin: 0 0 0.5rem;
    font-size: clamp(0.88rem, 3.5vw, 0.97rem);
    line-height: 1.42;
  }

  #question-modal-options {
    gap: 0.36rem;
  }

  #question-modal-options .option-btn {
    padding: 0.48rem 0.56rem;
    font-size: clamp(0.84rem, 3.35vw, 0.92rem);
    line-height: 1.34;
    white-space: normal;
  }

  .turn-toast {
    width: min(92vw, 420px);
    justify-content: center;
  }

  .turn-modal-card {
    width: min(94vw, 420px);
  }

  .winner-modal-card {
    width: min(94vw, 430px);
    padding: 0.88rem 0.74rem 0.8rem;
  }

  .winner-modal-card img {
    width: 94px;
  }
}

@keyframes dice-roll {
  0% {
    transform: rotate(0deg) scale(1);
  }
  40% {
    transform: rotate(140deg) scale(1.07);
  }
  75% {
    transform: rotate(280deg) scale(0.97);
  }
  100% {
    transform: rotate(360deg) scale(1);
  }
}

@keyframes token-hop {
  0% {
    transform: translateY(0) scale(1);
  }
  50% {
    transform: translateY(-5px) scale(1.08);
  }
  100% {
    transform: translateY(0) scale(1);
  }
}

@keyframes step-cell-pulse {
  0% {
    box-shadow: 0 0 0 0 rgba(124, 244, 217, 0.5) inset;
  }
  100% {
    box-shadow: 0 0 0 2px rgba(124, 244, 217, 0) inset;
  }
}

@keyframes ladder-cell-pulse {
  0% {
    box-shadow: 0 0 0 0 rgba(125, 232, 214, 0.75) inset;
  }
  100% {
    box-shadow: 0 0 0 4px rgba(125, 232, 214, 0) inset;
  }
}

@keyframes snake-cell-pulse {
  0% {
    box-shadow: 0 0 0 0 rgba(255, 138, 160, 0.78) inset;
  }
  100% {
    box-shadow: 0 0 0 4px rgba(255, 138, 160, 0) inset;
  }
}
