/* Все цвета — из темы Telegram (переменные задаёт telegram-web-app.js); значения после запятой — для обычного браузера. */
:root {
  --bg: var(--tg-theme-secondary-bg-color, #f1f2f6);
  --card: var(--tg-theme-section-bg-color, var(--tg-theme-bg-color, #ffffff));
  --text: var(--tg-theme-text-color, #0f1419);
  --hint: var(--tg-theme-hint-color, #5f6672);
  --accent: var(--tg-theme-button-color, #3e43c4);
  --on-accent: var(--tg-theme-button-text-color, #ffffff);
  --link: var(--tg-theme-link-color, var(--tg-theme-accent-text-color, #3e43c4));
  --section-head: var(--tg-theme-section-header-text-color, var(--hint));
  --danger: var(--tg-theme-destructive-text-color, #d14343);
  --line: color-mix(in srgb, var(--hint) 22%, transparent);
  --soft: color-mix(in srgb, var(--accent) 12%, transparent);
  --streak: #e8590c;               /* единственный «свой» цвет: серия дней */
  --streak-soft: color-mix(in srgb, #e8590c 14%, transparent);
  --radius: 16px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", Roboto, "Segoe UI", sans-serif;
  min-height: 100vh;
  padding-bottom: calc(76px + env(safe-area-inset-bottom));
}
button { font: inherit; color: inherit; border: 0; background: none; padding: 0; cursor: pointer; }

#screen { padding: 16px 16px 8px; display: flex; flex-direction: column; gap: 12px; max-width: 560px; margin: 0 auto; }

h1 { margin: 4px 0 0; font-size: 26px; line-height: 1.2; font-weight: 700; }
.head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.chip { display: inline-flex; align-items: center; gap: 4px; height: 32px; padding: 0 12px; border-radius: 16px;
        background: var(--soft); color: var(--link); font-size: 14px; font-weight: 600; white-space: nowrap; }

.card { background: var(--card); border-radius: var(--radius); padding: 16px; display: flex; flex-direction: column; gap: 10px; }
.label { font-size: 13px; font-weight: 600; letter-spacing: .02em; text-transform: uppercase; color: var(--section-head); }
.title { font-size: 18px; font-weight: 700; }
.muted { color: var(--hint); font-size: 14px; }
.small { font-size: 13px; }
.row { display: flex; align-items: center; gap: 12px; }
.grow { flex: 1; min-width: 0; }

.icon { width: 44px; height: 44px; border-radius: 14px; display: flex; align-items: center; justify-content: center; flex-shrink: 0;
        background: var(--soft); color: var(--link); }
.icon.warm { background: var(--streak-soft); color: var(--streak); }
svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

.btn { height: 48px; border-radius: 12px; background: var(--accent); color: var(--on-accent); font-size: 16px; font-weight: 600;
       display: flex; align-items: center; justify-content: center; gap: 8px; width: 100%; }
.btn.secondary { background: var(--soft); color: var(--link); }
.btn:active { opacity: .85; transform: scale(.99); }
.btn[disabled] { opacity: .5; }

.pill { font-size: 12px; font-weight: 600; padding: 3px 8px; border-radius: 10px; }
.pill.todo { color: var(--streak); background: var(--streak-soft); }
.pill.done { color: var(--link); background: var(--soft); }

.week { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 6px; }
.day { display: flex; flex-direction: column; align-items: center; gap: 6px; font-size: 12px; color: var(--hint); }
.dot { width: 32px; height: 32px; border-radius: 16px; background: var(--line); }
.dot.on { background: var(--streak); }
.dot.today { background: transparent; border: 2px solid var(--accent); }
.dot.on.today { background: var(--streak); border-color: var(--streak); }

.bar { height: 8px; border-radius: 4px; background: var(--line); overflow: hidden; }
.bar > i { display: block; height: 100%; border-radius: 4px; background: var(--accent); transition: width .4s ease; }

.stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.stat { background: var(--card); border-radius: 14px; padding: 12px; }
.stat b { display: block; font-size: 22px; }
.scale { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); font-size: 11px; font-weight: 600; color: var(--hint); }
.err { display: flex; align-items: center; gap: 12px; min-height: 44px; }
.count { width: 30px; height: 30px; border-radius: 15px; display: flex; align-items: center; justify-content: center;
         font-weight: 700; font-size: 14px; color: var(--streak); background: var(--streak-soft); flex-shrink: 0; }
.note { background: var(--soft); color: var(--link); border-radius: 14px; padding: 12px 14px; font-size: 13px; }

/* карточки */
.progressline { height: 4px; border-radius: 2px; background: var(--line); overflow: hidden; }
.progressline > i { display: block; height: 100%; background: var(--accent); transition: width .3s ease; }
.flash { min-height: 52vh; background: var(--card); border-radius: 22px; padding: 28px 22px; display: flex; flex-direction: column;
         align-items: center; justify-content: center; gap: 16px; text-align: center; }
.term { font-size: 30px; font-weight: 700; line-height: 1.2; overflow-wrap: anywhere; }
.tr { font-size: 20px; font-weight: 600; }
.ex { font-size: 15px; color: var(--hint); font-style: italic; }
.sep { width: 48px; height: 2px; background: var(--line); }
.grades { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.grade { height: 60px; border-radius: 12px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; }
.grade b { font-size: 15px; }
.grade span { font-size: 12px; opacity: .85; }
.grade.again { background: var(--streak-soft); color: var(--streak); }
.grade.hard { background: var(--line); }
.grade.good { background: var(--accent); color: var(--on-accent); }

.center { text-align: center; padding: 40px 12px; display: flex; flex-direction: column; align-items: center; gap: 12px; }
.big-icon { width: 72px; height: 72px; border-radius: 36px; background: var(--soft); color: var(--link); display: flex; align-items: center; justify-content: center; }
.big-icon svg { width: 36px; height: 36px; }

.skeleton { background: var(--card); border-radius: var(--radius); height: 120px; animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .55; } }

.segs { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; padding: 3px; border-radius: 12px; background: var(--line); }
.seg { height: 36px; border-radius: 9px; font-size: 14px; font-weight: 600; color: var(--hint); }
.seg.on { background: var(--card); color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.08); }
.ipa { font-size: 16px; color: var(--hint); font-family: "Charis SIL", "Doulos SIL", "Lucida Sans Unicode", "Segoe UI", sans-serif; }
.speak { width: 44px; height: 44px; border-radius: 22px; display: flex; align-items: center; justify-content: center; background: var(--soft); color: var(--link); }
.flash { cursor: pointer; }

/* нижние вкладки */
#tabs { position: fixed; left: 0; right: 0; bottom: 0; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr));
        padding: 6px 8px calc(8px + env(safe-area-inset-bottom)); background: var(--card); border-top: 1px solid var(--line); }
#tabs button { min-height: 52px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
               font-size: 11px; color: var(--hint); }
#tabs button[aria-current="page"] { color: var(--link); font-weight: 600; }

@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
