/* Основни стилове: reset, layout, навигация, компоненти. */

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body {
    margin: 0;
    font-family: var(--font-ui);
    font-size: 16px;
    line-height: 1.5;
    color: var(--ink);
    background: var(--bg);
    min-height: 100dvh;
    padding-bottom: calc(64px + env(safe-area-inset-bottom));
    -webkit-font-smoothing: antialiased;
}
@media (min-width: 900px) { body { padding-bottom: var(--space-8); } }

h1, h2, h3, h4 { line-height: 1.2; margin: 0 0 var(--space-3); letter-spacing: -.01em; font-weight: 650; }
h1 { font-size: clamp(1.6rem, 1.2rem + 1.6vw, 2.3rem); }
h2 { font-size: 1.35rem; }
h3 { font-size: 1.1rem; }
p { margin: 0 0 var(--space-3); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 3px; }
code, pre { font-family: var(--font-mono); font-size: .92em; }
code { background: var(--code-bg); padding: .1em .35em; border-radius: 6px; }
pre { background: var(--code-bg); padding: var(--space-4); border-radius: var(--radius-sm); overflow: auto; }
pre code { background: none; padding: 0; }
img, svg { max-width: 100%; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }

.icon { width: 1.15em; height: 1.15em; vertical-align: -.2em; flex: none; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.right { text-align: right; }
.grow { flex: 1 1 auto; min-width: 0; }
.center-page { display: grid; place-items: center; min-height: 70dvh; }
.inline-form { display: inline; }
.skip-link { position: absolute; left: -999px; top: 8px; background: var(--bg-elev); padding: 8px 12px; border-radius: 8px; z-index: 100; }
.skip-link:focus { left: 8px; }

/* ---- Layout ---- */
.container { width: min(100% - 2 * var(--space-4), var(--container)); margin: 0 auto; padding-block: var(--space-5); }
.container.narrow { max-width: var(--narrow); }
@media (min-width: 900px) { .container { padding-block: var(--space-6); } }
.grid-2 { display: grid; gap: var(--space-5); grid-template-columns: 1fr; }
@media (min-width: 900px) { .grid-2 { grid-template-columns: 1.3fr 1fr; align-items: start; } }
.stack { display: grid; gap: var(--space-4); }

.page-head { display: flex; gap: var(--space-4); align-items: flex-start; margin-bottom: var(--space-5); }
.page-head h1 { margin-bottom: var(--space-2); }
.eyebrow { text-transform: uppercase; letter-spacing: .08em; font-size: .75rem; font-weight: 600; color: var(--muted); margin-bottom: var(--space-2); display: flex; gap: 6px; align-items: center; }
.lede { font-size: 1.05rem; max-width: 60ch; }
.crumbs { font-size: .875rem; color: var(--muted); margin-bottom: var(--space-4); display: flex; gap: 8px; flex-wrap: wrap; }
.crumbs a { color: var(--muted); }
.crumbs a:hover { color: var(--ink); }

/* ---- Topbar ---- */
.topbar { position: sticky; top: 0; z-index: 50; background: color-mix(in srgb, var(--bg) 85%, transparent); backdrop-filter: saturate(1.4) blur(12px); border-bottom: 1px solid var(--line); }
.topbar-inner { width: min(100% - 2 * var(--space-4), var(--container)); margin: 0 auto; height: 56px; display: flex; align-items: center; gap: var(--space-4); }
.brand { display: flex; align-items: center; gap: 10px; color: var(--ink); font-weight: 700; letter-spacing: -.02em; }
.brand:hover { text-decoration: none; }
.brand-mark { display: grid; place-items: center; width: 32px; height: 32px; border-radius: 10px; background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff; }
.brand-mark .icon { width: 18px; height: 18px; }
.brand-mark.big { width: 56px; height: 56px; border-radius: 18px; margin: 0 auto var(--space-3); }
.brand-mark.big .icon { width: 30px; height: 30px; }
.topnav { display: none; gap: 4px; margin-left: var(--space-4); }
@media (min-width: 900px) { .topnav { display: flex; } }
.topnav-link { display: flex; align-items: center; gap: 8px; padding: 8px 12px; border-radius: 10px; color: var(--ink-2); font-weight: 500; }
.topnav-link:hover { background: var(--bg-sunken); text-decoration: none; color: var(--ink); }
.topnav-link.is-active { background: color-mix(in srgb, var(--accent) 12%, transparent); color: var(--accent); }
.topbar-actions { margin-left: auto; display: flex; gap: 4px; align-items: center; }
.icon-btn { display: grid; place-items: center; width: 40px; height: 40px; border-radius: 10px; border: 0; background: transparent; color: var(--ink-2); }
.icon-btn:hover { background: var(--bg-sunken); color: var(--ink); }
.icon-btn .icon { width: 20px; height: 20px; }
.theme-moon { display: none; }
[data-theme="dark"] .theme-sun { display: none; }
[data-theme="dark"] .theme-moon { display: block; }
@media (prefers-color-scheme: dark) {
    [data-theme="auto"] .theme-sun { display: none; }
    [data-theme="auto"] .theme-moon { display: block; }
}

/* ---- Tabbar (mobile) ---- */
.tabbar { position: fixed; inset: auto 0 0 0; z-index: 50; display: grid; grid-template-columns: repeat(4, 1fr); background: color-mix(in srgb, var(--bg-elev) 92%, transparent); backdrop-filter: blur(12px); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
@media (min-width: 900px) { .tabbar { display: none; } }
.tabbar-link { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 4px 6px; font-size: .68rem; color: var(--muted); }
.tabbar-link .icon { width: 22px; height: 22px; }
.tabbar-link.is-active { color: var(--accent); }
.tabbar-link:hover { text-decoration: none; }
.page-login .tabbar { display: none; }

/* ---- Cards ---- */
.card { background: var(--bg-elev); border: 1px solid var(--line); border-radius: var(--radius); padding: var(--space-5); box-shadow: var(--shadow); }
.card h2, .card h3 { margin-bottom: var(--space-3); }
.card-row { display: flex; gap: var(--space-4); align-items: center; }
.card-row h3 { margin-bottom: 2px; }
.card-row p { margin: 0; }
.card-row-icon { display: grid; place-items: center; width: 44px; height: 44px; border-radius: 12px; background: color-mix(in srgb, var(--accent) 12%, transparent); color: var(--accent); flex: none; }
.card-hero { position: relative; overflow: hidden; border-color: color-mix(in srgb, var(--disc, var(--accent)) 40%, var(--line)); }
.card-hero::before { content: ""; position: absolute; inset: 0 auto 0 0; width: 6px; background: var(--disc, var(--accent)); }
.card-hero h2 { font-size: 1.5rem; }
.card-hero h2 a { color: var(--ink); }
.card-hero .btn { margin-top: var(--space-2); }

/* ---- Buttons ---- */
.btn { display: inline-flex; align-items: center; gap: 8px; padding: 10px 18px; border-radius: 999px; border: 1px solid transparent; font-weight: 600; line-height: 1.2; transition: transform var(--dur) var(--ease), background var(--dur), box-shadow var(--dur); }
.btn:hover { text-decoration: none; transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn:disabled { opacity: .55; cursor: default; transform: none; }
.btn-primary { background: var(--disc, var(--accent)); color: #fff; box-shadow: 0 6px 16px -8px var(--disc, var(--accent)); }
.btn-primary:hover { filter: brightness(1.06); }
.btn-ghost { background: transparent; border-color: var(--line-strong); color: var(--ink); }
.btn-ghost:hover { background: var(--bg-sunken); }
.btn-block { width: 100%; justify-content: center; }
.btn-sm { padding: 6px 12px; font-size: .875rem; }

/* ---- Forms ---- */
.form { display: grid; gap: var(--space-4); }
.field { display: grid; gap: 6px; font-weight: 500; }
.field input, .field select, select, input[type="text"], input[type="number"] { padding: 11px 14px; border-radius: 10px; border: 1px solid var(--line-strong); background: var(--bg); color: var(--ink); width: 100%; }
.field input:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 20%, transparent); }
.form-error { background: color-mix(in srgb, var(--danger) 12%, transparent); color: var(--danger); padding: 10px 14px; border-radius: 10px; font-size: .9rem; }
.login-card { width: min(100%, 420px); }
.login-hero { text-align: center; margin-bottom: var(--space-5); }
.login-hero h1 { margin-bottom: var(--space-1); }
.goal-form { display: flex; gap: 8px; align-items: center; margin-top: var(--space-4); flex-wrap: wrap; }
.goal-form label { font-weight: 500; font-size: .9rem; }
.goal-form select { width: auto; padding: 8px 12px; }

/* ---- Stats ---- */
.stat-row { display: grid; gap: var(--space-3); grid-template-columns: 1fr; margin-bottom: var(--space-5); }
@media (min-width: 640px) { .stat-row { grid-template-columns: repeat(3, 1fr); } }
.stat { display: flex; align-items: center; gap: var(--space-3); padding: var(--space-4); background: var(--bg-elev); border: 1px solid var(--line); border-radius: var(--radius); }
.stat-value { font-weight: 700; font-size: 1.15rem; letter-spacing: -.01em; }
.stat-label { font-size: .8rem; color: var(--muted); }
.stat-icon { display: grid; place-items: center; width: 48px; height: 48px; border-radius: 14px; background: var(--bg-sunken); color: var(--muted); flex: none; }
.stat-icon .icon { width: 24px; height: 24px; }
.stat-icon.is-hot { background: color-mix(in srgb, #f97316 15%, transparent); color: #f97316; }

.ring { position: relative; width: 48px; height: 48px; flex: none; }
.ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring circle { fill: none; stroke-width: 3.4; }
.ring-bg { stroke: var(--bg-sunken); }
.ring-fg { stroke: var(--accent); stroke-linecap: round; stroke-dasharray: calc(var(--p) * 1) 100; transition: stroke-dasharray .6s var(--ease); }
.ring-label { position: absolute; inset: 0; display: grid; place-items: center; font-size: .7rem; font-weight: 700; }

.bar { height: 8px; background: var(--bg-sunken); border-radius: 999px; overflow: hidden; }
.bar span { display: block; height: 100%; background: var(--disc, var(--accent)); border-radius: 999px; transition: width .6s var(--ease); }
.bar.thin { height: 4px; margin-top: var(--space-3); }

.meta-row { display: flex; gap: var(--space-4); flex-wrap: wrap; align-items: center; color: var(--muted); font-size: .9rem; margin-bottom: var(--space-3); }
.meta-row > span { display: inline-flex; gap: 6px; align-items: center; }
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 999px; background: color-mix(in srgb, var(--disc, var(--accent)) 14%, transparent); color: var(--disc, var(--accent)); font-size: .8rem; font-weight: 600; }
.pill-outline { background: transparent; border: 1px solid var(--line-strong); color: var(--muted); }
.pill-success { background: color-mix(in srgb, var(--success) 14%, transparent); color: var(--success); }
.pill-link:hover { text-decoration: none; filter: brightness(1.08); }

/* ---- Lists ---- */
.list { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
.list-link { display: flex; gap: var(--space-3); align-items: center; padding: 10px 12px; margin: 0 -12px; border-radius: 10px; color: var(--ink); }
.list-link:hover { background: var(--bg-sunken); text-decoration: none; }
.list-link .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--disc, var(--accent)); flex: none; }
.disc-icon { display: grid; place-items: center; width: 40px; height: 40px; border-radius: 12px; background: color-mix(in srgb, var(--disc, var(--accent)) 15%, transparent); color: var(--disc, var(--accent)); flex: none; }
.disc-icon .icon { width: 22px; height: 22px; }
.disc-icon.big { width: 64px; height: 64px; border-radius: 20px; }
.disc-icon.big .icon { width: 34px; height: 34px; }
.disc-icon.sm { width: 32px; height: 32px; border-radius: 10px; }
.disc-icon.sm .icon { width: 18px; height: 18px; }

/* ---- Heatmap ---- */
.heatmap { display: grid; grid-template-columns: repeat(14, 1fr); gap: 4px; margin: var(--space-3) 0; }
.heatmap-sm { grid-template-columns: repeat(14, 1fr); }
.heat { aspect-ratio: 1; border-radius: 4px; background: var(--heat-0); }
.heat.l1 { background: var(--heat-1); } .heat.l2 { background: var(--heat-2); } .heat.l3 { background: var(--heat-3); } .heat.l4 { background: var(--heat-4); }

/* ---- Discipline grid ---- */
.disc-grid { display: grid; gap: var(--space-4); grid-template-columns: 1fr; }
@media (min-width: 640px) { .disc-grid { grid-template-columns: repeat(2, 1fr); } }
@media (min-width: 1000px) { .disc-grid { grid-template-columns: repeat(3, 1fr); } }
.disc-card { display: flex; flex-direction: column; gap: var(--space-2); padding: var(--space-5); background: var(--bg-elev); border: 1px solid var(--line); border-radius: var(--radius-lg); color: var(--ink); box-shadow: var(--shadow); transition: transform var(--dur) var(--ease), box-shadow var(--dur), border-color var(--dur); position: relative; overflow: hidden; }
.disc-card::after { content: ""; position: absolute; inset: auto -30% -40% auto; width: 60%; aspect-ratio: 1; border-radius: 50%; background: radial-gradient(closest-side, color-mix(in srgb, var(--disc) 18%, transparent), transparent); pointer-events: none; }
.disc-card:hover { text-decoration: none; transform: translateY(-2px); box-shadow: var(--shadow-lg); border-color: color-mix(in srgb, var(--disc) 40%, var(--line)); }
.disc-card-head { display: flex; justify-content: space-between; align-items: center; }
.disc-num { font-family: var(--font-mono); color: var(--muted); font-size: .8rem; }
.disc-card h2 { font-size: 1.2rem; margin: var(--space-2) 0 0; }
.disc-card p { font-size: .92rem; flex: 1; }
.disc-card-foot { display: grid; gap: 8px; }
.disc-card-foot .meta-row { margin: 0; justify-content: space-between; }

/* ---- Discipline page ---- */
.disc-head { align-items: center; }
.modules { display: grid; gap: var(--space-5); }
.module { background: var(--bg-elev); border: 1px solid var(--line); border-radius: var(--radius-lg); overflow: hidden; }
.module.is-below { opacity: .8; }
.module-head { padding: var(--space-5) var(--space-5) var(--space-4); border-bottom: 1px solid var(--line); }
.module-head h2 { margin-bottom: var(--space-2); }
.module-head p { margin-bottom: var(--space-2); }
.module-level { display: inline-flex; align-items: center; gap: 8px; font-size: .8rem; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; margin-bottom: var(--space-2); }
.lvl-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--disc, var(--accent)); }
.lesson-list { list-style: none; margin: 0; padding: var(--space-2); display: grid; gap: 2px; }
.lesson-link { display: flex; gap: var(--space-3); align-items: center; padding: 12px; border-radius: 12px; color: var(--ink); }
.lesson-link:hover { background: var(--bg-sunken); text-decoration: none; }
.lesson-state { display: grid; place-items: center; width: 32px; height: 32px; border-radius: 50%; border: 2px solid var(--line-strong); color: var(--muted); flex: none; }
.lesson-state .icon { width: 16px; height: 16px; }
.is-done .lesson-state { background: var(--success); border-color: var(--success); color: #fff; }
.is-started .lesson-state { border-color: var(--disc, var(--accent)); color: var(--disc, var(--accent)); }
.is-open .lesson-state { color: var(--disc, var(--accent)); }
.is-locked .lesson-link, .is-stub .lesson-link { opacity: .7; }
.lesson-title { display: block; font-weight: 600; }
.lesson-summary { display: block; font-size: .875rem; }
.lesson-meta { text-align: right; white-space: nowrap; }

/* ---- Levels ---- */
.level-legend { display: flex; gap: 6px; flex-wrap: wrap; margin: var(--space-3) 0; }
.level-chip { font-size: .78rem; padding: 4px 10px; border-radius: 999px; background: var(--bg-sunken); color: var(--ink-2); }
.level-chip b { color: var(--disc, var(--accent)); margin-right: 2px; }
.level-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.level-row { display: flex; align-items: center; gap: var(--space-3); padding: 10px 12px; margin: 0 -12px; border-radius: 10px; color: var(--ink); }
.level-row:hover { background: var(--bg-sunken); text-decoration: none; }
.level-steps { display: flex; gap: 4px; margin-top: 6px; }
.level-steps i { width: 22px; height: 6px; border-radius: 3px; background: var(--bg-sunken); border: 1px solid var(--line); }
.level-steps i.on { background: var(--disc, var(--accent)); border-color: transparent; }

.rank-head { display: flex; gap: var(--space-3); align-items: center; margin-bottom: var(--space-3); }
.rank-head h2 { margin: 0; }
.rank-ladder { list-style: none; margin: var(--space-4) 0 0; padding: 0; display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px 16px; font-size: .875rem; }
.rank-ladder li { display: flex; justify-content: space-between; gap: 8px; color: var(--muted); padding: 4px 0; border-bottom: 1px dashed var(--line); }
.rank-ladder li.is-reached { color: var(--ink); font-weight: 600; }

/* ---- Badges ---- */
.badge-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: var(--space-3); }
.badge { display: grid; justify-items: center; text-align: center; gap: 4px; padding: var(--space-3); border-radius: var(--radius); border: 1px dashed var(--line-strong); opacity: .55; filter: grayscale(1); }
.badge.is-earned { opacity: 1; filter: none; border-style: solid; background: color-mix(in srgb, var(--accent) 6%, transparent); border-color: color-mix(in srgb, var(--accent) 30%, var(--line)); }
.badge-icon { display: grid; place-items: center; width: 40px; height: 40px; border-radius: 50%; background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff; }
.badge-title { font-weight: 600; font-size: .85rem; }
.badge-text { line-height: 1.3; }

