/* sundiary — базовые токены и компоненты.
   Светлая тема — источник истины; тёмная переопределяет только цвета.

   Какая из них включена, решает не медиазапрос, а атрибут data-theme: человек
   может выбрать тему в настройках, а не только унаследовать системную. Атрибут
   ставит скрипт в <head> ещё до первой отрисовки, поэтому второго — «системного» —
   списка тёмных токенов здесь нет: он бы неизбежно разошёлся с этим. */

:root {

  --bg: #fbf7f0;
  --bg-veil: rgba(251, 247, 240, 0.82);
  --surface: #ffffff;
  --surface-2: #f4ede1;
  --surface-3: #ece2d2;
  --text: #2a2520;
  --text-dim: #7c7063;
  --text-faint: #a89c8c;
  --line: #e7dccb;
  --line-strong: #d8cab3;
  --muted-line: #d9cfc0;

  --accent: #e8930f;
  --accent-ink: #8a5400;
  --accent-soft: rgba(232, 147, 15, 0.12);
  --accent-soft-2: rgba(232, 147, 15, 0.22);
  --sun: #f5b02a;
  --sun-empty: #ddd0bc;

  --good: #3f9a6b;
  --bad: #c9603f;

  /* Графики. Пара «настроение / погода» проверена валидатором на белой поверхности:
     разделение по CVD ΔE 22.5, контраст к фону выше 3:1. */
  --series-mood: #c47f0a;
  --series-weather: #3f6fa8;
  --chart-grid: #e7dccb;
  --chart-ink: #7c7063;

  /* Расходящаяся шкала настроения: холодный полюс — нейтральная середина — тёплый полюс.
     Светлота нарастает к середине и падает к обоим краям, как и положено diverging-шкале. */
  --mood-1: #35608f;
  --mood-2: #5f89b9;
  --mood-3: #9db2c4;
  --mood-4: #cfbb96;
  --mood-5: #d99a2e;
  --mood-6: #b0740a;

  --shadow-1: 0 1px 2px rgba(58, 45, 25, 0.05), 0 2px 8px rgba(58, 45, 25, 0.04);
  --shadow-2: 0 2px 6px rgba(58, 45, 25, 0.07), 0 12px 28px rgba(58, 45, 25, 0.08);

  --r-sm: 10px;
  --r-md: 16px;
  --r-lg: 22px;
  --r-pill: 999px;

  --pad: 16px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --tabbar-h: 62px;

  --font: 'Nunito', -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Segoe UI', system-ui, sans-serif;
}

:root[data-theme='dark'] {
  --bg: #15130f;
  --bg-veil: rgba(21, 19, 15, 0.82);
  --surface: #1f1c17;
  --surface-2: #272219;
  --surface-3: #322b20;
  --text: #f3eee4;
  --text-dim: #a4998a;
  --text-faint: #7d7365;
  --line: #302a21;
  --line-strong: #453c2e;
  --muted-line: #3b3428;

  --accent: #ffb43c;
  --accent-ink: #ffd08f;
  --accent-soft: rgba(255, 180, 60, 0.14);
  --accent-soft-2: rgba(255, 180, 60, 0.26);
  --sun: #ffbf4d;
  --sun-empty: #4a4133;

  --good: #5cbb8a;
  --bad: #e0805e;

  /* Тёмная тема — не автоматическая инверсия: пара пересчитана и проверена
     валидатором отдельно, на тёмной поверхности #1f1c17. */
  --series-mood: #c1821a;
  --series-weather: #4478b8;
  --chart-grid: #302a21;
  --chart-ink: #a4998a;

  --mood-1: #5f9ada;
  --mood-2: #4d7cb4;
  --mood-3: #6f7a85;
  --mood-4: #857b66;
  --mood-5: #c1821a;
  --mood-6: #f0ac33;

  --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-2: 0 2px 8px rgba(0, 0, 0, 0.45), 0 16px 32px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overscroll-behavior-y: none;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.45;
  -webkit-text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

button, input, textarea, select {
  font: inherit;
  color: inherit;
  font-size: 16px; /* меньше 16px — и Safari зумит страницу при фокусе */
}

button { cursor: pointer; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

h1, h2, h3 { margin: 0; font-weight: 700; letter-spacing: -0.01em; }

/* --- каркас --------------------------------------------------------------- */

#app {
  min-height: 100%;
  display: flex;
  flex-direction: column;
}

.screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding-bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 8px);
}

