/* ================================================================
   RESET & ROOT
================================================================ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:        #0F0F0F;
  --surface:   #1A1A1A;
  --surface2:  #252525;
  --text:      #F0F0F0;
  --muted:     #888;
  --accent:    #8B5CF6;
  --border:    rgba(255,255,255,0.08);
  --radius:    16px;
  --radius-sm: 10px;
  --nav-h:     49px;
}

html { height: 100%; }

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100%;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

/* ================================================================
   FLASH OVERLAY
================================================================ */
.flash-overlay {
  position: fixed;
  inset: 0;
  z-index: 999;
  pointer-events: none;
  opacity: 0;
}

.flash-overlay.flash-green {
  background: #10B981;
  animation: flashAnim 0.35s ease forwards;
}

.flash-overlay.flash-red {
  background: #EF4444;
  animation: flashAnim 0.4s ease forwards;
}

@keyframes flashAnim {
  0%   { opacity: 0.28; }
  100% { opacity: 0; }
}

/* ================================================================
   NAVBAR
================================================================ */
.navbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  height: var(--nav-h);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 100;
}

.nav-back {
  color: var(--muted);
  text-decoration: none;
  font-size: 0.85rem;
  font-weight: 500;
  transition: color 0.2s;
}
.nav-back:hover { color: var(--text); }

.nav-title {
  font-size: 0.95rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

/* ================================================================
   SCREENS
================================================================ */
.screen {
  display: none;
  max-width: 480px;
  margin: 0 auto;
}
.screen.active { display: block; }

/* ================================================================
   START SCREEN
================================================================ */
#screen-start {
  padding: 24px 20px 48px;
}

.start-hero { text-align: center; padding-bottom: 36px; }

.hero-icon {
  font-size: 64px;
  display: block;
  margin-bottom: 14px;
  animation: float 3s ease-in-out infinite;
}

@keyframes float {
  0%, 100% { transform: translateY(0); }
  50%       { transform: translateY(-10px); }
}

