/* Memory Rush — Neon Brain Arcade visual style (dark bg, neon tiles, glass
   UI, gradient highlights, particle effects — concept section 32).
   NOTE: any calc() using var() MUST have whitespace around +/- operators;
   `calc(var(--x)+10)` is invalid CSS and silently drops the entire
   containing declaration with zero console warning (a real bug found and
   fixed on a prior GameCMB game — see claude/color-trap-build-notes.md). */

:root {
  --bg-0: #06070f;
  --bg-1: #0b0e1c;
  --bg-2: #12162a;
  --glass: rgba(18, 22, 42, 0.72);
  --glass-border: rgba(148, 163, 255, 0.18);
  --ink: #eef1ff;
  --ink-dim: #9aa3c7;
  --accent-a: #7c5cff;
  --accent-b: #22d3ee;
  --accent-c: #f472b6;
  --good: #34d399;
  --bad: #f87171;
  --warn: #fbbf24;
  --radius-lg: 22px;
  --radius-md: 14px;
  --radius-sm: 9px;
  --shadow-glow: 0 0 24px rgba(124, 92, 255, 0.35);
  --font-display: 'Space Grotesk', 'Segoe UI', system-ui, sans-serif;
  --font-body: 'Inter', 'Segoe UI', system-ui, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg-0);
  color: var(--ink);
  font-family: var(--font-body);
  -webkit-tap-highlight-color: transparent;
}

body {
  min-height: 100vh;
  background:
    radial-gradient(1200px 600px at 50% -10%, rgba(124, 92, 255, 0.22), transparent 60%),
    radial-gradient(900px 500px at 90% 110%, rgba(34, 211, 238, 0.14), transparent 55%),
    var(--bg-0);
}

a { color: var(--accent-b); }

#app {
  max-width: 1180px;
  margin: 0 auto;
  padding: 0 16px 40px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

/* ---- Top bar --------------------------------------------------------- */
#topBar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 4px 4px;
}
.brand {
  display: flex;
  align-items: baseline;
  gap: 8px;
  font-family: var(--font-display);
}
.brand-name {
  font-weight: 700;
  font-size: 22px;
  letter-spacing: 0.02em;
  background: linear-gradient(120deg, var(--accent-a), var(--accent-b) 60%, var(--accent-c));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.brand-sub {
  font-size: 11px;
  color: var(--ink-dim);
}
.top-controls {
  display: flex;
  gap: 8px;
}
.icon-btn {
  width: 40px;
  height: 40px;
  min-width: 44px;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  border: 1px solid var(--glass-border);
  background: var(--glass);
  color: var(--ink);
  font-size: 17px;
  cursor: pointer;
  transition: transform 0.15s ease, background 0.15s ease;
}
.icon-btn:hover { transform: translateY(-1px); background: rgba(124, 92, 255, 0.18); }
.icon-btn.is-on { color: var(--accent-b); border-color: var(--accent-b); }

/* ---- Ad slots ---------------------------------------------------------
   Kept strictly outside gameplay per concept section 45: never over the
   board, never between input events. */
.ad-slot {
  min-height: 90px;
  border-radius: var(--radius-md);
  border: 1px dashed var(--glass-border);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--ink-dim);
  font-size: 12px;
  background: rgba(255, 255, 255, 0.02);
}

/* ---- Game stage -------------------------------------------------------- */
#gameStage {
  position: relative;
  background: linear-gradient(180deg, var(--bg-1), var(--bg-2));
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-lg);
  padding: 18px;
  min-height: 560px;
  overflow: hidden;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.45);
}
#gameStage::before {
  content: '';
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(rgba(148, 163, 255, 0.05) 1px, transparent 1px),
    linear-gradient(90deg, rgba(148, 163, 255, 0.05) 1px, transparent 1px);
  background-size: 34px 34px;
  pointer-events: none;
  opacity: 0.6;
}
#gameStage:fullscreen, #gameStage:-webkit-full-screen {
  width: 100vw;
  height: 100vh;
  border-radius: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

#fxCanvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 5;
}

