/* Apple-стиль: сгруппированные скруглённые карточки, крупные заголовки, «жидкое стекло» на таббаре */
:root {
  --page: var(--tg-theme-secondary-bg-color, #f2f2f7);
  --card: var(--tg-theme-section-bg-color, var(--tg-theme-bg-color, #ffffff));
  --text: var(--tg-theme-text-color, #000000);
  --hint: var(--tg-theme-hint-color, #8e8e93);
  /* Второй цвет интерфейса — rgb(79, 174, 173) */
  --brand: #4faead;
  --accent: var(--brand);          /* заливки: прогресс, обводка текущей пары */
  --accent-strong: #3a9695;        /* заливки с белым текстом: кнопки, сегодняшний день */
  --accent-ink: #2a7a79;           /* текст и иконки акцентного цвета (контраст ≥ 4.5) */
  --accent-text: #ffffff;
  --danger: var(--tg-theme-destructive-text-color, #ff3b30);
  --sep: rgba(60, 60, 67, .16);
  --fill: rgba(118, 118, 128, .12);
  --tint: rgba(79, 174, 173, .16);
  --seg-on: #ffffff;

  --glass-tint: rgba(255, 255, 255, .5);
  --glass-hi: rgba(255, 255, 255, .7);
  --glass-rim: rgba(255, 255, 255, .95);
  --glass-shadow: 0 10px 30px rgba(0, 0, 0, .12), 0 1px 3px rgba(0, 0, 0, .06);
  --glass-sel: rgba(118, 118, 128, .14);

  --r-card: 22px;
  --gutter: 16px;
  --safe-bottom: max(env(safe-area-inset-bottom), var(--tg-safe-area-inset-bottom, 0px));
  --spring: cubic-bezier(.32, 1.35, .5, 1);
}
:root[data-scheme=dark] {
  --accent-ink: #6cc9c8;
  --tint: rgba(79, 174, 173, .22);
  --sep: rgba(84, 84, 88, .55);
  --fill: rgba(118, 118, 128, .24);
  --seg-on: #636366;
  --glass-tint: rgba(44, 44, 48, .5);
  --glass-hi: rgba(255, 255, 255, .14);
  --glass-rim: rgba(255, 255, 255, .35);
  --glass-shadow: 0 10px 30px rgba(0, 0, 0, .5), 0 1px 3px rgba(0, 0, 0, .3);
  --glass-sel: rgba(255, 255, 255, .14);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--page);
  color: var(--text);
  font: 17px/1.35 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  letter-spacing: -.01em;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; letter-spacing: inherit; }
main { padding: 0 var(--gutter) calc(112px + var(--safe-bottom)); }
[hidden] { display: none !important; }
.icon { width: 22px; height: 22px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.message { text-align: center; padding: 30vh 12px 0; color: var(--hint); }
.message b { display: block; color: var(--text); font-size: 22px; margin-bottom: 8px; }

h1 { margin: 4px 0 2px; font-size: 34px; line-height: 1.12; font-weight: 700; letter-spacing: -.025em; }
.screen-title { padding: 24px 4px 4px; }

/* --- «жидкое стекло» --- */
.glass {
  position: relative;
  background: var(--glass-tint);
  -webkit-backdrop-filter: blur(18px) saturate(190%);
  backdrop-filter: blur(18px) saturate(190%);
  box-shadow: inset 0 1px 0 var(--glass-hi), inset 0 -1px 0 rgba(255, 255, 255, .06);
}
/* Внешнюю тень вешаем на обёртку: тень на самом стекле (и даже на его потомках) сдвигает
   координаты фильтра преломления в Chromium */
/* Блик по краю: тонкое кольцо с градиентом, как свет на кромке стекла */
.glass::before {
  content: ""; position: absolute; inset: 0; border-radius: inherit; padding: 1px; pointer-events: none;
  background: linear-gradient(140deg, var(--glass-rim), transparent 32%, transparent 68%, var(--glass-hi));
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor;
  mask: linear-gradient(#000 0 0) content-box exclude, linear-gradient(#000 0 0);
}
/* Настоящее преломление — там, где браузер умеет SVG-фильтры в backdrop-filter */
.glass.refract {
  -webkit-backdrop-filter: url(#lg-refract) blur(6px) saturate(190%) brightness(1.04);
  backdrop-filter: url(#lg-refract) blur(6px) saturate(190%) brightness(1.04);
}

/* --- таббар --- */
.tabbar-wrap {
  position: fixed; z-index: 20; left: var(--gutter); right: var(--gutter);
  bottom: calc(10px + var(--safe-bottom)); max-width: 440px; margin: 0 auto;
  border-radius: 34px; box-shadow: var(--glass-shadow);
}
.tabbar { display: flex; padding: 5px; border-radius: 34px; }
.tabbar button {
  position: relative; z-index: 1; flex: 1; height: 56px; border-radius: 28px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--text); font-size: 10.5px; font-weight: 600; letter-spacing: 0;
  transition: color .25s, transform .2s;
}
.tabbar button:active { transform: scale(.94); }
.tabbar button.active { color: var(--accent-ink); }
.tabbar .icon { width: 25px; height: 25px; }
.tab-indicator {
  position: absolute; z-index: 0; top: 5px; bottom: 5px; left: 0; width: 0; border-radius: 28px;
  background: var(--glass-sel);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .35);
  /* Двигаем только transform — его анимирует видеокарта, без пересчёта вёрстки */
  will-change: transform;
}

/* --- шапка: студент и университет --- */
.day-head { padding: 18px 4px 14px; }
.profile { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.who { min-width: 0; }
.surname { font-size: 32px; font-weight: 800; line-height: 1.08; letter-spacing: -.03em; overflow-wrap: anywhere; }
.given { font-size: 22px; font-weight: 600; line-height: 1.2; letter-spacing: -.02em; margin-top: 2px; opacity: .78; }
.logo {
  flex: none; width: 72px; height: 72px; background: var(--text);
  -webkit-mask: url(logo.png) center / contain no-repeat; mask: url(logo.png) center / contain no-repeat;
}
.title-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 26px; }
.title-row h1 { margin: 0; min-width: 0; }
.group-name, .group-select {
  color: var(--accent-ink); font-size: 13px; font-weight: 700; letter-spacing: .03em; text-transform: uppercase;
}
.group-name { flex: none; max-width: 48%; text-align: right; line-height: 1.25; }
.group-pick { flex: none; max-width: 48%; display: flex; align-items: center; gap: 2px; color: var(--accent-ink); }
.group-pick .icon { width: 15px; height: 15px; pointer-events: none; }
.group-select {
  min-width: 0; max-width: 100%; appearance: none; -webkit-appearance: none; border: 0; background: none;
  padding: 0; font-family: inherit; text-align: right;
}
.sub-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 2px; min-height: 30px; }
.pill-btn {
  height: 30px; padding: 0 14px; border-radius: 15px; font-size: 15px; font-weight: 600;
  background: var(--tint); color: var(--accent-ink); flex: none;
}
.day-sub { color: var(--hint); font-size: 15px; min-width: 0; }

/* --- неделя --- */
.week { display: flex; align-items: center; margin: 0 -6px 14px; }
.chev { width: 30px; height: 46px; display: grid; place-items: center; color: var(--hint); flex: none; }
.chev .icon { width: 20px; height: 20px; }
.days { flex: 1; display: flex; justify-content: space-between; }
.day { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 2px 0; }
.day .wd { font-size: 11px; font-weight: 600; color: var(--hint); text-transform: uppercase; }
.day .dn {
  width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center;
  font-size: 19px; font-weight: 500; font-variant-numeric: tabular-nums;
  transition: background .25s, color .25s, transform .35s var(--spring);
}
.day.empty .dn { color: var(--hint); }
.day.today .dn { color: var(--accent-ink); font-weight: 600; }
.day.active .dn { background: var(--text); color: var(--card); font-weight: 600; transform: scale(1.04); }
.day.today.active .dn { background: var(--accent-strong); color: var(--accent-text); }

/* --- пары --- */
.lessons { touch-action: pan-y; min-height: 50vh; }
.lesson {
  display: grid; grid-template-columns: 52px 1fr; gap: 14px;
  background: var(--card); border-radius: var(--r-card); padding: 16px 18px;
}
.lesson .time { font-variant-numeric: tabular-nums; line-height: 1.3; padding-top: 1px; }
.lesson .time b { display: block; font-size: 17px; font-weight: 600; }
.lesson .time span { color: var(--hint); font-size: 15px; }
.lesson .subject { font-size: 17px; font-weight: 600; line-height: 1.3; }
.lesson .meta { display: flex; flex-wrap: wrap; align-items: center; gap: 2px 6px; color: var(--hint); font-size: 14px; margin-top: 4px; }
.lesson .meta .sep::before { content: "·"; }
.lesson .kind { display: inline-flex; align-items: center; gap: 4px; }
.lesson .kind .icon { width: 16px; height: 16px; stroke-width: 1.7; }

.lesson.past { opacity: .5; }
.lesson.now { box-shadow: 0 0 0 2px var(--accent); }
.lesson.now .time b { color: var(--accent-ink); }
.progress { margin-top: 12px; display: flex; align-items: center; gap: 10px; color: var(--accent-ink); font-size: 13px; font-weight: 600; }
.progress .track { flex: 1; height: 6px; border-radius: 3px; background: var(--fill); overflow: hidden; }
.progress .fill { height: 100%; background: var(--accent); border-radius: 3px; transition: width .6s var(--spring); }
.soon {
  display: inline-block; margin-top: 10px; padding: 3px 10px; border-radius: 11px;
  background: var(--fill); font-size: 13px; font-weight: 600;
}

.gap { text-align: center; color: var(--hint); font-size: 13px; padding: 9px 0; }
.gap.window span {
  display: inline-block; padding: 4px 12px; border-radius: 13px; margin: 4px 0;
  background: var(--fill); color: var(--text); font-weight: 600;
}
.lesson + .lesson { margin-top: 10px; }

.empty-day { background: var(--card); border-radius: var(--r-card); padding: 48px 20px; text-align: center; color: var(--hint); }
.empty-day b { display: block; color: var(--text); font-size: 20px; font-weight: 600; margin-bottom: 4px; }

.slide-next { animation: slide-next .35s var(--spring); }
.slide-prev { animation: slide-prev .35s var(--spring); }
@keyframes slide-next { from { opacity: 0; transform: translateX(36px); } }
@keyframes slide-prev { from { opacity: 0; transform: translateX(-36px); } }
@media (prefers-reduced-motion: reduce) {
  .slide-next, .slide-prev { animation: none; }
  .day .dn { transition: none; }
}

/* --- сгруппированные списки (как «Настройки» в iOS) --- */
.group { margin-top: 24px; }
.group-title { color: var(--hint); font-size: 13px; text-transform: uppercase; letter-spacing: .02em; padding: 0 16px 7px; }
.group-note { color: var(--hint); font-size: 13px; line-height: 1.4; padding: 7px 16px 0; }
.card { background: var(--card); border-radius: var(--r-card); overflow: hidden; }
.row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  min-height: 52px; padding: 8px 16px; position: relative;
}
.row + .row::before { content: ""; position: absolute; top: 0; left: 16px; right: 0; height: 1px; background: var(--sep); transform: scaleY(.6); }
.row > .label { flex: 1; min-width: 0; }
.status { color: var(--hint); font-size: 13px; text-align: center; padding-top: 18px; min-height: 40px; }

.switch { position: relative; width: 51px; height: 31px; flex: none; }
.switch input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; z-index: 1; }
.switch .track { position: absolute; inset: 0; border-radius: 16px; background: var(--fill); transition: background .25s; }
.switch .track::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 27px; height: 27px; border-radius: 50%;
  background: #fff; box-shadow: 0 3px 8px rgba(0, 0, 0, .15), 0 3px 1px rgba(0, 0, 0, .06);
  transition: transform .35s var(--spring);
}
.switch input:checked + .track { background: var(--accent); }
.switch input:checked + .track::after { transform: translateX(20px); }

.segmented {
  display: inline-grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 2px;
  padding: 2px; border-radius: 9px; background: var(--fill);
}
.segmented button {
  min-width: 40px; height: 28px; padding: 0 10px; border-radius: 7px; font-size: 13px; font-weight: 500;
  transition: background .2s, box-shadow .2s;
}
.segmented button.on { background: var(--seg-on); font-weight: 600; box-shadow: 0 3px 8px rgba(0, 0, 0, .12), 0 1px 1px rgba(0, 0, 0, .04); }

input, select, textarea {
  font: inherit; color: var(--text); background: var(--fill); border: 0; border-radius: 10px;
  padding: 7px 10px; min-width: 0; outline: none; letter-spacing: inherit;
}
input[type=time], input[type=date] { font-variant-numeric: tabular-nums; }
input:focus, select:focus { box-shadow: 0 0 0 3px var(--tint); }

.btn {
  height: 50px; padding: 0 22px; border-radius: 25px; font-weight: 600;
  background: var(--accent-strong); color: var(--accent-text); transition: transform .2s, opacity .2s;
}
.btn:active { transform: scale(.97); }
.btn.tinted { background: var(--tint); color: var(--accent-ink); }
.btn.small { height: 32px; padding: 0 14px; font-size: 15px; border-radius: 16px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .4; }
.icon-btn { width: 34px; height: 34px; border-radius: 17px; display: grid; place-items: center; color: var(--accent-ink); flex: none; background: var(--fill); }
.icon-btn .icon { width: 17px; height: 17px; }
.icon-btn.danger { color: var(--danger); }

/* --- админка --- */
details.block { background: var(--card); border-radius: var(--r-card); margin-top: 12px; overflow: hidden; }
details.block > summary {
  list-style: none; display: flex; align-items: center; gap: 12px; min-height: 56px; padding: 0 16px;
  font-weight: 500; cursor: pointer;
}
details.block > summary::-webkit-details-marker { display: none; }
details.block > summary .badge-icon { width: 30px; height: 30px; border-radius: 8px; display: grid; place-items: center; background: var(--accent-strong); color: var(--accent-text); }
details.block > summary .badge-icon .icon { width: 18px; height: 18px; }
details.block > summary .grow { flex: 1; }
details.block > summary::after {
  content: ""; width: 8px; height: 8px; border-right: 2px solid var(--hint); border-bottom: 2px solid var(--hint);
  transform: rotate(-45deg); transition: transform .3s var(--spring); opacity: .7;
}
details.block[open] > summary::after { transform: rotate(45deg); }
details.block > .body { padding: 0 16px 16px; }
.stack { display: flex; flex-direction: column; gap: 10px; }
.inline { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.full { width: 100%; }
.note { color: var(--hint); font-size: 13px; line-height: 1.4; margin: 0; }

.item { display: flex; align-items: center; gap: 10px; padding: 10px 0; position: relative; }
.item + .item::before { content: ""; position: absolute; top: 0; left: 0; right: 0; height: 1px; background: var(--sep); transform: scaleY(.6); }
.item .sub { color: var(--hint); font-size: 13px; margin-top: 2px; }
.item .num { width: 22px; flex: none; color: var(--hint); font-variant-numeric: tabular-nums; }
.item input[type=time] { flex: 1; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--fill); flex: none; }
.dot.on { background: var(--accent); }
.weekday-title { color: var(--hint); font-size: 13px; text-transform: uppercase; letter-spacing: .02em; margin: 16px 0 2px; }

.form { background: var(--page); border-radius: 18px; padding: 14px; margin: 4px 0 8px; }
.form h3 { margin: 0 0 12px; font-size: 17px; }
.form input, .form select { background: var(--card); width: 100%; }
.form-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 10px; }
.form-grid .span2 { grid-column: span 2; }
.form-grid label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--hint); }
pre.result { white-space: pre-wrap; font: 13px/1.5 inherit; background: var(--page); padding: 12px; border-radius: 14px; margin: 0; }

