/* ============================================================
   Дизайн-токены
   ============================================================ */
:root {
  --bg: #eef1f9;
  --bg-grad-1: #e9ecfb;
  --bg-grad-2: #f4eefb;
  --surface: #ffffff;
  --surface-2: #f5f6fb;
  --surface-3: #eceef6;
  --text: #1b1d29;
  --text-soft: #5b6072;
  --text-faint: #8a90a3;
  --border: #e3e6f0;
  --primary: #6366f1;
  --primary-strong: #4f46e5;
  --primary-soft: #eef0fe;
  --accent: #8b5cf6;
  --ok: #16a34a;
  --ok-soft: #e7f7ee;
  --ok-border: #b7e6c7;
  --no: #e11d48;
  --no-soft: #fdeaee;
  --no-border: #f6c1cd;
  --warn: #d97706;
  --shadow-sm: 0 1px 2px rgba(23, 25, 40, 0.06);
  --shadow: 0 8px 24px rgba(40, 44, 82, 0.08);
  --shadow-lg: 0 20px 50px rgba(40, 44, 82, 0.16);
  --radius: 22px;
  --radius-sm: 14px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue",
    Arial, "Noto Sans", sans-serif;
  --tabbar-h: 68px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1119;
    --bg-grad-1: #141726;
    --bg-grad-2: #1a1526;
    --surface: #1a1d2b;
    --surface-2: #212536;
    --surface-3: #2a2f44;
    --text: #eef0f7;
    --text-soft: #a7adc2;
    --text-faint: #757b93;
    --border: #2c3145;
    --primary: #818cf8;
    --primary-strong: #6366f1;
    --primary-soft: #262a45;
    --accent: #a78bfa;
    --ok: #34d399;
    --ok-soft: #123122;
    --ok-border: #1e5940;
    --no: #fb7185;
    --no-soft: #3a1622;
    --no-border: #6d2437;
    --warn: #fbbf24;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
    --shadow-lg: 0 24px 60px rgba(0, 0, 0, 0.5);
  }
}

/* ============================================================
   Базовые стили
   ============================================================ */
* {
  box-sizing: border-box;
}
html,
body {
  margin: 0;
  padding: 0;
}
body {
  font-family: var(--font);
  color: var(--text);
  background: var(--bg);
  background-image: radial-gradient(
      1200px 600px at 15% -10%,
      var(--bg-grad-1),
      transparent 60%
    ),
    radial-gradient(1000px 500px at 100% 0%, var(--bg-grad-2), transparent 55%);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  min-height: 100vh;
  min-height: 100dvh;
}

button,
input,
textarea {
  font-family: inherit;
}

.app {
  max-width: 560px;
  margin: 0 auto;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

/* ============================================================
   Шапка
   ============================================================ */
.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(env(safe-area-inset-top) + 14px) 18px 12px;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: saturate(180%) blur(14px);
  -webkit-backdrop-filter: saturate(180%) blur(14px);
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 1.15rem;
  letter-spacing: -0.01em;
}
.app-header .brand {
  color: inherit;
  text-decoration: none;
  border-radius: 11px;
}
.app-header .brand:hover {
  opacity: 0.88;
}
.app-header .brand:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--primary) 45%, transparent);
  outline-offset: 3px;
}
.brand-mark {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 11px;
  color: #fff;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  box-shadow: var(--shadow-sm);
  font-size: 1.05rem;
}
.due-badge {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 7px 13px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  font-weight: 700;
  font-size: 0.9rem;
  color: var(--text-soft);
}
.due-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-faint);
}
.due-badge.has-due {
  color: var(--primary-strong);
  border-color: color-mix(in srgb, var(--primary) 40%, var(--border));
}
.due-badge.has-due .due-dot {
  background: var(--primary);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--primary) 20%, transparent);
  animation: pulse 2s infinite;
}
@keyframes pulse {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.45;
  }
}

/* ============================================================
   Основная область / вкладки
   ============================================================ */
.app-main {
  flex: 1;
  padding: 14px 16px calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 28px);
}
.view {
  display: none;
  animation: fade 0.28s ease;
}
.view.active {
  display: block;
}
@keyframes fade {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ============================================================
   Карточка (общая)
   ============================================================ */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px;
}

/* ============================================================
   Кнопки и поля
   ============================================================ */
