/* ========================================
   MARLIN — Connect 4 AI
   Premium Dark Theme Stylesheet
   ======================================== */

/* ---- Design Tokens ---- */
:root {
  --bg-primary: #060918;
  --bg-secondary: #0f1333;
  --bg-tertiary: #161b4a;
  --board-color: #1a237e;
  --board-gradient: linear-gradient(145deg, #1a237e, #0d1452);
  --board-border: #2835a8;
  --cell-shadow: inset 0 4px 8px rgba(0, 0, 0, 0.6);
  --cell-bg: #060918;

  --red: #ef4444;
  --red-light: #f87171;
  --red-dark: #b91c1c;
  --red-glow: 0 0 20px rgba(239, 68, 68, 0.5);
  --red-glow-intense: 0 0 30px rgba(239, 68, 68, 0.7), 0 0 60px rgba(239, 68, 68, 0.3);

  --yellow: #facc15;
  --yellow-light: #fde047;
  --yellow-dark: #ca8a04;
  --yellow-glow: 0 0 20px rgba(250, 204, 21, 0.5);
  --yellow-glow-intense: 0 0 30px rgba(250, 204, 21, 0.7), 0 0 60px rgba(250, 204, 21, 0.3);

  --text-primary: #e2e8f0;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;

  --accent: #6366f1;
  --accent-light: #818cf8;
  --accent-dark: #4f46e5;
  --accent-glow: 0 0 20px rgba(99, 102, 241, 0.4);

  --glass-bg: rgba(15, 19, 51, 0.7);
  --glass-border: rgba(99, 102, 241, 0.15);
  --glass-blur: 16px;

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 24px;

  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.5);
  --shadow-xl: 0 16px 48px rgba(0, 0, 0, 0.6);

  --transition-fast: all 0.15s ease;
  --transition-base: all 0.2s ease;
  --transition-slow: all 0.3s ease;

  --cell-size: 68px;
  --cell-gap: 8px;
  --board-padding: 16px;
}

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

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  overflow-x: hidden;
  background-image:
    radial-gradient(ellipse at 20% 50%, rgba(99, 102, 241, 0.06) 0%, transparent 60%),
    radial-gradient(ellipse at 80% 20%, rgba(99, 102, 241, 0.04) 0%, transparent 50%);
}

/* ---- App Container ---- */
#app {
  width: 100%;
  max-width: 640px;
  padding: 24px 16px 48px;
  display: flex;
  flex-direction: column;
  align-items: center;
  position: relative;
}

/* ---- Utility ---- */
.hidden {
  display: none !important;
}

/* ---- Header ---- */
#header {
  text-align: center;
  margin-bottom: 32px;
  animation: fadeInDown 0.6s ease;
}

.logo {
  font-size: 2.25rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  background: linear-gradient(135deg, var(--accent-light), var(--accent));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.subtitle {
  font-size: 0.9rem;
  color: var(--text-secondary);
  font-weight: 400;
  margin-top: 4px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.github-link {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-top: 16px;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-secondary);
  font-size: 0.85rem;
  font-weight: 500;
  text-decoration: none;
  transition: var(--transition-base);
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.github-link:hover {
  background: rgba(255, 255, 255, 0.1);
  color: var(--text-primary);
  transform: translateY(-1px);
}

/* ---- Setup Screen ---- */
#setup-screen {
  width: 100%;
  display: flex;
  justify-content: center;
  animation: fadeInUp 0.5s ease;
}

.setup-card {
  width: 100%;
  max-width: 480px;
  background: var(--glass-bg);
  backdrop-filter: blur(var(--glass-blur));
  -webkit-backdrop-filter: blur(var(--glass-blur));
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-xl);
  padding: 36px 32px;
  box-shadow: var(--shadow-xl);
}

.setup-title {
  font-size: 1.5rem;
  font-weight: 600;
  text-align: center;
  margin-bottom: 28px;
  color: var(--text-primary);
}

.setup-section {
  margin-bottom: 28px;
}

.setup-label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 12px;
}