.game-title {
  font-size: clamp(2rem, 9vw, 2.8rem);
  font-weight: 900;
  letter-spacing: -0.03em;
  background: linear-gradient(135deg, #8B5CF6 0%, #EC4899 50%, #EF4444 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 8px;
}

.game-subtitle {
  color: var(--muted);
  font-size: 0.95rem;
  margin-bottom: 24px;
}

/* How-to box */
.how-box {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 28px;
  text-align: left;
}

.how-intro {
  font-size: 0.9rem;
  color: var(--muted);
  line-height: 1.7;
  margin-bottom: 18px;
}

.how-intro strong { color: var(--text); }

/* Demo card */
.demo-card {
  background: var(--surface2);
  border-radius: var(--radius-sm);
  padding: 18px 20px;
  text-align: center;
  border: 1px solid var(--border);
}

.demo-label {
  font-size: 0.6rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 10px;
}

.demo-word {
  font-size: clamp(2.4rem, 12vw, 3.5rem);
  font-weight: 900;
  letter-spacing: -0.02em;
  text-transform: uppercase;
  color: #EF4444; /* "GREEN" written in RED — the classic trick */
  margin-bottom: 8px;
  line-height: 1;
}

.demo-question {
  font-size: 0.78rem;
  color: var(--muted);
  margin-bottom: 8px;
}

.demo-answer {
  font-size: 0.9rem;
  font-weight: 600;
}

.demo-answer strong { color: #EF4444; }
.demo-note { color: var(--muted); font-size: 0.8rem; font-weight: 400; }

/* ================================================================
   BUTTONS
================================================================ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: inherit;
  font-weight: 700;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  transition: transform 0.1s, opacity 0.15s;
  -webkit-tap-highlight-color: transparent;
  text-decoration: none;
}
.btn:active:not(:disabled) { transform: scale(0.95); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

.btn-primary {
  background: var(--accent);
  color: #fff;
  padding: 14px 28px;
  font-size: 1rem;
  transition: transform 0.1s, background-color 0.3s;
}

.btn-secondary {
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 12px 24px;
  font-size: 0.95rem;
  width: 100%;
}

.btn-xl {
  padding: 18px 40px;
  font-size: 1.05rem;
  border-radius: 100px;
  width: 100%;
}

.btn-lg {
  padding: 16px 32px;
  font-size: 1rem;
  width: 100%;
}

.btn-sm { padding: 6px 12px; font-size: 0.8rem; border-radius: 8px; }

.btn-outline {
  background: transparent;
  border: 2px solid var(--border);
  color: var(--text);
  padding: 14px 28px;
  font-size: 1rem;
}

.btn-ghost {
  background: transparent;
  color: var(--muted);
  padding: 6px 12px;
  font-size: 0.8rem;
  border-radius: 8px;
}
.btn-ghost:hover { background: var(--surface); color: var(--text); }

.pulse-btn { animation: btnPulse 2s ease-in-out infinite; }

@keyframes btnPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(139, 92, 246, 0.45); }
  50%       { box-shadow: 0 0 0 18px rgba(139, 92, 246, 0); }
}

/* ================================================================
   GAME SCREEN
================================================================ */
#screen-game {
  height: calc(100dvh - var(--nav-h));
  display: flex;
  flex-direction: column;
  padding: 12px 16px 14px;
  overflow-y: auto;
}

/* HUD */
.game-hud {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  margin-bottom: 10px;
}

.lives-display {
  font-size: 1.2rem;
  letter-spacing: 1px;
  flex-shrink: 0;
}

.lives-display.flash-red {
  animation: livesShake 0.4s ease;
}

@keyframes livesShake {
  0%, 100% { transform: scale(1); }
  35%       { transform: scale(1.3); filter: drop-shadow(0 0 6px #EF4444); }
}

.score-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 1;
}

.score-label {
  font-size: 0.58rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  color: var(--muted);
  margin-bottom: 2px;
}

.score-display {
  font-size: 1.9rem;
  font-weight: 900;
  letter-spacing: -0.03em;
}

.score-display.score-pop { animation: scorePop 0.22s ease; }

@keyframes scorePop {
  0%   { transform: scale(1); }
  50%  { transform: scale(1.35); }
  100% { transform: scale(1); }
}

/* Streak display */
.streak-display {
  font-size: 0.8rem;
  font-weight: 800;
  letter-spacing: 0.02em;
  min-width: 60px;
  text-align: right;
  flex-shrink: 0;
}

.streak-display.streak-active {
  animation: streakPulse 0.8s ease-in-out infinite alternate;
}

@keyframes streakPulse {
  from { opacity: 0.8; }
  to   { opacity: 1; filter: drop-shadow(0 0 4px currentColor); }
}

/* Level row */
.level-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  margin-bottom: 10px;
}

.level-badge {
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  border: 2px solid var(--accent);
  color: var(--accent);
  border-radius: 100px;
  padding: 4px 11px;
  transition: color 0.4s, border-color 0.4s;
}

.round-counter {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--muted);
}

/* Stroop section */
.stroop-section {
  flex-shrink: 0;
  margin-bottom: 14px;
}

.timer-bar-wrap { margin-bottom: 10px; }

.timer-bar {
  width: 100%;
  height: 5px;
  background: var(--surface2);
  border-radius: 3px;
  overflow: hidden;
}

.timer-bar-fill {
  height: 100%;
  width: 100%;
  border-radius: 3px;
  background: var(--accent);
}

/* Stroop card */
.stroop-card {
  background: var(--surface);
  border-radius: 20px;
  padding: 20px 16px;
  text-align: center;
  border: 1px solid var(--border);
}

.question-text {
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 14px;
}

.stroop-word-wrap {
  min-height: clamp(70px, 18vw, 100px);
  display: flex;
  align-items: center;
  justify-content: center;
}

.stroop-word {
  font-size: clamp(3rem, 15vw, 5.5rem);
  font-weight: 900;
  letter-spacing: -0.02em;
  text-transform: uppercase;
  line-height: 1;
  /* color set dynamically via JS */
}