.screen-body {
  padding: 0 var(--pad) 24px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  padding: calc(var(--safe-top) + 12px) var(--pad) 12px;
  background: var(--bg-veil);
  backdrop-filter: saturate(180%) blur(14px);
  -webkit-backdrop-filter: saturate(180%) blur(14px);
  border-bottom: 1px solid transparent;
  transition: border-color var(--dur) var(--ease-out);
}

.topbar.is-scrolled { border-bottom-color: var(--line); }

.topbar-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.topbar h1 { font-size: 22px; }

.topbar-sub {
  color: var(--text-dim);
  font-size: 13px;
  margin-top: 2px;
}

.icon-btn {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border: none;
  border-radius: var(--r-pill);
  background: var(--surface);
  box-shadow: var(--shadow-1);
  font-size: 17px;
  line-height: 1;
}

.icon-btn:active { transform: scale(0.92); }

/* --- баланс и серия ------------------------------------------------------- */

.stat-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 13px 7px 10px;
  border: none;
  border-radius: var(--r-pill);
  background: var(--surface);
  box-shadow: var(--shadow-1);
  font-weight: 700;
  font-size: 15px;
  white-space: nowrap;
}

.stat-chip .glyph { font-size: 16px; }

/* --- таб-бар -------------------------------------------------------------- */

.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 30;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  padding: 6px 6px calc(var(--safe-bottom) + 6px);
  background: var(--bg-veil);
  backdrop-filter: saturate(180%) blur(16px);
  -webkit-backdrop-filter: saturate(180%) blur(16px);
  border-top: 1px solid var(--line);
}

.tab {
  border: none;
  background: none;
  padding: 6px 2px;
  display: grid;
  justify-items: center;
  gap: 2px;
  color: var(--text-faint);
  font-size: 11px;
  font-weight: 700;
  border-radius: var(--r-md);
}

.tab-icon-wrap {
  position: relative;
  display: block;
  width: 24px;
  height: 24px;
}

.tab .tab-icon {
  width: 24px;
  height: 24px;
  display: block;
}

.tab[aria-current='page'] { color: var(--accent-ink); }
.tab[aria-current='page'] .tab-icon { stroke-width: 2; }

.tab .tab-dot {
  position: absolute;
  top: -1px;
  right: -3px;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 2px var(--bg);
}

/* --- карточки и типовые блоки --------------------------------------------- */

.card {
  background: var(--surface);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-1);
  padding: 16px;
}

.section-title {
  font-size: 15px;
  font-weight: 800;
  letter-spacing: -0.01em;
}

.section-note {
  font-size: 13px;
  color: var(--text-dim);
  margin-top: 2px;
}

.hint {
  font-size: 12px;
  color: var(--text-faint);
}

.empty {
  text-align: center;
  padding: 28px 18px;
  color: var(--text-dim);
  display: grid;
  gap: 12px;
  justify-items: center;
}

.empty .empty-glyph { font-size: 34px; }
.empty p { margin: 0; font-size: 14px; max-width: 34ch; }

/* --- кнопки --------------------------------------------------------------- */

.btn {
  border: none;
  border-radius: var(--r-pill);
  padding: 12px 18px;
  font-weight: 800;
  font-size: 15px;
  background: var(--surface-2);
  color: var(--text);
}

.btn:active { transform: scale(0.97); }

.btn-primary {
  background: var(--accent);
  color: #241703;
}

.btn-ghost {
  background: transparent;
  color: var(--accent-ink);
  box-shadow: inset 0 0 0 1.5px var(--line-strong);
}

.btn[disabled] {
  opacity: 0.45;
  cursor: default;
  transform: none;
}

