/* ============================================================
   Connect Four - Complete Stylesheet
   Uses CSS custom properties for consistent theming
   ============================================================ */

/* ----- Custom Properties (Theme) ----- */
:root {
  --color-board-bg: #2a5c8a;
  --color-board-border: #1a3a5a;
  --color-board-shadow: rgba(0, 0, 0, 0.3);
  --color-cell-empty: #ffffff;
  --color-cell-empty-border: #cccccc;
  --color-red: #e63946;
  --color-red-dark: #b71c1c;
  --color-red-highlight: #ff8a80;
  --color-yellow: #f4d03f;
  --color-yellow-dark: #f9a825;
  --color-yellow-highlight: #fff59d;
  --color-win-glow: #ffd700;
  --color-win-border: #b8860b;
  --color-bg: #1a1a2e;
  --color-text: #f0f0f0;
  --color-text-muted: #bbbbbb;
  --color-status: #ffffff;
  --color-btn-bg: #e63946;
  --color-btn-bg-hover: #c62828;
  --color-btn-text: #ffffff;
  --color-btn-shadow: rgba(0, 0, 0, 0.3);
  --color-header: #f4d03f;

  --cell-size: 60px;
  --board-gap: 4px;
  --board-padding: 10px;
  --border-radius-board: 16px;
  --border-radius-cell: 50%;
  --border-radius-btn: 8px;

  --font-family: 'Segoe UI', Roboto, -apple-system, BlinkMacSystemFont, sans-serif;
  --transition-speed: 0.2s;
}

/* ----- Reset & Base ----- */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-family);
  background: var(--color-bg);
  color: var(--color-text);
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 16px;
  margin: 0;
}

/* ----- Game Container ----- */
#app {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  width: 100%;
  max-width: 520px;
  padding: 20px 16px 24px;
  background: linear-gradient(145deg, #16213e, #0f3460);
  border-radius: 20px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
}

/* ----- Title ----- */
h1 {
  font-size: 1.8rem;
  font-weight: 800;
  letter-spacing: 1px;
  color: var(--color-header);
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
  text-align: center;
}

/* ----- Status Line ----- */
#status {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--color-status);
  text-align: center;
  padding: 8px 16px;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.25);
  border-radius: 8px;
  width: 100%;
  letter-spacing: 0.5px;
  transition: background var(--transition-speed);
}

#status.win-status {
  background: rgba(255, 215, 0, 0.15);
  border: 1px solid var(--color-win-glow);
}

#status.draw-status {
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid var(--color-text-muted);
}

/* ----- Board ----- */
#board {
  display: grid;
  grid-template-columns: repeat(7, var(--cell-size));
  grid-template-rows: repeat(6, var(--cell-size));
  gap: var(--board-gap);
  padding: var(--board-padding);
  background: var(--color-board-bg);
  border: 4px solid var(--color-board-border);
  border-radius: var(--border-radius-board);
  box-shadow:
    inset 0 0 0 2px rgba(0, 0, 0, 0.2),
    0 6px 20px var(--color-board-shadow);
  position: relative;
}

/* ----- Individual Cells ----- */
.cell {
  width: var(--cell-size);
  height: var(--cell-size);
  border-radius: var(--border-radius-cell);
  background: var(--color-cell-empty);
  border: 2px solid var(--color-cell-empty-border);
  cursor: pointer;
  transition: transform var(--transition-speed), box-shadow var(--transition-speed), background var(--transition-speed);
  position: relative;
}

/* Empty cell subtle hover */
.cell:hover:not(.red):not(.yellow) {
  transform: scale(1.05);
  box-shadow: 0 0 8px rgba(255, 255, 255, 0.3);
}

/* ----- Red Disc ----- */
.cell.red {
  background: radial-gradient(circle at 35% 35%, var(--color-red-highlight), var(--color-red) 40%, var(--color-red-dark) 100%);
  border-color: var(--color-red-dark);
  box-shadow: inset 0 -3px 6px rgba(0, 0, 0, 0.3), 0 2px 4px rgba(0, 0, 0, 0.2);
  cursor: default;
}

/* ----- Yellow Disc ----- */
.cell.yellow {
  background: radial-gradient(circle at 35% 35%, var(--color-yellow-highlight), var(--color-yellow) 40%, var(--color-yellow-dark) 100%);
  border-color: var(--color-yellow-dark);
  box-shadow: inset 0 -3px 6px rgba(0, 0, 0, 0.25), 0 2px 4px rgba(0, 0, 0, 0.2);
  cursor: default;
}

/* Add a subtle inner highlight for 3D effect on all discs */
.cell.red::after,
.cell.yellow::after {
  content: '';
  position: absolute;
  top: 8%;
  left: 18%;
  width: 30%;
  height: 25%;
  background: radial-gradient(circle, rgba(255, 255, 255, 0.5) 0%, transparent 70%);
  border-radius: 50%;
  pointer-events: none;
}

/* ----- Win Highlight ----- */
.cell.win {
  animation: winPulse 0.8s ease-in-out infinite alternate;
  border-color: var(--color-win-border);
  box-shadow:
    0 0 12px 4px var(--color-win-glow),
    0 0 24px 8px rgba(255, 215, 0, 0.4),
    inset 0 -3px 6px rgba(0, 0, 0, 0.3);
  transform: scale(1.08);
  z-index: 2;
}