.history { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.history li { display: flex; gap: var(--space-3); align-items: center; }
.score-chip { font-weight: 700; font-size: .8rem; padding: 4px 8px; border-radius: 8px; min-width: 48px; text-align: center; }
.score-chip.ok { background: color-mix(in srgb, var(--success) 14%, transparent); color: var(--success); }
.score-chip.low { background: color-mix(in srgb, var(--danger) 12%, transparent); color: var(--danger); }

/* ---- Empty states ---- */
.empty-state { text-align: center; padding: var(--space-7) var(--space-4); display: grid; justify-items: center; gap: var(--space-2); }
.empty-icon { display: grid; place-items: center; width: 64px; height: 64px; border-radius: 20px; background: var(--bg-sunken); color: var(--muted); margin-bottom: var(--space-2); }
.empty-icon .icon { width: 30px; height: 30px; }

/* ---- Toasts ---- */
.toasts { position: fixed; inset: auto 0 calc(72px + env(safe-area-inset-bottom)) 0; display: grid; justify-items: center; gap: 8px; pointer-events: none; z-index: 80; padding: 0 var(--space-4); }
@media (min-width: 900px) { .toasts { inset: auto var(--space-5) var(--space-5) auto; justify-items: end; } }
.toast { pointer-events: auto; display: flex; gap: 10px; align-items: center; padding: 12px 16px; border-radius: 14px; background: var(--ink); color: var(--bg); box-shadow: var(--shadow-lg); animation: toast-in .35s var(--ease); max-width: 360px; }
.toast.is-badge { background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff; }
.toast .icon { width: 20px; height: 20px; }
.toast.is-leaving { animation: toast-out .3s var(--ease) forwards; }
@keyframes toast-in { from { opacity: 0; transform: translateY(12px) scale(.96); } to { opacity: 1; transform: none; } }
@keyframes toast-out { to { opacity: 0; transform: translateY(8px); } }

/* ---- Callouts (shared with lesson content) ---- */
.callout { border-radius: var(--radius); padding: var(--space-4) var(--space-5); margin: var(--space-5) 0; background: var(--bg-elev); border: 1px solid var(--line); border-left: 4px solid var(--callout, var(--accent)); }
.callout-title { font-weight: 700; margin-bottom: var(--space-2); display: flex; gap: 8px; align-items: center; color: var(--callout, var(--accent)); font-family: var(--font-ui); }
.callout p:last-child, .callout ul:last-child, .callout ol:last-child { margin-bottom: 0; }
.callout-note { --callout: var(--accent); }
.callout-example { --callout: #0d9488; }
.callout-tip { --callout: var(--success); }
.callout-warning { --callout: var(--warning); }
.callout-think { --callout: #c026d3; }
.callout-analogy { --callout: #ea580c; }
.callout-history { --callout: #78716c; }
.callout-prereq { --callout: var(--accent-2); }
.prereq-list { margin: 0 0 var(--space-2); padding-left: 1.2em; }
