/* ═══════════════ Ars Medica · Praeparatio ═══════════════ */

:root {
  --bg: #f6f2ea;
  --bg-2: #efe9dd;
  --surface: #fffdf9;
  --surface-2: #faf6ef;
  --ink: #1d1916;
  --ink-2: #4a423b;
  --muted: #7a7065;
  --line: #e6ddcf;
  --line-2: #d9cebd;

  --accent: #8a1c2b;
  --accent-ink: #ffffff;
  --accent-soft: #f5e6e4;
  --accent-2: #b8862f;
  --accent-2-soft: #f7eedb;

  --ok: #2e7a57;
  --ok-soft: #e3f1e9;
  --bad: #b3372f;
  --bad-soft: #f9e5e2;
  --warn: #a86a12;
  --warn-soft: #fbefd9;
  --info: #2f5f8a;
  --info-soft: #e4edf6;

  --heat-0: #ece5d8;
  --heat-1: #e5c2bd;
  --heat-2: #cf8a86;
  --heat-3: #ab4a50;
  --heat-4: #8a1c2b;

  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(40, 28, 16, .05), 0 4px 18px rgba(40, 28, 16, .05);
  --shadow-lg: 0 10px 40px rgba(40, 28, 16, .12);

  --font: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --serif: 'Cormorant Garamond', 'Georgia', 'Times New Roman', serif;
  --sidebar: 248px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #141110; --bg-2: #1b1715; --surface: #1f1b18; --surface-2: #26211d;
    --ink: #f2ece4; --ink-2: #d4cabd; --muted: #a0968a; --line: #332d28; --line-2: #443c35;
    --accent: #e0707d; --accent-ink: #1a0d0f; --accent-soft: #3a2024; --accent-2: #d9ab58; --accent-2-soft: #3a2f1b;
    --ok: #5fc08f; --ok-soft: #173327; --bad: #ef7d73; --bad-soft: #3b1f1c; --warn: #e3a64a; --warn-soft: #3a2c15; --info: #7fb0dc; --info-soft: #1a2a39;
    --heat-0: #2a2420; --heat-1: #4a2a2e; --heat-2: #7a3a42; --heat-3: #b25360; --heat-4: #e0707d;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 4px 18px rgba(0,0,0,.25); --shadow-lg: 0 10px 40px rgba(0,0,0,.5);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #141110; --bg-2: #1b1715; --surface: #1f1b18; --surface-2: #26211d;
  --ink: #f2ece4; --ink-2: #d4cabd; --muted: #a0968a; --line: #332d28; --line-2: #443c35;
  --accent: #e0707d; --accent-ink: #1a0d0f; --accent-soft: #3a2024; --accent-2: #d9ab58; --accent-2-soft: #3a2f1b;
  --ok: #5fc08f; --ok-soft: #173327; --bad: #ef7d73; --bad-soft: #3b1f1c; --warn: #e3a64a; --warn-soft: #3a2c15; --info: #7fb0dc; --info-soft: #1a2a39;
  --heat-0: #2a2420; --heat-1: #4a2a2e; --heat-2: #7a3a42; --heat-3: #b25360; --heat-4: #e0707d;
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 4px 18px rgba(0,0,0,.25); --shadow-lg: 0 10px 40px rgba(0,0,0,.5);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 15px/1.6 var(--font); -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select, textarea { font: inherit; color: inherit; }
img, svg { display: block; }
svg[viewBox="0 0 24 24"] { width: 1.15em; height: 1.15em; flex: none; }
.ai-result-head svg { width: 20px; height: 20px; color: var(--accent); }
.ring-label b, .stat-val, .ai-score, .result-card .big, .module-num, .page-head h1, .lesson-head h1, .hero h2, .card h2, .lesson-card h3 { font-variant-numeric: lining-nums; }
h1, h2, h3, h4 { margin: 0; line-height: 1.2; }
.serif { font-family: var(--serif); }
::selection { background: var(--accent-soft); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }

/* ───── Layout ───── */
.app { min-height: 100vh; }
.sidebar {
  position: fixed; inset: 0 auto 0 0; width: var(--sidebar);
  background: var(--surface); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; padding: 22px 14px; z-index: 20;
}
.main { margin-left: var(--sidebar); padding: 36px 44px 80px; max-width: calc(1180px + var(--sidebar)); outline: none; }
.topbar, .bottom-nav { display: none; }

.brand { display: flex; align-items: center; gap: 12px; padding: 4px 10px 22px; color: var(--ink); }
.brand:hover { text-decoration: none; }
.brand-mark {
  width: 38px; height: 38px; border-radius: 11px; display: grid; place-items: center;
  background: var(--accent); color: var(--accent-ink); font: 700 17px/1 var(--serif); letter-spacing: .5px;
}
.brand-text { display: flex; flex-direction: column; line-height: 1.1; }
.brand-text b { font: 700 21px/1 var(--serif); }
.brand-text small { color: var(--muted); font-size: 12px; letter-spacing: .12em; text-transform: uppercase; margin-top: 3px; }

.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(--ink-2); font-weight: 500;
}
.nav a:hover { background: var(--surface-2); text-decoration: none; }
.nav a.active { background: var(--accent-soft); color: var(--accent); }
.nav svg { width: 19px; height: 19px; flex: none; }
.sidebar-foot { margin-top: auto; padding: 12px; font-size: 13px; color: var(--muted); }
.ai-pill { display: inline-flex; align-items: center; gap: 7px; padding: 5px 10px; border-radius: 99px; background: var(--surface-2); border: 1px solid var(--line); font-size: 12.5px; color: var(--ink-2); }
.ai-pill .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.ai-pill.on .dot { background: var(--ok); }

