:root,
[data-theme="light"] {
  --font-display: 'Instrument Serif', Georgia, serif;
  --font-body: 'Manrope', 'Segoe UI', sans-serif;
  --text-xs: clamp(0.75rem, 0.7rem + 0.25vw, 0.875rem);
  --text-sm: clamp(0.875rem, 0.8rem + 0.35vw, 1rem);
  --text-base: clamp(1rem, 0.95rem + 0.25vw, 1.125rem);
  --text-lg: clamp(1.125rem, 1rem + 0.75vw, 1.5rem);
  --text-xl: clamp(1.5rem, 1.2rem + 1.25vw, 2.25rem);
  --text-2xl: clamp(2rem, 1.2rem + 2.5vw, 3.5rem);
  --color-surface: rgba(255,255,255,0.74);
  --color-surface-strong: rgba(255,255,255,0.9);
  --color-border: rgba(40,37,29,0.12);
  --color-text: #221f1a;
  --color-text-muted: #6f6a61;
  --color-primary: #0d6b6f;
  --color-accent: #d78632;
  --shadow-lg: 0 24px 60px rgba(29,21,12,0.14);
  --shadow-md: 0 14px 36px rgba(29,21,12,0.1);
  --gradient-bg: radial-gradient(circle at top left, rgba(215,134,50,0.18), transparent 28%), radial-gradient(circle at right, rgba(13,107,111,0.18), transparent 28%), linear-gradient(180deg, #f8f5ef 0%, #efe9df 100%);
}
[data-theme="dark"] {
  --color-surface: rgba(20,22,28,0.76);
  --color-surface-strong: rgba(28,31,36,0.95);
  --color-border: rgba(255,255,255,0.11);
  --color-text: #f3efe7;
  --color-text-muted: #b2aba0;
  --color-primary: #69c6cb;
  --color-accent: #ffb15c;
  --shadow-lg: 0 24px 60px rgba(0,0,0,0.42);
  --shadow-md: 0 14px 36px rgba(0,0,0,0.28);
  --gradient-bg: radial-gradient(circle at top left, rgba(255,177,92,0.14), transparent 25%), radial-gradient(circle at right, rgba(105,198,203,0.16), transparent 30%), linear-gradient(180deg, #121316 0%, #0c0d10 100%);
}
* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font-body);
  font-size: var(--text-base);
  color: var(--color-text);
  background: var(--gradient-bg);
}
a { color: inherit; text-decoration: none; }
button { font: inherit; cursor: pointer; }
canvas, svg { display: block; max-width: 100%; }
.skip-link { position: absolute; left: -9999px; top: 1rem; }
.skip-link:focus { left: 1rem; z-index: 100; background: var(--color-surface-strong); padding: 0.75rem 1rem; border-radius: 0.85rem; }
.site-shell { width: min(1240px, calc(100% - 2rem)); margin: 0 auto; padding: 1rem 0 3rem; }
.topbar, .game-selector, .game-panel, .info-card { backdrop-filter: blur(18px); }
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  padding: 1rem 1.5rem;
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  border-radius: 1.75rem;
  position: sticky;
  top: 1rem;
  z-index: 20;
  box-shadow: var(--shadow-md);
}
.brand { display: inline-flex; align-items: center; gap: 0.75rem; }
.brand strong, .brand small { display: block; }
.brand strong { font-size: var(--text-lg); }
.brand small { color: var(--color-text-muted); }
.brand-mark { width: 2.8rem; color: var(--color-primary); }
.topbar-actions { display: flex; align-items: center; gap: 0.75rem; }
.score-pill {
  padding: 0.8rem 1rem;
  border-radius: 999px;
  background: var(--color-surface-strong);
  border: 1px solid var(--color-border);
  color: var(--color-text-muted);
  font-size: var(--text-sm);
}
.theme-toggle {
  position: relative;
  width: 48px;
  height: 48px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  border: 1px solid var(--color-border);
  background: var(--color-surface-strong);
  padding: 0;
}
.theme-icon {
  position: absolute;
  width: 20px;
  height: 20px;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.theme-icon--sun { display: none; }
[data-theme="light"] .theme-icon--sun { display: block; color: var(--color-accent); }
[data-theme="light"] .theme-icon--moon { display: none; }
[data-theme="dark"] .theme-icon--moon { display: block; color: var(--color-text); }
.hero.compact-hero { padding: 2rem 0 1rem; }
.eyebrow, .mini-label, .overlay-kicker {
  text-transform: uppercase;
  letter-spacing: 0.18em;
  font-size: var(--text-xs);
  color: var(--color-text-muted);
}
.hero h1, .info-card h3, .overlay h2 {
  font-family: var(--font-display);
  line-height: 1;
  font-weight: 400;
}
.hero h1 { font-size: clamp(3rem, 7vw, 5.4rem); margin: 0.5rem 0 1rem; max-width: 11ch; }
.hero-text, .info-card p { color: var(--color-text-muted); max-width: 62ch; }
.game-selector {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 0.75rem;
  margin: 1.5rem 0;
  padding: 0.75rem;
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  border-radius: 1.75rem;
  box-shadow: var(--shadow-md);
}
.game-tab {
  min-height: 52px;
  padding: 0.9rem 1rem;
  border-radius: 999px;
  border: 1px solid var(--color-border);
  background: rgba(255,255,255,0.02);
  color: var(--color-text-muted);
}
.game-tab.is-active { background: var(--color-primary); color: #f8fafb; border-color: transparent; }
.game-layout { display: grid; grid-template-columns: minmax(0, 1.45fr) minmax(280px, 0.8fr); gap: 1.5rem; }
.game-panel, .info-card {
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  border-radius: 1.75rem;
  box-shadow: var(--shadow-lg);
}
.game-panel { padding: 1rem; overflow: hidden; }
.hud {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.75rem;
  margin-bottom: 1rem;
}
.hud div {
  padding: 1rem;
  border-radius: 1.25rem;
  border: 1px solid var(--color-border);
  background: var(--color-surface-strong);
}
.hud span {
  display: block;
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.12em;
  margin-bottom: 0.35rem;
}
.hud strong { font-size: var(--text-lg); font-variant-numeric: tabular-nums; }
.canvas-wrap {
  position: relative;
  border-radius: 1.25rem;
  overflow: hidden;
  border: 1px solid var(--color-border);
  background: linear-gradient(180deg, #0a1020, #090c14);
  aspect-ratio: 16 / 9;
}
#gameCanvas, .memory-board, .clicker-layer { width: 100%; height: 100%; }
.memory-board, .clicker-layer {
  position: absolute;
  inset: 0;
  z-index: 2;
}
.memory-board {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.75rem;
  padding: 1rem;
  background: linear-gradient(180deg, #0c1020, #0a0c14);
}
.memory-card {
  position: relative;
  border-radius: 1rem;
  border: 1px solid rgba(255,255,255,0.12);
  background: rgba(255,255,255,0.06);
  transform-style: preserve-3d;
  transition: transform 220ms ease;
}
.memory-card.is-flipped { transform: rotateY(180deg); }
.memory-card__face {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  backface-visibility: hidden;
  border-radius: inherit;
  font-size: 2rem;
}
.memory-card__front { background: rgba(255,255,255,0.05); color: #fff; }
.memory-card__back { transform: rotateY(180deg); background: linear-gradient(180deg, rgba(255,177,92,0.18), rgba(105,198,203,0.18)); color: #fff; }
.clicker-layer { overflow: hidden; }
.click-target {
  position: absolute;
  width: 64px;
  height: 64px;
  border: none;
  border-radius: 50%;
  background: radial-gradient(circle at 30% 30%, #ffcf98, #ff8a4c);
  box-shadow: 0 0 24px rgba(255,177,92,0.45);
}
.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 1.5rem;
  background: linear-gradient(180deg, rgba(5,7,12,0.18), rgba(5,7,12,0.72));
  z-index: 3;
}
.overlay.is-hidden { display: none; }
.overlay-card {
  width: min(100%, 560px);
  text-align: center;
  padding: 2rem;
  border-radius: 1.75rem;
  background: rgba(12,15,20,0.76);
  border: 1px solid rgba(255,255,255,0.12);
  box-shadow: 0 18px 44px rgba(0,0,0,0.35);
}
.overlay h2 { font-size: clamp(2rem, 5vw, 3.8rem); margin: 0.25rem 0 0.8rem; color: #fff; }
.overlay p { color: rgba(255,255,255,0.84); max-width: 44ch; margin: 0 auto; }
.overlay-actions, .controls { display: flex; gap: 0.75rem; flex-wrap: wrap; margin-top: 1.5rem; }
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  min-height: 48px;
  padding: 0.9rem 1.2rem;
  border-radius: 999px;
  border: 1px solid transparent;
  transition: transform 180ms ease, background 180ms ease, border-color 180ms ease;
}
.btn:hover, .btn:focus-visible { transform: translateY(-1px); }
.btn-primary { background: var(--color-primary); color: #f8fafb; }
.btn-secondary { background: var(--color-surface-strong); border-color: var(--color-border); color: var(--color-text); }
.control-btn { flex: 1 1 150px; }
.info-panel { display: grid; gap: 1rem; }
.info-card { padding: 1.5rem; }
.info-card h3 { font-size: var(--text-xl); margin: 0.4rem 0 0.8rem; }
.is-hidden { display: none !important; }
:focus-visible { outline: 2px solid var(--color-accent); outline-offset: 3px; }
@media (max-width: 1100px) {
  .game-selector { grid-template-columns: repeat(3, 1fr); }
  .game-layout { grid-template-columns: 1fr; }
}
@media (max-width: 700px) {
  .site-shell { width: min(100% - 1rem, 1240px); }
  .topbar { flex-direction: column; align-items: stretch; }
  .topbar-actions { justify-content: space-between; }
  .game-selector { grid-template-columns: repeat(2, 1fr); }
  .hud { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 520px) {
  .hud { grid-template-columns: 1fr; }
  .memory-board { grid-template-columns: repeat(3, 1fr); }
}