#hud {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}
.hud-cluster { display: flex; align-items: center; gap: 18px; flex-wrap: wrap; }
.hud-item { display: flex; flex-direction: column; align-items: center; min-width: 56px; }
.hud-label { font-size: 10px; letter-spacing: 0.08em; color: var(--ink-dim); text-transform: uppercase; }
.hud-value { font-family: var(--font-display); font-size: 20px; font-weight: 700; }
#hudCombo.is-hot { color: var(--accent-c); text-shadow: 0 0 12px rgba(244, 114, 182, 0.7); }
#hudMode {
  font-size: 11px;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(34, 211, 238, 0.14);
  color: var(--accent-b);
  border: 1px solid rgba(34, 211, 238, 0.35);
  letter-spacing: 0.06em;
}
.hearts { display: flex; gap: 3px; font-size: 18px; }
.heart { color: var(--bad); text-shadow: 0 0 8px rgba(248, 113, 113, 0.6); transition: opacity 0.2s, transform 0.2s; }
.heart.is-lost { opacity: 0.25; transform: scale(0.85); text-shadow: none; }

#bannerWrap { position: relative; z-index: 2; text-align: center; min-height: 22px; margin-bottom: 6px; }
#bannerText {
  font-family: var(--font-display);
  font-size: 13px;
  letter-spacing: 0.14em;
  color: var(--ink-dim);
  text-transform: uppercase;
}

/* ---- Board / tiles ----------------------------------------------------- */
#boardWrap {
  position: relative;
  z-index: 2;
  display: flex;
  justify-content: center;
}
#board {
  display: grid;
  grid-template-columns: repeat(var(--grid-size, 3), 1fr);
  gap: 10px;
  width: min(92vw, 480px);
  aspect-ratio: 1 / 1;
}
.tile {
  position: relative;
  border: 1px solid rgba(148, 163, 255, 0.22);
  background: linear-gradient(160deg, rgba(255, 255, 255, 0.04), rgba(255, 255, 255, 0.01));
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
  min-height: 44px;
  min-width: 44px;
  transition: transform 0.12s ease, box-shadow 0.12s ease, background 0.15s ease;
  touch-action: manipulation;
}
.tile-icon { font-size: clamp(16px, 4.4vw, 30px); filter: drop-shadow(0 0 2px rgba(0, 0, 0, 0.4)); }
.tile.shape-circle { border-radius: 50%; }
.tile.shape-diamond { border-radius: var(--radius-sm); transform: rotate(0deg); }
.tile.shape-hex { clip-path: polygon(25% 6%, 75% 6%, 100% 50%, 75% 94%, 25% 94%, 0% 50%); }
.tile.shape-star { clip-path: polygon(50% 2%, 61% 37%, 98% 37%, 68% 59%, 79% 95%, 50% 73%, 21% 95%, 32% 59%, 2% 37%, 39% 37%); }
.tile.shape-square { border-radius: 6px; }
.tile.shape-triangle { clip-path: polygon(50% 4%, 96% 96%, 4% 96%); }

.tile.is-lit {
  transform: scale(1.08);
  background: linear-gradient(160deg, rgba(124, 92, 255, 0.55), rgba(34, 211, 238, 0.35));
  box-shadow: 0 0 22px rgba(124, 92, 255, 0.65), 0 0 42px rgba(34, 211, 238, 0.35);
  border-color: rgba(224, 231, 255, 0.6);
}
.tile.is-correct {
  animation: tilePop 0.32s ease;
  background: linear-gradient(160deg, rgba(52, 211, 153, 0.5), rgba(34, 211, 238, 0.25));
  border-color: rgba(52, 211, 153, 0.7);
  box-shadow: 0 0 18px rgba(52, 211, 153, 0.55);
}
.tile.is-wrong {
  animation: tileShake 0.4s ease;
  background: linear-gradient(160deg, rgba(248, 113, 113, 0.55), rgba(190, 24, 93, 0.3));
  border-color: rgba(248, 113, 113, 0.8);
  box-shadow: 0 0 18px rgba(248, 113, 113, 0.55);
}
.tile-order {
  position: absolute;
  top: 3px;
  right: 5px;
  font-family: var(--font-display);
  font-size: 11px;
  font-weight: 700;
  color: #06111a;
  background: #e0ffee;
  border-radius: 999px;
  min-width: 16px;
  height: 16px;
  padding: 0 3px;
  display: flex;
  align-items: center;
  justify-content: center;
}

@keyframes tilePop {
  0% { transform: scale(1); }
  45% { transform: scale(1.14); }
  100% { transform: scale(1); }
}
@keyframes tileShake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-6px) rotate(-2deg); }
  40% { transform: translateX(6px) rotate(2deg); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(4px); }
}

