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

:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface2: #242836;
  --border: #2e3348;
  --text: #e4e6f0;
  --text-dim: #8b8fa8;
  --accent: #6c63ff;
  --accent-glow: rgba(108, 99, 255, 0.25);
  --green: #4ade80;
  --red: #f87171;
  --yellow: #facc15;
  --cyan: #22d3ee;
  --pink: #f472b6;
  --orange: #fb923c;
  --radius: 12px;
}

body {
  font-family: 'Inter', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

header {
  padding: 3rem 1.5rem 2rem;
  text-align: center;
  background: linear-gradient(180deg, #161926 0%, var(--bg) 100%);
  border-bottom: 1px solid var(--border);
}

.header-inner {
  max-width: 800px;
  margin: 0 auto;
}

.logo {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  margin-bottom: 0.5rem;
}

.logo-icon {
  font-size: 2.5rem;
  cursor: pointer;
  transition: transform 0.2s;
  user-select: none;
}

.logo-icon:hover {
  transform: scale(1.2);
}

.logo-icon:active {
  transform: scale(0.95);
}

.logo h1 {
  font-size: 2.2rem;
  font-weight: 800;
  letter-spacing: -0.03em;
}

.accent {
  color: var(--accent);
}

.tagline {
  color: var(--text-dim);
  font-size: 1.1rem;
}

main {
  flex: 1;
  max-width: 1200px;
  width: 100%;
  margin: 0 auto;
  padding: 2.5rem 1.5rem;
}

.games-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 1.25rem;
}

.game-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  cursor: pointer;
  transition: transform 0.2s, border-color 0.2s, box-shadow 0.2s;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.game-card:hover {
  transform: translateY(-4px);
  border-color: var(--accent);
  box-shadow: 0 8px 30px var(--accent-glow);
}

.game-card-icon {
  font-size: 2.5rem;
  line-height: 1;
}

.game-card h3 {
  font-size: 1.15rem;
  font-weight: 700;
}

.game-card p {
  color: var(--text-dim);
  font-size: 0.88rem;
  line-height: 1.5;
}

.game-card-tag {
  display: inline-block;
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.72rem;
  background: var(--surface2);
  color: var(--accent);
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  width: fit-content;
}

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(4px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 1rem;
}

.modal-overlay.active {
  display: flex;
}

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: 100%;
  max-width: 700px;
  max-height: 95vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: modalIn 0.25s ease;
  position: relative;
}

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

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--border);
  position: relative;
  z-index: 20;
}

.modal-header-btns {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.modal-pause {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 1.3rem;
  cursor: pointer;
  padding: 0.25rem;
  transition: color 0.15s;
  line-height: 1;
}

.modal-pause:hover {
  color: var(--text);
}

.pause-overlay {
  display: none;
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.85);
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 0.75rem;
  z-index: 15;
  cursor: pointer;
}

.pause-overlay.active {
  display: flex;
}

.pause-title {
  font-family: 'JetBrains Mono', monospace;
  font-size: 2.5rem;
  font-weight: 800;
  color: var(--accent);
  letter-spacing: 0.15em;
}

.pause-hint {
  color: var(--text-dim);
  font-size: 0.95rem;
}

.modal-header h2 {
  font-size: 1.25rem;
  font-weight: 700;
}

.modal-close {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 1.75rem;
  cursor: pointer;
  line-height: 1;
  padding: 0.25rem;
  transition: color 0.15s;
}

.modal-close:hover {
  color: var(--text);
}

.modal-body {
  padding: 1.5rem;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
}

.modal-body canvas {
  border-radius: 8px;
  display: block;
  background: #111320;
  max-width: 100%;
}

/* Game-specific UI inside modal */
.game-controls {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  justify-content: center;
}

.game-btn {
  font-family: 'Inter', sans-serif;
  font-size: 0.9rem;
  font-weight: 600;
  padding: 0.6rem 1.4rem;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  background: var(--accent);
  color: #fff;
  transition: opacity 0.15s;
}

.game-btn:hover {
  opacity: 0.85;
}

.game-score {
  font-family: 'JetBrains Mono', monospace;
  font-size: 1rem;
  color: var(--yellow);
}

.game-info {
  font-size: 0.85rem;
  color: var(--text-dim);
  text-align: center;
  max-width: 500px;
}

/* Minesweeper */
.mine-board {
  display: grid;
  gap: 2px;
}

.mine-cell {
  width: 36px;
  height: 36px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
  user-select: none;
  font-family: 'JetBrains Mono', monospace;
}

.mine-cell.revealed {
  background: var(--bg);
  cursor: default;
}

.mine-cell.mine { background: var(--red); }
.mine-cell.flag { background: var(--surface2); }

