:root {
  color-scheme: light;
  --ink: #17212b;
  --muted: #66707d;
  --line: #d7dde4;
  --paper: #fbfaf6;
  --panel: #ffffff;
  --red: #d94841;
  --green: #23946f;
  --yellow: #e6aa28;
  --blue: #3478c8;
  --track: #f4f1ea;
  --shadow: 0 18px 55px rgba(28, 39, 54, 0.16);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  min-height: 100vh;
  min-height: 100svh;
  margin: 0;
  background:
    linear-gradient(135deg, rgba(217, 72, 65, 0.08), transparent 34%),
    linear-gradient(315deg, rgba(35, 148, 111, 0.1), transparent 34%),
    var(--paper);
  color: var(--ink);
}

button,
input,
select {
  font: inherit;
}

button {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
  touch-action: manipulation;
  transition: transform 150ms ease, border-color 150ms ease, box-shadow 150ms ease;
}

button:hover:not(:disabled) {
  border-color: #9aa8b6;
  transform: translateY(-1px);
  box-shadow: 0 7px 18px rgba(23, 33, 43, 0.1);
}

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

.primary-button {
  border: 0;
  background: #17212b;
  color: #fff;
  padding-inline: 18px;
  font-weight: 700;
}

.icon-button {
  width: 44px;
  padding: 0;
  font-size: 1.25rem;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 390px;
  gap: 22px;
  width: min(1440px, 100%);
  min-height: 100vh;
  margin: 0 auto;
  padding: 22px;
}

.game-surface,
.side-panel {
  min-width: 0;
  border: 1px solid rgba(215, 221, 228, 0.8);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.86);
  box-shadow: var(--shadow);
}

.game-surface {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  min-height: calc(100vh - 44px);
  overflow: hidden;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 20px;
  border-bottom: 1px solid var(--line);
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: clamp(1.7rem, 3vw, 2.8rem);
  line-height: 1;
  letter-spacing: 0;
}

h2 {
  margin-bottom: 10px;
  font-size: 0.92rem;
  letter-spacing: 0;
  text-transform: uppercase;
  color: var(--muted);
}

#roomLine {
  margin-top: 7px;
  color: var(--muted);
  overflow-wrap: anywhere;
}

.room-actions {
  display: flex;
  align-items: center;
  gap: 9px;
}

.board-wrap {
  display: grid;
  place-items: center;
  position: relative;
  min-width: 0;
  padding: clamp(12px, 2vw, 28px);
}

#board,
.effects-layer {
  position: relative;
  width: min(100%, calc(100vh - 154px));
  max-width: 100%;
  max-height: calc(100vh - 154px);
  aspect-ratio: 1;
  border-radius: 8px;
}

#board {
  z-index: 1;
  background: #fffaf0;
  box-shadow: inset 0 0 0 1px var(--line), 0 20px 60px rgba(23, 33, 43, 0.12);
}

body[data-game-status="lobby"] #board {
  box-shadow: inset 0 0 0 2px rgba(52, 120, 200, 0.18), 0 20px 60px rgba(23, 33, 43, 0.12);
}

body[data-game-status="playing"] #board {
  box-shadow: inset 0 0 0 2px rgba(35, 148, 111, 0.3), 0 22px 62px rgba(35, 148, 111, 0.16);
}

body[data-game-status="finished"] #board {
  box-shadow: inset 0 0 0 2px rgba(230, 170, 40, 0.34), 0 22px 62px rgba(230, 170, 40, 0.16);
}

.cell {
  fill: var(--track);
  stroke: #cfd7df;
  stroke-width: 0.035;
}

.home-lane-runway {
  fill: none;
  stroke-linecap: square;
  stroke-linejoin: round;
  stroke-width: 0.92;
  stroke-opacity: 0.24;
  pointer-events: none;
}

.home-lane-runway-edge {
  fill: none;
  stroke: rgba(23, 33, 43, 0.2);
  stroke-dasharray: 0.28 0.72;
  stroke-linecap: round;
  stroke-width: 0.045;
  pointer-events: none;
}

.home-entry-cell {
  fill: var(--entry-color);
  fill-opacity: 0.88;
  stroke: rgba(255, 255, 255, 0.7);
  stroke-width: 0.045;
}