/* ---- Screens (overlays inside #gameStage, applied from round 1) ------ */
.screen-overlay {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(4, 6, 13, 0.74);
  backdrop-filter: blur(7px);
  -webkit-backdrop-filter: blur(7px);
}
.screen-panel {
  width: 100%;
  max-width: 420px;
  max-height: 100%;
  overflow-y: auto;
  background: var(--glass);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-lg);
  padding: 26px 22px;
  box-shadow: var(--shadow-glow);
  text-align: center;
}
.screen-panel.wide { max-width: 560px; }

.logo-huge {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(34px, 8vw, 52px);
  line-height: 1.02;
  letter-spacing: 0.01em;
  background: linear-gradient(120deg, var(--accent-a), var(--accent-b) 55%, var(--accent-c));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  margin: 4px 0 2px;
}
.tagline { color: var(--ink-dim); font-size: 13px; margin-bottom: 22px; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 13px 18px;
  margin: 6px 0;
  border-radius: 999px;
  border: 1px solid transparent;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 15px;
  letter-spacing: 0.03em;
  cursor: pointer;
  min-height: 44px;
  transition: transform 0.14s ease, box-shadow 0.14s ease, filter 0.14s ease;
}
.btn:active { transform: scale(0.98); }
.btn-primary {
  color: #06111a;
  background: linear-gradient(120deg, var(--accent-b), var(--accent-a) 70%);
  box-shadow: 0 10px 26px rgba(124, 92, 255, 0.4);
}
.btn-primary:hover { filter: brightness(1.07); }
.btn-secondary {
  color: var(--ink);
  background: rgba(255, 255, 255, 0.05);
  border-color: var(--glass-border);
}
.btn-secondary:hover { background: rgba(255, 255, 255, 0.09); }
.btn-ghost {
  color: var(--ink-dim);
  background: transparent;
  border: none;
  font-family: var(--font-body);
  font-weight: 500;
  text-decoration: underline;
  width: auto;
  padding: 8px;
}
.btn-small { width: auto; padding: 9px 16px; font-size: 13px; }

.menu-row { display: flex; gap: 8px; justify-content: center; margin-top: 10px; }
.menu-footnote { margin-top: 14px; font-size: 11px; color: var(--ink-dim); }

/* Countdown */
#screenCountdown .screen-panel { background: transparent; border: none; box-shadow: none; }
#countdownNum {
  font-family: var(--font-display);
  font-size: 88px;
  font-weight: 800;
  color: var(--ink);
  text-shadow: 0 0 40px rgba(124, 92, 255, 0.8);
}

/* How to play */
.howto-steps { display: flex; flex-direction: column; gap: 12px; text-align: left; margin: 16px 0; }
.howto-step { display: flex; gap: 12px; align-items: flex-start; }
.howto-num {
  flex: none;
  width: 28px; height: 28px;
  border-radius: 50%;
  background: linear-gradient(120deg, var(--accent-a), var(--accent-b));
  color: #06111a;
  font-weight: 800;
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-display);
}
.howto-step p { margin: 0; font-size: 13px; color: var(--ink-dim); }
.howto-step strong { display: block; font-size: 14px; color: var(--ink); }

/* Game over */
.go-score-big { font-family: var(--font-display); font-size: 44px; font-weight: 800; margin: 4px 0; }
.go-badge {
  display: inline-block;
  font-size: 12px;
  padding: 3px 10px;
  border-radius: 999px;
  background: rgba(251, 191, 36, 0.16);
  color: var(--warn);
  border: 1px solid rgba(251, 191, 36, 0.4);
  margin-bottom: 8px;
}
.go-stats { display: flex; justify-content: center; gap: 22px; margin: 10px 0 6px; }
.go-stat-label { font-size: 10px; color: var(--ink-dim); text-transform: uppercase; letter-spacing: 0.06em; }
.go-stat-value { font-family: var(--font-display); font-weight: 700; font-size: 18px; }
#goRetentionLine { font-size: 13px; color: var(--accent-b); margin: 10px 0 4px; }
#goRankLine { font-size: 13px; color: var(--warn); margin: 8px 0; font-weight: 600; }
#goOfflineNote { font-size: 11px; color: var(--ink-dim); margin-top: 6px; }

.nickname-row { display: flex; gap: 8px; margin-top: 4px; }
#nicknameInput {
  flex: 1;
  min-height: 44px;
  border-radius: 999px;
  border: 1px solid var(--glass-border);
  background: rgba(255, 255, 255, 0.04);
  color: var(--ink);
  padding: 0 16px;
  font-size: 14px;
}
#nicknameInput:focus { outline: 2px solid var(--accent-b); }
.field-error { color: var(--bad); font-size: 12px; margin-top: 6px; min-height: 16px; }
#submitStatus { font-size: 12px; color: var(--ink-dim); margin-top: 4px; min-height: 16px; }

