/* Бумага, тушь и киноварь. Цвета тонов — схема MDBG: 1 красный, 2 оранжевый, 3 зелёный, 4 синий. */
:root {
  --bg: #f7f3ec;
  --surface: #fffdf9;
  --ink: #1d1a16;
  --muted: #6f675d;
  --line: #e6ddd0;
  --accent: #b3261e;
  --accent-ink: #ffffff;
  --t1: #d0342c;
  --t2: #d97a00;
  --t3: #2f8a3a;
  --t4: #1f5fbf;
  --t5: #8b8378;
  --lvl-new: #ebe4d8;
  --lvl-learning: #f1c453;
  --lvl-young: #a5d39a;
  --lvl-mature: #3e8e4e;
  --lvl-mature-ink: #ffffff;
  --radius: 14px;
  --hanzi-font: "PingFang SC", "Hiragino Sans GB", "Noto Sans CJK SC", "Noto Sans SC", "Source Han Sans SC",
    "Microsoft YaHei", sans-serif;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15120f;
    --surface: #1f1b17;
    --ink: #f2ece3;
    --muted: #a39a8e;
    --line: #342e27;
    --accent: #e0574e;
    --accent-ink: #1a0f0d;
    --t1: #ff6b61;
    --t2: #ffad3b;
    --t3: #62c46f;
    --t4: #72a8ff;
    --t5: #9a9187;
    --lvl-new: #2a251f;
    --lvl-learning: #8c6d1c;
    --lvl-young: #3d6c3a;
    --lvl-mature: #5fb46c;
    --lvl-mature-ink: #10210f;
  }
}

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

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

button { font: inherit; color: inherit; }

.app {
  max-width: 560px;
  margin: 0 auto;
  padding: calc(12px + env(safe-area-inset-top)) 16px calc(92px + env(safe-area-inset-bottom));
}

.muted { color: var(--muted); }
.small { font-size: 14px; }

.t1 { color: var(--t1); }
.t2 { color: var(--t2); }
.t3 { color: var(--t3); }
.t4 { color: var(--t4); }
.t5 { color: var(--t5); }

/* Верхняя строка */
.bar { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 40px; }
.bar__title { font-family: var(--hanzi-font); font-size: 22px; font-weight: 600; color: var(--accent); }
.bar__counts { display: flex; gap: 6px; }
.bar__link { color: var(--muted); font-size: 14px; }
.pill {
  font-size: 13px; padding: 3px 10px; border-radius: 999px;
  background: var(--surface); border: 1px solid var(--line); color: var(--muted);
}
.pill--new { color: var(--accent); }

/* Кнопки */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 0 20px; border-radius: var(--radius);
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  text-decoration: none; font-weight: 600; cursor: pointer;
}
.btn--primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn--wide { width: 100%; }

/* Сцена занятия */
.stage { padding-top: 8px; }
.stage--center {
  min-height: calc(100vh - 200px); min-height: calc(100dvh - 200px);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16px; text-align: center;
}
.label { margin: 8px 0 4px; font-size: 14px; color: var(--muted); }
.label__new { color: var(--accent); font-weight: 600; }
.actions { margin-top: 24px; width: 100%; }

.question { display: flex; flex-direction: column; align-items: center; gap: 12px; }
.question__hanzi { font-family: var(--hanzi-font); line-height: 1.1; font-size: clamp(96px, 34vw, 180px); }
.question__hanzi--2 { font-size: clamp(80px, 26vw, 150px); }
.question__hanzi--3 { font-size: clamp(64px, 20vw, 120px); }

.listen {
  width: 140px; height: 140px; border-radius: 50%; border: none; cursor: pointer;
  background: var(--accent); color: var(--accent-ink); display: grid; place-items: center;
}
.listen svg { width: 64px; height: 64px; fill: currentColor; }

/* Оборот карточки */
.word__head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.word__hanzi { font-family: var(--hanzi-font); line-height: 1.15; font-size: 88px; }
.word__hanzi--2 { font-size: 76px; }
.word__hanzi--3 { font-size: 60px; }
.sound {
  flex: none; width: 52px; height: 52px; border-radius: 50%; cursor: pointer;
  border: 1px solid var(--line); background: var(--surface); display: grid; place-items: center;
}
.sound svg { width: 26px; height: 26px; fill: var(--accent); }
.word__pinyin { font-size: 26px; font-weight: 600; display: flex; gap: 8px; flex-wrap: wrap; }
.word__spoken { font-size: 15px; color: var(--muted); display: flex; gap: 6px; align-items: baseline; }
.word__spoken span { font-weight: 600; }
.word__meaning { font-size: 22px; margin-top: 8px; }
.word__note { margin: 8px 0 0; color: var(--muted); font-size: 15px; }

.example {
  display: block; width: 100%; text-align: left; margin-top: 16px; padding: 12px 14px; cursor: pointer;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
}
.example__zh { display: block; font-family: var(--hanzi-font); font-size: 24px; line-height: 2; }
.example__zh rt { font-family: system-ui, sans-serif; font-size: 11px; }
.example__ru { display: block; color: var(--muted); font-size: 15px; }