/* ───── Common ───── */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; margin-bottom: 28px; flex-wrap: wrap; }
.page-head h1 { font: 700 40px/1.05 var(--serif); letter-spacing: -.01em; }
.page-head p { margin: 6px 0 0; color: var(--muted); }
.eyebrow { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .14em; color: var(--accent); margin-bottom: 8px; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 22px; }
.card h2 { font: 700 24px/1.15 var(--serif); }
.card h3 { font-size: 15px; font-weight: 600; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.card-head .muted { font-size: 13px; }
.muted { color: var(--muted); }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 18px; }
.stack { display: flex; flex-direction: column; gap: 18px; }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.spacer { flex: 1; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 18px; border-radius: 10px; border: 1px solid var(--line-2);
  background: var(--surface); color: var(--ink); font-weight: 600; font-size: 14px; cursor: pointer;
  transition: background .15s, border-color .15s, transform .05s;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn svg { width: 17px; height: 17px; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { background: var(--accent); filter: brightness(1.08); }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-ghost:hover { background: var(--surface-2); }
.btn-sm { padding: 6px 12px; font-size: 13px; border-radius: 8px; }
.btn-lg { padding: 13px 22px; font-size: 15px; }
.btn-danger { color: var(--bad); }

.badge { display: inline-flex; align-items: center; gap: 5px; padding: 3px 9px; border-radius: 99px; font-size: 12px; font-weight: 600; background: var(--surface-2); color: var(--ink-2); border: 1px solid var(--line); white-space: nowrap; }
.badge svg { width: 13px; height: 13px; }
.badge.ok { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.badge.bad { background: var(--bad-soft); color: var(--bad); border-color: transparent; }
.badge.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.badge.accent { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.badge.info { background: var(--info-soft); color: var(--info); border-color: transparent; }

.progress { height: 8px; border-radius: 99px; background: var(--bg-2); overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--accent); border-radius: 99px; transition: width .5s ease; }
.progress.ok > span { background: var(--ok); }

.empty { text-align: center; padding: 26px 10px; color: var(--muted); font-size: 14px; }

/* ───── Forms ───── */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; }
.field label { font-size: 13px; font-weight: 600; color: var(--ink-2); }
.field .hint { font-size: 12.5px; color: var(--muted); }
.input, select.input, textarea.input {
  width: 100%; padding: 10px 13px; border-radius: 10px; border: 1px solid var(--line-2);
  background: var(--surface); transition: border-color .15s, box-shadow .15s;
}
.input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
textarea.input { min-height: 96px; resize: vertical; line-height: 1.5; }
.switch { display: flex; align-items: flex-start; gap: 12px; cursor: pointer; padding: 10px 0; }
.switch input { width: 40px; height: 22px; appearance: none; border-radius: 99px; background: var(--line-2); position: relative; cursor: pointer; flex: none; transition: background .15s; margin-top: 1px; }
.switch input::after { content: ''; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: transform .15s; box-shadow: 0 1px 2px rgba(0,0,0,.2); }
.switch input:checked { background: var(--accent); }
.switch input:checked::after { transform: translateX(18px); }
.switch b { display: block; font-weight: 600; font-size: 14px; }
.switch small { color: var(--muted); font-size: 13px; }
.seg { display: inline-flex; background: var(--bg-2); border-radius: 10px; padding: 3px; gap: 2px; flex-wrap: wrap; }
.seg button { border: 0; background: transparent; padding: 7px 14px; border-radius: 8px; cursor: pointer; font-weight: 500; font-size: 13.5px; color: var(--ink-2); }
.seg button.active { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }

/* ───── Dashboard ───── */
.hero {
  display: grid; grid-template-columns: 1fr auto; gap: 28px; align-items: center;
  background: linear-gradient(135deg, var(--surface) 0%, var(--surface-2) 100%);
  position: relative; overflow: hidden;
}
.hero::after {
  content: 'Ars longa'; position: absolute; right: -10px; bottom: -34px; font: italic 600 120px/1 var(--serif);
  color: var(--accent); opacity: .05; pointer-events: none; white-space: nowrap;
}
.hero h2 { font: 700 30px/1.1 var(--serif); margin-bottom: 6px; }
.hero .next-title { font-size: 17px; font-weight: 600; margin: 14px 0 4px; }
.ring { width: 150px; height: 150px; position: relative; flex: none; }
.ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring .ring-bg { stroke: var(--bg-2); }
.ring .ring-fg { stroke: var(--accent); transition: stroke-dashoffset .8s ease; }
.ring-label { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; }
.ring-label b { font: 700 36px/1 var(--serif); }
.ring-label small { font-size: 12px; color: var(--muted); }

.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; }
.stat { padding: 18px; }
.stat .stat-top { display: flex; align-items: center; justify-content: space-between; color: var(--muted); font-size: 13px; }
.stat .stat-top svg { width: 18px; height: 18px; color: var(--accent); }
.stat .stat-val { font: 700 32px/1.1 var(--serif); margin-top: 8px; }
.stat .stat-sub { font-size: 12.5px; color: var(--muted); }

.module-row { display: grid; grid-template-columns: 34px 1fr auto; gap: 12px; align-items: center; padding: 10px 0; border-bottom: 1px dashed var(--line); }
.module-row:last-child { border-bottom: 0; }
.module-num { font: 700 18px/1 var(--serif); color: var(--accent); text-align: center; }
.module-row .t { font-weight: 600; font-size: 14px; margin-bottom: 6px; }
.module-row .v { font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }

.heatmap { display: grid; grid-auto-flow: column; grid-template-rows: repeat(7, 13px); gap: 3px; overflow-x: auto; padding-bottom: 4px; }
.heatmap i { width: 13px; height: 13px; border-radius: 3px; background: var(--heat-0); }
.heatmap i[data-l="1"] { background: var(--heat-1); }
.heatmap i[data-l="2"] { background: var(--heat-2); }
.heatmap i[data-l="3"] { background: var(--heat-3); }
.heatmap i[data-l="4"] { background: var(--heat-4); }
.heatmap i.future { opacity: .3; }
.heat-legend { display: flex; align-items: center; gap: 4px; font-size: 12px; color: var(--muted); margin-top: 10px; }
.heat-legend i { width: 11px; height: 11px; border-radius: 3px; display: inline-block; }

.days-strip { display: grid; grid-template-columns: repeat(10, 1fr); gap: 6px; }
.day-dot {
  aspect-ratio: 1; border-radius: 9px; display: grid; place-items: center; font-size: 13px; font-weight: 600;
  background: var(--bg-2); color: var(--muted); border: 1px solid transparent;
}
.day-dot.done { background: var(--accent); color: var(--accent-ink); }
.day-dot.current { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }
.day-dot:hover { text-decoration: none; filter: brightness(.97); }

.weak-item { display: flex; align-items: center; gap: 12px; padding: 9px 0; border-bottom: 1px dashed var(--line); }
.weak-item:last-child { border-bottom: 0; }
.weak-item .name { flex: 1; font-size: 14px; font-weight: 500; }
.weak-item .bar { width: 90px; }
.weak-item .pct { width: 44px; text-align: right; font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }

.err-item { padding: 10px 0; border-bottom: 1px dashed var(--line); font-size: 13.5px; }
.err-item:last-child { border-bottom: 0; }
.err-item .q { color: var(--ink-2); }
.err-item .a { margin-top: 4px; display: flex; gap: 10px; flex-wrap: wrap; }
.err-item s { color: var(--bad); }
.err-item b { color: var(--ok); font-weight: 600; }

.proverb-card { text-align: center; padding: 26px 22px; }
.proverb-card .la { font: italic 600 26px/1.2 var(--serif); color: var(--accent); }
.proverb-card .ru { margin-top: 8px; color: var(--muted); }

/* ───── Program ───── */
.module-block { margin-bottom: 34px; }
.module-block-head { display: flex; align-items: baseline; gap: 14px; margin-bottom: 14px; flex-wrap: wrap; }
.module-block-head .num { font: 700 44px/1 var(--serif); color: var(--accent); opacity: .85; }
.module-block-head h2 { font: 700 26px/1.1 var(--serif); }
.module-block-head p { margin: 2px 0 0; color: var(--muted); font-size: 14px; }
.lesson-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 14px; }
.lesson-card { display: flex; flex-direction: column; gap: 10px; color: var(--ink); position: relative; transition: transform .15s, box-shadow .15s, border-color .15s; padding: 18px 18px 16px; }
a.lesson-card:hover { text-decoration: none; transform: translateY(-2px); box-shadow: var(--shadow-lg); border-color: var(--line-2); }
.lesson-card .top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.lesson-card .day-no { font: 700 14px/1 var(--font); color: var(--muted); letter-spacing: .08em; text-transform: uppercase; }
.lesson-card h3 { font: 700 21px/1.15 var(--serif); }
.lesson-card p { margin: 0; color: var(--muted); font-size: 13.5px; line-height: 1.45; }
.lesson-card .foot { display: flex; align-items: center; gap: 10px; margin-top: auto; font-size: 12.5px; color: var(--muted); }
.lesson-card .foot svg { width: 14px; height: 14px; }
.lesson-card.locked { opacity: .6; background: var(--surface-2); box-shadow: none; }
.lesson-card.current { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft), var(--shadow); }
.lesson-card.done .day-no { color: var(--ok); }