.btn-block { width: 100%; }

.btn-row { display: flex; gap: 10px; flex-wrap: wrap; }

/* --- поля ----------------------------------------------------------------- */

.input, .textarea {
  width: 100%;
  border: 1.5px solid var(--line);
  background: var(--surface);
  border-radius: var(--r-md);
  padding: 12px 14px;
  transition: border-color var(--dur-fast) var(--ease-out);
}

.textarea {
  min-height: 130px;
  resize: none;
  line-height: 1.55;
}

.input:focus, .textarea:focus {
  outline: none;
  border-color: var(--accent);
}

.input[disabled], .textarea[disabled] {
  background: var(--surface-2);
  color: var(--text-dim);
  border-style: dashed;
}

/* Строка тега тесная: значок, название и три кнопки должны поместиться в ширину
   телефона, иначе поле названия сжимается до неразличимых «Тренировк». */
.tag-row { gap: 6px; }

.tag-row .input { padding-left: 10px; padding-right: 10px; }

.tag-row .icon-btn {
  width: 32px;
  height: 32px;
  font-size: 15px;
  background: var(--surface-2);
  box-shadow: none;
}

.tag-emoji {
  width: 50px;
  flex: none;
  text-align: center;
  padding-left: 4px;
  padding-right: 4px;
}

/* Подпись автора — единственное место, где используется рукописный шрифт. */
.signature {
  font-family: 'Caveat', cursive;
  font-size: 22px;
  text-align: center;
  color: var(--text-faint);
  padding: 8px 0 4px;
  user-select: none;
}

.field { display: grid; gap: 6px; }
.field-label { font-size: 13px; font-weight: 700; color: var(--text-dim); }

/* --- сегментированный переключатель --------------------------------------- */

.segmented {
  display: inline-flex;
  padding: 3px;
  gap: 3px;
  background: var(--surface-2);
  border-radius: var(--r-pill);
  width: 100%;
}

.segmented button {
  flex: 1;
  border: none;
  background: transparent;
  border-radius: var(--r-pill);
  padding: 8px 6px;
  font-size: 13px;
  font-weight: 700;
  color: var(--text-dim);
}

.segmented button[aria-pressed='true'] {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-1);
}

/* --- лента дней ----------------------------------------------------------- */

.month-head {
  position: sticky;
  /* Высоту шапки подставляет renderScreen: она разная на разных экранах. */
  top: var(--topbar-h, calc(var(--safe-top) + 62px));
  z-index: 10;
  padding: 10px 0 6px;
  /* Подложка непрозрачная: сквозь полупрозрачную было видно карточку дня,
     проезжающую под названием месяца, и две надписи наезжали друг на друга.
     Мягкий край вынесен в ::after — он гасит стык, ничего не открывая. */
  background: var(--bg);
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-faint);
}

.month-head::after {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  top: 100%;
  height: 10px;
  background: linear-gradient(var(--bg), transparent);
}

.daylist { display: grid; gap: 10px; }

.day-card {
  display: grid;
  grid-template-columns: 52px 1fr auto;
  align-items: center;
  gap: 14px;
  width: 100%;
  text-align: left;
  border: none;
  padding: 14px 16px;
  border-radius: var(--r-lg);
  background: var(--surface);
  box-shadow: var(--shadow-1);
  color: inherit;
  position: relative;
}

.day-card:active { transform: scale(0.985); }

.day-card.is-future {
  background: transparent;
  box-shadow: inset 0 0 0 1.5px var(--line);
  opacity: 0.55;
  cursor: default;
}

.day-card.is-future:active { transform: none; }

.day-card.is-today {
  box-shadow: var(--shadow-1), inset 0 0 0 2px var(--accent);
}

.day-num {
  font-size: 30px;
  font-weight: 300;
  line-height: 1;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}

.day-week {
  font-size: 12px;
  color: var(--text-dim);
  text-transform: lowercase;
  margin-top: 3px;
}

.day-main { min-width: 0; display: grid; gap: 7px; }

