/* Color Trap — GameCMB (gamecmb.com)
   Visual direction: minimal, neon, glassmorphism, soft glow, dark bg. */

@font-face {
  font-family: 'Sora';
  src: local('Sora');
  font-display: swap;
}

:root {
  --bg-0: #05070c;
  --bg-1: #0b0f1a;
  --accent-h: 222;
  --accent: hsl(var(--accent-h), 85%, 62%);
  --accent-soft: hsl(var(--accent-h), 85%, 62%, 0.35);
  --glass: rgba(255, 255, 255, 0.06);
  --glass-border: rgba(255, 255, 255, 0.12);
  --text: #f2f4fa;
  --text-dim: #9aa3b8;
  --danger: #ff5470;
  --success: #4ade80;
  --gold: #ffd15c;
  --radius: 22px;
  --shadow-glow: 0 0 40px hsla(var(--accent-h), 85%, 62%, 0.25);
}

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

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg-0);
}

body {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  font-family: 'Sora', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  color: var(--text);
  background:
    radial-gradient(1200px 600px at 15% -10%, hsla(var(--accent-h), 85%, 55%, 0.18), transparent 60%),
    radial-gradient(900px 500px at 110% 10%, hsla(calc(var(--accent-h) + 60), 85%, 55%, 0.12), transparent 55%),
    var(--bg-0);
  overflow-x: hidden;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

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

.site-header {
  width: 100%;
  max-width: 640px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px 4px;
}

.brand {
  font-weight: 800;
  font-size: 1.05rem;
  letter-spacing: 0.02em;
  display: flex;
  align-items: center;
  gap: 8px;
}
.brand .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 10px var(--accent); }

.top-controls {
  display: flex;
  gap: 8px;
}
.icon-btn {
  width: 38px;
  height: 38px;
  border-radius: 12px;
  border: 1px solid var(--glass-border);
  background: var(--glass);
  color: var(--text);
  font-size: 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  backdrop-filter: blur(8px);
  transition: transform 0.15s ease, background 0.15s ease;
}
.icon-btn:hover { background: rgba(255,255,255,0.1); }
.icon-btn:active { transform: scale(0.92); }

#gameShell {
  width: 100%;
  max-width: 520px;
  padding: 8px 16px 24px;
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: stretch;
}

.card {
  background: var(--glass);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius);
  backdrop-filter: blur(14px);
  box-shadow: var(--shadow-glow), 0 20px 60px rgba(0,0,0,0.4);
  padding: 28px 22px;
}