/* Side Selection Cards */
.side-selector {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.side-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 20px 16px;
  border-radius: var(--radius-lg);
  border: 2px solid transparent;
  background: rgba(255, 255, 255, 0.03);
  cursor: pointer;
  transition: var(--transition-base);
  font-family: inherit;
  color: var(--text-primary);
}

.side-card:hover {
  background: rgba(255, 255, 255, 0.06);
  transform: translateY(-2px);
}

.side-card.side-red {
  border-color: rgba(239, 68, 68, 0.15);
}

.side-card.side-red:hover {
  border-color: rgba(239, 68, 68, 0.3);
}

.side-card.side-red.selected {
  border-color: var(--red);
  background: rgba(239, 68, 68, 0.08);
  transform: scale(1.03);
  box-shadow: 0 0 24px rgba(239, 68, 68, 0.15);
}

.side-card.side-yellow {
  border-color: rgba(250, 204, 21, 0.15);
}

.side-card.side-yellow:hover {
  border-color: rgba(250, 204, 21, 0.3);
}

.side-card.side-yellow.selected {
  border-color: var(--yellow);
  background: rgba(250, 204, 21, 0.08);
  transform: scale(1.03);
  box-shadow: 0 0 24px rgba(250, 204, 21, 0.15);
}

.side-piece {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: block;
}

.red-piece {
  background: radial-gradient(circle at 35% 35%, var(--red-light), var(--red), var(--red-dark));
  box-shadow: 0 2px 8px rgba(239, 68, 68, 0.4);
}

.yellow-piece {
  background: radial-gradient(circle at 35% 35%, var(--yellow-light), var(--yellow), var(--yellow-dark));
  box-shadow: 0 2px 8px rgba(250, 204, 21, 0.4);
}

.side-name {
  font-size: 1rem;
  font-weight: 600;
}

.side-detail {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-weight: 400;
}

/* Difficulty Selector */
.difficulty-selector {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  border-radius: var(--radius-md);
  overflow: hidden;
  border: 1px solid rgba(99, 102, 241, 0.2);
}

.diff-btn {
  padding: 12px 8px;
  font-family: inherit;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-secondary);
  background: transparent;
  border: none;
  cursor: pointer;
  transition: var(--transition-base);
  position: relative;
}

.diff-btn:not(:last-child) {
  border-right: 1px solid rgba(99, 102, 241, 0.2);
}

.diff-btn:hover {
  color: var(--text-primary);
  background: rgba(99, 102, 241, 0.08);
}

.diff-btn.selected {
  color: #ffffff;
  background: var(--accent);
  font-weight: 600;
}

/* Start Button */
.start-button {
  display: block;
  width: 100%;
  padding: 16px 24px;
  font-family: inherit;
  font-size: 1rem;
  font-weight: 600;
  color: #ffffff;
  background: linear-gradient(135deg, var(--accent), var(--accent-dark));
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: var(--transition-base);
  letter-spacing: 0.01em;
  box-shadow: 0 4px 16px rgba(99, 102, 241, 0.3);
}

.start-button:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 24px rgba(99, 102, 241, 0.5);
  background: linear-gradient(135deg, var(--accent-light), var(--accent));
}

.start-button:active {
  transform: translateY(0);
  box-shadow: 0 2px 8px rgba(99, 102, 241, 0.3);
}

/* ---- Game Screen ---- */
#game-screen {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  animation: fadeInUp 0.5s ease;
}

/* ---- Board ---- */
#board-container {
  display: flex;
  justify-content: center;
  width: 100%;
  margin-bottom: 16px;
}

.board {
  display: grid;
  grid-template-columns: repeat(7, var(--cell-size));
  gap: 0;
  background: var(--board-gradient);
  padding: var(--board-padding);
  border-radius: var(--radius-xl);
  border: 2px solid var(--board-border);
  box-shadow:
    var(--shadow-xl),
    inset 0 1px 0 rgba(255, 255, 255, 0.05),
    0 0 60px rgba(26, 35, 126, 0.3);
  position: relative;
}

.column {
  display: flex;
  flex-direction: column;
  gap: var(--cell-gap);
  cursor: pointer;
  position: relative;
}

