/* ═══════════════════════════════════════════════════════════════
   NeuroGames — Focus Zone Design System
   ADHD-friendly: purple primary · teal accent · gold rewards
   ═══════════════════════════════════════════════════════════════ */

/* ── Design Tokens ──────────────────────────────────────────── */
:root {
  /* Colour primitives */
  --purple-dark:  #4338CA;
  --purple:       #6D28D9;
  --purple-mid:   #7C3AED;
  --purple-light: #EDE9FE;
  --purple-pale:  #F5F3FF;
  --teal:         #0891B2;
  --teal-mid:     #0E7490;
  --teal-light:   #CFFAFE;
  --gold:         #D97706;
  --gold-light:   #FEF3C7;
  --green:        #059669;
  --green-light:  #D1FAE5;
  --coral:        #E11D48;
  --orange:       #EA580C;
  --indigo-dark:  #1E1B4B;
  --indigo-mid:   #312E81;
  --indigo:       #3730A3;

  /* Semantic aliases */
  --color-bg:          #EDE9FE;
  --color-bg-card:     #ffffff;
  --color-primary:     var(--purple);
  --color-accent:      var(--teal);
  --color-text:        var(--indigo-dark);
  --color-text-muted:  #A78BFA;
  --color-border:      #C4B5FD;

  /* Game colours (kept from original for canvas games) */
  --go-color:   #06d6a0;
  --nogo-color: #ef476f;

  /* Typography */
  --font-main: 'Nunito', 'Comic Sans MS', cursive;

  /* Radii */
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 20px;

  /* Easing */
  --ease-pop:    cubic-bezier(0.34, 1.56, 0.64, 1);
  --ease-smooth: cubic-bezier(0.4, 0, 0.2, 1);
}

/* ── Reset & Base ───────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  width: 100%; height: 100%;
  font-family: var(--font-main);
  background: var(--color-bg);
  color: var(--color-text);
  -webkit-font-smoothing: antialiased;
}

/* ── Screen System ──────────────────────────────────────────── */
.screen {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  overflow-y: auto;
  background: var(--color-bg);
  opacity: 0;
  pointer-events: none;
  transform: scale(0.97);
  transition: opacity 0.3s var(--ease-smooth), transform 0.3s var(--ease-smooth);
}
.screen.active {
  opacity: 1;
  pointer-events: all;
  transform: scale(1);
}

/* Game screen: overflow hidden so canvas fills exactly */
#screen-game {
  overflow: hidden;
  background: var(--indigo-dark);
  justify-content: flex-start;
  align-items: stretch;
}

/* Results screen: soft gradient background */
#screen-results {
  background: linear-gradient(160deg, var(--purple-pale) 0%, #EFF6FF 55%, var(--green-light) 100%);
}

/* Menu screen: tinted gradient */
#screen-menu {
  background: linear-gradient(135deg, var(--purple-light) 0%, #E0F2FE 100%);
  align-items: stretch;
}

/* ── ════════════════ LOGIN SCREEN ════════════════════════════ */

.login-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  width: 100%;
  max-width: 440px;
  padding: 20px 20px 48px;
}