/* ───── Lesson ───── */
.lesson-head { margin-bottom: 20px; }
.lesson-head .crumbs { font-size: 13px; color: var(--muted); margin-bottom: 10px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.lesson-head h1 { font: 700 42px/1.05 var(--serif); }
.lesson-head .sub { color: var(--muted); margin-top: 6px; font-size: 16px; }
.lesson-meta { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 14px; }

.steps { display: flex; gap: 6px; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 6px; margin-bottom: 22px; position: sticky; top: 10px; z-index: 5; box-shadow: var(--shadow); overflow-x: auto; }
.steps button { flex: 1; display: flex; align-items: center; justify-content: center; gap: 8px; border: 0; background: transparent; padding: 10px 12px; border-radius: 10px; cursor: pointer; font-weight: 600; font-size: 14px; color: var(--muted); white-space: nowrap; }
.steps button .n { width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; font-size: 12px; background: var(--bg-2); color: var(--muted); }
.steps button.active { background: var(--accent-soft); color: var(--accent); }
.steps button.active .n { background: var(--accent); color: var(--accent-ink); }
.steps button.seen .n { background: var(--ok-soft); color: var(--ok); }

.lesson-body { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 22px; align-items: start; }
.lesson-side { position: sticky; top: 84px; display: flex; flex-direction: column; gap: 14px; }
.goals { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 8px; font-size: 14px; }
.goals li { display: flex; gap: 9px; }
.goals li::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: var(--accent); margin-top: 9px; flex: none; }

