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

html, body {
  width: 100%;
  height: 100%;
  font-family: "Segoe UI", Arial, sans-serif;
  background: #e2bd59;
  color: #1f2937;
}

body {
  overflow: hidden;
}

body.theme-dark {
  background: #1f1f1f;
  color: #e5e7eb;
}

body.theme-dark .menu-card,
body.theme-dark .modal-card,
body.theme-dark .controls-panel {
  background: #2b2b2b;
  color: #e5e7eb;
  border-color: #3b3b3b;
}

body.theme-dark .modal-text,
body.theme-dark .modal-title,
body.theme-dark .modal-heading {
  color: #e5e7eb;
}

body.theme-dark .board-wrap {
  background: #2a2a2a;
  border-color: #e5e7eb;
}

body.theme-dark .ghost-btn {
  background: #3b3b3b;
  color: #e5e7eb;
  border-color: #4b4b4b;
}

.app {
  height: 100%;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 12px;
  align-items: center;
}

.app-header {
  display: none;
}

.app-title {
  font-size: 1.6rem;
  font-weight: 800;
}

.app-subtitle {
  color: #6b7280;
}

.hud-mini {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  background: #6b6b55;
  color: #fff;
  border-radius: 12px;
  padding: 10px 12px;
  border: none;
}

.hud-item {
  font-size: 0.9rem;
  color: #374151;
}

.screen {
  display: none;
  flex: 1;
  overflow: hidden;
  width: 100%;
  max-width: 1200px;
}

.screen.active {
  display: block;
}

.screen-menu.active {
  display: flex;
  justify-content: center;
  align-items: center;
}

.menu-card {
  max-width: 420px;
  background: #fff;
  border-radius: 16px;
  padding: 20px;
  border: 1px solid #e5e7eb;
  box-shadow: 0 10px 24px rgba(15, 23, 42, 0.1);
  width: 100%;
}

.menu-title {
  font-size: 1.2rem;
  font-weight: 700;
  margin-bottom: 12px;
}

.menu-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 12px;
}

.menu-row select {
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid #e5e7eb;
  background: #f9fafb;
}

.menu-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 14px;
}

.primary-btn {
  background: #2563eb;
  color: #fff;
  border: none;
  border-radius: 12px;
  padding: 10px 14px;
  font-weight: 700;
  cursor: pointer;
}

.ghost-btn {
  background: #f1f5f9;
  color: #334155;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  padding: 7px 10px;
  font-weight: 600;
  cursor: pointer;
}

.icon-btn {
  width: 36px;
  height: 36px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
}

.screen-game {
  overflow: hidden;
  padding-top: max(2px, env(safe-area-inset-top));
  padding-bottom: env(safe-area-inset-bottom);
}

.screen-game.active {
  display: flex;
  justify-content: flex-start;
  align-items: stretch;
}

.game-panel {
  display: flex;
  justify-content: center;
  gap: 10px;
  height: 100%;
  align-items: flex-start;
  width: 100%;
  padding: 2px 0 8px;
}

.board-area {
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
  width: 100%;
}

.game-topbar {
  display: flex;
  flex-direction: column;
  gap: 4px;
  width: 100%;
}

.topbar-row {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
}

.topbar-row-icons {
  justify-content: space-between;
}

.topbar-row-center {
  justify-content: center;
}

.topbar-left,
.topbar-right {
  display: flex;
  gap: 6px;
}

#rewardAdBtn {
  flex: 0 0 auto;
  white-space: nowrap;
  font-size: 0.74rem;
  padding: 3px 7px;
}

@media (max-width: 520px) {
  .screen-game.active {
    justify-content: center;
    align-items: center;
  }

  .game-panel {
    align-items: center;
  }

  .icon-btn {
    width: 32px;
    height: 32px;
    font-size: 0.95rem;
  }

  #rewardAdBtn {
    font-size: 0.72rem;
    padding: 3px 6px;
  }
}

.controls-panel {
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: center;
  width: 100%;
  perspective: 1200px;
}

.controls-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: center;
}

.dice-cube {
  --size: clamp(66px, 16vw, 88px);
  --depth: calc(var(--size) / 2);
  width: var(--size);
  height: var(--size);
  position: relative;
  transform-style: preserve-3d;
  transition: transform 0.6s ease-out;
}

