/* Shared dark theme, mobile-first. */
:root {
  --bg: #0d1124;
  --bg-elev: #1a1f3d;
  --bg-card: #232844;
  --border: #2d3563;
  --fg: #e8e9ee;
  --fg-dim: #9aa0b4;
  --accent: #6ee7ff;
  --accent-2: #ffb86b;
  --danger: #ff6b8a;
  --good: #8aff9a;
  --shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
  --radius: 12px;
  --tap: 44px;

  /* Per-game accents (used on cards via [data-game] and on game pages via body[data-game]) */
  --accent-snake: #58e08a;
  --accent-tictactoe: #7cb8ff;
  --accent-memory: #d97cff;
  --accent-mines: #ff7c7c;
  --accent-2048: #ffd166;
  --accent-breakout: #ff9a4d;
  --accent-flappy: #6ee7ff;
  --accent-physics: #b08aff;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen,
    Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
  font-size: 16px;
  line-height: 1.4;
  -webkit-text-size-adjust: 100%;
  min-height: 100vh;
}

body {
  display: flex;
  flex-direction: column;
}

a { color: var(--accent); text-decoration: none; }
a:hover, a:focus { text-decoration: underline; }
a:focus-visible, button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

h1, h2, h3 { margin: 0 0 0.5em; line-height: 1.2; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.15rem; color: var(--accent); }
p { margin: 0 0 1em; }