/* Leaderboard */
.tab-row { display: flex; gap: 6px; justify-content: center; flex-wrap: wrap; margin-bottom: 10px; }
.tab-btn {
  border: 1px solid var(--glass-border);
  background: transparent;
  color: var(--ink-dim);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 12px;
  cursor: pointer;
  min-height: 32px;
}
.tab-btn.is-active { background: rgba(124, 92, 255, 0.22); color: var(--ink); border-color: var(--accent-a); }
#lbTable { width: 100%; border-collapse: collapse; margin-top: 8px; font-size: 13px; }
#lbTable td { padding: 8px 6px; border-bottom: 1px solid rgba(255, 255, 255, 0.06); text-align: left; }
.lb-rank { width: 40px; text-align: center !important; }
.lb-score { text-align: right !important; font-family: var(--font-display); font-weight: 700; }
tr.is-you { background: rgba(34, 211, 238, 0.1); border-radius: 8px; }
.lb-empty { text-align: center !important; color: var(--ink-dim); padding: 20px 0; }

/* Daily */
#dailyDoneScore { font-family: var(--font-display); font-size: 30px; font-weight: 800; color: var(--accent-b); }

/* Toasts */
#toastLayer {
  position: absolute;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 30;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  pointer-events: none;
}
.toast {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 13px;
  padding: 7px 16px;
  border-radius: 999px;
  background: rgba(15, 18, 34, 0.85);
  border: 1px solid var(--glass-border);
  color: var(--ink);
  opacity: 0;
  transform: translateY(-8px) scale(0.9);
  transition: opacity 0.2s ease, transform 0.2s ease;
}
.toast.is-in { opacity: 1; transform: translateY(0) scale(1); }
.toast-combo { color: var(--accent-c); border-color: rgba(244, 114, 182, 0.5); }
.toast-perfect { color: var(--warn); border-color: rgba(251, 191, 36, 0.5); }
.toast-achievement { color: var(--good); border-color: rgba(52, 211, 153, 0.5); }

/* ---- SEO content ------------------------------------------------------- */
#seoContent {
  background: var(--glass);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-lg);
  padding: 26px 22px;
  font-size: 14px;
  line-height: 1.65;
  color: var(--ink-dim);
}
#seoContent h1, #seoContent h2 { color: var(--ink); font-family: var(--font-display); }
#seoContent h1 { font-size: 22px; margin-top: 0; }
#seoContent h2 { font-size: 17px; margin-top: 26px; }
#seoContent details { margin: 6px 0; border-bottom: 1px solid rgba(255, 255, 255, 0.06); padding-bottom: 8px; }
#seoContent summary { cursor: pointer; color: var(--ink); font-weight: 600; }

footer.site-footer {
  text-align: center;
  color: var(--ink-dim);
  font-size: 12px;
  padding: 10px 0 20px;
}
footer.site-footer a { color: var(--ink-dim); }

/* ---- Responsive --------------------------------------------------------- */
@media (max-width: 640px) {
  #app { padding: 0 10px 28px; gap: 12px; }
  #gameStage { padding: 12px; min-height: 480px; }
  .hud-cluster { gap: 12px; }
  .go-score-big { font-size: 36px; }
  #board { width: 90vw; }

  /* Narrow-viewport top bar: the full "MEMORY RUSH by Game CMB" + 4 icon
     buttons doesn't fit one line under ~420px and was wrapping the
     brand-sub label into an ugly stacked "by / Game / CMB" — found via a
     390px-viewport screenshot review, not any failing assertion (same
     category of bug as a prior GameCMB game's calc() gradient issue:
     zero console errors, only visible by actually looking at a render). */
  #topBar { flex-wrap: nowrap; }
  .brand-sub { display: none; }
  .brand-name { font-size: 17px; }
  .top-controls { gap: 6px; }
  .icon-btn { width: 40px; height: 40px; min-width: 40px; min-height: 40px; font-size: 15px; }
}

/* ---- Accessibility ------------------------------------------------------ */
.reduced-motion * {
  animation-duration: 0.001s !important;
  transition-duration: 0.001s !important;
}
.high-contrast {
  --ink-dim: #cfd4ec;
  --glass: rgba(4, 6, 13, 0.92);
  --glass-border: rgba(255, 255, 255, 0.45);
}
.high-contrast .tile { border-width: 2px; }
.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