.stroop-word.appear {
  animation: wordAppear 0.18s ease;
}

@keyframes wordAppear {
  0%   { transform: scale(0.7) translateY(6px); opacity: 0; }
  100% { transform: scale(1) translateY(0); opacity: 1; }
}

.stroop-word.correct-flash {
  animation: wordCorrect 0.3s ease;
}

@keyframes wordCorrect {
  0%   { transform: scale(1); }
  45%  { transform: scale(1.15); filter: brightness(1.6); }
  100% { transform: scale(1); filter: none; }
}

.stroop-word.shake {
  animation: wordShake 0.4s ease;
}

@keyframes wordShake {
  0%, 100% { transform: translateX(0); }
  18%       { transform: translateX(-10px); }
  36%       { transform: translateX(10px); }
  54%       { transform: translateX(-7px); }
  72%       { transform: translateX(7px); }
}

/* Color grid */
.color-grid {
  flex: 1;
  display: grid;
  gap: 9px;
  min-height: 160px;
  max-height: 400px;
  align-content: stretch;
  /* grid-template-columns set dynamically by JS */
}

.color-btn {
  width: 100%;
  height: 100%;
  min-height: 52px;
  border: none;
  border-radius: 14px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: inherit;
  font-size: clamp(0.7rem, 2.5vw, 0.9rem);
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  box-shadow: 0 3px 12px rgba(0,0,0,0.35);
  touch-action: manipulation;
  transition: transform 0.08s, box-shadow 0.1s;
  position: relative;
  overflow: hidden;
}

.color-btn::after {
  content: '';
  position: absolute;
  inset: 0;
  background: rgba(255,255,255,0);
  transition: background 0.12s;
  border-radius: inherit;
}
.color-btn:active::after { background: rgba(255,255,255,0.18); }

.color-btn.correct-tap { animation: btnCorrect 0.3s ease forwards; }

@keyframes btnCorrect {
  0%   { transform: scale(1); }
  40%  { transform: scale(1.1); box-shadow: 0 0 0 8px rgba(255,255,255,0.15); }
  100% { transform: scale(1); }
}

.color-btn.wrong-tap { animation: btnWrong 0.4s ease forwards; }

@keyframes btnWrong {
  0%, 100% { transform: scale(1); }
  20%       { transform: scale(0.92); filter: brightness(0.6); }
  60%       { transform: scale(0.96); filter: brightness(0.8); }
}

/* ================================================================
   BETWEEN LEVELS SCREEN
================================================================ */
#screen-between {
  padding: 20px 20px 40px;
}

.between-wrap {
  text-align: center;
  padding-top: 40px;
}

.between-icon { font-size: 56px; margin-bottom: 12px; }

.between-title {
  font-size: 1.8rem;
  font-weight: 900;
  letter-spacing: -0.02em;
  margin-bottom: 28px;
}

.between-stats {
  display: flex;
  gap: 14px;
  justify-content: center;
  margin-bottom: 32px;
}

.bstat {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 18px 28px;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 100px;
}

.bstat-label {
  font-size: 0.6rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  color: var(--muted);
  margin-bottom: 6px;
}

.bstat-value {
  font-size: 2.2rem;
  font-weight: 900;
  letter-spacing: -0.03em;
  background: linear-gradient(135deg, #8B5CF6, #EC4899);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

/* ================================================================
   GAME OVER SCREEN
================================================================ */
#screen-gameover {
  padding: 20px 20px 48px;
}

.gameover-wrap {
  text-align: center;
  max-width: 400px;
  margin: 0 auto;
}

.go-icon { font-size: 52px; margin-bottom: 10px; }

.go-title {
  font-size: 2rem;
  font-weight: 900;
  letter-spacing: -0.03em;
  margin-bottom: 20px;
}

.go-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 14px;
}

