:root {
  --bg: #f6f5ff;
  --surface: #ffffff;
  --text: #1c1b2e;
  --muted: #6b6a80;
  --line: #e4e2f3;
  --brand: #5b4bff;
  --ok: #18a058;
  --ok-bg: #e6f7ee;
  --bad: #d64545;
  --bad-bg: #fdecec;
  --radius: 18px;
  --shadow: 0 2px 0 rgba(28, 27, 46, .06), 0 8px 24px rgba(28, 27, 46, .06);
  --accent: var(--brand);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12111c;
    --surface: #1d1c2b;
    --text: #f1f0fa;
    --muted: #a3a2b8;
    --line: #2f2d44;
    --ok-bg: #133824;
    --bad-bg: #3b1a1a;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
a { color: inherit; }
main { flex: 1; width: 100%; max-width: 760px; margin: 0 auto; padding: 16px; outline: none; }
h1, h2 { line-height: 1.2; margin: 0 0 .4em; }
h1 { font-size: 1.7rem; }
h2 { font-size: 1.25rem; }

.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top));
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 800; font-size: 1.15rem; text-decoration: none; }
.brand img { border-radius: 8px; }
.stats { display: flex; gap: 14px; font-size: 1rem; }
.stat b { font-variant-numeric: tabular-nums; }

