/* Universal Learning Companion — pure CSS, no frameworks.
   Color psychology: trust blues + calm greens. */

:root {
  --bg: #f4f7fb;
  --surface: #ffffff;
  --text: #102040;
  --muted: #5d6c84;
  --accent: #1f6feb;          /* trust blue */
  --accent-2: #2da77b;        /* calm green */
  --warn: #d18b00;
  --bad: #c0392b;
  --good: #1f8a4c;
  --border: #d6dde9;
  --shadow: 0 4px 14px rgba(20, 40, 90, .08);
  --radius: 14px;
  --font-base: 16px;
}

[data-theme="dark"] {
  --bg: #0f1525;
  --surface: #18223a;
  --text: #e3ecf7;
  --muted: #99aac4;
  --accent: #5aa0ff;
  --accent-2: #6ad4a8;
  --border: #2a3650;
  --shadow: 0 4px 14px rgba(0, 0, 0, .35);
}

[data-font="S"] { --font-base: 14px; }
[data-font="M"] { --font-base: 16px; }
[data-font="L"] { --font-base: 19px; }
[data-font="XL"] { --font-base: 22px; }

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: var(--font-base);
  min-height: 100vh;
}

.hidden { display: none !important; }

.view { min-height: 100vh; padding: 24px; }

/* ---------- Profile picker ---------- */
.picker {
  max-width: 540px;
  margin: 8vh auto 0;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 32px;
  border: 1px solid var(--border);
}
.picker h1 { margin: 0 0 4px; color: var(--accent); }
.picker .sub { color: var(--muted); margin-top: 0; }
.profile-list { display: flex; flex-direction: column; gap: 8px; margin: 18px 0; }
.profile-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  cursor: pointer;
}
.profile-row:hover { border-color: var(--accent); }
.profile-row .name { font-weight: 600; }
.profile-row .meta { color: var(--muted); font-size: .9em; }
.add-form { display: flex; gap: 8px; margin-top: 8px; }
.add-form input { flex: 1; padding: 12px 14px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface); color: var(--text); font-size: 1em; }
.add-form button { padding: 12px 18px; border-radius: 10px; border: 0; background: var(--accent); color: white; cursor: pointer; font-weight: 600; }
.footnote { font-size: .85em; color: var(--muted); margin-top: 14px; }

