/**
 * Оформление Зоны J.
 *
 * Цвет фона — #303545: тёмно-синий графит вместо чёрного. Чёрный с ярким
 * акцентом читается как терминал или сигнальный канал; приглушённый синий
 * с песочным акцентом — как кабинет, в котором работают годами.
 *
 * Каркас: полоса сверху, полоса слева, тонкая полоса снизу со слоганом.
 * Меню живёт в левой полосе, и у каждого пункта своё место. Раньше
 * «Каталог», «Мои курсы» и «Задания» стояли рядом одинаковыми словами, и
 * было непонятно, куда жать: теперь это один раздел «Обучение» с
 * вкладками внутри.
 */

:root {
  color-scheme: dark;

  /* Тёмная тема — «Терминал» с главной: тот же фон, те же шрифты, тот же
     песочный. Человек, пришедший с главной, должен узнать место, а не
     попасть в другой продукт */
  --bg: #14171f;
  --rail: #11141b;
  --surface: #1a1f2a;
  --surface-2: #222838;
  --line: #2a3142;
  --ink: #eef1f6;
  --muted: #a3acbf;
  --faint: #7f889c;
  --accent: #d8b26a;      /* песочный: кнопки и ссылки, больше нигде */
  --sale: #c2603f;        /* терракота: только скидка, чтобы не путалась с кнопкой */
  --accent-ink: #14171f;
  --profit: #5fae86;
  --loss: #d0826a;
  --warn: #d8b26a;

  --font-body: 'Manrope', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-head: 'Unbounded', 'Manrope', -apple-system, 'Segoe UI', sans-serif;
  --head-track: -.025em;
  --btn-radius: 999px;

  /* Полосы не участвуют в смене темы: рамка окна остаётся тёмной всегда.
     Так рабочая область светлеет для чтения днём, а каркас остаётся
     узнаваемым — интерфейс не «мигает» целиком при переключении */
  --rail-bg: #11141b;
  --rail-ink: #eef1f6;
  --rail-muted: #a3acbf;
  --rail-line: #242a38;
  --rail-active: #1c2230;
  --rail-accent: #d8b26a;

  --radius: 14px;
  --rail-w: 216px;
  --top-h: 58px;
  --strip-h: 26px;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

[data-theme="light"] {
  /* Светлая — «Редакция» с главной: кремовая бумага, заголовки с засечками.
     Светлой становится только рабочая область, полосы остаются тёмными */
  color-scheme: light;
  --bg: #f5f2ec;
  --surface: #fbf9f4;
  --surface-2: #ece6da;
  --line: #ded8cc;
  --ink: #1b1f2a;
  --muted: #5c6274;
  --faint: #8a8f9d;
  --accent: #a8742c;
  --sale: #b84a2a;
  --accent-ink: #ffffff;
  --profit: #1d6e56;
  --loss: #9b3d20;
  --font-body: 'Golos Text', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-head: 'Literata', Georgia, 'Times New Roman', serif;
  --head-track: -.015em;
  --btn-radius: 10px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  font: 15.5px/1.6 var(--font-body);
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  padding-bottom: var(--strip-h);
}

/* ── Верхняя полоса ──────────────────────────────────────────────────── */
header {
  position: fixed; top: 0; left: 0; right: 0; height: var(--top-h);
  display: flex; align-items: center; gap: 8px; padding: 0 18px;
  background: var(--rail-bg); border-bottom: 1px solid var(--rail-line);
  color: var(--rail-ink); z-index: 10;
}
header .muted { color: var(--rail-muted); }
.grow { flex: 1; }
.brand {
  display: flex; align-items: center; gap: 9px;
  font: 700 17px/1 var(--font-head); letter-spacing: -.01em;
  background: none; border: 0; cursor: pointer; padding: 6px 8px; color: var(--rail-ink);
}
header .tool {
  background: none; border: 0; color: var(--rail-muted); font: inherit; font-size: 13px;
  padding: 6px 10px; border-radius: 8px; cursor: pointer;
}
header .tool:hover { color: var(--rail-ink); background: var(--rail-active); }
header .btn {
  background: var(--rail-active); border-color: var(--rail-line); color: var(--rail-ink);
}
header .btn.primary { background: var(--rail-accent); color: var(--rail-bg); border-color: var(--rail-accent); }

/* ── Левая полоса с меню ─────────────────────────────────────────────── */
#rail {
  position: fixed; top: var(--top-h); bottom: var(--strip-h); left: 0; width: var(--rail-w);
  background: var(--rail-bg); border-right: 1px solid var(--rail-line);
  padding: 14px 10px; overflow-y: auto;
}
#rail button {
  display: flex; align-items: center; gap: 10px; width: 100%;
  background: none; border: 0; font: inherit; color: var(--rail-muted);
  padding: 9px 12px; border-radius: 9px; cursor: pointer; text-align: left;
}
#rail button:hover { background: var(--rail-active); color: var(--rail-ink); }
#rail button.active {
  background: var(--rail-active); color: var(--rail-ink); font-weight: 600;
  box-shadow: inset 2px 0 0 var(--rail-accent);
}
#rail .group {
  font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.1em;
  color: var(--rail-muted); opacity: .65; padding: 18px 12px 6px;
}

