:root {
  --bg: #f7f5ef;
  --bg-card: #ffffff;
  --ink: #1c1c1c;
  --ink-soft: #555;
  --ink-faint: #888;
  --accent: #2f6fb0;
  --accent-soft: #d6e6f5;
  --math: #c4651a;
  --physics: #2f7d6d;
  --chemistry: #7a3f9b;
  --good: #2a8a3a;
  --bad: #b53030;
  --line: #e3ddd0;
  --shadow: 0 1px 2px rgba(0,0,0,0.06), 0 4px 12px rgba(0,0,0,0.04);
  --radius: 12px;
  --font-body: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  --font-display: Georgia, "Iowan Old Style", "Palatino Linotype", serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--ink);
  line-height: 1.55;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ---- topbar ---- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 28px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 10;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: var(--font-display);
  font-size: 22px;
  text-decoration: none;
  color: var(--ink);
}
.brand-mark {
  width: 36px;
  height: 36px;
  background: var(--ink);
  color: var(--bg);
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 20px;
  font-weight: 700;
}
.topnav { display: flex; gap: 24px; }
.topnav a {
  text-decoration: none;
  color: var(--ink-soft);
  font-size: 15px;
  padding: 6px 0;
  border-bottom: 2px solid transparent;
}
.topnav a:hover { color: var(--ink); }
.topnav a.active { color: var(--ink); border-bottom-color: var(--accent); }

/* ---- main ---- */
.app {
  flex: 1;
  width: 100%;
  max-width: 1100px;
  margin: 0 auto;
  padding: 32px 24px 64px;
}

.footer {
  text-align: center;
  padding: 24px;
  color: var(--ink-faint);
  font-size: 13px;
  border-top: 1px solid var(--line);
}

h1, h2, h3 { font-family: var(--font-display); font-weight: 600; line-height: 1.25; }
h1 { font-size: 36px; margin: 0 0 12px; }
h2 { font-size: 26px; margin: 32px 0 12px; }
h3 { font-size: 19px; margin: 20px 0 8px; }
p { margin: 0 0 12px; }

.hero {
  padding: 8px 0 24px;
}
.hero p.lede {
  font-size: 18px;
  color: var(--ink-soft);
  max-width: 720px;
}

/* ---- subject grid ---- */
.subjects {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 18px;
  margin-top: 24px;
}
.subject-card {
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 24px;
  text-decoration: none;
  color: var(--ink);
  display: block;
  transition: transform 0.12s, box-shadow 0.12s;
  box-shadow: var(--shadow);
  position: relative;
  overflow: hidden;
}
.subject-card::before {
  content: "";
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 4px;
  background: var(--accent);
}
.subject-card.math::before { background: var(--math); }
.subject-card.physics::before { background: var(--physics); }
.subject-card.chemistry::before { background: var(--chemistry); }
.subject-card:hover { transform: translateY(-2px); box-shadow: 0 8px 20px rgba(0,0,0,0.08); }
.subject-card .icon {
  font-size: 42px;
  font-family: var(--font-display);
  display: block;
  margin-bottom: 6px;
}
.subject-card h2 { margin: 0 0 6px; font-size: 22px; }
.subject-card p { color: var(--ink-soft); margin: 0; font-size: 14px; }

/* ---- levels ---- */
.levels {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px;
  margin-top: 18px;
}
.level-card {
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  text-decoration: none;
  color: var(--ink);
  position: relative;
  transition: transform 0.1s;
}
.level-card:hover { transform: translateY(-1px); }
.level-num {
  display: inline-block;
  background: var(--ink);
  color: var(--bg);
  font-size: 12px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 999px;
  letter-spacing: 0.5px;
}
.level-card h3 { margin: 8px 0 4px; }
.level-card .age { font-size: 13px; color: var(--ink-faint); }
.level-card .progress-bar {
  height: 4px;
  background: var(--line);
  border-radius: 2px;
  margin-top: 12px;
  overflow: hidden;
}
.level-card .progress-bar > span {
  display: block;
  height: 100%;
  background: var(--good);
  width: 0%;
  transition: width 0.3s;
}

/* ---- lesson list ---- */
.lesson-list {
  list-style: none;
  padding: 0;
  margin: 18px 0 0;
  display: grid;
  gap: 8px;
}
.lesson-list li {
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 14px 18px;
  display: flex;
  align-items: center;
  gap: 14px;
}
.lesson-list a {
  text-decoration: none;
  color: var(--ink);
  flex: 1;
  font-weight: 500;
}
.lesson-list a:hover { color: var(--accent); }
.lesson-status {
  width: 22px; height: 22px;
  border-radius: 50%;
  border: 2px solid var(--line);
  display: grid; place-items: center;
  font-size: 12px;
  flex-shrink: 0;
}
.lesson-status.done { background: var(--good); border-color: var(--good); color: white; }

/* ---- lesson page ---- */
.lesson {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 32px 36px;
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  max-width: 820px;
}
.lesson .crumbs {
  font-size: 13px;
  color: var(--ink-faint);
  margin-bottom: 8px;
}
.lesson .crumbs a { color: var(--ink-faint); text-decoration: none; }
.lesson .crumbs a:hover { color: var(--ink); }

.lesson .body p, .lesson .body li {
  font-size: 16px;
  color: var(--ink);
}
.lesson .body { font-size: 16px; }
.lesson .body ul, .lesson .body ol { padding-left: 24px; }

.callout {
  background: var(--accent-soft);
  border-left: 4px solid var(--accent);
  padding: 14px 18px;
  margin: 16px 0;
  border-radius: 6px;
  font-size: 15px;
}
.callout.help {
  background: #fff8e1;
  border-color: #d4a017;
}
.callout strong { display: block; margin-bottom: 4px; }

