/*
  Voice to Task – «слова на сцене».
  Стиль iA (Refero): бледная бумага, почти черный текст, иерархия только шрифтом,
  мягкие рассеянные тени вместо рамок, кнопки-пилюли, панели 12 px, угольная сцена для записи.
  Коралл #dd4c4f – только запись: круг записи, точка «Идет запись» и курсор в полях.
  Шрифт системный, без загрузки. Моноширинный – только для кода внутри заметки.
  Темы, задачи и раскладка (kb-*, side-tabs, home-kb, chip) живут в kb.css.
*/

:root {
  --font: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace; /* только код внутри заметки */

  /* Цвет – светлая тема */
  --bg: #f7f7f7;            /* холст, текст заметки лежит прямо на нем */
  --surface: #ffffff;       /* шторки, меню, поля, второстепенные кнопки */
  --fill: rgba(0, 0, 0, .05);        /* наведение, выбранная строка, блок загрузки, поиск */
  --fill-strong: rgba(0, 0, 0, .08); /* нажатие, дорожка спиннера */
  --text: #222222;
  --text-2: #666666;        /* даты, подсказки, превью */
  --text-3: #8f8f8f;        /* только не-текст: маркеры, шевроны */
  --rule: #dfdfdf;          /* волосяные разделители */
  --edge: #8f8f8f;          /* контур пустых чекбоксов */
  --inverse: #222222;       /* главная кнопка и тост */
  --on-inverse: #ffffff;
  --accent: #dd4c4f;        /* коралл – одна роль: запись */
  --accent-press: #c63f42;
  --on-accent: #ffffff;
  --stage: #252525;         /* угольная сцена записи */
  --on-stage: #f0f0f0;
  --on-stage-2: #a3a3a3;
  --scrim: rgba(0, 0, 0, .32);
  --focus: #222222;
  --shadow-panel: 0 0 10px rgba(0, 0, 0, .05), 0 0 15px rgba(0, 0, 0, .05), 0 0 20px rgba(0, 0, 0, .05), 0 0 25px rgba(0, 0, 0, .05);
  --shadow-float: 5px 5px 10px rgba(0, 0, 0, .05), 10px 10px 20px rgba(0, 0, 0, .05), 20px 20px 40px rgba(0, 0, 0, .05);

  /* Шрифт: 6 размеров и таймер */
  --fs-caption: 13px;
  --fs-meta: 14px;
  --fs-ui: 16px;
  --fs-body: 17px;
  --fs-h2: 19px;
  --fs-title: 28px;
  --fs-timer: clamp(56px, 17vw, 80px);
  --lh-body: 1.6;
  --lh-ui: 1.35;
  --lh-h2: 1.3;
  --lh-title: 1.15;
  --w-body: 400;
  --w-ui: 500;
  --w-strong: 600;
  --track-title: -.012em;
  --track-timer: -.02em;
  --track-small: .01em;
  --measure: 36em;          /* 66–70 знаков в строке заметки */

  /* Ритм */
  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-5: 24px;
  --sp-6: 32px;
  --sp-7: 48px;
  --sp-8: 72px;

  /* Форма */
  --r-pill: 999px;
  --r-panel: 12px;
  --r-check: 6px;
  --h-control: 44px;
  --h-field: 48px;
  --rec-size: 80px;
  --dock-btn: 48px;
  --chrome-h: 52px;
  --sidebar-w: 300px;

  /* Раскладка: поля по бокам и высота дока, под которым ничего не должно прятаться */
  --gutter: 16px;
  --dock-h: 144px;

  /* Движение */
  --ease: cubic-bezier(.2, .8, .2, 1);
  --t-fast: 120ms;
  --t-base: 200ms;
  --t-sheet: 260ms;

  /* Совместимость: волна записи рисуется цветом --ink, она лежит на угольной сцене */
  --ink: var(--on-stage);

  color-scheme: light;
}

/* Темная тема: по выбору (data-theme="dark") или как на устройстве (data-theme="system").
   Без выбора тема светлая. Атрибут ставит /js/theme.js до первой отрисовки. */
:root[data-theme="dark"] {
  --bg: #1c1c1c;
  --surface: #262626;
  --fill: rgba(255, 255, 255, .07);
  --fill-strong: rgba(255, 255, 255, .11);
  --text: #ededed;
  --text-2: #a3a3a3;
  --text-3: #737373;
  --rule: #333333;
  --edge: #737373;
  --inverse: #ededed;
  --on-inverse: #1c1c1c;
  --accent: #e5585b;
  --accent-press: #ef6a6d;
  --on-accent: #ffffff;
  --stage: #000000;
  --on-stage: #f0f0f0;
  --on-stage-2: #a3a3a3;
  --scrim: rgba(0, 0, 0, .6);
  --focus: #ededed;
  --shadow-panel: 0 0 0 1px rgba(255, 255, 255, .06), 0 8px 24px rgba(0, 0, 0, .5);
  --shadow-float: 0 0 0 1px rgba(255, 255, 255, .06), 0 16px 40px rgba(0, 0, 0, .55);
  --w-body: 380;          /* светлый текст на темном выглядит жирнее */
  color-scheme: dark;
}