main { margin: var(--top-h) 0 0 var(--rail-w); padding: 26px 30px 50px; max-width: 1060px; }

/* ── Нижняя полоса со слоганом ───────────────────────────────────────── */
#strip {
  position: fixed; left: 0; right: 0; bottom: 0; height: var(--strip-h);
  display: flex; align-items: center; justify-content: center; gap: 10px;
  background: var(--rail-bg); border-top: 1px solid var(--rail-line);
  font-size: 11px; letter-spacing: 0.14em; text-transform: uppercase;
  color: var(--rail-muted); z-index: 10;
}
#strip b { color: var(--rail-accent); font-weight: 600; }

/* ── Текст ───────────────────────────────────────────────────────────── */
/* Иерархия держится на двух шрифтах, а не на размере: заголовки экранов и
   разделов — шрифтом главной, всё внутри карточек — шрифтом текста, но
   жирным. Раньше всё было одним шрифтом разных размеров, и глаз не мог
   зацепиться: где раздел, где подпись, где число */
h1, h2 { font-family: var(--font-head); letter-spacing: var(--head-track); font-weight: 700; text-wrap: balance; }
h1 { font-size: 27px; line-height: 1.18; margin: 0 0 8px; }
h2 { font-size: 19px; line-height: 1.25; margin: 34px 0 12px; }
h3 { font-family: var(--font-body); font-size: 16px; line-height: 1.35; font-weight: 700; margin: 0 0 8px; letter-spacing: -.005em; }
.card h3 { font-size: 16.5px; }
p { margin: 6px 0; }
.muted { color: var(--muted); font-size: 14px; line-height: 1.55; }
h1 + .muted { font-size: 15.5px; max-width: 62ch; }
.card h3 + .muted { margin-top: -2px; }
b, strong { font-weight: 700; }
a { color: var(--accent); }

/* ── Карточки и вкладки ──────────────────────────────────────────────── */
.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 20px 22px; margin: 14px 0;
}
/* Окно кода подтверждения: поверх всего, по центру, затемнённый фон.
   Своё окно вместо window.prompt — системное глушат встроенные браузеры */
.code-shade {
  position: fixed; inset: 0; z-index: 1000;
  display: grid; place-items: center; padding: 16px;
  background: rgba(8, 10, 14, .62);
}
.code-box { width: min(420px, 100%); margin: 0; }
.code-box input { font-size: 20px; letter-spacing: .12em; text-align: center; }

/* Необратимое действие: карточка удаления аккаунта. Цвет — не украшение,
   а предупреждение, поэтому он единственный на экране */
.card.danger { border-color: color-mix(in srgb, var(--loss) 55%, var(--line)); }
.card.danger h3 { color: var(--loss); }

.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 14px; }

/* Вкладки не переносятся по словам, а уезжают вбок: «Мои курсы» в две
   строки на узком телефоне выглядит как сломанная вёрстка */
.tabs {
  display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin: 10px 0 18px;
  overflow-x: auto; scrollbar-width: none; -webkit-overflow-scrolling: touch;
}
.tabs::-webkit-scrollbar { display: none; }
.tabs button {
  background: none; border: 0; border-bottom: 2px solid transparent;
  color: var(--muted); font: inherit; padding: 9px 14px; cursor: pointer;
  white-space: nowrap; flex: 0 0 auto;
}
.tabs button:hover { color: var(--ink); }
.tabs button.active { color: var(--ink); border-bottom-color: var(--accent); font-weight: 600; }

/* ── Управление ──────────────────────────────────────────────────────── */
button, .btn {
  font: inherit; font-weight: 600; padding: 10px 17px; border-radius: var(--btn-radius); cursor: pointer;
  border: 1px solid var(--line); background: var(--surface-2); color: var(--ink);
  text-decoration: none; display: inline-block;
}
button:hover, .btn:hover { border-color: var(--muted); }
/* Ссылка-кнопка ведёт себя так же, как кнопка: на лендинге главный
   призыв — это ссылка, и он не должен выглядеть второстепенным */
