:root {
  --bg: #f5f6f8;
  --card: #ffffff;
  --border: #e4e6eb;
  --text: #1c1e21;
  --muted: #65676b;
  --primary: #4f46e5;
  --primary-dark: #4338ca;
  --radius: 12px;
}

* { box-sizing: border-box; }

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

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- Top bar ---------- */
.topbar {
  background: var(--card);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar-inner {
  max-width: 1000px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 10px 16px;
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--text); font-weight: 700; }
.brand:hover { text-decoration: none; }
.brand-mark {
  background: var(--primary);
  color: #fff;
  font-weight: 800;
  padding: 6px 9px;
  border-radius: 8px;
  font-size: 13px;
  letter-spacing: 0.5px;
}
.topnav { display: flex; gap: 4px; margin-left: 8px; }
.nav-link {
  padding: 8px 14px;
  border-radius: 8px;
  color: var(--muted);
  font-weight: 600;
  font-size: 14px;
}
.nav-link.active { color: var(--primary); background: #eef0fe; }
.nav-link.disabled { color: #b0b3b8; cursor: default; }
.topbar-user { margin-left: auto; display: flex; align-items: center; gap: 12px; }

/* Mobile: logo + account on row 1, nav becomes a scrollable strip on row 2 */
@media (max-width: 640px) {
  .topbar-inner { flex-wrap: wrap; gap: 8px; padding: 8px 12px; }
  .brand-text { display: none; }              /* keep just the crest */
  .topbar-user { margin-left: auto; gap: 8px; }
  .topnav {
    order: 3; width: 100%; margin-left: 0;
    overflow-x: auto; flex-wrap: nowrap;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .topnav::-webkit-scrollbar { display: none; }
  .nav-link { padding: 6px 11px; font-size: 13px; white-space: nowrap; }
}

/* ---------- Avatars ---------- */
.avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px; height: 40px;
  border-radius: 50%;
  color: #fff;
  font-weight: 700;
  font-size: 14px;
  flex: none;
}
.avatar-sm { width: 30px; height: 30px; font-size: 12px; }

/* ---------- Layout ---------- */
.container { max-width: 1000px; margin: 24px auto; padding: 0 16px; }
.feed-layout {
  display: grid;
  grid-template-columns: 1fr 300px;
  gap: 20px;
  align-items: start;
}
@media (max-width: 800px) {
  .feed-layout { grid-template-columns: 1fr; }
  .feed-side { display: none; }
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
}

/* ---------- Composer ---------- */
.composer { display: flex; gap: 12px; }
.composer form { flex: 1; }
.composer textarea, .comment-form input, .auth-card input {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  font: inherit;
  resize: vertical;
  background: #fafbfc;
}
.composer textarea:focus, .comment-form input:focus, .auth-card input:focus {
  outline: none;
  border-color: var(--primary);
  background: #fff;
}
.composer-actions { display: flex; justify-content: flex-end; margin-top: 10px; }

/* ---------- Buttons ---------- */
.btn {
  border: none;
  border-radius: 9px;
  padding: 9px 18px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  background: #e4e6eb;
  color: var(--text);
}
.btn:hover { filter: brightness(0.97); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-sm { padding: 7px 12px; font-size: 13px; }
.btn-link {
  background: none; border: none; color: var(--muted);
  cursor: pointer; font: inherit; font-weight: 600; padding: 0;
}
.btn-link:hover { color: var(--text); }

/* ---------- Posts ---------- */
.post-head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.post-author { font-weight: 700; }
.post-meta { color: var(--muted); font-size: 13px; }
.post-body { white-space: pre-wrap; margin-bottom: 14px; }
.post-foot { display: flex; gap: 16px; align-items: center; border-top: 1px solid var(--border); padding-top: 10px; }
.post-stat {
  background: none; border: none; font: inherit;
  color: var(--muted); cursor: pointer; padding: 4px 6px; border-radius: 6px;
}
.like-btn:hover { background: #f0f1f3; }
.like-btn.liked { color: #e0245e; font-weight: 600; }

/* ---------- Comments ---------- */
.comments { margin-top: 12px; display: flex; flex-direction: column; gap: 10px; }
.comment { display: flex; gap: 8px; }
.comment-body {
  background: #f0f1f3;
  border-radius: 12px;
  padding: 8px 12px;
  flex: 1;
}
.comment-author { font-weight: 700; margin-right: 6px; }
.comment-meta { color: var(--muted); font-size: 12px; margin-top: 2px; }
.comment-form { display: flex; gap: 8px; margin-top: 12px; }
.comment-form input { flex: 1; }

/* ---------- Side cards ---------- */
.side-card h3 { margin: 0 0 8px; font-size: 15px; display: flex; align-items: center; gap: 6px; }
.side-card .count { color: var(--muted); font-weight: 600; }
.member-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.member-list li { display: flex; align-items: center; gap: 10px; }

/* ---------- Auth ---------- */
.auth-card {
  max-width: 380px;
  margin: 40px auto;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
}
.auth-logo { width: 72px; height: 72px; border-radius: 50%; object-fit: cover; display: block; margin: 0 auto 14px; }
.auth-card h1 { margin: 0 0 4px; font-size: 22px; text-align: center; }
.auth-card > .muted { text-align: center; }
.auth-card label { display: block; font-weight: 600; font-size: 14px; margin-top: 14px; }
.auth-card input { margin-top: 6px; }
.auth-card .btn { width: 100%; margin-top: 20px; }
.hint { display: block; font-weight: 400; color: var(--muted); font-size: 12px; margin-top: 4px; }

/* ---------- Classroom ---------- */
.classroom-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
.classroom-head h1 { margin: 0 0 4px; }
.progress-badge { text-align: right; flex: none; }
.progress-pct { font-size: 24px; font-weight: 800; color: var(--primary); }
.progress-bar {
  height: 8px; background: #e4e6eb; border-radius: 999px;
  overflow: hidden; margin: 14px 0 24px;
}
.progress-bar span { display: block; height: 100%; background: var(--primary); border-radius: 999px; }

.module-list { display: flex; flex-direction: column; gap: 16px; }
.module.locked { opacity: 0.75; }
.module-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.module-head h2 { margin: 0; font-size: 18px; }
.week-chip {
  background: #eef0fe; color: var(--primary);
  font-weight: 700; font-size: 12px; padding: 4px 10px; border-radius: 999px; flex: none;
}
.lock-tag { margin-left: auto; color: var(--muted); font-size: 13px; font-weight: 600; flex: none; }
.module-summary { margin: 8px 0 12px; }
.lesson-list { list-style: none; margin: 8px 0 0; padding: 0; }
.lesson-row { border-top: 1px solid var(--border); }
.lesson-row a, .lesson-locked {
  display: flex; align-items: center; gap: 10px;
  padding: 11px 4px; color: var(--text);
}
.lesson-row a:hover { text-decoration: none; background: #f7f8fa; border-radius: 8px; }
.lesson-locked { color: var(--muted); cursor: default; }
.lesson-row.done a { color: var(--muted); }
.lesson-check { width: 20px; flex: none; }
.lesson-tag {
  margin-left: auto; font-size: 11px; color: var(--muted);
  background: #f0f1f3; padding: 2px 8px; border-radius: 999px;
}

/* Lesson page */
.lesson-page { max-width: 720px; margin: 0 auto; }
.back-link { display: inline-block; margin-bottom: 14px; color: var(--muted); font-weight: 600; }
.lesson-eyebrow { color: var(--primary); font-weight: 700; font-size: 13px; margin-bottom: 6px; }
.lesson-card h1 { margin: 0 0 16px; }
.video-wrap {
  position: relative; padding-bottom: 56.25%; height: 0;
  border-radius: 10px; overflow: hidden; margin-bottom: 18px; background: #000;
}
.video-wrap iframe { position: absolute; top: 0; left: 0; width: 100%; height: 100%; }
.lesson-body { white-space: pre-wrap; line-height: 1.65; }
.lesson-actions { margin-top: 22px; padding-top: 18px; border-top: 1px solid var(--border); }
.complete-btn.done { background: #e7f7ee; color: #137a45; }
.lesson-nav { display: flex; justify-content: space-between; gap: 12px; margin-top: 18px; }

/* ---------- Brand logo ---------- */
.brand-logo {
  width: 34px; height: 34px; border-radius: 50%;
  object-fit: cover; flex: none; display: block;
}
a.btn { text-decoration: none; display: inline-block; }
a.btn:hover { text-decoration: none; }

/* ---------- Wiki / landing ---------- */
.hero { text-align: center; padding: 28px 16px 8px; max-width: 760px; margin: 0 auto; }
.hero-logo {
  width: 128px; height: 128px; border-radius: 50%;
  object-fit: cover; margin-bottom: 14px;
  box-shadow: 0 6px 24px rgba(0,0,0,0.12);
}
.hero h1 { font-size: 34px; margin: 6px 0 12px; letter-spacing: -0.5px; }
.hero-tagline { font-size: 17px; color: var(--muted); line-height: 1.6; margin: 0 auto 22px; max-width: 620px; }
.hero-actions { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }
.hero-meta { margin-top: 16px; font-size: 13px; }

.wiki-section { margin-top: 36px; }
.wiki-section-head h2 { margin: 0 0 2px; font-size: 20px; }
.wiki-section-head p { margin: 0 0 16px; }
.concept-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 16px;
}
.concept-card { margin-bottom: 0; transition: transform 0.08s, box-shadow 0.08s; }
.concept-card:hover {
  text-decoration: none; transform: translateY(-2px);
  box-shadow: 0 6px 18px rgba(0,0,0,0.08); border-color: #cdd0fb;
}
.concept-card h3 { margin: 0 0 8px; font-size: 16px; color: var(--text); }
.concept-card p { margin: 0 0 12px; font-size: 14px; line-height: 1.5; }
.concept-more { color: var(--primary); font-weight: 700; font-size: 13px; }

/* Wiki article */
.wiki-article { max-width: 720px; margin: 0 auto; }
.article-eyebrow { color: var(--primary); font-weight: 700; font-size: 13px; text-transform: uppercase; letter-spacing: 0.5px; }
.article-card h1 { margin: 6px 0 12px; }
.article-summary { font-size: 17px; color: var(--muted); line-height: 1.6; margin: 0 0 20px; padding-bottom: 18px; border-bottom: 1px solid var(--border); }
.article-card p { line-height: 1.7; margin: 0 0 16px; }
.key-points {
  background: #f7f8fa; border: 1px solid var(--border);
  border-radius: 10px; padding: 4px 18px 14px; margin-top: 22px;
}
.key-points h4 { margin: 14px 0 8px; font-size: 14px; }
.key-points ul { margin: 0; padding-left: 20px; }
.key-points li { margin: 6px 0; }

.related { margin-top: 22px; }
.related h4 { margin: 0 0 10px; }
.related-links { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  background: #eef0fe; color: var(--primary); font-weight: 600; font-size: 14px;
  padding: 6px 14px; border-radius: 999px;
}
.chip:hover { text-decoration: none; background: #e0e3fc; }

.wiki-cta { margin-top: 24px; text-align: center; }
.wiki-cta p { margin: 6px 0 14px; }

/* ---------- Leaderboard ---------- */
.leaderboard h1 { margin: 0 0 4px; }
.progress-bar.slim { height: 6px; margin: 8px 0; }

.standing-card { display: flex; align-items: center; gap: 18px; margin-top: 16px; }
.standing-rank { font-size: 30px; font-weight: 800; color: var(--primary); min-width: 56px; text-align: center; }
.standing-main { flex: 1; }
.standing-level { display: flex; align-items: center; gap: 8px; font-size: 16px; }
.level-progress { margin-top: 4px; }

.board { padding: 0; overflow: hidden; }
.board-row {
  display: flex; align-items: center; gap: 14px;
  padding: 12px 16px; border-top: 1px solid var(--border);
}
.board-row:first-child { border-top: none; }
.board-row.me { background: #eef0fe; }
.board-rank { min-width: 28px; text-align: center; font-weight: 700; font-size: 18px; color: var(--muted); }
.board-name { flex: 1; font-weight: 600; }
.board-sub { display: flex; align-items: center; gap: 6px; margin-top: 2px; font-weight: 400; }
.board-points { font-weight: 800; font-size: 17px; }
.board-points .muted { font-weight: 400; font-size: 13px; }
.you-tag {
  background: var(--primary); color: #fff; font-size: 11px; font-weight: 700;
  padding: 1px 7px; border-radius: 999px; vertical-align: middle;
}

.level-badge {
  display: inline-block; font-size: 11px; font-weight: 700; color: #fff;
  padding: 2px 8px; border-radius: 999px; background: var(--muted);
}
.level-badge.level-1 { background: #94a3b8; }
.level-badge.level-2 { background: #38bdf8; }
.level-badge.level-3 { background: #34d399; }
.level-badge.level-4 { background: #a3e635; }
.level-badge.level-5 { background: #fbbf24; }
.level-badge.level-6 { background: #fb923c; }
.level-badge.level-7 { background: #f87171; }
.level-badge.level-8 { background: #c084fc; }
.level-badge.level-9 { background: var(--primary); }

/* ---------- Misc ---------- */
.muted { color: var(--muted); }
.center { text-align: center; }
.empty { text-align: center; color: var(--muted); padding: 40px 16px; }
.alert {
  background: #fdecea; color: #b71c1c;
  border: 1px solid #f5c6c2; border-radius: 8px;
  padding: 10px 12px; margin-top: 14px; font-size: 14px;
}
