/* Beyim AI Studio — мини-приложение Telegram.
   Две оболочки, как у нативных клиентов:
     .os-desktop — Telegram Desktop / macOS / Web: боковая панель, как в клиенте на egui (src/ui);
     .os-android — Android / iOS: нижняя навигация, как в клиенте на Compose (android/.../ui).
   Токены и имена совпадают с Kit (DESIGN.md): сетка 4px, радиусы 8/14/16, Noto Sans 400/500/600,
   один акцент, без свечений, градиентов и эмодзи. */

@import url('https://fonts.googleapis.com/css2?family=Noto+Sans:wght@400;500;600&display=swap');

/* ── палитра (theme.rs / Theme.kt) ── */
:root {
  --bg: #121413;
  --side: #171918;
  --card: #1C1F1D;
  --card-hi: #252927;
  --border: #2E3230;
  --text: #EBEDEA;
  --muted: #9AA09C;
  --accent: #7BA7E8;
  --on-accent: #0B1220;
  --ok: #86C98B;
  --warn: #D9AE5A;
  --err: #E08A7E;
  --scrim: rgba(6, 8, 7, .62);
  --shadow: 0 16px 48px rgba(0, 0, 0, .36);
  color-scheme: dark;
}
:root[data-theme="light"] {
  --bg: #F4F3EF;
  --side: #FAF9F6;
  --card: #FFFFFF;
  --card-hi: #EFEEE9;
  --border: #E0DED8;
  --text: #1B1D1C;
  --muted: #6A6F6B;
  --accent: #2A58A8;
  --on-accent: #FFFFFF;
  --ok: #2F7D3E;
  --warn: #9A6A12;
  --err: #B4432F;
  --scrim: rgba(27, 29, 28, .32);
  --shadow: 0 16px 48px rgba(27, 29, 28, .14);
  color-scheme: light;
}