.mine-1 { color: #60a5fa; }
.mine-2 { color: var(--green); }
.mine-3 { color: var(--red); }
.mine-4 { color: #a78bfa; }
.mine-5 { color: var(--orange); }
.mine-6 { color: var(--cyan); }
.mine-7 { color: var(--pink); }
.mine-8 { color: var(--text-dim); }

/* 2048 */
.twenty48-board {
  display: grid;
  grid-template-columns: repeat(4, 80px);
  grid-template-rows: repeat(4, 80px);
  gap: 6px;
  background: var(--bg);
  padding: 6px;
  border-radius: 8px;
}

.twenty48-cell {
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 1.4rem;
  font-family: 'JetBrains Mono', monospace;
  transition: transform 0.12s;
}

/* Simon */
.simon-board {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  width: 280px;
}

.simon-pad {
  width: 130px;
  height: 130px;
  border-radius: 16px;
  border: none;
  cursor: pointer;
  opacity: 0.6;
  transition: opacity 0.15s, transform 0.1s;
}

.simon-pad:hover { opacity: 0.8; }
.simon-pad.lit { opacity: 1; transform: scale(1.05); }
.simon-pad.green { background: var(--green); }
.simon-pad.red { background: var(--red); }
.simon-pad.yellow { background: var(--yellow); }
.simon-pad.blue { background: #60a5fa; }

/* Hangman */
.hangman-word {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: center;
}

.hangman-letter {
  width: 36px;
  height: 44px;
  border-bottom: 3px solid var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  font-weight: 700;
  font-family: 'JetBrains Mono', monospace;
}

.hangman-keyboard {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: center;
  max-width: 400px;
}

.hangman-key {
  width: 38px;
  height: 38px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  transition: background 0.15s;
}

.hangman-key:hover:not(:disabled) {
  background: var(--accent);
}

.hangman-key:disabled {
  opacity: 0.3;
  cursor: default;
}

/* Wordle */
.wordle-board {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.wordle-row {
  display: flex;
  gap: 6px;
}

.wordle-cell {
  width: 56px;
  height: 56px;
  border: 2px solid var(--border);
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  font-weight: 800;
  font-family: 'JetBrains Mono', monospace;
  color: var(--text);
  text-transform: uppercase;
  transition: border-color 0.15s, background 0.3s;
}

.wordle-cell.filled {
  border-color: var(--text-dim);
}

.wordle-cell.correct {
  background: #16a34a;
  border-color: #16a34a;
  color: #fff;
}

.wordle-cell.present {
  background: #ca8a04;
  border-color: #ca8a04;
  color: #fff;
}

.wordle-cell.absent {
  background: #3f3f46;
  border-color: #3f3f46;
  color: #a1a1aa;
}

.wordle-keyboard {
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: center;
}

.wordle-kb-row {
  display: flex;
  gap: 5px;
}

.wordle-key {
  min-width: 36px;
  height: 46px;
  padding: 0 8px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-weight: 700;
  font-size: 0.85rem;
  cursor: pointer;
  transition: background 0.15s;
  font-family: 'Inter', sans-serif;
}

.wordle-key:hover {
  background: var(--border);
}

.wordle-key.wide {
  min-width: 56px;
  font-size: 0.75rem;
}

.wordle-key.correct {
  background: #16a34a;
  border-color: #16a34a;
  color: #fff;
}

.wordle-key.present {
  background: #ca8a04;
  border-color: #ca8a04;
  color: #fff;
}

.wordle-key.absent {
  background: #3f3f46;
  border-color: #3f3f46;
  color: #71717a;
}

/* Chess */
.chess-board {
  display: grid;
  grid-template-columns: repeat(8, 50px);
  grid-template-rows: repeat(8, 50px);
  border-radius: 4px;
  overflow: hidden;
  border: 2px solid var(--border);
}

.chess-cell {
  width: 50px;
  height: 50px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2rem;
  cursor: pointer;
  user-select: none;
  position: relative;
  line-height: 1;
}

.chess-cell.light { background: #c8a882; }
.chess-cell.dark { background: #8b6b4a; }
.chess-cell.selected { background: rgba(108, 99, 255, 0.55); }

.chess-cell.move-target::after {
  content: '';
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: rgba(74, 222, 128, 0.5);
  position: absolute;
}

.chess-cell.capture-target {
  box-shadow: inset 0 0 0 3px rgba(248, 113, 113, 0.7);
}

/* Footer */
footer {
  text-align: center;
  padding: 2rem 1rem;
  color: var(--text-dim);
  font-size: 0.85rem;
  border-top: 1px solid var(--border);
}

/* Mobile touch controls */
.touch-controls {
  display: none;
  gap: 4px;
  justify-content: center;
}

.touch-btn {
  width: 56px;
  height: 56px;
  border-radius: 10px;
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 1.4rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.touch-dpad {
  display: grid;
  grid-template-columns: repeat(3, 56px);
  grid-template-rows: repeat(3, 56px);
  gap: 4px;
}

.touch-dpad .empty { visibility: hidden; }

@media (pointer: coarse) {
  .touch-controls { display: flex; }
}

@media (max-width: 600px) {
  .logo h1 { font-size: 1.6rem; }
  .logo-icon { font-size: 2rem; }
  .games-grid { grid-template-columns: 1fr; }
  .twenty48-board { grid-template-columns: repeat(4, 65px); grid-template-rows: repeat(4, 65px); }
  .twenty48-cell { font-size: 1rem; }
  .simon-board { width: 220px; }
  .simon-pad { width: 100px; height: 100px; }
  .modal { max-width: 100%; }
  .chess-board { grid-template-columns: repeat(8, 40px); grid-template-rows: repeat(8, 40px); }
  .chess-cell { width: 40px; height: 40px; font-size: 1.6rem; }
  .chess-cell.move-target::after { width: 10px; height: 10px; }
}
