* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

:root {
  --bg: #1b1b2f;
  --bg-light: #222244;
  --p1-color: #ff6b8a;
  --p2-color: #5bc0eb;
  --p1-light: #ff8fa3;
  --p2-light: #7dd3f0;
  --text: #eaeaff;
  --text-dim: #9999bb;
  --dot: #ffffff;
  --line-idle: #3a3a5c;
  --accent: #ff6b8a;
}

html, body {
  height: 100%;
  overflow: hidden;
  font-family: 'Nunito', 'Baloo 2', 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

#app {
  height: 100%;
  width: 100%;
  position: relative;
}


.screen {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2rem;
  padding: 1.5rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

.screen.active {
  opacity: 1;
  pointer-events: all;
}

/* Animated background — shared across menu screens */
#menu-bg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
  pointer-events: none;
  transition: opacity 0.4s;
}

#menu-bg.hidden {
  opacity: 0;
}

/* Menu screen */
#menu-screen {
  padding: 0;
  gap: 0;
}

#menu-content {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1.5rem;
  padding: 2rem;
  flex: 1;
}


/* Title */
.title {
  font-size: 3.5rem;
  text-align: center;
  line-height: 1.05;
  font-weight: 900;
  background: linear-gradient(135deg, #ff6b8a, #ffb347, #5bc0eb, #9b59b6);
  background-size: 300% 300%;
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  animation: title-gradient 5s ease infinite;
  filter: drop-shadow(0 3px 12px rgba(255, 107, 138, 0.25));
}

@keyframes title-gradient {
  0%, 100% { background-position: 0% 50%; }
  50% { background-position: 100% 50%; }
}

.subtitle {
  font-size: 1.05rem;
  color: var(--text-dim);
  text-align: center;
  letter-spacing: 0.5px;
  font-weight: 600;
}

.credits {
  position: absolute;
  bottom: 0.8rem;
  font-size: 0.65rem;
  color: rgba(255,255,255,0.35);
  letter-spacing: 0.5px;
  text-transform: uppercase;
  transition: color 0.3s;
  z-index: 2;
}

.credits:hover, .credits:active {
  color: rgba(255,255,255,0.6);
}

.credits a {
  color: inherit;
  text-decoration: none;
}

h2 {
  font-size: 1.8rem;
  color: var(--text);
}

/* Buttons */
.btn {
  border: none;
  border-radius: 1.2rem;
  padding: 1rem 2rem;
  font-size: 1.2rem;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  transition: transform 0.15s, box-shadow 0.15s;
  color: white;
  min-width: 220px;
  justify-content: center;
  letter-spacing: 0.3px;
}

.btn:active {
  transform: scale(0.93);
}

.btn-icon {
  font-size: 1.5rem;
}

.btn-primary {
  background: linear-gradient(135deg, #ff6b8a, #ff8fa3);
  box-shadow: 0 4px 18px rgba(255, 107, 138, 0.35);
}

.btn-secondary {
  background: linear-gradient(135deg, #5b9bff, #80b4ff);
  box-shadow: 0 4px 18px rgba(91, 155, 255, 0.35);
}

.btn-easy {
  background: linear-gradient(135deg, #56d98a, #7be8a4);
  box-shadow: 0 4px 15px rgba(86, 217, 138, 0.35);
}

.btn-medium {
  background: linear-gradient(135deg, #ffb347, #ffc96b);
  box-shadow: 0 4px 15px rgba(255, 179, 71, 0.35);
}

.btn-hard {
  background: linear-gradient(135deg, #ff6b6b, #ff8787);
  box-shadow: 0 4px 15px rgba(255, 107, 107, 0.35);
}

.btn-size {
  background: linear-gradient(135deg, #b388ff, #ce9ffc);
  box-shadow: 0 4px 15px rgba(179, 136, 255, 0.35);
  flex-direction: column;
  min-width: 0;
  padding: 0.7rem 0.5rem;
  font-size: 0.85rem;
  flex: 1;
}

.size-preview {
  font-size: 1.1rem;
  letter-spacing: 1px;
  font-weight: 900;
}

.btn-back {
  background: transparent;
  border: 2px solid var(--text-dim);
  color: var(--text-dim);
  min-width: auto;
  padding: 0.6rem 1.5rem;
  font-size: 1rem;
}

.btn-small {
  font-size: 1rem;
  padding: 0.6rem 1.2rem;
  min-width: auto;
}

.btn-undo {
  background: linear-gradient(135deg, #666, #888);
  box-shadow: 0 2px 8px rgba(0,0,0,0.2);
  color: white;
  border: none;
}

.btn-undo:disabled {
  opacity: 0.3;
  pointer-events: none;
}

.btn-tutorial {
  background: transparent;
  border: 2px solid var(--text-dim);
  color: var(--text-dim);
  min-width: 220px;
  font-size: 1rem;
  padding: 0.7rem 2rem;
}

.btn-rounds {
  background: linear-gradient(135deg, #ffb347, #ffc96b);
  box-shadow: 0 4px 15px rgba(255, 179, 71, 0.35);
  font-size: 1.5rem;
  font-weight: 900;
  min-width: 70px;
  padding: 1rem;
}

.rounds-options {
  display: flex;
  gap: 1rem;
  justify-content: center;
}

/* Tutorial */
#tutorial-screen {
  gap: 1rem;
}

#tutorial-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  width: 100%;
  max-width: 400px;
}

#tutorial-canvas {
  width: 100%;
  max-width: 300px;
  height: 250px;
  border-radius: 1rem;
  background: var(--bg-light);
}

#tutorial-step-text {
  text-align: center;
  color: var(--text);
  font-size: 1.05rem;
  line-height: 1.5;
  padding: 0 1rem;
}

.tutorial-actions {
  display: flex;
  gap: 1rem;
  align-items: center;
}

/* Round info */
.round-info {
  font-size: 1.1rem;
  color: var(--text-dim);
  margin-top: 0.5rem;
}

.round-info.hidden, .hidden {
  display: none;
}

#game-actions {
  display: flex;
  gap: 0.8rem;
  align-items: center;
  justify-content: center;
  padding: 0.5rem;
  flex-shrink: 0;
}

.menu-options, .difficulty-options, .size-options {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  align-items: center;
}

.size-options {
  flex-direction: row;
  flex-wrap: nowrap;
  gap: 0.5rem;
  justify-content: center;
  width: 100%;
  max-width: 400px;
}

/* ============ NAMES SCREEN ============ */
.names-form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  width: 100%;
  max-width: 300px;
}

.name-input-group {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.name-input-group label {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  font-weight: 700;
}

.name-input-group.p1 label { color: var(--p1-color); }
.name-input-group.p2 label { color: var(--p2-color); }

.name-input-group input {
  background: var(--bg-light);
  border: 2px solid #444466;
  border-radius: 0.8rem;
  padding: 0.8rem 1rem;
  font-size: 1.1rem;
  color: var(--text);
  font-family: inherit;
  outline: none;
  transition: border-color 0.2s;
}

.name-input-group input:focus {
  border-color: var(--accent);
}

.name-input-group.p1 input:focus { border-color: var(--p1-light); }
.name-input-group.p2 input:focus { border-color: var(--p2-light); }

/* ============ GAME SCREEN ============ */
#game-screen {
  gap: 0;
  padding: 0;
  align-items: stretch;
  justify-content: flex-start;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

/* Scoreboard */
#scoreboard {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 0.2rem 0.5rem;
  gap: 0.3rem;
  flex-shrink: 0;
}

.score-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 0.2rem 0.6rem;
  border-radius: 0.6rem;
  background: var(--bg-light);
  min-width: 60px;
  transition: all 0.3s;
  border: 2px solid transparent;
}

.score-box.active {
  border-color: currentColor;
  transform: scale(1.05);
}

#player1-score { color: var(--p1-light); }
#player2-score { color: var(--p2-light); }

.player-name {
  font-size: 0.6rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  opacity: 0.8;
}

.player-points {
  font-size: 1.4rem;
  font-weight: 800;
}

#turn-indicator {
  font-size: 0.65rem;
  color: var(--text-dim);
  text-align: center;
}

/* Dice info bar — fixed height to prevent layout shift */
#dice-info-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 32px;
  flex-shrink: 0;
}