.column::before {
  content: '';
  position: absolute;
  inset: -4px -2px;
  border-radius: var(--radius-md);
  background: transparent;
  transition: var(--transition-fast);
  z-index: 0;
}

.column:hover::before {
  background: rgba(255, 255, 255, 0.03);
}

.cell {
  width: var(--cell-size);
  height: var(--cell-size);
  border-radius: 50%;
  background: var(--cell-bg);
  box-shadow: var(--cell-shadow);
  transition: var(--transition-base);
  position: relative;
  z-index: 1;
}

/* Piece States */
.cell.red {
  background: radial-gradient(circle at 35% 35%, var(--red-light), var(--red), var(--red-dark));
  box-shadow:
    var(--cell-shadow),
    var(--red-glow);
}

.cell.yellow {
  background: radial-gradient(circle at 35% 35%, var(--yellow-light), var(--yellow), var(--yellow-dark));
  box-shadow:
    var(--cell-shadow),
    var(--yellow-glow);
}

/* Hover Ghost Piece */
.cell.hover-red {
  background: radial-gradient(circle at 35% 35%, var(--red-light), var(--red), var(--red-dark));
  opacity: 0.25;
  box-shadow: var(--cell-shadow);
}

.cell.hover-yellow {
  background: radial-gradient(circle at 35% 35%, var(--yellow-light), var(--yellow), var(--yellow-dark));
  opacity: 0.25;
  box-shadow: var(--cell-shadow);
}

/* Drop Animation */
@keyframes drop {
  0% {
    transform: translateY(-400px);
    opacity: 0.8;
  }
  60% {
    transform: translateY(0px);
    opacity: 1;
  }
  75% {
    transform: translateY(-12px);
  }
  85% {
    transform: translateY(0px);
  }
  92% {
    transform: translateY(-4px);
  }
  100% {
    transform: translateY(0px);
  }
}

.cell.dropping {
  animation: drop 0.5s cubic-bezier(0.22, 1, 0.36, 1) forwards;
}

/* Winning Pulse Glow */
@keyframes pulse-glow-red {
  0%, 100% {
    transform: scale(1);
    box-shadow:
      var(--cell-shadow),
      var(--red-glow);
  }
  50% {
    transform: scale(1.08);
    box-shadow:
      var(--cell-shadow),
      var(--red-glow-intense);
  }
}

@keyframes pulse-glow-yellow {
  0%, 100% {
    transform: scale(1);
    box-shadow:
      var(--cell-shadow),
      var(--yellow-glow);
  }
  50% {
    transform: scale(1.08);
    box-shadow:
      var(--cell-shadow),
      var(--yellow-glow-intense);
  }
}

.cell.winning.red {
  animation: pulse-glow-red 1.2s ease-in-out infinite;
  z-index: 2;
}

.cell.winning.yellow {
  animation: pulse-glow-yellow 1.2s ease-in-out infinite;
  z-index: 2;
}

/* ---- Status Bar ---- */
#status-bar {
  width: 100%;
  max-width: calc(7 * var(--cell-size) + 2 * var(--board-padding) + 4px);
  background: var(--glass-bg);
  backdrop-filter: blur(var(--glass-blur));
  -webkit-backdrop-filter: blur(var(--glass-blur));
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-lg);
  padding: 14px 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 52px;
  box-shadow: var(--shadow-sm);
  margin-bottom: 16px;
}

#turn-indicator {
  display: flex;
  align-items: center;
  gap: 10px;
}

.turn-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--red);
  box-shadow: 0 0 8px rgba(239, 68, 68, 0.5);
  transition: var(--transition-base);
}

.turn-dot.yellow {
  background: var(--yellow);
  box-shadow: 0 0 8px rgba(250, 204, 21, 0.5);
}

#status-text {
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text-primary);
}

/* Thinking Indicator */
#thinking-indicator {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text-secondary);
  font-size: 0.9rem;
  font-weight: 500;
}

.thinking-dots {
  display: flex;
  gap: 4px;
  align-items: center;
}

.thinking-dots .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent-light);
  animation: bounce-dot 1.4s ease-in-out infinite;
}

.thinking-dots .dot:nth-child(2) {
  animation-delay: 0.16s;
}

