:root {
  --bg: #0a0a14;
  --bg-2: #12122a;
  --surface: #1a1a35;
  --surface-2: #232347;
  --border: #2d2d55;
  --text: #f0f0ff;
  --muted: #9090b8;
  --primary: #6366f1;
  --primary-2: #8b5cf6;
  --accent: #ec4899;
  --success: #10b981;
  --shadow: 0 20px 60px -20px rgba(99, 102, 241, 0.4);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html { scroll-behavior: smooth; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

body::before {
  content: '';
  position: fixed;
  inset: 0;
  background:
    radial-gradient(circle at 20% 10%, rgba(99,102,241,0.15), transparent 50%),
    radial-gradient(circle at 80% 80%, rgba(236,72,153,0.12), transparent 50%);
  pointer-events: none;
  z-index: -1;
}

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 24px;
}

/* Header */
.site-header {
  position: sticky;
  top: 0;
  z-index: 100;
  backdrop-filter: blur(12px);
  background: rgba(10, 10, 20, 0.7);
  border-bottom: 1px solid var(--border);
}
.header-inner {
  display: flex;
  justify-content: space-between;
  align-items: center;
  height: 68px;
}
.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 1.25rem;
  text-decoration: none;
  color: var(--text);
  font-weight: 500;
}
.logo strong { font-weight: 800; background: linear-gradient(135deg, var(--primary), var(--accent)); -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent; }
.logo-icon {
  width: 36px; height: 36px;
  display: grid; place-items: center;
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
  border-radius: 10px;
  font-size: 0.9rem;
  box-shadow: var(--shadow);
}
.nav { display: flex; gap: 28px; }
.nav a {
  color: var(--muted);
  text-decoration: none;
  font-weight: 500;
  transition: color 0.2s;
}
.nav a:hover { color: var(--text); }
.lang-link {
  padding: 4px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  font-size: 0.85rem;
}
.lang-link:hover { border-color: var(--primary); }

/* Hero */
.hero { padding: 80px 0 60px; }
.hero-inner {
  display: grid;
  grid-template-columns: 1.1fr 1fr;
  gap: 60px;
  align-items: center;
}
.badge {
  display: inline-block;
  padding: 6px 14px;
  background: rgba(99,102,241,0.15);
  border: 1px solid rgba(99,102,241,0.4);
  border-radius: 999px;
  font-size: 0.85rem;
  color: var(--primary);
  font-weight: 600;
  margin-bottom: 20px;
}
.hero h1 {
  font-size: clamp(2.2rem, 5vw, 3.6rem);
  line-height: 1.1;
  font-weight: 800;
  letter-spacing: -0.02em;
  margin-bottom: 20px;
}
.grad {
  background: linear-gradient(135deg, var(--primary), var(--accent));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}
.lead {
  font-size: 1.15rem;
  color: var(--muted);
  margin-bottom: 32px;
  max-width: 540px;
}
.lead strong { color: var(--text); }
.cta-row { display: flex; gap: 14px; flex-wrap: wrap; margin-bottom: 40px; }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 14px 26px;
  border-radius: 12px;
  font-weight: 600;
  font-size: 1rem;
  text-decoration: none;
  border: none;
  cursor: pointer;
  transition: all 0.2s;
  font-family: inherit;
}
.btn-primary {
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
  color: white;
  box-shadow: var(--shadow);
}
.btn-primary:hover { transform: translateY(-2px); box-shadow: 0 25px 70px -20px rgba(99,102,241,0.6); }
.btn-ghost {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-ghost:hover { background: var(--surface-2); border-color: var(--primary); }
.btn-ghost.active {
  background: linear-gradient(135deg, var(--accent), var(--primary-2));
  color: white;
  border-color: transparent;
}

.stats { display: flex; gap: 36px; }
.stats > div { display: flex; flex-direction: column; }
.stats strong { font-size: 1.7rem; font-weight: 800; color: var(--text); }
.stats span { font-size: 0.85rem; color: var(--muted); }

.hero-visual { display: flex; justify-content: center; }
.hero-card {
  position: relative;
  width: 100%;
  max-width: 460px;
  aspect-ratio: 1;
  border-radius: 24px;
  overflow: hidden;
  border: 1px solid var(--border);
  box-shadow: var(--shadow), 0 0 80px -20px rgba(236,72,153,0.3);
  background: var(--surface);
}
.hero-video {
  width: 100%; height: 100%;
  object-fit: cover;
  display: block;
}
.hero-grid {
  position: absolute; inset: 0;
  background-image:
    linear-gradient(rgba(255,255,255,0.15) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,0.15) 1px, transparent 1px);
  background-size: calc(100% / 4) calc(100% / 4);
  pointer-events: none;
  animation: gridPulse 4s ease-in-out infinite;
}
@keyframes gridPulse {
  0%, 100% { opacity: 0.4; }
  50% { opacity: 0.8; }
}