button.primary, .btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 700; }
button.primary:hover, .btn.primary:hover { filter: brightness(1.06); }
/* Необратимое действие (удаление аккаунта) не красится в цвет «продолжить»:
   рука на телефоне идёт к золотой кнопке не глядя */
button.danger { background: var(--loss); color: #fff; border-color: var(--loss); font-weight: 700; }
button.danger:hover { filter: brightness(1.06); }
button.ghost { background: none; }
button:disabled { opacity: .4; cursor: default; }

input, textarea, select {
  font: inherit; padding: 11px 13px; width: 100%;
  border: 1px solid var(--line); border-radius: 10px;
  background: var(--bg); color: var(--ink);
}
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--accent); }
textarea { min-height: 120px; resize: vertical; }
label { display: block; margin: 14px 0 6px; font-size: 13.5px; font-weight: 600; color: var(--muted); }

.bar { height: 4px; background: var(--surface-2); border-radius: 2px; overflow: hidden; margin-top: 10px; }
.bar > i { display: block; height: 100%; background: var(--profit); }

.lesson {
  display: flex; gap: 12px; align-items: center; padding: 10px 0;
  border-bottom: 1px solid var(--line); cursor: pointer;
}
.lesson:last-child { border-bottom: 0; }
.lesson:hover:not(.locked) { color: var(--accent); }
.lesson .dot { width: 7px; height: 7px; border-radius: 50%; flex: none; background: var(--line); border: 1px solid var(--muted); }
.lesson.done .dot { background: var(--profit); border-color: var(--profit); }
.lesson.locked { color: var(--muted); cursor: default; }

.tag {
  font-size: 12px; font-weight: 600; padding: 3px 10px; border-radius: 20px;
  border: 1px solid var(--line); color: var(--muted); background: var(--surface-2);
  display: inline-block;
}
.tag.ok { color: var(--profit); border-color: color-mix(in srgb, var(--profit) 45%, var(--line)); }
.tag.warn { color: var(--loss); border-color: color-mix(in srgb, var(--loss) 45%, var(--line)); }

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th {
  color: var(--faint); font-weight: 700; font-size: 11.5px;
  text-transform: uppercase; letter-spacing: 0.07em; background: var(--surface-2);
}
tr:last-child td { border-bottom: 0; }
td.num, .num { font-family: var(--mono); font-variant-numeric: tabular-nums; text-align: right; }

pre, code { font-family: var(--mono); font-size: 12.5px; }
pre { background: var(--surface-2); border: 1px solid var(--line); border-radius: 9px; padding: 14px; overflow: auto; }
/* Учебный текст. Работы учеников и отзывы приходят простым текстом —
   им нужен pre-wrap; уроки проходят через rich() и приходят абзацами,
   списками и подзаголовками, поэтому у них свои отступы */
.content { white-space: pre-wrap; line-height: 1.7; }
.content p { margin: 0 0 13px; }
.content ul, .content ol { margin: 0 0 13px; padding-left: 22px; }
.content li { margin-bottom: 6px; }
.content h3 { margin: 20px 0 8px; font-size: 16.5px; }
.content > :first-child { margin-top: 0; }
.content > :last-child { margin-bottom: 0; }
.content code { font-size: .92em; padding: 1px 5px; border-radius: 5px; background: var(--surface-2); }

/* Закрытый раздел: видно, что впереди, но прочитать нельзя */
.blurred { filter: blur(5px); user-select: none; pointer-events: none; opacity: .65; }

.figure { margin: 14px 0; padding: 14px; }
.figure img { width: 100%; height: auto; display: block; border-radius: 9px; }
.figure figcaption { margin-top: 10px; font-size: 13px; }

ul { margin: 4px 0; padding-left: 20px; }
li { margin: 3px 0; }

#toast {
  position: fixed; left: 50%; bottom: calc(var(--strip-h) + 18px); transform: translateX(-50%);
  background: var(--surface-2); color: var(--ink); border: 1px solid var(--line);
  padding: 11px 18px; border-radius: 9px; font-size: 14px; max-width: 90vw; z-index: 20;
}
#toast.bad { border-color: var(--loss); color: var(--loss); }

.auth { max-width: 400px; margin: 6vh auto; }