.day-title { font-size: 14px; font-weight: 700; }
.day-title.is-dim { color: var(--text-faint); font-weight: 600; }

.day-preview { display: flex; align-items: center; gap: 8px; min-width: 0; }

.mood-strip {
  display: flex;
  height: 6px;
  border-radius: var(--r-pill);
  overflow: hidden;
  flex: 0 0 62px;
  background: var(--surface-2);
}

.mood-strip span { flex: 1; }

/* Строка тегов идёт под настроением и погодой, занимает всю ширину карточки
   и листается вбок, если тегов за день больше, чем помещается. */
.day-tags {
  display: flex;
  gap: 5px;
  /* Растягиваем на всю строку: иначе градиент ниже считался бы от ширины самих
     тегов и гасил край последнего даже тогда, когда обрезать нечего. */
  flex: 1 1 auto;
  min-width: 0;
  overflow-x: auto;
  /* Прокрутка не должна перескакивать на страницу за спиной карточки. */
  overscroll-behavior-x: contain;
  scrollbar-width: none;
  /* Край растворяется с той стороны, в которую ещё есть что листать: обрезанный
     на полуслове тег выглядит как ошибка вёрстки, а не как приглашение листать. */
  --fade-l: 22px;
  --fade-r: 22px;
  -webkit-mask-image: linear-gradient(to right, transparent, #000 var(--fade-l),
    #000 calc(100% - var(--fade-r)), transparent);
  mask-image: linear-gradient(to right, transparent, #000 var(--fade-l),
    #000 calc(100% - var(--fade-r)), transparent);
}

.day-tags::-webkit-scrollbar { display: none; }
.day-tags.at-start { --fade-l: 0px; }
.day-tags.at-end { --fade-r: 0px; }

.day-tag { flex: none; }

.day-tag {
  font-size: 11px;
  padding: 3px 8px;
  border-radius: var(--r-pill);
  background: var(--surface-2);
  color: var(--text-dim);
  white-space: nowrap;
}

.sun {
  width: 30px;
  height: 30px;
  flex: none;
  display: block;
}

.sun .sun-core {
  fill: var(--sun-empty);
  transform-origin: 50% 50%;
}

.sun .sun-rays {
  stroke: var(--sun-empty);
  stroke-width: 2;
  stroke-linecap: round;
  fill: none;
}

.sun.is-filled .sun-core { fill: var(--sun); }
.sun.is-filled .sun-rays { stroke: var(--sun); }

/* --- страница дня --------------------------------------------------------- */

.day-hero { display: grid; gap: 4px; }

.locked-banner {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-radius: var(--r-md);
  background: var(--surface-2);
  font-size: 13px;
  color: var(--text-dim);
}

.scale {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 4px;
}

.scale-btn {
  border: none;
  background: transparent;
  border-radius: var(--r-md);
  padding: 8px 0;
  font-size: 27px;
  line-height: 1;
  filter: grayscale(0.55);
  opacity: 0.62;
}

.scale-btn[aria-pressed='true'] {
  filter: none;
  opacity: 1;
  background: var(--accent-soft);
}

.scale-ends {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--text-faint);
}

.scale-readout {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-dim);
  min-height: 19px;
  text-align: center;
}

.mood-marks {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.mood-mark {
  border: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px 6px 9px;
  border-radius: var(--r-pill);
  background: var(--surface-2);
  font-size: 13px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.pills { display: flex; flex-wrap: wrap; gap: 8px; }

.pill {
  border: none;
  padding: 9px 15px;
  border-radius: var(--r-pill);
  background: var(--surface-2);
  color: var(--text-dim);
  font-size: 14px;
  font-weight: 700;
  position: relative;
  overflow: hidden;
}

.pill[aria-pressed='true'] {
  background: var(--accent);
  color: #241703;
}

.pill[disabled] { opacity: 0.5; }

/* --- задачи --------------------------------------------------------------- */

.task-row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: start;
  gap: 12px;
  padding: 13px 14px;
  background: var(--surface);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-1);
}