.page-header {
  padding: 1rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  background: var(--bg-elev);
}
.page-header h1 { margin: 0; font-size: 1.15rem; }
/* Brand: bigger, bolder, gradient-filled on the landing only (no data-game body) */
body:not([data-game]) .page-header h1 {
  font-size: 1.4rem;
  font-weight: 800;
  letter-spacing: 0.02em;
  background: linear-gradient(90deg, #6ee7ff, #b08aff);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.back-link {
  display: inline-flex;
  align-items: center;
  min-height: var(--tap);
  padding: 0 0.75rem;
  border-radius: 8px;
  font-weight: 600;
}

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

.subtitle {
  color: var(--fg-dim);
  margin-bottom: 1.5rem;
}

/* --- Landing grid --- */
.game-grid {
  display: grid;
  gap: 1rem;
  grid-template-columns: 1fr;
}
@media (min-width: 560px) {
  .game-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (min-width: 900px) {
  .game-grid { grid-template-columns: repeat(4, 1fr); }
}

.game-card {
  --card-accent: var(--accent);
  position: relative;
  display: flex;
  flex-direction: column;
  background: var(--bg-card);
  background: linear-gradient(160deg, var(--bg-card), color-mix(in srgb, var(--bg-card) 80%, var(--card-accent) 20%));
  border: 1px solid var(--border);
  border-left: 4px solid var(--card-accent);
  border-radius: var(--radius);
  padding: 1.25rem;
  color: var(--fg);
  min-height: 160px;
  transition: transform 0.12s ease, border-color 0.12s ease, box-shadow 0.18s ease;
  box-shadow: var(--shadow);
}
.game-card:hover, .game-card:focus-visible {
  transform: translateY(-2px);
  border-color: var(--card-accent);
  border-left-color: var(--card-accent);
  box-shadow: 0 0 24px color-mix(in srgb, var(--card-accent) 45%, transparent), var(--shadow);
  text-decoration: none;
}
.game-card .emoji {
  font-size: 3rem;
  line-height: 1;
  margin-bottom: 0.5rem;
}
.game-card h2 { color: var(--card-accent); margin-bottom: 0.25rem; }
.game-card p { color: var(--fg-dim); margin: 0; font-size: 0.9rem; }

/* Per-game accent assignment on cards. */
.game-card[data-game="snake"]      { --card-accent: var(--accent-snake); }
.game-card[data-game="tictactoe"]  { --card-accent: var(--accent-tictactoe); }
.game-card[data-game="memory"]     { --card-accent: var(--accent-memory); }
.game-card[data-game="minesweeper"]{ --card-accent: var(--accent-mines); }
.game-card[data-game="2048"]       { --card-accent: var(--accent-2048); }
.game-card[data-game="breakout"]   { --card-accent: var(--accent-breakout); }
.game-card[data-game="flappy"]     { --card-accent: var(--accent-flappy); }
.game-card[data-game="physics"]    { --card-accent: var(--accent-physics); }

/* Per-game-page accent — body[data-game] re-tints --accent for the whole page
   (scoreboard ranks, scores, .primary buttons, focus rings, etc.). */
body[data-game="snake"]       { --accent: var(--accent-snake); }
body[data-game="tictactoe"]   { --accent: var(--accent-tictactoe); }
body[data-game="memory"]      { --accent: var(--accent-memory); }
body[data-game="minesweeper"] { --accent: var(--accent-mines); }
body[data-game="2048"]        { --accent: var(--accent-2048); }
body[data-game="breakout"]    { --accent: var(--accent-breakout); }
body[data-game="flappy"]      { --accent: var(--accent-flappy); }
body[data-game="physics"]     { --accent: var(--accent-physics); }
.badge-new {
  display: inline-block;
  margin-left: 0.4rem;
  padding: 0.05rem 0.4rem;
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  background: #ff6fa3;
  color: #1a0510;
  border-radius: 999px;
  vertical-align: middle;
}

/* --- Game layout --- */
.game-layout {
  display: grid;
  gap: 1rem;
  grid-template-columns: 1fr;
}
@media (min-width: 800px) {
  /* Desktop: board column is a fixed size (so it doesn't stretch into a
     wide empty card after the ad-slot was removed in T-ADSENSE.A1), and the
     whole row is centered. .game-layout:has(.sidebar-col) gets the extra
     leaderboard column docked tight to the right of the board. */
  .game-layout {
    grid-template-columns: 480px;
    justify-content: center;
  }
  .game-layout:has(.sidebar-col) {
    grid-template-columns: 480px 240px;
  }
}

.game-area {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
}

.game-meta {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
  justify-content: center;
  font-size: 0.95rem;
  color: var(--fg-dim);
}
.game-meta strong { color: var(--fg); }

/* Right-column wrapper so the desktop ad-slot can sit ABOVE the sidebar
   without being wiped by Scores.renderScoreboard (which clears the aside). */
.sidebar-col {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  min-width: 0;
}
.sidebar {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  font-size: 0.95rem;
}
.sidebar h2 { margin-top: 0; }
.sidebar .empty { color: var(--fg-dim); font-style: italic; }

.scoreboard {
  list-style: none;
  padding: 0;
  margin: 0;
  counter-reset: rank;
}
.scoreboard li {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 0.4rem 0;
  border-bottom: 1px dashed var(--border);
  counter-increment: rank;
}
.scoreboard li::before {
  content: counter(rank) ".";
  color: var(--accent);
  margin-right: 0.5rem;
  font-weight: 700;
  min-width: 1.4em;
  display: inline-block;
}
.scoreboard li .name {
  flex: 0 0 auto;
  font-weight: 700;
  color: var(--fg);
  margin-right: 0.5rem;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  max-width: 7em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.scoreboard li .score { flex: 1; font-weight: 600; text-align: right; color: var(--accent); margin-right: 0.5rem; }
.scoreboard li .date { color: var(--fg-dim); font-size: 0.8rem; flex: 0 0 auto; }
.scoreboard li:last-child { border-bottom: none; }

/* Inline name-input prompt shown when a round ends with a top-5 score. */
.name-prompt {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  justify-content: center;
  margin: 0;
}
.name-prompt-label {
  flex: 0 0 100%;
  text-align: center;
  font-weight: 600;
  color: var(--good);
}
.name-prompt-input {
  flex: 1 1 8em;
  min-width: 6em;
  max-width: 12em;
  min-height: var(--tap);
  padding: 0 0.75rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--fg);
  font-size: 1rem;
  font-family: inherit;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.name-prompt-input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}
.name-prompt-btn { flex: 0 0 auto; }
.name-prompt-hint {
  margin: 0;
  font-size: 0.8rem;
  color: var(--fg-dim);
  text-align: center;
  flex: 0 0 100%;
}
.name-prompt-hint.error {
  color: var(--danger);
  font-weight: 600;
}
.name-prompt-saved {
  margin: 0;
  text-align: center;
  font-weight: 600;
  color: var(--good);
}
/* Eager-save confirmation with inline rename. */
.saved-with-edit {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  margin: 0;
  font-weight: 600;
  color: var(--good);
}
.saved-with-edit .saved-name {
  color: var(--fg);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.saved-with-edit .edit-btn {
  appearance: none;
  -webkit-appearance: none;
  background: transparent;
  border: none;
  color: var(--accent);
  font-weight: 600;
  font-size: 0.95rem;
  padding: 0.25rem 0.5rem;
  min-height: var(--tap);
  cursor: pointer;
  text-decoration: underline;
}
.saved-with-edit .edit-btn:hover { color: #8af0ff; }
.name-prompt-cancel {
  appearance: none;
  -webkit-appearance: none;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--fg-dim);
  font-weight: 600;
  min-height: var(--tap);
  padding: 0 0.75rem;
  border-radius: 8px;
  cursor: pointer;
}
.name-prompt-cancel:hover { color: var(--fg); }
.name-prompt-final {
  margin: 0;
  text-align: center;
  color: var(--fg-dim);
}

/* --- Buttons --- */
button, .btn {
  appearance: none;
  -webkit-appearance: none;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--fg);
  min-height: var(--tap);
  padding: 0 1rem;
  font-size: 1rem;
  border-radius: 8px;
  cursor: pointer;
  font-family: inherit;
  font-weight: 600;
  transition: background 0.1s ease, border-color 0.1s ease;
}
button:hover:not(:disabled), .btn:hover { background: #262a3a; }
button:active:not(:disabled) { transform: translateY(1px); }
button.primary, .btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #07212a;
}
button.primary:hover:not(:disabled) { background: #8af0ff; }
button:disabled { opacity: 0.5; cursor: not-allowed; }

.controls-row {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  justify-content: center;
}

/* --- Canvas --- */
canvas {
  display: block;
  background: #0a0c12;
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--accent) 30%, transparent);
  max-width: 100%;
  height: auto;
  touch-action: none;
}

/* --- D-pad for Snake on mobile --- */
.dpad {
  display: grid;
  grid-template-columns: repeat(3, var(--tap));
  grid-template-rows: repeat(3, var(--tap));
  gap: 6px;
  margin-top: 0.5rem;
  user-select: none;
}
.dpad button {
  min-height: 0;
  padding: 0;
  font-size: 1.4rem;
  background: var(--bg-card);
}
.dpad .up    { grid-column: 2; grid-row: 1; }
.dpad .left  { grid-column: 1; grid-row: 2; }
.dpad .right { grid-column: 3; grid-row: 2; }
.dpad .down  { grid-column: 2; grid-row: 3; }
@media (hover: hover) and (pointer: fine) {
  .dpad { display: none; }
}

/* --- Tic-Tac-Toe board --- */
.ttt-board {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  grid-template-rows: repeat(3, minmax(0, 1fr));
  gap: 6px;
  width: min(360px, 100%);
  aspect-ratio: 1 / 1;
}
.ttt-cell {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: clamp(2rem, 14vw, 3.5rem);
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
  padding: 0;
  color: var(--fg);
  cursor: pointer;
}
.ttt-cell[data-mark="X"] { color: var(--accent); }
.ttt-cell[data-mark="O"] { color: var(--accent-2); }
.ttt-cell.win { background: rgba(110, 231, 255, 0.18); border-color: var(--accent); }
.ttt-cell:disabled { cursor: default; }

/* --- Memory board --- */
.memory-board {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  width: min(420px, 100%);
}
.memory-card {
  aspect-ratio: 1 / 1;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: clamp(1.5rem, 8vw, 2.4rem);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-weight: 700;
  color: var(--fg);
  min-height: 0;
  padding: 0;
  transition: background 0.15s ease, transform 0.1s ease;
}
.memory-card[data-state="hidden"] { color: transparent; background: linear-gradient(135deg, #2a2f44, #1c1f2e); }
.memory-card[data-state="hidden"]::before {
  content: "?";
  color: var(--fg-dim);
  font-weight: 600;
}
.memory-card[data-state="revealed"] { background: var(--bg-card); }
.memory-card[data-state="matched"] {
  background: rgba(138, 255, 154, 0.15);
  border-color: var(--good);
  cursor: default;
}

/* --- Minesweeper --- */
.mine-board {
  display: grid;
  grid-template-columns: repeat(9, minmax(0, 1fr));
  grid-template-rows: repeat(9, minmax(0, 1fr));
  gap: 2px;
  width: min(360px, 100%);
  aspect-ratio: 1 / 1;
  background: var(--border);
  padding: 2px;
  border-radius: 6px;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}
.mine-cell {
  background: #2c3144;
  border: none;
  border-radius: 3px;
  font-size: clamp(0.9rem, 3.5vw, 1.1rem);
  font-weight: 800;
  color: var(--fg);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
  min-height: 0;
}
.mine-cell.revealed { background: #181b27; }
.mine-cell.flagged { color: var(--accent-2); }
.mine-cell.mine.revealed { background: var(--danger); color: #1a0007; }
.mine-cell[data-count="1"] { color: #6ee7ff; }
.mine-cell[data-count="2"] { color: #8aff9a; }
.mine-cell[data-count="3"] { color: #ffb86b; }
.mine-cell[data-count="4"] { color: #c98aff; }
.mine-cell[data-count="5"] { color: #ff8a8a; }
.mine-cell[data-count="6"] { color: #6effe7; }
.mine-cell[data-count="7"] { color: #eaeaea; }
.mine-cell[data-count="8"] { color: #ffffff; }

.status-banner {
  min-height: 1.5em;
  text-align: center;
  font-weight: 600;
  margin: 0;
}
.status-banner.win { color: var(--good); }
.status-banner.lose { color: var(--danger); }

/* --- Policy / About / Contact pages: plain flowing text, no card --- */
.policy-content {
  max-width: 780px;
  margin: 0 auto;
}
.policy-content h2 { margin-top: 1.5rem; }
.policy-content h2:first-child { margin-top: 0; }
.about-games {
  list-style: none;
  padding: 0;
  margin: 0;
}
.about-games li {
  padding: 0.6rem 0;
  border-bottom: 1px dashed var(--border);
}
.about-games li:last-child { border-bottom: none; }
.about-games li a { font-weight: 700; margin-right: 0.4em; }

footer {
  padding: 1rem;
  text-align: center;
  color: var(--fg-dim);
  font-size: 0.85rem;
  border-top: 1px solid var(--border);
}
footer a { margin: 0 0.5em; }

/* --- AdSense placeholder slots ---
   The dashed-border placeholder is visible until a real publisher id and slot
   id are wired into the <ins class="adsbygoogle"> tags (see HTML markers
   "adsense:start" / "adsense:end"). */
.ad-slot {
  display: block;
  margin: 1rem auto;
  min-height: 100px;
  background: rgba(255, 255, 255, 0.02);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  color: var(--fg-dim);
  font-size: 0.85rem;
  text-align: center;
  padding: 1rem;
  max-width: 100%;
}
.ad-slot--desktop { display: none; }
.ad-slot--mobile { display: block; }
@media (min-width: 800px) {
  .ad-slot--desktop { display: block; }
  .ad-slot--mobile { display: none; }
}

/* --- Footer nav (Privacy / Terms / Contact / About) --- */
.footer-nav {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.5rem 1rem;
  padding-bottom: 0.4rem;
}
.footer-nav a {
  color: var(--fg-dim);
  font-size: 0.9rem;
  margin: 0;
}
.footer-credit { margin: 0.4rem 0 0; color: var(--fg-dim); font-size: 0.85rem; }

/* --- How-to-play sections on game pages --- */
.howto {
  max-width: 720px;
  margin: 2rem auto 0;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem 1.25rem 1rem;
}
.howto h2 { margin-top: 0; font-size: 1.15rem; }
.howto h3 { font-size: 1rem; margin-bottom: 0.3rem; color: var(--fg); }
.howto p { color: var(--fg-dim); }
.howto ul { color: var(--fg-dim); padding-left: 1.2rem; }
.howto li { margin: 0.2rem 0; }

/* --- Result panel: hidden until the round ends --- */
/* Bottom margin ≥ 50px keeps the ad-slot inside the panel comfortably away
   from any game controls (Start/Restart, dpad) that follow in the DOM. */
.result-panel {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin-top: 1rem;
  margin-bottom: 3.5rem;
  padding: 1rem;
  background: rgba(255,255,255,0.02);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.result-panel[hidden] { display: none !important; }
.result-panel .ad-slot {
  margin: 0.4rem 0 0;
  min-height: 90px;
}
/* In the result panel the ad shows on every viewport (single slot per page). */
.result-panel .ad-slot--desktop,
.result-panel .ad-slot--mobile { display: block !important; }

/* --- Cookie banner --- */
#cookieBanner {
  position: fixed;
  left: 50%;
  bottom: 1rem;
  transform: translateX(-50%);
  width: min(560px, calc(100% - 2rem));
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(0,0,0,0.45);
  padding: 0.85rem 1rem;
  display: flex;
  gap: 0.75rem;
  align-items: center;
  z-index: 9999;
  font-size: 0.9rem;
}
#cookieBanner p { margin: 0; color: var(--fg); flex: 1; }
#cookieBanner a { color: var(--accent, #6ee7ff); }
#cookieBanner button { flex-shrink: 0; padding: 0.55rem 1rem; }
@media (max-width: 480px) {
  #cookieBanner { flex-direction: column; align-items: stretch; text-align: center; }
}

/* Reduce motion for users that prefer it */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    transition-duration: 0.001ms !important;
  }
}
