:root {
  --bg: #f6f7fb;
  --bg2: #eef0f7;
  --card: #ffffff;
  --card2: #f8f9fd;
  --text: #171a2c;
  --muted: #5d6380;
  --line: #e3e6f0;
  --accent: #5b5bf0;
  --accent2: #f2602e;
  --accent-soft: #ecebff;
  --good: #12a46b;
  --good-soft: #e3f7ee;
  --bad: #e0453a;
  --bad-soft: #fde9e7;
  --warn: #d48806;
  --warn-soft: #fff5dd;
  --shadow: 0 1px 2px rgba(20, 24, 50, .05), 0 8px 24px rgba(20, 24, 50, .06);
  --radius: 16px;
  --grad: linear-gradient(135deg, #5b5bf0 0%, #9b4dea 55%, #f2602e 100%);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0d1020; --bg2: #13172b; --card: #171b31; --card2: #1d223b; --text: #eceefa; --muted: #9aa0bf;
    --line: #2a2f4b; --accent: #8b8bff; --accent-soft: #24264a; --good: #3ccf91; --good-soft: #13372a;
    --bad: #ff7a70; --bad-soft: #3d1d1d; --warn: #f5b942; --warn-soft: #3a2f14;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 10px 30px rgba(0,0,0,.25); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0d1020; --bg2: #13172b; --card: #171b31; --card2: #1d223b; --text: #eceefa; --muted: #9aa0bf;
  --line: #2a2f4b; --accent: #8b8bff; --accent-soft: #24264a; --good: #3ccf91; --good-soft: #13372a;
  --bad: #ff7a70; --bad-soft: #3d1d1d; --warn: #f5b942; --warn-soft: #3a2f14;
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 10px 30px rgba(0,0,0,.25); color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.6 "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
h1, h2, h3 { line-height: 1.25; margin: 0 0 .5em; letter-spacing: -.01em; }
h1 { font-size: 1.75rem; }
h2 { font-size: 1.3rem; }
h3 { font-size: 1.05rem; margin-top: 1.4em; }
code { font-family: ui-monospace, "Cascadia Code", Consolas, monospace; font-size: .88em; background: var(--bg2); padding: .1em .35em; border-radius: 6px; }
pre { background: var(--bg2); padding: 12px 14px; border-radius: 12px; overflow-x: auto; border: 1px solid var(--line); }
pre code { background: none; padding: 0; }
svg.i { width: 20px; height: 20px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* ---------- Layout */
.shell { display: flex; min-height: 100vh; }
.sidebar {
  width: 248px; flex: none; position: sticky; top: 0; height: 100vh;
  padding: 20px 14px; border-right: 1px solid var(--line); background: var(--card);
  display: flex; flex-direction: column; gap: 18px;
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--text); font-size: 1.15rem; padding: 4px 8px; }
.brand b { background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a {
  display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 10px;
  color: var(--muted); font-weight: 500;
}
.nav a:hover { background: var(--bg2); color: var(--text); }
.nav a.active { background: var(--accent-soft); color: var(--accent); }
.sidebar-foot { margin-top: auto; font-size: .8rem; color: var(--muted); padding: 0 8px; }
.main { flex: 1; min-width: 0; }
.topbar {
  position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 12px;
  padding: 12px 28px; background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: blur(12px); border-bottom: 1px solid var(--line);
}
.brand-mobile { display: none; }
.topbar-stats { display: flex; gap: 8px; margin-left: auto; flex-wrap: wrap; }
.pill {
  display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 999px;
  background: var(--card); border: 1px solid var(--line); font-size: .82rem; font-weight: 600; white-space: nowrap;
}
.pill svg.i { width: 15px; height: 15px; }
.icon-btn {
  width: 38px; height: 38px; display: grid; place-items: center; border-radius: 10px;
  border: 1px solid var(--line); background: var(--card); color: var(--text); cursor: pointer;
}
.view { padding: 28px; max-width: 1180px; margin: 0 auto; outline: none; animation: fade .25s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
.bottomnav { display: none; }

/* ---------- Components */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); }
.grid { display: grid; gap: 16px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.spread { justify-content: space-between; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.mt { margin-top: 24px; }
.mt-s { margin-top: 12px; }
.section-title { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin: 32px 0 14px; }
.section-title h2 { margin: 0; }

.hero {
  position: relative; overflow: hidden; border-radius: 22px; padding: 28px; color: #fff;
  background: var(--grad); box-shadow: var(--shadow);
}
.hero::after {
  content: ""; position: absolute; right: -60px; top: -60px; width: 260px; height: 260px; border-radius: 50%;
  background: rgba(255,255,255,.12);
}
.hero h1 { font-size: 1.9rem; }
.hero p { opacity: .92; max-width: 620px; margin: 0 0 16px; }
.hero .btn { background: #fff; color: #3a2f9a; }
.hero .btn.ghost { background: rgba(255,255,255,.16); color: #fff; border-color: rgba(255,255,255,.35); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 10px 16px; border-radius: 11px;
  border: 1px solid transparent; background: var(--accent); color: #fff; font: inherit; font-weight: 600;
  cursor: pointer; transition: transform .08s ease, filter .15s ease; text-align: center;
}
.btn:hover { filter: brightness(1.07); }
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.ghost { background: transparent; color: var(--text); border-color: var(--line); }
.btn.soft { background: var(--accent-soft); color: var(--accent); }
.btn.danger { background: var(--bad); }
.btn.sm { padding: 6px 12px; font-size: .88rem; }
.btn.block { width: 100%; }

.stat { display: flex; flex-direction: column; gap: 2px; }
.stat .v { font-size: 1.6rem; font-weight: 700; letter-spacing: -.02em; }
.stat .l { font-size: .82rem; color: var(--muted); }
.stat .ico { width: 38px; height: 38px; border-radius: 11px; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); margin-bottom: 8px; }

.bar { height: 8px; border-radius: 999px; background: var(--bg2); overflow: hidden; }
.bar > i { display: block; height: 100%; border-radius: inherit; background: var(--grad); transition: width .5s ease; }
.bar.good > i { background: var(--good); }

.ring { --p: 0; --c: var(--accent); width: 76px; height: 76px; border-radius: 50%; display: grid; place-items: center; flex: none;
  background: conic-gradient(var(--c) calc(var(--p) * 1%), var(--bg2) 0); }
.ring > span { width: 60px; height: 60px; border-radius: 50%; background: var(--card); display: grid; place-items: center; font-weight: 700; font-size: .95rem; }

.tag { display: inline-flex; align-items: center; gap: 4px; padding: 2px 9px; border-radius: 999px; font-size: .75rem; font-weight: 600; background: var(--bg2); color: var(--muted); }
.tag.good { background: var(--good-soft); color: var(--good); }
.tag.accent { background: var(--accent-soft); color: var(--accent); }
.tag.warn { background: var(--warn-soft); color: var(--warn); }

.module-card { display: flex; flex-direction: column; gap: 12px; color: var(--text); transition: transform .15s ease, border-color .15s; }
.module-card:hover { transform: translateY(-2px); border-color: var(--accent); }
.module-card .head { display: flex; gap: 12px; align-items: flex-start; }
.mod-ico { width: 44px; height: 44px; border-radius: 12px; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); flex: none; }
.module-card h3 { margin: 0 0 2px; font-size: 1rem; }
.module-card p { margin: 0; color: var(--muted); font-size: .88rem; }

.cert-card { position: relative; overflow: hidden; color: var(--text); display: flex; flex-direction: column; gap: 10px; }
.cert-card::before { content: ""; position: absolute; inset: 0 0 auto 0; height: 4px; background: var(--cc, var(--accent)); }
.cert-card:hover { border-color: var(--cc, var(--accent)); }

.list { display: flex; flex-direction: column; gap: 8px; }
.list-item { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--card); color: var(--text); }
.list-item:hover { border-color: var(--accent); }
.list-item .grow { flex: 1; min-width: 0; }
.check { width: 26px; height: 26px; border-radius: 50%; border: 2px solid var(--line); display: grid; place-items: center; flex: none; color: transparent; }
.check.done { background: var(--good); border-color: var(--good); color: #fff; }
.check svg.i { width: 15px; height: 15px; stroke-width: 3; }

/* Lesson */
.crumbs { display: flex; gap: 6px; align-items: center; font-size: .85rem; color: var(--muted); margin-bottom: 14px; flex-wrap: wrap; }
.crumbs a { color: var(--muted); }
.crumbs a:hover { color: var(--accent); }
.lesson { max-width: 780px; }
.lesson-body { font-size: 1rem; }
.lesson-body table { width: 100%; border-collapse: collapse; margin: 12px 0; font-size: .92rem; display: block; overflow-x: auto; }
.lesson-body th, .lesson-body td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
.lesson-body th { background: var(--bg2); font-weight: 600; }
.lesson-body li { margin: 4px 0; }
.callout { border-left: 4px solid var(--accent); background: var(--accent-soft); padding: 12px 16px; border-radius: 0 12px 12px 0; margin: 16px 0; }
.callout.tip { border-color: var(--good); background: var(--good-soft); }
.callout.warn { border-color: var(--warn); background: var(--warn-soft); }

/* Quiz */
.quiz { max-width: 760px; margin: 0 auto; }
.quiz-head { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; }
.quiz-head .bar { flex: 1; }
.question { font-size: 1.12rem; font-weight: 600; margin: 4px 0 18px; }
.options { display: flex; flex-direction: column; gap: 10px; }
.option {
  display: flex; gap: 12px; align-items: flex-start; width: 100%; text-align: left; padding: 14px 16px;
  border-radius: 13px; border: 1.5px solid var(--line); background: var(--card); color: var(--text); font: inherit; cursor: pointer;
  transition: border-color .12s, background .12s;
}
.option:hover:not(:disabled) { border-color: var(--accent); }
.option .key { width: 26px; height: 26px; border-radius: 8px; display: grid; place-items: center; background: var(--bg2); font-weight: 700; font-size: .82rem; flex: none; }
.option.selected { border-color: var(--accent); background: var(--accent-soft); }
.option.selected .key { background: var(--accent); color: #fff; }
.option.correct { border-color: var(--good); background: var(--good-soft); }
.option.correct .key { background: var(--good); color: #fff; }
.option.wrong { border-color: var(--bad); background: var(--bad-soft); }
.option.wrong .key { background: var(--bad); color: #fff; }
.option:disabled { cursor: default; }
.explain { margin-top: 16px; padding: 14px 16px; border-radius: 13px; background: var(--card2); border: 1px solid var(--line); }
.explain b.ok { color: var(--good); }
.explain b.no { color: var(--bad); }
.quiz-foot { display: flex; justify-content: space-between; gap: 10px; margin-top: 20px; flex-wrap: wrap; }

.timer { font-variant-numeric: tabular-nums; }
.timer.low { color: var(--bad); border-color: var(--bad); }
.navgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(38px, 1fr)); gap: 6px; }
.navgrid button { height: 36px; border-radius: 9px; border: 1px solid var(--line); background: var(--card); color: var(--text); font: inherit; font-size: .82rem; cursor: pointer; position: relative; }
.navgrid button.answered { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.navgrid button.current { outline: 2px solid var(--accent); outline-offset: 1px; }
.navgrid button.flagged::after { content: ""; position: absolute; top: 3px; right: 3px; width: 7px; height: 7px; border-radius: 50%; background: var(--warn); }
.navgrid button.good { background: var(--good-soft); border-color: var(--good); color: var(--good); }
.navgrid button.bad { background: var(--bad-soft); border-color: var(--bad); color: var(--bad); }

.result-hero { text-align: center; padding: 32px 20px; }
.result-hero .big { font-size: 3rem; font-weight: 800; letter-spacing: -.03em; }

/* Flashcards */
.flash-wrap { max-width: 620px; margin: 0 auto; perspective: 1400px; }
.flash { position: relative; height: 300px; cursor: pointer; transform-style: preserve-3d; transition: transform .5s cubic-bezier(.3,.7,.3,1); }
.flash.flipped { transform: rotateY(180deg); }
.flash .face {
  position: absolute; inset: 0; backface-visibility: hidden; border-radius: 22px; padding: 28px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center;
  background: var(--card); border: 1px solid var(--line); box-shadow: var(--shadow);
}
.flash .front { background: var(--grad); color: #fff; border: none; }
.flash .front h2 { font-size: 1.7rem; margin: 0; }
.flash .back { transform: rotateY(180deg); font-size: 1.08rem; opacity: 0; }
.flash .face { -webkit-backface-visibility: hidden; transition: opacity 0s linear .2s; }
.flash.flipped .front { opacity: 0; }
.flash.flipped .back { opacity: 1; }
.flash .hint { position: absolute; bottom: 14px; font-size: .78rem; opacity: .75; }
.rate { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 18px; }

/* Forms */
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-weight: 600; font-size: .9rem; }
input[type=text], input[type=search], select {
  font: inherit; padding: 10px 12px; border-radius: 11px; border: 1px solid var(--line); background: var(--card); color: var(--text); width: 100%;
}
input:focus, select:focus, .btn:focus-visible, .option:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { padding: 7px 13px; border-radius: 999px; border: 1px solid var(--line); background: var(--card); color: var(--text); cursor: pointer; font: inherit; font-size: .88rem; }
.chip.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.seg { display: inline-flex; background: var(--bg2); border-radius: 12px; padding: 4px; gap: 4px; flex-wrap: wrap; }
.seg button { border: 0; background: transparent; color: var(--muted); padding: 7px 14px; border-radius: 9px; font: inherit; font-weight: 600; cursor: pointer; }
.seg button.on { background: var(--card); color: var(--text); box-shadow: var(--shadow); }

.gloss-item { padding: 14px 16px; border-bottom: 1px solid var(--line); }
.gloss-item:last-child { border: 0; }
.gloss-item b { display: block; }

.heat { display: grid; grid-template-columns: repeat(14, 1fr); gap: 4px; }
.heat span { aspect-ratio: 1; border-radius: 4px; background: var(--bg2); }
.heat span.l1 { background: color-mix(in srgb, var(--accent) 35%, var(--bg2)); }
.heat span.l2 { background: color-mix(in srgb, var(--accent) 65%, var(--bg2)); }
.heat span.l3 { background: var(--accent); }

.toast {
  position: fixed; left: 50%; bottom: 28px; transform: translate(-50%, 30px); opacity: 0; pointer-events: none;
  background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 12px; font-weight: 600; z-index: 50;
  transition: all .25s ease; max-width: calc(100vw - 32px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.code-box { font-family: ui-monospace, Consolas, monospace; font-size: 1.3rem; font-weight: 700; letter-spacing: .08em; padding: 10px 14px; border-radius: 11px; background: var(--bg2); display: inline-block; }
.empty { text-align: center; padding: 40px 20px; color: var(--muted); }

/* ---------- Responsive */
@media (max-width: 1080px) { .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .g3 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 860px) {
  .sidebar { display: none; }
  .brand-mobile { display: flex; padding: 0; font-size: 1.05rem; }
  .topbar { padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top)); }
  .topbar-stats .pill.hide-m { display: none; }
  .view { padding: 18px 16px 110px; }
  .g2, .g3 { grid-template-columns: minmax(0, 1fr); }
  .hero { padding: 22px; } .hero h1 { font-size: 1.5rem; }
  h1 { font-size: 1.45rem; }
  .bottomnav {
    display: grid; grid-template-columns: repeat(5, 1fr); position: fixed; bottom: 0; left: 0; right: 0; z-index: 20;
    background: color-mix(in srgb, var(--card) 92%, transparent); backdrop-filter: blur(14px);
    border-top: 1px solid var(--line); padding: 6px 4px max(6px, env(safe-area-inset-bottom));
  }
  .bottomnav a { display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: .7rem; color: var(--muted); padding: 6px 0; border-radius: 10px; }
  .bottomnav a.active { color: var(--accent); }
  .flash { height: 260px; }
  .toast { bottom: 92px; }
}
@media (max-width: 420px) { .g4 { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 10px; } .card { padding: 16px; } .stat .v { font-size: 1.3rem; } }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