/* Sound toggle */
.sound-row {
  display: flex;
  justify-content: flex-end;
  width: 100%;
}
.sound-btn {
  background: var(--purple-light);
  border: 1.5px solid var(--color-border);
  border-radius: 20px;
  padding: 6px 14px;
  font-size: 13px;
  font-family: var(--font-main);
  font-weight: 700;
  color: var(--purple-mid);
  cursor: pointer;
  transition: background 0.15s;
}
.sound-btn:hover { background: #DDD6FE; }

/* Brand */
.brand-logo {
  font-size: 72px;
  animation: float 3s ease-in-out infinite;
  filter: drop-shadow(0 0 20px rgba(109, 40, 217, 0.4));
}
@keyframes float {
  0%, 100% { transform: translateY(0); }
  50%       { transform: translateY(-10px); }
}
.brand-title {
  font-size: 2.8rem;
  font-weight: 900;
  color: var(--purple-dark);
  letter-spacing: -0.5px;
  text-align: center;
}
.brand-subtitle {
  font-size: 1rem;
  font-weight: 700;
  color: var(--purple-mid);
  margin-top: -6px;
}

/* Form Cards */
.form-card {
  width: 100%;
  background: var(--color-bg-card);
  border: 2px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 16px;
  box-shadow: 0 2px 10px rgba(109, 40, 217, 0.08);
}
.form-card-teal { border-color: #67E8F9; }
.form-card-gold  { border-color: #FCD34D; }

.form-label {
  display: block;
  font-size: 14px;
  font-weight: 800;
  color: var(--purple);
  margin-bottom: 10px;
}

.form-input {
  width: 100%;
  border: 2px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font-family: var(--font-main);
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--color-text);
  background: var(--purple-pale);
  outline: none;
  transition: border-color 0.2s, background 0.2s, box-shadow 0.2s;
}
.form-input:focus {
  border-color: var(--purple);
  background: #fff;
  box-shadow: 0 0 0 3px rgba(109, 40, 217, 0.15);
}

/* Avatar Grid */
.avatar-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}
.avatar-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 10px 4px;
  border: 2.5px solid #E5E7EB;
  border-radius: var(--radius-md);
  font-size: 28px;
  cursor: pointer;
  background: #F9FAFB;
  font-family: var(--font-main);
  transition: transform 0.15s var(--ease-pop), border-color 0.15s, box-shadow 0.15s;
}
.avatar-item:nth-child(1) { background: #FEF3C7; border-color: #F59E0B; }
.avatar-item:nth-child(2) { background: #DBEAFE; border-color: #60A5FA; }
.avatar-item:nth-child(3) { background: #D1FAE5; border-color: #34D399; }
.avatar-item:nth-child(4) { background: #FED7AA; border-color: #FB923C; }
.avatar-item:nth-child(5) { background: #EDE9FE; border-color: #A78BFA; }
.avatar-item:nth-child(6) { background: #FCE7F3; border-color: #F472B6; }
.avatar-item:nth-child(7) { background: #CFFAFE; border-color: #22D3EE; }
.avatar-item:nth-child(8) { background: #FDF4FF; border-color: #C084FC; }
.avatar-item.sel {
  border-width: 3px;
  box-shadow: 0 0 0 3px rgba(109, 40, 217, 0.28);
  transform: scale(1.08);
}
.avatar-name {
  font-size: 10px;
  font-weight: 700;
  color: #4B5563;
  line-height: 1;
}

/* Age Grid */
.age-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}
.age-btn {
  border: 2.5px solid #E5E7EB;
  border-radius: var(--radius-md);
  padding: 14px 4px;
  text-align: center;
  font-family: var(--font-main);
  font-size: 16px;
  font-weight: 800;
  cursor: pointer;
  line-height: 1.4;
  transition: all 0.15s var(--ease-pop);
}
.age-btn small { font-size: 11px; font-weight: 600; }
.age-btn-0 { background: #FFFBEB; border-color: #FCD34D; color: #92400E; }
.age-btn-1 { background: #F5F3FF; border-color: #A78BFA; color: #4338CA; }
.age-btn-2 { background: #EFF6FF; border-color: #93C5FD; color: #1E40AF; }
.age-btn.sel {
  border-width: 3px;
  box-shadow: 0 2px 12px rgba(109, 40, 217, 0.25);
  transform: scale(1.05);
}
.age-btn-1.sel { background: var(--purple-light); border-color: var(--purple); }

/* ── ════════════════════ BUTTONS ════════════════════════════ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: none;
  cursor: pointer;
  font-family: var(--font-main);
  font-weight: 800;
  border-radius: var(--radius-lg);
  transition: transform 0.15s var(--ease-pop), box-shadow 0.15s, background 0.2s;
  text-decoration: none;
}
.btn:active { transform: scale(0.93) !important; }

.btn-primary {
  background: linear-gradient(135deg, var(--purple) 0%, var(--purple-dark) 100%);
  color: #fff;
  padding: 13px 28px;
  font-size: 1.05rem;
  box-shadow: 0 4px 18px rgba(109, 40, 217, 0.4);
}
.btn-primary:hover {
  transform: translateY(-2px) scale(1.03);
  box-shadow: 0 8px 28px rgba(109, 40, 217, 0.5);
}

.btn-secondary {
  background: var(--color-bg-card);
  color: var(--purple);
  border: 2.5px solid var(--purple);
  padding: 13px 28px;
  font-size: 1.05rem;
}
.btn-secondary:hover {
  background: var(--purple-light);
  transform: translateY(-2px);
}

.btn-ghost {
  background: transparent;
  color: var(--purple-mid);
  border: 2px dashed var(--color-border);
  padding: 10px 20px;
  font-size: 0.95rem;
  border-radius: var(--radius-md);
}
.btn-ghost:hover { background: var(--purple-light); }

.btn-large {
  padding: 18px;
  font-size: 1.2rem;
  width: 100%;
  border-radius: var(--radius-lg);
}
.btn-sm { padding: 6px 14px; font-size: 0.85rem; border-radius: 10px; }

/* ── ════════════════ GAME MENU SCREEN ══════════════════════ */

/* Player Header — sticky at top */
.player-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 20px;
  background: linear-gradient(90deg, var(--purple-light) 0%, #E0F2FE 100%);
  border-bottom: 2px solid var(--color-border);
  position: sticky;
  top: 0;
  z-index: 10;
  flex-shrink: 0;
  width: 100%;
}
.player-avatar-circle {
  font-size: 26px;
  width: 48px; height: 48px; min-width: 48px;
  border: 2.5px solid var(--purple-mid);
  border-radius: 50%;
  background: var(--gold-light);
  display: flex;
  align-items: center;
  justify-content: center;
}
.player-info { flex: 1; min-width: 0; }
.player-name       { font-size: 16px; font-weight: 900; color: var(--purple-dark); }
.player-level-text { font-size: 12px; font-weight: 700; color: var(--purple-mid); }
.level-badge {
  background: var(--gold-light);
  border: 2px solid #FCD34D;
  border-radius: 20px;
  padding: 5px 14px;
  font-size: 13px;
  color: #92400E;
  font-weight: 800;
  white-space: nowrap;
}

/* Scrollable menu content area */
.menu-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  width: 100%;
  max-width: 440px;
  padding: 20px 20px 48px;
  /* centres within the full-width #screen-menu */
  align-self: center;
}

.page-title {
  font-size: 2rem;
  font-weight: 900;
  color: var(--purple-dark);
  text-align: center;
  margin-bottom: -4px;
}
.page-subtitle {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--purple-mid);
  text-align: center;
}

/* Carousel */
.carousel-area {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.carousel-arrows {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.carousel-arrow {
  background: var(--purple-light);
  border: 2px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 10px 16px;
  font-size: 15px;
  font-weight: 800;
  color: var(--purple);
  cursor: pointer;
  font-family: var(--font-main);
  transition: background 0.15s, transform 0.15s var(--ease-pop);
}
.carousel-arrow:hover  { background: #DDD6FE; transform: scale(1.08); }
.carousel-arrow:active { transform: scale(0.93); }

.carousel-counter {
  font-size: 14px;
  font-weight: 800;
  color: var(--purple-mid);
}
.carousel-card {
  background: linear-gradient(135deg, var(--purple-pale) 0%, #ffffff 100%);
  border: 2.5px solid var(--purple-mid);
  border-radius: 16px;
  padding: 28px 20px 20px;
  text-align: center;
  box-shadow: 0 6px 24px rgba(109, 40, 217, 0.15);
  animation: carouselIn 0.3s var(--ease-pop);
}
@keyframes carouselIn {
  from { transform: scale(0.92); opacity: 0.5; }
  to   { transform: scale(1);    opacity: 1; }
}
.carousel-icon  { font-size: 72px; display: block; margin-bottom: 10px; }
.carousel-name  { font-size: 22px; font-weight: 900; color: var(--purple-dark); margin-bottom: 6px; }
.carousel-skill { font-size: 14px; font-weight: 700; color: var(--purple-mid); margin-bottom: 10px; }
.carousel-stars { font-size: 26px; letter-spacing: 4px; color: var(--gold); }
.carousel-best  { font-size: 12px; font-weight: 700; color: var(--color-text-muted); margin-top: 6px; }

/* Dots */
.dots { display: flex; justify-content: center; gap: 8px; }
.dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  background: #DDD6FE;
  border: 1.5px solid var(--color-border);
  transition: all 0.3s var(--ease-smooth);
}
.dot.on {
  background: var(--purple);
  border-color: var(--purple);
  width: 26px;
  border-radius: 5px;
}

/* ── ════════════════ GAME SCREEN ═══════════════════════════ */

/* Dark Indigo HUD */
.game-hud {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-around;
  padding: 10px 12px;
  background: linear-gradient(90deg, var(--indigo-dark) 0%, var(--indigo-mid) 100%);
  border-bottom: 2px solid var(--indigo);
  flex-shrink: 0;
  z-index: 10;
}
.hud-block { text-align: center; }
.hud-lbl {
  font-size: 10px;
  color: #A78BFA;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-weight: 700;
  margin-bottom: 2px;
}
.hud-back {
  font-size: 22px;
  cursor: pointer;
  color: #C4B5FD;
  background: none;
  border: none;
  font-family: var(--font-main);
  font-weight: 900;
  padding: 2px 8px;
  border-radius: 6px;
  transition: background 0.15s;
}
.hud-back:hover { background: rgba(255,255,255,0.1); }
.hud-game-name {
  font-size: 16px;
  font-weight: 900;
  color: #fff;
}
.hud-val   { font-size: 18px; font-weight: 900; }
.hud-score { color: #FCD34D !important; }
.hud-time  { color: #67E8F9 !important; }

/* Progress Bar */
.progress-bar-container {
  width: 100%;
  height: 8px;
  background: rgba(255, 255, 255, 0.08);
  flex-shrink: 0;
  overflow: hidden;
}
.progress-bar-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--purple), var(--teal));
  transition: width 0.4s var(--ease-smooth);
  border-radius: 0 4px 4px 0;
}

/* Canvas */
#game-canvas {
  display: block;
  flex: 1;
  width: 100%;
  cursor: pointer;
  touch-action: none;
}

/* ── Instruction Overlay ────────────────────────────────────── */
.instruction-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(30, 27, 75, 0.87);
  backdrop-filter: blur(8px);
  z-index: 20;
  transition: opacity 0.3s;
}
.instruction-overlay.hidden { opacity: 0; pointer-events: none; }

.instruction-card {
  background: #fff;
  border: 2.5px solid var(--purple-mid);
  border-radius: var(--radius-lg);
  padding: 36px 28px;
  max-width: 400px;
  width: 90%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  box-shadow: 0 0 60px rgba(109, 40, 217, 0.3);
  animation: popIn 0.4s var(--ease-pop);
}
@keyframes popIn {
  from { transform: scale(0.8); opacity: 0; }
  to   { transform: scale(1);   opacity: 1; }
}
.instruction-icon  { font-size: 4rem; }
.instruction-title {
  font-size: 2rem;
  font-weight: 900;
  color: var(--purple-dark);
  text-align: center;
}
.instruction-text {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--purple-mid);
  text-align: center;
  line-height: 1.7;
  max-width: 320px;
  white-space: pre-line;
}

/* ── Feedback Overlay ───────────────────────────────────────── */
.feedback-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  z-index: 15;
}
.feedback-overlay.hidden { opacity: 0; }
.feedback-content {
  font-size: 5rem;
  font-weight: 900;
  animation: feedbackPop 0.4s var(--ease-pop);
  filter: drop-shadow(0 0 20px currentColor);
}
@keyframes feedbackPop {
  from { transform: scale(0.4); opacity: 0; }
  60%  { transform: scale(1.2); }
  to   { transform: scale(1);   opacity: 1; }
}

/* ── Round-End Overlay (between rounds) ─────────────────────── */
.round-end-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(30, 27, 75, 0.87);
  backdrop-filter: blur(8px);
  z-index: 20;
  transition: opacity 0.3s;
}
.round-end-overlay.hidden { opacity: 0; pointer-events: none; }

.round-end-card {
  background: linear-gradient(135deg, #ffffff 0%, var(--green-light) 100%);
  border: 2.5px solid var(--green);
  border-radius: var(--radius-lg);
  padding: 32px 28px;
  max-width: 400px;
  width: 90%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  box-shadow: 0 0 60px rgba(5, 150, 105, 0.3);
  animation: popIn 0.4s var(--ease-pop);
}
.round-end-emoji    { font-size: 3.5rem; }
.round-end-title    { font-size: 1.8rem; font-weight: 900; color: var(--green); text-align: center; }
.round-end-subtitle { font-size: 0.95rem; font-weight: 700; color: var(--teal-mid); text-align: center; }

.round-end-metrics {
  width: 100%;
  background: rgba(255,255,255,0.85);
  border: 1.5px solid #6EE7B7;
  border-radius: var(--radius-sm);
  padding: 6px 16px;
}
.round-end-metrics .metric-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px dashed #A7F3D0;
  font-size: 0.95rem;
}
.round-end-metrics .metric-row:last-child { border-bottom: none; }
.round-end-metrics .metric-label { color: var(--teal-mid); font-weight: 700; }
.round-end-metrics .metric-value { font-weight: 900; color: var(--green); font-size: 1rem; }

/* ── ════════════════ RESULTS SCREEN ════════════════════════ */
.results-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  padding: 32px 20px 52px;
  width: 100%;
  max-width: 480px;
}

.results-trophy {
  font-size: 5.5rem;
  animation: float 2.5s ease-in-out infinite;
  filter: drop-shadow(0 4px 16px rgba(217, 119, 6, 0.4));
}
.results-title {
  font-size: 2.4rem;
  font-weight: 900;
  color: var(--purple-dark);
  text-align: center;
}
.results-subtitle { color: var(--purple-mid); font-size: 1rem; font-weight: 700; }
.results-stars    { font-size: 2.4rem; letter-spacing: 6px; color: var(--gold); }

/* Encouragement Banner */
.encourage-banner {
  width: 100%;
  background: linear-gradient(135deg, var(--green-light) 0%, var(--teal-light) 100%);
  border: 2px solid #6EE7B7;
  border-radius: var(--radius-md);
  padding: 16px 20px;
  text-align: center;
}
.encourage-emoji  { font-size: 2.4rem; margin-bottom: 6px; }
.encourage-msg    { font-size: 1.05rem; font-weight: 900; color: var(--green); margin-bottom: 4px; }
.encourage-detail { font-size: 0.9rem;  font-weight: 700; color: var(--teal); }

/* Results Metrics */
.results-metrics {
  width: 100%;
  background: var(--color-bg-card);
  border: 2px solid #67E8F9;
  border-radius: var(--radius-md);
  padding: 8px 20px;
}
.metric-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1.5px dashed #DDD6FE;
  font-size: 1rem;
}
.metric-row:last-child { border-bottom: none; }
.metric-label { color: var(--purple-mid); font-weight: 700; }
.metric-value { font-weight: 900; color: var(--purple-dark); font-size: 1.05rem; }

/* Results Actions */
.results-actions {
  display: flex;
  gap: 14px;
  width: 100%;
}
.results-actions .btn { flex: 1; padding: 14px; font-size: 1rem; }

.results-upload-status {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--purple-mid);
  min-height: 20px;
  text-align: center;
  transition: color 0.3s;
}
.results-upload-status.ok    { color: var(--green); }
.results-upload-status.error { color: var(--coral); }

/* ── ════════════════ TOAST ═══════════════════════════════════ */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(80px);
  background: var(--purple-dark);
  color: #fff;
  border-radius: var(--radius-md);
  padding: 12px 24px;
  font-size: 0.95rem;
  font-weight: 800;
  z-index: 1000;
  transition: transform 0.3s var(--ease-pop), opacity 0.3s;
  box-shadow: 0 8px 32px rgba(67, 56, 202, 0.45);
  white-space: nowrap;
}
.toast.show   { transform: translateX(-50%) translateY(0); }
.toast.hidden { opacity: 0; }

/* ── ════════════════ UTILITIES ═══════════════════════════════ */
.hidden    { display: none !important; }
.invisible { visibility: hidden; }

/* Particle burst (correct answer celebration) */
@keyframes burst {
  0%   { transform: translate(0,0)                         scale(1); opacity: 1; }
  100% { transform: translate(var(--dx), var(--dy)) scale(0); opacity: 0; }
}
.particle {
  position: fixed;
  width: 12px; height: 12px;
  border-radius: 50%;
  pointer-events: none;
  z-index: 999;
  animation: burst 0.7s var(--ease-smooth) forwards;
}

/* ── RESPONSIVE ─────────────────────────────────────────────── */
@media (max-width: 480px) {
  .brand-title    { font-size: 2.2rem; }
  .brand-logo     { font-size: 56px; }
  .avatar-item    { font-size: 22px; padding: 8px 2px; }
  .avatar-name    { font-size: 9px; }
  .carousel-icon  { font-size: 56px; }
  .carousel-arrow { padding: 8px 12px; font-size: 14px; }
  .results-title  { font-size: 2rem; }
}