.home-base {
  stroke: rgba(23, 33, 43, 0.18);
  stroke-width: 0.06;
}

.home-inner {
  fill: rgba(255, 255, 255, 0.82);
}

.center-triangle {
  stroke: rgba(23, 33, 43, 0.12);
  stroke-width: 0.04;
  filter: drop-shadow(0 0.02px 0.02px rgba(23, 33, 43, 0.18));
}

.safe-star {
  fill: #fff;
  stroke: rgba(23, 33, 43, 0.34);
  stroke-width: 0.04;
}

.adventure-marker {
  pointer-events: none;
}

.adventure-fire-glow {
  fill: rgba(217, 72, 65, 0.18);
  stroke: rgba(217, 72, 65, 0.5);
  stroke-width: 0.06;
}

.adventure-fire {
  fill: #d94841;
  stroke: rgba(110, 28, 22, 0.42);
  stroke-width: 0.04;
}

.adventure-fire-inner {
  fill: #ffd66b;
  opacity: 0.95;
}

.adventure-shield-glow {
  fill: rgba(52, 120, 200, 0.16);
  stroke: rgba(52, 120, 200, 0.48);
  stroke-width: 0.06;
}

.adventure-shield {
  fill: #3478c8;
  stroke: #fff;
  stroke-width: 0.055;
}

.adventure-safe-ring {
  fill: rgba(255, 255, 255, 0.22);
  stroke: var(--shield-owner, var(--blue));
  stroke-dasharray: 0.16 0.11;
  stroke-linecap: round;
  stroke-width: 0.08;
}

.adventure-safe-core {
  fill: color-mix(in srgb, var(--shield-owner, var(--blue)) 20%, transparent);
  stroke: rgba(255, 255, 255, 0.82);
  stroke-width: 0.035;
}

.home-lane-arrow {
  stroke: #fff;
  stroke-linecap: round;
  stroke-width: 0.13;
  stroke-opacity: 0.94;
  pointer-events: none;
}

.token-piece {
  cursor: default;
  outline: none;
}

.token-piece.movable {
  cursor: pointer;
  filter: drop-shadow(0 0 0.14px rgba(23, 33, 43, 0.5));
}

.token-piece:focus,
.token-piece:focus-visible {
  outline: none;
}

.token-halo {
  fill: none;
  stroke-linecap: round;
  stroke-width: 0.075;
  stroke-opacity: 0.72;
  pointer-events: none;
  transform-box: fill-box;
  transform-origin: center;
}

.token-piece.movable:hover .token-halo,
.token-piece.movable.selected .token-halo,
.token-piece.movable:focus-visible .token-halo {
  stroke-width: 0.105;
  stroke-opacity: 0.95;
}

.token-piece.selected {
  filter: drop-shadow(0 0 0.24px var(--token-color));
}

body:not([data-visual-mode="off"]) .token-piece.movable {
  animation: token-ready 1.4s ease-in-out infinite;
}

body:not([data-visual-mode="off"]) .token-piece.movable .token-halo {
  animation: token-halo 1.4s ease-in-out infinite;
}

.move-guides {
  pointer-events: none;
}

.move-guide-line {
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 0.12;
  stroke-opacity: 0.72;
  stroke-dasharray: 0.2 0.16;
  filter: drop-shadow(0 0.04px 0.05px rgba(255, 255, 255, 0.9));
}

.move-guide-dot {
  opacity: 0.88;
  pointer-events: none;
}

.move-guide-goal {
  opacity: 0.76;
  pointer-events: none;
  stroke: #fff;
  stroke-width: 0.05;
}

body:not([data-visual-mode="off"]) .token-piece.moved {
  animation: token-hop 520ms cubic-bezier(0.2, 0.85, 0.2, 1);
}

body:not([data-visual-mode="off"]) .token-piece.returned {
  animation: token-return 520ms ease-out;
}

.token-hit {
  fill: transparent;
  stroke: transparent;
}

.token-label {
  pointer-events: none;
  fill: #fff;
  font-size: 0.28px;
  font-weight: 800;
  text-anchor: middle;
  dominant-baseline: middle;
}