@media (prefers-color-scheme: dark) {
  :root[data-theme="system"] {
    --bg: #1c1c1c;
    --surface: #262626;
    --fill: rgba(255, 255, 255, .07);
    --fill-strong: rgba(255, 255, 255, .11);
    --text: #ededed;
    --text-2: #a3a3a3;
    --text-3: #737373;
    --rule: #333333;
    --edge: #737373;
    --inverse: #ededed;
    --on-inverse: #1c1c1c;
    --accent: #e5585b;
    --accent-press: #ef6a6d;
    --on-accent: #ffffff;
    --stage: #000000;
    --on-stage: #f0f0f0;
    --on-stage-2: #a3a3a3;
    --scrim: rgba(0, 0, 0, .6);
    --focus: #ededed;
    --shadow-panel: 0 0 0 1px rgba(255, 255, 255, .06), 0 8px 24px rgba(0, 0, 0, .5);
    --shadow-float: 0 0 0 1px rgba(255, 255, 255, .06), 0 16px 40px rgba(0, 0, 0, .55);
    --w-body: 380;          /* светлый текст на темном выглядит жирнее */
    color-scheme: dark;
  }
}

@media (min-width: 960px) {
  :root {
    --fs-body: 18px;
    --fs-title: 34px;
    --gutter: 32px;
    --dock-h: 128px;
  }
}

/* ---------- база ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font: var(--w-body) var(--fs-ui)/var(--lh-ui) var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
::selection { background: var(--fill-strong); }
[hidden] { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }
img { display: block; }
a { color: inherit; }
h1, h2, h3 { text-wrap: balance; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
/* Заголовки получают фокус программно, чтобы диктор прочел новый экран. Рамка у них не нужна. */
:is(h1, h2)[tabindex="-1"]:focus { outline: none; }

.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
.spacer { flex: 1; }
.visually-hidden,
.home.has-notes .page-title {
  position: absolute !important;
  width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%);
  white-space: nowrap; border: 0;
}
.icon {
  width: 22px; height: 22px; flex: none;
  fill: none; stroke: currentColor; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round;
}
.icon-sm { width: 18px; height: 18px; }

/* ---------- текст ---------- */
.support { margin: 0; font-size: var(--fs-ui); line-height: 1.5; color: var(--text-2); }
.serial { font-size: var(--fs-caption); font-weight: var(--w-ui); color: var(--text-2); white-space: nowrap; }
.count {
  margin-left: 6px;
  font-size: var(--fs-caption); font-weight: var(--w-ui);
  color: var(--text-2); font-variant-numeric: tabular-nums;
}
.count:empty { display: none; }
.notice {
  margin: var(--sp-4) 0 0; padding: var(--sp-3) var(--sp-4);
  border-radius: var(--r-panel); background: var(--fill);
  font-size: var(--fs-meta); line-height: 1.5; color: var(--text);
}
.notice-wide { margin: 0 max(var(--gutter), env(safe-area-inset-right)) var(--sp-3) max(var(--gutter), env(safe-area-inset-left)); }

/* ---------- кнопки ----------
   .btn – главная (пилюля цвета текста), .btn-line – второстепенная, .btn-text – словом,
   .btn-quiet – тихая заливка, .btn-icon – круглая с иконкой. .btn-ink – синоним главной. */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--sp-2);
  min-height: var(--h-control); padding: 0 20px;
  border: 0; border-radius: var(--r-pill);
  background: var(--inverse); color: var(--on-inverse);
  font: var(--w-strong) var(--fs-ui)/1.2 var(--font); letter-spacing: var(--track-small);
  text-decoration: none; white-space: nowrap;
  cursor: pointer; touch-action: manipulation; -webkit-user-select: none; user-select: none;
  transition: background-color var(--t-fast) linear, color var(--t-fast) linear, transform var(--t-fast) var(--ease);
}
.btn-line, .btn.is-done { background: var(--surface); color: var(--text); box-shadow: inset 0 0 0 1px var(--rule); }
.btn-ink { background: var(--inverse); color: var(--on-inverse); box-shadow: none; }
.btn-text { background: transparent; color: var(--text-2); font-weight: var(--w-ui); padding: 0 var(--sp-3); }
.btn-quiet { background: var(--fill); color: var(--text); font-weight: var(--w-ui); }
.btn-compact { min-height: 36px; padding: 0 14px; font-size: 15px; gap: 6px; }
.btn-icon { width: var(--h-control); padding: 0; flex: none; }
.btn-compact.btn-icon { width: 36px; }
.btn-block { width: 100%; }
.btn:active { transform: scale(.98); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .4; cursor: default; pointer-events: none; }

.icon-btn {
  display: inline-grid; place-items: center; flex: none;
  width: var(--h-control); height: var(--h-control); padding: 0;
  border: 0; border-radius: 50%;
  background: transparent; color: var(--text); cursor: pointer;
  transition: background-color var(--t-fast) linear;
}
/* Ссылка-кнопка. «Опасная» выглядит так же: красный у нас только для записи. */
.link-btn, .link-danger {
  display: inline-flex; align-items: center; min-height: 36px; padding: 0;
  border: 0; background: none; color: var(--text);
  font: var(--w-ui) var(--fs-meta)/1.3 var(--font);
  text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 3px;
  text-decoration-color: var(--text-3);
  cursor: pointer; touch-action: manipulation;
}
.link-btn[aria-disabled="true"], .link-btn:disabled {
  color: var(--text-2); text-decoration: none; cursor: default; font-variant-numeric: tabular-nums;
}

@media (hover: hover) {
  .btn-line:hover, .btn-quiet:hover { background: var(--fill-strong); }
  .btn-text:hover { background: var(--fill); color: var(--text); }
  .icon-btn:hover { background: var(--fill); }
  .link-btn:hover { text-decoration-color: currentColor; }
}
@supports (background: color-mix(in srgb, red 50%, blue)) {
  @media (hover: hover) {
    .btn:not(.btn-line, .btn-text, .btn-quiet, .is-done):hover { background: color-mix(in srgb, var(--inverse) 84%, var(--bg)); }
  }
}

