/* ===========================================================================
   Digital Mektep — дизайн-система (тёмная тема по умолчанию, mobile-first)
   Референс: spaced.school — чистый тёмный, «плитки» на чёрном.
   Приоритет №1: мобильный экран 390px. Тач-таргеты ≥44px. safe-area-inset.
   =========================================================================== */

/* ---------- 1. Переменные (тёмная тема) ---------- */
:root {
  color-scheme: dark;

  --bg: #0B0B0C;             /* фон страницы */
  --surface: #161618;        /* поверхность карточек */
  --surface-2: #1F1F22;      /* вторая поверхность (инпуты, вложенное) */
  --surface-3: #2A2A2E;      /* третья поверхность / трек */
  --ink: #F5F5F7;
  --ink-2: #C7C7CC;
  --muted: #8E8E93;
  --line: #2A2A2E;
  --line-strong: #3A3A40;

  --accent: #E5E5EA;         /* бренд Digital Mektep — монохром */
  --accent-ink: #0B0B0C;
  --accent-soft: rgba(255,255,255,.14);
  --accent-press: #C7C7CC;

  --danger: #FF453A;
  --warn: #FFD60A;
  --ok: #34C759;
  --ok-strong: #34C759;

  /* оценки за прогресс — оттенки сохранены, фоны затемнены под тёмную тему */
  --g2: #5c1f1c;             /* регресс (тёмно-красный фон) */
  --g2-ink: #FF6961;
  --g3: #4a3f0d;             /* на уровне (тёмно-янтарный фон) */
  --g3-ink: #FFD60A;
  --g4: #16482a;             /* рост (тёмно-зелёный фон) */
  --g4-ink: #4ade80;
  --g5: #1f6b3a;             /* сильный прогресс */
  --g5-ink: #d4ffe1;

  /* Токены, зависящие от темы (здесь — значения тёмной темы) */
  --btn-primary-bg: #ffffff;  /* основная кнопка: белая с тёмным текстом */
  --btn-primary-ink: #0B0B0C;
  --btn-primary-press: #d9d9de;
  --accent-ink-soft: #D5D5DA; /* текст на фоне accent-soft */
  --tabbar-bg: rgba(11,11,12,.86);
  --tab-active-ink: #ffffff;
  --side-active-bg: rgba(255,255,255,.08);
  --side-active-ink: #ffffff;
  --selection-bg: rgba(255,255,255,.26);
  --selection-ink: #ffffff;
  --code-bg: rgba(255,255,255,.10);

  --radius: 16px;
  --radius-sm: 12px;
  --radius-lg: 22px;
  --radius-pill: 999px;

  --shadow-1: 0 0 0 1px var(--line), 0 8px 24px rgba(0,0,0,.5);
  --shadow-2: 0 12px 40px rgba(0,0,0,.6);
  --shadow-press: 0 0 0 1px var(--line-strong);

  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;

  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;

  --tap: 44px;
  --ease: 0.2s ease;

  --sidebar-w: 248px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --tabbar-h: 58px;
}