.toast {
  position: fixed; z-index: 30; left: 50%; transform: translateX(-50%);
  bottom: calc(90px + var(--safe-bottom)); max-width: calc(100% - 48px);
  padding: 11px 18px; border-radius: 22px; font-size: 15px; font-weight: 500; text-align: center; white-space: pre-line;
  box-shadow: var(--glass-shadow), inset 0 1px 0 var(--glass-hi);
  animation: toast-in .45s var(--spring);
}
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 12px) scale(.96); } }

/* --- профиль --- */
.profile-card { display: flex; align-items: center; gap: 14px; padding: 16px; margin-top: 12px; }
.avatar {
  position: relative; width: 64px; height: 64px; flex: none; border-radius: 50%; overflow: hidden;
  display: grid; place-items: center; background: var(--tint); color: var(--accent-ink);
  font-size: 24px; font-weight: 700;
}
.avatar img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.pname { font-size: 20px; font-weight: 700; line-height: 1.2; letter-spacing: -.02em; }
.psub { color: var(--hint); font-size: 15px; margin-top: 2px; }
.row .value { text-align: right; font-weight: 600; }
.row.column { flex-direction: column; align-items: stretch; gap: 10px; padding-top: 12px; padding-bottom: 14px; }
.progress.semester { margin: 0; }
.segmented.wide { display: grid; width: 100%; }
textarea { resize: vertical; min-height: 92px; line-height: 1.4; }
.link-row { width: 100%; text-align: left; cursor: pointer; }
.hint-text { color: var(--hint); font-size: 15px; }

