:root,
[data-theme="dark"] {
  --bg: #0e0f12;
  --surface: rgba(255, 255, 255, 0.028);
  --surface-hover: rgba(255, 255, 255, 0.05);
  --border: rgba(255, 255, 255, 0.08);
  --border-strong: rgba(255, 255, 255, 0.16);
  --text: #e7e9ee;
  --muted: #8a909c;
  --accent: #6ee7a8;
  --accent-ink: #06231a;
  --canvas-bg: #0a0b0e;
  --game-bg: #0e0f12;
  --game-board-surface: #12151b;
  --game-board-stroke: rgba(255, 255, 255, 0.06);
  --game-grid: rgba(138, 144, 156, 0.1);
  --game-grid-line: rgba(255, 255, 255, 0.09);
  --game-ghost-alpha: 0.16;
  --game-preview-frame: #101218;
  --game-preview-surface: #0a0b0e;
  --game-panel: #14161b;
  --preview-bg: #12141a;
  --tile-bg: #16181d;
  --panel-solid: #14161b;
  --overlay-scrim: rgba(12, 13, 16, 0.82);
  --overlay-scrim-strong: rgba(14, 15, 18, 0.86);
  --overlay-scrim-soft: rgba(12, 13, 16, 0.78);
  --modal-scrim: rgba(8, 9, 12, 0.78);
  --elevated: rgba(255, 255, 255, 0.03);
  --elevated-hover: rgba(255, 255, 255, 0.07);
  --elevated-strong: rgba(255, 255, 255, 0.09);
  --shadow-soft: rgba(0, 0, 0, 0.42);
  --shadow-strong: rgba(0, 0, 0, 0.5);
  --title-gradient: linear-gradient(120deg, #6ee7a8 0%, #8ef0c0 38%, #7cc4ff 100%);
  --link-accent: #b8f5d4;
}

[data-theme="light"] {
  --bg: #f3f4f8;
  --surface: rgba(0, 0, 0, 0.03);
  --surface-hover: rgba(0, 0, 0, 0.055);
  --border: rgba(0, 0, 0, 0.1);
  --border-strong: rgba(0, 0, 0, 0.18);
  --text: #1b1f27;
  --muted: #5d6572;
  --accent: #18a566;
  --accent-ink: #ffffff;
  --canvas-bg: #e7e9f0;
  --game-bg: #f3f4f8;
  --game-board-surface: #dce1ea;
  --game-board-stroke: rgba(0, 0, 0, 0.08);
  --game-grid: rgba(0, 0, 0, 0.1);
  --game-grid-line: rgba(0, 0, 0, 0.06);
  --game-ghost-alpha: 0.28;
  --game-preview-frame: #d8dde8;
  --game-preview-surface: #e2e6ef;
  --game-panel: #eef1f6;
  --preview-bg: #e2e6ef;
  --tile-bg: #ffffff;
  --panel-solid: #ffffff;
  --overlay-scrim: rgba(243, 244, 248, 0.84);
  --overlay-scrim-strong: rgba(243, 244, 248, 0.9);
  --overlay-scrim-soft: rgba(243, 244, 248, 0.78);
  --modal-scrim: rgba(243, 244, 248, 0.82);
  --elevated: rgba(0, 0, 0, 0.04);
  --elevated-hover: rgba(0, 0, 0, 0.07);
  --elevated-strong: rgba(0, 0, 0, 0.08);
  --shadow-soft: rgba(15, 23, 42, 0.12);
  --shadow-strong: rgba(15, 23, 42, 0.16);
  --title-gradient: linear-gradient(120deg, #18a566 0%, #2fbf7f 38%, #3d8fe0 100%);
  --link-accent: #18a566;
}

html {
  color-scheme: dark;
}

[data-theme="light"] {
  color-scheme: light;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

body {
  -webkit-user-select: none;
  -moz-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

html, body {
  min-height: 100%;
  background-color: var(--bg);
  color: var(--text);
}

html:has(body.hub-body) {
  overflow: hidden;
  height: 100%;
}

body {
  font-family: "Inter", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  -webkit-font-smoothing: antialiased;
}

/* ---------- Arcade Hub (PS-style carousel) ---------- */
.hub-body {
  position: fixed;
  inset: 0;
  flex-direction: column;
  overflow: hidden;
  overscroll-behavior: none;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100dvh;
  max-height: 100dvh;
  padding:
    clamp(20px, 3.5vh, 48px)
    clamp(16px, 4vw, 40px)
    clamp(52px, 6vh, 72px);
  scrollbar-width: none;
}

.hub-body::-webkit-scrollbar {
  display: none;
}

.hub {
  width: min(1120px, 100%);
  height: 100%;
  max-height: 100%;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: clamp(20px, 3vh, 40px);
  min-height: 0;
  overflow: hidden;
}

.hub-header {
  text-align: center;
  max-width: 580px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: clamp(8px, 1.4vh, 12px);
  flex-shrink: 0;
}

.hub-title {
  font-weight: 700;
  font-size: clamp(30px, 5.5vw, 44px);
  letter-spacing: -0.5px;
  line-height: 1.1;
  background: var(--title-gradient);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.hub-sub {
  color: var(--muted);
  margin: 0;
  font-size: 14px;
  line-height: 1.55;
  max-width: 560px;
}

.hub-note {
  color: var(--muted);
  margin: 0;
  font-size: 12px;
  line-height: 1.5;
  max-width: 560px;
  opacity: 0.78;
}

.hub-footer {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 5;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding:
    16px clamp(16px, 4vw, 40px)
    max(14px, env(safe-area-inset-bottom));
  text-align: center;
  background: linear-gradient(to top, rgba(14, 15, 18, 0.94) 35%, rgba(14, 15, 18, 0));
  pointer-events: none;
}

.hub-footer-line {
  margin: 0;
  font-size: 11px;
  line-height: 1.45;
  color: var(--muted);
  opacity: 0.72;
}

.hub-footer-project {
  pointer-events: auto;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin: 2px 0 1px;
  padding: 7px 16px;
  border-radius: 999px;
  border: 1px solid rgba(110, 231, 168, 0.38);
  background: rgba(110, 231, 168, 0.1);
  color: var(--link-accent);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-decoration: none;
  box-shadow: 0 0 20px rgba(110, 231, 168, 0.12);
  transition: color 0.15s ease, border-color 0.15s ease, background 0.15s ease, box-shadow 0.15s ease;
}

.hub-footer-project:hover {
  color: var(--accent-ink);
  background: var(--accent);
  border-color: var(--accent);
  box-shadow: 0 0 24px rgba(110, 231, 168, 0.28);
}

.hub-footer-license {
  font-size: 10.5px;
  opacity: 0.62;
}

.hub-footer-license a {
  pointer-events: auto;
  color: inherit;
  text-decoration: none;
  border-bottom: 1px solid rgba(138, 144, 156, 0.28);
  transition: color 0.15s ease, border-color 0.15s ease;
}

.hub-footer-license a:hover {
  color: var(--accent);
  border-color: rgba(110, 231, 168, 0.45);
}

.hub-footer-dot {
  margin: 0 5px;
  opacity: 0.55;
}

.hub-stage {
  display: grid;
  grid-template-columns: minmax(0, 1.08fr) minmax(0, 0.92fr);
  gap: clamp(20px, 4vw, 48px);
  align-items: center;
  width: 100%;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.hub-preview {
  display: flex;
  justify-content: center;
  min-height: 0;
  overflow: hidden;
}

.preview-frame {
  width: 100%;
  max-width: 440px;
  max-height: 100%;
  display: flex;
  flex-direction: column;
  gap: clamp(10px, 1.4vh, 14px);
  transition: opacity 0.28s ease, transform 0.28s ease;
  min-height: 0;
  overflow: visible;
}

.preview-frame.is-switching {
  opacity: 0.72;
  transform: translateY(4px);
}

.preview-meta {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.preview-tag {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--accent);
}

.preview-name {
  font-size: clamp(28px, 4vw, 38px);
  font-weight: 700;
  letter-spacing: -0.6px;
  line-height: 1.1;
}

.preview-screen {
  position: relative;
  width: min(100%, 440px, calc(100dvh - 320px));
  aspect-ratio: 1;
  flex-shrink: 1;
  min-height: 0;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: var(--preview-bg);
  overflow: hidden;
  box-shadow: 0 24px 56px var(--shadow-soft);
}

.preview-screen::before {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at 50% 28%, var(--preview-tint, transparent) 0%, transparent 68%);
  opacity: 0.5;
  pointer-events: none;
  animation: preview-glow 5s ease-in-out infinite;
}

@keyframes preview-glow {
  0%, 100% { opacity: 0.42; }
  50% { opacity: 0.58; }
}

#preview-canvas {
  position: relative;
  z-index: 1;
  width: 100%;
  height: 100%;
  display: block;
}

.preview-desc {
  color: var(--muted);
  font-size: 15px;
  line-height: 1.5;
  max-width: 38ch;
}

.hub-preview .play-btn {
  align-self: flex-start;
  margin: 12px 0;
}

.hub-picker {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 0;
  overflow: hidden;
  touch-action: none;
}

.picker-label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.carousel {
  position: relative;
  width: 100%;
  max-width: 420px;
  height: 280px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.deck {
  position: relative;
  width: 200px;
  height: 200px;
  transform-style: preserve-3d;
}

.tile {
  position: absolute;
  top: 0;
  left: 0;
  width: 200px;
  height: 200px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: var(--tile-bg);
  box-shadow: 0 18px 40px var(--shadow-soft);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  overflow: hidden;
  transition: transform 0.38s cubic-bezier(0.22, 0.61, 0.36, 1), opacity 0.38s ease, border-color 0.25s ease;
  will-change: transform, opacity;
  -webkit-tap-highlight-color: transparent;
}

.tile::before {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at 50% 32%, var(--tile-tint, transparent) 0%, transparent 62%);
  opacity: 0.5;
}

.tile .tile-icon {
  font-size: 68px;
  line-height: 1;
  position: relative;
  filter: grayscale(0.15);
}

.tile .tile-label {
  position: relative;
  font-weight: 600;
  font-size: 15px;
  color: var(--text);
  opacity: 0;
  transition: opacity 0.3s ease;
}

.tile.active {
  border-color: var(--border-strong);
}

.tile.active .tile-label { opacity: 1; }

.nav-arrow {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  z-index: 20;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: rgba(20, 22, 26, 0.82);
  color: var(--text);
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding-bottom: 3px;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.nav-arrow:hover { background: rgba(40, 44, 52, 0.9); border-color: var(--border-strong); }
.nav-prev { left: 0; }
.nav-next { right: 0; }

.play-btn {
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 13px 40px;
  font-size: 15px;
  border-radius: 999px;
  letter-spacing: 0.3px;
  box-shadow: 0 0 24px rgba(110, 231, 168, 0.28);
}

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

@media (max-width: 900px) {
  .hub-body {
    padding:
      clamp(16px, 3vh, 32px)
      clamp(14px, 4vw, 24px)
      clamp(48px, 7vh, 64px);
  }

  .hub {
    gap: clamp(14px, 2.5vh, 24px);
  }

  .hub-stage {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(0, 1fr) auto;
    gap: clamp(16px, 2.5vh, 24px);
  }

  .hub-preview { order: -1; }

  .preview-frame {
    max-width: min(440px, 100%);
    margin: 0 auto;
  }

  .preview-screen {
    width: min(72vw, calc(100dvh - 380px), 340px);
  }

  .hub-preview .play-btn { align-self: center; }

  .preview-desc { text-align: center; max-width: none; }

  .preview-meta { text-align: center; align-items: center; }
}

@media (max-height: 760px) {
  .hub-note {
    display: none;
  }

  .hub-sub {
    font-size: 13px;
    line-height: 1.45;
  }
}

@media (max-width: 520px) {
  .deck, .tile { width: 176px; height: 176px; }
  .tile .tile-icon { font-size: 58px; }
  .carousel { height: 240px; max-width: 100%; }
  .nav-prev { left: 4px; }
  .nav-next { right: 4px; }
}

/* ---------- Game Shell ---------- */
.game-shell {
  position: relative;
  width: min(92vw, 500px);
  padding: 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.back-link {
  text-decoration: none;
  color: var(--muted);
  font-size: 18px;
  width: 36px;
  height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
  border: 1px solid var(--border);
  transition: color 0.15s ease, border-color 0.15s ease;
  flex-shrink: 0;
}

.back-link:hover { color: var(--text); border-color: var(--border-strong); }

.logo {
  font-weight: 600;
  font-size: 17px;
  letter-spacing: 0.5px;
  color: var(--text);
  flex: 1;
}

.scores { display: flex; gap: 8px; }

.score-box {
  min-width: 68px;
  padding: 7px 12px;
  border-radius: 10px;
  background: var(--elevated);
  border: 1px solid var(--border);
  text-align: center;
}

.score-label {
  display: block;
  font-size: 10px;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  color: var(--muted);
}

.score-value { font-size: 20px; font-weight: 600; }

.canvas-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid var(--border);
  background: var(--canvas-bg);
}

.junction-shell {
  width: min(96vw, 750px);
}

.junction-shell .canvas-wrap {
  aspect-ratio: 3 / 2;
}

canvas { width: 100%; height: 100%; display: block; }

.tetris-shell {
  background: var(--bg);
}

.tetris-shell .canvas-wrap {
  background: var(--bg);
}

.tetris-shell .overlay,
.tetris-shell .game-pause-overlay {
  background: var(--overlay-scrim-strong);
}

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--overlay-scrim);
  transition: opacity 0.2s ease;
}

.overlay.hidden { opacity: 0; pointer-events: none; }

.game-pause-overlay {
  position: absolute;
  inset: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--overlay-scrim-soft);
  border-radius: 12px;
  transition: opacity 0.15s ease;
}

.game-pause-overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

.game-pause-card {
  text-align: center;
  padding: 20px 28px;
}

.game-pause-card h2 {
  font-size: 24px;
  font-weight: 700;
  margin-bottom: 8px;
}

.game-pause-card p {
  color: var(--muted);
  font-size: 14px;
}

.overlay-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 24px;
  max-width: 340px;
}

.overlay-card h2 {
  font-size: 27px;
  font-weight: 700;
  letter-spacing: -0.5px;
  margin-bottom: 6px;
}

.overlay-card p {
  color: var(--muted);
  margin-bottom: 24px;
  font-size: 13.5px;
  line-height: 1.55;
  max-width: 250px;
}

.btn {
  border: none;
  cursor: pointer;
  padding: 10px 24px;
  border-radius: 10px;
  font-family: inherit;
  font-weight: 600;
  font-size: 14px;
  color: var(--accent-ink);
  background: var(--accent);
  transition: filter 0.15s ease, transform 0.1s ease;
}

.btn:hover { filter: brightness(1.08); }
.btn:active { transform: scale(0.98); }

/* Circular play/icon button for the idle overlay */
.play-icon-btn {
  width: 74px;
  height: 74px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  background: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 12px 32px rgba(110, 231, 168, 0.32);
  transition: transform 0.16s ease, box-shadow 0.16s ease, filter 0.16s ease;
}

.play-icon-btn::before {
  content: "";
  width: 0;
  height: 0;
  border-style: solid;
  border-width: 13px 0 13px 21px;
  border-color: transparent transparent transparent var(--accent-ink);
  margin-left: 5px;
}

.play-icon-btn:hover {
  transform: scale(1.06);
  filter: brightness(1.05);
  box-shadow: 0 16px 40px rgba(110, 231, 168, 0.45);
}

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

.hint {
  margin-top: 26px;
  font-size: 12px;
  color: var(--muted);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 7px;
}

.hint span { opacity: 0.85; }

kbd {
  background: var(--elevated-strong);
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  padding: 3px 8px;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--text);
  font-family: inherit;
}