.btn {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 1rem;
  font-weight: 600;
  padding: 13px 18px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: transform 0.08s ease, background 0.15s ease, box-shadow 0.15s ease,
    border-color 0.15s ease;
  width: 100%;
}
.btn:active {
  transform: scale(0.98);
}
.btn.primary {
  color: #fff;
  border-color: transparent;
  background: linear-gradient(135deg, var(--primary), var(--primary-strong));
  box-shadow: 0 8px 20px color-mix(in srgb, var(--primary) 35%, transparent);
}
.btn.primary:hover {
  filter: brightness(1.04);
}
.btn.ghost {
  background: transparent;
  border-color: var(--border);
  color: var(--text-soft);
}
.btn.small {
  width: auto;
  padding: 9px 14px;
  font-size: 0.9rem;
}

.input {
  width: 100%;
  padding: 14px 16px;
  font-size: 1.05rem;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}
.input::placeholder {
  color: var(--text-faint);
}
.input:focus {
  border-color: var(--primary);
  background: var(--surface);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--primary) 18%, transparent);
}
.textarea {
  resize: vertical;
  line-height: 1.5;
  font-size: 1rem;
}

/* ============================================================
   Учить — переключатель направлений
   ============================================================ */
.chips {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 5px;
  border-radius: 999px;
  box-shadow: var(--shadow-sm);
}
.chip {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--text-soft);
  font-weight: 600;
  font-size: 0.92rem;
  padding: 10px 8px;
  border-radius: 999px;
  cursor: pointer;
  transition: color 0.15s ease, background 0.15s ease;
  white-space: nowrap;
}
.chip.active {
  color: #fff;
  background: linear-gradient(135deg, var(--primary), var(--primary-strong));
  box-shadow: 0 6px 14px color-mix(in srgb, var(--primary) 30%, transparent);
}

/* ============================================================
   Учить — карточка вопроса
   ============================================================ */
.study {
  text-align: center;
  padding: 30px 22px 24px;
  position: relative;
  overflow: hidden;
}
.study.shake {
  animation: shake 0.4s cubic-bezier(0.36, 0.07, 0.19, 0.97);
}
@keyframes shake {
  10%,
  90% {
    transform: translateX(-2px);
  }
  20%,
  80% {
    transform: translateX(4px);
  }
  30%,
  50%,
  70% {
    transform: translateX(-8px);
  }
  40%,
  60% {
    transform: translateX(8px);
  }
}
.study.pop {
  animation: pop 0.35s ease;
}
@keyframes pop {
  0% {
    transform: scale(1);
  }
  40% {
    transform: scale(1.02);
  }
  100% {
    transform: scale(1);
  }
}

.dir-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--primary-strong);
  background: var(--primary-soft);
  padding: 7px 14px;
  border-radius: 999px;
  margin-bottom: 22px;
}
.dir-badge .lang {
  opacity: 0.65;
}

.prompt {
  font-size: clamp(2rem, 9vw, 2.9rem);
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1.15;
  word-break: break-word;
  margin: 6px 0 4px;
}
.prompt-sub {
  color: var(--text-faint);
  font-size: 0.92rem;
  margin-bottom: 26px;
}