/* ---------- поля ---------- */
.input-field { display: flex; flex-direction: column; gap: var(--sp-2); }
.field-label { margin: 0; font: var(--w-ui) var(--fs-meta)/var(--lh-ui) var(--font); color: var(--text); }
.field-hint { margin: 0; font-size: var(--fs-meta); line-height: 1.45; color: var(--text-2); }
.form-error { margin: 0; font-size: var(--fs-meta); font-weight: var(--w-ui); line-height: 1.45; color: var(--text); }

input[type="email"], input[type="password"], input[type="search"], input[type="text"], select, textarea {
  width: 100%; min-height: var(--h-field); padding: 0 var(--sp-4);
  border: 0; border-radius: var(--r-panel);
  background: var(--surface); color: var(--text);
  box-shadow: inset 0 0 0 1px var(--rule);
  font: var(--w-body) var(--fs-ui)/var(--lh-ui) var(--font); /* 16 px: иначе iOS приближает страницу */
  caret-color: var(--accent);
  -webkit-appearance: none; appearance: none;
  transition: box-shadow var(--t-fast) linear, background-color var(--t-fast) linear;
}
textarea { display: block; padding: var(--sp-3) var(--sp-4); line-height: 1.5; resize: vertical; }
select {
  padding-right: 44px; cursor: pointer;
  background-image: linear-gradient(45deg, transparent 50%, var(--text-2) 50%), linear-gradient(135deg, var(--text-2) 50%, transparent 50%);
  background-position: calc(100% - 22px) 52%, calc(100% - 17px) 52%;
  background-size: 5px 5px; background-repeat: no-repeat;
}
::placeholder { color: var(--text-2); opacity: 1; }
input:focus, select:focus, textarea:focus { outline: none; box-shadow: inset 0 0 0 1.5px var(--focus); }
input[type="search"]::-webkit-search-decoration { -webkit-appearance: none; }

/* Поиск: пилюля с иконкой на заливке */
.search { position: relative; display: block; }
.search .icon { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); color: var(--text-2); pointer-events: none; }
.search input { min-height: var(--h-control); padding-left: 42px; border-radius: var(--r-pill); background: var(--fill); box-shadow: none; }
.search input:focus { background: var(--surface); box-shadow: inset 0 0 0 1.5px var(--focus); }

/* ---------- загрузка и вход ---------- */
.boot { position: fixed; inset: 0; display: grid; place-items: center; background: var(--bg); }
.loader {
  width: 20px; height: 20px; border-radius: 50%;
  border: 2px solid var(--fill-strong); border-top-color: var(--text);
  animation: spin .8s linear infinite;
}

.login {
  min-height: 100vh; min-height: 100dvh;
  display: grid; place-items: center;
  padding: calc(env(safe-area-inset-top) + var(--sp-5)) var(--gutter) calc(env(safe-area-inset-bottom) + var(--sp-5));
}
.login-window { width: 100%; max-width: 400px; display: flex; flex-direction: column; gap: var(--sp-4); }
.login-mark { width: 48px; height: 48px; border-radius: var(--r-panel); }
.login-title { margin: 0; font: var(--w-strong) var(--fs-title)/var(--lh-title) var(--font); letter-spacing: var(--track-title); }
.login .support b { font-weight: var(--w-strong); color: var(--text); overflow-wrap: anywhere; }
.login-block { display: flex; flex-direction: column; gap: var(--sp-4); }
.login-or { display: flex; align-items: center; gap: var(--sp-3); margin: 0; font-size: var(--fs-meta); color: var(--text-2); }
.login-or::before, .login-or::after { content: ""; flex: 1; height: 1px; background: var(--rule); }
.login .code-input { font-size: 24px; font-weight: var(--w-ui); letter-spacing: .32em; font-variant-numeric: tabular-nums; }
.login input[aria-invalid="true"] { box-shadow: inset 0 0 0 2px var(--text); }

/* Яндекс ID: цвета бренда, а не токены. Черная пилюля на светлом, белая на темном. */
.btn-yandex {
  display: flex; align-items: center; justify-content: center; gap: var(--sp-3);
  min-height: var(--h-control); padding: 0 28px;
  border-radius: var(--r-pill);
  background: #000; color: #fff;
  font: var(--w-ui) var(--fs-ui)/1 var(--font);
  text-decoration: none; white-space: nowrap;
  touch-action: manipulation; -webkit-user-select: none; user-select: none;
}
.btn-yandex[aria-disabled="true"] { pointer-events: none; opacity: .6; }
.yandex-mark { width: 24px; height: 24px; flex: none; }

/* ---------- каркас ---------- */
.app { min-height: 100vh; min-height: 100dvh; }
.stage { min-width: 0; min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; }
.chrome {
  display: flex; align-items: center; gap: var(--sp-2);
  min-height: calc(var(--chrome-h) + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) max(var(--gutter), env(safe-area-inset-right)) 0 max(var(--gutter), env(safe-area-inset-left));
}
.mark {
  display: inline-flex; align-items: center; gap: var(--sp-2); min-height: var(--h-control);
  font: var(--w-strong) var(--fs-ui)/1 var(--font); letter-spacing: -.01em;
  color: var(--text); text-decoration: none;
}
.mark img { border-radius: 6px; }
.offline {
  display: inline-flex; align-items: center; gap: 6px;
  height: 28px; padding: 0 10px; border-radius: var(--r-pill);
  background: var(--fill); color: var(--text-2);
  font: var(--w-ui) var(--fs-caption)/1 var(--font); white-space: nowrap;
}
.offline::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--text-3); }
.view {
  flex: 1; width: 100%;
  max-width: calc(var(--measure) + 2 * var(--gutter)); /* em считаются от размера текста заметки */
  margin: 0 auto;
  padding: var(--sp-2) max(var(--gutter), env(safe-area-inset-right)) calc(var(--dock-h) + var(--sp-5) + env(safe-area-inset-bottom)) max(var(--gutter), env(safe-area-inset-left));
  font-size: var(--fs-body);
}
.row-start { display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-1) var(--sp-5); }
.row-end { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: var(--sp-2); }
.row-between { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--sp-3); }

