:root {
  --bg-primary: #0e111a;
  --bg-secondary: #171b26;
  --bg-card: #1f2433;
  --bg-card-hover: #293044;
  --border-color: #2e364a;
  --text-main: #f9fafb;
  --text-muted: #9aa5b8;
  --accent-primary: #8b5cf6;
  --accent-hover: #7c3aed;
  --accent-glow: rgba(139, 92, 246, 0.35);

  --p1: #ef4444; /* Ruby Red */
  --p2: #3b82f6; /* Ocean Blue */
  --p3: #10b981; /* Emerald Green */
  --p4: #f59e0b; /* Amber Gold */

  --font-main: 'Fredoka', system-ui, -apple-system, sans-serif;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-main);
  background-color: var(--bg-primary);
  color: var(--text-main);
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  overflow-x: hidden;
}

.app-container {
  width: 100%;
  max-width: 1300px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  padding: 16px 20px;
}

/* Screens */
.screen {
  display: none;
  width: 100%;
  flex: 1;
  animation: fadeIn 0.3s ease-out;
}

.screen.active {
  display: flex;
  flex-direction: column;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Setup Screen */
#setup-screen {
  justify-content: center;
  align-items: center;
  padding: 24px 12px;
}

.setup-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 28px;
  padding: 38px;
  width: 100%;
  max-width: 520px;
  box-shadow: 0 24px 50px rgba(0, 0, 0, 0.45);
  text-align: center;
}

.brand-badge {
  display: inline-block;
  background: rgba(139, 92, 246, 0.15);
  color: #c4b5fd;
  font-size: 13px;
  font-weight: 600;
  padding: 6px 14px;
  border-radius: 20px;
  margin-bottom: 14px;
  border: 1px solid rgba(139, 92, 246, 0.3);
}

.setup-card h1 {
  font-size: 36px;
  font-weight: 700;
  margin-bottom: 6px;
  background: linear-gradient(135deg, #ffffff 40%, #c4b5fd 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.subtitle {
  color: var(--text-muted);
  font-size: 14.5px;
  line-height: 1.4;
  margin-bottom: 24px;
}

.setup-section {
  text-align: left;
  margin-bottom: 18px;
}

.setup-section label {
  display: block;
  font-size: 12px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 8px;
}

.mode-selector, .count-selector {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.count-selector {
  grid-template-columns: repeat(3, 1fr);
}

.mode-btn, .count-btn {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  padding: 12px 8px;
  border-radius: 12px;
  font-family: var(--font-main);
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.mode-btn:hover, .count-btn:hover {
  background: var(--bg-card-hover);
  border-color: #434c64;
}

.mode-btn.active, .count-btn.active {
  background: var(--accent-primary);
  border-color: var(--accent-primary);
  color: #fff;
  box-shadow: 0 4px 14px var(--accent-glow);
}

.player-customizer {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 220px;
  overflow-y: auto;
  padding-right: 4px;
}

.player-custom-row {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--bg-card);
  padding: 8px 14px;
  border-radius: 14px;
  border: 1px solid var(--border-color);
}

.player-color-preview {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  flex-shrink: 0;
  display: grid;
  place-items: center;
  font-size: 16px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
}

.player-name-input {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text-main);
  font-family: var(--font-main);
  font-size: 15px;
  font-weight: 600;
  outline: none;
  padding: 4px 6px;
  border-radius: 6px;
}

.player-name-input:focus {
  background: rgba(255, 255, 255, 0.05);
}

.player-type-badge {
  font-size: 11px;
  font-weight: 600;
  background: var(--border-color);
  padding: 4px 8px;
  border-radius: 6px;
  color: var(--text-muted);
}

.primary-btn {
  width: 100%;
  background: linear-gradient(135deg, #8b5cf6 0%, #6d28d9 100%);
  color: white;
  border: none;
  padding: 15px 20px;
  border-radius: 14px;
  font-family: var(--font-main);
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 6px 20px var(--accent-glow);
  transition: all 0.2s ease;
}

.primary-btn:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(139, 92, 246, 0.45);
}

.primary-btn:active:not(:disabled) {
  transform: translateY(0);
}

.primary-btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

/* Header */
.game-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 0 18px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  margin-bottom: 16px;
}