/* Board wrapper — fills ALL remaining space */
#board-wrapper {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow: hidden;
  width: 100%;
}

/* Canvas — sized by JS */
#game-canvas {
  display: block;
  touch-action: none;
}

/* Game actions */
#game-actions {
  display: flex;
  gap: 0.8rem;
  align-items: center;
  justify-content: center;
  padding: 0.3rem;
  flex-shrink: 0;
}

/* ---- Landscape: just make UI more compact ---- */
@media (orientation: landscape) {
  #scoreboard { padding: 0.1rem 0.5rem; }
  .score-box { padding: 0.1rem 0.5rem; }
  .player-points { font-size: 1.1rem; }
  .player-name { font-size: 0.5rem; }
  #turn-indicator { font-size: 0.5rem; }
  #dice-info-bar { min-height: 20px; }
  #game-actions { padding: 0.1rem; }
  .btn-small { font-size: 0.8rem; padding: 0.3rem 0.8rem; }
}

/* ============ DICE OVERLAY ============ */
#dice-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1.2rem;
  z-index: 10;
  cursor: pointer;
  background: radial-gradient(circle, rgba(26,26,46,0.85) 0%, rgba(26,26,46,0.6) 60%, transparent 100%);
  transition: opacity 0.35s ease, visibility 0.35s;
}