/* ── Kit: отступы, радиусы, движение ── */
:root {
  --xs: 4px; --sm: 8px; --md: 12px; --lg: 16px; --xl: 24px; --xxl: 32px;
  --r-control: 8px; --r-card: 14px; --r-panel: 16px;
  --fast: 120ms; --base: 200ms; --enter: 400ms;
  --ease: cubic-bezier(0.16, 1, 0.3, 1);
  --ease-io: cubic-bezier(0.76, 0, 0.24, 1);
  --field: color-mix(in oklab, var(--card) 45%, var(--bg));
  --track: color-mix(in oklab, var(--card-hi) 40%, var(--border));
  --vh: var(--tg-viewport-stable-height, 100dvh);
  --safe-b: max(env(safe-area-inset-bottom), var(--tg-safe-area-inset-bottom, 0px));
  --safe-t: calc(var(--tg-safe-area-inset-top, 0px) + var(--tg-content-safe-area-inset-top, 0px));
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Noto Sans', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
  transition: background-color .25s ease, color .25s ease;
}
button { font: inherit; color: inherit; }
svg { display: block; flex: none; }
.muted { color: var(--muted); }
.hidden { display: none !important; }
.grow { flex: 1; min-width: 0; }
.row { display: flex; align-items: center; gap: var(--sm); }
.stack { display: flex; flex-direction: column; gap: var(--md); }
.clip1 { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.clip2 { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.tnum { font-variant-numeric: tabular-nums; }

#app { height: var(--vh); }

/* ═════════ Оболочка: ПК (egui) ═════════ */
.os-desktop .shell { display: grid; grid-template-columns: 228px 1fr; height: var(--vh); }
.side {
  background: var(--side); border-right: 1px solid var(--border);
  padding: var(--lg); display: flex; flex-direction: column; min-height: 0;
  transition: background-color .25s ease;
}
.side .brand { display: flex; align-items: center; gap: var(--md); padding: 6px 4px 0; height: 46px; }
.side .brand b { display: block; font-size: 16.5px; font-weight: 600; line-height: 1.15; }
.side .brand span { display: block; font-size: 12.5px; color: var(--muted); line-height: 1.2; }
.nav { position: relative; margin-top: 22px; display: flex; flex-direction: column; gap: 4px; }
.nav .ind {
  position: absolute; left: 0; right: 0; top: 0; height: 42px; border-radius: 10px;
  background: var(--card-hi); border: 1px solid color-mix(in oklab, var(--card-hi) 92%, var(--text));
  transition: transform var(--base) var(--ease); pointer-events: none;
}
.nav .ind::before {
  content: ""; position: absolute; left: -1px; top: 11px; width: 3px; height: 18px;
  border-radius: 2px; background: var(--accent);
}
.nav-item {
  position: relative; height: 42px; display: flex; align-items: center; gap: 14px;
  padding: 0 16px; border: 0; background: transparent; border-radius: 12px;
  color: var(--muted); font-size: 14.5px; cursor: pointer; text-align: left;
  transition: color var(--fast), background-color var(--fast);
}
.nav-item:hover:not([aria-current="true"]) { background: color-mix(in oklab, var(--card-hi) 80%, transparent); color: var(--text); }
.nav-item[aria-current="true"] { color: var(--text); font-weight: 600; }
.nav-item[aria-current="true"] svg { color: var(--accent); }
.side .spacer { flex: 1; }
.usercard {
  display: flex; align-items: center; gap: var(--md); height: 56px; padding: 0 10px;
  border: 1px solid var(--border); border-radius: var(--r-card);
  background: color-mix(in oklab, var(--card) 60%, transparent); cursor: pointer; text-align: left;
  transition: background-color var(--fast);
}
.usercard:hover { background: var(--card-hi); }
.avatar {
  flex: none; width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center;
  background: color-mix(in oklab, var(--card) 78%, var(--accent)); color: var(--accent);
  font-weight: 600; font-size: 13px;
}
.usercard .name { font-weight: 600; font-size: 13.5px; }
.usercard .sub { font-size: 12px; color: var(--muted); }
.usercard .sub.demo { color: var(--warn); }

.os-desktop .main { overflow-y: auto; overflow-x: hidden; min-width: 0; scrollbar-gutter: stable; }
.os-desktop .page { max-width: 1080px; padding: var(--xl) 30px var(--xxl); }

/* Узкое окно Telegram Desktop: сайдбар сворачивается в рейку, как без подписей. */
@media (max-width: 559px) {
  .os-desktop .stat.extra { display: none; }
  .btn-row > .btn { padding: 0 8px; }
}
@media (max-width: 719px) {
  .os-desktop .shell { grid-template-columns: 72px 1fr; }
  .os-desktop .side { padding: var(--lg) var(--md); }
  .os-desktop .side .brand { justify-content: center; padding: 6px 0 0; }
  .os-desktop .side .brand div, .os-desktop .nav-item span,
  .os-desktop .usercard .grow { display: none; }
  .os-desktop .nav-item { justify-content: center; padding: 0; }
  .os-desktop .usercard { justify-content: center; padding: 0; border-color: transparent; background: transparent; }
  .os-desktop .page { padding: var(--lg) var(--lg) var(--xxl); }
}

/* ═════════ Оболочка: Android (Compose) ═════════ */
.os-android .shell { display: flex; flex-direction: column; height: var(--vh); }
.os-android .main { flex: 1; overflow-y: auto; overflow-x: hidden; min-height: 0; overscroll-behavior: contain; }
.os-android .page { padding: calc(var(--safe-t) + 8px) 18px var(--lg); max-width: 640px; margin: 0 auto; }
.bottombar {
  flex: none; background: var(--side); border-top: 1px solid var(--border);
  padding: 6px 8px calc(6px + var(--safe-b));
  transition: background-color .25s ease;
}
.bottombar .track { position: relative; display: grid; grid-template-columns: repeat(var(--n, 4), 1fr); height: 52px; }
.bottombar .ind {
  position: absolute; top: 0; bottom: 0; left: 0; width: calc(100% / var(--n, 4)); padding: 0 3px; pointer-events: none;
  transition: transform 260ms cubic-bezier(.4, 0, .2, 1);
}
.bottombar .ind::before {
  content: ""; display: block; height: 100%; border-radius: 14px;
  background: color-mix(in oklab, var(--side) 84%, var(--accent));
}
.tab {
  position: relative; border: 0; background: none; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 2px; color: var(--muted); font-size: 10.5px; cursor: pointer; min-width: 0;
  transition: color var(--base);
}
.tab[aria-current="true"] { color: var(--text); font-weight: 600; }
.tab[aria-current="true"] svg { color: var(--accent); }

/* ═════════ Шапка страницы ═════════ */
.header { display: flex; align-items: center; gap: var(--md); padding-top: var(--sm); }
.header h1 { margin: 0; font-size: 24px; font-weight: 600; letter-spacing: -.015em; line-height: 1.2; }
.os-android .header h1 { font-size: 26px; }
.header p { margin: 2px 0 0; color: var(--muted); font-size: 13px; }
.filters { display: flex; flex-wrap: wrap; align-items: center; gap: 6px var(--lg); margin-top: 10px; }
.filters .grp { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; min-width: 0; }
.filters .lbl { color: var(--muted); font-size: 13px; margin-right: 2px; }
.os-android .filters { flex-direction: column; flex-wrap: nowrap; align-items: stretch; gap: 6px; }
.os-android .filters .grp { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; margin: 0 -18px; padding: 0 18px; }
.os-android .filters .grp::-webkit-scrollbar { display: none; }
.page > * + * { margin-top: var(--md); }
.page > .header + * { margin-top: var(--lg); }
.h2 { font-size: 17px; font-weight: 600; margin-top: var(--lg) !important; }

/* ═════════ Элементы Kit ═════════ */
.card {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--r-card); padding: var(--lg);
  transition: background-color .25s ease, border-color .25s ease;
}
.card.tap { cursor: pointer; transition: transform 110ms ease, background-color var(--fast), border-color var(--fast); }
.card.tap:hover { border-color: color-mix(in oklab, var(--border) 80%, var(--text)); }
.card.tap:active { transform: scale(.985); }
.card.flush { padding: 0; overflow: hidden; }

.btn {
  appearance: none; display: inline-flex; align-items: center; justify-content: center; gap: var(--sm);
  height: 40px; padding: 0 18px; border-radius: var(--r-control); cursor: pointer;
  border: 1px solid var(--border); background: var(--card); color: var(--text);
  font-weight: 500; font-size: 14px; white-space: nowrap;
  transition: background-color var(--fast), border-color var(--fast), transform 110ms ease, opacity var(--fast);
}
.os-android .btn { height: 48px; font-size: 15px; font-weight: 600; }
.btn.full { width: 100%; }
.btn { min-width: 0; max-width: 100%; }
.btn .lbl { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.btn:hover:not(:disabled) { background: var(--card-hi); }
.btn:active:not(:disabled) { transform: scale(.97); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.primary:hover:not(:disabled) { background: color-mix(in oklab, var(--accent) 90%, var(--text)); }
.btn.danger {
  background: color-mix(in oklab, var(--card) 90%, var(--err)); color: var(--err);
  border-color: color-mix(in oklab, var(--border) 50%, var(--err));
}
.btn.danger:hover:not(:disabled) { background: color-mix(in oklab, var(--card) 82%, var(--err)); }
.btn.sm { height: 34px; padding: 0 var(--md); font-size: 13.5px; }
.btn:disabled { opacity: .45; cursor: default; }
.btn-row { display: flex; gap: var(--sm); }
.btn-row > .btn { flex: 1 1 0; padding: 0 12px; }
.btn-row > .btn.wide { flex-grow: 1.3; }
.btn-row.wrap { flex-wrap: wrap; }
.btn-row.wrap > .btn { flex: 1 1 150px; }

.iconbtn {
  flex: none; width: 42px; height: 42px; border-radius: 12px; display: grid; place-items: center;
  border: 1px solid var(--border); background: var(--card); color: var(--muted); cursor: pointer;
  transition: background-color var(--fast), color var(--fast), transform 110ms ease;
}
.iconbtn:hover { background: var(--card-hi); color: var(--text); }
.iconbtn:active { transform: scale(.94); }
.os-desktop .iconbtn { width: 36px; height: 36px; border-radius: var(--r-control); }

.chip {
  height: 32px; padding: 0 var(--md); border-radius: var(--r-control); cursor: pointer; flex: none;
  border: 1px solid var(--border); background: var(--card); color: var(--muted); font-size: 13.5px;
  transition: background-color var(--base), border-color var(--base), color var(--base), transform 110ms ease;
}
.os-android .chip { height: 36px; padding: 0 var(--lg); border-radius: 999px; font-size: 14px; }
.chip:hover { color: var(--text); }
.chip:active { transform: scale(.96); }
.chip[aria-pressed="true"] {
  background: var(--card-hi); color: var(--text); font-weight: 500;
  border-color: var(--chip, var(--accent));
}
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.os-android .chips.scroll { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; margin: 0 -18px; padding: 0 18px; }
.os-android .chips.scroll::-webkit-scrollbar { display: none; }

.seg {
  position: relative; display: grid; grid-auto-flow: column; grid-auto-columns: 1fr;
  height: 40px; padding: 4px; border-radius: 12px; background: var(--field); border: 1px solid var(--border);
}
.os-android .seg { height: 44px; border-radius: 14px; }
.seg .thumb {
  position: absolute; top: 4px; bottom: 4px; left: 4px; border-radius: var(--r-control);
  background: var(--card-hi); border: 1px solid color-mix(in oklab, var(--border) 85%, var(--text));
  transition: transform 240ms cubic-bezier(.4, 0, .2, 1); pointer-events: none;
}
.seg button {
  position: relative; border: 0; background: none; cursor: pointer; color: var(--muted);
  font-size: 13px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding: 0 6px;
  transition: color var(--base);
}
.seg button[aria-pressed="true"] { color: var(--text); }

.field {
  width: 100%; display: block; background: var(--field); border: 1px solid var(--border); color: var(--text);
  border-radius: var(--r-control); padding: 0 14px; height: 40px; font: inherit; font-size: 14px;
  transition: border-color var(--fast);
}
.os-android .field { height: 48px; border-radius: 13px; font-size: 15px; }
.field::placeholder { color: var(--muted); }
.field:focus { outline: none; border-color: var(--accent); }
.search { position: relative; }
.search svg { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.search .field { padding-left: 40px; }

.stat .k { font-size: 12px; color: var(--muted); }
.stat .v { font-size: 20px; font-weight: 600; letter-spacing: -.01em; font-variant-numeric: tabular-nums; line-height: 1.25; }
.stats { display: flex; flex-wrap: wrap; gap: var(--md) var(--xl); margin-top: var(--md); }

.badge { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); white-space: nowrap; }
.badge i { width: 6px; height: 6px; border-radius: 50%; background: var(--c); }

.bar { height: 6px; border-radius: 99px; background: var(--track); overflow: hidden; }
.bar > i {
  display: block; height: 100%; border-radius: 99px; background: var(--c, var(--accent));
  width: calc(var(--f) * 100%); transition: width 800ms var(--ease);
}
.bar.anim > i { animation: grow 800ms var(--ease); }
@keyframes grow { from { width: 0; } }

.ring { position: relative; display: grid; place-items: center; flex: none; }
.ring svg { position: absolute; inset: 0; transform: rotate(-90deg); }
.ring .trk { stroke: var(--track); }
.ring .arc { stroke: var(--c, var(--accent)); stroke-linecap: round; transition: stroke-dashoffset 900ms var(--ease); }
.ring.anim .arc { animation: ring-in 900ms var(--ease); }
@keyframes ring-in { from { stroke-dashoffset: var(--len); } }
.ring b { position: relative; font-weight: 600; font-variant-numeric: tabular-nums; }

.skel { background: var(--card-hi); border-radius: var(--r-control); animation: pulse 1.8s ease-in-out infinite alternate; }
@keyframes pulse { from { opacity: .45; } to { opacity: 1; } }

.spinner {
  width: var(--s, 22px); height: var(--s, 22px); border-radius: 50%; flex: none;
  border: 2px solid color-mix(in oklab, var(--c, var(--accent)) 18%, transparent);
  border-top-color: var(--c, var(--accent)); animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.empty { display: flex; flex-direction: column; align-items: center; gap: var(--md); padding: 40px var(--md); color: var(--muted); text-align: center; }
.empty .ic { width: 48px; height: 48px; border-radius: 50%; border: 1px solid var(--border); display: grid; place-items: center; }

.note { padding: 10px var(--md); border-radius: 11px; font-size: 13px; border: 1px solid color-mix(in oklab, var(--border) 50%, var(--c)); background: color-mix(in oklab, var(--card) 90%, var(--c)); color: var(--c); }

/* ═════════ Обзор ═════════ */
.hero { display: flex; align-items: center; gap: var(--lg); }
.hero .t { font-size: 17px; font-weight: 600; }
.hero .s { font-size: 13px; color: var(--muted); }
.hero .bar { margin-top: var(--sm); }
.subjects { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--md); }
@media (max-width: 359px) { .os-android .subjects { grid-template-columns: minmax(0, 1fr); } }
@media (min-width: 1000px) { .os-desktop .subjects { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
@media (max-width: 559px) { .os-desktop .subjects { grid-template-columns: minmax(0, 1fr); } }
.subj { display: flex; flex-direction: column; justify-content: space-between; gap: var(--sm); min-height: 150px; padding: 14px; }
.subj .top { display: flex; align-items: center; gap: 10px; min-width: 0; }
.subj .name { font-size: 15px; font-weight: 600; }
.subj .cap { font-size: 12px; color: var(--muted); }
.subj .acts { display: flex; justify-content: space-between; font-size: 11px; color: var(--muted); margin-bottom: 4px; }
.subj .done { font-size: 12px; color: var(--ok); font-weight: 600; }
.next { display: flex; align-items: center; gap: 10px; padding: var(--md); }
.next .t { font-size: 14px; }
.next .s { font-size: 12px; color: var(--muted); }

/* ═════════ Темы ═════════ */
.tools { display: flex; gap: var(--sm); align-items: center; flex-wrap: wrap; }
.tools .seg { flex: 1 1 240px; min-width: 0; }
.os-android .tools { flex-direction: column; align-items: stretch; }
.os-android .tools .seg { min-width: 0; flex: none; }
.sec-head {
  display: flex; align-items: center; gap: 10px; width: 100%; padding: 14px; border: 0; background: none;
  cursor: pointer; text-align: left;
}
.sec-head .chev { color: var(--muted); transition: transform 220ms var(--ease); }
.sec-head[aria-expanded="true"] .chev { transform: rotate(90deg); }
.sec-head .t { font-size: 15px; font-weight: 600; }
.sec-head .bar { width: 110px; height: 5px; margin-top: 6px; }
.sec-head .n { font-size: 13px; font-weight: 600; color: var(--muted); }
.sec-head .n.ok { color: var(--ok); }
.sec-body { display: grid; grid-template-rows: 0fr; transition: grid-template-rows 240ms var(--ease); }
.sec-body > div { overflow: hidden; }
.sec-body.open { grid-template-rows: 1fr; }
.sec-inner { padding: 0 8px 8px; }
.sec-inner .btn { margin: 6px 6px 0; width: calc(100% - 12px); }
.sec-inner .hint { font-size: 12px; color: var(--muted); padding: 6px 10px 4px; }
.topic {
  display: flex; align-items: center; gap: 10px; width: 100%; padding: 8px 6px; border: 0; background: none;
  border-radius: 10px; cursor: pointer; text-align: left; transition: background-color var(--fast), transform 110ms ease;
}
.topic:hover { background: color-mix(in oklab, var(--card-hi) 70%, transparent); }
.topic:active { transform: scale(.985); }
.topic .st { width: 22px; height: 22px; display: grid; place-items: center; flex: none; }
.topic .st i { display: block; border-radius: 50%; }
.topic .st.ok i { width: 22px; height: 22px; border: 1.5px solid var(--ok); display: grid; place-items: center; color: var(--ok); }
.topic .st.warn i { width: 18px; height: 18px; border: 2px solid var(--warn); display: grid; place-items: center; }
.topic .st.warn i::after { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--warn); }
.topic .st.none i { width: 18px; height: 18px; border: 2px solid var(--border); }
.topic .t { font-size: 14px; }
.topic.passed .t { color: var(--muted); }
.topic .acts { display: flex; align-items: center; gap: var(--sm); margin-top: 5px; font-size: 11px; color: var(--muted); }
.topic .acts .bar { width: 60px; height: 4px; }
.topic .sc { font-size: 13px; font-weight: 600; padding: 0 4px; font-variant-numeric: tabular-nums; }

/* ═════════ Профиль / настройки ═════════ */
.profile { display: flex; align-items: center; gap: 14px; }
.profile .avatar { width: 64px; height: 64px; font-size: 22px; }
.profile .n { font-size: 19px; font-weight: 600; }
.profile .s { font-size: 13px; color: var(--muted); }
.nrow { display: flex; align-items: center; gap: var(--sm); min-width: 0; }
/* PRO — тихая отметка акцентом, без золота и свечений. */
.tag {
  flex: none; display: inline-flex; align-items: center; height: 20px; padding: 0 7px;
  border: 1px solid color-mix(in oklab, var(--accent) 55%, transparent); border-radius: 6px;
  color: var(--accent); font-size: 11px; font-weight: 600; letter-spacing: .06em;
}
.tokens { display: flex; align-items: center; gap: 14px; }
.tokens .num {
  flex: none; min-width: 64px; text-align: center; font-size: clamp(30px, 8vw, 38px); font-weight: 600;
  letter-spacing: -.03em; line-height: 1; font-variant-numeric: tabular-nums; color: var(--text);
}
.tokens .num.inf { color: var(--accent); }
.perks { margin: 0; padding: 0 0 2px 18px; font-size: 13px; color: var(--muted); display: grid; gap: 3px; }
.perks li::marker { color: var(--accent); }
.reward { font-size: 13px; color: var(--muted); }
.reward.plus { color: var(--ok); font-weight: 600; }
.card .ttl { font-size: 16px; font-weight: 600; }
.card .desc { font-size: 13px; color: var(--muted); }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--c); flex: none; }
.kv { display: flex; justify-content: space-between; gap: var(--md); padding: 10px 0; border-top: 1px solid var(--border); font-size: 14px; }
.kv:first-of-type { border-top: 0; }
.kv span:last-child { font-weight: 600; font-variant-numeric: tabular-nums; }
.os-desktop .settings { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(340px, 100%), 1fr)); gap: var(--md); align-items: start; }
.os-desktop .settings > .card { margin: 0; }