/* Win highlight for red discs */
.cell.red.win {
  border-color: var(--color-win-border);
  box-shadow:
    0 0 12px 4px var(--color-win-glow),
    0 0 24px 8px rgba(255, 215, 0, 0.4),
    inset 0 -3px 6px rgba(0, 0, 0, 0.3);
}

/* Win highlight for yellow discs */
.cell.yellow.win {
  border-color: var(--color-win-border);
  box-shadow:
    0 0 12px 4px var(--color-win-glow),
    0 0 24px 8px rgba(255, 215, 0, 0.4),
    inset 0 -3px 6px rgba(0, 0, 0, 0.3);
}

@keyframes winPulse {
  0% {
    box-shadow:
      0 0 8px 2px var(--color-win-glow),
      0 0 16px 4px rgba(255, 215, 0, 0.3);
    transform: scale(1.05);
  }
  100% {
    box-shadow:
      0 0 16px 6px var(--color-win-glow),
      0 0 32px 12px rgba(255, 215, 0, 0.5);
    transform: scale(1.1);
  }
}

/* ----- New Game Button ----- */
#newGameBtn {
  font-family: var(--font-family);
  font-size: 1.1rem;
  font-weight: 700;
  padding: 12px 32px;
  background: var(--color-btn-bg);
  color: var(--color-btn-text);
  border: none;
  border-radius: var(--border-radius-btn);
  cursor: pointer;
  transition: background var(--transition-speed), transform var(--transition-speed), box-shadow var(--transition-speed);
  box-shadow: 0 4px 8px var(--color-btn-shadow);
  letter-spacing: 0.5px;
  text-transform: uppercase;
  width: 100%;
  max-width: 260px;
}

#newGameBtn:hover {
  background: var(--color-btn-bg-hover);
  transform: translateY(-2px);
  box-shadow: 0 6px 14px var(--color-btn-shadow);
}

#newGameBtn:active {
  transform: translateY(0);
  box-shadow: 0 2px 4px var(--color-btn-shadow);
}

#newGameBtn:focus-visible {
  outline: 3px solid var(--color-win-glow);
  outline-offset: 3px;
}

/* ----- Responsive Adjustments ----- */

/* Larger screens / tablets */
@media (min-width: 600px) {
  :root {
    --cell-size: 64px;
    --board-gap: 5px;
    --board-padding: 12px;
  }

  #app {
    max-width: 560px;
    padding: 28px 24px 32px;
  }

  h1 {
    font-size: 2rem;
  }

  #status {
    font-size: 1.3rem;
    padding: 10px 20px;
  }

  #newGameBtn {
    font-size: 1.15rem;
    padding: 14px 36px;
  }
}

/* Phones / small screens */
@media (max-width: 480px) {
  :root {
    --cell-size: 44px;
    --board-gap: 3px;
    --board-padding: 8px;
    --border-radius-board: 12px;
  }

  #app {
    max-width: 400px;
    padding: 16px 12px 20px;
    gap: 12px;
  }

  h1 {
    font-size: 1.4rem;
  }

  #status {
    font-size: 1rem;
    min-height: 36px;
    padding: 6px 12px;
  }

  #newGameBtn {
    font-size: 1rem;
    padding: 10px 24px;
    max-width: 220px;
  }
}

/* Very small screens */
@media (max-width: 380px) {
  :root {
    --cell-size: 36px;
    --board-gap: 2px;
    --board-padding: 6px;
  }

  h1 {
    font-size: 1.2rem;
  }

  #status {
    font-size: 0.9rem;
  }

  #newGameBtn {
    font-size: 0.9rem;
    padding: 8px 18px;
  }
}

/* ----- Board column hover visual aid ----- */
#board.col-hover .cell.highlight-col {
  background: rgba(255, 255, 255, 0.15);
  border-color: rgba(255, 255, 255, 0.4);
}

/* ----- Utility: board frozen state ----- */
#board.frozen .cell {
  cursor: default;
}

#board.frozen .cell:hover {
  transform: none;
  box-shadow: none;
}

/* ----- Disc drop animation ----- */
@keyframes dropDisc {
  0% {
    transform: translateY(-200%);
    opacity: 0.5;
  }
  60% {
    transform: translateY(5%);
  }
  80% {
    transform: translateY(-2%);
  }
  100% {
    transform: translateY(0);
    opacity: 1;
  }
}

.cell.dropping {
  animation: dropDisc 0.35s ease-out forwards;
}

/* ----- Accessibility: reduced motion ----- */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }

  .cell.win {
    animation: none;
    transform: scale(1.05);
    border-color: var(--color-win-border);
    box-shadow:
      0 0 12px 4px var(--color-win-glow),
      0 0 24px 8px rgba(255, 215, 0, 0.4);
  }

  .cell.dropping {
    animation: none;
  }
}

/* ----- Print styles ----- */
@media print {
  body {
    background: white;
    color: black;
  }

  #app {
    background: white;
    box-shadow: none;
    border: 2px solid #ccc;
  }

  #newGameBtn {
    display: none;
  }
}