.chars { margin-top: 16px; display: grid; gap: 10px; }
.char { padding: 12px 14px; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--line); }
.char__head { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.char__glyph { font-family: var(--hanzi-font); font-size: 34px; line-height: 1; }
.char__pinyin { font-weight: 600; }
.badge {
  margin-left: auto; font-size: 12px; padding: 2px 8px; border-radius: 999px;
  background: var(--accent); color: var(--accent-ink);
}
.char__parts { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.part {
  display: inline-flex; align-items: baseline; gap: 6px; padding: 3px 10px; border-radius: 999px;
  border: 1px solid var(--line); font-size: 14px;
}
.part b { font-family: var(--hanzi-font); font-size: 18px; font-weight: 500; }
.part em { font-style: normal; color: var(--accent); font-size: 12px; }
.part--sound { border-color: var(--accent); }
.char__hint { margin: 8px 0 0; font-size: 14px; color: var(--muted); }
.char__used { margin: 6px 0 0; font-size: 14px; color: var(--muted); }
.char__list { font-family: var(--hanzi-font); font-size: 18px; color: var(--ink); letter-spacing: 4px; }

/* Оценка */
.rate {
  position: sticky; bottom: calc(76px + env(safe-area-inset-bottom)); margin-top: 20px;
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; padding: 8px 0; background: var(--bg);
}
.rate__btn {
  display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 10px 4px; cursor: pointer;
  border-radius: var(--radius); border: 1px solid var(--line); background: var(--surface); font-weight: 600;
  border-top: 4px solid var(--line);
}
.rate__btn small { font-weight: 400; color: var(--muted); font-size: 12px; }
.rate__btn--1 { border-top-color: var(--t1); }
.rate__btn--2 { border-top-color: var(--t2); }
.rate__btn--3 { border-top-color: var(--t3); }
.rate__btn--4 { border-top-color: var(--t4); }

/* Итог дня */
.done__glyph { font-family: var(--hanzi-font); font-size: 96px; color: var(--accent); line-height: 1; }
.done__title { margin: 0; font-size: 24px; }

/* Прогресс */
.summary { margin-top: 8px; padding: 16px; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--line); }
.summary__main { display: flex; align-items: baseline; gap: 8px; }
.summary__value { font-size: 40px; font-weight: 700; line-height: 1; }
.summary__of { color: var(--muted); }
.meter { display: flex; height: 10px; border-radius: 999px; overflow: hidden; margin: 12px 0; gap: 2px; }
.meter__part { flex-basis: 0; min-width: 0; }
.summary__stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.summary__stats div { display: flex; flex-direction: column; }
.summary__stats b { font-size: 22px; }
.summary__stats span { font-size: 13px; color: var(--muted); line-height: 1.25; }

.settings { margin-top: 12px; }
.settings__row { display: flex; align-items: center; justify-content: space-between; gap: 12px; font-weight: 600; }
.settings select {
  font: inherit; padding: 8px 12px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--surface); color: var(--ink);
}

.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; margin: 16px 0 4px; font-size: 13px; color: var(--muted); }
.legend__item { display: inline-flex; align-items: center; gap: 6px; }
.legend__dot { width: 14px; height: 14px; border-radius: 4px; display: inline-block; }
.legend__ear { width: 8px; height: 8px; border-radius: 50%; display: inline-block; background: var(--ink); }

.lesson__title { font-size: 16px; margin: 18px 0 8px; }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(64px, 1fr)); gap: 6px; }
.tile {
  position: relative; min-height: 58px; padding: 6px 2px; border: none; border-radius: 10px; cursor: pointer;
  display: grid; place-items: center;
}
.tile__hanzi { font-family: var(--hanzi-font); font-size: 20px; line-height: 1.1; }
.tile__ear { position: absolute; top: 5px; right: 5px; width: 9px; height: 9px; border-radius: 50%; outline: 2px solid var(--surface); }
/* Точка «на слух» темнее плитки, иначе на зелёном зелёная точка теряется */
.tile__ear.lvl-learning { background: var(--t2); }
.tile__ear.lvl-young { background: var(--t3); }
.tile__ear.lvl-mature { background: var(--ink); }

.lvl-new { background: var(--lvl-new); }
.lvl-learning { background: var(--lvl-learning); }
.lvl-young { background: var(--lvl-young); }
.lvl-mature { background: var(--lvl-mature); color: var(--lvl-mature-ink); }
.legend__dot.lvl-new, .tile.lvl-new { border: 1px solid var(--line); }

.sheet {
  position: fixed; inset: 0; z-index: 20; background: rgb(0 0 0 / 0.45);
  display: flex; align-items: flex-end; justify-content: center;
}
.sheet__body {
  position: relative; width: 100%; max-width: 560px; max-height: 88vh; overflow-y: auto;
  background: var(--bg); border-radius: 20px 20px 0 0;
  padding: 20px 16px calc(24px + env(safe-area-inset-bottom));
}
.sheet__close {
  position: absolute; top: 8px; right: 12px; width: 40px; height: 40px; border: none; background: none;
  font-size: 30px; color: var(--muted); cursor: pointer;
}

/* Нижняя навигация */
.nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; display: flex; justify-content: center; gap: 8px;
  padding: 8px 16px calc(8px + env(safe-area-inset-bottom));
  background: var(--surface); border-top: 1px solid var(--line);
}
.nav__item {
  flex: 1; max-width: 200px; display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 6px 0; border-radius: 12px; color: var(--muted); text-decoration: none; font-size: 13px;
}
.nav__glyph { font-family: var(--hanzi-font); font-size: 22px; line-height: 1.1; }
.nav__item--active { color: var(--accent); }

/* Вход */
.app--login { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding-bottom: 16px; }
.login { width: 100%; max-width: 360px; text-align: center; }
.login__glyph { font-family: var(--hanzi-font); font-size: 72px; color: var(--accent); line-height: 1.1; }
.login__title { margin: 4px 0 24px; font-size: 22px; }
.login__form { display: grid; gap: 14px; text-align: left; }
.login__form label { display: grid; gap: 6px; font-weight: 600; font-size: 14px; }
.login__form input {
  font: inherit; min-height: 48px; padding: 0 14px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
}
.login__error { margin: 0; color: var(--t1); }