.side-panel {
  display: grid;
  align-content: start;
  gap: 14px;
  max-height: calc(100vh - 44px);
  overflow: auto;
  padding: 18px;
}

.sidebar-tabs {
  position: sticky;
  top: 0;
  z-index: 2;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px;
  margin: -2px -2px 2px;
  padding: 2px;
  border-radius: 8px;
  background: rgba(244, 241, 234, 0.82);
  backdrop-filter: blur(10px);
}

.sidebar-tab {
  min-height: 36px;
  border-color: transparent;
  border-radius: 7px;
  background: transparent;
  padding: 0 8px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
}

.sidebar-tab.active {
  background: #fff;
  color: var(--ink);
  box-shadow: 0 6px 18px rgba(23, 33, 43, 0.09);
}

.sidebar-tab:disabled {
  display: none;
}

.join-panel,
.turn-panel,
.side-panel section {
  border-bottom: 1px solid var(--line);
  padding-bottom: 18px;
}

.join-panel {
  display: grid;
  gap: 10px;
}

label {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--muted);
}

.join-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 112px;
  gap: 8px;
}

input,
select {
  min-height: 42px;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 0 12px;
  color: var(--ink);
}

.dice-area {
  display: grid;
  grid-template-columns: 76px minmax(0, 1fr);
  gap: 14px;
  align-items: center;
  margin-bottom: 14px;
}

.dice {
  position: relative;
  display: grid;
  place-items: center;
  width: 76px;
  height: 76px;
  border: 2px solid var(--ink);
  border-radius: 8px;
  background: #fff;
  font-size: 2.4rem;
  font-weight: 900;
  line-height: 1;
}

.dice-shadow {
  fill: rgba(23, 33, 43, 0.18);
}

.dice-svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.dice-top {
  stroke: rgba(23, 33, 43, 0.16);
  stroke-width: 2;
}

.dice-side {
  stroke: rgba(23, 33, 43, 0.16);
  stroke-width: 2;
}

.dice-front {
  stroke: rgba(23, 33, 43, 0.38);
  stroke-width: 2.4;
}

.dice-pip {
  fill: var(--ink);
}

.dice-dash {
  stroke: var(--ink);
  stroke-width: 6;
  stroke-linecap: round;
}

.dice-pop {
  animation: dice-pop 420ms cubic-bezier(0.2, 0.8, 0.2, 1);
}

.turn-text {
  font-size: 1.05rem;
  font-weight: 800;
}

.hint-text {
  margin-top: 5px;
  color: var(--muted);
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.control-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.settings-panel {
  display: grid;
  gap: 10px;
}

.settings-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.25fr);
  gap: 9px 10px;
  align-items: center;
}

.settings-grid label {
  margin: 0;
}

.toggle-row {
  display: flex;
  grid-column: 1 / -1;
  align-items: center;
  gap: 9px;
  min-height: 36px;
}

.toggle-row input {
  width: 18px;
  min-height: 18px;
  accent-color: var(--ink);
}

input[type="range"] {
  padding: 0;
  accent-color: var(--ink);
}

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

.player-seat {
  display: grid;
  grid-template-columns: 16px minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  min-height: 52px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #fff;
}

.computer-seat {
  min-height: 34px;
  padding: 0 10px;
  font-size: 0.78rem;
  font-weight: 800;
}

.player-seat.active {
  border-color: var(--seat-color);
  box-shadow: inset 4px 0 0 var(--seat-color);
}

.color-dot {
  width: 14px;
  height: 14px;
  border-radius: 999px;
  background: var(--seat-color);
}

.player-seat strong,
.player-seat small {
  display: block;
  min-width: 0;
  overflow-wrap: anywhere;
}

.player-seat small {
  margin-top: 2px;
  color: var(--muted);
}

.speech-coach {
  display: grid;
  gap: 12px;
  margin-bottom: 14px;
  border: 2px solid rgba(52, 120, 200, 0.24);
  border-radius: 8px;
  padding: 14px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.98), rgba(244, 249, 255, 0.96));
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.7);
}

.speech-coach-head {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 10px;
}

.speech-kicker {
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 850;
  letter-spacing: 0;
  text-transform: uppercase;
}