/* ═════════ Вход ═════════ */
.login {
  height: var(--vh); overflow-y: auto; display: grid; place-items: center;
  padding: calc(var(--safe-t) + 20px) 20px calc(var(--safe-b) + 20px);
}
.login .card { width: 100%; max-width: 440px; padding: var(--xl); }
.login .head { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 2px; margin-bottom: var(--lg); }
.login .head h1 { margin: 10px 0 0; font-size: 24px; font-weight: 600; letter-spacing: -.015em; }
.login .head p { margin: 0; color: var(--muted); font-size: 13px; }
.login .foot { margin-top: var(--md); text-align: center; font-size: 12px; color: var(--muted); }
.login form, .login .pane { display: flex; flex-direction: column; gap: 10px; margin-top: 14px; }

/* ═════════ Слои: диалоги, тест, упражнения ═════════ */
.layer { position: fixed; inset: 0; z-index: 30; display: grid; grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr); place-items: center; padding: var(--lg); }
.layer > .modal, .layer > .win { min-width: 0; grid-area: 1 / 1; }
.layer > .scrim { grid-area: 1 / 1; }
.layer .scrim { position: absolute; inset: 0; background: var(--scrim); animation: fade var(--base) ease; }
.modal {
  position: relative; width: 100%; max-width: var(--w, 460px); max-height: calc(var(--vh) - 32px);
  display: flex; flex-direction: column; background: var(--card); border: 1px solid var(--border);
  border-radius: var(--r-panel); box-shadow: var(--shadow); animation: pop 260ms var(--ease);
}
.modal .body { padding: var(--xl); overflow-y: auto; overflow-x: hidden; min-width: 0; display: flex; flex-direction: column; gap: var(--md); }
.modal h2 { margin: 0; font-size: 20px; font-weight: 600; letter-spacing: -.01em; }
.os-android .layer { align-items: end; justify-items: stretch; padding: 0; }
.os-android .modal {
  max-width: none; border-radius: 20px 20px 0 0; border-bottom: 0; max-height: calc(var(--vh) - var(--safe-t) - 24px);
  animation: sheet 320ms var(--ease);
}
.os-android .modal .body { padding: 20px 18px calc(18px + var(--safe-b)); }
.os-android .modal::before {
  content: ""; position: absolute; top: 8px; left: 50%; width: 36px; height: 4px; margin-left: -18px;
  border-radius: 2px; background: var(--border);
}
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: translateY(10px) scale(.98); } }
@keyframes sheet { from { transform: translateY(100%); } }