/* ---------- главная ----------
   Первый раз: заголовок, подсказка и красный круг. Когда заметки есть, заголовок остается только для диктора. */
.home { padding-top: var(--sp-2); }
.page-title {
  margin: 0 0 var(--sp-3);
  font: var(--w-strong) var(--fs-title)/var(--lh-title) var(--font); letter-spacing: var(--track-title);
  text-wrap: balance; overflow-wrap: anywhere;
}
.home .page-title { max-width: 14em; }
.home-hint { margin: 0 0 var(--sp-3); font-size: var(--fs-body); line-height: var(--lh-body); text-wrap: pretty; }
.home-note { margin: 0; font-size: var(--fs-meta); line-height: 1.5; color: var(--text-2); text-wrap: pretty; }
.home.has-notes #home-hint,
.home.has-notes #home-note { display: none; }
.recent { margin-top: var(--sp-5); }
.home-kb[hidden] + .recent { margin-top: 0; } /* без плашек сверху список начинается сразу под шапкой */
.section-title {
  margin: 0 0 var(--sp-1);
  font: var(--w-strong) var(--fs-meta)/var(--lh-ui) var(--font); letter-spacing: var(--track-small);
  color: var(--text-2);
}

/* ---------- списки заметок: главная и боковая колонка ----------
   Строка: название, ниже «время · длина · первая мысль». Между строками волосяная линия. */
.recent-list, .day ul { list-style: none; margin: 0; padding: 0; }
.recent-list { margin: 0 calc(-1 * var(--sp-3)); }
.note-link {
  position: relative;
  display: grid; grid-template-columns: auto minmax(0, 1fr); grid-template-areas: "title title" "meta preview";
  row-gap: 2px;
  padding: 10px var(--sp-3);
  border-radius: var(--r-panel);
  color: var(--text); text-decoration: none;
  transition: background-color var(--t-fast) linear;
}
li + li > .note-link::before {
  content: ""; position: absolute; left: var(--sp-3); right: var(--sp-3); top: 0;
  height: 1px; background: var(--rule);
}
.note-link[aria-current="page"] { background: var(--fill); }
.note-link[aria-current="page"]::before,
li:has(> .note-link[aria-current="page"]) + li > .note-link::before { opacity: 0; }
@media (hover: hover) {
  .note-link:hover { background: var(--fill); }
  .note-link:hover::before, li:hover + li > .note-link::before { opacity: 0; }
}
.note-link-title {
  grid-area: title;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
  font: var(--w-ui) var(--fs-ui)/var(--lh-ui) var(--font); overflow-wrap: anywhere;
}
.note-link-title.is-placeholder { color: var(--text-2); }
.note-link-meta, .note-link-preview { font-size: var(--fs-meta); line-height: 1.4; color: var(--text-2); }
.note-link-meta { grid-area: meta; display: flex; white-space: nowrap; font-variant-numeric: tabular-nums; }
.note-link-meta > span + span::before { content: "·"; margin: 0 .35em; }
.note-link-meta .is-busy { color: var(--text); }
.note-link-meta .is-error { color: var(--text); font-weight: var(--w-ui); }
.note-link-preview { grid-area: preview; min-width: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.note-link-preview:not(:empty)::before { content: "·"; margin: 0 .35em; }

/* ---------- боковая колонка: на телефоне шторка справа, на компьютере колонка слева ---------- */
.sidebar {
  position: fixed; z-index: 40; top: 0; right: 0; bottom: 0;
  width: min(88vw, 360px);
  display: flex; flex-direction: column; gap: var(--sp-3);
  padding: calc(env(safe-area-inset-top) + var(--sp-2)) max(var(--sp-3), env(safe-area-inset-right)) calc(env(safe-area-inset-bottom) + var(--sp-3)) var(--sp-3);
  background: var(--surface);
  border-radius: var(--r-panel) 0 0 var(--r-panel);
  box-shadow: var(--shadow-panel);
  transform: translateX(105%); visibility: hidden;
  transition: transform var(--t-sheet) var(--ease), visibility 0s linear var(--t-sheet);
}
.sidebar.is-open { transform: none; visibility: visible; transition: transform var(--t-sheet) var(--ease), visibility 0s; }
.scrim { position: fixed; inset: 0; z-index: 35; background: var(--scrim); animation: fade-in var(--t-base) linear; }
.sidebar-head { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-2); padding-left: var(--sp-1); }
.side-panel { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; }
.history-empty { margin: var(--sp-2) var(--sp-3); font-size: var(--fs-meta); line-height: 1.45; color: var(--text-2); }
.day { margin: 0 0 var(--sp-2); }
.day h3 {
  margin: var(--sp-4) var(--sp-3) var(--sp-1);
  font: var(--w-strong) var(--fs-caption)/1.3 var(--font); letter-spacing: var(--track-small);
  color: var(--text-2);
}
.day:first-child h3 { margin-top: var(--sp-1); }
.sidebar-foot {
  display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3);
  padding: var(--sp-1) var(--sp-3) 0; border-top: 1px solid var(--rule);
}
.sidebar-mini { font-size: var(--fs-caption); color: var(--text-2); font-variant-numeric: tabular-nums; }