.go-stat {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 14px 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.go-stat-label {
  font-size: 0.58rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 4px;
}

.go-stat-value {
  font-size: 2rem;
  font-weight: 900;
  letter-spacing: -0.03em;
  line-height: 1;
}

.go-stat-value.score-val {
  background: linear-gradient(135deg, #8B5CF6, #EC4899);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.go-stat-value.streak-val { color: #F97316; }

.go-detail {
  font-size: 0.82rem;
  color: var(--muted);
  margin-bottom: 8px;
}

.go-brain-rating {
  font-size: 1rem;
  font-weight: 700;
  margin-bottom: 22px;
  padding: 10px 16px;
  background: var(--surface);
  border-radius: var(--radius-sm);
  line-height: 1.5;
}

/* Submit box */
.submit-box {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 20px;
  text-align: left;
}

.submit-title {
  font-size: 0.875rem;
  font-weight: 700;
  margin-bottom: 12px;
}

.submit-row {
  display: flex;
  gap: 10px;
  margin-bottom: 8px;
}

.nickname-input {
  flex: 1;
  min-width: 0;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: inherit;
  font-size: 0.95rem;
  padding: 11px 13px;
  outline: none;
  transition: border-color 0.2s;
}
.nickname-input:focus { border-color: var(--accent); }

.submit-msg {
  font-size: 0.83rem;
  color: var(--accent);
  min-height: 18px;
}

/* Share box */
.share-box { margin-bottom: 20px; }
.share-box.hidden { display: none; }

.share-preview {
  background: var(--surface2);
  border-radius: var(--radius-sm);
  padding: 14px;
  font-size: 0.82rem;
  color: var(--muted);
  white-space: pre-line;
  text-align: left;
  margin-bottom: 10px;
  border: 1px solid var(--border);
  line-height: 1.6;
}

.copy-msg {
  font-size: 0.82rem;
  color: #10B981;
  text-align: center;
  margin-top: 8px;
  min-height: 18px;
}

/* Leaderboard */
.leaderboard-section { margin-top: 4px; }

.lb-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.lb-title { font-size: 0.95rem; font-weight: 700; }

.lb-container {
  background: var(--surface);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 20px;
}

.lb-loading, .lb-empty {
  padding: 20px;
  text-align: center;
  color: var(--muted);
  font-size: 0.875rem;
}

.lb-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
}

.lb-table thead tr { border-bottom: 1px solid var(--border); }

.lb-table th {
  padding: 9px 12px;
  text-align: left;
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

.lb-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}

.lb-table tbody tr:last-child td { border-bottom: none; }
.lb-table tbody tr.my-row { background: rgba(139, 92, 246, 0.1); }
.lb-table tbody tr.my-row td { color: var(--accent); font-weight: 700; }

.lb-challenge {
  padding: 10px 12px;
  font-size: 0.75rem;
  color: var(--muted);
  text-align: center;
  border-top: 1px solid var(--border);
}

#btn-play-again { margin-top: 4px; }

/* ================================================================
   TOAST
================================================================ */
.toast {
  position: fixed;
  bottom: 28px;
  left: 50%;
  transform: translateX(-50%) translateY(80px);
  background: var(--surface2);
  color: var(--text);
  padding: 11px 20px;
  border-radius: 100px;
  font-size: 0.9rem;
  font-weight: 600;
  opacity: 0;
  transition: transform 0.28s ease, opacity 0.28s ease;
  pointer-events: none;
  z-index: 1000;
  white-space: nowrap;
  box-shadow: 0 4px 24px rgba(0,0,0,0.5);
  border: 1px solid var(--border);
}

.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ================================================================
   RESPONSIVE
================================================================ */
@media (max-height: 680px) {
  .stroop-card { padding: 14px 12px; }

  .stroop-word-wrap { min-height: 64px; }

  .stroop-word { font-size: clamp(2.4rem, 13vw, 4rem); }

  .game-hud { margin-bottom: 8px; }

  .level-row { margin-bottom: 8px; }

  .stroop-section { margin-bottom: 10px; }

  .color-grid { gap: 7px; }
}