.task-row.is-done .task-text { color: var(--text-faint); }

.check {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 2px solid var(--line-strong);
  background: transparent;
  display: grid;
  place-items: center;
  padding: 0;
  flex: none;
}

.check[aria-pressed='true'] {
  background: var(--good);
  border-color: var(--good);
}

.check svg { width: 14px; height: 14px; }
.check path { stroke: #fff; stroke-width: 2.6; stroke-linecap: round; stroke-linejoin: round; fill: none; }

.task-text { font-size: 15px; word-break: break-word; }
.task-text .strike { position: relative; }

.task-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 6px;
  flex-wrap: wrap;
}

.prio {
  font-size: 11px;
  font-weight: 800;
  padding: 2px 9px;
  border-radius: var(--r-pill);
}

.prio-1 { background: var(--surface-2); color: var(--text-dim); }
.prio-2 { background: var(--accent-soft-2); color: var(--accent-ink); }
.prio-3 { background: rgba(201, 96, 63, 0.16); color: var(--bad); }

.date-chip {
  border: none;
  font-size: 11px;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: var(--r-pill);
  background: var(--surface-2);
  color: var(--text-dim);
}

.task-del {
  border: none;
  background: none;
  color: var(--text-faint);
  font-size: 15px;
  padding: 2px 4px;
}

/* --- призы ---------------------------------------------------------------- */

.prize-card {
  display: grid;
  gap: 12px;
  padding: 14px 16px;
  background: var(--surface);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-1);
}

.prize-head {
  display: flex;
  align-items: center;
  gap: 12px;
}

.prize-emoji { font-size: 30px; }
.prize-title { font-weight: 700; font-size: 15px; }
.prize-cost { font-size: 13px; color: var(--text-dim); margin-top: 2px; }

.progress {
  height: 6px;
  border-radius: var(--r-pill);
  background: var(--surface-2);
  overflow: hidden;
  margin-top: 8px;
}

.progress i {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
  transform-origin: left center;
}

.history-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 4px;
  border-bottom: 1px solid var(--line);
  font-size: 14px;
}

.history-row:last-child { border-bottom: none; }

/* --- аналитика ------------------------------------------------------------ */

.insight-card {
  display: grid;
  gap: 12px;
  padding: 16px;
  border-radius: var(--r-lg);
  background: var(--surface);
  box-shadow: var(--shadow-1);
  position: relative;
}

.insight-head {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--text-faint);
}

.insight-text { font-size: 15px; line-height: 1.5; }
.insight-text b { color: var(--accent-ink); }

.insight-foot {
  font-size: 11.5px;
  color: var(--text-faint);
  font-variant-numeric: tabular-nums;
}

.badge-new {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
}

.compare {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  align-items: end;
}

/* У знаковой пары общая нулевая линия: без неё «плюс» и «минус» неотличимы. */
.compare.is-signed {
  align-items: stretch;
  position: relative;
  padding-top: 4px;
}

.compare.is-signed::before {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  top: 42px;
  height: 1px;
  z-index: 0;
  background: var(--line-strong);
}

.compare-col {
  display: grid;
  gap: 6px;
  justify-items: center;
}

.compare-col.is-signed {
  grid-template-rows: 38px 38px auto auto;
  gap: 0;
}

.compare-slot {
  display: flex;
  justify-content: center;
  width: 100%;
  height: 38px;
}

.compare-slot.is-above { align-items: flex-end; }
.compare-slot.is-below { align-items: flex-start; }

.compare-col.is-signed .compare-val { margin-top: 10px; }
.compare-col.is-signed .compare-cap { margin-top: 4px; }

.compare-bar {
  width: 100%;
  max-width: 44px;
  border-radius: 4px 4px 0 0;
  background: var(--muted-line);
  transform-origin: bottom center;
}

.compare-bar.is-with { background: var(--series-mood); }
.compare-bar.is-down { border-radius: 0 0 4px 4px; transform-origin: top center; }

.compare-val { font-size: 15px; font-weight: 800; font-variant-numeric: tabular-nums; }
.compare-cap { font-size: 11px; color: var(--text-dim); text-align: center; }