/* ── Телефон: левая полоса уезжает под шапку строкой ─────────────────── */
@media (max-width: 860px) {
  #rail {
    position: static; width: auto; border-right: 0; border-bottom: 1px solid var(--rail-line);
    display: flex; gap: 4px; overflow-x: auto; padding: 8px 10px; margin-top: var(--top-h);
  }
  #rail button { width: auto; white-space: nowrap; padding: 7px 12px; }
  #rail .group { display: none; }
  main { margin: 0; padding: 18px 16px 40px; }
  h1 { font-size: 23px; }
  h2 { font-size: 17.5px; }
  th, td { padding: 8px 6px; font-size: 13px; }
}

/* ── Приложение на телефоне ──────────────────────────────────────────────
   На узком экране каркас меняется целиком, а не сжимается. Семнадцать
   пунктов в прокручиваемой строке под шапкой — это меню, которое
   невозможно запомнить и неудобно доставать большим пальцем. Внизу
   остаются четыре раздела, ради которых открывают телефон: урок, дневник
   перед сделкой, пятёрка, фон дня. Всё остальное — в «Ещё», той же
   группировкой, что в левой полосе на компьютере.

   Шапка на iPhone уходит под статус-бар (black-translucent), поэтому
   отступы считаются от безопасной зоны экрана. */
#tabbar, #more { display: none; }

@media (max-width: 860px) {
  body.cabinet { padding-bottom: 0; }
  .cabinet header {
    height: calc(var(--top-h) + env(safe-area-inset-top));
    padding: env(safe-area-inset-top) max(14px, env(safe-area-inset-right)) 0 max(14px, env(safe-area-inset-left));
  }
  .cabinet .brand span { white-space: nowrap; }
  /* Вторичное из шапки переехало в «Ещё»: на 390 точках ему не хватает места */
  .cabinet header .tool, .cabinet header #who { display: none; }
  .cabinet #rail, .cabinet #strip { display: none; }

  .cabinet main {
    margin: calc(var(--top-h) + env(safe-area-inset-top)) 0 0;
    padding: 18px max(16px, env(safe-area-inset-right)) calc(96px + env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  }
  /* Меньше 16px — и iPhone увеличивает страницу при каждом касании поля */
  .cabinet input, .cabinet textarea, .cabinet select { font-size: 16px; }
  .cabinet #toast { bottom: calc(76px + env(safe-area-inset-bottom)); }

  #tabbar {
    display: grid; grid-auto-flow: column; grid-auto-columns: 1fr;
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 15;
    padding: 6px max(6px, env(safe-area-inset-right)) calc(6px + env(safe-area-inset-bottom)) max(6px, env(safe-area-inset-left));
    background: var(--rail-bg); border-top: 1px solid var(--rail-line);
  }
  #tabbar button {
    display: flex; flex-direction: column; align-items: center; gap: 3px;
    background: none; border: 0; border-radius: 10px; padding: 6px 2px 4px;
    color: var(--rail-muted); font-size: 11px; line-height: 1.2; letter-spacing: 0.01em;
    -webkit-tap-highlight-color: transparent; min-width: 0;
  }
  #tabbar button span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  #tabbar svg { width: 24px; height: 24px; }
  /* Активный раздел — песочным, как активный пункт в полосе на компьютере */
  #tabbar button.active { color: var(--rail-accent); }
  #tabbar button:focus-visible { outline: 2px solid var(--rail-accent); outline-offset: -2px; }

  #more:not([hidden]) { display: block; position: fixed; inset: 0; z-index: 30; }
  #more .scrim { position: absolute; inset: 0; background: rgba(20, 22, 30, .55); }
  #more .sheet {
    position: absolute; left: 0; right: 0; bottom: 0; max-height: 86vh; max-height: 86dvh; overflow-y: auto;
    background: var(--rail-bg); color: var(--rail-ink);
    border-radius: 16px 16px 0 0; border-top: 1px solid var(--rail-line);
    padding: 8px max(12px, env(safe-area-inset-right)) calc(18px + env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
    overscroll-behavior: contain;
    animation: sheet-up .22s ease-out;
  }
  @keyframes sheet-up { from { transform: translateY(24px); opacity: .6; } to { transform: none; opacity: 1; } }
  #more .grip { width: 36px; height: 4px; border-radius: 2px; background: var(--rail-line); margin: 4px auto 10px; }
  #more .who { padding: 4px 12px 8px; color: var(--rail-muted); font-size: 13px; }
  #more .group { font-size: 12px; color: var(--rail-muted); padding: 14px 12px 4px; }
  #more .item {
    display: flex; align-items: center; justify-content: space-between; width: 100%;
    background: none; border: 0; border-radius: 10px; text-align: left;
    color: var(--rail-ink); font-size: 16px; padding: 11px 12px; min-height: 44px;
  }
  #more .item:active, #more .item.active { background: var(--rail-active); }
  #more .item.active { box-shadow: inset 2px 0 0 var(--rail-accent); }
  #more .item small { color: var(--rail-muted); font-size: 13px; }
  #more .item.quiet { color: var(--rail-muted); }
  #more .foot { padding: 14px 12px 0; color: var(--rail-muted); font-size: 12px; }
}
@media (max-width: 860px) and (prefers-reduced-motion: reduce) {
  #more .sheet { animation: none; }
}