#dice-overlay.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

#dice-overlay.waiting {
  animation: overlay-breathe 2s ease-in-out infinite;
}

@keyframes overlay-breathe {
  0%, 100% { background: radial-gradient(circle, rgba(26,26,46,0.85) 0%, rgba(26,26,46,0.6) 60%, transparent 100%); }
  50% { background: radial-gradient(circle, rgba(40,35,60,0.9) 0%, rgba(26,26,46,0.65) 60%, transparent 100%); }
}

#dice-label {
  font-size: 1.3rem;
  font-weight: 800;
  color: #f39c12;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  text-shadow: 0 2px 10px rgba(243, 156, 18, 0.4);
  animation: label-bounce 1.5s ease-in-out infinite;
}

#dice-overlay.hidden #dice-label,
#dice-overlay.rolling-state #dice-label {
  animation: none;
}

@keyframes label-bounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-4px); }
}

/* 3D Dice */
#dice-scene {
  width: 100px;
  height: 100px;
  perspective: 500px;
}

#dice-cube {
  width: 100%;
  height: 100%;
  position: relative;
  transform-style: preserve-3d;
  transition: transform 0.15s ease-out;
  transform: rotateX(-20deg) rotateY(20deg);
}

.dice-face {
  position: absolute;
  width: 100px;
  height: 100px;
  border-radius: 16px;
  background: linear-gradient(145deg, #ffffff, #e8e0d4);
  border: 2px solid #ccc4b8;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: inset 0 0 10px rgba(0,0,0,0.06);
}

.dice-face svg {
  width: 80px;
  height: 80px;
}

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

#dice-cube.rolling {
  transition: none;
  animation: dice-tumble 1s cubic-bezier(0.25, 0.8, 0.25, 1);
}

@keyframes dice-tumble {
  0%   { transform: rotateX(0)      rotateY(0)      rotateZ(0)      translateY(0)    scale(0.8); }
  10%  { transform: rotateX(-120deg) rotateY(60deg)  rotateZ(30deg)  translateY(-60px) scale(1.1); }
  25%  { transform: rotateX(-270deg) rotateY(150deg) rotateZ(70deg)  translateY(-20px) scale(1); }
  40%  { transform: rotateX(-400deg) rotateY(250deg) rotateZ(120deg) translateY(-40px) scale(1.05); }
  55%  { transform: rotateX(-520deg) rotateY(340deg) rotateZ(170deg) translateY(-10px) scale(1); }
  70%  { transform: rotateX(-620deg) rotateY(400deg) rotateZ(200deg) translateY(-18px) scale(1.02); }
  85%  { transform: rotateX(-700deg) rotateY(440deg) rotateZ(220deg) translateY(-3px)  scale(1); }
  100% { transform: var(--dice-final); }
}

#dice-cube.landed {
  transition: transform 0.1s ease-out;
}

#dice-scene.rolling-shadow::after {
  content: '';
  position: absolute;
  bottom: -8px;
  left: 50%;
  transform: translateX(-50%);
  width: 70px;
  height: 14px;
  background: rgba(0,0,0,0.3);
  border-radius: 50%;
  animation: dice-shadow 1s cubic-bezier(0.25, 0.8, 0.25, 1);
}