/* --- вне Telegram (PWA): свои цвета светлой и тёмной темы --- */
:root.web { --page: #f2f2f7; --card: #ffffff; --text: #000000; --hint: #8e8e93; }
:root.web[data-scheme=dark] { --page: #000000; --card: #1c1c1e; --text: #ffffff; --hint: #8e8e93; }
:root.web main { padding-top: env(safe-area-inset-top); }

/* --- экран входа --- */
.login { text-align: center; padding: 12vh 8px 0; max-width: 420px; margin: 0 auto; }
.login-logo { display: block; width: 112px; height: 112px; margin: 0 auto 18px; }
.login h1 { font-size: 30px; }
.login-text { color: var(--hint); font-size: 16px; margin: 8px 0 28px; }
.login .btn { margin-top: 10px; }
.login .note { margin-top: 10px; }
.login-note { font-size: 15px; margin: 6px 0 10px; }
.login-code {
  font-size: 44px; font-weight: 800; letter-spacing: .25em; font-variant-numeric: tabular-nums;
  color: var(--accent-ink); margin: 4px 0 2px; padding-left: .25em;
}
.waiting { animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .4; } }
#install-hint { margin-top: 28px; }
.install { background: var(--card); border-radius: var(--r-card); padding: 14px 16px; text-align: left; font-size: 15px; line-height: 1.45; }
.install b { display: block; margin-bottom: 4px; }
.inline-icon { width: 17px; height: 17px; vertical-align: -3px; color: var(--accent-ink); }
.danger-row .label { color: var(--danger); }
