/* styles.css — mobile-first, app-like. Dark by default; light via [data-theme]. */

:root, [data-theme="dark"] {
  --bg: #0e1620;        --surface: #17212e;   --surface-2: #1f2c3b;
  --border: #2b3a4b;    --text: #e7eef5;      --muted: #93a4b6;
  --primary: #4a90ff;   --primary-ink: #ffffff;
  --correct: #2fbd6f;   --wrong: #ff5a5a;   --warn: #f2a33c;
  --shadow: 0 6px 20px rgba(0,0,0,.35);
}
[data-theme="light"] {
  --bg: #eef2f7;        --surface: #ffffff;   --surface-2: #f3f6fa;
  --border: #dde4ec;    --text: #16202c;      --muted: #5f6f80;
  --primary: #2b6fff;   --primary-ink: #ffffff;
  --correct: #17a45c;   --wrong: #e23b3b;     --warn: #d98219;
  --shadow: 0 6px 20px rgba(20,40,70,.10);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-text-size-adjust: 100%; -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}
button { font: inherit; color: inherit; cursor: pointer; }
h1,h2,h3 { line-height: 1.25; }
a { color: var(--primary); }

/* Layout shell */
#app { max-width: 720px; margin: 0 auto; padding: 0 16px calc(84px + env(safe-area-inset-bottom)); }
.topbar {
  position: sticky; top: 0; z-index: 20; background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(8px);
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 4px 10px; margin-bottom: 4px;
}
.topbar h1 { font-size: 18px; margin: 0; letter-spacing: .2px; }
.topbar .sub { color: var(--muted); font-size: 12.5px; }
.icon-btn { background: none; border: none; padding: 8px; border-radius: 10px; color: var(--muted); }
.icon-btn:hover { background: var(--surface-2); color: var(--text); }

/* Cards & sections */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 18px; box-shadow: var(--shadow); }
.card + .card { margin-top: 14px; }
.section-title { font-size: 13px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 22px 4px 10px; }

/* Buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  background: var(--surface-2); border: 1px solid var(--border); color: var(--text);
  padding: 13px 16px; border-radius: 12px; font-weight: 600; width: 100%; transition: transform .05s ease; }
.btn:active { transform: scale(.985); }
.btn.primary { background: var(--primary); color: var(--primary-ink); border-color: transparent; }
.btn.ghost { background: transparent; }
.btn.small { width: auto; padding: 9px 13px; border-radius: 10px; font-size: 14px; font-weight: 600; }
.btn-row { display: flex; gap: 10px; }

/* Dashboard stats */
.hero { text-align: center; padding: 24px 18px; }
.hero .big { font-size: 46px; font-weight: 800; letter-spacing: -1px; }
.hero .big.zero { color: var(--muted); }
.hero .label { color: var(--muted); font-size: 14px; margin-top: -2px; }
.stat-grid { display: grid; grid-template-columns: repeat(4,1fr); gap: 10px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 12px 8px; text-align: center; }
.stat .n { font-size: 22px; font-weight: 700; }
.stat .t { font-size: 11px; color: var(--muted); margin-top: 2px; }
.stat.new .n { color: var(--primary); }
.stat.learn .n { color: var(--warn); }
.stat.mature .n { color: var(--correct); }

/* Topic list */
.topic { display: flex; align-items: center; gap: 12px; padding: 13px 14px; background: var(--surface);
  border: 1px solid var(--border); border-radius: 12px; margin-bottom: 8px; text-align: left; width: 100%; }
.topic:active { background: var(--surface-2); }
.topic .name { flex: 1; font-weight: 600; font-size: 14.5px; }
.topic .meter { height: 6px; border-radius: 4px; background: var(--surface-2); overflow: hidden; margin-top: 6px; }
.topic .meter > i { display: block; height: 100%; background: var(--correct); }
.pill { font-size: 11.5px; font-weight: 700; padding: 3px 8px; border-radius: 999px; background: var(--surface-2); color: var(--muted); }
.pill.due { background: color-mix(in srgb, var(--primary) 22%, transparent); color: var(--primary); }

/* Study session */
.progress-line { height: 5px; background: var(--surface-2); border-radius: 4px; overflow: hidden; margin: 6px 0 16px; }
.progress-line > i { display: block; height: 100%; background: var(--primary); transition: width .25s ease; }
.q-meta { display: flex; justify-content: space-between; align-items: center; color: var(--muted); font-size: 12.5px; margin-bottom: 8px; }
.q-topic { font-weight: 600; color: var(--muted); }
.q-stem { font-size: 19px; font-weight: 600; line-height: 1.4; margin: 4px 0 18px; }
.options { display: flex; flex-direction: column; gap: 10px; }
.opt { display: flex; gap: 12px; align-items: flex-start; text-align: left; background: var(--surface);
  border: 1.5px solid var(--border); border-radius: 13px; padding: 14px; width: 100%; transition: border-color .12s; }
.opt:active { border-color: var(--primary); }
.opt .k { flex: none; width: 26px; height: 26px; border-radius: 8px; background: var(--surface-2);
  display: grid; place-items: center; font-weight: 700; font-size: 13px; color: var(--muted); }