.answer-form {
  margin-top: 26px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.answer-form .input {
  text-align: center;
  font-size: 1.2rem;
  padding: 16px;
}

/* Результат */
.result-banner {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  font-weight: 800;
  font-size: 1.3rem;
  letter-spacing: -0.01em;
  margin-top: 26px;
  padding: 16px 18px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  box-shadow: inset 0 1px 0 color-mix(in srgb, #fff 55%, transparent), var(--shadow-sm);
}
.result-banner .ic {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  flex: none;
  border-radius: 50%;
  color: #fff;
  font-size: 1.05rem;
  box-shadow: 0 5px 12px color-mix(in srgb, currentColor 28%, transparent);
}
.study.correct .result-banner {
  color: var(--ok);
  background: linear-gradient(
    135deg,
    var(--ok-soft),
    color-mix(in srgb, var(--ok-soft) 58%, var(--surface))
  );
  border-color: var(--ok-border);
}
.study.correct .result-banner .ic {
  background: var(--ok);
}
.study.wrong .result-banner {
  color: var(--no);
  background: linear-gradient(
    135deg,
    var(--no-soft),
    color-mix(in srgb, var(--no-soft) 58%, var(--surface))
  );
  border-color: var(--no-border);
}
.study.wrong .result-banner .ic {
  background: var(--no);
}

.answers {
  margin-top: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  text-align: center;
}
.ans-row {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 5px;
  min-height: 76px;
  padding: 14px 18px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-2);
  box-shadow: inset 0 1px 0 color-mix(in srgb, #fff 45%, transparent);
}
.ans-row .lbl {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-faint);
}
.ans-row .val {
  width: 100%;
  font-size: 1.2rem;
  font-weight: 800;
  line-height: 1.3;
  overflow-wrap: anywhere;
}
.ans-row.right {
  background: linear-gradient(
    135deg,
    var(--ok-soft),
    color-mix(in srgb, var(--ok-soft) 62%, var(--surface))
  );
  border-color: var(--ok-border);
}
.ans-row.right .val {
  color: var(--ok);
}
.ans-row.your {
  background: linear-gradient(
    135deg,
    var(--no-soft),
    color-mix(in srgb, var(--no-soft) 62%, var(--surface))
  );
  border-color: var(--no-border);
}
.ans-row.your .val {
  color: var(--no);
  text-decoration: line-through;
}
.next-hint {
  margin-top: 10px;
  font-size: 0.82rem;
  color: var(--text-faint);
}

/* Пустое состояние */
.empty {
  text-align: center;
  padding: 46px 24px;
}
.empty .emoji {
  font-size: 3rem;
  margin-bottom: 12px;
}
.empty h2 {
  margin: 0 0 8px;
  font-size: 1.3rem;
}
.empty p {
  color: var(--text-soft);
  margin: 0 0 20px;
  line-height: 1.5;
}

/* ============================================================
   Слова
   ============================================================ */
.add-form {
  padding: 16px;
  margin-bottom: 14px;
}
.add-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}
.add-row .input {
  flex: 1;
  min-width: 0;
}
.add-arrow {
  color: var(--text-faint);
  font-size: 1.2rem;
  flex: none;
}
.import {
  margin-top: 12px;
  border-top: 1px solid var(--border);
  padding-top: 10px;
}
.import summary {
  cursor: pointer;
  color: var(--primary-strong);
  font-weight: 600;
  font-size: 0.92rem;
  list-style: none;
  padding: 4px 0;
}
.import summary::-webkit-details-marker {
  display: none;
}
.import summary::before {
  content: "＋ ";
}
.import[open] summary::before {
  content: "－ ";
}
.import .hint,
.hint {
  color: var(--text-faint);
  font-size: 0.85rem;
  margin: 8px 0;
  line-height: 1.4;
}
.import .textarea {
  margin-bottom: 10px;
}

.search-wrap {
  margin: 4px 0 8px;
}

.word-sort-wrap {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  margin-bottom: 14px;
  color: var(--text-soft);
  font-size: 0.78rem;
  font-weight: 600;
}
.word-sort {
  width: auto;
  min-height: 44px;
  padding: 8px 38px 8px 12px;
  font-size: 0.88rem;
  font-weight: 600;
}

.words-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.word-row {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-sm);
  padding: 5px 8px 5px 14px;
}
.active-word-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  column-gap: 10px;
  row-gap: 2px;
}
.active-word-row .word-main {
  min-width: 0;
}
.word-meta {
  grid-column: 1 / -1;
  min-width: 0;
  padding: 0 0 4px;
  color: var(--text-soft);
  font-size: 0.78rem;
  font-weight: 600;
  line-height: 1.35;
}
.word-main {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: baseline;
  gap: 7px;
}
.w-en {
  flex: 0 1 auto;
  min-width: 0;
  font-weight: 700;
  font-size: 1rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.w-sep {
  flex: none;
  color: var(--text-faint);
}
.w-ru {
  flex: 1 1 auto;
  min-width: 0;
  color: var(--text-soft);
  font-size: 0.95rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.w-actions {
  display: flex;
  gap: 2px;
  flex: none;
}
.icon-btn {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border-radius: 10px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-faint);
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}
.icon-btn:hover {
  background: var(--surface-2);
  color: var(--text);
}
.icon-btn.danger:hover {
  background: var(--no-soft);
  color: var(--no);
}
.icon-btn svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.list-empty {
  text-align: center;
  color: var(--text-faint);
  padding: 34px 10px;
}
.word-main {
  cursor: pointer;
}
.word-row:hover {
  border-color: color-mix(in srgb, var(--primary) 35%, var(--border));
}

/* Архив слов */
.archive-heading {
  margin-bottom: 18px;
}
.archive-heading h2 {
  margin: 0 0 7px;
  font-size: 1.45rem;
  letter-spacing: -0.015em;
}
.archive-heading p {
  margin: 0;
  color: var(--text-soft);
  font-size: 0.9rem;
  line-height: 1.5;
}
.archive-word-row {
  padding: 9px 9px 9px 14px;
}
.archive-word-row .word-main {
  flex-direction: column;
  align-items: stretch;
  gap: 3px;
  cursor: default;
}
.archive-word-pair {
  min-width: 0;
  display: flex;
  align-items: baseline;
  gap: 7px;
}
.archive-date {
  color: var(--text-faint);
  font-size: 0.75rem;
  font-weight: 600;
}
.restore-word {
  flex: none;
  min-height: 42px;
}
.restore-word:disabled {
  cursor: wait;
  opacity: 0.55;
}
.restore-word:focus-visible,
.settings-link:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--primary) 45%, transparent);
  outline-offset: 2px;
}
.archive-empty {
  box-shadow: var(--shadow-sm);
}