@keyframes dice-shadow {
  0%   { opacity: 0.5; width: 70px; }
  10%  { opacity: 0.15; width: 30px; }
  25%  { opacity: 0.4; width: 60px; }
  40%  { opacity: 0.2; width: 40px; }
  55%  { opacity: 0.45; width: 65px; }
  70%  { opacity: 0.2; width: 45px; }
  100% { opacity: 0.5; width: 70px; }
}

#dice-overlay.show-result #dice-scene {
  animation: dice-result-pop 0.4s ease;
}

@keyframes dice-result-pop {
  0% { transform: scale(1); }
  40% { transform: scale(1.25); }
  100% { transform: scale(1); }
}

/* Moves left pill */
.moves-left {
  background: var(--bg-light);
  border-radius: 2rem;
  padding: 0.4rem 1.2rem;
  font-size: 1rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  border: 2px solid #444466;
  transition: opacity 0.3s, transform 0.3s;
}

.moves-left.hidden {
  visibility: hidden;
}

#moves-count {
  font-size: 1.6rem;
  color: #f39c12;
  min-width: 1.2rem;
  text-align: center;
}

#moves-word {
  color: var(--text-dim);
  font-size: 0.85rem;
}

.moves-left.pop-in {
  animation: pop-in 0.3s ease;
}

@keyframes pop-in {
  0% { transform: scale(0.5); opacity: 0; }
  70% { transform: scale(1.1); }
  100% { transform: scale(1); opacity: 1; }
}

/* ============ RESULT ============ */
#result-content {
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

#result-title { font-size: 2.5rem; }
#result-detail { font-size: 1.2rem; color: var(--text-dim); }

#result-scores {
  display: flex;
  justify-content: center;
  gap: 2rem;
  font-size: 1.5rem;
  font-weight: 700;
}

.result-p1 { color: var(--p1-light); }
.result-p2 { color: var(--p2-light); }

/* ============ ANIMATIONS ============ */
@keyframes pop {
  0% { transform: scale(1); }
  50% { transform: scale(1.3); }
  100% { transform: scale(1); }
}

.score-box.pop {
  animation: pop 0.3s ease;
}

/* ============ RESPONSIVE ============ */

/* Mobile small screens */
@media (max-height: 600px) {
  .title { font-size: 2rem; }
  .btn { padding: 0.7rem 1.5rem; font-size: 1rem; min-width: 160px; }
  h2 { font-size: 1.3rem; }
  .player-points { font-size: 1.5rem; }
  #dice-scene { width: 80px; height: 80px; }
  .dice-face { width: 80px; height: 80px; }
  .dice-face svg { width: 64px; height: 64px; }
  .face-1 { transform: rotateY(  0deg) translateZ(40px); }
  .face-2 { transform: rotateY(180deg) translateZ(40px); }
  .face-3 { transform: rotateY( 90deg) translateZ(40px); }
  .face-4 { transform: rotateY(-90deg) translateZ(40px); }
  .face-5 { transform: rotateX( 90deg) translateZ(40px); }
  .face-6 { transform: rotateX(-90deg) translateZ(40px); }
}

/* Desktop / tablet: wider layout */
@media (min-width: 768px) {
  .title { font-size: 5rem; }
  .subtitle { font-size: 1.2rem; }

  #game-screen {
    flex-direction: column;
  }

  #scoreboard {
    padding: 0.6rem 2rem;
  }

  .score-box {
    min-width: 120px;
    padding: 0.6rem 1.5rem;
  }

  .player-name { font-size: 0.85rem; }
  .player-points { font-size: 2.2rem; }
  #turn-indicator { font-size: 0.9rem; }

  #dice-label { font-size: 1.5rem; }

  #dice-scene { width: 120px; height: 120px; }
  .dice-face { width: 120px; height: 120px; border-radius: 20px; }
  .dice-face svg { width: 96px; height: 96px; }
  .face-1 { transform: rotateY(  0deg) translateZ(60px); }
  .face-2 { transform: rotateY(180deg) translateZ(60px); }
  .face-3 { transform: rotateY( 90deg) translateZ(60px); }
  .face-4 { transform: rotateY(-90deg) translateZ(60px); }
  .face-5 { transform: rotateX( 90deg) translateZ(60px); }
  .face-6 { transform: rotateX(-90deg) translateZ(60px); }
}

/* Very wide screens: cap game board so it's not absurdly wide */
@media (min-width: 1200px) {
  #game-screen {
    padding: 0 10vw;
  }
}