.figure {
  margin: 18px 0;
  text-align: center;
  padding: 16px;
  background: #fcfbf6;
  border: 1px solid var(--line);
  border-radius: 10px;
}
.figure svg {
  max-width: 100%;
  height: auto;
}
.figure figcaption {
  margin-top: 8px;
  font-size: 13px;
  color: var(--ink-soft);
  font-style: italic;
}

.example {
  background: #f9f6ee;
  border: 1px dashed #d4c89a;
  padding: 14px 18px;
  margin: 16px 0;
  border-radius: 8px;
}
.example strong { color: var(--math); display: block; margin-bottom: 4px; }

/* ---- exercises ---- */
.exercise {
  background: #fcfbf6;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 18px 22px;
  margin: 18px 0;
}
.exercise .q { font-weight: 500; margin-bottom: 12px; }
.exercise .choices {
  display: grid;
  gap: 8px;
  margin-bottom: 10px;
}
.exercise .choice {
  display: block;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  cursor: pointer;
  background: white;
  text-align: left;
  font-size: 15px;
  font-family: inherit;
  color: var(--ink);
  transition: background 0.1s, border-color 0.1s;
}
.exercise .choice:hover { background: var(--accent-soft); border-color: var(--accent); }
.exercise .choice.correct { background: #d6f0d8; border-color: var(--good); }
.exercise .choice.wrong { background: #f5d6d6; border-color: var(--bad); }
.exercise .choice:disabled { cursor: default; }

.exercise input[type="text"], .exercise input[type="number"] {
  font-family: inherit;
  font-size: 16px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  width: 200px;
}
.exercise .check-btn {
  margin-left: 8px;
  padding: 8px 18px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 6px;
  font-family: inherit;
  font-size: 15px;
  cursor: pointer;
}
.exercise .check-btn:hover { background: #245a91; }
.exercise .check-btn:disabled { background: var(--ink-faint); cursor: default; }

.feedback {
  margin-top: 12px;
  padding: 10px 14px;
  border-radius: 6px;
  font-size: 14px;
}
.feedback.good { background: #d6f0d8; color: var(--good); }
.feedback.bad { background: #f5d6d6; color: var(--bad); }

.btn {
  display: inline-block;
  padding: 10px 20px;
  background: var(--ink);
  color: var(--bg);
  text-decoration: none;
  border-radius: 8px;
  font-size: 15px;
  border: none;
  cursor: pointer;
  font-family: inherit;
}
.btn:hover { background: #333; }
.btn.secondary {
  background: white;
  color: var(--ink);
  border: 1px solid var(--line);
}
.btn.secondary:hover { background: var(--bg); }

.lesson-nav {
  display: flex;
  justify-content: space-between;
  margin-top: 28px;
  gap: 12px;
}

/* ---- overview ---- */
.overview-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 16px;
  margin-top: 20px;
}
.overview-card {
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
}
.overview-card h3 { margin-top: 0; }
.overview-card .stat {
  font-size: 32px;
  font-family: var(--font-display);
  font-weight: 600;
}
.overview-card .stat-label { color: var(--ink-faint); font-size: 13px; }

.reset-btn {
  margin-top: 18px;
  background: transparent;
  color: var(--bad);
  border: 1px solid var(--bad);
  padding: 6px 14px;
  border-radius: 6px;
  cursor: pointer;
  font-family: inherit;
  font-size: 13px;
}
.reset-btn:hover { background: var(--bad); color: white; }

/* ---- rang ---- */
.rank-banner {
  display: flex;
  align-items: center;
  gap: 18px;
  background: linear-gradient(135deg, #fff, #f4ede0);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 22px;
  margin: 18px 0 28px;
  box-shadow: var(--shadow);
}
.rank-banner.empty { background: var(--bg-card); }
.rank-banner.mastered {
  background: linear-gradient(135deg, #fff8e1, #f6e9b8);
  border-color: #d4a017;
}
.rank-symbol {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--ink);
  color: var(--bg);
  display: grid;
  place-items: center;
  font-size: 28px;
  font-family: var(--font-display);
  flex-shrink: 0;
}
.rank-banner.mastered .rank-symbol { background: #d4a017; color: #fff; }
.rank-banner.empty .rank-symbol { background: var(--line); color: var(--ink-faint); }
.rank-label {
  font-size: 12px;
  color: var(--ink-faint);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.rank-title {
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 600;
  margin: 2px 0;
}
.rank-blurb {
  font-size: 14px;
  color: var(--ink-soft);
}

.rank-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--ink);
  color: var(--bg);
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  margin-top: 4px;
}
.rank-chip span {
  font-size: 16px;
  font-family: var(--font-display);
}
.rank-chip.mastered { background: #d4a017; }
.rank-chip.empty { background: var(--line); color: var(--ink-faint); }

.rank-ladder {
  display: grid;
  gap: 8px;
  margin-top: 14px;
}
.rank-step {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px 16px;
}
.rank-step.master { background: linear-gradient(135deg, #fff8e1, #f6e9b8); border-color: #d4a017; }
.rank-step-symbol {
  width: 36px; height: 36px;
  border-radius: 50%;
  background: var(--ink);
  color: var(--bg);
  display: grid; place-items: center;
  font-family: var(--font-display);
  font-size: 18px;
  flex-shrink: 0;
}
.rank-step.master .rank-step-symbol { background: #d4a017; }

@media (max-width: 600px) {
  .topbar { padding: 12px 16px; }
  .topnav { gap: 14px; }
  .topnav a { font-size: 14px; }
  h1 { font-size: 28px; }
  .lesson { padding: 22px 18px; }
  .app { padding: 20px 14px 48px; }
}