/* ============================================================
   Страница карточки
   ============================================================ */
.back-link {
  background: none;
  border: none;
  color: var(--primary-strong);
  font-weight: 600;
  font-size: 0.95rem;
  padding: 2px 0 12px;
  cursor: pointer;
}
.card-word {
  text-align: center;
  margin-bottom: 14px;
}
.cw-en {
  font-size: 1.7rem;
  font-weight: 800;
  letter-spacing: -0.01em;
  word-break: break-word;
}
.cw-ru {
  color: var(--text-soft);
  font-size: 1.05rem;
  margin-top: 2px;
}
.cd-block {
  margin-bottom: 14px;
  padding: 18px;
}
.cd-title {
  display: inline-block;
  font-weight: 700;
  font-size: 0.82rem;
  letter-spacing: 0.04em;
  color: var(--primary-strong);
  background: var(--primary-soft);
  padding: 6px 13px;
  border-radius: 999px;
  margin-bottom: 14px;
}
.cd-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.cd-stats > div {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 12px;
}
.cd-stats span {
  display: block;
  font-size: 0.72rem;
  color: var(--text-faint);
  font-weight: 600;
  margin-bottom: 2px;
}
.cd-stats b {
  font-size: 1.05rem;
}
.cd-empty {
  text-align: center;
  color: var(--text-faint);
  padding: 26px 8px;
  font-size: 0.9rem;
}
.iv-svg {
  display: block;
  width: 100%;
  height: auto;
  margin-top: 12px;
}
.iv-svg .iv-line {
  fill: none;
  stroke: var(--primary);
  stroke-width: 2;
  stroke-linejoin: round;
  stroke-linecap: round;
}
.iv-svg .iv-dot.ok {
  fill: var(--ok);
}
.iv-svg .iv-dot.no {
  fill: var(--no);
}
.iv-svg .iv-x,
.iv-svg .iv-y {
  fill: var(--text-faint);
  font-size: 9px;
  font-weight: 600;
}

/* ============================================================
   Статистика
   ============================================================ */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}
.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-sm);
  padding: 18px;
}
.stat.wide {
  grid-column: 1 / -1;
}
.stat .stat-label {
  font-size: 0.82rem;
  color: var(--text-faint);
  font-weight: 600;
  margin-bottom: 6px;
}
.stat .stat-value {
  font-size: 2rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1;
}
.stat .stat-value small {
  font-size: 0.95rem;
  color: var(--text-faint);
  font-weight: 600;
}
.stat-value.ok {
  color: var(--ok);
}
.stat-value.danger,
.stat-value.danger small {
  color: var(--no);
}

.breakdown {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}
.bd {
  flex: 1;
  text-align: center;
  padding: 10px 6px;
  border-radius: 12px;
  background: var(--surface-2);
}
.bd .bd-num {
  font-weight: 800;
  font-size: 1.3rem;
}
.bd .bd-lbl {
  font-size: 0.72rem;
  color: var(--text-faint);
  margin-top: 2px;
}
.bd.new .bd-num {
  color: var(--accent);
}
.bd.learning .bd-num {
  color: var(--warn);
}
.bd.review .bd-num {
  color: var(--ok);
}

.bar {
  height: 10px;
  border-radius: 999px;
  background: var(--surface-3);
  overflow: hidden;
  margin-top: 12px;
}
.bar > span {
  display: block;
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--ok), #4ade80);
}

/* График ответов + слов в библиотеке */
.chart-card {
  margin-bottom: 12px;
  padding: 16px;
}
.chart-periods {
  margin-bottom: 12px;
}
.chart-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 4px;
}
.chart-range {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--text-soft);
  text-align: center;
  flex: 1;
}
.nav-btn {
  flex: none;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-soft);
  font-size: 1.3rem;
  line-height: 1;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}