.video-wrap { position: relative; aspect-ratio: 16 / 9; border-radius: 12px; overflow: hidden; background: #000; }
.video-wrap iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }
.video-list { display: flex; flex-direction: column; gap: 10px; margin-top: 14px; }
.video-item { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line); cursor: pointer; background: var(--surface); text-align: left; width: 100%; }
.video-item.active { border-color: var(--accent); background: var(--accent-soft); }
.video-item svg { width: 18px; height: 18px; color: var(--accent); flex: none; }

/* theory typography */
.prose { font-size: 15.5px; line-height: 1.7; }
.prose h3 { font: 700 23px/1.2 var(--serif); margin: 28px 0 10px; }
.prose h3:first-child { margin-top: 0; }
.prose p { margin: 0 0 12px; }
.prose .lead { font-size: 17px; color: var(--ink-2); }
.prose ul.clean { padding-left: 0; list-style: none; margin: 0 0 14px; }
.prose ul.clean li { padding: 6px 0 6px 20px; position: relative; border-bottom: 1px dashed var(--line); }
.prose ul.clean li:last-child { border-bottom: 0; }
.prose ul.clean li::before { content: '›'; position: absolute; left: 4px; color: var(--accent); font-weight: 700; }
.prose i { font-family: var(--serif); font-size: 1.12em; font-weight: 600; color: var(--accent); font-style: italic; }
.prose ol { padding-left: 22px; margin: 6px 0 0; }
.prose .rule, .prose .note, .prose .tip { border-radius: 12px; padding: 14px 16px; margin: 16px 0; font-size: 15px; }
.prose .rule { background: var(--accent-soft); border-left: 4px solid var(--accent); }
.prose .note { background: var(--info-soft); border-left: 4px solid var(--info); }
.prose .tip { background: var(--accent-2-soft); border-left: 4px solid var(--accent-2); }
.prose .recipe { font-family: var(--serif); font-size: 18px; line-height: 1.5; background: var(--surface-2); border: 1px dashed var(--line-2); border-radius: 12px; padding: 14px 18px; margin: 12px 0; }
.prose .formula { display: inline-flex; font: 600 22px/1 var(--serif); background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px; padding: 10px 16px; margin: 4px 0 12px; }
.prose .formula span:nth-child(2) { color: var(--accent); }
.prose .formula span:nth-child(3) { color: var(--info); }
.cards3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin: 14px 0; }
.cards3 .mini { background: var(--surface-2); border: 1px solid var(--line); border-radius: 12px; padding: 14px; }
.cards3 .mini h4 { font: 700 18px/1.1 var(--serif); margin-bottom: 6px; color: var(--accent); }
.cards3 .mini p { margin: 0; font-size: 13.5px; }