/* ── Экран «Приложение и уведомления» ─────────────────────────────────── */
.install-steps { counter-reset: step; list-style: none; padding: 0; margin: 12px 0 4px; }
.install-steps li {
  counter-increment: step; position: relative; padding: 10px 0 10px 40px; margin: 0;
  border-bottom: 1px solid var(--line);
}
.install-steps li:last-child { border-bottom: 0; }
/* Шаги действительно идут по порядку — поэтому номера */
.install-steps li::before {
  content: counter(step); position: absolute; left: 0; top: 9px;
  width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center;
  font-size: 13px; font-weight: 600; background: var(--surface-2); border: 1px solid var(--line); color: var(--ink);
}
.install-steps .glyph { display: inline-block; vertical-align: -4px; width: 20px; height: 20px; color: var(--accent); }
.qr-box { background: #fff; padding: 10px; border-radius: 10px; display: inline-block; line-height: 0; }
.qr-box svg { width: 168px; height: 168px; }
.state-line { display: flex; gap: 10px; align-items: baseline; flex-wrap: wrap; }

/* «Назад»: отдельной строкой над содержимым, не липнет к заголовку */
button.back { margin-bottom: 12px; padding: 6px 12px; font-size: 14px; }

/* Широкая таблица листается внутри своей карточки: на телефоне колонки не
   помещаются, и без этого вся страница уезжает вбок */
.scroll-x { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.scroll-x table { min-width: 560px; }
@media (max-width: 700px) {
  /* На телефоне любая таблица в карточке листается сама, а не растягивает
     страницу: на широком экране это не нужно и только сузило бы таблицы */
  .card table { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; white-space: nowrap; }
}

/* Пройденный урок: галочка вместо точки. Серое «пройден» справа легко
   пропустить, а галочку слева видно, пробегая список глазами */
.lesson .check { width: 18px; text-align: center; color: var(--ok, #6fbf8a); font-weight: 700; margin-right: 8px; }

/* Недоступная главная кнопка не должна выглядеть как грязная главная:
   раньше «Закрыт» был песочным с прозрачностью и читался как «нажми» */
button.primary:disabled, .btn.primary[aria-disabled="true"] {
  background: transparent; color: var(--muted); border-color: var(--line); filter: none;
}
/* Значок темы в шапке */
header #theme { display: inline-flex; align-items: center; justify-content: center; padding: 7px 9px; }
/* Числа в сводках — моноширинные по ширине, чтобы колонки не прыгали */
.card h3 { font-variant-numeric: tabular-nums; }
/* Ссылки в тексте — без подчёркивания, пока не наведёшь: подчёркнутые
   ссылки посреди абзаца рябят сильнее самого текста */
.card a:not(.btn), .muted a:not(.btn) { text-decoration: none; border-bottom: 1px solid color-mix(in srgb, var(--accent) 40%, transparent); }
.card a:not(.btn):hover, .muted a:not(.btn):hover { border-bottom-color: var(--accent); }

/* ── Разделы с вкладками ─────────────────────────────────────────────────
   Строка вкладок раздела стоит над заголовком экрана: видно, где ты и что
   ещё есть рядом. На телефоне вкладки листаются вбок, а не переносятся */
.hub-tabs { margin: 0 0 18px; overflow-x: auto; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
.hub-tabs::-webkit-scrollbar { display: none; }
.hub-tabs button { white-space: nowrap; border-radius: 0; }

/* ── Левое меню в стиле главной ──────────────────────────────────────── */
#rail { padding: 16px 12px; }
#rail button { font-size: 14.5px; font-weight: 500; padding: 10px 12px; border-radius: 10px; }
#rail button.active { font-weight: 700; background: var(--rail-active); box-shadow: inset 3px 0 0 var(--rail-accent); }
#rail .group { padding: 22px 12px 8px; }
#rail .group:first-child { padding-top: 6px; }