/* Sections */
.section-head { text-align: center; max-width: 600px; margin: 0 auto 40px; }
.section-head h2 {
  font-size: clamp(1.8rem, 4vw, 2.5rem);
  font-weight: 800;
  letter-spacing: -0.01em;
  margin-bottom: 12px;
}
.section-head p { color: var(--muted); font-size: 1.1rem; }

.play-section { padding: 60px 0; }

.player-bar { margin-bottom: 14px; }
.player-chip {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 12px 18px;
  flex-wrap: wrap;
}
.player-chip.hidden { display: none; }
.chip-icon { font-size: 1.1rem; }
.chip-text { color: var(--muted); font-size: 0.9rem; }
.player-chip strong {
  color: var(--text);
  font-size: 1rem;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}
.chip-btn {
  margin-left: auto;
  padding: 7px 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--muted);
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.82rem;
  transition: all 0.2s;
}
.chip-btn:hover { color: var(--text); border-color: var(--primary); }
.chip-btn.primary {
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
  color: white;
  border-color: transparent;
  margin-left: 0;
}
.player-chip.edit input {
  flex: 1;
  min-width: 140px;
  padding: 9px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-family: inherit;
  font-size: 0.95rem;
  outline: none;
}
.player-chip.edit input:focus { border-color: var(--primary); }
.player-chip.edit .chip-btn { margin-left: 0; }

.video-picker {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 14px 18px;
  margin-bottom: 14px;
}
.picker-label {
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 600;
  margin-right: 6px;
  text-transform: uppercase;
  letter-spacing: 1px;
}
.vid-btn {
  padding: 9px 16px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--muted);
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.9rem;
  transition: all 0.2s;
  white-space: nowrap;
}
.vid-btn:hover { color: var(--text); border-color: var(--accent); }
.vid-btn.active {
  background: linear-gradient(135deg, var(--accent), var(--primary-2));
  color: white;
  border-color: transparent;
}

.game-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 20px;
  justify-content: space-between;
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 20px;
  margin-bottom: 20px;
}
.difficulty { display: flex; gap: 6px; flex-wrap: wrap; flex: 1; min-width: 0; }
.diff-btn {
  padding: 9px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--muted);
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.85rem;
  transition: all 0.2s;
  white-space: nowrap;
}
.diff-btn:hover { color: var(--text); border-color: var(--primary); }
.diff-btn.active {
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
  color: white;
  border-color: transparent;
}
.game-actions { display: flex; gap: 10px; }

.game-stats {
  display: flex;
  gap: 30px;
  justify-content: center;
  padding: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  margin-bottom: 20px;
  font-size: 0.95rem;
  color: var(--muted);
}
.game-stats strong { color: var(--text); margin-left: 4px; }

.game-area {
  position: relative;
  width: 100%;
  max-width: 720px;
  margin: 0 auto;
  aspect-ratio: 1;
  border-radius: 20px;
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}
#sourceVideo {
  position: absolute;
  width: 1px; height: 1px;
  opacity: 0;
  pointer-events: none;
}
#puzzleCanvas {
  width: 100%;
  height: 100%;
  display: block;
  cursor: pointer;
}

.win-overlay {
  position: absolute;
  inset: 0;
  background: rgba(10, 10, 20, 0.85);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fadeIn 0.3s;
}
.win-overlay.hidden { display: none; }
.win-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 40px;
  text-align: center;
  max-width: 400px;
  box-shadow: var(--shadow);
}
.win-emoji { font-size: 4rem; margin-bottom: 12px; }
.win-card h3 {
  font-size: 2rem;
  margin-bottom: 8px;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}
.win-card p { color: var(--muted); margin-bottom: 8px; }
.win-detail { font-size: 0.9rem; }
.win-detail strong { color: var(--text); }
.stars {
  font-size: 1.8rem;
  letter-spacing: 4px;
  margin-bottom: 12px;
  color: #fbbf24;
  text-shadow: 0 0 12px rgba(251, 191, 36, 0.5);
}
.stars .dim { color: rgba(255,255,255,0.15); text-shadow: none; }
.win-score-row {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin: 16px 0 12px;
  padding: 16px;
  background: rgba(99, 102, 241, 0.1);
  border: 1px solid rgba(99, 102, 241, 0.3);
  border-radius: 14px;
}
.win-score-label { font-size: 0.85rem; color: var(--muted); text-transform: uppercase; letter-spacing: 1px; }
.win-score-value {
  font-size: 2.6rem;
  font-weight: 800;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}