/* ---------- 1b. Светлая тема (переключается html[data-theme="light"]) ---------- */
html[data-theme="light"] {
  color-scheme: light;

  --bg: #F5F5F7;
  --surface: #FFFFFF;
  --surface-2: #ECECF0;
  --surface-3: #DDDDE3;
  --ink: #1C1C1E;
  --ink-2: #48484A;
  --muted: #8E8E93;
  --line: #E3E3E8;
  --line-strong: #D1D1D6;

  --accent: #1C1C1E;
  --accent-ink: #ffffff;
  --accent-soft: rgba(0,0,0,.08);
  --accent-press: #000000;
  --accent-ink-soft: #1C1C1E;

  /* оценки за прогресс — светлые тинты (как в Bilim) */
  --g2: #FFE1DE; --g2-ink: #D70015;
  --g3: #FFF3CE; --g3-ink: #8A6D00;
  --g4: #DCF6E4; --g4-ink: #1A8A4A;
  --g5: #C4F0D2; --g5-ink: #0E7C3A;

  --btn-primary-bg: #1C1C1E;  /* основная кнопка: тёмная с белым текстом */
  --btn-primary-ink: #ffffff;
  --btn-primary-press: #3A3A3C;
  --tabbar-bg: rgba(245,245,247,.86);
  --tab-active-ink: #1C1C1E;
  --side-active-bg: rgba(0,0,0,.06);
  --side-active-ink: #1C1C1E;
  --selection-bg: rgba(0,0,0,.16);
  --selection-ink: #1C1C1E;
  --code-bg: rgba(0,0,0,.06);

  /* мягкие тени как в Bilim */
  --shadow-1: 0 0 0 1px var(--line), 0 8px 24px rgba(0,0,0,.08);
  --shadow-2: 0 12px 40px rgba(0,0,0,.14);
  --shadow-press: 0 0 0 1px var(--line-strong);
}
/* Семантические подписи, читаемые на светлых тинтах */
html[data-theme="light"] .chip.ok,     html[data-theme="light"] .alert-ok    { color: #1A8A4A; }
html[data-theme="light"] .chip.warn                                          { color: #8A6D00; }
html[data-theme="light"] .chip.danger, html[data-theme="light"] .alert-danger { color: #D70015; }
html[data-theme="light"] .session-plate { color: #1C1C1E; }
html[data-theme="light"] .raised-box    { color: #8A6D00; }

/* ---------- 2. Reset ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.45;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  min-height: 100vh;
  min-height: 100dvh;
}
h1,h2,h3,h4,p,figure,ul,ol { margin: 0; }
ul,ol { padding: 0; list-style: none; }
a { color: inherit; text-decoration: none; }
img,svg { max-width: 100%; display: block; }
button { font-family: inherit; }
input,select,textarea { font-family: inherit; font-size: 16px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Тёмные скроллбары и фиолетовое выделение текста */
html { scrollbar-color: var(--surface-3) transparent; scrollbar-width: thin; }
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb { background: var(--surface-3); border-radius: 999px; border: 2px solid var(--bg); }
*::-webkit-scrollbar-thumb:hover { background: var(--line-strong); }
::selection { background: var(--selection-bg); color: var(--selection-ink); }

/* ---------- 3. Типографика ---------- */
h1 { font-size: 28px; line-height: 1.15; font-weight: 700; letter-spacing: -.02em; }
h2 { font-size: 22px; line-height: 1.2; font-weight: 700; letter-spacing: -.01em; }
h3 { font-size: 18px; line-height: 1.25; font-weight: 650; }
h4 { font-size: 15px; font-weight: 650; }
small { font-size: 13px; }
.title-lg { font-size: 34px; font-weight: 800; letter-spacing: -.03em; }
.muted { color: var(--muted); }
.subtle { color: var(--ink-2); }
.center { text-align: center; }
.nowrap { white-space: nowrap; }
.mono { font-variant-numeric: tabular-nums; }

/* ---------- 4. Каркас приложения ---------- */
.app-main {
  padding: calc(var(--space-4) + var(--safe-top)) var(--space-4)
           calc(var(--tabbar-h) + var(--safe-bottom) + var(--space-4));
  max-width: 760px;
  margin: 0 auto;
  width: 100%;
}
body.no-nav .app-main { padding-bottom: calc(var(--space-6) + var(--safe-bottom)); }

/* ---------- 5. Карточки ---------- */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-1);
  padding: var(--space-4);
  margin-bottom: var(--space-4);
}
.card.pad-lg { padding: var(--space-5); }
.card.flat { box-shadow: none; border: 1px solid var(--line); }
.card-title { font-size: 13px; font-weight: 650; color: var(--muted);
  text-transform: uppercase; letter-spacing: .04em; margin-bottom: var(--space-2); }

/* ---------- 6. Кнопки ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: var(--space-2);
  min-height: var(--tap); padding: 0 var(--space-4);
  border: none; border-radius: var(--radius-sm);
  background: var(--surface-2); color: var(--ink);
  font-size: 16px; font-weight: 600; cursor: pointer;
  transition: transform var(--ease), background var(--ease), box-shadow var(--ease), opacity var(--ease);
  -webkit-tap-highlight-color: transparent; user-select: none;
}
.btn:active { transform: scale(.97); box-shadow: var(--shadow-press); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
/* Основная кнопка — контрастная (тёмная в тёмной теме — белая; в светлой — тёмная). */
.btn-primary { background: var(--btn-primary-bg); color: var(--btn-primary-ink); }
.btn-primary:active { background: var(--btn-primary-press); }
/* Акцентная фиолетовая кнопка (когда нужен бренд-цвет на кнопке). */
.btn-accent { background: var(--accent); color: var(--accent-ink); }
.btn-accent:active { background: var(--accent-press); }
.btn-ghost { background: transparent; color: var(--ink); border: 1px solid var(--line-strong); }
.btn-ghost:active { background: var(--surface-2); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-block { width: 100%; }
.btn-sm { min-height: 36px; padding: 0 var(--space-3); font-size: 14px; }
.btn-lg { min-height: 52px; font-size: 17px; padding: 0 var(--space-5); }

/* ---------- 7. Чипы / бейджи ---------- */
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px; border-radius: var(--radius-pill);
  background: var(--surface-2); color: var(--ink-2);
  font-size: 13px; font-weight: 600; white-space: nowrap;
}
.chip.accent { background: var(--accent-soft); color: var(--accent-ink-soft); }
.chip.ok { background: rgba(52,199,89,.16); color: #4ade80; }
.chip.warn { background: rgba(255,214,10,.16); color: #FFD60A; }
.chip.danger { background: rgba(255,69,58,.16); color: #FF6961; }
.badge {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 20px; height: 20px; padding: 0 6px;
  border-radius: var(--radius-pill);
  background: var(--danger); color: #fff; font-size: 12px; font-weight: 700;
}
.badge.neutral { background: var(--surface-3); color: var(--ink-2); }

/* ---------- 7b. Ссылка «назад» (шапки страниц) ---------- */
.back {
  display: inline-flex; align-items: center; gap: 6px;
  min-height: 44px; padding: 10px 14px 10px 0;
  font-size: 16px; font-weight: 600; color: var(--accent);
  text-decoration: none; border-radius: 8px;
  -webkit-tap-highlight-color: transparent;
}
.back:active { opacity: .6; }

/* ---------- 8. Оценки за прогресс ---------- */
.grade {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 34px; height: 34px; padding: 0 8px;
  border-radius: 10px; font-weight: 800; font-size: 17px;
  font-variant-numeric: tabular-nums;
}
.grade-2 { background: var(--g2); color: var(--g2-ink); }
.grade-3 { background: var(--g3); color: var(--g3-ink); }
.grade-4 { background: var(--g4); color: var(--g4-ink); }
.grade-5 { background: var(--g5); color: var(--g5-ink); }
.grade-label { font-size: 12px; font-weight: 600; color: var(--muted); }
.grade-cell { display: inline-flex; flex-direction: column; align-items: center; gap: 2px; }

/* ---------- 9. Списки ---------- */
.list { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow-1); overflow: hidden; }
.list-item {
  display: flex; align-items: center; gap: var(--space-3);
  min-height: var(--tap); padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--line);
  transition: background var(--ease);
}
.list-item:last-child { border-bottom: none; }
.list-item:active { background: var(--surface-2); }
.list-item .li-main { flex: 1; min-width: 0; }
.list-item .li-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-item .li-sub { font-size: 13px; color: var(--muted); }
.list-item .li-trail { margin-left: auto; display: flex; align-items: center; gap: var(--space-2); }
.list-item.link::after { content: "›"; color: var(--line-strong); font-size: 22px; margin-left: 4px; }

/* ---------- 10. Bottom-sheet ---------- */
.sheet-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,.4);
  opacity: 0; pointer-events: none; transition: opacity var(--ease); z-index: 60;
}
.sheet-backdrop.open { opacity: 1; pointer-events: auto; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 61;
  background: var(--surface);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  box-shadow: var(--shadow-2);
  padding: var(--space-4) var(--space-4) calc(var(--space-5) + var(--safe-bottom));
  transform: translateY(100%);
  transition: transform .28s cubic-bezier(.2,.8,.2,1);
  max-height: 88vh; overflow-y: auto;
}
.sheet.open { transform: translateY(0); }
.sheet-grip { width: 40px; height: 5px; border-radius: 3px; background: var(--line-strong);
  margin: 0 auto var(--space-3); }
@media (min-width: 640px) {
  .sheet { left: 50%; right: auto; bottom: 50%; transform: translate(-50%, 60%) scale(.98);
    width: 460px; max-width: calc(100vw - 32px); border-radius: var(--radius-lg); opacity: 0; }
  .sheet.open { transform: translate(-50%, 50%) scale(1); opacity: 1; }
}

/* ---------- 11. Таблица со скроллом и липкой первой колонкой ---------- */
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch;
  border-radius: var(--radius); box-shadow: var(--shadow-1); background: var(--surface); }
.table-scroll table { border-collapse: collapse; width: 100%; min-width: max-content; }
.table-scroll th, .table-scroll td {
  padding: var(--space-3); text-align: center; font-size: 14px;
  border-bottom: 1px solid var(--line); white-space: nowrap;
}
.table-scroll thead th { position: sticky; top: 0; background: var(--surface-2);
  font-weight: 650; color: var(--ink-2); z-index: 2; }
.table-scroll th.sticky-col, .table-scroll td.sticky-col {
  position: sticky; left: 0; background: var(--surface); text-align: left;
  z-index: 3; box-shadow: 1px 0 0 var(--line);
}
.table-scroll thead th.sticky-col { z-index: 4; background: var(--surface-2); }

/* ---------- 12. Progress-ring ---------- */
.progress-ring { --p: 0; --size: 64px; --tw: 7px;
  width: var(--size); height: var(--size); border-radius: 50%;
  display: grid; place-items: center; position: relative;
  background: conic-gradient(var(--accent) calc(var(--p) * 1%), var(--surface-3) 0);
}
.progress-ring::before { content: ""; position: absolute; inset: var(--tw);
  border-radius: 50%; background: var(--surface); }
.progress-ring .pr-val { position: relative; font-weight: 800; font-size: 16px; font-variant-numeric: tabular-nums; }

/* ---------- 13. Скелетоны ---------- */
.skeleton { background: linear-gradient(100deg, var(--surface-2) 30%, var(--surface-3) 50%, var(--surface-2) 70%);
  background-size: 200% 100%; animation: sk 1.2s infinite linear; border-radius: var(--radius-sm); }
.skeleton.line { height: 14px; margin-bottom: 8px; }
.skeleton.line.short { width: 55%; }
.skeleton.block { height: 96px; }
@keyframes sk { to { background-position: -200% 0; } }

/* ---------- 14. Формы ---------- */
.field { display: flex; flex-direction: column; gap: 6px; }
.field-label { font-size: 13px; font-weight: 600; color: var(--ink-2); }
.input, .select, .textarea {
  width: 100%; min-height: var(--tap); padding: 10px var(--space-3);
  border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--ink);
  transition: border-color var(--ease), box-shadow var(--ease);
}
.textarea { min-height: 96px; padding: var(--space-3); resize: vertical; line-height: 1.5; }
.input:focus, .select:focus, .textarea:focus {
  border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); outline: none; }
