/* ── Reset & Base ───────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --bg:        #F0F4FF;
  --card:      #FFFFFF;
  --primary:   #4F46E5;
  --primary-d: #3730A3;
  --text:      #1E1B4B;
  --muted:     #6B7280;
  --border:    #E5E7EB;
  --radius:    16px;
  --radius-sm: 10px;
  /* category colors */
  --physical:  #10B981;
  --motor:     #3B82F6;
  --cognitive: #8B5CF6;
  --learning:  #F59E0B;
  /* score */
  --gold:      #F59E0B;
  --gold-bg:   #FFFBEB;
}

html, body {
  height: 100%;
  font-family: 'Segoe UI', system-ui, sans-serif;
  font-size: 18px;
  background: var(--bg);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}

/* ── Layout shell ───────────────────────────────────────────────────────────── */
#app { min-height: 100vh; display: flex; flex-direction: column; }

/* ── Score bar (always on top when logged in) ─────────────────────────────── */
#score-bar {
  position: sticky; top: 0; z-index: 100;
  background: var(--primary);
  color: white;
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px;
  gap: 12px;
  box-shadow: 0 2px 8px rgba(0,0,0,.2);
}
#score-bar.hidden { display: none; }
#score-bar .greeting { font-weight: 700; font-size: 1rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#score-bar .scores { display: flex; gap: 10px; align-items: center; flex-shrink: 0; }
#score-bar .badge {
  background: rgba(255,255,255,.15);
  border-radius: 20px;
  padding: 4px 12px;
  font-size: 0.85rem;
  font-weight: 600;
  white-space: nowrap;
}
#score-bar .badge.gold { background: var(--gold); color: #1E1B4B; }
#score-bar .nav-btn {
  background: rgba(255,255,255,.2);
  border: none; border-radius: 8px;
  color: white; cursor: pointer;
  padding: 6px 12px; font-size: 0.85rem;
}
#score-bar .nav-btn:active { background: rgba(255,255,255,.35); }

/* ── Progress strips under score bar ─────────────────────────────────────── */
#progress-strips { display: flex; height: 8px; background: var(--border); }
#progress-strips.hidden { display: none; }
#strip-day   { background: var(--gold); transition: width .5s ease; }
#strip-month { background: var(--primary); opacity: .5; transition: width .5s ease; }

/* ── Main content ─────────────────────────────────────────────────────────── */
#main { flex: 1; padding: 16px; max-width: 600px; width: 100%; margin: 0 auto; }

