:root {
  --bg: #f4f6fb;
  --card: #ffffff;
  --ink: #1c2433;
  --muted: #6b7689;
  --line: #e3e8f0;
  --brand: #1e5eff;
  --brand-ink: #ffffff;
  --good: #1aa179;
  --good-bg: #e7f6f0;
  --bad: #d64550;
  --bad-bg: #fceaec;
  --shadow: 0 1px 2px rgba(20, 30, 50, 0.06), 0 8px 24px rgba(20, 30, 50, 0.06);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
  line-height: 1.5;
}

.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }

/* Layout */
.topbar {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.75rem 1.25rem;
  background: var(--card);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 10;
}
.brand { font-weight: 700; font-size: 1.1rem; }
.topbar nav { display: flex; gap: 0.25rem; margin-left: auto; }
.topbar #logout { margin-left: 0.5rem; }

main { max-width: 760px; margin: 1.5rem auto; padding: 0 1rem 4rem; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 1.25rem 1.4rem;
  box-shadow: var(--shadow);
  margin-bottom: 1.25rem;
}

h1 { font-size: 1.5rem; margin: 0 0 0.25rem; }
h2 { font-size: 1.15rem; margin: 0 0 1rem; }

/* Buttons */
.btn {
  font: inherit;
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 0.6rem 1.1rem;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.05s;
}
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--brand); color: var(--brand-ink); }
.btn.primary:hover { background: #1850e0; }
.btn.primary:disabled { background: #b9c6e6; cursor: not-allowed; }
.btn.ghost { background: transparent; border-color: var(--line); color: var(--ink); }
.btn.ghost:hover { background: #f0f3f9; }

.tab {
  font: inherit;
  background: transparent;
  border: none;
  padding: 0.5rem 0.9rem;
  border-radius: 8px;
  cursor: pointer;
  color: var(--muted);
  font-weight: 600;
}
.tab.active { background: #eef2fb; color: var(--brand); }

/* Login */
.login-view {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
.login-card { width: 100%; max-width: 360px; text-align: center; }
.login-card input {
  width: 100%;
  font: inherit;
  padding: 0.7rem 0.9rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  margin: 0.5rem 0 0.75rem;
}
.login-card .btn { width: 100%; }
.error { color: var(--bad); margin: 0.75rem 0 0; }

/* Category picker */
.category-list { display: grid; gap: 0.6rem; margin-bottom: 1rem; }
.category-option {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.8rem 1rem;
  cursor: pointer;
  text-align: left;
}
.category-option.selected { border-color: var(--brand); background: #f4f7ff; }
.category-option .co-label { font-weight: 600; }
.category-option .co-count { margin-left: auto; color: var(--muted); font-size: 0.9rem; }
.session-size { display: flex; align-items: center; gap: 0.6rem; margin-bottom: 1rem; color: var(--muted); }
.session-size select { font: inherit; padding: 0.35rem 0.5rem; border-radius: 8px; border: 1px solid var(--line); }

/* Quiz */
.quiz-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 0.75rem; }
.badge {
  background: #eef2fb;
  color: var(--brand);
  font-size: 0.75rem;
  font-weight: 700;
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.passage {
  background: #f7f9fd;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.9rem 1rem;
  white-space: pre-wrap;
}
.prompt { font-size: 1.12rem; font-weight: 600; margin: 0.5rem 0 1rem; }
.options { display: grid; gap: 0.6rem; }
.option {
  display: flex;
  gap: 0.7rem;
  align-items: flex-start;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.75rem 0.9rem;
  cursor: pointer;
  font: inherit;
  text-align: left;
  background: var(--card);
}
.option:hover:not(:disabled) { border-color: #b9c6e6; }
.option .key { font-weight: 700; color: var(--muted); min-width: 1.2rem; }
.option.correct { background: var(--good-bg); border-color: var(--good); }
.option.incorrect { background: var(--bad-bg); border-color: var(--bad); }
.option:disabled { cursor: default; }

.feedback { margin-top: 1rem; border-top: 1px solid var(--line); padding-top: 1rem; }
.verdict { font-weight: 700; margin-bottom: 0.35rem; }
.verdict.good { color: var(--good); }
.verdict.bad { color: var(--bad); }
.reference { display: inline-block; margin-top: 0.5rem; color: var(--brand); text-decoration: none; word-break: break-all; }
.quiz-actions { display: flex; gap: 0.6rem; margin-top: 1.2rem; }

/* Stats */
.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1rem; margin-bottom: 1.25rem; }
.stat { text-align: center; padding: 1rem 0.5rem; margin: 0; }
.stat-num { font-size: 1.8rem; font-weight: 700; }
.stat-label { color: var(--muted); font-size: 0.85rem; }

.cat-row { margin-bottom: 1rem; }
.cat-row:last-child { margin-bottom: 0; }
.cat-row .cat-head { display: flex; justify-content: space-between; margin-bottom: 0.35rem; font-size: 0.95rem; }
.cat-head .cat-acc { color: var(--muted); }
.bar { display: flex; height: 12px; border-radius: 6px; overflow: hidden; background: #eef1f7; }
.bar .seg-learned { background: var(--good); }
.bar .seg-progress { background: #f3b340; }
.bar .seg-unseen { background: #d8dee9; }

.heatmap { display: flex; flex-wrap: wrap; gap: 3px; }
.heatmap .cell { width: 13px; height: 13px; border-radius: 3px; background: #e7ebf3; }
.heatmap .cell.l1 { background: #c6e2d6; }
.heatmap .cell.l2 { background: #84c7a8; }
.heatmap .cell.l3 { background: #3fa97e; }
.heatmap .cell.l4 { background: #1aa179; }

@media (max-width: 560px) {
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
}