.bars { display: grid; gap: 12px; }

.bar-row { display: grid; gap: 5px; }

.bar-head {
  display: flex;
  align-items: baseline;
  gap: 8px;
  font-size: 13px;
}

.bar-label {
  flex: 1;
  min-width: 0;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bar-n {
  font-size: 11px;
  color: var(--text-faint);
  font-variant-numeric: tabular-nums;
}

.bar-n::after { content: ' дн.'; }

.bar-val {
  font-variant-numeric: tabular-nums;
  font-weight: 800;
  white-space: nowrap;
}

.bar-track {
  height: 8px;
  border-radius: var(--r-pill);
  background: var(--surface-2);
  overflow: hidden;
  position: relative;
}

.bar-fill {
  position: absolute;
  top: 0;
  bottom: 0;
  border-radius: var(--r-pill);
}

.chart-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.chart-wrap svg { display: block; }

.legend {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  font-size: 12px;
  color: var(--text-dim);
}

.legend i {
  display: inline-block;
  width: 14px;
  height: 3px;
  border-radius: 2px;
  margin-right: 6px;
  vertical-align: middle;
}

.deep-answer {
  white-space: pre-wrap;
  font-size: 14.5px;
  line-height: 1.6;
}

/* --- шит ------------------------------------------------------------------ */

.sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(20, 15, 8, 0.38);
  display: flex;
  align-items: flex-end;
}

.sheet {
  width: 100%;
  background: var(--bg);
  border-radius: var(--r-lg) var(--r-lg) 0 0;
  padding: 18px var(--pad) calc(var(--safe-bottom) + 18px);
  display: grid;
  gap: 14px;
  max-height: 86vh;
  overflow-y: auto;
}

.sheet-grip {
  width: 38px;
  height: 4px;
  border-radius: var(--r-pill);
  background: var(--line-strong);
  justify-self: center;
}

/* --- уведомление об обновлении -------------------------------------------- */

.notice {
  position: fixed;
  left: var(--pad);
  right: var(--pad);
  bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 12px);
  z-index: 40;
  padding: 12px 16px;
  border-radius: var(--r-md);
  background: var(--text);
  color: var(--bg);
  font-size: 14px;
  font-weight: 700;
  box-shadow: var(--shadow-2);
  display: flex;
  align-items: center;
  gap: 12px;
}

.notice button {
  border: none;
  background: none;
  color: inherit;
  font-weight: 800;
  text-decoration: underline;
  padding: 0;
}

/* --- онбординг ------------------------------------------------------------ */

.onboarding {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: var(--bg);
  display: grid;
  grid-template-rows: 1fr auto;
  padding: calc(var(--safe-top) + 24px) var(--pad) calc(var(--safe-bottom) + 24px);
}

.onb-slide {
  display: grid;
  align-content: center;
  justify-items: center;
  gap: 16px;
  text-align: center;
}

.onb-glyph { font-size: 64px; }
.onb-slide h2 { font-size: 24px; }
.onb-slide p { margin: 0; color: var(--text-dim); max-width: 30ch; line-height: 1.55; }

.onb-foot { display: grid; gap: 16px; justify-items: center; }

.dots { display: flex; gap: 7px; }

.dots i {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--line-strong);
}

.dots i.is-on { background: var(--accent); }

/* --- утилиты -------------------------------------------------------------- */

.stack { display: grid; gap: 12px; }

/* Пустой контейнер внутри grid всё равно добавляет отступ — схлопываем такие места. */
.collapsible:empty { display: none; }
.row { display: flex; align-items: center; gap: 10px; }
.grow { flex: 1; min-width: 0; }
.center { text-align: center; }
.dim { color: var(--text-dim); }
.nowrap { white-space: nowrap; }
.tnum { font-variant-numeric: tabular-nums; }

/* Название занятия внутри текста и в рейтинге.
   Длинный тег переносится по строкам, и края скругляются только по краям всей
   пилюли, а не каждого куска: два обрубка с круглыми боками читались бы как два
   разных занятия. Поэтому box-decoration-break остаётся значением по умолчанию. */