.alert { padding: var(--space-3) var(--space-4); border-radius: var(--radius-sm);
  font-size: 14px; font-weight: 600; margin-bottom: var(--space-3); }
.alert-danger { background: rgba(255,69,58,.16); color: #FF6961; }
.alert-ok { background: rgba(52,199,89,.16); color: #4ade80; }

/* ---------- 15. Утилиты ---------- */
.row { display: flex; align-items: center; gap: var(--space-3); }
.row.wrap { flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.row.end { justify-content: flex-end; }
.stack { display: flex; flex-direction: column; gap: var(--space-3); }
.stack.tight { gap: var(--space-2); }
/* minmax(0,1fr): колонка обязана сжиматься — иначе длинный nowrap-контент
   распирает сетку и страница уезжает вбок на телефоне */
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--space-3); }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--space-3); }
.grid-auto { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: var(--space-3); }
.spacer { flex: 1; }
.hide { display: none !important; }
.mt-1 { margin-top: var(--space-1); } .mt-2 { margin-top: var(--space-2); }
.mt-3 { margin-top: var(--space-3); } .mt-4 { margin-top: var(--space-4); }
.mt-5 { margin-top: var(--space-5); } .mt-6 { margin-top: var(--space-6); }
.mb-0 { margin-bottom: 0; } .mb-2 { margin-bottom: var(--space-2); }
.mb-3 { margin-bottom: var(--space-3); } .mb-4 { margin-bottom: var(--space-4); }
.pad-0 { padding: 0; }
.stat { font-size: 30px; font-weight: 800; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.divider { height: 1px; background: var(--line); margin: var(--space-3) 0; border: 0; }

/* ---------- 16. Навигация: нижний tab-bar (мобайл) ---------- */
.tab-bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  display: flex; justify-content: space-around;
  background: var(--tabbar-bg);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-top: 1px solid var(--line);
  padding-bottom: var(--safe-bottom);
}
.tab-bar .tab {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; min-height: var(--tabbar-h); padding: 6px 2px;
  color: var(--muted); font-size: 11px; font-weight: 600;
  transition: color var(--ease), transform var(--ease);
}
.tab-bar .tab .ic { font-size: 22px; line-height: 1; filter: grayscale(.5) opacity(.7); transition: filter var(--ease), transform var(--ease); }
.tab-bar .tab .lb { letter-spacing: -.01em; }
.tab-bar .tab.active { color: var(--tab-active-ink); }
.tab-bar .tab.active .ic { filter: none; transform: translateY(-1px) scale(1.06); }
.tab-bar .tab:active { transform: scale(.94); }