.opt .txt { flex: 1; padding-top: 2px; }
.opt.correct { border-color: var(--correct); background: color-mix(in srgb, var(--correct) 12%, var(--surface)); }
.opt.correct .k { background: var(--correct); color: #fff; }
.opt.wrong { border-color: var(--wrong); background: color-mix(in srgb, var(--wrong) 12%, var(--surface)); }
.opt.wrong .k { background: var(--wrong); color: #fff; }
.opt.dim { opacity: .55; }
.opt[disabled] { cursor: default; }

/* Explanation + grading */
.explain { margin-top: 16px; padding: 14px 16px; border-radius: 13px; border: 1px solid var(--border);
  background: var(--surface-2); font-size: 14.5px; }
.explain .verdict { font-weight: 800; margin-bottom: 6px; }
.explain .verdict.correct { color: var(--correct); }
.explain .verdict.wrong { color: var(--wrong); }
.explain .body { color: var(--text); }
.explain .cite { color: var(--muted); font-size: 12.5px; }
.grade-row { display: grid; grid-template-columns: repeat(4,1fr); gap: 8px; margin-top: 14px; }
.grade { padding: 12px 6px; border-radius: 12px; border: 1px solid var(--border); background: var(--surface); font-weight: 700; font-size: 13.5px; text-align: center; }
.grade small { display: block; font-weight: 500; font-size: 10.5px; color: var(--muted); margin-top: 2px; }
.grade.again { border-color: color-mix(in srgb, var(--wrong) 55%, var(--border)); }
.grade.good  { border-color: color-mix(in srgb, var(--primary) 55%, var(--border)); }
.grade.easy  { border-color: color-mix(in srgb, var(--correct) 55%, var(--border)); }

/* Bottom nav */
.tabbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: flex; justify-content: space-around; align-items: center;
  background: color-mix(in srgb, var(--surface) 96%, transparent); backdrop-filter: blur(10px);
  border-top: 1px solid var(--border); padding: 8px 8px calc(8px + env(safe-area-inset-bottom)); }
.tab { display: flex; flex-direction: column; align-items: center; gap: 3px; background: none; border: none;
  color: var(--muted); font-size: 10.5px; font-weight: 600; padding: 4px 14px; border-radius: 10px; }
.tab.active { color: var(--primary); }
.tab svg { width: 22px; height: 22px; }

/* Browse / search list */
.search-input { width: 100%; padding: 13px 14px; border-radius: 12px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font-size: 15px; }
.qrow { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 14px; margin-bottom: 10px; }
.qrow .qt { font-weight: 600; margin-bottom: 8px; }
.qrow .qa { color: var(--correct); font-size: 14px; }
.qrow .qx { color: var(--muted); font-size: 13.5px; margin-top: 6px; }
.tag { display: inline-block; font-size: 11px; color: var(--muted); background: var(--surface-2); padding: 2px 8px; border-radius: 999px; margin-bottom: 8px; }

/* Settings */
.row { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 14px 2px; border-bottom: 1px solid var(--border); }
.row:last-child { border-bottom: none; }
.row .rl { font-weight: 600; }
.row .rd { color: var(--muted); font-size: 12.5px; margin-top: 2px; }
.seg { display: inline-flex; background: var(--surface-2); border-radius: 10px; padding: 3px; }
.seg button { border: none; background: none; color: var(--muted); padding: 7px 12px; border-radius: 8px; font-weight: 600; font-size: 13px; }
.seg button.on { background: var(--primary); color: var(--primary-ink); }
.stepper { display: inline-flex; align-items: center; gap: 0; }
.stepper button { width: 38px; height: 38px; border: 1px solid var(--border); background: var(--surface); font-size: 20px; font-weight: 700; }
.stepper button:first-child { border-radius: 10px 0 0 10px; }
.stepper button:last-child { border-radius: 0 10px 10px 0; }
.stepper .val { min-width: 46px; text-align: center; border-top: 1px solid var(--border); border-bottom: 1px solid var(--border);
  height: 38px; display: grid; place-items: center; font-weight: 700; background: var(--surface); }
input[type=date] { background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: 10px; padding: 8px 10px; font: inherit; }

/* Misc */
.center-msg { text-align: center; color: var(--muted); padding: 48px 20px; }
.center-msg .emoji { font-size: 44px; }
.muted { color: var(--muted); }
.hidden { display: none !important; }
.spacer { height: 10px; }
.toast { position: fixed; left: 50%; bottom: calc(96px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 999px; font-size: 13.5px; font-weight: 600;
  box-shadow: var(--shadow); z-index: 50; opacity: 0; transition: opacity .2s, transform .2s; pointer-events: none; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(-4px); }
kbd { font: 12px/1 ui-monospace, Menlo, monospace; background: var(--surface-2); border: 1px solid var(--border); border-radius: 5px; padding: 2px 6px; color: var(--muted); }

@media (min-width: 640px) {
  .q-stem { font-size: 21px; }
  .tab { font-size: 11.5px; }
}