.dice-cube.rolling {
  animation: rollSpin3d 1s ease-out;
}

.dice-face {
  position: absolute;
  width: 100%;
  height: 100%;
  background: #ffffff;
  border: 2px solid #111827;
  border-radius: 10px;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.05);
  backface-visibility: hidden;
  background-repeat: no-repeat;
  background-size: 100% 100%;
}

.face-1 { transform: rotateY(0deg) translateZ(var(--depth)); }
.face-2 { transform: rotateY(90deg) translateZ(var(--depth)); }
.face-3 { transform: rotateX(90deg) translateZ(var(--depth)); }
.face-4 { transform: rotateX(-90deg) translateZ(var(--depth)); }
.face-5 { transform: rotateY(-90deg) translateZ(var(--depth)); }
.face-6 { transform: rotateY(180deg) translateZ(var(--depth)); }

.face-1 {
  background-image: radial-gradient(circle at 50% 50%, #111827 7px, transparent 8px);
}

.face-2 {
  background-image:
    radial-gradient(circle at 28% 28%, #111827 7px, transparent 8px),
    radial-gradient(circle at 72% 72%, #111827 7px, transparent 8px);
}

.face-3 {
  background-image:
    radial-gradient(circle at 28% 28%, #111827 7px, transparent 8px),
    radial-gradient(circle at 50% 50%, #111827 7px, transparent 8px),
    radial-gradient(circle at 72% 72%, #111827 7px, transparent 8px);
}

.face-4 {
  background-image:
    radial-gradient(circle at 28% 28%, #111827 7px, transparent 8px),
    radial-gradient(circle at 72% 28%, #111827 7px, transparent 8px),
    radial-gradient(circle at 28% 72%, #111827 7px, transparent 8px),
    radial-gradient(circle at 72% 72%, #111827 7px, transparent 8px);
}

.face-5 {
  background-image:
    radial-gradient(circle at 28% 28%, #111827 7px, transparent 8px),
    radial-gradient(circle at 72% 28%, #111827 7px, transparent 8px),
    radial-gradient(circle at 50% 50%, #111827 7px, transparent 8px),
    radial-gradient(circle at 28% 72%, #111827 7px, transparent 8px),
    radial-gradient(circle at 72% 72%, #111827 7px, transparent 8px);
}

.face-6 {
  background-image:
    radial-gradient(circle at 28% 25%, #111827 7px, transparent 8px),
    radial-gradient(circle at 28% 50%, #111827 7px, transparent 8px),
    radial-gradient(circle at 28% 75%, #111827 7px, transparent 8px),
    radial-gradient(circle at 72% 25%, #111827 7px, transparent 8px),
    radial-gradient(circle at 72% 50%, #111827 7px, transparent 8px),
    radial-gradient(circle at 72% 75%, #111827 7px, transparent 8px);
}

.roll-result {
  font-size: 0.9rem;
  font-weight: 700;
  color: #1f2937;
}

@keyframes rollSpin3d {
  0% { transform: rotateX(0deg) rotateY(0deg) rotateZ(0deg); }
  20% { transform: rotateX(160deg) rotateY(120deg) rotateZ(40deg); }
  40% { transform: rotateX(320deg) rotateY(240deg) rotateZ(80deg); }
  60% { transform: rotateX(480deg) rotateY(360deg) rotateZ(120deg); }
  80% { transform: rotateX(640deg) rotateY(520deg) rotateZ(160deg); }
  100% { transform: rotateX(800deg) rotateY(680deg) rotateZ(200deg); }
}

.dice-result.value-1 {
  background-image: radial-gradient(circle at 50% 50%, #111827 7px, transparent 8px);
}

.dice-result.value-2 {
  background-image:
    radial-gradient(circle at 28% 28%, #111827 7px, transparent 8px),
    radial-gradient(circle at 72% 72%, #111827 7px, transparent 8px);
}

.dice-result.value-3 {
  background-image:
    radial-gradient(circle at 28% 28%, #111827 7px, transparent 8px),
    radial-gradient(circle at 50% 50%, #111827 7px, transparent 8px),
    radial-gradient(circle at 72% 72%, #111827 7px, transparent 8px);
}

.dice-result.value-4 {
  background-image:
    radial-gradient(circle at 28% 28%, #111827 7px, transparent 8px),
    radial-gradient(circle at 72% 28%, #111827 7px, transparent 8px),
    radial-gradient(circle at 28% 72%, #111827 7px, transparent 8px),
    radial-gradient(circle at 72% 72%, #111827 7px, transparent 8px);
}

.dice-result.value-5 {
  background-image:
    radial-gradient(circle at 28% 28%, #111827 7px, transparent 8px),
    radial-gradient(circle at 72% 28%, #111827 7px, transparent 8px),
    radial-gradient(circle at 50% 50%, #111827 7px, transparent 8px),
    radial-gradient(circle at 28% 72%, #111827 7px, transparent 8px),
    radial-gradient(circle at 72% 72%, #111827 7px, transparent 8px);
}

.dice-result.value-6 {
  background-image:
    radial-gradient(circle at 28% 25%, #111827 7px, transparent 8px),
    radial-gradient(circle at 28% 50%, #111827 7px, transparent 8px),
    radial-gradient(circle at 28% 75%, #111827 7px, transparent 8px),
    radial-gradient(circle at 72% 25%, #111827 7px, transparent 8px),
    radial-gradient(circle at 72% 50%, #111827 7px, transparent 8px),
    radial-gradient(circle at 72% 75%, #111827 7px, transparent 8px);
}

.hidden {
  display: none !important;
}

.ghost-btn.disabled,
.ghost-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}


.board-wrap {
  background: #fdf6e3;
  border-radius: 16px;
  border: 3px solid #1f2937;
  padding: clamp(4px, 1.2vw, 8px);
  box-shadow: 0 8px 18px rgba(15, 23, 42, 0.16);
  display: flex;
  align-items: center;
  justify-content: center;
}

.board {
  display: grid;
  --cell-size: clamp(16px, 5vw, 25px);
  grid-template-columns: repeat(15, var(--cell-size));
  grid-template-rows: repeat(15, var(--cell-size));
  gap: clamp(1px, 0.35vw, 2px);
}

@media (max-height: 720px) {
  .game-panel {
    padding: 0 0 6px;
  }

  .board-area {
    gap: 6px;
  }

  .game-topbar {
    gap: 3px;
  }

  #rewardAdBtn {
    font-size: 0.7rem;
    padding: 2px 6px;
  }

  .controls-panel {
    gap: 5px;
  }

  .controls-row {
    gap: 5px;
  }

  .dice-cube {
    --size: clamp(62px, 14.5vw, 86px);
  }

  .roll-result {
    font-size: 0.85rem;
  }

  .board {
    --cell-size: clamp(15px, 4.8vw, 24px);
  }
}

@media (max-height: 660px) {
  .game-panel {
    padding: 0 0 4px;
  }

  .board-area {
    gap: 4px;
  }

  .game-topbar {
    gap: 2px;
  }

  #rewardAdBtn {
    font-size: 0.68rem;
    padding: 2px 5px;
  }

  .controls-panel {
    gap: 4px;
  }

  .controls-row {
    gap: 4px;
  }

  .dice-cube {
    --size: clamp(58px, 13.5vw, 82px);
  }

  .roll-result {
    font-size: 0.8rem;
  }

  .board {
    --cell-size: clamp(14px, 4.6vw, 23px);
  }
}

@media (max-height: 600px) {
  .app {
    gap: 8px;
    padding: 8px;
  }

  .game-panel {
    padding: 0 0 2px;
  }

  .board-area {
    gap: 3px;
  }

  .game-topbar {
    gap: 2px;
  }

  .topbar-row {
    gap: 6px;
  }

  #rewardAdBtn {
    font-size: 0.66rem;
    padding: 2px 5px;
  }

  .controls-panel {
    gap: 4px;
  }

  .controls-row {
    gap: 4px;
  }

  .dice-cube {
    --size: clamp(56px, 13vw, 80px);
  }

  .roll-result {
    font-size: 0.78rem;
  }

  .board {
    --cell-size: clamp(13px, 4.4vw, 22px);
  }
}

.cell {
  width: var(--cell-size);
  height: var(--cell-size);
  border-radius: 5px;
  background: #ffffff;
  border: 1px solid #d4d9e2;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

.cell.track {
  background: #f1f5f9;
}

.cell.arrow {
  position: relative;
}

.cell.arrow::after {
  content: "";
  width: 14px;
  height: 14px;
  border-right: 3px solid #3b82f6;
  border-bottom: 3px solid #3b82f6;
  position: absolute;
  top: 50%;
  left: 50%;
  transform-origin: center;
  pointer-events: none;
}

.cell.arrow-down::after {
  transform: translate(-50%, -50%) rotate(45deg);
}

.cell.arrow-right::after {
  transform: translate(-50%, -50%) rotate(-45deg);
}

.cell.arrow-up::after {
  transform: translate(-50%, -50%) rotate(-135deg);
}

.cell.arrow-left::after {
  transform: translate(-50%, -50%) rotate(135deg);
}

.cell.home-yellow {
  background: #fbbf24;
}

.cell.home-blue {
  background: #38bdf8;
}

.cell.home-red {
  background: #f87171;
}

.cell.home-green {
  background: #84cc16;
}

.cell.center {
  background: conic-gradient(#f87171 0deg 90deg, #84cc16 90deg 180deg, #38bdf8 180deg 270deg, #fbbf24 270deg 360deg);
}

.cell.center-fill {
  background: conic-gradient(#f87171 0deg 90deg, #84cc16 90deg 180deg, #38bdf8 180deg 270deg, #fbbf24 270deg 360deg);
}

.token {
  width: clamp(12px, 3.5vw, 16px);
  height: clamp(12px, 3.5vw, 16px);
  border-radius: 50%;
  border: 2px solid #fff;
  box-shadow: 0 4px 10px rgba(0,0,0,0.2);
  cursor: pointer;
}

.token.selectable {
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.7), 0 6px 12px rgba(0,0,0,0.2);
}

.token.red { background: #ef4444; }
.token.green { background: #22c55e; }
.token.blue { background: #3b82f6; }
.token.yellow { background: #f59e0b; }

.turn-toast {
  position: fixed;
  top: 12px;
  left: 50%;
  transform: translateX(-50%) translateY(-8px);
  background: rgba(15, 23, 42, 0.92);
  color: #fff;
  padding: 10px 16px;
  border-radius: 999px;
  font-weight: 600;
  font-size: 0.95rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 20;
}

.turn-toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.65);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 30;
}

.modal-card {
  background: #ffffff;
  border-radius: 16px;
  padding: 20px;
  min-width: 240px;
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.25);
  display: flex;
  flex-direction: column;
  gap: 16px;
  align-items: center;
}

.modal-card.modal-wide {
  width: min(560px, 92vw);
  align-items: stretch;
  overflow: hidden;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.modal-close {
  border: none;
  background: rgba(148, 163, 184, 0.2);
  color: #111827;
  width: 32px;
  height: 32px;
  border-radius: 10px;
  cursor: pointer;
  font-size: 1rem;
  font-weight: 700;
  line-height: 1;
}

.modal-text {
  display: flex;
  flex-direction: column;
  gap: 14px;
  color: #1f2937;
  font-size: 0.95rem;
  line-height: 1.35;
  min-height: 0;
}

#helpModal .modal-card {
  max-height: min(78vh, 620px);
}

#helpModal .modal-text {
  overflow-y: auto;
  padding-right: 4px;
  flex: 1 1 auto;
  -webkit-overflow-scrolling: touch;
}

#helpModal .modal-text {
  scrollbar-width: thin;
  scrollbar-color: #94a3b8 transparent;
}

#helpModal .modal-text::-webkit-scrollbar {
  width: 8px;
}

#helpModal .modal-text::-webkit-scrollbar-track {
  background: transparent;
}

#helpModal .modal-text::-webkit-scrollbar-thumb {
  background: #94a3b8;
  border-radius: 999px;
  border: 2px solid transparent;
  background-clip: padding-box;
}

.modal-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.modal-heading {
  font-weight: 800;
}

.modal-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.modal-title {
  font-size: 1.2rem;
  font-weight: 800;
  color: #111827;
  text-align: center;
}

.modal-actions {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: center;
}


@media (max-width: 900px) {
  .game-panel {
    justify-content: center;
  }
}
