/* ===== Game Shared Styles ===== */

/* Game container */
.game-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.game-stats {
  display: flex;
  gap: 20px;
  font-size: 0.9375rem;
  font-weight: 500;
}
.game-stat {
  text-align: center;
  padding: 8px 16px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.game-stat-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-transform: uppercase;
}
.game-stat-value {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--accent);
}

.game-controls {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
}

.game-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius);
  z-index: 10;
  animation: fadeIn 0.3s ease;
}
.game-overlay h3 {
  color: #fff;
  font-size: 1.5rem;
  margin-bottom: 12px;
}

/* ===== Canvas Games (Snake) ===== */
.canvas-wrapper {
  position: relative;
  display: inline-block;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--bg-secondary);
}

/* D-pad for mobile */
.dpad {
  display: grid;
  grid-template-columns: 60px 60px 60px;
  grid-template-rows: 60px 60px 60px;
  gap: 4px;
  justify-content: center;
}
.dpad-btn {
  width: 60px;
  height: 60px;
  font-size: 1.5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-secondary);
  color: var(--text-primary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition);
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
}
.dpad-btn:active {
  background: var(--accent-light);
}
.dpad-up    { grid-column: 2; grid-row: 1; }
.dpad-left  { grid-column: 1; grid-row: 2; }
.dpad-center{ grid-column: 2; grid-row: 2; visibility: hidden; }
.dpad-right { grid-column: 3; grid-row: 2; }
.dpad-down  { grid-column: 2; grid-row: 3; }

/* ===== 2048 Grid ===== */
.grid-2048 {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  background: var(--border);
  padding: 8px;
  border-radius: var(--radius-lg);
  width: min(100%, 400px);
  aspect-ratio: 1;
}
.tile-2048 {
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 1.5rem;
  border-radius: 6px;
  background: var(--bg-secondary);
  transition: all 0.15s ease;
  color: var(--text-primary);
}
.tile-2048[data-value="2"]    { background: #eee4da; color: #776e65; }
.tile-2048[data-value="4"]    { background: #ede0c8; color: #776e65; }
.tile-2048[data-value="8"]    { background: #f2b179; color: #fff; }
.tile-2048[data-value="16"]   { background: #f59563; color: #fff; }
.tile-2048[data-value="32"]   { background: #f67c5f; color: #fff; }
.tile-2048[data-value="64"]   { background: #f65e3b; color: #fff; }
.tile-2048[data-value="128"]  { background: #edcf72; color: #fff; font-size: 1.25rem; }
.tile-2048[data-value="256"]  { background: #edcc61; color: #fff; font-size: 1.25rem; }
.tile-2048[data-value="512"]  { background: #edc850; color: #fff; font-size: 1.25rem; }
.tile-2048[data-value="1024"] { background: #edc53f; color: #fff; font-size: 1rem; }
.tile-2048[data-value="2048"] { background: #edc22e; color: #fff; font-size: 1rem; }
.tile-2048.new-tile { animation: tilePop 0.2s ease; }
.tile-2048.merged   { animation: tilePop 0.25s ease; }

@keyframes tilePop {
  0%   { transform: scale(0); }
  50%  { transform: scale(1.1); }
  100% { transform: scale(1); }
}

/* ===== Minesweeper ===== */
.mine-grid {
  display: inline-grid;
  gap: 1px;
  background: var(--border);
  border: 2px solid var(--border);
  border-radius: 4px;
  padding: 1px;
}
.mine-cell {
  width: 32px;
  height: 32px;
  border: none;
  padding: 0;
  cursor: pointer;
  font-size: 0.8125rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-secondary);
  transition: background var(--transition);
  color: var(--text-primary);
}
.mine-cell:active:not(.revealed) {
  background: var(--border);
}
.mine-cell.revealed {
  background: var(--bg-primary);
  cursor: default;
}
.mine-cell.flagged {
  background: var(--accent-light);
}
.mine-cell.mine-exploded {
  background: var(--danger) !important;
}

/* Number colors */
.mine-cell[data-n="1"] { color: #2563eb; }
.mine-cell[data-n="2"] { color: #16a34a; }
.mine-cell[data-n="3"] { color: #dc2626; }
.mine-cell[data-n="4"] { color: #7c3aed; }
.mine-cell[data-n="5"] { color: #b91c1c; }
.mine-cell[data-n="6"] { color: #0891b2; }
.mine-cell[data-n="7"] { color: #000; }
.mine-cell[data-n="8"] { color: #6b7280; }

/* ===== Memory Card Match ===== */
.memory-grid {
  display: grid;
  gap: 10px;
  justify-content: center;
}

.memory-card {
  aspect-ratio: 1;
  perspective: 600px;
  cursor: pointer;
  background: none;
  border: none;
  padding: 0;
}
.memory-card-inner {
  position: relative;
  width: 100%;
  height: 100%;
  transition: transform 0.5s ease;
  transform-style: preserve-3d;
}
.memory-card.flipped .memory-card-inner,
.memory-card.matched .memory-card-inner {
  transform: rotateY(180deg);
}

.memory-card-face {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius);
  border: 2px solid var(--border);
  backface-visibility: hidden;
  font-size: 2rem;
}
.memory-card-back {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.memory-card-front {
  background: var(--bg-secondary);
  transform: rotateY(180deg);
}
.memory-card.matched .memory-card-front {
  border-color: var(--success);
  background: rgba(34,197,94,0.1);
}

/* ===== Typing Speed Test ===== */
.typing-display {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  font-size: 1.25rem;
  line-height: 1.8;
  letter-spacing: 0.5px;
  min-height: 120px;
  word-break: break-all;
}
.typing-display .correct { color: var(--success); }
.typing-display .incorrect { color: var(--danger); text-decoration: underline; }
.typing-display .pending { color: var(--text-muted); }
.typing-display .cursor {
  border-left: 2px solid var(--accent);
  animation: blink 1s step-end infinite;
}
@keyframes blink {
  50% { border-color: transparent; }
}

.typing-input {
  width: 100%;
  opacity: 0;
  position: absolute;
  pointer-events: none;
}

/* ===== Responsive Games ===== */
@media (max-width: 480px) {
  .mine-cell {
    width: 24px;
    height: 24px;
    font-size: 0.6875rem;
  }
  .grid-2048 {
    width: 100%;
  }
  .tile-2048 {
    font-size: 1.125rem;
  }
  .tile-2048[data-value="128"],
  .tile-2048[data-value="256"],
  .tile-2048[data-value="512"] { font-size: 1rem; }
  .tile-2048[data-value="1024"],
  .tile-2048[data-value="2048"] { font-size: 0.75rem; }
  .memory-card-face {
    font-size: 1.5rem;
  }
  .typing-display {
    font-size: 1rem;
    padding: 14px;
  }
}