.table-wrap { overflow-x: auto; margin: 10px 0 16px; border: 1px solid var(--line); border-radius: 12px; }
table.grid, table.decl { width: 100%; border-collapse: collapse; font-size: 14px; }
table.grid th, table.decl th { background: var(--surface-2); text-align: left; font-weight: 600; font-size: 12.5px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
table.grid th, table.grid td, table.decl th, table.decl td { padding: 9px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.grid tr:last-child td, table.decl tr:last-child td { border-bottom: 0; }
table.grid.center td, table.grid.center th { text-align: center; }
table.decl td { font-family: var(--serif); font-size: 17px; }
table.decl td:first-child { font-family: var(--font); font-size: 13px; font-weight: 600; color: var(--muted); }
table.decl td b { color: var(--accent); }

/* vocab */
.vocab { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 10px; }
.vocab-item { padding: 12px 14px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); }
.vocab-item .la { font: 600 18px/1.2 var(--serif); color: var(--accent); }
.vocab-item .ru { font-size: 14px; color: var(--ink-2); margin-top: 2px; }

/* exercises */
.ex-list { display: flex; flex-direction: column; gap: 14px; }
.ex { border: 1px solid var(--line); border-radius: 14px; background: var(--surface); padding: 18px 20px; transition: border-color .2s; }
.ex.correct { border-color: color-mix(in srgb, var(--ok) 45%, var(--line)); }
.ex.wrong { border-color: color-mix(in srgb, var(--bad) 45%, var(--line)); }
.ex.partial { border-color: color-mix(in srgb, var(--warn) 45%, var(--line)); }
.ex-head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.ex-num { width: 26px; height: 26px; border-radius: 8px; display: grid; place-items: center; font-size: 12.5px; font-weight: 700; background: var(--bg-2); color: var(--muted); flex: none; }
.ex.correct .ex-num { background: var(--ok); color: #fff; }
.ex.wrong .ex-num { background: var(--bad); color: #fff; }
.ex.partial .ex-num { background: var(--warn); color: #fff; }
.ex-q { font-size: 15.5px; margin-bottom: 12px; }
.ex-q i { font-family: var(--serif); font-size: 1.12em; font-weight: 600; color: var(--accent); }
.options { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 8px; }
.option { display: flex; align-items: center; gap: 10px; padding: 11px 14px; border-radius: 10px; border: 1px solid var(--line-2); background: var(--surface); cursor: pointer; text-align: left; transition: border-color .15s, background .15s; font-family: var(--serif); font-size: 17px; font-weight: 500; }
.option:hover:not(:disabled) { border-color: var(--accent); background: var(--accent-soft); }
.option:disabled { cursor: default; }
.option.chosen-ok { border-color: var(--ok); background: var(--ok-soft); color: var(--ok); }
.option.chosen-bad { border-color: var(--bad); background: var(--bad-soft); color: var(--bad); }
.option.reveal { border-color: var(--ok); border-style: dashed; }
.ex-input-row { display: flex; gap: 8px; }
.ex-input-row .input { font-family: var(--serif); font-size: 18px; font-weight: 500; }
.match-row { display: grid; grid-template-columns: minmax(120px, 1fr) minmax(160px, 1.4fr); gap: 10px; align-items: center; padding: 6px 0; }
.match-row .l { font: 600 17px/1.2 var(--serif); color: var(--accent); }
.match-row select.ok { border-color: var(--ok); background: var(--ok-soft); }
.match-row select.bad { border-color: var(--bad); background: var(--bad-soft); }
.feedback { margin-top: 12px; padding: 12px 14px; border-radius: 10px; font-size: 14px; }
.feedback.ok { background: var(--ok-soft); color: var(--ink); }
.feedback.bad { background: var(--bad-soft); color: var(--ink); }
.feedback.warn { background: var(--warn-soft); color: var(--ink); }
.feedback .fb-title { font-weight: 700; margin-bottom: 2px; }
.feedback.ok .fb-title { color: var(--ok); }
.feedback.bad .fb-title { color: var(--bad); }
.feedback.warn .fb-title { color: var(--warn); }
.feedback .answer { font-family: var(--serif); font-size: 17px; font-weight: 600; }
.ex-actions { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }

.ai-result { margin-top: 14px; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.ai-result-head { display: flex; align-items: center; gap: 12px; padding: 12px 14px; background: var(--surface-2); border-bottom: 1px solid var(--line); }
.ai-score { font: 700 26px/1 var(--serif); }
.ai-result-body { padding: 14px; font-size: 14px; }
.ai-result-body h5 { margin: 14px 0 6px; font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.ai-result-body h5:first-child { margin-top: 0; }
.ai-err { border-left: 3px solid var(--bad); padding: 8px 12px; background: var(--bad-soft); border-radius: 0 8px 8px 0; margin-bottom: 8px; }
.ai-err .frag { font-family: var(--serif); font-size: 16px; font-weight: 600; }
.ai-err .arrow { color: var(--muted); margin: 0 6px; }
.ai-err .fix { font-family: var(--serif); font-size: 16px; font-weight: 600; color: var(--ok); }
.ai-err .type { font-size: 11.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--bad); }
.ai-corrected { font-family: var(--serif); font-size: 17px; background: var(--ok-soft); padding: 10px 12px; border-radius: 8px; }
.ai-recs { margin: 0; padding-left: 18px; }
.ai-recs li { margin-bottom: 4px; }
.ai-raw { white-space: pre-wrap; }

.spinner { width: 16px; height: 16px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.result-card { text-align: center; padding: 30px 22px; }
.result-card .big { font: 700 64px/1 var(--serif); }
.result-card.pass .big { color: var(--ok); }
.result-card.fail .big { color: var(--bad); }
.result-card h3 { font: 700 26px/1.1 var(--serif); margin: 8px 0 6px; }

.tutor-log { display: flex; flex-direction: column; gap: 10px; max-height: 360px; overflow-y: auto; margin-bottom: 10px; }
.msg { padding: 10px 12px; border-radius: 12px; font-size: 14px; white-space: pre-wrap; }
.msg.user { background: var(--accent-soft); align-self: flex-end; max-width: 90%; }
.msg.ai { background: var(--surface-2); border: 1px solid var(--line); }

/* ───── Reference ───── */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 20px; overflow-x: auto; }
.tabs button { border: 0; background: transparent; padding: 11px 16px; font-weight: 600; font-size: 14px; color: var(--muted); cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tabs button.active { color: var(--accent); border-bottom-color: var(--accent); }
.dict-row { display: grid; grid-template-columns: minmax(180px, 1fr) 1.2fr auto; gap: 14px; padding: 10px 4px; border-bottom: 1px solid var(--line); align-items: baseline; }
.dict-row .la { font: 600 18px/1.25 var(--serif); color: var(--accent); }
.dict-row .ru { font-size: 14.5px; }
.dict-row .src { font-size: 12px; color: var(--muted); white-space: nowrap; }
mark { background: var(--accent-2-soft); color: inherit; border-radius: 3px; padding: 0 2px; }

/* ───── Trainer ───── */
.flash-wrap { max-width: 560px; margin: 0 auto; }
.flash { perspective: 1200px; cursor: pointer; height: 280px; }
.flash-inner { position: relative; width: 100%; height: 100%; transition: transform .5s; transform-style: preserve-3d; }
.flash.flipped .flash-inner { transform: rotateY(180deg); }
.flash-face { position: absolute; inset: 0; backface-visibility: hidden; display: grid; place-content: center; text-align: center; padding: 24px; border-radius: 18px; border: 1px solid var(--line); background: var(--surface); box-shadow: var(--shadow-lg); }
.flash-face.back { transform: rotateY(180deg); background: var(--surface-2); }
.flash-face .w { font: 700 38px/1.15 var(--serif); color: var(--accent); }
.flash-face .t { font-size: 22px; font-weight: 600; }
.flash-face .h { margin-top: 12px; font-size: 13px; color: var(--muted); }
.flash-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 18px; }
.boxes { display: flex; gap: 8px; justify-content: center; margin-top: 18px; flex-wrap: wrap; }
.boxes .badge { font-variant-numeric: tabular-nums; }

/* ───── Toasts ───── */
.toast-host { position: fixed; right: 20px; bottom: 20px; display: flex; flex-direction: column; gap: 10px; z-index: 100; }
.toast { background: var(--ink); color: var(--bg); padding: 12px 16px; border-radius: 12px; box-shadow: var(--shadow-lg); font-size: 14px; max-width: 360px; animation: toastIn .25s ease; }
.toast.ok { background: var(--ok); color: #fff; }
.toast.bad { background: var(--bad); color: #fff; }
@keyframes toastIn { from { opacity: 0; transform: translateY(8px); } }

.confetti { position: fixed; inset: 0; pointer-events: none; z-index: 90; overflow: hidden; }
.confetti i { position: absolute; top: -12px; width: 8px; height: 14px; border-radius: 2px; animation: fall linear forwards; }
@keyframes fall { to { transform: translateY(110vh) rotate(720deg); } }

/* ───── Responsive ───── */
@media (max-width: 1180px) {
  .lesson-body { grid-template-columns: 1fr; }
  .lesson-side { position: static; }
  .stats { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 900px) {
  .sidebar { display: none; }
  .topbar {
    display: flex; align-items: center; justify-content: space-between; position: sticky; top: 0; z-index: 20;
    background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(10px);
    padding: 10px 16px; border-bottom: 1px solid var(--line);
  }
  .topbar .brand { padding: 0; }
  .topbar .brand-mark { width: 32px; height: 32px; font-size: 14px; }
  .main { margin-left: 0; padding: 22px 16px 100px; }
  .bottom-nav {
    display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
    background: var(--surface); border-top: 1px solid var(--line); padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
  }
  .bottom-nav a { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px 2px; font-size: 11px; font-weight: 600; color: var(--muted); border-radius: 10px; }
  .bottom-nav a svg { width: 21px; height: 21px; }
  .bottom-nav a.active { color: var(--accent); }
  .bottom-nav a:hover { text-decoration: none; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .hero { grid-template-columns: 1fr; }
  .hero .ring { margin: 0 auto; order: -1; width: 130px; height: 130px; }
  .page-head h1, .lesson-head h1 { font-size: 32px; }
  .cards3 { grid-template-columns: 1fr; }
  .steps { top: 62px; }
  .steps button .lbl { display: none; }
  .steps button.active .lbl { display: inline; }
  .dict-row { grid-template-columns: 1fr; gap: 2px; }
  .toast-host { left: 16px; right: 16px; bottom: 80px; }
  .days-strip { grid-template-columns: repeat(5, 1fr); }
}
@media (max-width: 520px) {
  .stats { grid-template-columns: 1fr 1fr; gap: 10px; }
  .stat { padding: 14px; }
  .stat .stat-val { font-size: 26px; }
  .card { padding: 16px; }
  .ex { padding: 14px; }
  .options { grid-template-columns: 1fr; }
  .match-row { grid-template-columns: 1fr; gap: 4px; }
  .ex-input-row { flex-direction: column; }
  .flash-actions { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