.footer { display: flex; justify-content: center; align-items: center; gap: 16px; padding: 24px 16px 32px; color: var(--muted); font-size: .9rem; }
.footer select { background: var(--surface); color: var(--text); border: 1px solid var(--line); border-radius: 8px; padding: 4px 8px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 48px; padding: 0 22px;
  border: 0; border-radius: 14px;
  background: var(--accent); color: #fff;
  font: inherit; font-weight: 700; text-decoration: none; cursor: pointer;
  box-shadow: 0 4px 0 color-mix(in srgb, var(--accent) 65%, #000);
  transition: transform .06s, box-shadow .06s, opacity .2s;
}
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 color-mix(in srgb, var(--accent) 65%, #000); }
.btn:disabled { opacity: .4; cursor: not-allowed; transform: none; }
.btn-small { min-height: 40px; padding: 0 16px; font-size: .95rem; }
.btn-ghost { background: var(--surface); color: var(--text); border: 2px solid var(--line); box-shadow: 0 4px 0 var(--line); }
.btn-ghost:active { box-shadow: 0 1px 0 var(--line); }

.hero { padding: 12px 0 20px; }
.hero > p { color: var(--muted); margin: 0 0 16px; }
.goal {
  display: flex; align-items: center; gap: 12px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 16px; box-shadow: var(--shadow);
}
.goal > div { flex: 1; }
.goal span { color: var(--muted); }
.goal-icon { font-size: 1.8rem; color: inherit !important; }
.goal-done { border-color: var(--ok); }

.course-grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
.course-card {
  display: flex; flex-direction: column; gap: 4px;
  background: var(--surface); border: 1px solid var(--line); border-top: 6px solid var(--accent);
  border-radius: var(--radius); padding: 16px; text-decoration: none; box-shadow: var(--shadow);
  transition: transform .15s;
}
.course-card:hover { transform: translateY(-2px); }
.course-card h2 { margin: 0; }
.course-card p { margin: 0 0 8px; color: var(--muted); font-size: .95rem; flex: 1; }
.course-card small { color: var(--muted); }
.course-emoji { font-size: 2rem; }
.course-emoji.big { font-size: 3rem; }
.course-topic { font-size: .75rem; text-transform: uppercase; letter-spacing: .08em; font-weight: 800; color: var(--accent); }

.bar { height: 10px; background: var(--line); border-radius: 99px; overflow: hidden; flex: 1; }
.bar span { display: block; height: 100%; background: var(--accent); border-radius: 99px; transition: width .3s; }

.back { display: inline-block; margin: 4px 0 12px; color: var(--muted); text-decoration: none; }
.course-head { display: flex; gap: 14px; align-items: flex-start; margin-bottom: 12px; }
.course-head p { margin: 0; color: var(--muted); }
.disclaimer { background: color-mix(in srgb, #f5a623 14%, var(--surface)); border: 1px solid color-mix(in srgb, #f5a623 40%, transparent); border-radius: 12px; padding: 10px 14px; font-size: .9rem; }
.banner { background: var(--ok-bg); border-radius: 12px; padding: 10px 14px; font-weight: 700; }

.lesson-list { list-style: none; padding: 0; margin: 16px 0; display: grid; gap: 10px; }
.lesson-list a {
  display: flex; align-items: center; gap: 12px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px;
  padding: 12px 14px; text-decoration: none;
}
.lesson-list .num {
  flex: none; width: 36px; height: 36px; border-radius: 50%;
  display: grid; place-items: center; font-weight: 800;
  background: var(--line);
}
.lesson-list .is-done .num { background: var(--ok); color: #fff; }
.lesson-list .is-next a { border: 2px solid var(--accent); }
.lesson-list .is-next .num { background: var(--accent); color: #fff; }
.lesson-list .lt { flex: 1; display: flex; flex-direction: column; }
.lesson-list small { color: var(--muted); }
.lesson-list .go { color: var(--accent); font-weight: 700; }

.lesson { display: flex; flex-direction: column; min-height: calc(100vh - 170px); }
.lesson-top { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; }
.quit { text-decoration: none; font-size: 1.3rem; color: var(--muted); padding: 4px 6px; }
.count { color: var(--muted); font-size: .85rem; font-variant-numeric: tabular-nums; white-space: nowrap; }
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 22px 20px; box-shadow: var(--shadow); animation: pop .25s ease-out;
}
.card p { font-size: 1.08rem; margin: 0; }
.card-emoji { font-size: 3rem; margin-bottom: 6px; }
.q { font-size: 1.2rem; }
.hint { color: var(--muted); font-size: .9rem !important; margin-bottom: 10px !important; }
@keyframes pop { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.options { display: grid; gap: 10px; margin-top: 12px; }
.option, .chip {
  text-align: left; font: inherit; color: var(--text);
  background: var(--bg); border: 2px solid var(--line); border-radius: 14px;
  padding: 12px 14px; cursor: pointer;
}
.option.picked { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 10%, var(--surface)); }
.option.right { border-color: var(--ok); background: var(--ok-bg); }
.option.wrong { border-color: var(--bad); background: var(--bad-bg); }
.option:disabled, .chip:disabled { cursor: default; }

.order-chosen { min-height: 48px; padding-left: 22px; margin: 0 0 12px; display: grid; gap: 8px; }
.order-chosen .empty { color: var(--muted); list-style: none; }
.order-pool { display: flex; flex-wrap: wrap; gap: 8px; }
.chip.on { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 10%, var(--surface)); width: 100%; }

.feedback { margin-top: 14px; border-radius: 14px; padding: 12px 16px; animation: pop .2s ease-out; }
.feedback p { margin: 4px 0 0; }
.feedback.ok { background: var(--ok-bg); color: var(--text); border-left: 5px solid var(--ok); }
.feedback.bad { background: var(--bad-bg); color: var(--text); border-left: 5px solid var(--bad); }
.actions { margin-top: auto; padding-top: 18px; position: sticky; bottom: 0; padding-bottom: max(12px, env(safe-area-inset-bottom)); background: linear-gradient(transparent, var(--bg) 30%); }
.actions .btn { width: 100%; }

.finish { text-align: center; padding: 24px 0; }
.finish-emoji { font-size: 4rem; animation: pop .4s ease-out; }
.earned { font-weight: 800; font-size: 1.2rem; color: var(--accent); }
.muted { color: var(--muted); }
.finish-actions { display: grid; gap: 10px; max-width: 340px; margin: 20px auto 0; }

.ad-slot { margin: 24px 0; min-height: 100px; }
.prose { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; }
.prose h2 { margin-top: 1.2em; }
.center { text-align: center; }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 99px; font-weight: 700; z-index: 10; }

@media (max-width: 420px) {
  h1 { font-size: 1.45rem; }
  .course-head { flex-direction: column; gap: 4px; }
}
