@import url('https://fonts.googleapis.com/css2?family=Nunito:wght@600;700;800;900&display=swap');

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

:root {
  --tg-h: 100vh;
  --game-chrome: 248px;
  --tg-bg: var(--tg-theme-bg-color, #0a0a14);
  --tg-secondary: var(--tg-theme-secondary-bg-color, #12121f);
  --tg-text: var(--tg-theme-text-color, #e8e8ff);
  --tg-hint: var(--tg-theme-hint-color, #8888aa);
  --tg-link: var(--tg-theme-link-color, #00e5ff);
  --tg-btn: var(--tg-theme-button-color, #ff2d6a);
  --tg-btn-text: var(--tg-theme-button-text-color, #ffffff);
  --tg-section: var(--tg-theme-section-bg-color, #16162a);
  --red: #ff2d6a;
  --green: #39ff14;
  --yellow: #ffe566;
  --blue: #00e5ff;
  --gold: #ffe566;
  --board-bg: #080810;
  --play: #ff2d6a;
  --play-dark: #c41d52;
  --neon-pink: #ff2d6a;
  --neon-cyan: #00e5ff;
  --shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 8px 32px rgba(255, 45, 106, 0.15);
  --radius: 16px;
  --radius-sm: 12px;
}

html, body { height: 100%; overflow: hidden; }

body {
  font-family: 'Nunito', -apple-system, sans-serif;
  background: var(--tg-bg);
  color: var(--tg-text);
  user-select: none;
  font-size: 16px;
}

#app {
  height: var(--tg-h);
  max-width: 480px;
  margin: 0 auto;
  overflow: hidden;
  background: linear-gradient(180deg, var(--tg-bg) 0%, var(--tg-secondary) 100%);
}

.screen {
  display: none;
  flex-direction: column;
  height: var(--tg-h);
  overflow-y: auto;
  padding: 16px;
  padding-bottom: max(16px, env(safe-area-inset-bottom));
}
.screen.active { display: flex; }

.screen-game { padding: 0 !important; overflow: hidden !important; background: var(--board-bg); position: relative; }
.screen-game.active { display: flex; flex-direction: column; }

.menu-hero { text-align: center; padding: 20px 16px 16px; }
.menu-logo-wrap {
  width: 96px; height: 96px; margin: 0 auto 12px;
  background: var(--tg-section); border-radius: 22px;
  display: grid; grid-template-columns: 1fr 1fr; gap: 6px; padding: 14px;
  box-shadow: var(--shadow-lg); border: 2px solid rgba(255,255,255,0.1);
}
.pawn-demo {
  width: 28px; height: 28px; border-radius: 50%; margin: auto;
  box-shadow: inset 0 -3px 0 rgba(0,0,0,0.15), 0 2px 4px rgba(0,0,0,0.12);
  border: 2px solid #fff;
}
.pawn-demo.red { background: var(--red); box-shadow: 0 0 8px var(--red); }
.pawn-demo.green { background: var(--green); box-shadow: 0 0 8px var(--green); }
.pawn-demo.yellow { background: var(--yellow); box-shadow: 0 0 8px var(--yellow); }
.pawn-demo.blue { background: var(--blue); box-shadow: 0 0 8px var(--blue); }
h1 { font-size: 36px; font-weight: 900; letter-spacing: 3px; color: var(--neon-cyan); text-shadow: 0 0 12px rgba(0,229,255,0.5); }
.menu-tagline { color: var(--tg-hint); font-size: 15px; margin-top: 4px; font-weight: 600; }
.app-version-label {
  margin-top: 10px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent, #6c5ce7);
  opacity: 0.9;
}
.app-version-foot {
  margin: 14px 0 0;
  text-align: center;
  font-size: 12px;
  color: var(--tg-hint);
}

.menu-card {
  width: 100%; max-width: 340px; margin: 0 auto;
  background: var(--tg-section); border-radius: 20px; padding: 20px; box-shadow: var(--shadow);
}
.menu-rules-link {
  display: block; width: 100%; text-align: center; color: var(--tg-link);
  font-weight: 700; font-size: 14px; background: none; border: none; padding: 8px; margin-bottom: 12px; cursor: pointer;
}

h2 { font-size: 22px; font-weight: 800; text-align: center; margin: 8px 0; }
.subtitle { color: var(--tg-hint); font-size: 14px; text-align: center; margin-bottom: 16px; font-weight: 600; }

button { font-family: inherit; -webkit-appearance: none; appearance: none; cursor: pointer; }

.btn-primary, .btn-big, .btn-action, .btn-play, .btn-roll, .btn-play-main {
  display: block; width: 100%; padding: 18px 20px; font-size: 18px; font-weight: 800;
  border: none; border-radius: var(--radius); color: #fff;
  background: linear-gradient(180deg, #ff5c8a 0%, var(--play) 100%);
  box-shadow: 0 0 16px rgba(255,45,106,0.4), 0 4px 0 var(--play-dark); margin-bottom: 10px;
}
.btn-primary:active, .btn-big:active, .btn-roll:active, .btn-play-main:active {
  transform: translateY(3px); box-shadow: 0 1px 0 var(--play-dark);
}

.menu-bot-row {
  display: flex; gap: 8px; margin: 4px 0 12px;
}
.btn-bot-count {
  flex: 1; padding: 10px 4px; font-size: 12px; font-weight: 800;
  border: 2px solid rgba(255,255,255,0.12); border-radius: 12px;
  background: var(--tg-secondary); color: var(--tg-text);
}
.btn-bot-count.active {
  border-color: var(--neon-cyan); background: rgba(0,229,255,0.12); color: var(--neon-cyan);
}
body.tg-dark .btn-bot-count.active {
  background: rgba(0,229,255,0.15); color: var(--neon-cyan);
}

.setup-preview {
  display: flex; flex-direction: column; gap: 8px; margin: 16px auto; max-width: 280px;
}
.setup-seat {
  display: flex; align-items: center; gap: 10px; padding: 12px 16px;
  background: var(--tg-section); border-radius: 14px; font-weight: 800; box-shadow: var(--shadow);
}
.setup-dot { width: 18px; height: 18px; border-radius: 50%; border: 2px solid #fff; box-shadow: 0 1px 3px rgba(0,0,0,0.15); }

.btn-secondary, .btn-multi {
  display: block; width: 100%; padding: 14px 20px; font-size: 16px; font-weight: 700;
  border: none; border-radius: var(--radius-sm); background: var(--tg-secondary);
  color: var(--tg-text); margin-bottom: 8px; box-shadow: none;
}

.btn-ghost, .btn-outline {
  background: transparent; border: 2px solid rgba(108, 92, 231, 0.35); color: var(--tg-link);
  padding: 12px 20px; border-radius: var(--radius-sm); font-weight: 700; font-size: 15px; width: 100%; margin-bottom: 8px;
}

.btn-roll:disabled, .btn-action:disabled { background: #b2bec3; box-shadow: 0 4px 0 #95a5a6; opacity: 0.7; }
.btn-small { background: transparent; border: none; color: var(--tg-hint); font-weight: 700; font-size: 15px; padding: 12px; margin-top: 8px; }

.menu-row { display: flex; gap: 10px; justify-content: center; margin-top: 16px; }
.btn-icon { width: 52px; height: 52px; font-size: 22px; border: none; border-radius: 14px; background: var(--tg-section); box-shadow: var(--shadow); }

.player-pick { display: flex; gap: 12px; justify-content: center; margin: 20px 0; }
.btn-pick {
  width: 60px; height: 60px; font-size: 26px; font-weight: 900; border: 3px solid transparent;
  border-radius: 16px; background: var(--tg-section); color: var(--tg-text); box-shadow: var(--shadow);
}
.btn-pick.active { border-color: var(--gold); background: rgba(255,229,102,0.12); transform: scale(1.05); color: var(--gold); }

.join-row { display: flex; gap: 8px; margin: 12px 0; }
.room-input {
  flex: 1; padding: 14px; font-size: 18px; font-weight: 800; text-align: center;
  text-transform: uppercase; letter-spacing: 3px; border: 2px solid #dfe6e9;
  border-radius: var(--radius-sm); background: var(--tg-section); color: var(--tg-text); font-family: inherit;
}
.btn-join { max-width: 90px !important; padding: 14px !important; font-size: 15px !important;
  background: linear-gradient(180deg, #66bb6a 0%, var(--play) 100%) !important; box-shadow: 0 4px 0 var(--play-dark) !important; }

.hidden { display: none !important; }

.screen-game { padding: 0 !important; overflow: hidden !important; background: var(--board-bg); position: relative; }
.screen-game.active {
  display: grid;
  grid-template-rows: auto 1fr auto;
  height: var(--tg-h);
  max-height: var(--tg-h);
  overflow: hidden;
}

.game-head {
  flex-shrink: 0;
  padding: 6px 10px 4px;
  background: var(--board-bg);
  min-height: 92px;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.opponent-strip-slot {
  position: relative;
  height: 0;
  flex-shrink: 0;
  overflow: hidden;
  transition: height 0.25s ease;
}
.opponent-strip-slot.strip-open {
  height: 34px;
  margin-bottom: 2px;
}

.opponent-strip {
  position: absolute;
  inset: 0;
  display: flex; align-items: center; gap: 8px;
  padding: 6px 10px;
  border-radius: 12px; background: rgba(20,24,40,0.95);
  border: 1px solid rgba(255,255,255,0.08);
  opacity: 0;
  transform: translateY(4px);
  pointer-events: none;
  transition: opacity 0.35s ease, transform 0.35s ease;
}
.opponent-strip.is-visible {
  opacity: 1;
  transform: translateY(0);
  pointer-events: none;
  box-shadow: 0 0 12px rgba(255, 229, 102, 0.15);
  border-color: rgba(255, 229, 102, 0.25);
}
.opponent-strip.is-rolling {
  animation: opp-strip-pulse 0.85s ease-in-out infinite;
}
@keyframes opp-strip-pulse {
  0%, 100% { box-shadow: 0 0 12px rgba(255, 229, 102, 0.18); }
  50% { box-shadow: 0 0 22px rgba(255, 229, 102, 0.42); }
}
.opponent-strip-dot {
  width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0;
}
.opponent-strip-name {
  flex: 1; font-size: 13px; font-weight: 800; color: var(--tg-text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.action-dock-top.opponent-dice-show {
  position: relative;
  z-index: 60;
}
.action-dock-top.opponent-dice-show .dice-dock {
  transform: scale(1.06);
  border: 2px solid rgba(255, 229, 102, 0.75) !important;
  box-shadow: 0 0 32px rgba(255, 229, 102, 0.55) !important;
  animation: opp-dock-pulse 0.65s ease-in-out infinite;
}
.action-dock-top.opponent-dice-show .die {
  animation: rollDice 0.09s ease infinite;
}
.action-dock-top.opponent-dice-show .dice-action-label {
  color: var(--gold) !important;
  font-size: 15px;
  font-weight: 900;
}
.dice-dock.opponent-rolling {
  border-color: rgba(255, 229, 102, 0.55);
  box-shadow: 0 0 20px rgba(255, 229, 102, 0.25);
  animation: opp-dock-pulse 0.9s ease-in-out infinite;
}
@keyframes opp-dock-pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.03); }
}
.dice-dock.opponent-rolling .dice-action-label { color: var(--gold); font-weight: 800; }
.mini-die {
  width: 28px; height: 28px; border-radius: 6px;
  background: linear-gradient(145deg, #fff, #e8e8e8);
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; font-weight: 900; color: #2d3436;
  box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}
.mini-die.rolling { animation: rollDice 0.1s ease infinite; }
.mini-die.dice-land { animation: diceLand 0.3s ease; }
@keyframes stripIn {
  from { opacity: 0; transform: translateY(-6px); }
  to { opacity: 1; transform: translateY(0); }
}

.race-bar {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 0 2px;
  flex-shrink: 0;
}
.race-status {
  font-size: 11px;
  font-weight: 900;
  text-align: center;
  letter-spacing: 0.3px;
  min-height: 14px;
  color: var(--tg-hint);
}
.race-status.leading { color: #7af0ff; }
.race-status.behind { color: #ff8fab; }
.race-status.danger { color: #ffe566; animation: racePulse 1.2s ease infinite; }
@keyframes racePulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.65; }
}
.race-tracks { display: flex; flex-direction: column; gap: 3px; }
.race-row {
  display: grid;
  grid-template-columns: 52px 1fr 28px;
  align-items: center;
  gap: 6px;
}
.race-label {
  font-size: 10px;
  font-weight: 800;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--tg-hint);
}
.race-label.me { color: var(--tg-text); }
.race-track {
  height: 7px;
  border-radius: 4px;
  background: rgba(255,255,255,0.08);
  overflow: hidden;
}
.race-fill {
  height: 100%;
  border-radius: 4px;
  transition: width 0.5s ease;
  box-shadow: 0 0 8px currentColor;
}
.race-fill.leader { filter: brightness(1.15); }
.race-score {
  font-size: 10px;
  font-weight: 900;
  text-align: right;
  color: var(--tg-hint);
}

.players-bar {
  display: flex;
  flex-wrap: nowrap;
  gap: 5px;
  justify-content: flex-start;
  overflow-x: auto;
  scrollbar-width: none;
  max-height: 28px;
  flex-shrink: 0;
  -webkit-overflow-scrolling: touch;
}
.players-bar::-webkit-scrollbar { display: none; }

.player-chip {
  display: flex; align-items: center; gap: 5px; padding: 4px 9px; border-radius: 16px;
  font-size: 11px; font-weight: 800; background: var(--tg-section); box-shadow: 0 1px 3px rgba(0,0,0,0.07);
}
.player-chip.leader { box-shadow: 0 0 10px rgba(255,229,102,0.35); }
.player-chip.active { box-shadow: 0 2px 8px rgba(0,0,0,0.14); transform: scale(1.02); }
.player-chip .dot { width: 8px; height: 8px; border-radius: 50%; }

#board-container {
  min-height: 0;
  width: 100%;
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2px 0;
  overflow: hidden;
  position: relative;
}
#board {
  width: min(calc(var(--tg-h) - var(--game-chrome)), calc(100vw - 12px), 440px);
  height: min(calc(var(--tg-h) - var(--game-chrome)), calc(100vw - 12px), 440px);
  display: block;
  border-radius: 10px;
  box-shadow: 0 6px 28px rgba(0,0,0,0.35);
  flex-shrink: 0;
}

.opponent-dice-overlay {
  position: absolute;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(8, 10, 22, 0.5);
  border-radius: 10px;
  pointer-events: none;
}
.opponent-dice-overlay.hidden { display: none; }
.opponent-dice-overlay-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 14px 18px;
  border-radius: 14px;
  background: rgba(22, 26, 44, 0.94);
  border: 1px solid rgba(255, 229, 102, 0.38);
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.4);
  min-width: min(72vw, 240px);
}
.opponent-dice-overlay-title {
  font-size: 15px;
  font-weight: 900;
  color: var(--gold);
  text-align: center;
}
.opponent-dice-overlay-pair {
  display: flex;
  gap: 14px;
  align-items: center;
  justify-content: center;
}
.opp-overlay-die {
  width: 56px;
  height: 56px;
  border-radius: 12px;
  background: linear-gradient(145deg, #fff, #e8e8e8);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.35);
  border: 2px solid rgba(255, 255, 255, 0.85);
}
.opp-overlay-die span {
  font-size: 28px;
  font-weight: 900;
  color: #2d3436;
  line-height: 1;
}
.opp-overlay-die.rolling { animation: rollDice 0.09s ease infinite; }
.opp-overlay-die.dice-land { animation: diceLand 0.35s ease; }
.opp-overlay-die.dice-six {
  box-shadow: 0 0 18px rgba(255, 214, 0, 0.75);
  border-color: #ffd700;
}
.opponent-dice-overlay-sum {
  font-size: 18px;
  font-weight: 900;
  color: #fff;
  min-height: 1.4em;
  letter-spacing: 0.02em;
}

.game-guide {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 150;
}
.game-guide.hidden { display: none; }
.guide-arrows {
  position: absolute;
  inset: 0;
  overflow: visible;
}
.guide-arrow {
  position: fixed;
  display: flex;
  flex-direction: column;
  align-items: center;
  transform: translate(-50%, -100%);
  animation: guide-arrow-bounce 1.1s ease-in-out infinite;
  filter: drop-shadow(0 0 10px rgba(255, 229, 102, 0.75));
}
.guide-arrow-line {
  width: 3px;
  height: 30px;
  background: linear-gradient(180deg, #ffe566 0%, #ffb800 100%);
  border-radius: 2px;
}
.guide-arrow-tip {
  width: 0;
  height: 0;
  margin-top: -1px;
  border-left: 11px solid transparent;
  border-right: 11px solid transparent;
  border-top: 15px solid #ffb800;
}
@keyframes guide-arrow-bounce {
  0%, 100% { transform: translate(-50%, -100%) translateY(0); }
  50% { transform: translate(-50%, -100%) translateY(10px); }
}
.guide-bubble {
  position: fixed;
  left: 50%;
  top: max(10px, env(safe-area-inset-top));
  transform: translateX(-50%);
  width: min(340px, calc(100vw - 24px));
  padding: 12px 14px;
  border-radius: 14px;
  background: rgba(12, 12, 24, 0.92);
  border: 2px solid rgba(0, 229, 255, 0.45);
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.45);
  text-align: center;
  pointer-events: auto;
}
.game-guide-step {
  display: block;
  font-size: 11px;
  font-weight: 800;
  color: var(--neon-cyan);
  margin-bottom: 4px;
}
.guide-bubble p {
  font-size: 14px;
  font-weight: 800;
  line-height: 1.35;
  margin-bottom: 8px;
}
.guide-bubble .btn-small {
  font-size: 12px;
  padding: 6px 12px;
}
.guide-highlight {
  outline: 3px solid #ffe566 !important;
  outline-offset: 3px;
  box-shadow: 0 0 24px rgba(255,229,102,0.55) !important;
  z-index: 15;
  position: relative;
}

.action-dock {
  flex-shrink: 0;
  padding: 0;
  background: transparent;
}
.action-dock-top {
  padding: 4px 0 0;
}

.game-playfield {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4px;
  align-items: stretch;
  padding: 0 6px;
}

.game-roll-layer {
  position: absolute;
  inset: 0;
  z-index: 25;
  border: none;
  background: transparent;
  cursor: pointer;
  padding: 0;
  margin: 0;
  font-family: inherit;
}
.game-roll-layer.can-roll {
  background: radial-gradient(ellipse at 50% 55%, rgba(0, 229, 255, 0.06) 0%, transparent 70%);
  animation: boardTapPulse 2.4s ease-in-out infinite;
}
.game-roll-layer.hidden { display: none !important; pointer-events: none; }
.game-roll-layer:disabled { display: none !important; }

.game-rail {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  border: 2px solid rgba(255,255,255,0.1);
  border-radius: 14px;
  background: rgba(18,18,34,0.92);
  color: var(--tg-text);
  font-family: inherit;
  cursor: pointer;
  padding: 8px 4px;
  transition: border-color 0.2s, box-shadow 0.2s, transform 0.12s, opacity 0.2s;
  box-shadow: 0 2px 12px rgba(0,0,0,0.2);
}
.game-rail .rail-icon { font-size: 22px; line-height: 1; }
.game-rail .rail-label {
  font-size: 9px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--tg-hint);
  writing-mode: vertical-rl;
  transform: rotate(180deg);
}
.game-rail.rail-left.can-roll {
  border-color: rgba(0,229,255,0.75);
  box-shadow: 0 0 18px rgba(0,229,255,0.35);
  animation: diceReadyPulse 2.2s ease-in-out infinite;
}
.game-rail.rail-right.is-visible {
  border-color: rgba(255,229,102,0.65);
}
.game-rail:active:not(:disabled) { transform: scale(0.96); }
.game-rail:disabled { opacity: 0.35; cursor: default; }
.game-rail.hidden { visibility: hidden; pointer-events: none; }

.board-tap-layer {
  position: absolute;
  inset: 0;
  z-index: 5;
  border: none;
  border-radius: 10px;
  background: transparent;
  cursor: pointer;
  padding: 0;
}
.board-tap-layer.can-roll {
  background: radial-gradient(ellipse at center, rgba(0,229,255,0.07) 0%, transparent 68%);
  animation: boardTapPulse 2.4s ease-in-out infinite;
}
.board-tap-layer.hidden { display: none; }
@keyframes boardTapPulse {
  0%, 100% { box-shadow: inset 0 0 0 0 rgba(0,229,255,0); }
  50% { box-shadow: inset 0 0 24px 2px rgba(0,229,255,0.12); }
}

.game-foot {
  flex-shrink: 0;
  padding: 6px 12px max(10px, env(safe-area-inset-bottom));
  text-align: center;
}
.turn-hint {
  font-size: 12px;
  font-weight: 700;
  color: var(--tg-hint);
  line-height: 1.35;
}
.turn-hint.active-turn { color: var(--neon-cyan); }
.turn-hint.pick-turn { color: var(--gold); }
.turn-hint.spectator-turn {
  color: #ffb347;
  font-size: 14px;
  font-weight: 800;
}
.turn-hint.skip-turn {
  color: var(--gold);
  font-size: 15px;
  font-weight: 900;
  animation: skipPulse 0.9s ease-in-out infinite;
}
.turn-hint.handoff-turn {
  color: var(--neon-cyan);
  font-size: 15px;
  font-weight: 900;
}
@keyframes skipPulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.85; transform: scale(1.02); }
}
#board-container.spectator-mode {
  box-shadow: inset 0 0 0 3px rgba(255, 179, 71, 0.35);
  border-radius: 8px;
}

.settings-label {
  font-size: 13px;
  font-weight: 800;
  margin: 0 0 10px;
  color: var(--tg-hint);
}
.color-picker {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-bottom: 14px;
}
.color-swatch {
  aspect-ratio: 1;
  border-radius: 12px;
  border: 3px solid transparent;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0,0,0,0.25);
  transition: transform 0.12s, border-color 0.15s;
}
.color-swatch.active {
  border-color: #fff;
  transform: scale(1.06);
  box-shadow: 0 0 14px currentColor;
}
.color-swatch:active { transform: scale(0.95); }

.lane-glow-cell { pointer-events: none; }
.lane-glow-start { pointer-events: none; }
.lane-glow-base { pointer-events: none; }

.action-dock-bottom {
  flex-shrink: 0;
  min-height: 92px;
  padding: 6px 12px max(12px, env(safe-area-inset-bottom));
  background: linear-gradient(180deg, transparent 0%, rgba(8,8,16,0.92) 28%);
}

.dice-dock {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 14px;
  align-items: center;
  width: 100%;
  min-height: 76px;
  padding: 10px 16px;
  border: 2px solid rgba(255,255,255,0.1);
  border-radius: 20px;
  background: rgba(18,18,34,0.96);
  cursor: pointer;
  font-family: inherit;
  text-align: left;
  transition: border-color 0.2s, box-shadow 0.2s, transform 0.15s, background 0.2s;
  flex-shrink: 0;
  box-shadow: 0 4px 20px rgba(0,0,0,0.25);
}

.dice-stage { position: relative; flex-shrink: 0; }

.dice-dock.can-roll {
  border-color: rgba(0,229,255,0.85);
  background: linear-gradient(135deg, rgba(0,229,255,0.18) 0%, rgba(255,45,106,0.1) 100%);
  box-shadow: 0 0 28px rgba(0,229,255,0.4), inset 0 0 24px rgba(0,229,255,0.06);
  animation: diceReadyPulse 2.2s ease-in-out infinite;
}
.dice-dock.can-roll:active { transform: scale(0.98); }
.dice-dock.can-roll .die {
  border-color: rgba(0,229,255,0.5);
  box-shadow: inset 0 2px 4px #fff, 0 4px 14px rgba(0,229,255,0.35);
}

.dice-dock.pick-token {
  border-color: rgba(255,229,102,0.75);
  background: linear-gradient(135deg, rgba(255,229,102,0.14) 0%, rgba(18,18,34,0.96) 100%);
  box-shadow: 0 0 20px rgba(255,229,102,0.25);
}
.dice-dock.pick-token .dice-action-label { color: var(--gold); }

.dice-dock.is-locked {
  opacity: 0.82;
  cursor: default;
  border-color: rgba(255,255,255,0.06);
}
.dice-dock.is-locked .dice-action-label { color: var(--tg-hint); }

.dice-dock.is-rolling {
  border-color: rgba(0,229,255,0.5);
  animation: none;
  pointer-events: none;
}
.dice-dock.pulse-once { animation: diceReadyPulse 0.55s ease; }

@keyframes diceReadyPulse {
  0%, 100% { box-shadow: 0 0 22px rgba(0,229,255,0.32), inset 0 0 16px rgba(0,229,255,0.05); }
  50% { box-shadow: 0 0 36px rgba(0,229,255,0.55), inset 0 0 24px rgba(0,229,255,0.1); }
}

.dice-dock-center {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 2px;
  min-width: 0;
}

.dice-action-label {
  font-size: 18px;
  font-weight: 900;
  color: var(--tg-text);
  line-height: 1.15;
  letter-spacing: 0.2px;
}
.dice-dock.can-roll .dice-action-label { color: #7af0ff; }

.dice-pair { display: flex; gap: 10px; flex-shrink: 0; }
.die {
  width: 50px; height: 50px;
  background: linear-gradient(155deg, #fff 0%, #e4e4e4 55%, #d0d0d0 100%);
  border-radius: 12px; display: flex; align-items: center; justify-content: center;
  box-shadow: inset 0 2px 4px #fff, 0 4px 10px rgba(0,0,0,0.2);
  border: 2px solid rgba(0,0,0,0.12);
  transition: box-shadow 0.2s, border-color 0.2s;
}
.die span { font-size: 24px; font-weight: 900; color: #1a1a2e; line-height: 1; }
.die.rolling { animation: rollDice 0.1s ease infinite; }
.die.dice-land { animation: diceLand 0.3s ease; }
.die.dice-six { animation: diceSix 0.5s ease; box-shadow: 0 0 16px var(--gold); }
.die.die-used { opacity: 0.38; filter: grayscale(0.55); transform: scale(0.9); }

.dice-sum {
  display: block; font-size: 14px; font-weight: 800; color: var(--tg-hint);
  line-height: 1.2; min-height: 18px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.dice-sum:empty { display: none; }
.dice-dock.can-roll .dice-sum { color: rgba(122,240,255,0.85); }
.dice-dock.pick-token .dice-sum { color: var(--gold); opacity: 0.9; }

.move-panel {
  flex: 1; min-height: 54px; max-height: 54px;
  display: flex; flex-direction: column; justify-content: center;
  overflow: hidden;
}
.move-panel.is-empty { pointer-events: none; }
.move-panel.is-empty .move-panel-title,
.move-panel.is-empty .move-chips { opacity: 0; }
.move-panel-title {
  font-size: 11px; font-weight: 800; color: var(--tg-hint);
  text-transform: uppercase; letter-spacing: 0.4px; margin-bottom: 4px; text-align: center;
  min-height: 14px; flex-shrink: 0;
}
.move-chips {
  display: flex; gap: 8px; overflow-x: auto; overflow-y: hidden;
  padding-bottom: 2px; flex: 1; align-items: center;
  -webkit-overflow-scrolling: touch; scrollbar-width: none;
}
.move-chips::-webkit-scrollbar { display: none; }
.btn-move-chip {
  flex-shrink: 0; display: flex; align-items: center; gap: 8px;
  padding: 8px 12px; font-size: 13px; font-weight: 800; border: none;
  border-radius: 12px; background: var(--tg-secondary); color: var(--tg-text);
  box-shadow: var(--shadow); font-family: inherit; cursor: pointer; white-space: nowrap;
  touch-action: manipulation;
}
.btn-move-chip:active { transform: scale(0.96); }
.move-dot { width: 16px; height: 16px; border-radius: 50%; border: 2px solid #fff; box-shadow: 0 1px 3px rgba(0,0,0,0.2); flex-shrink: 0; }

body.tg-dark { --board-bg: #080810; }
body.tg-dark .screen-game { background: #080810; }

.list li.lobby-empty { opacity: 0.45; font-style: italic; }
.list li {
  padding: 14px 16px; background: var(--tg-section); border-radius: var(--radius-sm);
  margin-bottom: 8px; display: flex; justify-content: space-between; font-weight: 700; box-shadow: var(--shadow);
}
.achievements-grid { width: 100%; display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.ach-card { background: var(--tg-section); border-radius: var(--radius-sm); padding: 14px; text-align: center; box-shadow: var(--shadow); }
.ach-card.locked { opacity: 0.4; }
.ach-card .emoji { font-size: 28px; }
.ach-card .title { font-size: 12px; font-weight: 800; margin-top: 6px; }
.ach-card .desc { font-size: 10px; color: var(--tg-hint); margin-top: 4px; }

.profile-stats { width: 100%; background: var(--tg-section); border-radius: var(--radius); padding: 20px; font-size: 16px; font-weight: 700; line-height: 2; box-shadow: var(--shadow); }
.result-emoji { font-size: 72px; margin-top: 32px; }
.result-xp { font-size: 22px; color: var(--gold); font-weight: 900; margin: 12px 0; }
.room-code { color: var(--tg-link); letter-spacing: 4px; font-weight: 900; }

.dice.rolling { animation: rollDice 0.12s ease infinite; }
.die.rolling { animation: rollDice 0.1s ease infinite; }
.dice.dice-land, .die.dice-land { animation: diceLand 0.35s ease; }
.dice.dice-six, .die.dice-six { animation: diceSix 0.5s ease; box-shadow: 0 0 16px var(--gold); }
@keyframes rollDice { 50% { transform: rotate(12deg) scale(1.05); } }
@keyframes diceLand { 0% { transform: scale(1.2); } 100% { transform: scale(1); } }
@keyframes diceSix { 50% { transform: scale(1.1); } }

#toast-box { position: fixed; top: max(12px, env(safe-area-inset-top)); left: 50%; transform: translateX(-50%); z-index: 9999; width: 92%; max-width: 360px; pointer-events: none; }
.toast { padding: 14px 18px; border-radius: var(--radius-sm); font-weight: 800; font-size: 15px; text-align: center; opacity: 0; transform: translateY(-10px); transition: all 0.3s; background: var(--tg-section); box-shadow: var(--shadow-lg); margin-bottom: 8px; }
.toast.show { opacity: 1; transform: translateY(0); }
.toast-gold { border: 2px solid var(--gold); }
.toast-hit { border: 2px solid var(--red); }
.toast-info { border: 2px solid var(--tg-link); }

#fx-layer { position: fixed; inset: 0; pointer-events: none; z-index: 9998; }
.particle { position: absolute; width: 8px; height: 8px; border-radius: 50%; animation: particleFly 0.7s ease-out forwards; }
@keyframes particleFly { to { transform: translate(var(--dx), var(--dy)); opacity: 0; } }
.confetti { position: absolute; top: -10px; width: 8px; height: 12px; border-radius: 2px; animation: confettiFall 2.5s linear forwards; }
@keyframes confettiFall { to { transform: translateY(100vh) rotate(720deg); opacity: 0; } }

.tutorial, .rules-card {
  position: fixed; inset: 0; background: rgba(45,52,54,0.75); backdrop-filter: blur(4px);
  z-index: 10000; display: flex; align-items: center; justify-content: center; padding: 20px;
}
.tutorial-card, .rules-inner {
  background: var(--tg-section); border-radius: 24px; padding: 24px; max-width: 360px; width: 100%; box-shadow: var(--shadow-lg);
}
.tutorial-step-num { color: var(--tg-link); font-weight: 900; font-size: 13px; margin-bottom: 8px; }
.tutorial-card h3 { font-size: 22px; font-weight: 900; margin-bottom: 12px; }
.tutorial-card p { font-size: 15px; line-height: 1.55; color: var(--tg-hint); font-weight: 600; margin-bottom: 20px; }
.tutorial-btns { display: flex; flex-direction: column; gap: 8px; }
.rules-inner { max-height: 80vh; overflow-y: auto; }
.rules-inner h3 { color: var(--tg-link); font-weight: 900; margin-bottom: 12px; }
.rules-inner ol { padding-left: 20px; font-weight: 600; line-height: 1.6; }
.rules-inner li { margin-bottom: 8px; }
.ach-badge { background: rgba(255,229,102,0.15); padding: 12px; border-radius: var(--radius-sm); margin-bottom: 8px; font-weight: 800; border: 2px solid var(--gold); color: var(--gold); }
.legal-card {
  width: 100%; padding: 16px; background: var(--tg-section); border-radius: var(--radius);
  font-size: 14px; line-height: 1.55; color: var(--tg-hint); box-shadow: var(--shadow); margin-bottom: 12px;
}
.legal-card p { margin: 0 0 12px; }
.btn-play-main.is-loading, .btn-play-main:disabled { opacity: 0.65; pointer-events: none; }

/* Всплывающее окно выбора хода */
.move-dialog {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(4px);
  z-index: 11000;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 12px;
}
.move-dialog.hidden { display: none; }
.move-dialog-card {
  width: 100%;
  max-width: 420px;
  background: var(--tg-section);
  border-radius: 20px 20px 0 0;
  padding: 14px 14px max(14px, env(safe-area-inset-bottom));
  box-shadow: 0 -6px 24px rgba(0,0,0,0.35);
}
.move-dialog-card h3 {
  font-size: 16px;
  font-weight: 900;
  text-align: center;
  margin-bottom: 8px;
}
.move-dialog-list {
  max-height: 210px;
  overflow-y: auto;
  padding: 4px 0;
  margin-bottom: 4px;
}
.move-dialog-btn {
  width: 100%;
  margin-bottom: 8px;
  padding: 16px 18px;
  border-radius: 16px;
  border: 1px solid rgba(0,229,255,0.25);
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  font-size: 17px;
  font-weight: 900;
  background: rgba(0,229,255,0.06);
  color: var(--tg-text);
  box-shadow: 0 0 12px rgba(0,229,255,0.1);
  text-align: left;
}
.move-dialog-btn:active { transform: scale(0.98); background: rgba(255,45,106,0.15); border-color: var(--neon-pink); }
.move-dialog-btn-main { font-size: 18px; }
.move-dialog-btn-sub {
  font-size: 13px;
  font-weight: 700;
  color: var(--tg-hint);
}
.move-dialog-cancel {
  width: 100%;
  text-align: center;
  margin-top: 6px;
}

/* Token stacks */
.stack-footprint {
  animation: stack-glow 2s ease-in-out infinite;
}
.stack-footprint.stack-mixed {
  animation: stack-mixed-glow 1.6s ease-in-out infinite;
}
@keyframes stack-mixed-glow {
  0%, 100% { stroke-opacity: 0.55; }
  50% { stroke-opacity: 1; }
}
.stack-count-badge {
  paint-order: stroke;
  stroke: rgba(0,0,0,0.65);
  stroke-width: 0.35px;
}
.token.stacked {
  filter: drop-shadow(0 1px 2px rgba(0,0,0,0.45));
}
@keyframes stack-glow {
  0%, 100% { stroke-opacity: 0.45; }
  50% { stroke-opacity: 0.95; }
}
.move-preview-line {
  pointer-events: none;
}
.move-preview-ring {
  animation: dest-pulse 1.2s ease-in-out infinite;
  pointer-events: auto;
  cursor: pointer;
}
.move-preview-hit {
  cursor: pointer;
}

/* Token selection & move hints */
.dest-hint {
  animation: dest-pulse 1.2s ease-in-out infinite;
}
.dest-hit { cursor: pointer; }
@keyframes dest-pulse {
  0%, 100% { opacity: 0.35; transform: scale(1); }
  50% { opacity: 0.65; transform: scale(1.06); }
}
.token-ring.selected {
  animation: token-select 1s ease-in-out infinite;
}
@keyframes token-select {
  0%, 100% { opacity: 0.85; }
  50% { opacity: 1; stroke-width: 0.9; }
}
.trail-blur { pointer-events: none; mix-blend-mode: screen; }
.token-glow { pointer-events: none; mix-blend-mode: screen; }
.token { pointer-events: none; }
.token-ring { pointer-events: none; }
.token-hit {
  cursor: pointer;
  touch-action: manipulation;
}
.dest-hint, .dest-hit {
  cursor: pointer;
  touch-action: manipulation;
}
.token.moving { pointer-events: none; }
.token-trail-group { pointer-events: none; }
.capture-ripple { pointer-events: none; }

/* Accessibility */
.dice-dock:focus-visible,
.game-rail:focus-visible,
.game-roll-layer:focus-visible,
.btn-play-main:focus-visible,
.token-hit:focus-visible,
.dest-hit:focus-visible {
  outline: 2px solid var(--neon-cyan);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
  .die.rolling { animation: none !important; }
}