.header-left, .header-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.game-title-mini {
  font-weight: 700;
  font-size: 19px;
  background: linear-gradient(135deg, #fff 40%, #c4b5fd 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  margin-left: 6px;
}

.icon-btn {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  padding: 8px 14px;
  border-radius: 10px;
  font-family: var(--font-main);
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.icon-btn:hover {
  background: var(--border-color);
}

/* Layout */
.game-layout {
  display: grid;
  grid-template-columns: minmax(320px, 1fr) 360px;
  gap: 24px;
  flex: 1;
  align-items: start;
}

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

/* Board Column */
.board-column {
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-items: center;
}

.start-dock {
  width: 100%;
  max-width: 620px;
  background: var(--bg-secondary);
  border: 1px dashed var(--border-color);
  border-radius: 14px;
  padding: 8px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.dock-label {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-muted);
  letter-spacing: 0.05em;
}

.dock-tokens {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 32px;
}

.board-container {
  width: 100%;
  max-width: 620px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 20px;
  padding: 14px;
  box-shadow: 0 16px 36px rgba(0, 0, 0, 0.4);
}

.board {
  width: 100%;
  aspect-ratio: 1;
  position: relative;
  border-radius: 14px;
  overflow: hidden;
  background: #12141c;
  border: 2px solid #333c52;
}

.board-cells {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-columns: repeat(10, 1fr);
  grid-template-rows: repeat(10, 1fr);
  z-index: 1;
}

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

/* Cells */
.cell {
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 3px 4px;
  font-size: 11px;
  border: 0.5px solid rgba(255, 255, 255, 0.04);
  user-select: none;
  transition: background-color 0.2s ease;
}

.cell:nth-child(even) {
  background: rgba(255, 255, 255, 0.02);
}

.cell:nth-child(odd) {
  background: rgba(255, 255, 255, 0.05);
}

.cell.cell-100 {
  background: linear-gradient(135deg, rgba(245, 158, 11, 0.25), rgba(239, 68, 68, 0.25));
  border: 1px solid rgba(245, 158, 11, 0.5);
}

.cell.cell-ladder-bottom {
  background: rgba(16, 185, 129, 0.14);
}

.cell.cell-snake-head {
  background: rgba(239, 68, 68, 0.14);
}

.cell-number {
  font-size: 10.5px;
  font-weight: 700;
  color: rgba(255, 255, 255, 0.5);
}

.cell.cell-100 .cell-number {
  color: #fbbf24;
}

.cell-badge {
  position: absolute;
  top: 2px;
  right: 2px;
  font-size: 11px;
  line-height: 1;
  pointer-events: none;
}

/* Token Containers */
.tokens-container {
  position: absolute;
  inset: 0;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 2px;
  padding: 2px;
  z-index: 5;
  pointer-events: none;
}

.token {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 12px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.6);
  border: 2px solid #ffffff;
  transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
  animation: popIn 0.25s ease-out;
}

@keyframes popIn {
  0% { transform: scale(0.3); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

.token.p1 { background: var(--p1); }
.token.p2 { background: var(--p2); }
.token.p3 { background: var(--p3); }
.token.p4 { background: var(--p4); }

/* Control Panel */
.control-panel {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.current-turn-card, .dice-section, .players-status-card, .game-log-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 20px;
  padding: 18px 20px;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.2);
}

/* Turn Card */
.current-turn-card {
  display: flex;
  align-items: center;
  gap: 16px;
  border-left: 5px solid var(--accent-primary);
  transition: border-color 0.3s ease;
}

.turn-avatar {
  width: 48px;
  height: 48px;
  border-radius: 14px;
  background: var(--bg-card);
  display: grid;
  place-items: center;
  font-size: 24px;
  border: 2px solid var(--border-color);
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.25);
  transition: border-color 0.3s ease;
}

.turn-label {
  font-size: 11.5px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.current-turn-card h3 {
  font-size: 19px;
  font-weight: 700;
  margin: 2px 0;
}

.turn-hint {
  font-size: 13px;
  color: var(--text-muted);
}

/* 3D Dice Section */
.dice-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 14px;
  padding: 22px 20px;
}

.dice-scene {
  width: 70px;
  height: 70px;
  perspective: 450px;
  cursor: pointer;
  user-select: none;
}

.dice {
  width: 100%;
  height: 100%;
  position: relative;
  transform-style: preserve-3d;
  transition: transform 0.6s cubic-bezier(0.2, 0.85, 0.4, 1.25);
}

.dice.rolling {
  animation: diceJumble 0.6s infinite linear;
}

@keyframes diceJumble {
  0% { transform: rotateX(0deg) rotateY(0deg) rotateZ(0deg); }
  25% { transform: rotateX(180deg) rotateY(90deg) rotateZ(45deg); }
  50% { transform: rotateX(360deg) rotateY(180deg) rotateZ(90deg); }
  75% { transform: rotateX(180deg) rotateY(270deg) rotateZ(135deg); }
  100% { transform: rotateX(360deg) rotateY(360deg) rotateZ(180deg); }
}

.dice-face {
  position: absolute;
  width: 70px;
  height: 70px;
  background: #ffffff;
  border: 2px solid #e2e8f0;
  border-radius: 14px;
  box-shadow: inset 0 3px 6px rgba(0, 0, 0, 0.12), 0 4px 10px rgba(0, 0, 0, 0.3);
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  padding: 8px;
}

/* Face 3D Positions (depth = 35px) */
.dice-face.face-1 { transform: rotateY(0deg) translateZ(35px); }
.dice-face.face-6 { transform: rotateY(180deg) translateZ(35px); }
.dice-face.face-3 { transform: rotateY(-90deg) translateZ(35px); }
.dice-face.face-4 { transform: rotateY(90deg) translateZ(35px); }
.dice-face.face-5 { transform: rotateX(-90deg) translateZ(35px); }
.dice-face.face-2 { transform: rotateX(90deg) translateZ(35px); }

/* Transformations to bring a given face front and center */
.dice.show-1 { transform: rotateX(0deg) rotateY(0deg); }
.dice.show-2 { transform: rotateX(-90deg) rotateY(0deg); }
.dice.show-3 { transform: rotateX(0deg) rotateY(90deg); }
.dice.show-4 { transform: rotateX(0deg) rotateY(-90deg); }
.dice.show-5 { transform: rotateX(90deg) rotateY(0deg); }
.dice.show-6 { transform: rotateX(0deg) rotateY(180deg); }

/* Pip Dots inside Dice */
.pip {
  background: #1e293b;
  border-radius: 50%;
  width: 9.5px;
  height: 9.5px;
  align-self: center;
  justify-self: center;
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.4);
}

