/* ---------- Home Learn styles ---------- */
:root {
  --bg: #f4f6fb;
  --card: #ffffff;
  --ink: #1e2333;
  --muted: #6b7280;
  --brand: #4f46e5;
  --brand-soft: #eef2ff;
  --accent: #0ea5e9;
  --good: #16a34a;
  --good-soft: #dcfce7;
  --bad: #dc2626;
  --bad-soft: #fee2e2;
  --warn: #d97706;
  --border: #e5e7eb;
  --radius: 14px;
  --shadow: 0 1px 3px rgba(16, 24, 40, .08), 0 4px 14px rgba(16, 24, 40, .06);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--ink);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ---------- top bar ---------- */
.topbar {
  background: linear-gradient(90deg, #4f46e5, #6d28d9);
  color: #fff;
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 12px 24px;
  position: sticky;
  top: 0;
  z-index: 20;
  box-shadow: var(--shadow);
}
.brand { font-size: 20px; font-weight: 700; color: #fff; text-decoration: none; }
.topnav { display: flex; gap: 6px; margin-left: auto; }
.topnav a {
  color: #e0e7ff; text-decoration: none; font-weight: 600;
  padding: 8px 14px; border-radius: 10px;
}
.topnav a:hover { background: rgba(255,255,255,.15); color: #fff; }

main#app { flex: 1; width: 100%; max-width: 1100px; margin: 0 auto; padding: 24px 20px 60px; }
.footer { text-align: center; color: var(--muted); font-size: 13px; padding: 16px; }

/* ---------- generic ---------- */
h1 { font-size: 26px; margin: 8px 0 4px; }
h2 { font-size: 20px; margin: 20px 0 10px; }
.sub { color: var(--muted); margin: 0 0 18px; }
.crumbs { font-size: 14px; color: var(--muted); margin-bottom: 10px; }
.crumbs a { color: var(--brand); text-decoration: none; font-weight: 600; }
.crumbs a:hover { text-decoration: underline; }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 20px;
}

.grid { display: grid; gap: 16px; }
.grid.cols-2 { grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }

.btn {
  display: inline-flex; align-items: center; gap: 8px;
  background: var(--brand); color: #fff;
  border: none; border-radius: 10px;
  padding: 10px 16px; font-size: 15px; font-weight: 600;
  cursor: pointer; text-decoration: none;
  transition: filter .15s, transform .05s;
}
.btn:hover { filter: brightness(1.1); }
.btn:active { transform: translateY(1px); }
.btn.secondary { background: var(--brand-soft); color: var(--brand); }
.btn.ghost { background: transparent; color: var(--brand); border: 1px solid var(--brand); }
.btn.good { background: var(--good); }
.btn.bad { background: var(--bad); }
.btn.small { padding: 6px 12px; font-size: 13px; border-radius: 8px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.pill {
  display: inline-block; padding: 3px 10px; border-radius: 999px;
  font-size: 12px; font-weight: 700; letter-spacing: .3px;
}
.pill.brand { background: var(--brand-soft); color: var(--brand); }
.pill.good { background: var(--good-soft); color: var(--good); }
.pill.gray { background: #f3f4f6; color: var(--muted); }

/* ---------- subject / chapter cards ---------- */
.subject-card { display: flex; flex-direction: column; gap: 10px; }
.subject-card .icon { font-size: 40px; }
.subject-card h2 { margin: 0; }

.chapter-card { cursor: pointer; transition: transform .12s, box-shadow .12s; }
.chapter-card:hover { transform: translateY(-2px); box-shadow: 0 6px 20px rgba(79,70,229,.15); }
.chapter-card .ch-num {
  width: 42px; height: 42px; border-radius: 12px;
  background: var(--brand-soft); color: var(--brand);
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 18px; margin-bottom: 10px;
}
.chapter-card h3 { margin: 0 0 6px; font-size: 17px; }
.chapter-card .meta { color: var(--muted); font-size: 13px; }
.progress-bar { height: 8px; border-radius: 99px; background: #eef0f4; overflow: hidden; margin-top: 12px; }
.progress-bar > div { height: 100%; background: linear-gradient(90deg, #34d399, #10b981); border-radius: 99px; }

/* ---------- topic list ---------- */
.topic-row {
  display: flex; align-items: center; gap: 14px;
  padding: 14px 16px; border-bottom: 1px solid var(--border);
}
.topic-row:last-child { border-bottom: none; }
.topic-row .t-id { font-weight: 800; color: var(--brand); min-width: 44px; }
.topic-row .t-title { flex: 1; font-weight: 600; }
.topic-row .t-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.topic-row .stars { font-size: 14px; min-width: 60px; text-align: center; }

/* ---------- topic sub-section links ---------- */
.sections { display: flex; flex-wrap: wrap; gap: 8px; margin: -6px 0 6px; }
.pill-link {
  display: inline-flex; align-items: center; gap: 6px;
  background: #fff; border: 1px solid var(--border); border-radius: 999px;
  padding: 5px 12px; font-size: 13px; font-weight: 600; color: var(--ink); text-decoration: none;
}
.pill-link span { color: var(--muted); font-weight: 500; }
.pill-link:hover { border-color: var(--brand); color: var(--brand); }
.pill-link.exam { background: var(--brand-soft); border-color: #c7d2fe; color: var(--brand); }

/* ---------- tabs ---------- */
.tabs { display: flex; gap: 4px; border-bottom: 2px solid var(--border); margin: 18px 0; flex-wrap: wrap; }
.tabs button {
  background: none; border: none; padding: 10px 18px;
  font-size: 15px; font-weight: 600; color: var(--muted);
  cursor: pointer; border-bottom: 3px solid transparent; margin-bottom: -2px;
}
.tabs button.active { color: var(--brand); border-bottom-color: var(--brand); }

/* ---------- learn (predefined questions) ---------- */
.q-card { margin-bottom: 14px; }
.q-card .q-head { display: flex; align-items: baseline; gap: 10px; }
.q-card .q-num { font-weight: 800; color: var(--brand); }
.q-card .q-text { flex: 1; font-size: 16px; line-height: 1.55; }
.q-card .answer {
  margin-top: 12px; padding: 14px 16px; border-radius: 10px;
  background: var(--good-soft); border: 1px solid #bbf7d0;
  line-height: 1.6;
}
.q-card .answer .ans-label { font-weight: 800; color: var(--good); }
.q-card .working { margin-top: 8px; color: #374151; font-size: 14.5px; line-height: 1.65; }
.hidden { display: none; }

/* ---------- quiz ---------- */
.quiz-shell { max-width: 760px; margin: 0 auto; }
.quiz-top { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.quiz-top .qcount { font-weight: 700; color: var(--muted); }
.quiz-top .score { margin-left: auto; font-weight: 800; color: var(--brand); }
.quiz-q { font-size: 18px; line-height: 1.6; margin-bottom: 18px; }
.quiz-input { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.quiz-input input[type=text] {
  font-size: 17px; padding: 10px 14px; border-radius: 10px;
  border: 2px solid var(--border); width: 240px;
}
.quiz-input input[type=text]:focus { outline: none; border-color: var(--brand); }
.mc-option {
  display: block; width: 100%; text-align: left;
  background: #fff; border: 2px solid var(--border); border-radius: 10px;
  padding: 12px 16px; margin-bottom: 10px; font-size: 16px; cursor: pointer;
  transition: border-color .1s, background .1s;
}
.mc-option:hover { border-color: var(--brand); background: var(--brand-soft); }
.mc-option.picked-good { border-color: var(--good); background: var(--good-soft); }
.mc-option.picked-bad { border-color: var(--bad); background: var(--bad-soft); }
.mc-option.reveal-good { border-color: var(--good); background: var(--good-soft); }

.feedback { margin-top: 16px; padding: 14px 16px; border-radius: 10px; line-height: 1.6; }
.feedback.good { background: var(--good-soft); border: 1px solid #bbf7d0; }
.feedback.bad { background: var(--bad-soft); border: 1px solid #fecaca; }
.feedback .fb-title { font-weight: 800; margin-bottom: 4px; }
.feedback .fb-title.good { color: var(--good); }
.feedback .fb-title.bad { color: var(--bad); }

.quiz-result { text-align: center; padding: 30px 20px; }
.quiz-result .big { font-size: 52px; margin: 8px 0; }
.quiz-result .msg { font-size: 18px; color: var(--muted); margin-bottom: 20px; }

/* ---------- book viewer ---------- */
.book-frame-wrap { height: calc(100vh - 210px); min-height: 500px; }
.book-frame-wrap iframe {
  width: 100%; height: 100%; border: 1px solid var(--border);
  border-radius: var(--radius); background: #525659;
}
.book-toolbar { display: flex; gap: 10px; align-items: center; margin-bottom: 12px; flex-wrap: wrap; }
.book-toolbar input {
  width: 90px; font-size: 15px; padding: 8px 10px;
  border-radius: 8px; border: 2px solid var(--border);
}

/* ---------- profiles ---------- */
.topnav .profile-chip {
  background: rgba(255,255,255,.18);
  border-radius: 999px;
}
.profiles-grid { max-width: 860px; margin: 0 auto; }
.profile-card {
  text-align: center; cursor: pointer;
  transition: transform .12s, box-shadow .12s;
  display: flex; flex-direction: column; align-items: center; gap: 6px;
}
.profile-card:hover { transform: translateY(-3px); box-shadow: 0 8px 24px rgba(79,70,229,.18); }
.profile-card.active { border-color: var(--brand); box-shadow: 0 0 0 2px var(--brand-soft); }
.profile-card.add { border-style: dashed; color: var(--muted); }
.profile-card h2 { margin: 0; }
.profile-card .meta { color: var(--muted); font-size: 13px; line-height: 1.5; }
.p-avatar {
  font-size: 52px; line-height: 1;
  width: 84px; height: 84px; border-radius: 50%;
  background: var(--brand-soft);
  display: flex; align-items: center; justify-content: center;
}
.p-actions { display: flex; gap: 8px; margin-top: 8px; }
.avatar-row { display: flex; flex-wrap: wrap; gap: 6px; }
.avatar-opt {
  font-size: 24px; width: 44px; height: 44px;
  background: #fff; border: 2px solid var(--border); border-radius: 10px; cursor: pointer;
}
.avatar-opt:hover { border-color: var(--brand); }
.avatar-opt.picked { border-color: var(--brand); background: var(--brand-soft); }

/* ---------- progress page ---------- */
table.stats { width: 100%; border-collapse: collapse; font-size: 14.5px; }
table.stats th, table.stats td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); }
table.stats th { color: var(--muted); font-weight: 600; font-size: 13px; text-transform: uppercase; letter-spacing: .4px; }

.notice { background: #fffbeb; border: 1px solid #fde68a; color: #92400e; border-radius: 10px; padding: 12px 16px; }

@media (max-width: 640px) {
  .topic-row { flex-wrap: wrap; }
  .quiz-input input[type=text] { width: 100%; }
}