.speech-who {
  width: fit-content;
  margin-bottom: 6px;
  border-radius: 999px;
  padding: 4px 8px;
  background: rgba(23, 33, 43, 0.08);
  color: var(--ink);
  font-size: 0.78rem;
  font-weight: 850;
}

#speechPrompt {
  display: block;
  border-radius: 8px;
  padding: 12px;
  background: #fff;
  box-shadow: inset 0 0 0 1px rgba(215, 221, 228, 0.9);
  font-size: 1.35rem;
  line-height: 1.15;
  overflow-wrap: anywhere;
}

.speech-badge {
  flex: 0 0 auto;
  border-radius: 999px;
  padding: 5px 8px;
  background: rgba(35, 148, 111, 0.14);
  color: #17674e;
  font-size: 0.72rem;
  font-weight: 850;
}

.speech-badge[data-mode="practice"] {
  background: rgba(230, 170, 40, 0.18);
  color: #785711;
}

.speech-guide {
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.35;
}

.speech-steps {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 7px;
}

.speech-steps button {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 48px;
  padding: 0 10px;
  font-size: 0.9rem;
  font-weight: 800;
  line-height: 1.15;
}

.step-number {
  display: inline-grid;
  place-items: center;
  flex: 0 0 auto;
  width: 24px;
  height: 24px;
  border-radius: 999px;
  background: rgba(23, 33, 43, 0.1);
  color: var(--ink);
  font-size: 0.78rem;
  font-weight: 900;
}

.primary-button .step-number {
  background: rgba(255, 255, 255, 0.18);
  color: #fff;
}

.speech-progress {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  color: var(--muted);
  font-size: 0.8rem;
}

.speech-progress > span {
  border: 1px solid rgba(215, 221, 228, 0.9);
  border-radius: 999px;
  padding: 5px 8px;
  background: #fff;
}

.speech-progress strong {
  color: var(--ink);
}

.log {
  display: grid;
  gap: 7px;
  max-height: 260px;
  margin: 0;
  padding-left: 20px;
  color: var(--muted);
  line-height: 1.35;
}

.log li:last-child {
  color: var(--ink);
  font-weight: 700;
}

.effects-layer {
  position: absolute;
  left: 50%;
  top: 50%;
  z-index: 3;
  pointer-events: none;
  overflow: hidden;
  transform: translate(-50%, -50%);
}

.board-dice {
  position: absolute;
  left: 50%;
  top: 50%;
  z-index: 2;
  width: clamp(58px, 8vmin, 92px);
  height: clamp(58px, 8vmin, 92px);
  border: 2px solid var(--dice-color, var(--ink));
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.92);
  padding: 0;
  box-shadow: 0 12px 28px rgba(23, 33, 43, 0.18);
  pointer-events: none;
  transform: translate(-50%, -50%);
}

.board-dice[hidden] {
  display: none;
}

.board-dice.waiting {
  opacity: 0.78;
}

.board-dice.rollable {
  cursor: pointer;
  pointer-events: auto;
  opacity: 1;
  box-shadow: 0 14px 34px color-mix(in srgb, var(--dice-color, var(--ink)) 34%, transparent);
}

.board-dice.rollable:hover,
.board-dice.rollable:focus-visible {
  transform: translate(-50%, -50%) scale(1.04);
}

.board-dice:disabled {
  cursor: default;
}

.toast-stack {
  position: sticky;
  top: 54px;
  z-index: 4;
  display: grid;
  justify-items: stretch;
  gap: 6px;
  width: min(280px, 100%);
  justify-self: end;
  pointer-events: none;
}

.toast {
  position: relative;
  max-width: 100%;
  border: 1px solid color-mix(in srgb, var(--toast-color, var(--ink)) 42%, transparent);
  border-left: 0;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.95);
  box-shadow: 0 10px 24px rgba(23, 33, 43, 0.14);
  padding: 8px 10px 8px 26px;
  color: var(--ink);
  font-size: 0.78rem;
  font-weight: 750;
  line-height: 1.22;
  overflow-wrap: anywhere;
  animation: toast-in 200ms ease-out, toast-out 300ms ease-in 2.9s forwards;
}