.choice { display: flex; align-items: center; gap: var(--md); padding: 14px; }
.choice .ic {
  width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; flex: none;
  background: color-mix(in oklab, var(--card) 82%, var(--accent)); color: var(--accent);
}
.choice .t { font-size: 15px; font-weight: 600; }
.choice .d { font-size: 12.5px; color: var(--muted); }
.choice .l { font-size: 12px; color: var(--text); margin-top: 2px; }
.choice .chev { color: var(--muted); }

.check {
  display: flex; align-items: center; gap: var(--md); width: 100%; padding: 10px var(--md);
  border: 1px solid var(--border); border-radius: var(--r-control); background: none; cursor: pointer; text-align: left;
  transition: border-color var(--fast), background-color var(--fast);
}
.check .box {
  width: 20px; height: 20px; border-radius: 6px; border: 1.5px solid var(--border); display: grid; place-items: center; flex: none;
  color: var(--on-accent); transition: background-color var(--fast), border-color var(--fast);
}
.check[aria-checked="true"] { border-color: color-mix(in oklab, var(--border) 40%, var(--accent)); background: var(--card-hi); }
.check[aria-checked="true"] .box { background: var(--accent); border-color: var(--accent); }
.check .box svg { opacity: 0; }
.check[aria-checked="true"] .box svg { opacity: 1; }