/* ---------- Top bar ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; flex-wrap: wrap;
  padding: 12px 18px; background: var(--surface);
  border-radius: var(--radius); border: 1px solid var(--border);
  box-shadow: var(--shadow);
}
.user-info { display: flex; gap: 16px; align-items: center; flex-wrap: wrap; }
.user-name { font-weight: 700; font-size: 1.1em; }
.user-meta span { margin-right: 14px; color: var(--muted); font-size: .9em; }
.user-meta strong { color: var(--accent); font-size: 1.15em; }
.topbar-actions { display: flex; gap: 8px; }

/* ---------- Subject chips ---------- */
.subjects { display: flex; gap: 8px; flex-wrap: wrap; margin: 16px 0; }
.chip {
  padding: 8px 14px; border-radius: 999px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); cursor: pointer;
  font-size: .95em; transition: background .12s, border-color .12s, transform .08s;
}
.chip:hover { border-color: var(--accent); }
.chip.active { background: var(--accent); color: white; border-color: var(--accent); }
.chip.ghost { background: transparent; }
.chip.danger { color: var(--bad); border-color: var(--bad); }
.chip.subj[data-subject="math"].active { background: #1f6feb; }
.chip.subj[data-subject="reading"].active { background: #6c5ce7; }
.chip.subj[data-subject="vocabulary"].active { background: #d33682; }
.chip.subj[data-subject="science"].active { background: #2da77b; }
.chip.subj[data-subject="history"].active { background: #b58900; }
.chip.subj[data-subject="geography"].active { background: #268bd2; }
.chip.subj[data-subject="logic"].active { background: #cb4b16; }
.chip.subj[data-subject="code"].active { background: #586e75; }

/* ---------- Control row ---------- */
.control-row { display: flex; gap: 12px; align-items: center; margin: 12px 0; flex-wrap: wrap; }
.control-row select { padding: 6px 10px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); color: var(--text); }
.timer { color: var(--warn); font-weight: 700; margin-left: auto; }

/* ---------- Problem card ---------- */
.problem-card {
  max-width: 720px; margin: 18px auto 0;
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  padding: 28px;
}
.sub-meta { color: var(--muted); margin: 0 0 8px; text-transform: uppercase; letter-spacing: .04em; font-size: .8em; }
.question { font-size: 1.5em; margin: 0 0 18px; line-height: 1.35; white-space: pre-wrap; }
.choices { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }
.choices label { display: flex; gap: 10px; padding: 10px 14px; border: 1px solid var(--border); border-radius: 10px; cursor: pointer; }
.choices label:hover { border-color: var(--accent); }
.choices input[type=radio] { accent-color: var(--accent); }
.answer-row { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; }
.answer-row input {
  flex: 1; padding: 12px 14px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--bg); color: var(--text); font-size: 1.1em;
}
.primary { padding: 12px 22px; border: 0; border-radius: 10px; background: var(--accent); color: white; font-weight: 700; cursor: pointer; }
.primary:disabled { opacity: .5; cursor: not-allowed; }
.action-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 4px; }
.mic-indicator { color: var(--accent); font-weight: 700; font-family: monospace; padding-left: 4px; }
.hint-text { color: var(--warn); background: rgba(217, 139, 0, 0.08); padding: 10px 14px; border-radius: 8px; margin-top: 12px; }

.feedback { margin-top: 14px; padding: 14px 16px; border-radius: 10px; }
.feedback.correct { background: rgba(31, 138, 76, .12); color: var(--good); border: 1px solid var(--good); }
.feedback.wrong   { background: rgba(192, 57, 43, .12); color: var(--bad);  border: 1px solid var(--bad); }
.feedback h3 { margin: 0 0 6px; }
.feedback .expl { color: var(--text); margin-top: 8px; }
.feedback .badge-pop { color: var(--accent); margin-top: 8px; font-weight: 700; }

/* ---------- Drawer ---------- */
.drawer {
  position: fixed; top: 0; right: 0; height: 100vh; width: 380px; max-width: 100%;
  background: var(--surface); border-left: 1px solid var(--border);
  box-shadow: -6px 0 20px rgba(0,0,0,.12);
  z-index: 100; overflow-y: auto;
  transition: transform .25s ease;
}
.drawer.hidden { transform: translateX(110%); display: block !important; }
[data-motion="reduce"] .drawer { transition: none; }
.drawer-inner { padding: 22px; }
.drawer .close { position: absolute; top: 12px; right: 14px; background: transparent; border: 0; font-size: 1.6em; cursor: pointer; color: var(--muted); }
.srow { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin: 12px 0; flex-wrap: wrap; }
.srow select, .srow input[type=range] { flex: 1; max-width: 60%; }

.big-stats { display: flex; gap: 14px; margin: 14px 0; }
.big-stats > div { flex: 1; background: var(--bg); border: 1px solid var(--border); border-radius: 10px; padding: 14px; display: flex; flex-direction: column; align-items: center; }
.big-stats .big { font-size: 2em; font-weight: 800; color: var(--accent); }
.bars { display: flex; flex-direction: column; gap: 8px; }
.bar-row { display: flex; gap: 8px; align-items: center; }
.bar-row .label { width: 90px; font-size: .9em; color: var(--muted); }
.bar-row .track { flex: 1; height: 10px; background: var(--bg); border-radius: 6px; overflow: hidden; }
.bar-row .fill { height: 100%; background: var(--accent-2); }
.bar-row .pct { width: 50px; text-align: right; font-size: .85em; color: var(--muted); }

.badges-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 10px; }
.badge {
  border: 1px solid var(--border); border-radius: 10px; padding: 10px; text-align: center;
  background: var(--bg);
}
.badge.locked { filter: grayscale(1) opacity(.5); }
.badge .name { font-weight: 700; font-size: .9em; }
.badge .desc { font-size: .8em; color: var(--muted); }

/* ---------- Toast ---------- */
.toast {
  position: fixed; bottom: 30px; left: 50%; transform: translateX(-50%);
  background: var(--text); color: var(--bg);
  padding: 10px 16px; border-radius: 999px;
  box-shadow: var(--shadow);
  z-index: 200;
}

/* ---------- Reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
[data-motion="reduce"] * { transition: none !important; animation: none !important; }

@media (max-width: 720px) {
  .view { padding: 12px; }
  .picker { padding: 20px; margin-top: 24px; }
  .question { font-size: 1.2em; }
  .drawer { width: 100vw; border-left: 0; }
}