.toast::before {
  content: "";
  position: absolute;
  left: 9px;
  top: 50%;
  width: 9px;
  height: 9px;
  border-radius: 999px;
  background: var(--toast-color, var(--ink));
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--toast-color, var(--ink)) 18%, transparent);
  transform: translateY(-50%);
}

.toast.roll {
  --toast-color: var(--blue);
}

.toast.capture {
  --toast-color: var(--red);
}

.toast.bonus,
.toast.win {
  --toast-color: var(--yellow);
}

.toast.join {
  --toast-color: var(--green);
}

.board-flash,
.particle,
.confetti,
.finish-ring,
.finish-spark,
.congrats-banner {
  position: absolute;
  left: 50%;
  top: 50%;
  pointer-events: none;
}

.board-flash {
  width: 100%;
  height: 100%;
  border: 3px solid rgba(23, 33, 43, 0.18);
  border-radius: 8px;
  opacity: 0;
  transform: translate(-50%, -50%) scale(0.96);
  animation: board-flash 620ms ease-out;
}

.board-flash.capture {
  border-color: rgba(217, 72, 65, 0.42);
}

.board-flash.bonus,
.board-flash.win {
  border-color: rgba(230, 170, 40, 0.54);
}

.board-flash.turn {
  border-color: rgba(52, 120, 200, 0.44);
}

.particle {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  background: var(--c);
  box-shadow: 0 0 16px var(--c);
  transform: translate(-50%, -50%);
  animation: particle-burst 760ms ease-out forwards;
}

.particle.capture {
  width: 13px;
  height: 13px;
}

.particle.win {
  width: 12px;
  height: 18px;
  border-radius: 2px;
}

.confetti {
  width: 9px;
  height: 15px;
  border-radius: 2px;
  background: var(--c);
  box-shadow: 0 0 10px color-mix(in srgb, var(--c) 65%, transparent);
  transform: translate(-50%, -50%);
  animation: confetti-fall 1400ms cubic-bezier(0.18, 0.72, 0.2, 1) forwards;
}

.finish-ring {
  width: min(52%, 360px);
  aspect-ratio: 1;
  border: 5px solid var(--winner-color, var(--yellow));
  border-radius: 999px;
  opacity: 0;
  transform: translate(-50%, -50%) scale(0.2);
  animation: finish-ring 900ms ease-out forwards;
}

.finish-spark {
  width: 12px;
  height: 12px;
  border-radius: 999px;
  background: var(--c);
  box-shadow: 0 0 16px var(--c);
  transform: translate(-50%, -50%);
  animation: finish-spark 980ms ease-out forwards;
}

.congrats-banner {
  min-width: min(320px, 80%);
  border: 2px solid var(--winner-color, var(--yellow));
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.95);
  box-shadow: 0 18px 44px rgba(23, 33, 43, 0.22);
  padding: 12px 16px;
  color: var(--ink);
  font-weight: 900;
  text-align: center;
  transform: translate(-50%, -50%);
  animation: congrats-pop 1600ms ease-out forwards;
}

body[data-visual-mode="calm"] .token-piece.movable {
  animation-duration: 2.4s;
}

body[data-visual-mode="off"] .dice-pop,
body[data-visual-mode="off"] .token-piece.movable,
body[data-visual-mode="off"] .token-piece.movable .token-halo,
body[data-visual-mode="off"] .token-piece.moved,
body[data-visual-mode="off"] .token-piece.returned {
  animation: none;
}

@keyframes dice-pop {
  0% {
    transform: rotate(-8deg) scale(1);
  }
  50% {
    transform: rotate(8deg) scale(1.14);
  }
  100% {
    transform: rotate(0deg) scale(1);
  }
}

@keyframes token-ready {
  0%,
  100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-0.08px);
  }
}

@keyframes token-halo {
  0%,
  100% {
    opacity: 0.62;
    transform: scale(1);
  }
  50% {
    opacity: 0.95;
    transform: scale(1.08);
  }
}

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

@keyframes token-return {
  0% {
    opacity: 0.45;
    transform: scale(0.72);
  }
  70% {
    opacity: 1;
    transform: scale(1.08);
  }
  100% {
    transform: scale(1);
  }
}

@keyframes board-flash {
  12% {
    opacity: 1;
  }
  100% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(1.04);
  }
}