/* ---------- запись: угольная сцена ---------- */
.live { padding-top: var(--sp-2); }
.live-stage {
  display: flex; flex-direction: column; align-items: center;
  padding: 18px 18px 22px;
  border-radius: var(--r-panel);
  background: var(--stage); color: var(--on-stage);
  text-align: center;
}
.live-state {
  display: inline-flex; align-items: center; gap: var(--sp-2); margin: 0;
  font: var(--w-ui) var(--fs-meta)/var(--lh-ui) var(--font); color: var(--on-stage-2);
}
.live-state::before {
  content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--accent);
  animation: blink 1.1s steps(2, jump-none) infinite;
}
.live.is-paused .live-state::before { animation: none; background: var(--on-stage-2); }
.live-time {
  margin: 26px 0 22px;
  font: var(--w-ui) var(--fs-timer)/1 var(--font); letter-spacing: var(--track-timer);
  font-variant-numeric: tabular-nums; color: var(--on-stage);
}
.live.is-paused .live-time { color: var(--on-stage-2); }
.live-wave { display: block; width: 100%; height: 72px; color: var(--on-stage); }
.live-hint { margin: 18px 0 0; font-size: var(--fs-meta); line-height: var(--lh-ui); color: var(--on-stage-2); }
/* «Удалить запись» – словом, под сценой, подальше от «Готово» */
.live-cancel { display: flex; margin: var(--sp-3) auto 0; }

/* ---------- заметка ---------- */
.back-link {
  display: inline-grid; place-items: center;
  width: var(--h-control); height: var(--h-control); margin: 0 0 0 -12px;
  border-radius: 50%; color: var(--text);
}
@media (hover: hover) { .back-link:hover { background: var(--fill); } }
.note-title {
  margin: var(--sp-1) 0 6px;
  font: var(--w-strong) var(--fs-title)/var(--lh-title) var(--font); letter-spacing: var(--track-title);
  text-wrap: balance; overflow-wrap: anywhere;
}
.note-title.is-placeholder { color: var(--text-2); }
.note-meta {
  margin: 0 0 var(--sp-5);
  font-size: var(--fs-meta); line-height: 1.4; letter-spacing: .005em;
  color: var(--text-2); font-variant-numeric: tabular-nums;
}

/* Ожидание: панель-заливка, спиннер и одна строка. Игривая строка встает на место обычной. */
.status {
  position: relative;
  display: grid; grid-template-columns: auto minmax(0, 1fr);
  grid-template-areas: "spin text" "bar bar" "act act";
  column-gap: var(--sp-3); align-items: start;
  margin: 0 0 var(--sp-5); padding: 14px var(--sp-4);
  border-radius: var(--r-panel); background: var(--fill);
}
.status::before {
  content: ""; grid-area: spin;
  width: 16px; height: 16px; margin-top: 3px; border-radius: 50%;
  border: 2px solid var(--fill-strong); border-top-color: var(--text);
  animation: spin .8s linear infinite;
}
.status-text, .status-quip {
  grid-area: text; margin: 0;
  font: var(--w-ui) var(--fs-ui)/var(--lh-ui) var(--font); overflow-wrap: anywhere;
}
.status-quip.is-in { animation: quip-in .35s var(--ease); }
@supports ((-webkit-background-clip: text) or (background-clip: text)) {
  .status-quip {
    background: linear-gradient(90deg, var(--text) 0 35%, var(--text-3) 50%, var(--text) 65%) 0 0 / 250% 100%;
    -webkit-background-clip: text; background-clip: text;
    color: transparent;
    animation: shimmer 2.4s linear infinite;
  }
  .status-quip.is-in { animation: quip-in .35s var(--ease), shimmer 2.4s linear infinite; }
}
/* Ошибка и «нет сети»: без спиннера и без меток из CSS, текст говорит сам */
.status.is-error, .status.is-wait { grid-template-areas: "text text" "bar bar" "act act"; }
.status.is-error::before, .status.is-wait::before { display: none; }
.status.is-error .status-text, .status.is-wait .status-text { font-weight: var(--w-body); line-height: 1.5; }
.status:has(> .status-text[hidden]):has(> .status-quip[hidden]):has(> .status-actions[hidden]) { display: none; }
/* Полоска – только для настоящих процентов загрузки */
.progress { grid-area: bar; height: 2px; margin-top: var(--sp-3); border-radius: 2px; overflow: hidden; background: var(--fill-strong); }
.progress span { display: block; width: 0; height: 100%; background: var(--text); transition: width var(--t-base) linear; }
.progress.is-indeterminate { display: none; }
.status-actions { grid-area: act; display: flex; flex-wrap: wrap; gap: var(--sp-2); margin-top: var(--sp-3); }

/* Скелет на месте будущих буллетов */
.skeleton { display: grid; gap: 14px; margin: var(--sp-5) 0; }
.skeleton span { display: block; height: 12px; border-radius: var(--r-check); background: var(--fill); animation: pulse 1.6s ease-in-out infinite; }
.skeleton span:nth-child(1) { width: 92%; }
.skeleton span:nth-child(2) { width: 78%; animation-delay: .15s; }
.skeleton span:nth-child(3) { width: 85%; animation-delay: .3s; }