.tag-chip {
  display: inline;
  padding: 2px 9px;
  border-radius: var(--r-pill);
  background: var(--surface-2);
  font-weight: 700;
  font-size: 0.94em;
}

/* В рейтинге пилюля обнимает название, а не растягивается на всю строку:
   растянутая читалась бы как полоса значения, которая рисуется ниже. */
.bar-label.tag-chip {
  flex: 0 1 auto;
  margin-right: auto;
  align-self: start;
  font-size: 14px;
}

/* --- фото дня ------------------------------------------------------------- */

/* Снимки лежат внизу дня как распечатанные: белое поле, тень, лёгкий наклон.
   Бумага остаётся светлой и в тёмной теме — иначе это уже не фотокарточка. */
.photos {
  display: grid;
  gap: 22px;
  justify-items: center;
  /* Запас по бокам: наклонённая карточка занимает чуть больше своей ширины. */
  padding: 8px 10px 4px;
}

/* Долгое нажатие — наш жест: системное перетаскивание картинки и всплывающее
   меню «Сохранить изображение» его перебивают, поэтому отключены. */
.photo {
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-user-drag: none;
  --tilt: 0deg;
  --drag-x: 0px;
  --drag-y: 0px;
  width: 100%;
  margin: 0;
  transform: translate(var(--drag-x), var(--drag-y)) rotate(var(--tilt));
}

.photo-paper {
  padding: 10px 10px 34px;
  background: #fffdf6;
  border-radius: 3px;
  box-shadow: var(--shadow-2);
}

:root[data-theme='dark'] .photo-paper { background: #e9e1d3; }

/* Кадр показывается целиком: окно повторяет пропорции снимка (--ratio), а сам
   снимок крутится внутри него — см. orientVars в js/photos.js. */
.photo-window {
  position: relative;
  display: block;
  width: 100%;
  aspect-ratio: var(--ratio, 1);
  overflow: hidden;
  border: none;
  padding: 0;
  background: #ded5c4;
}

.photo-window img {
  -webkit-user-drag: none;
  pointer-events: none;
  position: absolute;
  top: 50%;
  left: 50%;
  width: var(--img-w, 100%);
  height: auto;
  transform: translate(-50%, -50%) rotate(var(--turn, 0deg));
}

.photo-actions {
  display: flex;
  justify-content: center;
  gap: 6px;
  margin-top: 6px;
  height: 28px;
}

.photo-actions .icon-btn {
  width: 32px;
  height: 28px;
  font-size: 15px;
  background: transparent;
  box-shadow: none;
  color: #7a6a51;
}

.photo-actions .icon-btn:active { background: rgba(0, 0, 0, 0.06); }

/* --- просмотр во весь экран ------------------------------------------------ */

.viewer {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  grid-template-rows: 1fr auto;
  background: rgba(12, 9, 4, 0.94);
}

.viewer-stage {
  display: grid;
  place-items: center;
  overflow: hidden;
  padding: calc(var(--safe-top, 0px) + 56px) 12px 12px;
}

/* Пределы задаёт JS: у повёрнутого кадра ширина и высота меняются местами,
   а CSS про поворот ничего не знает. */
.viewer-img { transform: rotate(var(--turn, 0deg)); }

.viewer-bar {
  display: grid;
  padding: 12px var(--pad) calc(var(--safe-bottom) + 16px);
}

.viewer-close {
  position: absolute;
  top: calc(var(--safe-top, 0px) + 12px);
  right: 12px;
  z-index: 1;
  background: rgba(255, 255, 255, 0.14);
  color: #fff;
  box-shadow: none;
}

/* Кнопка записи в состоянии «уже сохранено»: подтверждает, но не зовёт нажать. */
.btn.is-saved {
  background: transparent;
  color: var(--text-faint);
  box-shadow: inset 0 0 0 1.5px var(--line);
}

.btn.is-saved[disabled] { opacity: 1; }
