:root {
  --bg-color: #0f172a;
  --panel-bg: #1e293b;
  --panel-border: #334155;
  --text-main: #f8fafc;
  --text-dim: #94a3b8;
  --accent-color: #38bdf8;

  /* Stone Colors */
  --stone-red: #ef4444;
  --stone-red-highlight: #fca5a5;
  --stone-blue: #3b82f6;
  --stone-blue-highlight: #93c5fd;
  --stone-green: #22c55e;
  --stone-green-highlight: #86efac;
  --stone-yellow: #eab308;
  --stone-yellow-highlight: #fef08a;

  --cell-size: 38px;
  --cols: 6;
  --rows: 12;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background-color: var(--bg-color);
  color: var(--text-main);
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  user-select: none;
  padding: 16px;
}

.game-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  max-width: 900px;
  width: 100%;
}

.game-header {
  margin-bottom: 16px;
  text-align: center;
}

.game-header h1 {
  font-size: 1.8rem;
  letter-spacing: 1px;
  color: #38bdf8;
  text-transform: uppercase;
}

.main-layout {
  display: flex;
  flex-wrap: wrap;
  gap: 20px;
  justify-content: center;
  align-items: flex-start;
}

/* Sidebar Panels */
.sidebar {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 170px;
}

.panel-box {
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  padding: 12px;
  text-align: center;
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.2);
}

.stat-label {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--text-dim);
  letter-spacing: 1px;
  margin-bottom: 4px;
}

.stat-value {
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--text-main);
  font-variant-numeric: tabular-nums;
}

/* Next Piece Preview */
.next-preview-grid {
  display: grid;
  grid-template-columns: repeat(2, var(--cell-size));
  grid-template-rows: repeat(2, var(--cell-size));
  gap: 4px;
  justify-content: center;
  margin-top: 8px;
  min-height: calc(var(--cell-size) * 2 + 4px);
}

/* Board Styling */
.board-wrapper {
  position: relative;
}

.board-frame {
  position: relative;
  background: #020617;
  border: 3px solid #475569;
  border-radius: 8px;
  padding: 4px;
  box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.5), inset 0 0 12px rgba(0, 0, 0, 0.8);
  overflow: hidden;
}

.board {
  display: grid;
  grid-template-columns: repeat(var(--cols), var(--cell-size));
  grid-template-rows: repeat(var(--rows), var(--cell-size));
  gap: 2px;
  background-color: #0b1120;
}

/* Cell & Stone */
.cell {
  width: var(--cell-size);
  height: var(--cell-size);
  background-color: #111827;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

.stone {
  width: 90%;
  height: 90%;
  border-radius: 50%;
  box-shadow: inset 0 3px 6px rgba(255, 255, 255, 0.4), inset 0 -4px 6px rgba(0, 0, 0, 0.4), 0 2px 4px rgba(0, 0, 0, 0.5);
  transition: transform 0.08s ease;
  position: relative;
}

/* Stone Colors */
.stone.color-1 {
  background: radial-gradient(circle at 35% 35%, var(--stone-red-highlight), var(--stone-red));
}

.stone.color-2 {
  background: radial-gradient(circle at 35% 35%, var(--stone-blue-highlight), var(--stone-blue));
}

.stone.color-3 {
  background: radial-gradient(circle at 35% 35%, var(--stone-green-highlight), var(--stone-green));
}

.stone.color-4 {
  background: radial-gradient(circle at 35% 35%, var(--stone-yellow-highlight), var(--stone-yellow));
}

/* Pivot indicator (subtle center dot) */
.stone.pivot::after {
  content: "";
  position: absolute;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.85);
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  box-shadow: 0 0 2px rgba(0,0,0,0.5);
}

/* Elimination animation */
.stone.popping {
  animation: popAnim 0.28s ease-in-out forwards;
}

@keyframes popAnim {
  0% {
    transform: scale(1);
    filter: brightness(1.6);
  }
  50% {
    transform: scale(1.25);
    filter: brightness(2);
  }
  100% {
    transform: scale(0);
    opacity: 0;
  }
}

/* Chain Combo Banner */
.chain-banner {
  position: absolute;
  top: 40%;
  left: 50%;
  transform: translate(-50%, -50%) scale(1);
  background: linear-gradient(135deg, #f59e0b, #ef4444);
  color: white;
  padding: 8px 16px;
  font-size: 1.25rem;
  font-weight: 900;
  border-radius: 9999px;
  box-shadow: 0 0 20px rgba(245, 158, 11, 0.8);
  pointer-events: none;
  z-index: 10;
  transition: opacity 0.3s ease, transform 0.3s ease;
}

.chain-banner.pop {
  animation: bannerPop 0.6s ease forwards;
}

@keyframes bannerPop {
  0% { transform: translate(-50%, -50%) scale(0.6); opacity: 0; }
  30% { transform: translate(-50%, -50%) scale(1.15); opacity: 1; }
  80% { transform: translate(-50%, -50%) scale(1); opacity: 1; }
  100% { transform: translate(-50%, -50%) scale(0.9); opacity: 0; }
}

/* Controls list */
.controls-card {
  text-align: left;
}

.controls-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 8px 0;
}

.controls-list li {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.85rem;
}

.key-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 26px;
  height: 26px;
  padding: 0 6px;
  background: #334155;
  border: 1px solid #64748b;
  border-radius: 4px;
  font-weight: 700;
  color: #38bdf8;
  font-family: monospace;
  box-shadow: 0 2px 0 #1e293b;
}

.controls-hint {
  font-size: 0.72rem;
  color: var(--text-dim);
  margin-top: 6px;
}

/* On-screen pad */
.onscreen-controls {
  padding: 8px;
}

.pad-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin-top: 8px;
}

.pad-btn {
  background: #334155;
  border: 1px solid #475569;
  border-radius: 6px;
  color: var(--text-main);
  padding: 8px 4px;
  font-weight: 700;
  font-size: 0.8rem;
  cursor: pointer;
  transition: background 0.1s;
}

.pad-btn:active {
  background: #0284c7;
}

/* Buttons */
.btn {
  background: #334155;
  color: var(--text-main);
  border: none;
  border-radius: 6px;
  padding: 10px 14px;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s, transform 0.05s;
}

.btn:hover {
  background: #475569;
}

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

.btn-primary {
  background: #0284c7;
}

.btn-primary:hover {
  background: #0369a1;
}

/* Game Over Overlay */
.overlay {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.85);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 20;
}

.overlay.hidden, .chain-banner.hidden {
  display: none;
}

.overlay-content {
  background: #1e293b;
  border: 2px solid #ef4444;
  border-radius: 10px;
  padding: 24px;
  text-align: center;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.7);
}

.overlay-content h2 {
  font-size: 1.8rem;
  color: #ef4444;
  margin-bottom: 12px;
}

.overlay-content p {
  font-size: 1.1rem;
  margin-bottom: 18px;
  color: var(--text-main);
}

@media (max-width: 600px) {
  :root {
    --cell-size: 32px;
  }
  .main-layout {
    flex-direction: column;
    align-items: center;
  }
  .sidebar {
    width: 100%;
    max-width: calc(var(--cell-size) * 6 + 20px);
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: space-between;
  }
  .sidebar .panel-box {
    flex: 1 1 45%;
  }
}
