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

:root {
  --bg:        #0f1117;
  --surface:   #1a1d27;
  --surface2:  #22263a;
  --border:    #2e3349;
  --text:      #e8eaf6;
  --text-muted:#8b91b0;
  --accent:    #4ECDC4;
  --green:     #4CAF50;
  --red:       #E74C3C;
  --radius:    14px;
  --radius-sm: 8px;
}

html { font-size: 16px; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

/* ── Screens ───────────────────────────────────────────────────────────────── */
.screen { display: none; max-width: 640px; margin: 0 auto; padding: 24px 16px 64px; }
.screen.active { display: block; animation: fadeIn .2s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ── Auth screen ───────────────────────────────────────────────────────────── */
#screen-auth { align-items: center; justify-content: center; min-height: 100vh; padding: 24px 16px; max-width: 100%; }
#screen-auth.active { display: flex; }

.auth-wrap { width: 100%; max-width: 400px; text-align: center; }
.auth-logo  { font-size: 56px; margin-bottom: 8px; }
.auth-brand { font-size: 1.8rem; font-weight: 800; letter-spacing: -.5px; margin-bottom: 28px; }

.auth-form  { display: flex; flex-direction: column; gap: 12px; margin-bottom: 16px; }
.auth-input {
  width: 100%; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm); color: var(--text); font-size: .95rem;
  padding: 12px 14px; outline: none; transition: border-color .15s;
}
.auth-input:focus { border-color: var(--accent); }
.auth-input::placeholder { color: var(--text-muted); }

.auth-error {
  background: #E74C3C18; border: 1px solid #E74C3C40; color: #E74C3C;
  border-radius: var(--radius-sm); padding: 10px 12px; font-size: .85rem; text-align: left;
}

.auth-switch { font-size: .85rem; color: var(--text-muted); }
.link-btn {
  background: none; border: none; color: var(--accent); cursor: pointer;
  font-size: inherit; text-decoration: underline; padding: 0;
}

/* ── App header ────────────────────────────────────────────────────────────── */
header { margin-bottom: 20px; }
.header-row {
  display: flex; justify-content: space-between; align-items: center;
  padding-bottom: 16px; border-bottom: 1px solid var(--border);
}
.header-brand { font-weight: 800; font-size: 1.1rem; }
.header-user  { display: flex; align-items: center; gap: 10px; font-size: .85rem; color: var(--text-muted); }
.logout-btn {
  background: none; border: 1px solid var(--border); border-radius: 99px;
  color: var(--text-muted); font-size: .75rem; padding: 4px 10px; cursor: pointer;
  transition: border-color .15s;
}
.logout-btn:hover { border-color: var(--text-muted); color: var(--text); }

/* ── Stats bar ─────────────────────────────────────────────────────────────── */
.stats-bar { display: flex; gap: 10px; margin-bottom: 14px; }
.stat {
  flex: 1; background: var(--surface); border-radius: var(--radius);
  padding: 12px 8px; text-align: center; border: 1px solid var(--border);
}
.stat-value { display: block; font-size: 1.5rem; font-weight: 800; color: var(--accent); }
.stat-label { font-size: .7rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: .5px; }

/* ── Secondary stats bar (category counts) ─────────────────────────────────── */
.stats-bar-sm { margin-top: -6px; }
.stats-bar-sm .stat-value { font-size: 1.1rem; }

/* ── Rank bar ──────────────────────────────────────────────────────────────── */
.rank-bar-wrap { margin-bottom: 28px; }
.rank-label { font-weight: 700; margin-bottom: 6px; font-size: .88rem; }
.rank-bar  { height: 10px; background: var(--surface2); border-radius: 99px; overflow: hidden; }
.rank-fill { height: 100%; background: linear-gradient(90deg, #4ECDC4, #9B59B6); border-radius: 99px; transition: width .6s ease; }
.rank-next { font-size: .78rem; color: var(--text-muted); margin-top: 5px; }

/* ── Tab bar ───────────────────────────────────────────────────────────────── */
.tab-bar {
  display: flex; gap: 4px; margin-bottom: 20px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 4px; flex-wrap: wrap;
}
.tab-btn {
  flex: 1; background: none; border: none; border-radius: var(--radius-sm);
  color: var(--text-muted); font-size: .82rem; font-weight: 700;
  padding: 9px 4px; cursor: pointer; transition: all .15s; white-space: nowrap;
}
.tab-btn:hover  { color: var(--text); }
.tab-btn.active { background: var(--accent); color: #0f1117; }

/* ── Tier sections ─────────────────────────────────────────────────────────── */
.tier-section  { margin-bottom: 28px; }
.tier-header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 12px; padding: 12px 14px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
}
.tier-header.tier-locked { opacity: .45; }
.tier-header-left { display: flex; align-items: center; gap: 12px; }
.tier-icon     { font-size: 1.6rem; flex-shrink: 0; }
.tier-name     { font-weight: 800; font-size: .95rem; }
.tier-tagline  { font-size: .75rem; color: var(--text-muted); margin-top: 2px; }
.tier-prog     { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.tier-prog-bar { width: 70px; height: 6px; background: var(--surface2); border-radius: 99px; overflow: hidden; }
.tier-prog-fill { height: 100%; border-radius: 99px; transition: width .4s; }
.tier-prog-count { font-size: .75rem; color: var(--text-muted); white-space: nowrap; }

/* ── Move (drill) grid ─────────────────────────────────────────────────────── */
.move-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }

.move-tile {
  background: var(--surface); border: 1px solid var(--border);
  border-top: 3px solid var(--tile-color, var(--accent));
  border-radius: var(--radius-sm); padding: 10px 8px 8px;
  cursor: pointer; text-align: left; color: var(--text);
  transition: transform .12s, border-color .12s;
  min-height: 70px; display: flex; flex-direction: column; justify-content: space-between;
}
.move-tile:hover:not(.move-locked):not(.move-readonly) { transform: translateY(-2px); border-color: var(--tile-color, var(--accent)); }
.move-tile.move-done { background: color-mix(in srgb, var(--tile-color) 6%, var(--surface)); border-color: color-mix(in srgb, var(--tile-color) 40%, transparent); }
.move-tile.move-locked  { opacity: .4; cursor: default; filter: grayscale(80%); }
.move-tile.move-readonly { cursor: default; }
.move-tile-name   { font-size: .82rem; font-weight: 700; line-height: 1.3; margin-bottom: 6px; }
.move-tile-bottom { display: flex; justify-content: space-between; align-items: center; }
.move-xp          { font-size: .68rem; font-weight: 700; color: var(--tile-color, var(--accent)); opacity: .8; }
.move-stars       { font-size: .65rem; }
.move-lock-icon   { font-size: .8rem; }

/* ── Back button ───────────────────────────────────────────────────────────── */
.back-btn {
  background: none; border: none; color: var(--text-muted); font-size: .9rem;
  cursor: pointer; padding: 6px 0; margin-bottom: 20px; display: flex; align-items: center; gap: 4px;
}
.back-btn:hover { color: var(--text); }

/* ── Drill detail ──────────────────────────────────────────────────────────── */
.move-breadcrumb  { font-size: .75rem; font-weight: 700; text-transform: uppercase; letter-spacing: .8px; margin-bottom: 8px; }
.move-title       { font-size: 1.6rem; font-weight: 800; margin-bottom: 12px; }
.move-meta-row { display: flex; gap: 8px; margin-bottom: 18px; }
.xp-pill   { background: #4ECDC420; color: #4ECDC4; padding: 2px 10px; border-radius: 99px; font-size: .75rem; font-weight: 700; }
.unit-pill { background: #9B59B620; color: #9B59B6; padding: 2px 10px; border-radius: 99px; font-size: .75rem; }

.best-box {
  background: var(--surface2); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 12px 14px; font-size: .85rem; color: var(--text-muted); margin-bottom: 18px;
}
.start-box { margin-bottom: 20px; }

/* ── Log input / activity entries (parent drill view) ──────────────────────── */
.log-input-box {
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px; margin-bottom: 20px;
}
.log-label { display: block; font-size: .85rem; font-weight: 600; margin-bottom: 10px; }
.entry-total {
  font-size: .8rem; font-weight: 700; color: var(--accent);
  margin-bottom: 10px; padding-bottom: 8px; border-bottom: 1px solid var(--border);
}
.entry-row {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 0; border-bottom: 1px solid var(--border); font-size: .85rem;
}
.entry-row:last-child { border-bottom: none; }
.entry-date  { color: var(--text-muted); font-size: .78rem; min-width: 60px; }
.entry-value { flex: 1; font-weight: 600; }
.entry-edit-btn {
  background: var(--surface2); border: 1px solid var(--border); border-radius: var(--radius-sm);
  color: var(--text); font-size: .75rem; padding: 3px 9px; cursor: pointer;
}
.entry-edit-btn:hover { border-color: var(--accent); }
.entry-del-btn {
  background: none; border: none; color: var(--text-muted); font-size: .85rem;
  cursor: pointer; padding: 3px 6px; transition: color .15s;
}
.entry-del-btn:hover { color: var(--red); }

/* ── Practice session ──────────────────────────────────────────────────────── */
.practice-top {
  display: flex; justify-content: space-between; align-items: center;
  font-weight: 700; font-size: .9rem; margin-bottom: 14px;
}
.practice-count { color: var(--text-muted); font-weight: 600; }

.q-dots { display: flex; gap: 5px; flex-wrap: wrap; margin-bottom: 22px; }
.q-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--surface2); border: 1px solid var(--border); }
.q-dot-done    { background: var(--accent); border-color: var(--accent); }
.q-dot-current { background: var(--text); border-color: var(--text); }

.problem-box {
  background: var(--surface); border: 2px solid var(--border); border-radius: var(--radius);
  padding: 32px 20px; text-align: center; margin-bottom: 20px; transition: border-color .2s, background .2s;
}
.problem-box.problem-correct { border-color: var(--green); background: color-mix(in srgb, var(--green) 8%, var(--surface)); }
.problem-box.problem-wrong   { border-color: var(--red);   background: color-mix(in srgb, var(--red) 8%, var(--surface)); }

.problem-text {
  font-size: 2.2rem; font-weight: 800; letter-spacing: -.5px; margin-bottom: 20px;
  font-variant-numeric: tabular-nums;
}
.answer-input {
  width: 160px; max-width: 100%; background: var(--bg); border: 1px solid var(--border);
  border-radius: var(--radius-sm); color: var(--text); font-size: 1.8rem; font-weight: 800;
  padding: 10px 14px; text-align: center; outline: none;
}
.answer-input:focus { border-color: var(--accent); }
.feedback { margin-top: 14px; font-size: 1rem; font-weight: 700; }

.keypad {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 16px;
}
.key-btn {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm);
  color: var(--text); font-size: 1.2rem; font-weight: 700; padding: 16px 0; cursor: pointer;
  transition: border-color .15s, background .15s;
}
.key-btn:hover  { border-color: var(--accent); }
.key-btn:disabled { opacity: .5; cursor: default; }
.key-clear, .key-back { color: var(--text-muted); font-size: 1rem; }

/* ── Session results ───────────────────────────────────────────────────────── */
.results-box {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 36px 24px; text-align: center; margin-top: 40px;
}
.results-emoji { font-size: 3rem; margin-bottom: 10px; }
.results-stars { font-size: 1.8rem; margin-bottom: 12px; letter-spacing: 4px; }
.results-score { font-size: 1.4rem; font-weight: 800; margin-bottom: 8px; }
.results-msg   { color: var(--text-muted); margin-bottom: 10px; font-size: .9rem; }
.results-xp    { font-size: 1.1rem; font-weight: 800; color: var(--accent); margin-bottom: 20px; }
.results-actions { margin-top: 12px; }

/* ── Buttons ───────────────────────────────────────────────────────────────── */
.btn-primary {
  display: block; width: 100%; background: var(--accent); color: #0f1117; border: none;
  border-radius: var(--radius); font-size: 1rem; font-weight: 700; padding: 14px;
  cursor: pointer; margin-bottom: 10px; transition: opacity .15s;
}
.btn-primary:hover { opacity: .9; }
.btn-primary:disabled { opacity: .5; cursor: default; }
.btn-large { font-size: 1.1rem; padding: 16px; }
.btn-secondary {
  display: block; width: 100%; background: var(--surface2); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius); font-size: .95rem;
  padding: 12px; cursor: pointer; transition: border-color .15s;
}
.btn-secondary:hover { border-color: var(--text-muted); }

/* ── Parent dashboard ──────────────────────────────────────────────────────── */
.parent-hero {
  display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px;
}
.parent-hero-title { font-size: 1.4rem; font-weight: 800; }

.btn-add {
  background: var(--accent); color: #0f1117; border: none;
  border-radius: var(--radius-sm); font-size: .9rem; font-weight: 700;
  padding: 8px 16px; cursor: pointer; transition: opacity .15s;
}
.btn-add:hover { opacity: .9; }

/* Add kid form */
.add-kid-form {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 20px; margin-bottom: 24px; display: flex; flex-direction: column; gap: 12px;
}
.form-title { font-size: 1rem; font-weight: 700; margin-bottom: 2px; }
.form-hint  { font-size: .8rem; color: var(--text-muted); }
.form-row   { display: flex; gap: 10px; }
.form-row .btn-primary   { margin: 0; }
.form-row .btn-secondary { margin: 0; }
.form-error {
  background: #E74C3C18; border: 1px solid #E74C3C40; color: #E74C3C;
  border-radius: var(--radius-sm); padding: 10px 12px; font-size: .85rem;
}

/* Kid card list */
.trainee-card {
  display: flex; align-items: center; gap: 14px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 16px; margin-bottom: 10px;
}
.trainee-avatar {
  width: 44px; height: 44px; border-radius: 50%; background: var(--accent);
  color: #0f1117; font-size: 1.2rem; font-weight: 800; display: flex;
  align-items: center; justify-content: center; flex-shrink: 0;
}
.trainee-info      { flex: 1; min-width: 0; }
.trainee-name      { font-weight: 700; font-size: .95rem; }
.trainee-meta      { font-size: .75rem; color: var(--text-muted); margin-top: 2px; margin-bottom: 6px; }
.trainee-prog-row  { display: flex; align-items: center; gap: 8px; }
.trainee-prog-bar  { flex: 1; height: 5px; background: var(--surface2); border-radius: 99px; overflow: hidden; max-width: 120px; }
.trainee-prog-fill { height: 100%; background: var(--accent); border-radius: 99px; transition: width .4s; }
.trainee-prog-count { font-size: .72rem; color: var(--text-muted); white-space: nowrap; }
.trainee-actions   { display: flex; flex-direction: column; gap: 6px; align-items: flex-end; flex-shrink: 0; }

.btn-view {
  background: var(--surface2); border: 1px solid var(--border); border-radius: var(--radius-sm);
  color: var(--text); font-size: .8rem; padding: 6px 12px; cursor: pointer; white-space: nowrap;
  transition: border-color .15s;
}
.btn-view:hover { border-color: var(--accent); }

.empty-state {
  text-align: center; color: var(--text-muted); padding: 40px 20px;
  background: var(--surface); border: 1px dashed var(--border); border-radius: var(--radius);
}

/* ── Kid view (read-only) ──────────────────────────────────────────────────── */
.trainee-view-hero {
  display: flex; align-items: flex-start; gap: 16px; margin-bottom: 24px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px;
}
.trainee-view-avatar {
  width: 52px; height: 52px; border-radius: 50%; background: var(--accent);
  color: #0f1117; font-size: 1.4rem; font-weight: 800; display: flex;
  align-items: center; justify-content: center; flex-shrink: 0;
}
.trainee-view-name { font-size: 1.2rem; font-weight: 800; margin-bottom: 4px; }
.trainee-view-meta { font-size: .8rem; color: var(--text-muted); }

/* ── Activity log (parent view) ────────────────────────────────────────────── */
.activity-section {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; margin-top: 12px;
}
.activity-title {
  font-size: .8rem; font-weight: 700; text-transform: uppercase; letter-spacing: .6px;
  color: var(--text-muted); margin-bottom: 12px;
}
.activity-empty { font-size: .85rem; color: var(--text-muted); text-align: center; padding: 8px 0; }
.activity-day { margin-bottom: 14px; }
.activity-day:last-child { margin-bottom: 0; }
.activity-day-label {
  font-size: .75rem; font-weight: 700; color: var(--accent);
  margin-bottom: 6px; text-transform: uppercase; letter-spacing: .4px;
}
.activity-move {
  display: flex; justify-content: space-between; align-items: center;
  padding: 5px 0; border-bottom: 1px solid var(--border); font-size: .85rem;
}
.activity-move:last-child { border-bottom: none; }
.activity-move-name { color: var(--text); }
.activity-move-stars { font-size: .78rem; white-space: nowrap; }
.activity-move-value { color: var(--text-muted); font-size: .75rem; }

/* ── Toast ─────────────────────────────────────────────────────────────────── */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: #333; color: #fff; padding: 10px 20px; border-radius: 99px;
  font-size: .9rem; pointer-events: none; z-index: 100; white-space: nowrap;
  animation: fadeIn .2s ease;
}
.hidden { display: none !important; }

/* ── Responsive ────────────────────────────────────────────────────────────── */
@media (max-width: 380px) {
  .stats-bar { gap: 6px; }
  .trainee-card { flex-wrap: wrap; }
  .trainee-actions { flex-direction: row; }
  .problem-text { font-size: 1.8rem; }
}