/* ── Auth forms ────────────────────────────────────────────────────────────── */
.auth-wrap {
  min-height: 100vh; display: flex; flex-direction: column;
  align-items: center; justify-content: center; padding: 24px;
}
.auth-logo { font-size: 3rem; margin-bottom: 8px; }
.auth-title { font-size: 1.6rem; font-weight: 800; color: var(--primary); margin-bottom: 4px; text-align: center; }
.auth-sub   { color: var(--muted); font-size: 0.95rem; margin-bottom: 28px; text-align: center; }
.auth-card  { background: var(--card); border-radius: var(--radius); padding: 28px 24px; width: 100%; max-width: 400px; box-shadow: 0 4px 24px rgba(0,0,0,.08); }
.auth-card h2 { font-size: 1.3rem; font-weight: 700; margin-bottom: 20px; }
.field-group { margin-bottom: 16px; }
.field-group label { display: block; font-weight: 600; margin-bottom: 6px; font-size: 0.95rem; }
.field-group input {
  width: 100%; padding: 14px 16px; border: 2px solid var(--border);
  border-radius: var(--radius-sm); font-size: 1rem;
  transition: border-color .2s;
  background: #FAFAFA;
}
.field-group input:focus { outline: none; border-color: var(--primary); background: white; }
.btn-primary {
  display: block; width: 100%; padding: 16px;
  background: var(--primary); color: white; font-size: 1.1rem; font-weight: 700;
  border: none; border-radius: var(--radius-sm); cursor: pointer;
  margin-top: 8px; transition: background .15s;
}
.btn-primary:active { background: var(--primary-d); }
.auth-switch { text-align: center; margin-top: 16px; font-size: 0.95rem; color: var(--muted); }
.auth-switch a { color: var(--primary); font-weight: 600; cursor: pointer; text-decoration: none; }
.error-msg { background: #FEE2E2; color: #B91C1C; border-radius: 8px; padding: 10px 14px; margin-bottom: 14px; font-size: 0.9rem; }

/* ── Home screen ────────────────────────────────────────────────────────────── */
.home-header { margin-bottom: 20px; }
.home-header h1 { font-size: 1.4rem; font-weight: 800; }
.home-header .sub { color: var(--muted); font-size: 0.95rem; margin-top: 2px; }

/* Daily goal card */
.goal-card {
  background: var(--card); border-radius: var(--radius); padding: 18px;
  margin-bottom: 20px; box-shadow: 0 2px 12px rgba(0,0,0,.06);
}
.goal-card .goal-row { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.goal-card .goal-label { font-weight: 600; font-size: 1rem; }
.goal-card .goal-pts { font-size: 1.1rem; font-weight: 800; color: var(--primary); }
.progress-bar-wrap { background: var(--border); border-radius: 99px; height: 14px; overflow: hidden; margin-bottom: 6px; }
.progress-bar-fill { height: 100%; border-radius: 99px; transition: width .5s ease; }
.fill-day   { background: linear-gradient(90deg, var(--gold), #FCD34D); }
.fill-month { background: linear-gradient(90deg, var(--primary), #818CF8); }
.goal-sub { font-size: 0.82rem; color: var(--muted); }

/* Streak badge */
.streak-row { display: flex; align-items: center; gap: 8px; margin-top: 12px; font-size: 0.9rem; color: var(--muted); }
.streak-pill { background: #FFF7ED; color: #C2410C; font-weight: 700; border-radius: 20px; padding: 2px 10px; font-size: 0.9rem; }

/* Section labels */
.section-label {
  font-size: 0.8rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: .08em; color: var(--muted); margin: 18px 0 10px;
}

/* Activity grid */
.activity-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 12px; }
.activity-card {
  background: var(--card); border-radius: var(--radius); padding: 16px;
  cursor: pointer; position: relative; overflow: hidden;
  box-shadow: 0 2px 8px rgba(0,0,0,.06);
  border: 2px solid transparent;
  transition: transform .1s, box-shadow .1s, border-color .2s;
  -webkit-user-select: none; user-select: none;
}
.activity-card:active { transform: scale(.97); box-shadow: 0 1px 4px rgba(0,0,0,.1); }
.activity-card.done { border-color: var(--physical); opacity: .8; }
.activity-card.capped { opacity: .55; cursor: default; }
.activity-card .cat-stripe {
  position: absolute; top: 0; left: 0; right: 0; height: 4px; border-radius: 2px 2px 0 0;
}
.cat-physical  { background: var(--physical); }
.cat-motor     { background: var(--motor); }
.cat-cognitive { background: var(--cognitive); }
.cat-learning  { background: var(--learning); }
.activity-card .icon { font-size: 2rem; margin-bottom: 6px; margin-top: 6px; }
.activity-card .act-name { font-size: 0.92rem; font-weight: 700; line-height: 1.2; margin-bottom: 6px; }
.activity-card .act-pts {
  font-size: 0.82rem; font-weight: 600; color: var(--muted);
  display: flex; align-items: center; gap: 4px;
}
.activity-card .act-pts .earned { color: var(--primary); }
.cap-bar-wrap { background: var(--border); border-radius: 99px; height: 5px; margin-top: 8px; }
.cap-bar-fill { height: 100%; border-radius: 99px; }

/* ── Activity / Game screen ─────────────────────────────────────────────────── */
.game-screen { display: flex; flex-direction: column; min-height: calc(100vh - 80px); }
.game-header { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; }
.back-btn {
  background: var(--card); border: 2px solid var(--border);
  border-radius: 10px; padding: 10px 14px; font-size: 1rem;
  cursor: pointer; font-weight: 700;
}
.game-header h2 { font-size: 1.2rem; font-weight: 800; flex: 1; }
.pts-badge { background: var(--gold-bg); color: #92400E; font-weight: 700; border-radius: 20px; padding: 4px 12px; font-size: 0.9rem; white-space: nowrap; }

.game-area { flex: 1; display: flex; flex-direction: column; gap: 16px; }

/* Canvas wrapper */
.canvas-wrap { background: var(--card); border-radius: var(--radius); overflow: hidden; box-shadow: 0 2px 12px rgba(0,0,0,.08); }
canvas { display: block; width: 100%; touch-action: none; }

/* Game info bar */
.game-info { display: flex; gap: 10px; }
.info-pill {
  flex: 1; background: var(--card); border-radius: var(--radius-sm); padding: 10px;
  text-align: center; box-shadow: 0 1px 4px rgba(0,0,0,.05);
}
.info-pill .val { font-size: 1.4rem; font-weight: 800; }
.info-pill .lbl { font-size: 0.75rem; color: var(--muted); font-weight: 600; }

/* Physical activity UI */
.physical-card {
  background: var(--card); border-radius: var(--radius); padding: 24px;
  text-align: center; box-shadow: 0 2px 12px rgba(0,0,0,.08);
}
.physical-card .big-icon { font-size: 5rem; margin-bottom: 16px; }
.physical-card h3 { font-size: 1.3rem; font-weight: 800; margin-bottom: 10px; }
.physical-card .instructions { color: var(--muted); font-size: 1rem; line-height: 1.6; margin-bottom: 20px; }
.physical-card .timer-display { font-size: 3.5rem; font-weight: 900; color: var(--primary); margin-bottom: 8px; font-variant-numeric: tabular-nums; }
.physical-card .reps-display { font-size: 3rem; font-weight: 900; color: var(--physical); }
.big-btn {
  display: block; width: 100%; padding: 18px;
  font-size: 1.15rem; font-weight: 800; border: none;
  border-radius: var(--radius-sm); cursor: pointer; margin-top: 8px;
  transition: transform .1s;
}
.big-btn:active { transform: scale(.97); }
.big-btn.green  { background: var(--physical); color: white; }
.big-btn.blue   { background: var(--primary); color: white; }
.big-btn.red    { background: #EF4444; color: white; }
.big-btn.gold   { background: var(--gold); color: #1E1B4B; }
.big-btn:disabled { opacity: .5; cursor: default; }

/* Result screen */
.result-card {
  background: var(--card); border-radius: var(--radius); padding: 28px;
  text-align: center; box-shadow: 0 4px 24px rgba(0,0,0,.1);
}
.result-card .result-icon { font-size: 5rem; margin-bottom: 12px; }
.result-card h2 { font-size: 1.5rem; font-weight: 800; margin-bottom: 8px; }
.result-card .pts-earned { font-size: 3rem; font-weight: 900; color: var(--gold); margin: 12px 0; }
.result-card .pts-lbl { font-size: 1rem; color: var(--muted); margin-bottom: 20px; }

/* ── Progress / History screen ──────────────────────────────────────────────── */
.progress-section { background: var(--card); border-radius: var(--radius); padding: 20px; margin-bottom: 16px; box-shadow: 0 2px 8px rgba(0,0,0,.06); }
.progress-section h3 { font-weight: 800; margin-bottom: 14px; }
.stat-row { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; margin-bottom: 0; }
.stat-box { text-align: center; background: var(--bg); border-radius: var(--radius-sm); padding: 14px 8px; }
.stat-box .sv { font-size: 1.6rem; font-weight: 900; color: var(--primary); }
.stat-box .sl { font-size: 0.75rem; color: var(--muted); font-weight: 600; margin-top: 2px; }

/* Bar chart */
.chart-wrap { overflow-x: auto; padding-bottom: 6px; }
.bar-chart { display: flex; align-items: flex-end; gap: 4px; height: 100px; min-width: 400px; }
.bar-col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 3px; }
.bar-fill { width: 100%; min-height: 2px; border-radius: 4px 4px 0 0; background: var(--primary); opacity: .7; }
.bar-lbl  { font-size: 0.6rem; color: var(--muted); }

/* Activity breakdown list */
.activity-list-item { display: flex; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--border); gap: 10px; }
.activity-list-item:last-child { border-bottom: none; }
.ali-icon { font-size: 1.4rem; }
.ali-info { flex: 1; }
.ali-name { font-weight: 600; font-size: 0.9rem; }
.ali-earned { font-size: 0.8rem; color: var(--muted); }
.ali-pts { font-weight: 800; color: var(--primary); font-size: 0.95rem; }

/* ── Cognitive/matching games ────────────────────────────────────────────────── */
.game-grid { display: grid; gap: 10px; }
.game-cell {
  aspect-ratio: 1; border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  font-size: 2rem; cursor: pointer; border: 3px solid transparent;
  transition: transform .1s, border-color .15s;
  -webkit-user-select: none; user-select: none;
}
.game-cell:active { transform: scale(.93); }

/* Simon/Memory lights */
.simon-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; max-width: 300px; margin: 0 auto; }
.simon-btn { aspect-ratio: 1; border-radius: var(--radius); border: none; cursor: pointer; opacity: .55; transition: opacity .15s; }
.simon-btn.lit { opacity: 1; filter: brightness(1.3); }

/* Card match */
.card-grid { display: grid; gap: 8px; }
.match-card {
  aspect-ratio: 1; border-radius: var(--radius-sm); border: 3px solid var(--border);
  background: var(--primary); color: white; font-size: 2rem;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; transition: transform .1s;
  -webkit-user-select: none; user-select: none;
}
.match-card.flipped { background: var(--card); color: var(--text); border-color: var(--primary); }
.match-card.matched  { background: #D1FAE5; border-color: var(--physical); }
.match-card:active:not(.matched) { transform: scale(.93); }

/* Sort-it */
.sort-items { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; margin-bottom: 16px; min-height: 60px; }
.sort-item { background: var(--card); border: 2px solid var(--border); border-radius: 10px; padding: 10px 14px; font-size: 1.1rem; cursor: pointer; font-weight: 600; }
.sort-item.selected { border-color: var(--primary); background: #EEF2FF; }
.sort-bins  { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.sort-bin   { background: var(--card); border: 2px dashed var(--border); border-radius: var(--radius-sm); padding: 12px 8px; min-height: 80px; cursor: pointer; transition: border-color .15s; }
.sort-bin.highlight { border-color: var(--primary); background: #EEF2FF; }
.sort-bin .bin-label { font-size: 0.8rem; font-weight: 700; text-transform: uppercase; color: var(--muted); margin-bottom: 8px; }
.sort-bin .bin-items { display: flex; flex-wrap: wrap; gap: 4px; }
.bin-item { font-size: 0.85rem; background: var(--primary); color: white; border-radius: 6px; padding: 2px 6px; }

/* Pattern / MCQ games */
.pattern-row { display: flex; align-items: center; gap: 8px; justify-content: center; margin-bottom: 20px; flex-wrap: wrap; }
.pattern-item { background: var(--card); border-radius: var(--radius-sm); padding: 12px 16px; font-size: 1.6rem; font-weight: 800; box-shadow: 0 2px 6px rgba(0,0,0,.08); }
.pattern-item.blank { background: var(--primary); color: transparent; border: 3px dashed white; }
.mcq-options { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.mcq-btn {
  background: var(--card); border: 3px solid var(--border); border-radius: var(--radius-sm);
  padding: 16px; font-size: 1.4rem; font-weight: 800; cursor: pointer;
  transition: border-color .15s; text-align: center;
}
.mcq-btn:active { transform: scale(.95); }
.mcq-btn.correct { border-color: var(--physical); background: #D1FAE5; }
.mcq-btn.wrong   { border-color: #EF4444; background: #FEE2E2; }

/* Number fun */
.math-display { background: var(--card); border-radius: var(--radius); padding: 24px; text-align: center; margin-bottom: 16px; }
.math-q { font-size: 2rem; font-weight: 900; }
.math-input { width: 100%; text-align: center; font-size: 2rem; font-weight: 800; border: 3px solid var(--border); border-radius: var(--radius-sm); padding: 12px; }
.math-input:focus { outline: none; border-color: var(--primary); }

/* Loading spinner */
.spinner { text-align: center; padding: 40px; font-size: 2rem; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Go/no-go (Tap this not that) ────────────────────────────────────────── */
.tap-arena { background: var(--card); border-radius: var(--radius); min-height: 340px; position: relative; overflow: hidden; box-shadow: 0 2px 12px rgba(0,0,0,.08); }
.tap-target { position: absolute; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 1.6rem; font-weight: 800; cursor: pointer; transition: transform .1s; -webkit-user-select: none; user-select: none; }
.tap-target:active { transform: scale(.85); }
.tap-target.tap   { background: var(--physical); color: white; }
.tap-target.notap { background: #EF4444; color: white; }

/* ── Camera preview ──────────────────────────────────────────────────────── */
.camera-wrap {
  background: #000;
  border-radius: var(--radius);
  overflow: hidden;
  position: relative;
  margin-bottom: 14px;
  box-shadow: 0 2px 12px rgba(0,0,0,.2);
}
.camera-wrap video {
  width: 100%;
  display: block;
  transform: scaleX(-1); /* mirror front camera */
  max-height: 220px;
  object-fit: cover;
}
.camera-badge {
  position: absolute;
  top: 10px; left: 10px;
  background: rgba(239,68,68,.9);
  color: white;
  font-size: 0.75rem;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 20px;
  display: flex;
  align-items: center;
  gap: 5px;
}
.camera-badge::before {
  content: '';
  width: 8px; height: 8px;
  background: white;
  border-radius: 50%;
  animation: blink 1s ease-in-out infinite;
}
@keyframes blink { 0%,100%{opacity:1} 50%{opacity:.2} }
.camera-off {
  background: #1E1B4B;
  border-radius: var(--radius);
  padding: 24px;
  text-align: center;
  color: #818CF8;
  font-size: 0.9rem;
  margin-bottom: 14px;
}
.camera-off .cam-icon { font-size: 2.5rem; margin-bottom: 8px; }

/* ── Utilities ────────────────────────────────────────────────────────────── */
.mt-8  { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mt-24 { margin-top: 24px; }
.text-center { text-align: center; }
.text-muted  { color: var(--muted); }
.hidden { display: none !important; }

/* ── Scrollbar ────────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