/* Окно теста: на ПК — отдельное окно поверх, на Android — отдельный экран. */
.win { position: relative; display: flex; flex-direction: column; background: var(--bg); min-height: 0; }
.os-desktop .win {
  width: min(880px, 100%); height: min(860px, calc(var(--vh) - 32px));
  border: 1px solid var(--border); border-radius: var(--r-panel); box-shadow: var(--shadow); overflow: hidden;
  animation: pop 280ms var(--ease);
}
.os-desktop .layer.full { padding: var(--lg); }
.os-android .layer.full { padding: 0; place-items: stretch; }
.os-android .win { width: 100%; height: var(--vh); animation: up 320ms var(--ease); }
@keyframes up { from { opacity: 0; transform: translateY(12%); } }
.os-android .layer.full .scrim { display: none; }
.win-head {
  display: flex; align-items: center; gap: var(--md); padding: 14px 20px;
  background: var(--side); border-bottom: 1px solid var(--border);
}
.os-android .win-head { padding: calc(var(--safe-t) + 12px) 18px 12px; }
.win-head .t { font-size: 16px; font-weight: 600; }
.win-head .s { font-size: 12.5px; color: var(--muted); }
.win-body { flex: 1; overflow-y: auto; overflow-x: hidden; min-height: 0; }
.win-body > .inner > * { min-width: 0; }
.win-body > .inner { max-width: 760px; margin: 0 auto; padding: 20px; display: flex; flex-direction: column; gap: var(--md); }
.os-android .win-body > .inner { padding: var(--lg) 18px; }
.win-foot { border-top: 1px solid var(--border); background: var(--side); padding: var(--md) 20px; }
.os-android .win-foot { padding: 10px 18px calc(10px + var(--safe-b)); }
.win-foot .inner { max-width: 760px; margin: 0 auto; display: flex; flex-direction: column; gap: 10px; }
.win-center { height: 100%; display: grid; place-items: center; padding: var(--xl); }
.win-center .box { max-width: 420px; width: 100%; display: flex; flex-direction: column; gap: var(--md); align-items: center; text-align: center; }
.win-center h3 { margin: 0; font-size: 19px; font-weight: 600; }
.win-center .btn { width: 100%; }