/* --- Start screen --- */
#screen-start { text-align: center; padding-top: 4vh; }
.logo-title {
  font-size: clamp(2.2rem, 9vw, 3.2rem);
  font-weight: 900;
  letter-spacing: -0.02em;
  margin: 6px 0 4px;
  background: linear-gradient(135deg, hsl(var(--accent-h),90%,70%), hsl(calc(var(--accent-h) + 70),90%,65%));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.tagline { color: var(--text-dim); margin: 0 0 24px; font-size: 1rem; }

.stat-row {
  display: flex;
  justify-content: center;
  gap: 28px;
  margin: 18px 0 26px;
}
.stat { display: flex; flex-direction: column; align-items: center; gap: 2px; }
.stat .num { font-size: 1.4rem; font-weight: 800; }
.stat .label { font-size: 0.72rem; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.08em; }

.streak-badge {
  display: inline-block;
  margin-bottom: 16px;
  padding: 6px 14px;
  border-radius: 999px;
  background: rgba(255,209,92,0.12);
  border: 1px solid rgba(255,209,92,0.3);
  color: var(--gold);
  font-size: 0.85rem;
  font-weight: 700;
}

.btn {
  appearance: none;
  border: none;
  cursor: pointer;
  font-family: inherit;
  font-weight: 800;
  letter-spacing: 0.03em;
  border-radius: 16px;
  padding: 16px 28px;
  font-size: 1.05rem;
  transition: transform 0.12s ease, box-shadow 0.12s ease, filter 0.12s ease;
}
.btn:active { transform: scale(0.97); }
.btn-primary {
  color: #06090f;
  background: linear-gradient(135deg, hsl(var(--accent-h),90%,68%), hsl(calc(var(--accent-h) + 60),90%,62%));
  box-shadow: 0 8px 30px hsla(var(--accent-h),90%,60%,0.45);
  width: 100%;
}
.btn-primary:hover { filter: brightness(1.06); }
.btn-secondary {
  color: var(--text);
  background: var(--glass);
  border: 1px solid var(--glass-border);
  width: 100%;
  margin-top: 12px;
}
.btn-ghost {
  color: var(--text-dim);
  background: transparent;
  border: 1px solid var(--glass-border);
}
.btn-row { display: flex; gap: 10px; margin-top: 14px; }
.btn-row .btn { flex: 1; margin-top: 0; }

/* --- Countdown --- */
#screen-countdown {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}
.countdown-number {
  font-size: 6rem;
  font-weight: 900;
  color: var(--accent);
  text-shadow: 0 0 40px var(--accent);
  animation: pop 0.6s ease;
}
@keyframes pop {
  0% { transform: scale(0.4); opacity: 0; }
  60% { transform: scale(1.15); opacity: 1; }
  100% { transform: scale(1); }
}

/* --- Game screen --- */
#screen-game { display: flex; flex-direction: column; gap: 14px; padding-top: 6px; }

.hud {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-radius: 16px;
  background: var(--glass);
  border: 1px solid var(--glass-border);
}
.hud-block { display: flex; flex-direction: column; align-items: flex-start; min-width: 64px; }
.hud-block.center { align-items: center; }
.hud-block.right { align-items: flex-end; }
.hud-label { font-size: 0.62rem; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.1em; }
.hud-value { font-size: 1.3rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.combo-badge {
  font-size: 0.78rem;
  font-weight: 800;
  color: var(--gold);
  min-height: 1.1em;
}
.combo-badge.on-fire { color: #ff8a3d; text-shadow: 0 0 12px #ff8a3d; }

.time-bar-track {
  height: 8px;
  border-radius: 999px;
  background: rgba(255,255,255,0.08);
  overflow: hidden;
}
.time-bar-fill {
  height: 100%;
  width: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, hsl(var(--accent-h),85%,60%), hsl(calc(var(--accent-h) + 50),85%,60%));
  transition: width 0.12s linear, background 0.3s ease;
}
.time-bar-fill.low { background: linear-gradient(90deg, #ff5470, #ff8a3d); }

#gridWrap {
  position: relative;
  border-radius: var(--radius);
  background: var(--glass);
  border: 1px solid var(--glass-border);
  padding: 14px;
  box-shadow: var(--shadow-glow);
}

#grid {
  display: grid;
  grid-template-columns: repeat(var(--cols, 3), 1fr);
  gap: 8px;
  aspect-ratio: 1 / 1;
}

.tile {
  appearance: none;
  border: none;
  border-radius: 12px;
  cursor: pointer;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.08), 0 4px 14px rgba(0,0,0,0.35);
  transition: transform 0.1s ease, box-shadow 0.15s ease;
  min-height: 0;
  min-width: 0;
}
.tile:hover { transform: scale(1.03); }
.tile:focus-visible { outline: 3px solid #fff; outline-offset: 2px; z-index: 1; }
.tile:active { transform: scale(0.94); }
.tile.wrong-flash { animation: wrongFlash 0.26s ease; }
.tile.reveal-target { outline: 3px dashed rgba(255,255,255,0.85); outline-offset: 3px; }
@keyframes wrongFlash {
  0%, 100% { filter: brightness(1); }
  40% { filter: brightness(1.6) saturate(0.4); box-shadow: inset 0 0 0 3px var(--danger); }
}

#particlesCanvas {
  position: absolute;
  inset: 14px;
  pointer-events: none;
}
#popupLayer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: visible;
}
.score-popup {
  position: absolute;
  transform: translate(-50%, -10px);
  font-weight: 900;
  font-size: 1rem;
  color: var(--success);
  text-shadow: 0 2px 8px rgba(0,0,0,0.6);
  animation: floatUp 0.85s ease forwards;
  white-space: nowrap;
}
.score-popup.perfect { color: var(--gold); font-size: 1.1rem; }
@keyframes floatUp {
  0% { opacity: 0; transform: translate(-50%, 0); }
  15% { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%, -46px); }
}

/* --- Game over --- */
#screen-gameover { text-align: center; padding-top: 3vh; }
.go-title { font-size: 1.6rem; font-weight: 900; letter-spacing: 0.02em; margin: 0 0 4px; color: var(--text-dim); }
.go-score { font-size: clamp(2.6rem, 12vw, 3.6rem); font-weight: 900; margin: 4px 0; }
.new-best-badge {
  display: inline-block;
  margin: 6px 0 10px;
  padding: 6px 16px;
  border-radius: 999px;
  background: rgba(74,222,128,0.14);
  border: 1px solid rgba(74,222,128,0.4);
  color: var(--success);
  font-weight: 800;
  font-size: 0.85rem;
  animation: pop 0.5s ease;
}
.go-message { color: var(--text-dim); margin: 6px 0 18px; min-height: 1.4em; }
#rankLine { color: var(--accent); font-weight: 700; margin-top: -8px; margin-bottom: 12px; }