/* Текст заметки */
.md {
  max-width: var(--measure);
  font-size: var(--fs-body); line-height: var(--lh-body); font-weight: var(--w-body);
  overflow-wrap: anywhere;
}
.md:empty { display: none; }
.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md h2, .md h3, .md h4 { margin: var(--sp-6) 0 var(--sp-2); font-weight: var(--w-strong); line-height: var(--lh-h2); color: var(--text); }
.md h2 { font-size: var(--fs-h2); }
.md h3 { font-size: var(--fs-body); }
.md h4 { font-size: var(--fs-ui); }
.md p { margin: 0 0 var(--sp-3); text-wrap: pretty; }
.md strong { font-weight: var(--w-strong); }
.md a { color: var(--text); text-decoration-color: var(--text-3); text-decoration-thickness: 1px; text-underline-offset: 3px; }
.md ul { list-style: none; margin: 0 0 var(--sp-3); padding: 0; }
.md ol { list-style: decimal; margin: 0 0 var(--sp-3); padding: 0 0 0 1.5em; }
.md li { position: relative; margin: 0 0 var(--sp-2); padding-left: 20px; text-wrap: pretty; }
.md ol > li { padding-left: 4px; }
.md ol > li::marker { color: var(--text-2); font-variant-numeric: tabular-nums; }
.md ul > li::before {
  content: ""; position: absolute; left: 5px; top: calc(.8em - 2.5px);
  width: 5px; height: 5px; border-radius: 50%; background: var(--text-3);
}
.md li ul, .md li ol { margin: var(--sp-2) 0 0; }
.md li ul > li::before { background: transparent; box-shadow: inset 0 0 0 1.25px var(--text-3); }
/* Задачи: квадрат 20 px, отмеченная – залита цветом текста */
.md .md-task { padding-left: 32px; }
.md .md-task::before { content: none; }
.md-check {
  position: absolute; left: 0; top: calc(.8em - 10px);
  display: grid; place-items: center;
  width: 20px; height: 20px;
  border: 1.5px solid var(--edge); border-radius: var(--r-check);
  cursor: pointer;
  transition: background-color var(--t-fast) linear, border-color var(--t-fast) linear;
}
.md-check::before { content: ""; position: absolute; inset: -12px; } /* палец промахивается – ловим шире */
.md-task.is-done .md-check { background: var(--text); border-color: var(--text); }
.md-task.is-done .md-check::after {
  content: ""; width: 9px; height: 5px; margin-top: -2px;
  border-left: 2px solid var(--bg); border-bottom: 2px solid var(--bg); transform: rotate(-45deg);
}
.md-task.is-done .md-task-text { color: var(--text-2); text-decoration: line-through; text-decoration-thickness: 1px; }
.md blockquote { margin: 0 0 var(--sp-3); padding-left: 14px; border-left: 2px solid var(--rule); color: var(--text-2); }
.md code { padding: 1px 5px; border-radius: var(--r-check); background: var(--fill); font: .88em/1.4 var(--font-mono); }
.md hr { margin: var(--sp-5) 0; border: 0; border-top: 1px solid var(--rule); }
.md.is-streaming::after {
  content: ""; display: block; width: 8px; height: 18px; margin-top: var(--sp-1);
  border-radius: 2px; background: var(--text);
  animation: blink 1s steps(2, jump-none) infinite;
}

/* Действия: «Скопировать», «Поделиться» и «…» в одну строку даже на 375 px */
.actions { display: flex; flex-wrap: nowrap; align-items: center; gap: var(--sp-2); margin-top: var(--sp-5); }
.actions > .btn { flex: 0 1 auto; padding: 0 18px; }
.menu-wrap { position: relative; flex: none; }
.menu {
  position: absolute; z-index: 30; top: calc(100% + 6px); right: 0;
  width: max-content; min-width: 184px; max-width: calc(100vw - 2 * var(--gutter));
  display: flex; flex-direction: column;
  padding: 6px; border-radius: var(--r-panel);
  background: var(--surface); box-shadow: var(--shadow-panel);
  transform-origin: top right;
  animation: menu-in var(--t-fast) var(--ease);
}
.menu-item {
  display: flex; align-items: center; width: 100%;
  min-height: var(--h-control); padding: 0 var(--sp-3);
  border: 0; border-radius: 8px; background: none; color: var(--text);
  font: var(--w-ui) var(--fs-ui)/var(--lh-ui) var(--font);
  text-align: left; text-decoration: none; white-space: nowrap; cursor: pointer;
}
.menu-item:disabled, .menu-item[aria-disabled="true"] { color: var(--text-2); cursor: default; }
.menu-item:focus-visible { outline-offset: -2px; }
@media (hover: hover) { .menu-item:not(:disabled):hover { background: var(--fill); } }

/* Текст записи и аудио – одним раскрывающимся блоком внизу заметки */
.extra { margin-top: var(--sp-6); }
.transcript > summary {
  display: flex; align-items: center; gap: var(--sp-2);
  min-height: 52px; padding: var(--sp-3) 0;
  border-top: 1px solid var(--rule);
  font: var(--w-ui) var(--fs-ui)/var(--lh-ui) var(--font);
  list-style: none; cursor: pointer;
}
.transcript > summary::-webkit-details-marker { display: none; }
.transcript-meta { font-size: var(--fs-meta); font-weight: var(--w-body); color: var(--text-2); }
.transcript-meta:empty { display: none; }
.transcript .chevron { margin-left: auto; color: var(--text-3); transition: transform var(--t-base) var(--ease); }
.transcript[open] .chevron { transform: rotate(180deg); }
.transcript-body { display: flex; flex-direction: column; gap: var(--sp-3); padding-bottom: var(--sp-3); }
.transcript-text {
  margin: 0; font-size: var(--fs-ui); line-height: var(--lh-body);
  white-space: pre-wrap; overflow-wrap: anywhere;
}
.transcript-text:empty { display: none; }
.transcript-editor { display: flex; flex-direction: column; gap: var(--sp-3); }
.transcript-editor textarea { min-height: 200px; }
.audio-row audio { display: block; width: 100%; height: 40px; }