.nav-btn:hover:not(:disabled) {
  background: var(--surface-3);
  color: var(--text);
}
.nav-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}
.chart-svg {
  display: block;
  width: 100%;
  height: auto;
  margin-top: 4px;
}
.chart-svg .c-bar {
  fill: var(--primary);
}
.chart-svg .c-bar.today {
  fill: var(--accent);
}
.chart-svg .c-line {
  fill: none;
  stroke: var(--warn);
  stroke-width: 2;
  stroke-linejoin: round;
  stroke-linecap: round;
}
.chart-svg .c-dot {
  fill: var(--warn);
}
.chart-svg .c-val {
  fill: var(--text-soft);
  font-size: 9px;
  font-weight: 700;
}
.chart-svg .c-libval {
  fill: var(--warn);
  font-size: 9px;
  font-weight: 800;
}
.chart-svg .c-xlabel {
  fill: var(--text-faint);
  font-size: 9px;
  font-weight: 600;
}
.chart-svg .c-xlabel.today {
  fill: var(--primary-strong);
  font-weight: 800;
}
.chart-legend {
  display: flex;
  justify-content: center;
  gap: 18px;
  margin-top: 8px;
}
.chart-legend .lg {
  font-size: 0.78rem;
  color: var(--text-faint);
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.chart-legend .lg::before {
  content: '';
  width: 12px;
  height: 12px;
  border-radius: 3px;
}
.chart-legend .lg-bars::before {
  background: var(--primary);
}
.chart-legend .lg-line::before {
  border-radius: 999px;
  height: 4px;
  background: var(--warn);
}

/* ============================================================
   Нижняя навигация
   ============================================================ */
.tabbar {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: 0;
  width: 100%;
  max-width: 560px;
  z-index: 30;
  display: flex;
  padding: 8px 12px calc(env(safe-area-inset-bottom) + 8px);
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: saturate(180%) blur(16px);
  -webkit-backdrop-filter: saturate(180%) blur(16px);
  border-top: 1px solid var(--border);
}
.tab {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--text-faint);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 6px 4px;
  cursor: pointer;
  font-size: 0.72rem;
  font-weight: 600;
  border-radius: 12px;
  transition: color 0.15s ease;
}
.tab svg {
  width: 24px;
  height: 24px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.tab.active {
  color: var(--primary-strong);
}

/* ============================================================
   Диалог
   ============================================================ */
.dialog {
  border: none;
  border-radius: var(--radius);
  padding: 0;
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-lg);
  width: min(92vw, 420px);
}
.dialog::backdrop {
  background: rgba(15, 17, 25, 0.5);
  backdrop-filter: blur(3px);
}
.dialog-body {
  padding: 22px;
}
.dialog-body h3 {
  margin: 0 0 16px;
  font-size: 1.2rem;
}
.field {
  display: block;
  margin-bottom: 14px;
}
.field > span {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-soft);
  margin-bottom: 6px;
}
.dialog-actions {
  display: flex;
  gap: 10px;
  margin-top: 6px;
}
.dialog-actions .btn {
  flex: 1;
}

/* ============================================================
   Тосты
   ============================================================ */
.toast-wrap {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 16px);
  z-index: 50;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
  pointer-events: none;
  width: max-content;
  max-width: 90vw;
}
.toast {
  background: #1b1d29;
  color: #fff;
  padding: 11px 18px;
  border-radius: 999px;
  font-size: 0.9rem;
  font-weight: 600;
  box-shadow: var(--shadow-lg);
  animation: toast-in 0.25s ease, toast-out 0.25s ease forwards 2.4s;
}
.toast.ok {
  background: var(--ok);
}
.toast.err {
  background: var(--no);
}
@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}
@keyframes toast-out {
  to {
    opacity: 0;
    transform: translateY(12px);
  }
}

/* ============================================================
   Загрузка / вход / профиль
   ============================================================ */
[hidden] {
  display: none !important;
}