.record-badge {
  display: inline-block;
  padding: 6px 14px;
  background: linear-gradient(135deg, #fbbf24, #f59e0b);
  color: #1a1a35;
  font-weight: 800;
  font-size: 0.85rem;
  border-radius: 999px;
  margin-bottom: 12px;
  animation: pulse 1.5s ease-in-out infinite;
}
.record-badge.hidden { display: none; }
@keyframes pulse {
  0%, 100% { transform: scale(1); box-shadow: 0 0 0 0 rgba(251,191,36,0.6); }
  50% { transform: scale(1.05); box-shadow: 0 0 0 12px rgba(251,191,36,0); }
}
#playAgain { margin-top: 8px; }

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

/* Leaderboard */
.leaderboard-section { padding: 60px 0; }
.lb-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: center;
  margin-bottom: 24px;
}
.lb-tab {
  padding: 10px 18px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--muted);
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.9rem;
  transition: all 0.2s;
}
.lb-tab:hover { color: var(--text); border-color: var(--primary); }
.lb-tab.active {
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
  color: white;
  border-color: transparent;
}
.lb-content {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  overflow: hidden;
  max-width: 760px;
  margin: 0 auto;
}
.lb-loading, .lb-empty {
  text-align: center;
  padding: 40px;
  color: var(--muted);
}
.lb-row {
  display: grid;
  grid-template-columns: 50px 1fr auto auto auto;
  gap: 16px;
  align-items: center;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  transition: background 0.15s;
}
.lb-row:last-child { border-bottom: none; }
.lb-row:hover { background: var(--surface-2); }
.lb-row.me { background: rgba(99, 102, 241, 0.12); border-left: 3px solid var(--primary); }
.lb-rank {
  font-weight: 800;
  font-size: 1.1rem;
  color: var(--muted);
  text-align: center;
}
.lb-row.gold .lb-rank { color: #fbbf24; font-size: 1.3rem; }
.lb-row.silver .lb-rank { color: #cbd5e1; font-size: 1.2rem; }
.lb-row.bronze .lb-rank { color: #d97706; font-size: 1.15rem; }
.lb-name { font-weight: 600; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-stars { color: #fbbf24; font-size: 0.85rem; letter-spacing: 1px; }
.lb-score {
  font-weight: 800;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  font-size: 1.05rem;
}
.lb-meta { color: var(--muted); font-size: 0.8rem; text-align: right; }
@media (max-width: 600px) {
  .lb-row { grid-template-columns: 36px 1fr auto; gap: 10px; padding: 12px 14px; font-size: 0.9rem; }
  .lb-stars, .lb-meta { display: none; }
}

/* Submit box in win modal */
.submit-box {
  margin: 16px 0;
  padding: 16px;
  background: var(--surface-2);
  border-radius: 12px;
  border: 1px solid var(--border);
}
.submit-box label { display: block; font-size: 0.85rem; color: var(--muted); margin-bottom: 8px; }
.submit-row { display: flex; gap: 8px; }
.submit-row input {
  flex: 1;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-family: inherit;
  font-size: 0.95rem;
  outline: none;
  transition: border-color 0.2s;
}
.submit-row input:focus { border-color: var(--primary); }
.submit-row .btn { padding: 12px 18px; }
.submit-result { font-size: 0.85rem; margin-top: 10px; min-height: 1.2em; color: var(--success); }
.submit-result.error { color: #ef4444; }
.submit-box.done .submit-row { display: none; }

/* FAQ */
.faq-section { padding: 60px 0; }
.faq-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  margin-bottom: 12px;
  overflow: hidden;
  transition: border-color 0.2s;
}
.faq-item:hover { border-color: var(--primary); }
.faq-item summary {
  padding: 18px 22px;
  cursor: pointer;
  font-weight: 700;
  color: var(--text);
  font-size: 1.05rem;
  list-style: none;
  position: relative;
  user-select: none;
}
.faq-item summary::-webkit-details-marker { display: none; }
.faq-item summary::after {
  content: '+';
  position: absolute;
  right: 22px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 1.5rem;
  color: var(--primary);
  transition: transform 0.2s;
}
.faq-item[open] summary::after { content: '−'; }
.faq-item p {
  padding: 0 22px 22px;
  color: var(--muted);
  line-height: 1.75;
  margin: 0;
}

/* How section */
.how-section { padding: 80px 0; background: var(--bg-2); }
.steps {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 24px;
}
.step {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 30px;
}
.step-num {
  width: 44px; height: 44px;
  display: grid; place-items: center;
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
  color: white;
  font-weight: 800;
  border-radius: 12px;
  margin-bottom: 16px;
}
.step h3 { margin-bottom: 8px; font-size: 1.2rem; }
.step p { color: var(--muted); font-size: 0.95rem; }

/* Ads */
.ad-wrap {
  margin: 30px auto;
  min-height: 100px;
  text-align: center;
}

/* Interstitial ad */
.interstitial-overlay {
  position: fixed;
  inset: 0;
  background: rgba(10, 10, 20, 0.92);
  backdrop-filter: blur(6px);
  z-index: 1000;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
  animation: fadeIn 0.25s ease;
}
.interstitial-overlay.visible { display: flex; }
.interstitial-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 18px 22px;
  max-width: 640px;
  width: 100%;
  box-shadow: var(--shadow);
}
.interstitial-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
}
.interstitial-label {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: var(--muted);
  font-weight: 700;
}
.interstitial-close {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 1.4rem;
  cursor: pointer;
  font-family: inherit;
  display: grid;
  place-items: center;
  transition: all 0.2s;
}
.interstitial-close:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}
.interstitial-close:not(:disabled):hover {
  background: var(--accent);
  color: white;
  border-color: transparent;
}
.interstitial-ad-wrap {
  min-height: 280px;
  background: var(--surface-2);
  border-radius: 12px;
  display: grid;
  place-items: center;
  overflow: hidden;
}
.interstitial-footer {
  margin-top: 14px;
  text-align: center;
  font-size: 0.85rem;
  color: var(--muted);
  min-height: 1.2em;
}

/* Blog */
.blog-list { display: grid; gap: 20px; }
.blog-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  transition: transform 0.2s, border-color 0.2s;
}
.blog-card:hover { transform: translateY(-3px); border-color: var(--primary); }
.blog-card a {
  display: block;
  padding: 28px 30px;
  text-decoration: none;
  color: inherit;
}
.blog-card h2 {
  font-size: 1.45rem;
  margin-bottom: 10px;
  color: var(--text);
}
.blog-card p { color: var(--muted); margin-bottom: 12px; }
.blog-meta { color: var(--muted); font-size: 0.85rem; }
.article h1 { font-size: 2.2rem; margin-bottom: 12px; line-height: 1.2; }
.article h2 { font-size: 1.5rem; margin-top: 30px; margin-bottom: 12px; color: var(--text); }
.article p { color: var(--muted); margin-bottom: 14px; line-height: 1.75; font-size: 1.05rem; }
.article p strong { color: var(--text); }
.article p.lead { font-size: 1.2rem; color: var(--text); margin-bottom: 24px; }
.article ul { color: var(--muted); margin-left: 24px; margin-bottom: 18px; line-height: 1.8; }
.article ul li { margin-bottom: 8px; }
.article ul li strong { color: var(--text); }
.article code {
  background: var(--surface-2);
  padding: 2px 8px;
  border-radius: 6px;
  font-size: 0.92em;
  color: var(--accent);
}

/* Related videos grid */
.related-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 12px;
  margin: 20px 0;
}
.related-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  text-decoration: none;
  color: var(--text);
  font-weight: 600;
  font-size: 0.92rem;
  transition: all 0.2s;
}
.related-item:hover { border-color: var(--accent); transform: translateY(-2px); }
.related-emoji { font-size: 1.4rem; }

/* Footer */
.site-footer {
  border-top: 1px solid var(--border);
  background: var(--bg-2);
  padding: 40px 0;
  margin-top: 60px;
}
.footer-inner {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 20px;
}
.muted { color: var(--muted); font-size: 0.9rem; margin-top: 8px; }
.footer-links { display: flex; gap: 24px; }
.footer-links a {
  color: var(--muted);
  text-decoration: none;
  font-size: 0.95rem;
  transition: color 0.2s;
}
.footer-links a:hover { color: var(--primary); }

/* Responsive */
@media (max-width: 880px) {
  .hero { padding: 50px 0 40px; }
  .hero-inner { grid-template-columns: 1fr; gap: 40px; }
  .hero-visual { order: -1; }
  .hero-card { max-width: 360px; }
  .steps { grid-template-columns: 1fr; }
  .nav { display: none; }
  .game-controls { flex-direction: column; align-items: stretch; }
  .difficulty { justify-content: center; }
  .game-actions { justify-content: center; }
  .game-stats { gap: 16px; flex-wrap: wrap; }
  .stats { gap: 20px; }
}
