/* Sayvaa mini app — вся палитра приходит из темы Telegram (--tg-theme-*).
   Локальные значения — только запасные, на случай запуска вне клиента. */

:root {
  color-scheme: light dark;

  --bg: var(--tg-theme-bg-color, #ffffff);
  --card: var(--tg-theme-secondary-bg-color, #f1f3f7);
  --text: var(--tg-theme-text-color, #0f141b);
  --muted: var(--tg-theme-hint-color, #78838f);
  --accent: var(--tg-theme-button-color, #2f7ef4);
  --on-accent: var(--tg-theme-button-text-color, #ffffff);
  --danger: var(--tg-theme-destructive-text-color, #e5484d);

  --radius: 18px;
  --radius-sm: 12px;

  /* Производные оттенки. Без color-mix всё схлопывается в чистый акцент —
     высота столбика продолжает нести значение, поэтому график остаётся читаемым. */
  --line: rgba(125, 136, 150, .24);
  --rail: rgba(125, 136, 150, .18);
  --wash: var(--card);
  --fill-1: var(--accent);
  --fill-2: var(--accent);
  --fill-3: var(--accent);
  --fill-4: var(--accent);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: var(--tg-theme-bg-color, #17212b);
    --card: var(--tg-theme-secondary-bg-color, #222e3c);
    --text: var(--tg-theme-text-color, #f4f7fa);
    --muted: var(--tg-theme-hint-color, #8b97a5);
    --accent: var(--tg-theme-button-color, #4c9ce2);
    --on-accent: var(--tg-theme-button-text-color, #ffffff);
    --danger: var(--tg-theme-destructive-text-color, #ff6b6b);
  }
}

@supports (color: color-mix(in oklab, red, blue)) {
  :root {
    --line: color-mix(in oklab, var(--text) 13%, transparent);
    --rail: color-mix(in oklab, var(--text) 9%, var(--card));
    --wash: color-mix(in oklab, var(--accent) 12%, var(--card));
    --fill-1: color-mix(in oklab, var(--accent) 30%, var(--card));
    --fill-2: color-mix(in oklab, var(--accent) 55%, var(--card));
    --fill-3: color-mix(in oklab, var(--accent) 78%, var(--card));
    --fill-4: var(--accent);
  }
}

* { box-sizing: border-box; }

/* Правило браузера [hidden]{display:none} слабее любого авторского класса
   с display (.list, .avatar-fallback), поэтому скрытие через атрибут hidden
   ломалось: заглушка аватара висела поверх фотографии, а списки слов и фраз
   показывались одновременно. Здесь возвращаем атрибуту его смысл. */
[hidden] { display: none !important; }

body {
  margin: 0;
  padding: 18px 16px calc(84px + env(safe-area-inset-bottom));
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI",
        Roboto, system-ui, sans-serif;
  -webkit-text-size-adjust: 100%;
  overflow-x: hidden;
}

/* --- Три регистра одной гарнитуры: заголовок, текст, служебные капсы --- */

h1 {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -.02em;
  margin: 0;
}

h2, .eyebrow {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .09em;
  margin: 0 0 10px;
  color: var(--muted);
}

.muted { color: var(--muted); margin: 3px 0 0; font-size: 13px; }
.note { margin: 10px 2px 0; font-size: 13px; line-height: 1.4; }
.center { text-align: center; padding: 56px 12px; }
.error { color: var(--danger); }

button, input { font: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* --- Профиль --- */

.profile { display: flex; gap: 14px; align-items: center; margin-bottom: 20px; }
.profile-text { min-width: 0; }
.profile-text h1 { overflow-wrap: anywhere; }

.avatar {
  width: 60px; height: 60px; flex: none;
  border-radius: 50%; object-fit: cover;
  background: var(--card);
}
.avatar-fallback {
  display: grid; place-items: center;
  background: var(--wash); color: var(--accent);
  font-size: 24px; font-weight: 700; letter-spacing: -.02em;
}

.streak-card {
  background: var(--accent);
  color: var(--on-accent);
  border-radius: var(--radius);
  padding: 22px 22px 20px;
}
.streak-card .eyebrow { color: inherit; opacity: .8; margin: 0; }
.streak-number {
  font-size: clamp(54px, 19vw, 76px);
  font-weight: 700;
  letter-spacing: -.045em;
  line-height: .92;
  margin: 8px 0 0;
}
.streak-caption {
  margin: 6px 0 0;
  font-size: 14px;
  line-height: 1.35;
  opacity: .88;
  max-width: 22em;
}

.block { margin-top: 26px; }

.levels { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.level-btn {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 10px 17px;
  font-size: 15px; font-weight: 600; letter-spacing: .02em;
  background: transparent; color: var(--text);
  cursor: pointer;
}
.level-btn[aria-pressed="true"] {
  background: var(--accent); border-color: var(--accent);
  color: var(--on-accent);
}

/* --- Плитки статистики --- */

.tiles { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.tile {
  background: var(--card);
  border-radius: var(--radius);
  padding: 14px 15px 15px;
  display: flex; flex-direction: column; gap: 2px;
  min-width: 0;
}
.tile .value {
  font-size: 27px; font-weight: 700; letter-spacing: -.025em; line-height: 1.1;
}
.tile .unit { font-size: 17px; font-weight: 600; margin-left: 1px; }
.tile .label { color: var(--muted); font-size: 12.5px; line-height: 1.3; }

/* Доля от предела — трек из того же цвета, что и заливка. */
.meter { height: 4px; border-radius: 999px; background: var(--rail); margin-top: 9px; }
.meter i { display: block; height: 100%; border-radius: 999px; background: var(--accent); }

/* --- Полоса активности --- */

.chart {
  background: var(--card);
  border-radius: var(--radius);
  padding: 14px 14px 12px;
}
.activity {
  display: flex; align-items: flex-end; gap: 2px;
  height: 52px;
}
.activity .cell {
  flex: 1 1 0; min-width: 0; height: 100%;
  border-radius: 999px;
  background: linear-gradient(to top,
              var(--fill) var(--h, 0%), var(--rail) var(--h, 0%));
}
.cell { --fill: var(--fill-4); }
.cell[data-bin="0"] { --fill: var(--rail); }
.cell[data-bin="1"] { --fill: var(--fill-1); }
.cell[data-bin="2"] { --fill: var(--fill-2); }
.cell[data-bin="3"] { --fill: var(--fill-3); }
.cell[data-bin="4"] { --fill: var(--fill-4); }
.activity .cell[data-active] { box-shadow: 0 0 0 2px var(--card), 0 0 0 3.5px var(--accent); }

.axis {
  margin: 10px 0 0;
  font-size: 12px; color: var(--muted);
  font-variant-numeric: tabular-nums;
  min-height: 1.35em;
}
.scale {
  display: flex; align-items: center; gap: 3px;
  margin-top: 8px;
  font-size: 11px; color: var(--muted);
}
.scale span:first-child { margin-right: 3px; }
.scale span:last-child { margin-left: 3px; }
.scale .cell {
  width: 12px; height: 12px; border-radius: 3px;
  background: var(--fill);
}

/* --- Словарь --- */

.segmented {
  display: flex; gap: 4px;
  background: var(--card); padding: 3px;
  border-radius: var(--radius-sm);
  margin-bottom: 14px;
}
.seg {
  flex: 1; border: 0; background: none; color: var(--muted);
  padding: 9px; border-radius: 10px; font-size: 14px; cursor: pointer;
}
.seg.active { background: var(--bg); color: var(--text); font-weight: 600; }

.add-form { display: grid; grid-template-columns: 1fr 1fr 48px; gap: 8px; }
.add-form input {
  border: 1px solid var(--line); background: var(--card); color: var(--text);
  border-radius: var(--radius-sm); padding: 11px 13px; font-size: 16px;
  min-width: 0;
}
.add-form input::placeholder { color: var(--muted); }
.add-form button {
  border: 0; background: var(--accent); color: var(--on-accent);
  border-radius: var(--radius-sm); display: grid; place-items: center;
  cursor: pointer; padding: 0;
}
.add-form button svg { width: 22px; height: 22px; }
.add-form button:disabled { opacity: .5; }

.list { list-style: none; margin: 16px 0 0; padding: 0; display: grid; gap: 8px; }
.list li {
  background: var(--card); border-radius: var(--radius);
  padding: 13px 14px; display: flex; gap: 10px; align-items: flex-start;
  -webkit-tap-highlight-color: transparent;
}
.list li.pressing { background: var(--wash); }
.list .body { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.list .term { font-weight: 600; letter-spacing: -.005em; }
.list .sub { color: var(--muted); font-size: 13.5px; margin-top: 1px; }
.list .example {
  color: var(--muted); font-size: 13px; line-height: 1.4;
  margin-top: 7px; padding-left: 9px;
  border-left: 2px solid var(--line);
}
.list .said {
  color: var(--muted); font-size: 13px; margin-top: 3px;
  text-decoration: line-through; text-decoration-color: var(--line);
}
.list .empty { color: var(--muted); font-size: 13.5px; line-height: 1.45; }
.tag {
  font-size: 10px; font-weight: 600; text-transform: uppercase; letter-spacing: .07em;
  color: var(--muted); margin-top: 6px; display: inline-block;
}
.remove {
  border: 0; background: none; color: var(--muted);
  font-size: 17px; line-height: 1; cursor: pointer;
  padding: 4px 2px; margin: -4px -2px;
  flex: none;
}

/* --- Состояния --- */

.busy { opacity: .55; transition: opacity .15s ease; }
.dots { display: flex; gap: 4px; justify-content: center; margin-bottom: 12px; }
.dots i {
  width: 6px; height: 6px; border-radius: 50%; background: var(--muted);
  animation: pulse 1.1s ease-in-out infinite;
}
.dots i:nth-child(2) { animation-delay: .18s; }
.dots i:nth-child(3) { animation-delay: .36s; }
@keyframes pulse { 0%, 100% { opacity: .25; } 50% { opacity: 1; } }

.ghost-btn {
  margin-top: 14px; border: 1px solid var(--line); background: none;
  color: var(--text); border-radius: var(--radius-sm);
  padding: 10px 18px; cursor: pointer;
}

.toast {
  position: fixed; left: 16px; right: 16px;
  bottom: calc(80px + env(safe-area-inset-bottom));
  margin: 0; padding: 12px 14px;
  background: var(--text); color: var(--bg);
  border-radius: var(--radius-sm); font-size: 13.5px; text-align: center;
  z-index: 2;
}

/* --- Нижняя навигация --- */

.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 3;
  display: grid; grid-template-columns: repeat(3, 1fr);
  background: var(--bg); border-top: 1px solid var(--line);
  padding: 4px 0 calc(4px + env(safe-area-inset-bottom));
}
.tab {
  border: 0; background: none; color: var(--muted);
  display: grid; justify-items: center; gap: 3px;
  padding: 8px 2px; min-height: 48px; cursor: pointer;
}
.tab svg { width: 23px; height: 23px; }
.tab span { font-size: 11px; letter-spacing: .01em; }
.tab.active { color: var(--accent); }

svg { fill: none; stroke: currentColor; stroke-width: 1.7;
      stroke-linecap: round; stroke-linejoin: round; }

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}