/* ---------- 17. Навигация: сайдбар (десктоп) ---------- */
.sidebar { display: none; }
.sidebar-brand { display: flex; align-items: center; gap: var(--space-3);
  padding: var(--space-4) var(--space-4) var(--space-5);
  color: inherit; text-decoration: none; border-radius: 10px;
  -webkit-tap-highlight-color: transparent; }
.sidebar-brand:active { opacity: .7; }
.brand-mark { font-size: 26px; display: inline-flex; align-items: center; color: var(--accent); }
.brand-mark svg { width: 22px; height: 22px; display: block; }
.brand-text { display: flex; flex-direction: column; font-weight: 800; font-size: 18px; line-height: 1.05; color: var(--ink); }
.brand-text small { font-weight: 600; font-size: 11px; color: var(--muted); }
.sidebar-nav { display: flex; flex-direction: column; gap: 2px; padding: 0 var(--space-2); flex: 1; }
.side-link {
  display: flex; align-items: center; gap: var(--space-3);
  min-height: var(--tap); padding: 10px var(--space-3);
  border-radius: var(--radius-sm); color: var(--ink-2); font-weight: 600;
  transition: background var(--ease), color var(--ease);
}
.side-link .ic { font-size: 20px; width: 24px; text-align: center; }
.side-link:hover { background: var(--surface-2); }
.side-link:active { background: var(--surface-2); transform: scale(.98); }
.side-link.active { background: var(--side-active-bg); color: var(--side-active-ink); }
/* кнопка-переключатель темы использует стиль side-link */
button.side-link { width: 100%; text-align: left; border: none; background: transparent;
  font: inherit; cursor: pointer; }
