/* Цвета берутся из темы Telegram (светлая/тёмная), для браузера — запасные */
:root {
  --bg: var(--tg-theme-secondary-bg-color, #f1f2f6);
  --card: var(--tg-theme-bg-color, #ffffff);
  --text: var(--tg-theme-text-color, #16171b);
  --hint: var(--tg-theme-hint-color, #8b8e98);
  --accent: var(--tg-theme-button-color, #2f7cf6);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --link: var(--tg-theme-link-color, #2f7cf6);
  --danger: var(--tg-theme-destructive-text-color, #e5484d);
  --green: #1fa855;
  --line: color-mix(in srgb, var(--hint) 22%, transparent);
  --soft: color-mix(in srgb, var(--accent) 10%, var(--card));
  --radius: 22px;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 6px 20px rgba(0,0,0,.05);
  --tab-h: 64px;
  --safe-b: max(env(safe-area-inset-bottom), 10px);
}
@media (prefers-color-scheme: dark) {
  :root:not(.tg) { --bg: #0f1013; --card: #1b1c21; --text: #f2f3f5; --hint: #8a8d96; }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 16px/1.35 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; text-align: left; }
svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
[hidden] { display: none !important; }

#app { padding: 16px 16px calc(var(--tab-h) + var(--safe-b) + 28px); max-width: 560px; margin: 0 auto; }
.screen { animation: fade .22s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ---------- карточки ---------- */
.card {
  display: block; width: 100%; background: var(--card); border-radius: var(--radius);
  padding: 16px 18px; margin-bottom: 12px; box-shadow: var(--shadow);
  transition: transform .12s ease;
}
.card:active { transform: scale(.985); }
.card-label { font-size: 13px; color: var(--hint); font-weight: 500; margin-bottom: 6px; display: flex; gap: 8px; align-items: baseline; }
.hint-inline { font-weight: 400; opacity: .7; margin-left: auto; font-size: 12px; }

/* ---------- главная ---------- */
.hero { display: flex; flex-direction: column; align-items: center; padding: 8px 0 18px; }
.avatar {
  width: 148px; height: 148px; border-radius: 50%; overflow: hidden; position: relative;
  background: var(--card); box-shadow: var(--shadow);
  outline: 3px solid color-mix(in srgb, var(--accent) 35%, transparent); outline-offset: 4px;
  display: grid; place-items: center;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar-empty { display: flex; flex-direction: column; align-items: center; gap: 6px; color: var(--hint); font-size: 13px; }
.avatar-empty svg { width: 30px; height: 30px; }
.greeting { margin-top: 16px; font-size: 22px; font-weight: 700; letter-spacing: -.01em; text-align: center; }
.greeting small { display: block; font-size: 14px; font-weight: 400; color: var(--hint); margin-top: 2px; }

.next-body { display: flex; gap: 14px; align-items: stretch; }
.next-time { min-width: 62px; display: flex; flex-direction: column; justify-content: center; }
.next-time b { font-size: 22px; font-weight: 700; letter-spacing: -.02em; }
.next-time span { font-size: 12px; color: var(--hint); }
.next-info { border-left: 2px solid var(--accent); padding-left: 12px; min-width: 0; }
.next-subject { font-weight: 600; line-height: 1.25; }
.next-meta { font-size: 13px; color: var(--hint); margin-top: 4px; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.next-when { display: inline-block; font-size: 12px; font-weight: 600; color: var(--accent); margin-bottom: 4px; }
.next-when.now { color: var(--green); }
.empty-line { color: var(--hint); }

.word-line { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.word { font-size: 26px; font-weight: 700; letter-spacing: -.02em; }
.pos { font-size: 12px; color: var(--hint); font-style: italic; }
.translation { font-size: 17px; margin-top: 2px; }
.example { font-size: 13px; color: var(--hint); margin-top: 8px; font-style: italic; }
.card-word.flip .word, .card-word.flip .translation { animation: fade .25s ease; }

.card-note { min-height: 108px; background: var(--soft); }
.note-cta { display: flex; align-items: center; gap: 10px; font-size: 19px; font-weight: 600; color: var(--accent); }
.note-last { margin-top: 10px; font-size: 14px; color: var(--hint); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

.badge { display: inline-block; font-size: 11px; font-weight: 600; padding: 2px 7px; border-radius: 99px; background: var(--line); color: var(--text); white-space: nowrap; }
.badge.t-l { background: #2f7cf622; color: #2f7cf6; }
.badge.t-p { background: #1fa85522; color: #1fa855; }
.badge.t-lab { background: #9b5cf622; color: #9b5cf6; }
.badge.t-s { background: #f59e0b22; color: #d98a06; }

/* ---------- шапки экранов ---------- */
.screen-head { display: flex; align-items: center; justify-content: space-between; margin: 4px 2px 14px; }
.screen-head h1 { font-size: 28px; margin: 0; letter-spacing: -.02em; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center;
  background: var(--accent); color: var(--accent-text); box-shadow: var(--shadow);
}
.icon-btn:active { transform: scale(.94); }

/* ---------- расписание ---------- */
.week-nav { display: flex; align-items: center; justify-content: space-between; background: var(--card); border-radius: 16px; padding: 6px; margin-bottom: 10px; box-shadow: var(--shadow); }
.week-nav button { width: 40px; height: 40px; border-radius: 12px; font-size: 26px; line-height: 1; color: var(--accent); display: grid; place-items: center; }
.week-nav button:active { background: var(--line); }
.wk-label { text-align: center; }
.wk-label b { display: block; font-size: 16px; }
.wk-label span { font-size: 12px; color: var(--hint); }
.swap-weeks { display: block; margin: 14px auto 0; font-size: 13px; color: var(--hint); text-decoration: underline; text-underline-offset: 3px; text-align: center; }
.days { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; margin-bottom: 12px; scrollbar-width: none; }
.days::-webkit-scrollbar { display: none; }
.days button {
  flex: 1 0 44px; min-width: 44px; padding: 8px 0 7px; border-radius: 14px; background: var(--card);
  text-align: center; font-weight: 600; font-size: 14px; position: relative;
}
.days button small { display: block; font-size: 10px; font-weight: 500; color: var(--hint); margin-top: 1px; }
.days button.active { background: var(--accent); color: var(--accent-text); }
.days button.active small { color: inherit; opacity: .8; }
.days button.today::after { content: ""; position: absolute; left: 50%; bottom: 3px; width: 4px; height: 4px; margin-left: -2px; border-radius: 50%; background: currentColor; opacity: .6; }
.day-title { font-size: 20px; font-weight: 700; margin: 6px 2px 10px; }
.lessons { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.lesson { display: flex; gap: 14px; width: 100%; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.lesson:last-child { border-bottom: 0; }
.lesson:active { background: var(--line); }
.lesson-time { min-width: 50px; font-variant-numeric: tabular-nums; }
.lesson-time b { display: block; font-size: 16px; }
.lesson-time span { font-size: 12px; color: var(--hint); }
.lesson-main { min-width: 0; flex: 1; }
.lesson-subject { font-weight: 600; line-height: 1.25; }
.lesson-meta { font-size: 13px; color: var(--hint); margin-top: 4px; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.lesson.now { background: color-mix(in srgb, var(--green) 9%, transparent); box-shadow: inset 3px 0 0 var(--green); }
.lesson.past { opacity: .5; }
.empty { padding: 34px 20px; text-align: center; color: var(--hint); }
.empty b { display: block; color: var(--text); font-size: 17px; margin-bottom: 4px; }

/* ---------- Instagram ---------- */
.profiles { display: flex; flex-direction: column; gap: 10px; }
.profile {
  display: flex; align-items: center; gap: 14px; width: 100%; background: var(--card);
  border-radius: var(--radius); padding: 12px 16px; box-shadow: var(--shadow);
}
.profile:active { transform: scale(.985); }
.pic {
  width: 52px; height: 52px; border-radius: 50%; flex: none; padding: 2px;
  background: conic-gradient(from 200deg, #feda75, #fa7e1e, #d62976, #962fbf, #4f5bd5, #feda75);
}
.pic > * { width: 100%; height: 100%; border-radius: 50%; border: 2px solid var(--card); object-fit: cover; display: grid; place-items: center; background: var(--soft); font-weight: 700; color: var(--accent); font-size: 20px; }
.pic.big { width: 88px; height: 88px; }
.pic.big > * { font-size: 34px; border-width: 3px; }
.profile-name { font-weight: 600; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.profile-stats { text-align: right; font-size: 13px; color: var(--hint); line-height: 1.4; }
.profile-stats b { color: var(--text); font-weight: 600; }
.plus { color: var(--green); font-weight: 700; }
.pending { font-size: 13px; color: var(--hint); display: flex; gap: 6px; align-items: center; }
.spinner { width: 14px; height: 14px; border: 2px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.profile-head { display: flex; flex-direction: column; align-items: center; text-align: center; padding: 6px 0 14px; }
.profile-head h2 { margin: 10px 0 2px; font-size: 22px; letter-spacing: -.01em; }
.profile-head .sub { color: var(--hint); font-size: 14px; }
.profile-actions { display: flex; gap: 8px; margin-top: 14px; flex-wrap: wrap; justify-content: center; }
.btn { padding: 10px 16px; border-radius: 14px; background: var(--accent); color: var(--accent-text); font-weight: 600; font-size: 15px; text-align: center; }
.btn.ghost { background: var(--card); color: var(--text); box-shadow: var(--shadow); }
.btn.danger { background: transparent; color: var(--danger); }
.btn.wide { width: 100%; padding: 14px; }
.btn:active { opacity: .8; }
.btn[disabled] { opacity: .5; }

.hl-title { font-weight: 700; margin: 18px 2px 8px; display: flex; justify-content: space-between; align-items: baseline; }
.hl-title span { font-weight: 400; color: var(--hint); font-size: 13px; }
.gallery-count { font-size: 13px; color: var(--hint); margin: 18px 2px 8px; font-weight: 600; }
.gallery-count span { font-weight: 400; }
.grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 2px; margin: 0 -16px; }
.tile { aspect-ratio: 1; background: var(--line); position: relative; overflow: hidden; }
.tile img { width: 100%; height: 100%; object-fit: cover; display: block; }
.tile .vid { position: absolute; right: 6px; top: 6px; width: 20px; height: 20px; color: #fff; filter: drop-shadow(0 1px 2px rgba(0,0,0,.6)); }
.tile .vid svg { width: 20px; height: 20px; fill: #fff; stroke: none; }

/* ---------- нижнее меню ---------- */
.tabbar {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: var(--safe-b);
  width: min(calc(100% - 32px), 420px); height: var(--tab-h);
  display: flex; justify-content: space-around; align-items: center;
  background: color-mix(in srgb, var(--card) 86%, transparent);
  backdrop-filter: blur(18px); -webkit-backdrop-filter: blur(18px);
  border-radius: 999px; box-shadow: 0 8px 30px rgba(0,0,0,.12); z-index: 20;
}
.tabbar button { width: 64px; height: 48px; border-radius: 999px; display: grid; place-items: center; color: var(--hint); transition: background .2s, color .2s; }
.tabbar button.active { background: var(--soft); color: var(--accent); }
.tabbar svg { width: 26px; height: 26px; }
.tabbar .dot { fill: currentColor; }
.tabbar button { position: relative; }
.tab-badge { position: absolute; top: 2px; right: 8px; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px;
  background: var(--green); color: #fff; font-size: 11px; font-weight: 700; display: grid; place-items: center; }

/* ---------- панель снизу ---------- */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 40; animation: fadeIn .2s; }
@keyframes fadeIn { from { opacity: 0; } }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 41; max-height: 88vh; overflow-y: auto;
  background: var(--card); border-radius: 24px 24px 0 0; padding: 8px 18px calc(var(--safe-b) + 14px);
  animation: up .26s cubic-bezier(.2,.8,.2,1);
  max-width: 560px; margin: 0 auto;
}
@keyframes up { from { transform: translateY(100%); } }
.sheet-grip { width: 38px; height: 5px; border-radius: 3px; background: var(--line); margin: 2px auto 12px; }
.sheet h3 { margin: 0 0 12px; font-size: 20px; }
.field { display: block; margin-bottom: 10px; }
.field span { display: block; font-size: 12px; color: var(--hint); margin: 0 0 4px 4px; }
.field input, .field select, textarea {
  width: 100%; font: inherit; color: var(--text); background: var(--bg); border: 1px solid transparent;
  border-radius: 14px; padding: 12px 14px; outline: none; -webkit-appearance: none; appearance: none;
}
.field input:focus, textarea:focus, .field select:focus { border-color: var(--accent); }
.row { display: flex; gap: 10px; }
.row > * { flex: 1; min-width: 0; }
textarea { min-height: 130px; resize: vertical; line-height: 1.4; }
.sheet .btn { margin-top: 6px; }
.notes-list { margin-top: 18px; }
.notes-list h4 { margin: 0 0 8px 2px; font-size: 13px; color: var(--hint); font-weight: 500; }
.note { background: var(--bg); border-radius: 14px; padding: 10px 12px; margin-bottom: 8px; display: flex; gap: 10px; align-items: flex-start; }
.note-text { flex: 1; white-space: pre-wrap; word-break: break-word; font-size: 15px; }
.note-date { font-size: 11px; color: var(--hint); margin-top: 4px; }
.note-del { color: var(--hint); font-size: 18px; line-height: 1; padding: 2px 4px; }

/* ---------- просмотр медиа ---------- */
.viewer { position: fixed; inset: 0; background: #000; z-index: 60; display: flex; flex-direction: column; }
.viewer-top { display: flex; justify-content: space-between; align-items: center; color: #fff; padding: calc(env(safe-area-inset-top) + 10px) 14px 10px; font-size: 14px; }
.viewer-close { color: #fff; font-size: 20px; width: 36px; height: 36px; border-radius: 50%; background: rgba(255,255,255,.14); display: grid; place-items: center; }
.viewer-stage { flex: 1; display: grid; place-items: center; min-height: 0; }
.viewer-stage img, .viewer-stage video { max-width: 100%; max-height: 100%; object-fit: contain; }
.viewer-stage .msg { color: #bbb; text-align: center; padding: 20px; }
.viewer-nav { position: absolute; top: 50%; width: 44px; height: 64px; margin-top: -32px; color: #fff; font-size: 38px; text-align: center; opacity: .7; }
.viewer-nav.prev { left: 0; }
.viewer-nav.next { right: 0; }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--tab-h) + var(--safe-b) + 16px);
  background: rgba(20,20,24,.92); color: #fff; padding: 11px 16px; border-radius: 14px; font-size: 14px;
  z-index: 70; max-width: calc(100% - 32px); box-shadow: 0 6px 24px rgba(0,0,0,.2); animation: fadeIn .2s;
}
.blocker { position: fixed; inset: 0; z-index: 80; background: var(--bg); display: grid; place-items: center; padding: 30px; text-align: center; color: var(--hint); }
.blocker b { display: block; color: var(--text); font-size: 18px; margin-bottom: 6px; }
.skeleton { height: 44px; border-radius: 12px; background: linear-gradient(90deg, var(--line), transparent, var(--line)); background-size: 200% 100%; animation: shimmer 1.2s infinite; width: 100%; }
@keyframes shimmer { to { background-position: -200% 0; } }