.boot {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-items: center;
}
.spinner {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 3px solid var(--surface-3);
  border-top-color: var(--primary);
  animation: spin 0.8s linear infinite;
}
@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.auth-screen {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px 18px calc(env(safe-area-inset-bottom) + 24px);
}
.auth-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 30px 24px;
}
.brand.center {
  justify-content: center;
  font-size: 1.4rem;
}
.brand.center .brand-mark {
  width: 40px;
  height: 40px;
  font-size: 1.2rem;
}
.auth-sub {
  text-align: center;
  color: var(--text-soft);
  margin: 8px 0 22px;
  font-size: 0.95rem;
}
.auth-tabs {
  margin-bottom: 18px;
}
#auth-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.auth-error {
  color: var(--no);
  background: var(--no-soft);
  border: 1px solid var(--no-border);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 0.9rem;
  font-weight: 600;
  text-align: center;
}

/* Профиль */
.profile-card {
  padding: 22px;
}
.profile-head {
  display: flex;
  align-items: center;
  gap: 14px;
  padding-bottom: 18px;
  margin-bottom: 18px;
  border-bottom: 1px solid var(--border);
}
.avatar {
  width: 52px;
  height: 52px;
  flex: none;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 1.4rem;
  font-weight: 800;
  color: #fff;
  background: linear-gradient(135deg, var(--primary), var(--accent));
}
.profile-email {
  font-weight: 700;
  font-size: 1.05rem;
  word-break: break-all;
}
#profile-form {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
#profile-form .field {
  margin-bottom: 14px;
}
#profile-form .btn {
  margin-top: 4px;
}
#logout-btn {
  margin-top: 12px;
}
select.input {
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238a90a3' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  background-size: 20px;
  padding-right: 42px;
}

/* Переход к архиву из настроек */
.archive-settings-block {
  margin-top: 18px;
  padding-top: 18px;
  border-top: 1px solid var(--border);
}
.archive-settings-block > .hint {
  margin: 5px 0 12px;
}
.settings-link {
  width: 100%;
  min-height: 64px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text);
  text-align: left;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.08s ease;
}
.settings-link:hover {
  background: var(--surface-3);
  border-color: color-mix(in srgb, var(--primary) 35%, var(--border));
}
.settings-link:active {
  transform: scale(0.99);
}
.settings-link-icon {
  width: 38px;
  height: 38px;
  flex: none;
  display: grid;
  place-items: center;
  border-radius: 11px;
  background: var(--primary-soft);
  color: var(--primary-strong);
}
.settings-link-icon svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.settings-link-copy {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.settings-link-title {
  font-weight: 700;
  font-size: 0.96rem;
}
.settings-link-subtitle {
  color: var(--text-faint);
  font-size: 0.78rem;
}
.settings-link-arrow {
  flex: none;
  color: var(--text-faint);
  font-size: 1.7rem;
  line-height: 1;
}

@media (max-width: 390px) {
  .archive-word-row {
    align-items: stretch;
    flex-direction: column;
  }
  .restore-word {
    width: 100%;
  }
}

/* Блок уведомлений */
.notif-block {
  margin-top: 18px;
  padding-top: 18px;
  border-top: 1px solid var(--border);
}
.notif-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}
.notif-info {
  min-width: 0;
}
.notif-title {
  font-weight: 700;
  font-size: 1.02rem;
}
.notif-head .hint {
  margin: 4px 0 0;
}
#notif-cooldown-field {
  margin-top: 14px;
}
#notif-test {
  margin-top: 12px;
}

/* Переключатель */
.switch {
  flex: none;
  position: relative;
  width: 52px;
  height: 30px;
  border-radius: 999px;
  border: none;
  background: var(--surface-3);
  cursor: pointer;
  transition: background 0.2s ease;
  padding: 0;
}
.switch .knob {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #fff;
  box-shadow: var(--shadow-sm);
  transition: transform 0.2s ease;
}
.switch[aria-checked='true'] {
  background: linear-gradient(135deg, var(--primary), var(--primary-strong));
}
.switch[aria-checked='true'] .knob {
  transform: translateX(22px);
}
.switch:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Блок резервной копии */
.backup-block {
  margin-top: 18px;
  padding-top: 18px;
  border-top: 1px solid var(--border);
}
.backup-block .btn {
  margin-top: 6px;
}
.checkline {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 14px 0 4px;
  font-size: 0.92rem;
  color: var(--text-soft);
  cursor: pointer;
}
.checkline input {
  width: 20px;
  height: 20px;
  flex: none;
  accent-color: var(--primary);
  cursor: pointer;
}

/* ============================================================
   Десктоп
   ============================================================ */
@media (min-width: 620px) {
  .app-main {
    padding-top: 20px;
  }
  .study {
    padding: 40px 32px 30px;
  }
}