/* ---------- Touch controls ---------- */
.controls { display: none; flex-direction: column; align-items: center; gap: 8px; }
.pad-row { display: flex; gap: 8px; }

.pad {
  width: 54px;
  height: 54px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--elevated);
  color: var(--text);
  font-size: 18px;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.1s ease;
}

.pad:active { background: rgba(255, 255, 255, 0.1); transform: scale(0.94); }

@media (hover: none) and (pointer: coarse) {
  .controls { display: flex; }
}

/* ---------- 2048 ---------- */
.grid2048 {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
  background: var(--elevated);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 9px;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(4, 1fr);
  gap: 9px;
}

.cell2048 {
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.025);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: clamp(18px, 6vw, 32px);
}

.t2 { background: #2a2d34; color: #e7e9ee; }
.t4 { background: #34383f; color: #e7e9ee; }
.t8 { background: #3d5a49; color: #e7e9ee; }
.t16 { background: #46705a; color: #eafff3; }
.t32 { background: #4f8f6c; color: #eafff3; }
.t64 { background: #57b07d; color: #06231a; }
.t128 { background: #6ee7a8; color: #06231a; }
.t256 { background: #7ff0b6; color: #06231a; }
.t512 { background: #91f5c4; color: #06231a; }
.t1024 { background: #a7f9d2; color: #06231a; font-size: clamp(15px, 5vw, 26px); }
.t2048 { background: #c2ffe2; color: #06231a; font-size: clamp(15px, 5vw, 26px); }

/* ---------- Memory ---------- */
.memory-grid {
  display: grid;
  gap: 10px;
  width: 100%;
}

.memory-grid.size-sm { grid-template-columns: repeat(4, 1fr); }
.memory-grid.size-md { grid-template-columns: repeat(6, 1fr); gap: 8px; }
.memory-grid.size-lg { grid-template-columns: repeat(7, 1fr); gap: 7px; }

.mem-card.size-md { font-size: clamp(18px, 5vw, 30px); border-radius: 10px; }
.mem-card.size-lg { font-size: clamp(15px, 4vw, 24px); border-radius: 8px; }

.mem-card {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
  border-radius: 11px;
  cursor: pointer;
  font-size: clamp(24px, 8vw, 38px);
  background: rgba(255, 255, 255, 0.055);
  border: 1px solid var(--border);
  user-select: none;
  overflow: hidden;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.mem-card:hover:not(.flipped):not(.matched) {
  background: var(--elevated-strong);
  border-color: var(--border-strong);
}

/* Both layers stacked in the center of the card */
.mem-symbol,
.mem-emoji {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Default cover symbol */
.mem-symbol {
  color: rgba(110, 231, 168, 0.4);
  font-size: 0.72em;
  font-weight: 700;
  opacity: 1;
}

/* Emoji is hidden until the card is flipped */
.mem-emoji {
  opacity: 0;
}

.mem-card.flipped .mem-symbol,
.mem-card.matched .mem-symbol {
  opacity: 0;
}

.mem-card.flipped .mem-emoji,
.mem-card.matched .mem-emoji {
  opacity: 1;
}

.mem-card.matched {
  cursor: default;
  background: rgba(110, 231, 168, 0.12);
  border-color: rgba(110, 231, 168, 0.4);
}

/* Flip animation: the card briefly collapses on its Y axis, hiding the
   content while it swaps, then expands again */
.mem-card.anim {
  animation: mem-flip 0.4s ease;
}

@keyframes mem-flip {
  0% { transform: scaleX(1); }
  50% { transform: scaleX(0.05); }
  100% { transform: scaleX(1); }
}

@media (prefers-reduced-motion: reduce) {
  .mem-card.anim {
    animation: none;
  }
}

/* ---------- Tic-Tac-Toe ---------- */
.mode-switch {
  display: flex;
  gap: 4px;
  padding: 4px;
  background: var(--elevated);
  border: 1px solid var(--border);
  border-radius: 12px;
  align-self: center;
}

.mode-btn {
  border: none;
  cursor: pointer;
  padding: 8px 18px;
  border-radius: 9px;
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  color: var(--muted);
  background: transparent;
  transition: color 0.15s ease, background 0.15s ease;
}

.mode-btn.active {
  color: var(--text);
  background: var(--elevated-hover);
}

.diff-btn {
  border: none;
  cursor: pointer;
  padding: 8px 18px;
  border-radius: 9px;
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  color: var(--muted);
  background: transparent;
  transition: color 0.15s ease, background 0.15s ease;
}

.diff-btn.active {
  color: var(--text);
  background: rgba(124, 196, 255, 0.14);
}

.mode-switch.hidden {
  display: none;
}

.mode-switch-wrap {
  flex-wrap: wrap;
  justify-content: center;
  max-width: min(100%, 400px);
}

.mode-switch-wrap .mode-btn {
  padding: 8px 14px;
  font-size: 12px;
}

.ttt-grid {
  position: relative;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  gap: 8px;
  width: 100%;
  aspect-ratio: 1 / 1;
}

.ttt-win-line {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 3;
  opacity: 0;
  transition: opacity 0.2s ease;
}

.ttt-win-line.visible {
  opacity: 1;
}

.ttt-win-line-stroke {
  stroke: rgba(255, 255, 255, 0.68);
  stroke-width: 3.5;
  stroke-linecap: round;
}

.ttt-cell {
  border-radius: 12px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.025);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  min-width: 0;
  min-height: 0;
  aspect-ratio: 1 / 1;
  font-size: clamp(2.75rem, 14vw, 4.25rem);
  font-weight: 700;
  line-height: 1;
  transition: background 0.15s ease;
}

.ttt-cell.x {
  color: #6ee7a8;
  text-shadow: 0 0 6px rgba(110, 231, 168, 0.1);
}

.ttt-cell.o {
  color: #7cc4ff;
  text-shadow: 0 0 6px rgba(124, 196, 255, 0.1);
}

.ttt-cell:hover { background: rgba(255, 255, 255, 0.055); }

.ttt-grid.game-over .ttt-cell.dim {
  opacity: 0.2;
}

.ttt-cell.win {
  opacity: 1;
  border-width: 2px;
  background: rgba(255, 255, 255, 0.035);
  transition: opacity 0.25s ease, border-color 0.25s ease, box-shadow 0.25s ease;
}

.ttt-cell.win-x {
  border-color: rgba(110, 231, 168, 0.42);
  box-shadow: 0 0 10px rgba(110, 231, 168, 0.06);
}

.ttt-cell.win-o {
  border-color: rgba(124, 196, 255, 0.42);
  box-shadow: 0 0 10px rgba(124, 196, 255, 0.06);
}

.ttt-cell.win-x.x {
  text-shadow: 0 0 10px rgba(110, 231, 168, 0.18);
}

.ttt-cell.win-o.o {
  text-shadow: 0 0 10px rgba(124, 196, 255, 0.18);
}

.c4-board {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  grid-template-rows: repeat(6, 1fr);
  gap: clamp(6px, 1.4vw, 9px);
  width: 100%;
  max-width: 420px;
  aspect-ratio: 7 / 6;
  padding: clamp(10px, 2vw, 14px);
  background: linear-gradient(180deg, #2457b8 0%, #1a4190 100%);
  border: 1px solid rgba(124, 196, 255, 0.22);
  border-radius: 16px;
  box-shadow: 0 16px 36px rgba(0, 0, 0, 0.35);
  align-self: center;
}

.c4-cell {
  width: 100%;
  aspect-ratio: 1;
  border: none;
  border-radius: 50%;
  background: #101218;
  cursor: pointer;
  padding: 0;
  transition: transform 0.16s ease, box-shadow 0.16s ease, filter 0.16s ease;
}

.c4-cell:hover:not(:disabled):not(.red):not(.blue) {
  background: #1a2030;
}

.c4-cell.red {
  background: radial-gradient(circle at 35% 30%, #ff7a7a 0%, #ef4444 55%, #c93434 100%);
  box-shadow: inset 0 -4px 0 rgba(0, 0, 0, 0.22);
}

.c4-cell.blue {
  background: radial-gradient(circle at 35% 30%, #7ab4ff 0%, #3b82f6 55%, #2563c7 100%);
  box-shadow: inset 0 -4px 0 rgba(0, 0, 0, 0.22);
}

.c4-cell.drop {
  animation: c4-drop 0.24s ease-out;
}

@keyframes c4-drop {
  from { transform: translateY(-18%); }
  to { transform: translateY(0); }
}

.c4-board.game-over .c4-cell.dim {
  opacity: 0.34;
  filter: saturate(0.45);
}

.c4-cell.win {
  transform: scale(1.05);
}

.c4-cell.win-red {
  box-shadow: 0 0 18px rgba(239, 68, 68, 0.55), inset 0 -4px 0 rgba(0, 0, 0, 0.18);
}

.c4-cell.win-blue {
  box-shadow: 0 0 18px rgba(59, 130, 246, 0.55), inset 0 -4px 0 rgba(0, 0, 0, 0.18);
}

.ms-wrap {
  position: relative;
  width: 100%;
  align-self: center;
}

.ms-grid {
  display: grid;
  gap: 3px;
  padding: 10px;
  background: var(--elevated);
  border: 1px solid var(--border);
  border-radius: 14px;
  margin-inline: auto;
  box-sizing: border-box;
}

.ms-grid.level-easy { width: 360px; max-width: 100%; }
.ms-grid.level-medium { width: 420px; max-width: 100%; }
.ms-grid.level-hard { width: 480px; max-width: 100%; }
.ms-grid.level-ultra { width: 520px; max-width: 100%; }
.ms-grid.level-extreme { width: 560px; max-width: 100%; }

.ms-grid.level-ultra .ms-cell,
.ms-grid.level-extreme .ms-cell {
  font-size: clamp(10px, 1.8vw, 13px);
  border-radius: 5px;
}

.ms-cell {
  aspect-ratio: 1;
  min-width: 0;
  border: none;
  border-radius: 6px;
  background: var(--elevated-hover);
  color: var(--text);
  font-family: inherit;
  font-size: clamp(11px, 2.2vw, 15px);
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  padding: 0;
  transition: background 0.12s ease, transform 0.1s ease;
}

.ms-cell:hover:not(.revealed):not(.flagged) {
  background: rgba(110, 231, 168, 0.14);
}

.ms-cell.flagged {
  color: #ff8f8f;
  font-size: clamp(12px, 2.4vw, 16px);
}

.ms-cell.revealed {
  background: var(--elevated);
  cursor: default;
}

.ms-cell.mine {
  background: rgba(255, 95, 95, 0.18);
}

.ms-cell.mine.exploded {
  background: rgba(255, 70, 70, 0.42);
  box-shadow: 0 0 16px rgba(255, 80, 80, 0.45);
}

.status-line.hidden {
  display: none;
}

.status-line {
  text-align: center;
  font-size: 15px;
  font-weight: 500;
  min-height: 22px;
  color: var(--muted);
}

/* ---------- Reset highscore (subtle glass button) ---------- */
.reset-hs {
  align-self: center;
  margin-top: 2px;
  font-family: inherit;
  font-size: 11.5px;
  letter-spacing: 0.2px;
  color: var(--muted);
  background: var(--elevated);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 7px 15px;
  cursor: pointer;
  backdrop-filter: blur(6px);
  opacity: 0.6;
  transition: opacity 0.15s ease, color 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}

.reset-hs:hover {
  opacity: 1;
  color: var(--text);
  border-color: var(--border-strong);
  background: rgba(255, 255, 255, 0.06);
}

.reset-hs.done { color: var(--accent); border-color: rgba(110, 231, 168, 0.4); }

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.theme-toggle {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--elevated);
  color: var(--muted);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: color 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}

.theme-toggle:hover {
  color: var(--text);
  border-color: var(--border-strong);
  background: var(--elevated-hover);
}

.theme-toggle .theme-icon {
  width: 18px;
  height: 18px;
  display: none;
}

.theme-toggle[data-mode="dark"] .icon-sun { display: block; }
.theme-toggle[data-mode="light"] .icon-moon { display: block; }

.theme-toggle-hub,
.settings-btn {
  position: fixed;
  top: 20px;
  z-index: 50;
}

.theme-toggle-hub {
  right: 72px;
  width: 42px;
  height: 42px;
  border-radius: 12px;
}

.theme-toggle-hub.theme-toggle-blocked,
.theme-toggle-hub:disabled {
  cursor: not-allowed;
  opacity: 0.72;
  border-color: rgba(239, 95, 95, 0.42);
  background: rgba(239, 95, 95, 0.1);
  color: rgba(240, 130, 130, 0.82);
}

.theme-toggle-hub.theme-toggle-blocked:hover,
.theme-toggle-hub:disabled:hover {
  color: rgba(240, 130, 130, 0.82);
  border-color: rgba(239, 95, 95, 0.42);
  background: rgba(239, 95, 95, 0.1);
}

.theme-toggle-hub.theme-toggle-blocked::after,
.theme-toggle-hub:disabled::after {
  content: "";
  position: absolute;
  inset: 9px;
  border-radius: 6px;
  background: linear-gradient(
    to top right,
    transparent calc(50% - 1px),
    rgba(239, 95, 95, 0.88) calc(50% - 1px),
    rgba(239, 95, 95, 0.88) calc(50% + 1px),
    transparent calc(50% + 1px)
  );
  pointer-events: none;
}

/* ---------- Hub settings ---------- */
.settings-btn {
  right: 20px;
  width: 42px;
  height: 42px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--elevated);
  color: var(--muted);
  font-size: 20px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}

.settings-btn:hover {
  color: var(--text);
  border-color: var(--border-strong);
  background: var(--elevated-hover);
}

.settings-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: var(--modal-scrim);
  backdrop-filter: blur(8px);
  transition: opacity 0.2s ease;
}

.settings-overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

.settings-panel {
  width: min(92vw, 420px);
  max-height: min(80vh, 520px);
  overflow: auto;
  overscroll-behavior: contain;
  padding: 22px;
  border-radius: 16px;
  border: 1px solid var(--border);
  background: var(--panel-solid);
  box-shadow: 0 24px 60px var(--shadow-strong);
}

.settings-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}

.settings-head h2 {
  font-size: 20px;
  font-weight: 600;
}

.settings-close {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--elevated);
  color: var(--muted);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding-bottom: 2px;
}

.settings-close:hover { color: var(--text); border-color: var(--border-strong); }

.settings-sub {
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 18px;
}

.settings-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.025);
}

.settings-row-name {
  font-size: 14px;
  font-weight: 500;
}

.settings-reset {
  border: 1px solid var(--border);
  background: var(--elevated);
  color: var(--muted);
  font-family: inherit;
  font-size: 12px;
  font-weight: 500;
  padding: 7px 12px;
  border-radius: 8px;
  cursor: pointer;
  white-space: nowrap;
  transition: color 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}

.settings-reset:hover {
  color: var(--text);
  border-color: var(--border-strong);
  background: var(--elevated-hover);
}

.settings-reset.done {
  color: var(--accent);
  border-color: rgba(110, 231, 168, 0.4);
}

.settings-section {
  margin-top: 20px;
  padding-top: 18px;
  border-top: 1px solid var(--border);
}

.settings-section-title {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 14px;
  color: var(--text);
}

.settings-colors {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.settings-color-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.025);
}

.settings-color-row label {
  font-size: 13px;
  color: var(--muted);
}

.settings-color-input {
  width: 46px;
  height: 34px;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  padding: 3px;
  background: var(--elevated);
  cursor: pointer;
}

.settings-color-input::-webkit-color-swatch-wrapper { padding: 0; }
.settings-color-input::-webkit-color-swatch { border: none; border-radius: 5px; }
.settings-color-input::-moz-color-swatch { border: none; border-radius: 5px; }

/* ---------- Blade Rush ---------- */
.br-flash {
  position: absolute;
  inset: 0;
  border-radius: 12px;
  background: radial-gradient(circle, rgba(110, 231, 168, 0.5) 0%, transparent 70%);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.08s ease;
}