@keyframes particle-burst {
  0% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(0.5);
  }
  100% {
    opacity: 0;
    transform: translate(calc(-50% + var(--x)), calc(-50% + var(--y))) scale(0.1);
  }
}

@keyframes confetti-fall {
  0% {
    opacity: 1;
    transform: translate(-50%, -50%) rotate(0deg) scale(0.9);
  }
  72% {
    opacity: 1;
  }
  100% {
    opacity: 0;
    transform: translate(calc(-50% + var(--x)), calc(-50% + var(--y))) rotate(var(--r)) scale(0.78);
  }
}

@keyframes finish-ring {
  0% {
    opacity: 0.8;
    transform: translate(-50%, -50%) scale(0.18);
  }
  65% {
    opacity: 0.42;
  }
  100% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(1.08);
  }
}

@keyframes finish-spark {
  0% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(0.55);
  }
  100% {
    opacity: 0;
    transform: translate(calc(-50% + var(--x)), calc(-50% + var(--y))) scale(0.15);
  }
}

@keyframes congrats-pop {
  0% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.82);
  }
  18%,
  72% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
  }
  100% {
    opacity: 0;
    transform: translate(-50%, -56%) scale(0.96);
  }
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(-8px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes toast-out {
  to {
    opacity: 0;
    transform: translateY(-8px) scale(0.98);
  }
}

@media (max-width: 1050px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .game-surface {
    min-height: auto;
  }

  .side-panel {
    max-height: none;
  }

  #board,
  .effects-layer {
    width: min(100%, calc(100vw - 22px), 82vh);
    max-height: none;
  }
}

@media (max-width: 620px) {
  body {
    overflow-x: hidden;
  }

  .app-shell {
    width: 100%;
    min-height: 100svh;
    padding: 8px 8px calc(150px + env(safe-area-inset-bottom));
    gap: 8px;
  }

  .game-surface,
  .side-panel {
    border-radius: 8px;
    box-shadow: 0 10px 28px rgba(28, 39, 54, 0.12);
  }

  .topbar {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: start;
    gap: 10px;
    padding: 12px;
  }

  h1 {
    font-size: 1.55rem;
  }

  h2 {
    margin-bottom: 8px;
    font-size: 0.78rem;
  }

  #roomLine {
    margin-top: 4px;
    font-size: 0.86rem;
    line-height: 1.25;
  }

  .board-wrap {
    align-content: start;
    padding: 8px;
  }

  #board,
  .effects-layer {
    width: min(calc(100vw - 18px), calc(100svh - 224px));
    min-width: min(100%, 302px);
    max-height: none;
  }

  .room-actions {
    display: grid;
    grid-template-columns: 42px minmax(82px, 1fr);
    gap: 7px;
    min-width: 132px;
  }

  #copyInvite[hidden] + #newRoom {
    grid-column: 1 / -1;
  }

  .icon-button {
    width: 42px;
  }

  .side-panel {
    gap: 10px;
    border: 0;
    background: transparent;
    box-shadow: none;
    padding: 0;
    overflow: visible;
  }

  .sidebar-tabs {
    position: sticky;
    top: 8px;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 4px;
    margin: 0;
    padding: 4px;
    border: 1px solid rgba(215, 221, 228, 0.85);
    background: rgba(255, 255, 255, 0.92);
    box-shadow: 0 10px 24px rgba(28, 39, 54, 0.08);
  }

  .sidebar-tab {
    min-height: 40px;
    padding: 0 5px;
    font-size: 0.76rem;
  }

  .join-panel,
  .side-panel section {
    border: 1px solid rgba(215, 221, 228, 0.9);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.92);
    padding: 12px;
    box-shadow: 0 10px 24px rgba(28, 39, 54, 0.08);
  }

  .turn-panel {
    position: fixed;
    left: max(8px, env(safe-area-inset-left));
    right: max(8px, env(safe-area-inset-right));
    bottom: max(8px, env(safe-area-inset-bottom));
    z-index: 20;
    border: 1px solid rgba(215, 221, 228, 0.95);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.96);
    box-shadow: 0 18px 44px rgba(23, 33, 43, 0.22);
    padding: 10px;
    backdrop-filter: blur(10px);
  }

  body[data-sidebar-view="settings"] .turn-panel {
    display: none;
  }

  .join-panel {
    gap: 8px;
  }

  .join-row {
    grid-template-columns: minmax(0, 1fr) minmax(96px, 34%);
  }

  button,
  input,
  select {
    min-height: 46px;
    font-size: 1rem;
  }

  .primary-button {
    padding-inline: 12px;
  }

  .dice-area {
    grid-template-columns: 58px minmax(0, 1fr);
    gap: 10px;
    margin-bottom: 9px;
  }

  .dice {
    width: 58px;
    height: 58px;
    border-width: 1.5px;
  }

  .turn-text {
    font-size: 0.98rem;
    line-height: 1.15;
  }

  .hint-text {
    display: -webkit-box;
    margin-top: 3px;
    font-size: 0.82rem;
    line-height: 1.25;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    overflow: hidden;
  }

  .control-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 7px;
  }

  .control-grid button {
    min-height: 44px;
    padding-inline: 6px;
    font-size: 0.95rem;
    font-weight: 800;
  }

  #rollDice {
    border-color: rgba(23, 33, 43, 0.32);
    background: #fffaf0;
  }

  #rollDice:not(:disabled) {
    border-color: var(--ink);
    box-shadow: inset 0 -3px 0 rgba(23, 33, 43, 0.12);
  }

  .settings-grid {
    grid-template-columns: minmax(96px, 0.82fr) minmax(0, 1.18fr);
    width: 100%;
    gap: 8px;
  }

  .settings-grid label {
    font-size: 0.8rem;
    line-height: 1.15;
  }

  .toggle-row {
    grid-column: 1 / -1;
    min-height: 34px;
  }

  input[type="range"] {
    min-height: 34px;
  }

  .players {
    gap: 7px;
  }

  .player-seat {
    grid-template-columns: 14px minmax(0, 1fr) auto;
    min-height: 48px;
    gap: 8px;
    padding: 9px;
  }

  .color-dot {
    width: 12px;
    height: 12px;
  }

  .player-seat strong {
    font-size: 0.94rem;
    line-height: 1.15;
  }

  .player-seat small {
    font-size: 0.78rem;
    line-height: 1.25;
  }

  .computer-seat {
    min-height: 34px;
    max-width: 96px;
    padding: 0 8px;
    font-size: 0.74rem;
    white-space: normal;
  }

  .speech-coach {
    gap: 9px;
    margin-bottom: 12px;
    padding: 10px;
  }

  #speechPrompt {
    padding: 10px;
    font-size: 1.18rem;
  }

  .speech-steps {
    grid-template-columns: 1fr;
  }

  .speech-steps button {
    min-height: 48px;
    font-size: 0.95rem;
  }

  .log {
    max-height: 168px;
    gap: 5px;
    padding-left: 18px;
    font-size: 0.84rem;
  }

  .toast-stack {
    top: 66px;
    width: min(230px, 100%);
    gap: 6px;
  }

  .toast {
    padding: 7px 9px 7px 24px;
    font-size: 0.76rem;
    box-shadow: 0 10px 24px rgba(23, 33, 43, 0.16);
  }

  .board-dice {
    width: 56px;
    height: 56px;
    border-width: 1.5px;
  }

  .particle {
    width: 8px;
    height: 8px;
  }

  .particle.capture {
    width: 10px;
    height: 10px;
  }

  .particle.win {
    width: 9px;
    height: 14px;
  }

  .congrats-banner {
    min-width: min(280px, 82%);
    padding: 10px 12px;
    font-size: 0.9rem;
  }

  .finish-ring {
    width: min(62%, 280px);
    border-width: 4px;
  }

  .finish-spark {
    width: 9px;
    height: 9px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .dice-pop,
  .token-piece.movable,
  .token-piece.movable .token-halo,
  .token-piece.moved,
  .token-piece.returned,
  .board-flash,
  .particle,
  .confetti,
  .finish-ring,
  .finish-spark,
  .congrats-banner,
  .toast {
    animation: none;
  }

  .particle,
  .confetti,
  .finish-ring,
  .finish-spark,
  .board-flash {
    display: none;
  }
}
