/* =========================================================
   База
   ========================================================= */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  font: var(--fs-base)/1.5 Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--canvas);
  color: var(--ink);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
p { margin: 0 0 var(--s2); }
img { max-width: 100%; }
[hidden] { display: none !important; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.muted { color: var(--muted); }
.spacer { flex: 1; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* =========================================================
   Шапка
   ========================================================= */
.app-header {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: var(--s3);
  padding: calc(var(--s2) + env(safe-area-inset-top, 0px)) var(--s5) var(--s2);
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
.logo { display: flex; align-items: center; gap: 6px; font-size: var(--fs-md); font-weight: 800; letter-spacing: -.01em; }
.header-tools { display: flex; align-items: center; gap: var(--s2); }
.input.lang-select { width: auto; min-height: 36px; padding: 4px 8px; font-size: var(--fs-sm); font-weight: 700; }



/* =========================================================
   Раскладка
   ========================================================= */
main { max-width: var(--page-width, 1120px); margin: 0 auto; padding: var(--s5) var(--s4) var(--s6); }


.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: var(--s5);
  margin: var(--s4) 0;
  box-shadow: var(--shadow);
}
.notice {
  background: var(--warn-bg); color: var(--warn-ink);
  border: 1px solid #f0d58a; border-radius: var(--r-md);
  padding: var(--s3) var(--s4); margin-bottom: var(--s4); font-size: var(--fs-sm);
}
.warn {
  background: var(--warn-bg); color: var(--warn-ink);
  border-radius: var(--r-sm); padding: 6px 10px; margin-top: 6px; font-size: 14px;
}
.center { text-align: center; margin: var(--s5) 0; }

/* =========================================================
   Система компонентов: кнопки, сегменты, выключатель, ползунок
   Одни и те же классы на всех страницах (см. utils.js).
   ========================================================= */
/* Кнопка: основная по умолчанию; варианты — secondary, ghost (контурная), danger, quiet; размеры — sm, lg */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 40px; padding: 0 16px; flex: none;
  border: 1.5px solid transparent; border-radius: var(--r-md);
  background: var(--primary); color: #fff;
  font-family: inherit; font-size: 15px; font-weight: 600; line-height: 1; text-decoration: none; white-space: nowrap; cursor: pointer;
  transition: background-color .15s var(--ease), border-color .15s var(--ease), color .15s var(--ease), transform .1s var(--ease);
}
.btn:hover { background: var(--primary-hover); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: default; pointer-events: none; }
.btn .icon { flex: none; }
.btn-secondary { background: var(--primary-soft-2); color: var(--primary); }
.btn-secondary:hover { background: #6c4cf53a; }
.btn-ghost { background: var(--surface); color: var(--primary); border-color: var(--line); }
.btn-ghost:hover { background: var(--primary-soft); border-color: var(--primary-soft-2); }
.btn-danger { background: transparent; color: var(--bad); border-color: transparent; }
.btn-danger:hover { background: var(--bad-soft); }
.btn-quiet { background: transparent; color: var(--muted); border-color: transparent; }
.btn-quiet:hover { background: var(--canvas); color: var(--ink); }
.btn-sm { height: 32px; padding: 0 12px; font-size: 14px; gap: 6px; border-radius: var(--r-sm); }
.btn-lg { height: 48px; padding: 0 24px; font-size: 16px; }
.btn-icon { width: 40px; padding: 0; }
.btn-icon.btn-sm { width: 32px; }
.btn-row { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s2); }

/* Сегменты: вкладки, переключатели вида и ролей — везде одинаковые */
.segmented { display: inline-flex; flex-wrap: wrap; gap: 4px; padding: 4px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md); }
.segmented-item {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 36px; padding: 0 14px; border: 0; border-radius: 9px; background: none;
  font-family: inherit; font-size: 15px; font-weight: 600; line-height: 1; color: var(--muted); cursor: pointer; white-space: nowrap;
  transition: background-color .15s var(--ease), color .15s var(--ease);
}
.segmented-item:hover { color: var(--ink); background: var(--canvas); }
.segmented-item[aria-selected="true"], .segmented-item[aria-pressed="true"] { background: var(--primary); color: #fff; }
.segmented.segmented-sm .segmented-item { height: 30px; padding: 0 10px; font-size: 14px; }

/* Выключатель */
.switch { display: flex; align-items: flex-start; gap: 12px; cursor: pointer; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch-track { position: relative; flex: none; width: 40px; height: 24px; margin-top: 1px; border-radius: var(--r-pill); background: #cfcbe3; transition: background-color .15s var(--ease); }
.switch-track::after { content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px #0003; transition: transform .15s var(--ease); }
.switch input:checked + .switch-track { background: var(--primary); }
.switch input:checked + .switch-track::after { transform: translateX(16px); }
.switch input:focus-visible + .switch-track { outline: 3px solid var(--focus); outline-offset: 2px; }
.switch-text { display: flex; flex-direction: column; gap: 2px; }
.switch-label { font-weight: 600; }
.switch-hint { font-size: 13px; color: var(--muted); }

/* Ползунок */
.range-field { display: flex; flex-direction: column; gap: 6px; }
.range-head { display: flex; align-items: baseline; justify-content: space-between; gap: var(--s2); }
.range-value { font-variant-numeric: tabular-nums; color: var(--primary); }
.range { width: 100%; height: 24px; margin: 0; background: none; accent-color: var(--primary); cursor: pointer; }

/* =========================================================
   Шкала заголовков: одинаковый уровень — одинаковый вид на всех страницах
   ========================================================= */
.title-1, h1.page-title, .lesson-heading { font-size: 26px; font-weight: 800; line-height: 1.2; letter-spacing: -.01em; margin: 0; }
.title-2 { font-size: 20px; font-weight: 700; line-height: 1.3; margin: 0; }
.title-3 { font-size: 17px; font-weight: 700; line-height: 1.35; margin: 0; }
.overline { font-size: 12px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); margin: 0; }

/* =========================================================
   Поля ввода
   ========================================================= */
.input {
  width: 100%; padding: 9px 12px;
  background: var(--surface); color: var(--ink);
  border: 1.5px solid var(--line); border-radius: var(--r-sm);
  transition: border-color .15s var(--ease), box-shadow .15s var(--ease);
}
.input:focus { border-color: var(--primary); box-shadow: 0 0 0 4px var(--primary-soft-2); outline: none; }
textarea.input { resize: vertical; line-height: 1.5; }

.field { display: block; margin: var(--s4) 0 0; }
.field:first-child { margin-top: 0; }
.field-label { display: block; margin-bottom: 4px; font-size: var(--fs-sm); font-weight: 800; }
.field-hint { margin: 0 0 6px; font-size: 14px; color: var(--muted); }
.example {
  margin: 0 0 6px; padding: 6px 10px; border-radius: var(--r-sm);
  background: var(--primary-soft); white-space: pre-wrap;
  font: 14px/1.45 ui-monospace, Menlo, Consolas, monospace;
}
.example b { font-family: Inter, system-ui, sans-serif; color: var(--muted); }

/* =========================================================
   Меню
   ========================================================= */
.menu-wrap { position: relative; }
.menu {
  position: absolute; right: 0; top: calc(100% + 4px); z-index: 30;
  min-width: 190px; padding: 4px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md);
  box-shadow: 0 10px 30px #1d1a3a22;
}
.menu button {
  display: block; width: 100%; text-align: left;
  padding: 8px 12px; border: 0; border-radius: var(--r-sm);
  background: none; font-size: 14.5px; cursor: pointer;
}
.menu button:hover, .menu button:focus-visible { background: var(--canvas); outline: none; }
.menu .danger { color: var(--bad); }

/* =========================================================
   Уведомления
   ========================================================= */
.toasts {
  position: fixed; left: 50%; bottom: calc(16px + env(safe-area-inset-bottom, 0px)); z-index: 100;
  transform: translateX(-50%);
  display: flex; flex-direction: column; gap: var(--s2);
  width: min(560px, calc(100vw - 32px));
}
.toast {
  display: flex; align-items: center; gap: var(--s3);
  padding: 12px 16px; border-radius: var(--r-md);
  background: var(--ink); color: #fff; box-shadow: 0 10px 30px #0003;
  animation: toast-in .25s var(--ease);
}
.toast.error { background: #8c1c32; }
.toast button {
  margin-left: auto; padding: 4px 10px; flex: none;
  border: 1.5px solid #fff6; border-radius: var(--r-sm);
  background: none; color: #fff; font-weight: 800; cursor: pointer;
}

.confetti { position: fixed; top: -20px; z-index: 99; width: 9px; height: 14px; pointer-events: none; animation: fall 2.2s ease-in forwards; }

/* =========================================================
   Анимации — только в ответ на действия
   ========================================================= */
@keyframes pop { from { transform: scale(.3); opacity: 0; } 60% { transform: scale(1.12); } }
@keyframes pulse { 50% { transform: scale(1.12); } }
@keyframes shake { 25% { transform: translateX(-4px); } 75% { transform: translateX(4px); } }
@keyframes pulse-sm { 50% { transform: scale(1.05); } }
@keyframes shake-sm { 25% { transform: translateX(-2px); } 75% { transform: translateX(2px); } }
@keyframes fall { to { transform: translateY(110vh) rotate(720deg); } }
@keyframes toast-in { from { opacity: 0; transform: translateY(10px); } }
.pulse { animation: pulse .28s ease-out !important; }
.shake { animation: shake .14s ease-in-out 2 !important; }

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

/* Навигация разделов ученика (Уроки / Рейтинг) — общий сегментный компонент */
.app-nav { display: flex; justify-content: center; margin: var(--s4) auto 0; }
@media (max-width: 600px) { .app-nav .segmented { width: calc(100% - 2 * var(--s3)); } .app-nav .segmented-item { flex: 1; } }


/* Единая ширина страниц: все вкладки и разделы — по одному стандарту */
:root { --page-width: 1120px; }
main, main.wide, main.bank-width, main.seating-width { max-width: var(--page-width); }
main.bank-width { padding-bottom: 0; }
#bank-root, #bank-root.seating-width { max-width: var(--page-width); }
