:root {
  --bg: #ffffff;
  --surface: #f4f5f7;
  --surface-2: #e9ebef;
  --text: #14171a;
  --muted: #6b7480;
  --line: #dde1e6;
  --accent: #2f6fed;
  --accent-text: #ffffff;
  --g1: #d64545;
  --g2: #c2802b;
  --g3: #2f8f4e;
  --g4: #2f6fed;
  --radius: 14px;
  --pad: 16px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111417;
    --surface: #191d21;
    --surface-2: #232830;
    --text: #e8eaed;
    --muted: #8b949e;
    --line: #2b3138;
    --accent: #4b86f5;
    --g1: #e06c6c;
    --g2: #d99b3f;
    --g3: #4dae6c;
    --g4: #4b86f5;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

/* hidden живёт в UA-стилях со слабой специфичностью, и любой наш display
   его перебивает. Без этого правила оборот карточки виден всегда. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  overscroll-behavior-y: contain;
}

#app {
  max-width: 640px;
  margin: 0 auto;
  padding: max(12px, env(safe-area-inset-top)) var(--pad)
           calc(24px + env(safe-area-inset-bottom));
  min-height: 100dvh;
}

.screen { display: flex; flex-direction: column; gap: 14px; }
.screen[hidden] { display: none; }

h1 { font-size: 20px; margin: 0; font-weight: 650; }
h2 { font-size: 15px; margin: 16px 0 0; font-weight: 650; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
p { margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 13px; line-height: 1.45; }
.center { text-align: center; }

.bar { display: flex; align-items: center; gap: 10px; min-height: 40px; }
.bar h1 { flex: 1; }

button, .file { font: inherit; cursor: pointer; }

button.icon {
  background: none; border: 0; color: var(--muted);
  font-size: 24px; line-height: 1; padding: 6px 10px; border-radius: 10px;
}
button.icon:active { background: var(--surface-2); }

.primary {
  background: var(--accent); color: var(--accent-text);
  border: 0; border-radius: var(--radius); padding: 14px; font-weight: 600;
}
.primary.big { font-size: 17px; padding: 17px; }
.primary:disabled { opacity: .4; }

.ghost, .file {
  display: block; width: 100%; text-align: center;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--line); border-radius: var(--radius); padding: 13px;
}
.ghost.danger { color: var(--g1); }
.ghost:active, .file:active { background: var(--surface-2); }

/* ───────────────────────────────── главная */

.counts { display: flex; gap: 10px; }
.count {
  flex: 1; background: var(--surface); border-radius: var(--radius);
  padding: 14px 8px; text-align: center;
}
.count b { display: block; font-size: 30px; font-weight: 650; line-height: 1.1; }
.count span { font-size: 12px; color: var(--muted); }

.topics { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 8px; }
.topics button {
  background: var(--surface); border: 1px solid var(--line); color: var(--text);
  border-radius: 999px; padding: 8px 14px; font-size: 14px;
}
.topics button[aria-pressed="true"] {
  background: var(--accent); border-color: var(--accent); color: var(--accent-text);
}
.topics .n { opacity: .6; margin-inline-start: 6px; font-variant-numeric: tabular-nums; }

.picklist { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.picklist button {
  width: 100%; text-align: left; background: var(--surface);
  border: 1px solid var(--line); color: var(--text);
  border-radius: var(--radius); padding: 12px 14px;
}
.picklist button[aria-pressed="true"] { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.picklist b { display: block; font-size: 15px; font-weight: 600; }
.picklist i { display: block; font-size: 13px; font-style: normal; color: var(--muted); margin-top: 2px; }
.picklist button[aria-pressed="true"] b { color: var(--accent); }

.tabs { display: flex; gap: 10px; margin-top: 8px; }
.tabs button {
  flex: 1; background: var(--surface); border: 1px solid var(--line);
  color: var(--text); border-radius: var(--radius); padding: 13px;
}
.badge {
  background: var(--accent); color: var(--accent-text);
  border-radius: 999px; padding: 1px 7px; font-size: 12px; margin-inline-start: 6px;
}

/* ───────────────────────────────── карточка */

.progress { flex: 1; height: 4px; background: var(--surface-2); border-radius: 2px; overflow: hidden; }
.progress i { display: block; height: 100%; background: var(--accent); width: 0; transition: width .25s; }

.card {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 18px; text-align: center; padding: 24px 8px; min-height: 46dvh;
}
.kind { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; }

.face { display: flex; flex-direction: column; align-items: center; gap: 10px; width: 100%; }
.back { border-top: 1px solid var(--line); padding-top: 18px; }

.he {
  font-size: 46px; line-height: 1.35; font-weight: 500;
  direction: rtl; unicode-bidi: isolate;
  font-family: "Arial Hebrew", Arial, "Noto Sans Hebrew", "Segoe UI", "Alef", system-ui, sans-serif;
}
.he.sm { font-size: 26px; }
.ru { font-size: 30px; font-weight: 500; }
.tr { font-size: 19px; color: var(--muted); }
.gram { font-size: 14px; color: var(--muted); }
.gram b { color: var(--text); font-weight: 600; }

/* Оборот делится надвое: сперва ответ на заданный вопрос, ниже — словарная
   статья того слова, к которому ответ относится. Разделитель нужен затем же,
   зачем блоки разведены: понять, угадал или нет, надо раньше, чем начнёшь
   читать статью. */
.answer, .entry { display: flex; flex-direction: column; align-items: center; gap: 10px; width: 100%; }
.entry { margin-top: 18px; padding-top: 18px; border-top: 1px dashed var(--line); }

/* Одно прочтение формы. Их бывает несколько: без огласовок כתבת — это и
   катавта́, и ката́вт, и обе строки одинаково правильные. */
.ans {
  width: 100%; background: var(--surface); border-radius: var(--radius);
  padding: 10px 14px; display: flex; flex-direction: column; align-items: center; gap: 2px;
}
.ans .he { font-size: 32px; display: flex; align-items: baseline; gap: 10px; justify-content: center; }
.ans .pron { font-size: 18px; color: var(--muted); }
.ans .tr { font-size: 17px; }
.ans .slot { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }

/* Заголовок статьи на карточке формы: спрошено было כתבת, а статья — про
   לכתוב, и связь между ними должна читаться сразу. */
.entry .lex { display: flex; align-items: baseline; gap: 10px; justify-content: center; }
.entry .lex .he { font-size: 26px; }
.entry .lex .tr { font-size: 15px; }


/* ─────────── справочные блоки на обороте карточки ─────────── */

.forms {
  width: 100%; background: var(--surface); border-radius: var(--radius);
  padding: 10px 14px;
  display: grid; grid-template-columns: max-content max-content 1fr;
  align-items: baseline; column-gap: 10px; row-gap: 6px;
}
/* Строка раскрывается в три ячейки общей сетки таблицы, а не верстается
   сама по себе. Колонки подписи и транслитерации получают ширину самой
   длинной из них, поэтому начинаются с одной вертикали во всех строках —
   и когда подпись «м. ед.», и когда «сопряжённая». */
.forms > .row { display: contents; }
.forms > .grp {
  grid-column: 1 / -1;
  font-size: 11px; font-weight: 600; color: var(--muted);
  text-transform: uppercase; letter-spacing: .06em; margin-top: 8px;
  border-bottom: 1px solid var(--line); padding-bottom: 3px;
}
.forms > .grp:first-child { margin-top: 0; }
.forms .lbl { font-size: 11px; color: var(--muted); white-space: nowrap; }
.forms .tr { font-size: 14px; color: var(--muted); white-space: nowrap; }
/* Местоимение — колонка постоянной ширины у правого края; глагол примыкает
   к ней слева, поэтому во всех строках формы выровнены по одной вертикали. */
.forms .pair { display: flex; align-items: baseline; gap: 10px; direction: rtl; justify-content: flex-start; }
.forms .pron { flex: 0 0 56px; text-align: right; font-size: 15px; color: var(--muted); white-space: nowrap; }
.forms .he { font-size: 21px; white-space: nowrap; }
/* Спрошенная строка в раскрытой таблице. Красим ячейки, а не строку: сама
   .row — display: contents, своего прямоугольника у неё нет. */
.forms > .row.asked .lbl, .forms > .row.asked .tr { color: var(--accent); }
.forms > .row.asked .he { color: var(--accent); font-weight: 600; }

.example {
  width: 100%; background: var(--surface); border-radius: var(--radius);
  padding: 10px 14px; display: flex; flex-direction: column; gap: 7px;
}
.example > div { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.example .he { font-size: 19px; order: 2; }
.example .ru { font-size: 13px; color: var(--muted); order: 1; }

.gov, .conf { width: 100%; text-align: left; }
.gov > div, .conf > div { padding: 8px 0; border-bottom: 1px solid var(--line); }
.gov > div:last-child, .conf > div:last-child { border-bottom: 0; }
.gov .top, .conf .top { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.gov .prep { font-size: 19px; }
.gov .lab { font-size: 13px; color: var(--muted); }
.gov .ex { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; margin-top: 3px; }
.gov .ex .he { font-size: 18px; order: 2; }
.gov .ex .ru { font-size: 13px; color: var(--muted); order: 1; }
.conf .top .he { font-size: 20px; order: 2; }
.conf .top .tr { font-size: 14px; color: var(--muted); order: 1; }
.conf .ru { font-size: 14px; margin-top: 2px; }
.conf .note { font-size: 13px; color: var(--muted); margin-top: 2px; }

.pos { width: 100%; text-align: left; }
.pos > div { padding: 8px 0; border-bottom: 1px solid var(--line); }
.pos > div:last-child { border-bottom: 0; }
.pos .ru { font-size: 13px; color: var(--muted); }
.pos .line { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; margin-top: 3px; }
.pos .mark { font-size: 14px; }
.pos .he { font-size: 18px; }
.pos .ok .mark { color: var(--g3); }
.pos .bad .mark { color: var(--g1); }
.pos .bad .he { opacity: .55; text-decoration: line-through; }

/* ─────────── раскрывающиеся блоки ─────────── */

.fold { width: 100%; text-align: left; }
.fold summary {
  cursor: pointer; list-style: none; padding: 11px 14px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); font-size: 14px; color: var(--muted);
}
.fold summary::-webkit-details-marker { display: none; }
.fold summary::after { content: " ▾"; }
.fold[open] summary { border-radius: var(--radius) var(--radius) 0 0; }
.fold[open] summary::after { content: " ▴"; }
.fold h3 {
  font-size: 12px; font-weight: 600; color: var(--muted);
  text-transform: uppercase; letter-spacing: .06em; margin: 14px 0 6px;
}
.fold h3:first-of-type { margin-top: 10px; }
/* Внутри раскрытого блока подложка уже есть у самого блока — вложенная
   вторая делала бы «карточку в карточке». Область видимости обязательна:
   без неё правило гасит фон у таблицы настоящего времени, которая стоит
   на обороте сама по себе. */
.fold .forms, .fold .example { background: none; padding: 0; }
.fold p { margin-top: 6px; }



#controls { display: flex; flex-direction: column; gap: 10px; }
.grades { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.grade {
  background: var(--surface); border: 1px solid var(--line); color: var(--text);
  border-radius: var(--radius); padding: 12px 4px;
  display: flex; flex-direction: column; gap: 3px; align-items: center;
}
.grade b { font-size: 14px; font-weight: 600; }
.grade span { font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }
.grade:active { background: var(--surface-2); }
.g1 b { color: var(--g1); } .g2 b { color: var(--g2); }
.g3 b { color: var(--g3); } .g4 b { color: var(--g4); }

/* ───────────────────────────────── инбокс, статистика, настройки */

/* Экран входа. Он показывается до того, как загружена колода, поэтому не
   зависит ни от чего, кроме собственной разметки. */
.login {
  min-height: 70dvh; display: flex; flex-direction: column; justify-content: center;
  gap: 14px; max-width: 380px; margin: 0 auto; width: 100%;
}
.login h1 { text-align: center; margin: 0 0 6px; }
.error { color: var(--g1); }
.error:empty { display: none; }

.inbox-form { display: flex; flex-direction: column; gap: 8px; }
.inbox-form input {
  font: inherit; padding: 13px 14px; background: var(--surface); color: var(--text);
  border: 1px solid var(--line); border-radius: var(--radius);
}
.inbox-list, .leeches { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.inbox-list li, .leeches li {
  background: var(--surface); border-radius: var(--radius); padding: 12px 14px;
  display: flex; align-items: center; gap: 12px;
}
.inbox-list .t { flex: 1; font-size: 17px; }
.inbox-list .n { display: block; font-size: 13px; color: var(--muted); }
.inbox-list button { background: none; border: 0; color: var(--muted); font-size: 20px; padding: 4px 8px; }

.forecast { display: flex; align-items: flex-end; gap: 4px; height: 90px; }
.forecast div { flex: 1; background: var(--accent); border-radius: 3px 3px 0 0; min-height: 2px; position: relative; }
.forecast div span {
  position: absolute; bottom: -18px; left: 0; right: 0;
  font-size: 10px; color: var(--muted); text-align: center;
}
.stat-row { display: flex; justify-content: space-between; padding: 11px 0; border-bottom: 1px solid var(--line); }
.stat-row b { font-variant-numeric: tabular-nums; }

.row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  background: var(--surface); border-radius: var(--radius); padding: 12px 14px;
}
.row input[type="number"] {
  width: 84px; font: inherit; text-align: center; padding: 7px;
  background: var(--bg); color: var(--text); border: 1px solid var(--line); border-radius: 9px;
}
.row input[type="checkbox"] { width: 22px; height: 22px; accent-color: var(--accent); }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(24px + env(safe-area-inset-bottom));
  background: var(--text); color: var(--bg);
  padding: 11px 18px; border-radius: 999px; font-size: 14px;
  z-index: 10; max-width: 90vw; text-align: center;
}