.side-link.logout { color: #FF6961; }
.sidebar-foot { padding: var(--space-3) var(--space-2) var(--space-4); border-top: 1px solid var(--line); }
.user-chip { display: flex; align-items: center; gap: var(--space-2); padding: var(--space-2) var(--space-3); margin-bottom: var(--space-2); }
.user-chip .ava { width: 34px; height: 34px; border-radius: 50%; background: var(--accent); color: #fff;
  display: grid; place-items: center; font-weight: 700; text-transform: uppercase; }
.user-chip .u-meta { display: flex; flex-direction: column; min-width: 0; }
.user-chip .u-meta b { font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- 18. Экран логина ---------- */
.login-wrap { max-width: 420px; margin: 0 auto; padding-top: var(--space-5); }
.login-hero { text-align: center; margin-bottom: var(--space-5); }
.login-logo { line-height: 1; margin-bottom: var(--space-3); display: inline-block;
  color: var(--ink); text-decoration: none;
  filter: drop-shadow(0 6px 18px rgba(0,0,0,.35)); }
.login-logo svg, .login-logo img { height: 44px; width: auto; margin: 0 auto; }

/* Оригинальный логотип (logo.svg: звезда + словомарк одним SVG), цвет
   наследуется — работает в светлой и тёмной теме (не белый #fff). */
.logo-lockup { display: inline-flex; align-items: center; color: inherit; }
.logo-lockup .logo-full { height: 40px; width: auto; }
.login-logo .logo-full { height: 44px; }
.login-brand { font-size: 30px; font-weight: 800; letter-spacing: -.02em; }
.login-brand span { display: block; font-size: 14px; font-weight: 600; color: var(--accent); margin-top: 2px; }
.login-sub { margin-top: var(--space-2); }
.login-card { padding: var(--space-5); }
.demo-card { padding: var(--space-4); }
.demo-title { display: flex; align-items: center; justify-content: space-between; gap: var(--space-2);
  font-weight: 700; font-size: 14px; margin-bottom: var(--space-3); }
.demo-grid { display: flex; flex-direction: column; gap: var(--space-2); }
.demo-btn { justify-content: flex-start; gap: var(--space-3); text-align: left; height: auto; padding: 10px var(--space-3); }
.demo-ic { font-size: 22px; }
.demo-lb { display: flex; flex-direction: column; line-height: 1.2; }
.demo-lb small { font-weight: 500; }
.demo-hint { font-size: 12px; margin-top: var(--space-3); }
.login-foot { text-align: center; margin-top: var(--space-5); font-size: 12px; }

/* ---------- 18b. Круглая кнопка переключения темы (угол экрана) ---------- */
.theme-corner {
  position: fixed; top: calc(var(--safe-top) + 10px); right: 14px; z-index: 50;
  width: 42px; height: 42px; border-radius: 50%;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  font-size: 19px; line-height: 1; display: grid; place-items: center;
  cursor: pointer; box-shadow: var(--shadow-1); -webkit-tap-highlight-color: transparent;
  transition: transform var(--ease), background var(--ease); }
.theme-corner:active { transform: scale(.92); background: var(--surface-2); }
/* Вторая круглая кнопка (эмодзи) — левее кнопки темы */
.emoji-corner { right: 64px; }
/* Кнопка на главном кабинете нужна только на мобильных (на десктопе есть сайдбар) */
@media (min-width: 900px) { .theme-corner--app { display: none; } }

/* ---------- 19. Десктоп ≥900px: сайдбар вместо tab-bar ---------- */
@media (min-width: 900px) {
  .tab-bar { display: none; }
  body.has-nav .sidebar {
    display: flex; flex-direction: column;
    position: fixed; top: 0; bottom: 0; left: 0; width: var(--sidebar-w);
    background: var(--bg); border-right: 1px solid var(--line);
    padding-top: var(--safe-top); z-index: 30;
  }
  body.has-nav .app-main {
    margin-left: var(--sidebar-w);
    max-width: 860px;
    padding: var(--space-6) var(--space-6) var(--space-6);
    margin-right: auto;
  }
}

/* ---------- 19b. Космо-баннер (главная ученика) ---------- */
.space-hero {
  position: relative; overflow: hidden;
  height: 120px; border-radius: var(--radius);
  margin-bottom: var(--space-4);
  border: 1px solid var(--line);
  background:
    radial-gradient(1px 1px at 20% 30%, rgba(255,255,255,.9), transparent),
    radial-gradient(1px 1px at 70% 25%, rgba(255,255,255,.7), transparent),
    radial-gradient(1.5px 1.5px at 40% 70%, rgba(255,255,255,.85), transparent),
    radial-gradient(1px 1px at 85% 60%, rgba(255,255,255,.6), transparent),
    radial-gradient(1px 1px at 55% 45%, rgba(255,255,255,.75), transparent),
    radial-gradient(1.5px 1.5px at 12% 80%, rgba(255,255,255,.6), transparent),
    radial-gradient(1px 1px at 92% 20%, rgba(180,160,255,.9), transparent),
    linear-gradient(120deg, #1a0b2e 0%, #0b0b1a 60%, #0d0620 100%);
  display: flex; align-items: center; justify-content: center;
}
.space-hero .hero-star { width: 40px; height: 40px; color: #fff;
  filter: drop-shadow(0 0 14px rgba(255,255,255,.35)); }
.space-hero .hero-star svg { width: 100%; height: 100%; display: block; }
.space-hero::after { content: ""; position: absolute; inset: 0;
  background: radial-gradient(120% 90% at 80% 10%, rgba(255,255,255,.10), transparent 60%);
  pointer-events: none; }

/* ---------- 20. Прочее ---------- */
@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}

/* --- Markdown в репликах ИИ (фильтр |md) --- */
.bubble ul.md-list, .q-ai ul.md-list { margin: 4px 0 4px 18px; padding: 0; }
.bubble ul.md-list li { margin: 2px 0; }
.bubble code, .q-ai code {
  font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: .92em; background: var(--code-bg);
  padding: 1px 5px; border-radius: 6px;
}
.bubble.student code { background: rgba(255,255,255,.22); }
.md-link { color: var(--accent); text-decoration: underline; font-weight: 600; }
.bubble.student .md-link { color: inherit; }

/* Видимая реакция на нажатие для всех интерактивных элементов (мобильный приоритет) */
a, button, [role="tab"], [role="button"], .card.link, .list-item, .side-link, .tab {
  -webkit-tap-highlight-color: transparent;
}
.card.link, a.card { transition: background var(--ease), transform var(--ease), box-shadow var(--ease); }
.card.link:active, a.card:active { background: var(--surface-2); transform: scale(.99); }
.chip:active { transform: scale(.94); }

/* --- Страница никогда не прокручивается вбок «в пустоту» (мобильные) ------ */
html, body { overflow-x: clip; }
@supports not (overflow: clip) {
  html, body { overflow-x: hidden; }
}

/* --- Мастер первичной настройки (всплывает на главной у новой школы) ------ */
.wiz-back {
  position: fixed; inset: 0; z-index: 80; display: flex; align-items: center;
  justify-content: center; padding: var(--space-3);
  background: rgba(0,0,0,.55);
  backdrop-filter: blur(14px) saturate(140%);
  -webkit-backdrop-filter: blur(14px) saturate(140%);
  overscroll-behavior: contain;
}
.wiz {
  width: min(660px, 100%); max-height: min(88vh, 900px); display: flex;
  flex-direction: column; background: var(--surface); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-2); overflow: hidden;
}
.wiz-head { padding: var(--space-4) var(--space-4) var(--space-3); }
.wiz-head h2 { margin: 0 0 4px; font-size: 21px; letter-spacing: -.02em; }
.wiz-head p { margin: 0; font-size: 14px; }
.wiz-body { flex: 1; overflow-y: auto; padding: 0 var(--space-4) var(--space-3);
  -webkit-overflow-scrolling: touch; }
.wiz-step { display: flex; gap: 12px; padding: var(--space-3) 0;
  border-top: 1px solid var(--line); }
.wiz-num { flex: none; width: 28px; height: 28px; border-radius: 50%;
  display: grid; place-items: center; font-size: 14px; font-weight: 800;
  background: var(--surface-2); color: var(--ink-2); }
.wiz-num.ok { background: var(--ok); color: #fff; }
.wiz-main { flex: 1; min-width: 0; }
.wiz-main h3 { margin: 3px 0 2px; font-size: 16px; }
.wiz-main p { margin: 0 0 10px; font-size: 14px; line-height: 1.45; }
.wiz-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.wiz-row .input, .wiz-row .select { flex: 1; min-width: 150px; }
.wiz-card { background: var(--surface-2); border-radius: var(--radius-sm);
  padding: var(--space-3); margin-bottom: 8px; }
.wiz-form { display: grid; gap: 8px; }
.wiz-form-title { font-weight: 700; font-size: 15px; }
.wiz-done { font-size: 15px; }
.wiz-err { color: var(--danger, #FF453A); font-size: 13px; font-weight: 600; }
.wiz-cred { border: 1px solid var(--ok); border-radius: var(--radius-sm);
  padding: var(--space-3); margin-bottom: 10px; }
.wiz-cred-row { display: flex; gap: 10px; align-items: baseline; margin-top: 4px; }
.wiz-cred-row span { font-size: 13px; color: var(--muted); min-width: 62px; }
.wiz-cred code { font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: 15px; font-weight: 700; background: var(--surface-2);
  padding: 3px 9px; border-radius: 7px; user-select: all; }
.wiz-cred p { margin: 8px 0 0; font-size: 12px; }
.wiz-links { display: flex; flex-wrap: wrap; gap: 8px; }
.wiz-chips { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 10px; }
.wiz-chip { font-size: 13px; font-weight: 650; padding: 3px 10px;
  border-radius: var(--radius-pill); background: var(--surface-2); color: var(--ink-2); }
.wiz-chip.ok { background: rgba(52,199,89,.16); color: var(--ok); }
.wiz-foot { display: flex; gap: 8px; justify-content: flex-end;
  padding: var(--space-3) var(--space-4);
  padding-bottom: calc(var(--space-3) + var(--safe-bottom, 0px));
  border-top: 1px solid var(--line); background: var(--surface); }
@media (max-width: 520px) {
  .wiz-foot { flex-direction: column-reverse; }
  .wiz-foot .btn { width: 100%; }
}