.thinking-dots .dot:nth-child(3) {
  animation-delay: 0.32s;
}

@keyframes bounce-dot {
  0%, 80%, 100% {
    transform: translateY(0);
    opacity: 0.4;
  }
  40% {
    transform: translateY(-8px);
    opacity: 1;
  }
}

/* Result Text */
#result-text {
  font-size: 1rem;
  font-weight: 600;
  text-align: center;
}

#result-text.win {
  color: var(--accent-light);
}

#result-text.lose {
  color: var(--red);
}

#result-text.draw {
  color: var(--yellow);
}

/* ---- Controls ---- */
#controls {
  display: flex;
  justify-content: center;
}

.new-game-button {
  padding: 12px 28px;
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--accent-light);
  background: transparent;
  border: 2px solid rgba(99, 102, 241, 0.3);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: var(--transition-base);
  letter-spacing: 0.01em;
}

.new-game-button:hover {
  background: rgba(99, 102, 241, 0.1);
  border-color: var(--accent);
  box-shadow: var(--accent-glow);
  transform: translateY(-1px);
}

.new-game-button:active {
  transform: translateY(0);
}

/* ---- Game Over Overlay ---- */
#game-over-overlay {
  position: fixed;
  inset: 0;
  background: rgba(6, 9, 24, 0.85);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  animation: fadeIn 0.3s ease;
}

.overlay-content {
  text-align: center;
  padding: 48px 40px;
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-xl);
  animation: slideInUp 0.4s ease;
  max-width: 400px;
  width: calc(100% - 32px);
}

#overlay-icon {
  font-size: 3.5rem;
  margin-bottom: 16px;
  line-height: 1;
}

#overlay-title {
  font-size: 1.75rem;
  font-weight: 700;
  margin-bottom: 8px;
  color: var(--text-primary);
}

#overlay-subtitle {
  font-size: 0.95rem;
  color: var(--text-secondary);
  margin-bottom: 28px;
  line-height: 1.5;
}

.overlay-content .start-button {
  max-width: 240px;
  margin: 0 auto;
}

/* ---- Animations ---- */
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

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

@keyframes fadeInDown {
  from {
    opacity: 0;
    transform: translateY(-20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes slideInUp {
  from {
    opacity: 0;
    transform: translateY(40px) scale(0.95);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

/* ---- Disabled state for board during AI turn ---- */
.board.disabled .column {
  cursor: not-allowed;
  pointer-events: none;
}

.board.disabled .column::before {
  display: none;
}

/* ---- Responsive ---- */
@media (max-width: 600px) {
  :root {
    --cell-size: 45px;
    --cell-gap: 6px;
    --board-padding: 12px;
  }

  #app {
    padding: 16px 12px 32px;
  }

  .logo {
    font-size: 1.75rem;
  }

  .subtitle {
    font-size: 0.78rem;
  }

  #header {
    margin-bottom: 20px;
  }

  .setup-card {
    padding: 28px 20px;
  }

  .setup-title {
    font-size: 1.25rem;
  }

  .side-selector {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .side-card {
    flex-direction: row;
    gap: 12px;
    padding: 14px 16px;
  }

  .side-piece {
    width: 32px;
    height: 32px;
  }

  .diff-btn {
    padding: 10px 6px;
    font-size: 0.8rem;
  }

  .start-button {
    padding: 14px 20px;
    font-size: 0.9rem;
  }

  #status-bar {
    padding: 10px 14px;
    min-height: 44px;
  }

  #status-text,
  #thinking-indicator {
    font-size: 0.82rem;
  }

  #result-text {
    font-size: 0.9rem;
  }

  .overlay-content {
    padding: 36px 24px;
  }

  #overlay-icon {
    font-size: 2.5rem;
  }

  #overlay-title {
    font-size: 1.4rem;
  }

  #overlay-subtitle {
    font-size: 0.85rem;
  }
}

@media (max-width: 400px) {
  :root {
    --cell-size: 38px;
    --cell-gap: 4px;
    --board-padding: 10px;
  }

  .logo {
    font-size: 1.5rem;
  }
}
