:root {
  --bg: #112233;
  --panel: #18314f;
  --board-bg: #1d4e89;
  --board-shadow: #0b1d2f;
  --cell-empty: #dfe8f5;
  --player-red: #e53935;
  --player-yellow: #fdd835;
  --text: #eef6ff;
  --button: #4caf50;
  --button-hover: #3d8b40;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, var(--bg), #1f3a5f);
  color: var(--text);
  font-family: Arial, sans-serif;
}

.game-shell {
  width: min(92vw, 560px);
  background: rgba(24, 49, 79, 0.94);
  border-radius: 18px;
  padding: 24px 20px 18px;
  box-shadow: 0 18px 32px rgba(0, 0, 0, 0.28);
}

h1 {
  margin: 0 0 18px;
  text-align: center;
  font-size: clamp(2rem, 3vw, 2.6rem);
}

.status-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}

#status {
  font-size: 1.1rem;
  font-weight: bold;
}

#restart-btn {
  border: none;
  background: var(--button);
  color: white;
  padding: 10px 16px;
  border-radius: 10px;
  font-size: 0.95rem;
  font-weight: bold;
  cursor: pointer;
  transition: background 0.2s ease;
}

#restart-btn:hover {
  background: var(--button-hover);
}

.board-wrapper {
  display: flex;
  justify-content: center;
}

.board {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 10px;
  background: var(--board-bg);
  padding: 16px;
  border-radius: 18px;
  box-shadow: inset 0 0 16px rgba(11, 29, 47, 0.7);
  max-width: 520px;
  width: 100%;
}

.cell {
  width: 100%;
  min-width: 0;
  aspect-ratio: 1;
  border: none;
  border-radius: 50%;
  background: var(--cell-empty);
  box-shadow: inset 0 0 8px rgba(0, 0, 0, 0.14);
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}

.cell:hover:not(:disabled) {
  transform: scale(1.04);
  box-shadow: inset 0 0 8px rgba(0, 0, 0, 0.2), 0 0 10px rgba(255, 255, 255, 0.22);
}

.cell:disabled {
  cursor: default;
}

.cell.red {
  background: var(--player-red);
}

.cell.yellow {
  background: var(--player-yellow);
}

.cell.win {
  box-shadow: 0 0 0 4px rgba(255, 255, 255, 0.9), 0 0 18px rgba(255, 255, 255, 0.7);
}

.chip-layer {
  position: absolute;
  grid-column: 1 / -1;
  grid-row: 1 / -1;
  inset: 0;
  pointer-events: none;
  z-index: 5;
  mask-repeat: no-repeat;
  -webkit-mask-repeat: no-repeat;
}

.falling-chip {
  position: absolute;
  border-radius: 50%;
  animation: fall-through var(--fall-duration, 1s) cubic-bezier(0.5, 0, 0.4, 1.3) forwards;
}

.falling-chip.red {
  background: var(--player-red);
}

.falling-chip.yellow {
  background: var(--player-yellow);
}

@keyframes fall-through {
  0% {
    top: var(--start-top);
  }
  70% {
    top: calc(var(--end-top) + 10px);
  }
  85% {
    top: calc(var(--end-top) - 5px);
  }
  100% {
    top: var(--end-top);
  }
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(8, 16, 28, 0.72);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
}

.modal-overlay.hidden {
  display: none;
}

.modal {
  background: var(--panel);
  border-radius: 16px;
  padding: 26px 28px;
  width: min(88vw, 340px);
  text-align: center;
  box-shadow: 0 18px 32px rgba(0, 0, 0, 0.4);
}

.modal h2 {
  margin: 0 0 10px;
}

.modal p {
  margin: 0 0 18px;
  opacity: 0.85;
}

.modal-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.modal-actions button {
  border: none;
  background: var(--button);
  color: white;
  padding: 12px 16px;
  border-radius: 10px;
  font-size: 1rem;
  font-weight: bold;
  cursor: pointer;
  transition: background 0.2s ease;
}

.modal-actions button:hover {
  background: var(--button-hover);
}

@media (max-width: 480px) {
  .game-shell {
    padding: 18px 12px 14px;
  }

  .board {
    gap: 8px;
    padding: 12px;
  }

  .status-bar {
    flex-direction: column;
    align-items: flex-start;
  }
}

@media (max-width: 380px) {
  .game-shell {
    padding: 14px 8px 10px;
  }

  .board {
    gap: 6px;
    padding: 8px;
  }

  h1 {
    margin-bottom: 12px;
  }
}