/* --- Overlays / modals --- */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(3,5,10,0.72);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 50;
}
.modal {
  width: 100%;
  max-width: 380px;
  text-align: center;
}
.modal h2 { margin: 0 0 6px; font-size: 1.3rem; }
.modal p { color: var(--text-dim); font-size: 0.9rem; margin: 0 0 16px; }
.nickname-input {
  width: 100%;
  padding: 14px 16px;
  border-radius: 12px;
  border: 1px solid var(--glass-border);
  background: rgba(255,255,255,0.05);
  color: var(--text);
  font-size: 1rem;
  font-family: inherit;
  text-align: center;
}
.nickname-input:focus { outline: 2px solid var(--accent); }
.field-error { color: var(--danger); font-size: 0.8rem; min-height: 1.2em; margin: 8px 0 0; }
.submit-status { color: var(--text-dim); font-size: 0.85rem; min-height: 1.2em; margin-top: 8px; }

/* --- Leaderboard --- */
.lb-tabs { display: flex; gap: 6px; margin-bottom: 12px; }
.lb-tab {
  flex: 1;
  padding: 8px;
  border-radius: 10px;
  border: 1px solid var(--glass-border);
  background: transparent;
  color: var(--text-dim);
  font-weight: 700;
  font-size: 0.78rem;
  cursor: pointer;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.lb-tab.active { background: var(--accent); color: #06090f; border-color: transparent; }
#leaderboardList {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 340px;
  overflow-y: auto;
  text-align: left;
}
.lb-row {
  display: grid;
  grid-template-columns: 34px 1fr auto 48px;
  gap: 8px;
  align-items: center;
  padding: 9px 8px;
  border-radius: 10px;
  font-size: 0.9rem;
}
.lb-row.me { background: hsla(var(--accent-h), 85%, 60%, 0.14); }
.lb-rank { color: var(--text-dim); font-weight: 700; }
.lb-name { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-score { font-weight: 800; font-variant-numeric: tabular-nums; }
.lb-level { color: var(--text-dim); font-size: 0.8rem; text-align: right; }
.lb-empty, .lb-loading { text-align: center; color: var(--text-dim); padding: 20px 0; }

/* --- Achievement toast --- */
#achievementToast {
  position: fixed;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 80;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
  width: min(90vw, 360px);
}
.achievement-toast {
  background: rgba(10,12,20,0.92);
  border: 1px solid var(--glass-border);
  border-radius: 14px;
  padding: 10px 16px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  opacity: 0;
  transform: translateY(-12px);
  transition: opacity 0.3s ease, transform 0.3s ease;
  box-shadow: 0 10px 30px rgba(0,0,0,0.4);
}
.achievement-toast.show { opacity: 1; transform: translateY(0); }
.achievement-toast strong { color: var(--gold); font-size: 0.9rem; }
.achievement-toast span { color: var(--text-dim); font-size: 0.78rem; }

/* --- SEO footer content --- */
.seo-section {
  width: 100%;
  max-width: 640px;
  padding: 20px 20px 8px;
  color: var(--text-dim);
  font-size: 0.9rem;
  line-height: 1.6;
}
.seo-section h2 { color: var(--text); font-size: 1.1rem; }
.seo-section h3 { color: var(--text); font-size: 0.98rem; margin-bottom: 4px; }

.ad-slot {
  width: 100%;
  max-width: 640px;
  min-height: 90px;
  margin: 6px auto;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-dim);
  font-size: 0.75rem;
  border: 1px dashed var(--glass-border);
  border-radius: 12px;
}

.site-footer {
  color: var(--text-dim);
  font-size: 0.78rem;
  padding: 14px;
  text-align: center;
}

.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap;
}

/* --- Fullscreen mode --- */
body.is-fullscreen .site-header,
body.is-fullscreen .seo-section,
body.is-fullscreen .ad-slot,
body.is-fullscreen .site-footer {
  display: none;
}
body.is-fullscreen #gameShell {
  max-width: 100vw;
  max-width: 100dvw;
  height: 100dvh;
  padding: 10px;
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
}

@media (max-width: 420px) {
  .card { padding: 22px 16px; }
  .stat-row { gap: 18px; }
}