.face-1 .pip-center { grid-column: 2; grid-row: 2; background: #dc2626; width: 12px; height: 12px; }

.pip-tl { grid-column: 1; grid-row: 1; }
.pip-tr { grid-column: 3; grid-row: 1; }
.pip-cl { grid-column: 1; grid-row: 2; }
.pip-center { grid-column: 2; grid-row: 2; }
.pip-cr { grid-column: 3; grid-row: 2; }
.pip-bl { grid-column: 1; grid-row: 3; }
.pip-br { grid-column: 3; grid-row: 3; }

.dice-result-text {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-muted);
}

/* Standings */
.players-status-card h4, .log-header h4 {
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}

.player-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 10px;
}

.player-status-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  background: var(--bg-card);
  border-radius: 12px;
  border: 1px solid var(--border-color);
  transition: all 0.2s ease;
}

.player-status-item.active-turn {
  border-color: var(--accent-primary);
  background: rgba(139, 92, 246, 0.12);
}

.player-status-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.player-status-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  box-shadow: 0 0 6px currentColor;
}

.player-status-name {
  font-size: 14.5px;
  font-weight: 600;
}

.player-status-pos {
  font-size: 13.5px;
  font-weight: 700;
  color: var(--accent-primary);
  background: rgba(139, 92, 246, 0.18);
  padding: 3px 9px;
  border-radius: 8px;
}

/* Activity Feed */
.log-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.text-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-family: var(--font-main);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  padding: 2px 6px;
}

.text-btn:hover {
  color: var(--text-main);
}

.game-log {
  max-height: 125px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding-right: 4px;
}

.log-entry {
  font-size: 12.5px;
  color: var(--text-muted);
  padding: 6px 10px;
  background: var(--bg-card);
  border-radius: 8px;
  border-left: 3px solid var(--border-color);
  line-height: 1.35;
}

.log-entry.log-ladder {
  border-left-color: #10b981;
  color: #a7f3d0;
}

.log-entry.log-snake {
  border-left-color: #ef4444;
  color: #fecaca;
}

.log-entry.log-bonus {
  border-left-color: #f59e0b;
  color: #fef08a;
}

/* Modals */
.modal {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.72);
  backdrop-filter: blur(6px);
  z-index: 100;
  justify-content: center;
  align-items: center;
  padding: 20px;
  animation: fadeIn 0.2s ease;
}

.modal.active {
  display: flex;
}

.modal-content {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 26px;
  padding: 34px 28px;
  width: 100%;
  max-width: 460px;
  text-align: center;
  box-shadow: 0 24px 50px rgba(0, 0, 0, 0.6);
  animation: popIn 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.rules-content {
  text-align: left;
}

.rules-content h2 {
  text-align: center;
  margin-bottom: 18px;
  font-size: 24px;
}

.rules-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 24px;
}

.rules-list li {
  font-size: 14px;
  color: var(--text-muted);
  line-height: 1.45;
  padding-left: 20px;
  position: relative;
}

.rules-list li::before {
  content: '•';
  color: var(--accent-primary);
  font-size: 20px;
  position: absolute;
  left: 4px;
  top: -2px;
}

.rules-list strong {
  color: var(--text-main);
}

.trophy-icon {
  font-size: 64px;
  margin-bottom: 12px;
  animation: bounce 1.2s infinite alternate;
}

@keyframes bounce {
  from { transform: translateY(0); }
  to { transform: translateY(-10px); }
}

.modal-content h2 {
  font-size: 28px;
  font-weight: 700;
  margin-bottom: 6px;
}

.modal-content p {
  color: var(--text-muted);
  font-size: 15px;
  margin-bottom: 20px;
}

.modal-stats {
  background: var(--bg-card);
  border-radius: 12px;
  padding: 12px;
  margin-bottom: 20px;
  font-size: 14px;
  color: var(--text-muted);
}

.modal-actions {
  display: flex;
  gap: 12px;
}

.secondary-btn {
  flex: 1;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  padding: 14px;
  border-radius: 14px;
  font-family: var(--font-main);
  font-weight: 700;
  font-size: 15px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.secondary-btn:hover {
  background: var(--bg-card-hover);
}

/* Custom Scrollbars */
::-webkit-scrollbar {
  width: 6px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: var(--border-color);
  border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}