.pager { position: relative; display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none; padding-bottom: 2px; }
.pager::-webkit-scrollbar { display: none; }
.pager button {
  flex: none; min-width: 32px; height: 32px; padding: 0 6px; border-radius: var(--r-control);
  border: 1px solid var(--border); background: var(--card); color: var(--muted); font-size: 13px; cursor: pointer;
  font-variant-numeric: tabular-nums; transition: border-color var(--fast), background-color var(--fast), color var(--fast);
}
.pager button.answered { background: var(--card-hi); color: var(--text); }
.pager button.ok { color: var(--ok); }
.pager button.bad { color: var(--err); }
.pager button[aria-current="true"] { border-color: var(--accent); color: var(--accent); }

.q-n { font-size: 13px; font-weight: 600; color: var(--muted); }
/* Содержимое вопросов: ничего не выходит за край — широкое прокручивается внутри. */
.q-body { overflow-x: auto; font-size: 15px; line-height: 1.55; min-width: 0; overflow-wrap: anywhere; }
.q-body img, .opt .content img { display: block; max-width: 100%; height: auto; border-radius: var(--r-control); margin: 4px 0; }
.q-body img.zoom { cursor: zoom-in; }
.q-body img.broken, .opt .content img.broken { display: none; }
.q-body pre, .opt .content pre { white-space: pre-wrap; overflow-wrap: anywhere; }
.tbl { max-width: 100%; overflow-x: auto; margin: 4px 0; overflow-wrap: normal; }
.tbl td, .tbl th { overflow-wrap: normal; word-break: normal; }
.katex-display { max-width: 100%; overflow-x: auto; overflow-y: hidden; padding: 2px 0; margin: 6px 0; }
.katex { overflow-wrap: normal; }
.q-body p { margin: 0 0 var(--sm); }
.q-body table { border-collapse: collapse; }
.q-body td, .q-body th { border: 1px solid var(--border); padding: 4px 8px; }
.opt {
  display: flex; gap: var(--md); align-items: flex-start; width: 100%; text-align: left; cursor: pointer;
  border: 1px solid var(--border); background: var(--card); border-radius: 12px; padding: var(--md) 14px;
  transition: border-color var(--fast), background-color var(--fast), transform 110ms ease;
}
.opt:hover:not(:disabled) { border-color: color-mix(in oklab, var(--border) 70%, var(--text)); }
.opt:active:not(:disabled) { transform: scale(.99); }
.opt:disabled { cursor: default; }
.opt .lead {
  flex: none; width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center;
  border: 1.5px solid var(--border); font-size: 12.5px; font-weight: 600; color: var(--muted);
  transition: background-color var(--fast), border-color var(--fast), color var(--fast);
}
.opt .content { flex: 1; min-width: 0; overflow-x: auto; padding-top: 2px; overflow-wrap: anywhere; }
.opt .content p { margin: 0; }
.opt[aria-pressed="true"] { border-color: var(--accent); background: color-mix(in oklab, var(--card) 92%, var(--accent)); }
.opt[aria-pressed="true"] .lead { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.opt.correct { border-color: var(--ok); background: color-mix(in oklab, var(--card) 90%, var(--ok)); }
.opt.correct .lead { background: var(--ok); border-color: var(--ok); color: var(--bg); }
.opt.wrong { border-color: var(--err); }
.opt.wrong .lead { border-color: var(--err); color: var(--err); }

.result { display: flex; align-items: center; gap: 20px; }
.result .t { font-size: 20px; font-weight: 600; }
.rrow {
  display: flex; align-items: center; gap: 10px; width: 100%; padding: 10px var(--md); border: 0; background: none;
  border-top: 1px solid var(--border); cursor: pointer; text-align: left; transition: background-color var(--fast);
}
.rrow:first-child { border-top: 0; }
.rrow:hover { background: var(--card-hi); }

/* ═════════ Авто-решение и консоль ═════════ */
.modes { display: grid; gap: var(--sm); grid-template-columns: minmax(0, 1fr); }
.os-desktop .modes { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.mode {
  display: flex; align-items: flex-start; gap: 10px; width: 100%; padding: 12px 14px; text-align: left; cursor: pointer;
  border: 1px solid var(--border); background: var(--card); border-radius: var(--r-card); color: var(--text);
  transition: border-color var(--fast), background-color var(--fast), transform 110ms ease;
}
.os-desktop .mode { min-height: 96px; flex-direction: column; }
.mode:hover:not(:disabled) { border-color: color-mix(in oklab, var(--border) 70%, var(--text)); }
.mode:active:not(:disabled) { transform: scale(.985); }
.mode:disabled { cursor: default; opacity: .6; }
.mode .ic {
  width: 32px; height: 32px; border-radius: 50%; flex: none; display: grid; place-items: center; color: var(--muted);
  background: color-mix(in oklab, var(--card) 80%, var(--accent)); transition: color var(--fast);
}
.mode .t { font-size: 15px; font-weight: 600; }
.mode .d { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.mode[aria-pressed="true"] { border-color: var(--accent); background: color-mix(in oklab, var(--card) 92%, var(--accent)); }
.mode[aria-pressed="true"] .ic, .mode[aria-pressed="true"] .t { color: var(--accent); }
.check:disabled { cursor: default; opacity: .6; }
.chip:disabled { cursor: default; opacity: .6; }
.solve-head { display: flex; align-items: center; gap: var(--lg); }
.solve-head .ttl { font-size: 16px; font-weight: 600; }
.solve-head .cur { font-size: 13px; color: var(--accent); }
.os-desktop .solve-head .cur { color: var(--muted); }
.solve-head .prog { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.res { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-top: 1px solid var(--border); font-size: 13px; }
.res:first-child { border-top: 0; }
.rmark { width: 18px; height: 18px; border-radius: 50%; border: 1.5px solid var(--border); display: grid; place-items: center; flex: none; }
.rmark.ok { border-color: var(--ok); color: var(--ok); }
.term-card { background: var(--card); }
.term {
  height: calc(var(--vh) - 300px); min-height: 260px; max-height: 70vh; overflow: auto; padding: var(--md);
  display: flex; flex-direction: column; gap: 6px; font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: 12px;
  overscroll-behavior: contain;
}
.os-desktop .term { height: calc(var(--vh) - 250px); font-size: 12.5px; }
.ln { display: flex; align-items: baseline; gap: 8px; line-height: 1.45; flex: none; }
.ln .tm { color: var(--muted); font-size: 11.5px; flex: none; }
.ln .lv {
  flex: none; padding: 0 5px; border-radius: 4px; font-size: 10px; font-weight: 700; color: var(--c);
  background: color-mix(in oklab, var(--card) 80%, var(--c));
}
.ln .ms { min-width: 0; overflow-wrap: anywhere; white-space: pre-wrap; }
.term-empty { margin: auto; text-align: center; color: var(--muted); font-family: inherit; white-space: pre-line; font-size: 13px; }

/* ═════════ Тосты ═════════ */
.toasts { position: fixed; z-index: 50; display: flex; flex-direction: column; gap: var(--sm); pointer-events: none; }
.os-desktop .toasts { right: 22px; bottom: 22px; align-items: flex-end; }
.os-android .toasts { left: 16px; right: 16px; top: calc(var(--safe-t) + 16px); align-items: center; }
.toast {
  display: flex; align-items: center; gap: 10px; max-width: 360px; padding: var(--md) var(--lg);
  background: var(--card); color: var(--text); font-size: 14px; border-radius: 12px;
  border: 1px solid color-mix(in oklab, var(--border) 50%, var(--c)); box-shadow: var(--shadow);
}
.os-desktop .toast { animation: tin-r 300ms var(--ease); }
.os-android .toast { border-radius: 14px; animation: tin-t 300ms var(--ease); }
.toast.out { opacity: 0; transition: opacity 300ms ease, transform 300ms ease; }
.os-desktop .toast.out { transform: translateX(24px); }
.os-android .toast.out { transform: translateY(-100%); }
@keyframes tin-r { from { opacity: 0; transform: translateX(24px); } }
@keyframes tin-t { from { opacity: 0; transform: translateY(-100%); } }

/* ═════════ Появление ═════════ */
.rise { animation: rise var(--enter) var(--ease) both; animation-delay: calc(var(--i, 0) * 70ms); }
@keyframes rise { from { opacity: 0; transform: translateY(16px); } }
.page.enter { animation: page 260ms var(--ease); }
@keyframes page { from { opacity: 0; transform: translateY(14px); } }
.fadein { animation: fade 240ms ease; }
/* Смена вкладки: страница приходит с той стороны, куда нажали. */
.page.enter.from-r { animation: page-x 300ms var(--ease); --dx: 28px; }
.page.enter.from-l { animation: page-x 300ms var(--ease); --dx: -28px; }
@keyframes page-x { from { opacity: 0; transform: translateX(var(--dx)); } }

/* Закрытие слоёв: окно уходит, а не исчезает. */
.layer.closing { pointer-events: none; }
.layer.closing .scrim { animation: fade-out 180ms ease forwards; }
.layer.closing .modal, .os-desktop .layer.closing .win { animation: pop-out 180ms var(--ease-io) forwards; }
.os-android .layer.closing .modal { animation: sheet-out 220ms var(--ease-io) forwards; }
.os-android .layer.closing .win { animation: down-out 220ms var(--ease-io) forwards; }
@keyframes fade-out { to { opacity: 0; } }
@keyframes pop-out { to { opacity: 0; transform: translateY(8px) scale(.98); } }
@keyframes sheet-out { to { transform: translateY(100%); } }
@keyframes down-out { to { opacity: 0; transform: translateY(8%); } }

/* Переход между вопросами: вперёд — справа, назад — слева. */
.slide-next { animation: slide-x 280ms var(--ease) backwards; --dx: 24px; }
.slide-prev { animation: slide-x 280ms var(--ease) backwards; --dx: -24px; }
@keyframes slide-x { from { opacity: 0; transform: translateX(var(--dx)); } }
/* Варианты появляются лесенкой. */
.slide-next .opt, .slide-prev .opt, .stagger > * { animation: rise-s 360ms var(--ease) backwards; animation-delay: calc(var(--i, 0) * 45ms + 60ms); }
@keyframes rise-s { from { opacity: 0; transform: translateY(8px); } }

/* Выбор варианта: кружок с буквой «щёлкает». */
.opt[aria-pressed="true"] .lead { animation: tick 320ms cubic-bezier(0.34, 1.56, 0.64, 1); }
@keyframes tick { 40% { transform: scale(1.22); } }
/* Ответ в упражнении: верно — мягкий отклик, неверно — короткое покачивание. */
.opt.flash.correct { animation: yes 420ms cubic-bezier(0.34, 1.56, 0.64, 1); }
.opt.flash.correct .lead { animation: tick 420ms cubic-bezier(0.34, 1.56, 0.64, 1); }
.opt.flash.wrong { animation: no 380ms var(--ease); }
@keyframes yes { 35% { transform: scale(1.02); } }
@keyframes no { 20% { transform: translateX(-6px); } 45% { transform: translateX(5px); } 70% { transform: translateX(-3px); } }
.note.flash { animation: rise-s 300ms var(--ease) backwards; }
.opt.busy { animation: pulse .9s ease-in-out infinite alternate; }

/* Раскрытие раздела: темы выезжают по очереди. */
.sec-body.open .topic { animation: rise-s 340ms var(--ease) backwards; animation-delay: calc(var(--i, 0) * 40ms + 40ms); }
.sec-head .bar > i, .topic .bar > i { transition: width 600ms var(--ease); }
/* Итоги: строки вопросов и прогресс-бар упражнения. */
.rrow { animation: rise-s 340ms var(--ease) backwards; animation-delay: calc(var(--i, 0) * 35ms + 200ms); }
.pager button[aria-current="true"] { animation: tick 280ms cubic-bezier(0.34, 1.56, 0.64, 1); }
.result .t { animation: rise-s 420ms var(--ease) backwards 150ms; }
/* Чипы и кнопки: отклик на нажатие. */
.chip:active, .tab:active, .nav-item:active, .seg button:active { transform: scale(.96); }
.seg button { transition: transform 110ms ease, color var(--base), background-color var(--fast), border-color var(--fast); }

@media (max-width: 379px) {
  .os-android .page, .os-android .win-head, .os-android .win-body > .inner { padding-left: 14px; padding-right: 14px; }
  .os-android .chips.scroll, .os-android .filters .grp { margin: 0 -14px; padding: 0 14px; }
  .os-android .modal .body { padding-left: 14px; padding-right: 14px; }
  .os-android .btn { font-size: 14px; }
  .btn-row > .btn { padding: 0 8px; }
  .login .card { padding: var(--lg); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 1ms !important; animation-delay: 0ms !important; transition-duration: 1ms !important; }
}
