@import url('https://fonts.googleapis.com/css2?family=Press+Start+2P&display=swap');

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

:root {
  --bg: #1a1a2e;
  --surface: #20203a;
  --border: #2d2d55;
  --text: #e2e8f0;
  --muted: #4a5568;
  --accent: #a855f7;
}

/* ── Light mode ──────────────────────────────── */
html.light {
  --bg: #c8cde4;
  --surface: #dce1f5;
  --border: #a8b0d0;
  --text: #1e2040;
  --muted: #5a6080;
  --accent: #7c3aed;
}

/* Canvas games: lighter background drawn by JS when FBG_LIGHT is true.
   Canvas bg color used: #dce1f5  grid/line color: #b8c0dc  */

/* ── DOM game light-mode overrides ─────────────── */
/* Minesweeper grid + Tic-Tac-Toe board */
html.light #grid  { background: var(--surface) !important; border-color: var(--border) !important; }
html.light #board { background: var(--surface) !important; border-color: var(--border) !important; }

/* Shared .cell (Minesweeper + Tic-Tac-Toe) */
html.light .cell                    { background: #d0d4ed !important; border-color: var(--border) !important; }
html.light .cell:hover:not(.taken)  { background: #c0c4dd !important; }
html.light .cell.revealed           { background: #e8ecf8 !important; border-color: #c0c8e0 !important; }
html.light .cell.mine-hit           { background: #fecaca !important; }
html.light .cell.win                { background: #d1fae5 !important; border-color: #4ade80 !important; }

/* Memory Match */
html.light .card-back  { background: #c8ccdf !important; border-color: var(--border) !important; }

/* 2048 board wrapper */
html.light #board-wrap { background: var(--surface) !important; border-color: var(--border) !important; }

/* Tetris side panel */
html.light .side-box { background: var(--surface) !important; border-color: var(--border) !important; }

/* Theme toggle button injected by theme.js */
.theme-btn-game {
  font-size: 0.85rem;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.3rem 0.4rem;
  cursor: pointer;
  line-height: 1;
  flex-shrink: 0;
  transition: border-color 0.15s;
}
.theme-btn-game:hover { border-color: var(--text); }

body {
  font-family: 'Press Start 2P', monospace;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  overflow-x: hidden;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

/* ── Top bar ────────────────────────────────── */
.top-bar {
  width: 100%;
  max-width: 520px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.7rem 1rem;
  gap: 0.5rem;
  flex-shrink: 0;
}
.back {
  font-family: inherit;
  font-size: 0.6rem;
  color: var(--muted);
  text-decoration: none;
  padding: 0.45rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  white-space: nowrap;
  transition: color 0.12s, border-color 0.12s;
  flex-shrink: 0;
}
.back:hover { color: var(--text); border-color: var(--text); }
.game-title {
  font-size: clamp(0.62rem, 3vw, 0.88rem);
  text-align: center;
  flex: 1;
}
.score-box {
  font-size: 0.55rem;
  text-align: right;
  line-height: 1.9;
  color: var(--muted);
  flex-shrink: 0;
}
.score-box b { color: var(--accent); }

/* ── Canvas ─────────────────────────────────── */
canvas {
  display: block;
  max-width: 100%;
  height: auto;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  flex-shrink: 0;
}

/* ── Buttons ────────────────────────────────── */
.btn {
  font-family: inherit;
  font-size: 0.65rem;
  background: transparent;
  color: var(--text);
  border: 2px solid var(--border);
  padding: 0.6rem 1.2rem;
  border-radius: 8px;
  cursor: pointer;
  transition: border-color 0.12s, color 0.12s;
  -webkit-tap-highlight-color: transparent;
}
.btn:hover { border-color: var(--accent); color: var(--accent); }
.btn:active { opacity: 0.7; }

/* ── Mobile D-pad ───────────────────────────── */
.dpad-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0 0.25rem;
}
.dpad {
  display: grid;
  grid-template-areas: ". up ." "left . right" ". down .";
  grid-template-columns: 52px 52px 52px;
  grid-template-rows: 52px 52px 52px;
  gap: 5px;
}
.d-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.3rem;
  background: rgba(255,255,255,0.05);
  border: 1px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
  transition: background 0.1s;
}
.d-btn:active { background: rgba(255,255,255,0.18); }
.d-up    { grid-area: up; }
.d-left  { grid-area: left; }
.d-right { grid-area: right; }
.d-down  { grid-area: down; }

/* ── Action button row ──────────────────────── */
.action-row {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  padding: 0.4rem 1rem;
}
.act-btn {
  font-family: inherit;
  font-size: 0.6rem;
  padding: 0.5rem 1rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: rgba(255,255,255,0.05);
  color: var(--text);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.1s;
}
.act-btn:active { background: rgba(255,255,255,0.18); }

/* ── Overlay ─────────────────────────────────── */
.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1.2rem;
  background: rgba(8,8,16,0.88);
  z-index: 20;
  padding: 2rem;
}
.overlay h2 {
  font-size: clamp(0.9rem, 4vw, 1.4rem);
  text-align: center;
  line-height: 1.5;
}
.overlay p {
  font-size: clamp(0.5rem, 2.2vw, 0.7rem);
  color: var(--muted);
  text-align: center;
  line-height: 1.8;
}
.overlay .big {
  font-size: clamp(0.6rem, 2.5vw, 0.9rem);
  color: var(--accent);
}

/* Light mode: overlay / game-over / start screens */
html.light .overlay,
html.light #overlay {
  background: rgba(200, 205, 228, 0.96) !important;
}
html.light .overlay h2,
html.light #overlay h2 { color: var(--text) !important; }
html.light .overlay p,
html.light #overlay p  { color: var(--muted) !important; }