/* ---------- док: «Файл», красный круг и пустой слот для симметрии ---------- */
.dock {
  position: fixed; z-index: 20; left: 0; right: 0; bottom: 0;
  display: flex; justify-content: center; align-items: flex-start; gap: var(--sp-5);
  padding: 28px var(--gutter) calc(var(--sp-3) + env(safe-area-inset-bottom));
  background: linear-gradient(to bottom, transparent, var(--bg) 40%);
  pointer-events: none;
}
.dock-slot {
  display: grid; grid-template-rows: var(--rec-size) auto; justify-items: center; align-items: center; row-gap: 6px;
  width: 88px; pointer-events: auto;
}
.dock-slot-main { width: calc(var(--rec-size) + var(--sp-4)); }
.dock-slot-spacer { visibility: hidden; pointer-events: none; }
.dock-caption {
  grid-row: 2; min-height: 1.3em;
  font: var(--w-ui) var(--fs-caption)/1.3 var(--font); letter-spacing: var(--track-small);
  color: var(--text-2); white-space: nowrap;
}
.disk {
  grid-row: 1; position: relative; display: grid; place-items: center;
  padding: 0; border: 0; border-radius: 50%;
  cursor: pointer; touch-action: manipulation; -webkit-user-select: none; user-select: none;
  transition: background-color var(--t-fast) linear, color var(--t-fast) linear, transform var(--t-fast) var(--ease);
}
.disk:active { transform: scale(.95); }
.disk-sm { width: var(--dock-btn); height: var(--dock-btn); background: var(--surface); color: var(--text); box-shadow: var(--shadow-panel); }
.disk-rec { width: var(--rec-size); height: var(--rec-size); background: var(--accent); color: var(--on-accent); }
.rec-core {
  display: block; width: 24px; height: 24px; border-radius: 50%; background: var(--on-accent);
  transition: border-radius var(--t-base) var(--ease);
}
@media (hover: hover) {
  .disk-sm:hover { box-shadow: var(--shadow-panel), inset 0 0 0 100px var(--fill); }
  .disk-rec:hover { background: var(--accent-press); }
}
/* Состояния дока: пауза только во время записи, загрузка файла – только вне ее */
#btn-pause { display: none; }
.dock[data-state="recording"] #btn-pause,
.dock[data-state="paused"] #btn-pause { display: grid; }
.dock[data-state="recording"] #btn-upload,
.dock[data-state="paused"] #btn-upload { display: none; }
.dock[data-state="paused"] #btn-pause { color: var(--accent); }
.dock[data-state="recording"] .rec-core,
.dock[data-state="paused"] .rec-core { border-radius: var(--r-check); }
.dock[data-state="starting"] .disk-rec,
.dock[data-state="stopping"] .disk-rec { pointer-events: none; }
.dock[data-state="starting"] .rec-core,
.dock[data-state="stopping"] .rec-core {
  background: transparent; border: 2.5px solid rgba(255, 255, 255, .4); border-top-color: var(--on-accent);
  animation: spin .8s linear infinite;
}
.dock[data-state="starting"] .dock-slot:not(.dock-slot-main),
.dock[data-state="stopping"] .dock-slot:not(.dock-slot-main) { visibility: hidden; }

/* ---------- шторки и окна: снизу на телефоне, по центру на большом экране ---------- */
dialog.sheet {
  width: 100%; max-width: 100%; max-height: 92vh; max-height: 92dvh;
  margin: auto 0 0; padding: 0;
  border: 0; border-radius: var(--r-panel) var(--r-panel) 0 0;
  background: var(--surface); color: var(--text);
  box-shadow: var(--shadow-float);
  overflow: hidden;
}
dialog.sheet[open] { animation: sheet-up var(--t-sheet) var(--ease); }
dialog.sheet::backdrop { background: var(--scrim, rgba(0, 0, 0, .32)); }
.sheet-body {
  display: flex; flex-direction: column; gap: var(--sp-5);
  max-height: 92vh; max-height: 92dvh; overflow-y: auto; overscroll-behavior: contain;
  padding: var(--sp-4) var(--sp-5) calc(var(--sp-5) + env(safe-area-inset-bottom));
}
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-2); margin: 0 -10px calc(-1 * var(--sp-2)) 0; }
.sheet-title { margin: 0; font: var(--w-strong) var(--fs-h2)/var(--lh-h2) var(--font); }
.sheet-small .sheet-body { gap: var(--sp-3); }
.sheet-small .row-end { margin-top: var(--sp-3); }

/* Вид заметки: плитки на заливке, выбранная – цвета текста. Без номеров. */
.specimens { display: grid; grid-template-columns: 1fr 1fr; gap: var(--sp-2); }
.specimen {
  position: relative; display: flex; flex-direction: column; gap: var(--sp-1);
  min-height: 96px; padding: 14px var(--sp-4);
  border-radius: var(--r-panel); background: var(--fill);
  cursor: pointer; transition: background-color var(--t-fast) linear, color var(--t-fast) linear;
}
.specimen input { position: absolute; opacity: 0; pointer-events: none; }
.specimen b { font: var(--w-strong) var(--fs-ui)/var(--lh-ui) var(--font); }
.specimen small { font-size: var(--fs-meta); line-height: 1.35; color: var(--text-2); }
.specimen.is-checked, .specimen:has(input:checked) { background: var(--inverse); color: var(--on-inverse); }
.specimen.is-checked small, .specimen:has(input:checked) small { color: var(--on-inverse); opacity: .72; }
.specimen:has(input:focus-visible) { outline: 2px solid var(--focus); outline-offset: 2px; }
.specimen-wide { grid-column: 1 / -1; min-height: 72px; }
@media (hover: hover) { .specimen:not(.is-checked):not(:has(input:checked)):hover { background: var(--fill-strong); } }

/* Настройки */
.setting { display: flex; flex-direction: column; align-items: flex-start; gap: 6px; }
.setting .btn { margin-top: 6px; }
.account-row {
  display: flex; align-items: flex-start; justify-content: space-between; gap: var(--sp-4);
  padding: 14px var(--sp-4); border-radius: var(--r-panel); background: var(--fill);
}
.account-info { min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.account-info p { margin: 0; }
.account-email { font-size: var(--fs-ui); font-weight: var(--w-ui); color: var(--text); overflow-wrap: anywhere; }

/* ---------- тосты: над доком, по центру основной колонки ---------- */
.toasts {
  position: fixed; z-index: 90; left: 0; right: 0;
  bottom: calc(env(safe-area-inset-bottom) + 150px);
  display: flex; flex-direction: column; align-items: center; gap: var(--sp-2);
  padding: 0 var(--gutter); pointer-events: none;
}
.toast {
  display: flex; align-items: center; gap: var(--sp-3);
  width: min(100%, 460px); min-height: 48px;
  padding: var(--sp-2) var(--sp-2) var(--sp-2) var(--sp-4);
  border-radius: var(--r-panel);
  background: var(--inverse); color: var(--on-inverse); box-shadow: var(--shadow-float);
  font: var(--w-ui) 15px/1.4 var(--font);
  pointer-events: auto;
  animation: toast-in var(--t-base) var(--ease);
}
.toast > span { flex: 1; min-width: 0; padding: 4px 0; }
.toast button {
  flex: none; min-height: 32px; padding: 0 var(--sp-3);
  border: 0; border-radius: var(--r-pill);
  background: rgba(255, 255, 255, .14); color: inherit;
  font: var(--w-strong) var(--fs-meta)/1 var(--font); cursor: pointer;
}
.toast.is-leaving { opacity: 0; transform: translateY(4px); transition: opacity var(--t-base) linear, transform var(--t-base) var(--ease); }

/* ---------- перетаскивание файла ---------- */
.drop-overlay { position: fixed; inset: 0; z-index: 80; display: grid; place-items: center; padding: var(--sp-5); background: var(--scrim); }
.drop-window {
  width: min(440px, 100%); padding: var(--sp-7) var(--sp-5);
  border-radius: var(--r-panel); background: var(--surface); box-shadow: var(--shadow-float);
  outline: 1.5px dashed var(--edge); outline-offset: -12px;
  text-align: center;
}
.drop-title { margin: 0; font: var(--w-strong) var(--fs-h2)/var(--lh-h2) var(--font); text-wrap: balance; }

/* ---------- темная тема: исключения ---------- */
:root[data-theme="dark"] .btn-yandex { background: #fff; color: #000; }
:root[data-theme="dark"] .toast button { background: rgba(0, 0, 0, .1); }
@media (prefers-color-scheme: dark) {
  :root[data-theme="system"] .btn-yandex { background: #fff; color: #000; }
  :root[data-theme="system"] .toast button { background: rgba(0, 0, 0, .1); }
}

/* Переключатель темы в шапке: луна в светлой теме, солнце в темной */
.theme-toggle { color: var(--text-2); border-radius: var(--r-pill); }
.theme-toggle .icon-sun { display: none; }
.theme-toggle[aria-pressed="true"] .icon-sun { display: block; }
.theme-toggle[aria-pressed="true"] .icon-moon { display: none; }
@media (hover: hover) { .theme-toggle:hover { color: var(--text); background: var(--fill); } }

/* ---------- узкие телефоны: действия переносятся, а не обрезаются ---------- */
@media (max-width: 349px) {
  .actions { flex-wrap: wrap; }
}

/* ---------- от 640 px: окна по центру ---------- */
@media (min-width: 640px) {
  dialog.sheet { width: calc(100% - 2 * var(--sp-6)); max-width: 520px; margin: auto; border-radius: var(--r-panel); }
  dialog.sheet[open] { animation-name: sheet-in; }
  dialog.sheet-small { max-width: 420px; }
  .sheet-body { padding: var(--sp-5) var(--sp-6) var(--sp-6); }
}

/* ---------- от 960 px: колонка заметок слева, док только под основной колонкой ---------- */
@media (min-width: 960px) {
  .app { display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr); }
  .only-mobile, .scrim { display: none !important; }
  .sidebar {
    position: sticky; top: 0; height: 100vh; height: 100dvh; width: auto;
    padding: var(--sp-4) var(--sp-3) var(--sp-3) var(--sp-4);
    background: var(--bg); border-radius: 0; border-right: 1px solid var(--rule); box-shadow: none;
    transform: none; visibility: visible; transition: none;
  }
  .dock {
    --rec-size: 72px;
    --dock-btn: 44px;
    left: var(--sidebar-w);
    padding-top: var(--sp-5); padding-bottom: var(--sp-4);
  }
  .toasts { bottom: 124px; }
  .app:not([hidden]) ~ .toasts { left: var(--sidebar-w); }
  .home { padding-top: var(--sp-4); }
}

/* ---------- анимации ---------- */
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes blink { 50% { opacity: 0; } }
@keyframes pulse { 50% { opacity: .5; } }
@keyframes fade-in { from { opacity: 0; } }
@keyframes quip-in { from { opacity: 0; transform: translateY(3px); } }
@keyframes shimmer { from { background-position: 100% 0; } to { background-position: 0 0; } }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }
@keyframes menu-in { from { opacity: 0; transform: scale(.97); } }
@keyframes sheet-up { from { opacity: 0; transform: translateY(24px); } }
@keyframes sheet-in { from { opacity: 0; transform: translateY(8px) scale(.98); } }

/* Меньше движения: гасим все, кроме нужных спиннеров – их только замедляем */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
    scroll-behavior: auto !important;
  }
  .loader, .status::before,
  .dock[data-state="starting"] .rec-core,
  .dock[data-state="stopping"] .rec-core { animation: spin 1.6s linear infinite !important; }
}
