/* Дизайн-токены. Цвета текста подобраны под WCAG AA (≥ 4.5:1) на --bg, --surface и --surface-2.
   --ok/--bad/--info/--own годятся и для текста, --warn - только для значков и точек (3:1),
   для текста на жёлтом - --warn-ink. */
:root {
  --bg: #f4f5fb;
  --surface: #ffffff;
  --surface-2: #eef0f8;
  --line: #e2e5ef;
  --text: #151826;
  --text-2: #484d63;
  --text-3: #686d83;
  --accent: #5146e5;
  --accent-2: #7c5cf0;
  --accent-soft: #ebe9ff;
  --on-accent: #ffffff;
  --ok: #0b7d50;
  --ok-soft: #def5ea;
  --warn: #c27400;
  --warn-ink: #955500;
  --warn-soft: #fff0d6;
  --bad: #c22c3b;
  --bad-soft: #fde6e8;
  --info: #1767cc;
  --info-soft: #e2efff;
  --own: #0b7f8a;
  --own-ink: #08707b;
  --own-soft: #dcf4f6;
  --on-own: #ffffff;
  --now-a: #5146e5;
  --now-b: #6e4fe6;
  --seg-on: #ffffff;
  --sheet-bg: var(--bg);
  --scrim: rgba(10, 12, 24, .42);
  --shadow: 0 1px 2px rgba(20, 24, 50, .05), 0 3px 12px rgba(20, 24, 50, .06);
  --radius: 16px;
  --tabbar-h: 64px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  color-scheme: light;
}

:root[data-theme="dark"] {
  --bg: #0f1117;
  --surface: #181b24;
  --surface-2: #20242f;
  --line: #2a2f3c;
  --text: #eceef6;
  --text-2: #b0b5c7;
  --text-3: #868ba0;
  --accent: #8b83ff;
  --accent-2: #a98bff;
  --accent-soft: #272552;
  --on-accent: #0f1117;
  --ok: #3fd29b;
  --ok-soft: #12352a;
  --warn: #f2b14a;
  --warn-ink: #f2b14a;
  --warn-soft: #3a2c12;
  --bad: #ff6b78;
  --bad-soft: #3d1a20;
  --info: #66a8ff;
  --info-soft: #15294a;
  --own: #4fd1dc;
  --own-ink: #4fd1dc;
  --own-soft: #10343a;
  --on-own: #0f1117;
  --now-a: #4c42c9;
  --now-b: #6a4bd6;
  --seg-on: #2e3342;
  --sheet-bg: #14161e;
  --scrim: rgba(0, 0, 0, .62);
  --shadow: inset 0 0 0 1px rgba(255, 255, 255, .04), 0 1px 2px rgba(0, 0, 0, .3), 0 4px 14px rgba(0, 0, 0, .22);
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
html { background: var(--bg); -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: inherit; text-decoration: none; }
svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
[hidden] { display: none !important; }

/* фокус с клавиатуры (на касание не срабатывает) */
:focus-visible { outline: 2.5px solid var(--accent); outline-offset: 2px; }
:focus:not(:focus-visible) { outline: none; }

#app {
  min-height: 100%; display: flex; flex-direction: column; max-width: 640px; margin: 0 auto;
  padding-left: var(--safe-l); padding-right: var(--safe-r);
}
main { flex: 1; padding-bottom: calc(var(--tabbar-h) + var(--safe-b) + 16px); }

/* ---------------------------------------------------------------- шапка */

.topbar {
  position: sticky; top: 0; z-index: 20;
  padding: calc(var(--safe-t) + 8px) 16px 6px;
  background: color-mix(in srgb, var(--bg) 84%, transparent);
  backdrop-filter: saturate(1.8) blur(18px);
  -webkit-backdrop-filter: saturate(1.8) blur(18px);
  border-bottom: 1px solid transparent;
}
/* тонкая линия под шапкой появляется, когда под ней прокручивается содержимое */
@supports (animation-timeline: scroll()) {
  .topbar { animation: topbar-line linear both; animation-timeline: scroll(root); animation-range: 0 24px; }
  @keyframes topbar-line { to { border-bottom-color: var(--line); } }
}
.topbar:empty { display: none; }
.topbar-row { display: flex; align-items: center; gap: 8px; min-height: 44px; }
.topbar h1 {
  font-size: 26px; line-height: 1.15; margin: 0; letter-spacing: -.02em; font-weight: 750;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0;
}
.topbar .sub { color: var(--text-2); font-size: 13.5px; margin-top: 1px; }
.group-btn {
  display: inline-flex; align-items: center; gap: 4px; max-width: 100%;
  border: 0; background: none; padding: 0; text-align: left; border-radius: 8px;
}
.group-btn svg { width: 18px; height: 18px; color: var(--text-3); margin-top: 3px; }
.spacer { flex: 1; }
.icon-btn {
  width: 44px; height: 44px; border-radius: 14px; border: 0; flex: none;
  display: grid; place-items: center; background: var(--surface); color: var(--text);
  box-shadow: var(--shadow); transition: transform .12s, background .15s;
}
.icon-btn:active { transform: scale(.94); }
.icon-btn svg { width: 22px; height: 22px; }
.icon-btn:disabled { opacity: .3; box-shadow: none; }
.back-btn { margin-left: -10px; background: none; box-shadow: none; }

/* ---------------------------------------------------------------- лента недели */

.weekstrip { display: flex; gap: 4px; margin-top: 8px; }
.weekstrip button {
  flex: 1; min-width: 0; border: 0; border-radius: 14px; padding: 6px 0 7px;
  background: transparent; color: var(--text-3);
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  position: relative; transition: background .15s, color .15s;
}
.weekstrip .wd { font-size: 11px; line-height: 14px; text-transform: uppercase; letter-spacing: .05em; font-weight: 650; }
.weekstrip .dn { font-size: 18px; line-height: 22px; font-weight: 700; color: var(--text); font-variant-numeric: tabular-nums; }
.weekstrip .marks { display: flex; gap: 3px; height: 4px; margin-top: 2px; }
.weekstrip .marks i { width: 4px; height: 4px; border-radius: 50%; background: var(--text-3); opacity: .5; }
.weekstrip .marks i.chg { background: var(--warn); opacity: 1; }
.weekstrip button.today { background: var(--accent-soft); color: var(--accent); }
.weekstrip button.today .dn { color: var(--accent); }
.weekstrip button.sel { background: var(--accent); color: var(--on-accent); box-shadow: 0 4px 14px color-mix(in srgb, var(--accent) 35%, transparent); }
.weekstrip button.sel .wd { opacity: .85; }
.weekstrip button.sel .dn { color: var(--on-accent); }
.weekstrip button.sel .marks i { background: var(--on-accent); opacity: .6; }
.weekstrip button.sel .marks i.chg { background: #ffd27a; opacity: 1; }
:root[data-theme="dark"] .weekstrip button.sel .marks i.chg { background: #9a5a00; }
.weekstrip button.off { opacity: .4; }
.week-nav {
  display: flex; align-items: center; justify-content: space-between; margin-top: 2px;
  color: var(--text-2); font-size: 12.5px; font-variant-numeric: tabular-nums;
}
.week-nav button {
  position: relative; border: 0; background: none; color: var(--accent); font-weight: 650;
  min-height: 34px; padding: 6px 10px; margin: 0 -10px; font-size: 13px; border-radius: 10px;
}
.week-nav button::before { content: ""; position: absolute; inset: -5px 0; }   /* зона нажатия 44px */
.week-nav button:active { background: var(--accent-soft); }

/* ---------------------------------------------------------------- пейджер дней */

.pager {
  display: flex; overflow-x: auto; scroll-snap-type: x mandatory;
  scrollbar-width: none; overscroll-behavior-x: contain;
}
.pager::-webkit-scrollbar { display: none; }
.page { flex: 0 0 100%; scroll-snap-align: start; scroll-snap-stop: always; padding: 6px 16px 0; min-height: 60vh; min-width: 0; }
/* прыжок на далёкий день - день въезжает сбоку */
.page.slide-r { animation: page-in-r .28s cubic-bezier(.2, .8, .3, 1); }
.page.slide-l { animation: page-in-l .28s cubic-bezier(.2, .8, .3, 1); }
@keyframes page-in-r { from { transform: translateX(48px); opacity: 0; } }
@keyframes page-in-l { from { transform: translateX(-48px); opacity: 0; } }
.day-title { display: flex; align-items: baseline; flex-wrap: wrap; gap: 2px 8px; margin: 4px 4px 8px; }
.day-title b { font-size: 16px; font-weight: 700; }
.day-title span { color: var(--text-3); font-size: 13px; }

/* ---------------------------------------------------------------- карточка «сейчас» */

.now {
  border-radius: 20px; padding: 14px 16px 15px; margin-bottom: 12px; color: #fff;
  background: linear-gradient(135deg, var(--now-a) 0%, var(--now-b) 100%);
  box-shadow: 0 8px 24px color-mix(in srgb, var(--now-a) 28%, transparent);
  position: relative; overflow: hidden; isolation: isolate;
}
:root[data-theme="dark"] .now { color: #fff; box-shadow: 0 8px 24px rgba(0, 0, 0, .35); }
.now::after {
  content: ""; position: absolute; right: -60px; top: -80px; width: 200px; height: 200px; z-index: -1;
  border-radius: 50%; background: radial-gradient(circle, rgba(255, 255, 255, .2), rgba(255, 255, 255, 0) 70%);
}
.now .label { font-size: 11.5px; line-height: 1.3; text-transform: uppercase; letter-spacing: .08em; opacity: .88; font-weight: 700; }
.now .title { font-size: 18px; line-height: 1.25; font-weight: 700; margin: 4px 0 3px; overflow-wrap: anywhere; }
.now .meta { font-size: 13.5px; line-height: 1.35; opacity: .92; }
.now .bar { height: 5px; border-radius: 3px; background: rgba(255, 255, 255, .26); margin-top: 12px; overflow: hidden; }
.now .bar i { display: block; height: 100%; background: currentColor; border-radius: 3px; }
.now.calm, :root[data-theme="dark"] .now.calm { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.now.calm::after { display: none; }

/* ---------------------------------------------------------------- занятия */

.lessons { display: flex; flex-direction: column; gap: 8px; }
.lesson {
  display: flex; align-items: flex-start; gap: 12px; padding: 12px 14px 12px 10px; border-radius: var(--radius);
  background: var(--surface); box-shadow: var(--shadow); border: 0; width: 100%; text-align: left;
  position: relative; transition: transform .12s;
}
.lesson:active { transform: scale(.985); }
.lesson .time {
  width: 48px; flex: none; display: flex; flex-direction: column; align-items: center;
  font-variant-numeric: tabular-nums;
}
.lesson .num {
  width: 24px; height: 24px; border-radius: 8px; display: grid; place-items: center;
  background: var(--surface-2); font-weight: 750; font-size: 13px; color: var(--text-2);
}
.lesson .t1 { font-weight: 700; font-size: 15px; line-height: 18px; margin-top: 5px; letter-spacing: -.01em; }
.lesson .t2 { font-size: 12.5px; line-height: 16px; color: var(--text-3); }
.lesson .body { flex: 1; min-width: 0; }
.lesson .name { font-weight: 650; font-size: 16px; line-height: 1.25; overflow-wrap: anywhere; hyphens: auto; }
.lesson .info { display: flex; flex-wrap: wrap; gap: 2px 10px; margin-top: 4px; color: var(--text-2); font-size: 13.5px; line-height: 1.35; }
.lesson .info span { display: inline-flex; align-items: center; gap: 4px; min-width: 0; overflow-wrap: anywhere; }
.lesson .info svg { width: 15px; height: 15px; color: var(--text-3); }
.lesson .tags { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 5px; }
.lesson.current {
  background: color-mix(in srgb, var(--accent) 5%, var(--surface));
  box-shadow: 0 0 0 2px var(--accent), var(--shadow);
}
.lesson.current .num { background: var(--accent); color: var(--on-accent); }
.lesson.past { opacity: .62; box-shadow: none; }
.lesson.cancelled {
  background: transparent; box-shadow: none;
  border: 1.5px dashed color-mix(in srgb, var(--text-3) 45%, transparent);
}
.lesson.cancelled .name { text-decoration: line-through; text-decoration-thickness: 1.5px; color: var(--text-3); }
.lesson.cancelled .t1 { color: var(--text-2); }
.lesson.cancelled .tag:not(.cxl) { background: var(--surface-2); color: var(--text-2); }
.lesson.own { background: var(--own-soft); box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--own) 16%, transparent); }
.lesson.own .num { background: var(--own); color: var(--on-own); }
.lesson.own .t2, .lesson.own .info, .lesson.own .info svg { color: var(--text-2); }
.lesson.own .tag:not(.own) { background: color-mix(in srgb, var(--own) 14%, transparent); color: var(--own-ink); }
.lesson.own.current { box-shadow: 0 0 0 2px var(--own); }
.lesson.own.current .num { background: var(--own); color: var(--on-own); }
.lesson.other-sub { opacity: .5; }

/* пара по подгруппам в два столбца (настройка «Подгруппы в два столбца») */
.lesson.split { padding-right: 10px; }
.lesson.split:active { transform: none; }
.lesson.split .halves { flex: 1; min-width: 0; display: grid; gap: 0; }
.lesson .half {
  min-width: 0; border: 0; background: none; text-align: left; padding: 0 8px 0 10px; border-radius: 10px;
  display: flex; flex-direction: column; align-items: stretch; transition: background .12s;
}
.lesson .half + .half { box-shadow: inset 1px 0 0 var(--line); border-radius: 0 10px 10px 0; }   /* прямая линия-разделитель */
.lesson .half:active { background: var(--surface-2); }
.lesson .half .sub-label {
  display: flex; align-items: center; justify-content: space-between; gap: 4px;
  font-size: 11.5px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; color: var(--text-3); margin-bottom: 4px;
}
.lesson .half .tags { margin-bottom: 4px; }
.lesson .half .tag { height: 20px; padding: 0 6px; font-size: 11px; }
.lesson .half .name { font-size: 14.5px; line-height: 1.25; }
.lesson .half .info { flex-direction: column; gap: 1px; font-size: 12.5px; margin-top: 3px; }
.lesson .half .info svg { width: 13px; height: 13px; }
.lesson .half.no-pair .none { color: var(--text-3); font-size: 13.5px; font-style: italic; margin-top: 2px; }
.lesson.split.current .half + .half { box-shadow: inset 1px 0 0 color-mix(in srgb, var(--accent) 30%, var(--line)); }

.tag {
  display: inline-flex; align-items: center; gap: 5px; height: 20px; padding: 0 7px; border-radius: 6px;
  font-size: 11.5px; font-weight: 650; letter-spacing: .01em; line-height: 1;
  background: var(--surface-2); color: var(--text-2); white-space: nowrap;
}
/* тип занятия - мягкая плашка; статус (изменено/новая/отменена/аудитория) - плашка с точкой */
.tag.lec { background: var(--info-soft); color: var(--info); }
.tag.prac { background: var(--ok-soft); color: var(--ok); }
.tag.lab { background: var(--accent-soft); color: var(--accent); }
.tag.exam { background: var(--bad-soft); color: var(--bad); }
.tag.sub { background: var(--surface-2); color: var(--text-2); }
.tag.chg { background: var(--warn-soft); color: var(--warn-ink); }
.tag.new { background: var(--ok-soft); color: var(--ok); }
.tag.cxl { background: var(--bad-soft); color: var(--bad); }
.tag.room { background: var(--warn-soft); color: var(--warn-ink); }
.tag.chg::before, .tag.new::before, .tag.cxl::before, .tag.room::before {
  content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; flex: none;
}
.tag.own { background: var(--own); color: var(--on-own); }

.gap {
  display: flex; align-items: center; gap: 10px; color: var(--text-3); font-size: 12px; line-height: 16px;
  padding: 0 4px; margin: -2px 0; font-variant-numeric: tabular-nums;
}
.gap::before, .gap::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.gap.window { color: var(--warn-ink); font-weight: 600; }
.gap.window::before, .gap.window::after {
  background: repeating-linear-gradient(90deg, color-mix(in srgb, var(--warn) 55%, transparent) 0 4px, transparent 4px 8px);
}

.empty { text-align: center; color: var(--text-2); padding: 56px 28px; line-height: 1.45; max-width: 360px; margin: 0 auto; }
.empty .big { font-size: 44px; line-height: 1; margin-bottom: 12px; }
.empty b { display: block; color: var(--text); font-size: 17px; margin-bottom: 4px; }

/* ---------------------------------------------------------------- общие блоки */

.section { padding: 4px 16px 0; }
.section h2 { font-size: 12.5px; text-transform: uppercase; letter-spacing: .06em; color: var(--text-3); margin: 22px 6px 8px; font-weight: 700; }
.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.row {
  display: flex; align-items: center; gap: 12px; padding: 10px 16px; min-height: 54px;
  border: 0; background: none; width: 100%; text-align: left; line-height: 1.3;
  transition: background-color .12s;
}
/* разделитель начинается после значка, как в iOS-списках */
.row + .row {
  border-top: 0;
  background-image: linear-gradient(var(--line), var(--line));
  background-repeat: no-repeat; background-size: calc(100% - 62px) 1px; background-position: right top;
}
a.row:active, button.row:active, label.row:active { background-color: var(--surface-2); }
.row .grow { flex: 1; min-width: 0; }
.row .title { font-weight: 600; overflow-wrap: anywhere; }
.row .hint { color: var(--text-2); font-size: 13.5px; }
.row .val { color: var(--text-2); font-size: 15px; white-space: nowrap; }
.row .chev { color: var(--text-3); width: 18px; height: 18px; }
.row .ico { width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); flex: none; }
.row .ico svg { width: 19px; height: 19px; }
.row.danger .title { color: var(--bad); }
.row select { min-height: 36px; font-size: 15px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 50px; padding: 0 20px; border-radius: 14px; border: 0;
  background: var(--accent); color: var(--on-accent); font-weight: 650; font-size: 16px; width: 100%;
  transition: transform .12s, filter .15s, opacity .15s;
}
.btn:active { transform: scale(.98); filter: brightness(.95); }
.btn.secondary { background: var(--surface-2); color: var(--text); }
.btn.small { height: 40px; font-size: 14px; width: auto; padding: 0 16px; border-radius: 12px; }
.btn:disabled { opacity: .45; transform: none; filter: none; cursor: default; }

.search {
  display: flex; align-items: center; gap: 8px; height: 46px; padding: 0 14px; border-radius: 14px;
  background: var(--surface); box-shadow: var(--shadow); transition: box-shadow .15s;
}
.search:focus-within { box-shadow: 0 0 0 2px var(--accent), var(--shadow); }
.search svg { color: var(--text-3); width: 20px; height: 20px; }
.search input { flex: 1; border: 0; outline: 0; background: none; font-size: 16px; min-width: 0; height: 100%; }
.search input::placeholder { color: var(--text-3); }

.seg { display: flex; padding: 3px; border-radius: 13px; background: var(--surface-2); gap: 2px; overflow-x: auto; scrollbar-width: none; }
.seg::-webkit-scrollbar { display: none; }
.seg button {
  flex: 1 1 auto; border: 0; background: none; padding: 8px 6px; min-height: 36px; border-radius: 10px;
  font-size: 13.5px; font-weight: 600; color: var(--text-2); white-space: nowrap; transition: background .15s, color .15s;
}
.seg button.on { background: var(--seg-on); color: var(--text); box-shadow: var(--shadow); }
:root[data-theme="dark"] .seg button.on { background: var(--seg-on); }
.seg button:focus-visible { outline-offset: -2px; }


.grid-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; }
.grid-list button {
  border: 0; border-radius: 13px; background: var(--surface); box-shadow: var(--shadow);
  padding: 12px 6px; min-height: 46px; font-weight: 650; font-size: 15px; font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere; transition: transform .12s;
}
.grid-list button:active { transform: scale(.96); }
.grid-list button.on { background: var(--accent); color: var(--on-accent); }

.switch { position: relative; width: 51px; height: 31px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch i { position: absolute; inset: 0; border-radius: 16px; background: var(--line); transition: background .2s; }
:root[data-theme="dark"] .switch i { background: #3a4050; }
.switch i::after {
  content: ""; position: absolute; left: 3px; top: 3px; width: 25px; height: 25px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, .25); transition: transform .2s;
}
.switch input:checked + i { background: var(--ok); }
.switch input:checked + i::after { transform: translateX(20px); }
.switch input:focus-visible + i { outline: 2.5px solid var(--accent); outline-offset: 2px; }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field label { font-size: 13px; color: var(--text-2); font-weight: 600; padding-left: 4px; }
.field input, .field textarea, .field select {
  border: 1.5px solid var(--line); background: var(--surface); border-radius: 12px; padding: 12px 14px; outline: 0;
  font-size: 16px; width: 100%; min-height: 48px; transition: border-color .15s, box-shadow .15s;
}
.field input::placeholder, .field textarea::placeholder { color: var(--text-3); }
.field textarea { min-height: 96px; resize: vertical; line-height: 1.4; }
.field input:focus, .field textarea:focus, .field select:focus {
  border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 20%, transparent);
}
.field-row { display: flex; gap: 10px; }
.field-row .field { flex: 1; min-width: 0; }

/* ---------------------------------------------------------------- изменения */

.feed-day { margin: 18px 6px 8px; font-weight: 700; color: var(--text-2); font-size: 13.5px; }
.change {
  background: var(--surface); border-radius: var(--radius); padding: 12px 14px; box-shadow: var(--shadow);
  margin-bottom: 8px; display: flex; gap: 12px; align-items: flex-start; border: 0; width: 100%; text-align: left;
  transition: transform .12s;
}
.change:active { transform: scale(.985); }
.change .k {
  width: 32px; height: 32px; border-radius: 10px; display: grid; place-items: center; flex: none;
  font-size: 15px; font-weight: 700; font-variant-emoji: text;
}
.change .k.changed { background: var(--warn-soft); color: var(--warn-ink); }
.change .k.added { background: var(--ok-soft); color: var(--ok); }
.change .k.removed { background: var(--bad-soft); color: var(--bad); }
.change .what { font-weight: 650; font-size: 14.5px; line-height: 1.3; margin-top: 1px; }
.change .old { color: var(--text-3); text-decoration: line-through; font-size: 13.5px; line-height: 1.35; margin-top: 2px; overflow-wrap: anywhere; }
.change .new { font-size: 14px; line-height: 1.35; margin-top: 2px; overflow-wrap: anywhere; }
.change .when { color: var(--text-3); font-size: 12px; margin-top: 4px; }

/* ---------------------------------------------------------------- нижняя панель */

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: flex; justify-content: space-around; max-width: 640px; margin: 0 auto;
  height: calc(var(--tabbar-h) + var(--safe-b)); padding: 0 var(--safe-r) var(--safe-b) var(--safe-l);
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: saturate(1.8) blur(18px); -webkit-backdrop-filter: saturate(1.8) blur(18px);
  border-top: 1px solid var(--line);
}
.tabbar a {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  color: var(--text-3); font-size: 11px; line-height: 14px; font-weight: 600; position: relative;
  transition: color .15s;
}
/* «таблетка» под значком активной вкладки (Material 3) */
.tabbar a::before {
  content: ""; position: absolute; top: 7px; left: 50%; width: 56px; height: 30px; margin-left: -28px;
  border-radius: 15px; background: var(--accent-soft); opacity: 0; transform: scaleX(.5);
  transition: opacity .2s, transform .2s;
}
.tabbar a.on::before { opacity: 1; transform: none; }
.tabbar a svg, .tabbar a span { position: relative; }
.tabbar a.on { color: var(--accent); }
.tabbar a.on svg { stroke-width: 2.1; }
.tabbar a:focus-visible { outline-offset: -4px; border-radius: 14px; }
.tabbar .dot {
  position: absolute; top: 8px; left: calc(50% + 6px); width: 9px; height: 9px; border-radius: 50%;
  background: var(--bad); box-shadow: 0 0 0 2px var(--surface);
}

/* ---------------------------------------------------------------- нижние листы */

.sheet-back {
  position: fixed; inset: 0; z-index: 50; background: var(--scrim);
  animation: fade .2s ease;
}
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 51; max-width: 640px; margin: 0 auto;
  max-height: 88vh; overflow-y: auto; overscroll-behavior: contain;
  background: var(--sheet-bg); border-radius: 22px 22px 0 0;
  padding: 6px calc(16px + var(--safe-r)) calc(20px + var(--safe-b)) calc(16px + var(--safe-l));
  box-shadow: 0 -6px 30px rgba(10, 12, 24, .14);
  animation: up .28s cubic-bezier(.2, .9, .3, 1);
}
:root[data-theme="dark"] .sheet { box-shadow: inset 0 1px 0 rgba(255, 255, 255, .07), 0 -6px 30px rgba(0, 0, 0, .5); }
.sheet .grip { width: 36px; height: 5px; border-radius: 3px; background: color-mix(in srgb, var(--text-3) 35%, transparent); margin: 2px auto 12px; }
.sheet h3 { margin: 4px 4px 4px; font-size: 20px; line-height: 1.25; letter-spacing: -.01em; font-weight: 700; overflow-wrap: anywhere; }
.sheet:focus { outline: none; }      /* фокус ставится на лист программно - для клавиатуры и скринридеров */
.sheet-h2 { font-size: 12.5px; text-transform: uppercase; letter-spacing: .06em; color: var(--text-3); margin: 20px 4px 8px; font-weight: 700; }
.sheet .lead { color: var(--text-2); margin: 0 4px 14px; font-size: 14.5px; line-height: 1.45; }
.sheet .actions { display: flex; gap: 10px; margin-top: 16px; }
/* «Готово» в выборе группы не уезжает под длинный список групп */
.sheet .btn[data-act="ok"] {
  position: sticky; bottom: 0; z-index: 2;
  box-shadow: 0 0 0 10px var(--sheet-bg), 0 40px 0 40px var(--sheet-bg), 0 -16px 22px 6px var(--sheet-bg);
}
@keyframes up { from { transform: translateY(100%); } }
@keyframes fade { from { opacity: 0; } }

.kv { display: flex; gap: 12px; padding: 11px 4px; border-bottom: 1px solid var(--line); align-items: flex-start; line-height: 1.35; }
.kv:last-child { border-bottom: 0; }
.kv .k { color: var(--text-3); width: 108px; flex: none; font-size: 13.5px; padding-top: 1px; }
.kv .v { flex: 1; min-width: 0; font-weight: 550; overflow-wrap: anywhere; }
.kv a, .kv a.v { color: var(--accent); }
.note-box { background: var(--warn-soft); border-radius: 14px; padding: 12px 14px; margin-top: 10px; font-size: 14px; line-height: 1.45; overflow-wrap: anywhere; }
.note-box b { color: var(--warn-ink); }

/* ---------------------------------------------------------------- календарь архива */

.cal-head { display: flex; align-items: center; justify-content: space-between; margin: 4px 0 10px; }
.cal-head b { font-size: 17px; }
.cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal .wd { text-align: center; font-size: 11px; color: var(--text-3); font-weight: 700; padding: 4px 0; text-transform: uppercase; letter-spacing: .04em; }
.cal button {
  aspect-ratio: 1; min-height: 40px; border: 0; border-radius: 12px; background: none; font-weight: 600; font-size: 15px;
  position: relative; color: var(--text-3); font-variant-numeric: tabular-nums;
}
.cal button.has { background: var(--surface); box-shadow: var(--shadow); color: var(--text); }
.cal button.today { color: var(--accent); font-weight: 800; box-shadow: inset 0 0 0 1.5px var(--accent); }
.cal button.has.today { box-shadow: inset 0 0 0 1.5px var(--accent), var(--shadow); }
.cal button.sel { background: var(--accent); color: var(--on-accent); box-shadow: none; }
.cal button:disabled { color: var(--text-3); opacity: .5; }

/* ---------------------------------------------------------------- приветствие */

.welcome {
  min-height: calc(100svh - var(--tabbar-h) - var(--safe-b) - 16px);
  display: flex; flex-direction: column; justify-content: center;
  padding: calc(var(--safe-t) + 32px) 24px 40px;
}
.welcome .logo {
  width: 72px; height: 72px; border-radius: 22px; display: grid; place-items: center;
  background: linear-gradient(135deg, var(--now-a), var(--now-b)); color: #fff; margin-bottom: 20px;
  box-shadow: 0 12px 30px color-mix(in srgb, var(--now-a) 35%, transparent);
}
.welcome .logo svg { width: 38px; height: 38px; }
.welcome h1 { font-size: 30px; line-height: 1.15; letter-spacing: -.02em; margin: 0 0 8px; }
.welcome p { color: var(--text-2); margin: 0 0 28px; line-height: 1.45; max-width: 34ch; }

#toast {
  position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + var(--safe-b) + 14px); z-index: 60;
  transform: translate(-50%, 16px); opacity: 0; pointer-events: none;
  width: max-content; max-width: calc(100% - 32px);
  background: var(--text); color: var(--bg); padding: 11px 18px; border-radius: 14px;
  font-size: 14.5px; line-height: 1.35; font-weight: 600; text-align: center;
  box-shadow: 0 8px 24px rgba(10, 12, 24, .25);
  transition: opacity .2s, transform .2s;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

.offline-pill {
  display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 650; color: var(--warn-ink);
  background: var(--warn-soft); padding: 3px 9px; border-radius: 8px; margin-top: 6px;
}
.muted { color: var(--text-3); font-size: 13px; line-height: 1.45; padding: 10px 6px; }
.center { text-align: center; }
.mt { margin-top: 14px; }

/* ---------------------------------------------------------------- мелочи */

@media (hover: hover) {
  .lesson:hover, .change:hover, .grid-list button:hover { filter: brightness(.985); }
  :root[data-theme="dark"] .lesson:hover, :root[data-theme="dark"] .change:hover { filter: brightness(1.12); }
  a.row:hover, button.row:hover { background-color: color-mix(in srgb, var(--surface-2) 60%, transparent); }
}

/* узкие телефоны (360 px): вкладки поиска и переключатели помещаются без прокрутки */
@media (max-width: 374px) {
  .seg button { font-size: 13px; padding: 8px 4px; }
  .topbar h1 { font-size: 24px; }
  .weekstrip { gap: 2px; }
  .kv .k { width: 96px; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
  .lesson:active, .change:active, .btn:active, .icon-btn:active, .grid-list button:active { transform: none; }
}

/* ================================================================ стиль «Liquid Glass»
   Включается в настройках (html[data-style="glass"]). Полупрозрачное стекло с размытием того,
   что под ним, блик по верхней кромке и мягкий цветной фон, чтобы стеклу было что преломлять. */

:root[data-style="glass"] {
  --bg: #eceefa;
  --glass: rgba(255, 255, 255, .5);
  --glass-strong: rgba(250, 250, 255, .74);
  --glass-hi: rgba(255, 255, 255, .55);          /* блик по диагонали */
  --glass-edge: rgba(255, 255, 255, .9);         /* светлая верхняя кромка */
  --glass-rim: rgba(255, 255, 255, .5);          /* тонкий ободок */
  --glass-shadow: 0 1px 2px rgba(40, 40, 110, .06), 0 8px 26px rgba(40, 40, 110, .1);
  --glass-blur: blur(22px) saturate(1.9);
  --surface: var(--glass);
  --surface-2: rgba(255, 255, 255, .5);
  --line: rgba(30, 35, 80, .1);
  --seg-on: rgba(255, 255, 255, .88);
  --sheet-bg: rgba(246, 247, 255, .78);
  --scrim: rgba(20, 22, 50, .22);
  --radius: 20px;
}
:root[data-style="glass"][data-theme="dark"] {
  --bg: #090a12;
  --glass: rgba(34, 36, 54, .46);
  --glass-strong: rgba(26, 28, 44, .74);
  --glass-hi: rgba(255, 255, 255, .09);
  --glass-edge: rgba(255, 255, 255, .2);
  --glass-rim: rgba(255, 255, 255, .07);
  --glass-shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 10px 30px rgba(0, 0, 0, .35);
  --surface-2: rgba(255, 255, 255, .08);
  --line: rgba(255, 255, 255, .09);
  --seg-on: rgba(255, 255, 255, .16);
  --sheet-bg: rgba(20, 22, 36, .76);
  --scrim: rgba(0, 0, 0, .4);
}

/* цветной фон под стеклом */
:root[data-style="glass"] body { background: transparent; }
:root[data-style="glass"] body::before {
  content: ""; position: fixed; inset: -10%; z-index: -1; pointer-events: none;
  background:
    radial-gradient(38% 30% at 12% 8%, #c9c3ff 0, transparent 70%),
    radial-gradient(34% 28% at 92% 22%, #a9e4ff 0, transparent 70%),
    radial-gradient(42% 34% at 78% 78%, #ffc9e8 0, transparent 70%),
    radial-gradient(40% 32% at 8% 70%, #bff0dd 0, transparent 70%),
    radial-gradient(30% 24% at 50% 45%, #e3dcff 0, transparent 70%),
    var(--bg);
}
:root[data-style="glass"][data-theme="dark"] body::before {
  background:
    radial-gradient(38% 30% at 12% 8%, rgba(92, 72, 230, .42) 0, transparent 70%),
    radial-gradient(34% 28% at 92% 22%, rgba(20, 130, 180, .32) 0, transparent 70%),
    radial-gradient(42% 34% at 78% 78%, rgba(170, 50, 140, .3) 0, transparent 70%),
    radial-gradient(40% 32% at 8% 70%, rgba(20, 140, 105, .26) 0, transparent 70%),
    var(--bg);
}

/* само стекло. :where() - нулевая специфичность списка: иначе самый «тяжёлый» селектор
   (.cal button.has) поднял бы всё правило выше точечных (.grid-list button.on, .lesson.current и т.п.) */
:root[data-style="glass"] :where(.lesson, .card, .change, .search, .grid-list button, .icon-btn:not(.back-btn), .now.calm, .cal button.has, .seg, .btn.secondary) {
  background: linear-gradient(135deg, var(--glass-hi) 0%, transparent 55%), var(--glass);
  -webkit-backdrop-filter: var(--glass-blur);
  backdrop-filter: var(--glass-blur);
  box-shadow: inset 0 1px 0 var(--glass-edge), inset 0 0 0 1px var(--glass-rim), var(--glass-shadow);
}
:root[data-style="glass"] .seg { box-shadow: inset 0 1px 0 var(--glass-edge), inset 0 0 0 1px var(--glass-rim); }
:root[data-style="glass"] .seg button.on {
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .9), 0 2px 8px rgba(40, 40, 110, .12);
}
:root[data-style="glass"][data-theme="dark"] .seg button.on { box-shadow: inset 0 1px 0 rgba(255, 255, 255, .18), 0 2px 8px rgba(0, 0, 0, .3); }
:root[data-style="glass"] .icon-btn { border-radius: 50%; }
:root[data-style="glass"] :is(.search, .btn, .seg) { border-radius: 999px; }
:root[data-style="glass"] .seg button { border-radius: 999px; }

/* карточки пар: состояния поверх стекла */
:root[data-style="glass"] .lesson .num { background: var(--surface-2); box-shadow: inset 0 1px 0 var(--glass-edge); }
/* номер текущей пары и своего события - цветной, как в обычном стиле (общее правило выше его перебило бы) */
:root[data-style="glass"] .lesson.current .num { background: var(--accent); color: var(--on-accent); box-shadow: inset 0 1px 0 rgba(255, 255, 255, .45); }
:root[data-style="glass"] .lesson.own .num { background: var(--own); color: var(--on-own); }
:root[data-style="glass"] .lesson.current {
  background: linear-gradient(135deg, var(--glass-hi) 0%, transparent 55%), color-mix(in srgb, var(--accent) 12%, var(--glass));
  box-shadow: inset 0 1px 0 var(--glass-edge), inset 0 0 0 2px var(--accent),
    0 8px 28px color-mix(in srgb, var(--accent) 28%, transparent);
}
:root[data-style="glass"] .lesson.past { box-shadow: inset 0 0 0 1px var(--glass-rim); }
:root[data-style="glass"] .lesson.cancelled {
  background: transparent; -webkit-backdrop-filter: none; backdrop-filter: none; box-shadow: none;
}
:root[data-style="glass"] .lesson.own {
  background: linear-gradient(135deg, var(--glass-hi) 0%, transparent 55%), color-mix(in srgb, var(--own) 16%, var(--glass));
}
:root[data-style="glass"] .lesson.own.current { box-shadow: inset 0 1px 0 var(--glass-edge), inset 0 0 0 1.5px var(--own); }

/* карточка «сейчас» - цветное стекло */
:root[data-style="glass"] .now:not(.calm) {
  background:
    linear-gradient(135deg, rgba(255, 255, 255, .3) 0%, rgba(255, 255, 255, 0) 45%),
    linear-gradient(135deg, color-mix(in srgb, var(--now-a) 82%, transparent), color-mix(in srgb, var(--now-b) 72%, transparent));
  -webkit-backdrop-filter: var(--glass-blur);
  backdrop-filter: var(--glass-blur);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .55), inset 0 0 0 1px rgba(255, 255, 255, .18),
    0 10px 30px color-mix(in srgb, var(--now-a) 32%, transparent);
  border-radius: 24px;
}
:root[data-style="glass"] .now .bar { background: rgba(255, 255, 255, .3); box-shadow: inset 0 1px 1px rgba(0, 0, 0, .08); }

/* шапка - тонкое стекло во всю ширину */
:root[data-style="glass"] .topbar {
  background: color-mix(in srgb, var(--bg) 35%, transparent);
  -webkit-backdrop-filter: blur(26px) saturate(2);
  backdrop-filter: blur(26px) saturate(2);
}
:root[data-style="glass"] .weekstrip button.today {
  background: color-mix(in srgb, var(--accent) 12%, var(--glass));
  box-shadow: inset 0 1px 0 var(--glass-edge), inset 0 0 0 1px var(--glass-rim);
}
:root[data-style="glass"] .weekstrip button.sel {
  background: linear-gradient(180deg, rgba(255, 255, 255, .28), rgba(255, 255, 255, 0) 60%), var(--accent);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .5), 0 6px 18px color-mix(in srgb, var(--accent) 40%, transparent);
}

/* кнопки */
:root[data-style="glass"] .btn:not(.secondary) {
  background: linear-gradient(180deg, rgba(255, 255, 255, .26), rgba(255, 255, 255, 0) 60%), var(--accent);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .45), 0 6px 18px color-mix(in srgb, var(--accent) 35%, transparent);
}
:root[data-style="glass"] .grid-list button.on {
  background: linear-gradient(180deg, rgba(255, 255, 255, .26), rgba(255, 255, 255, 0) 60%), var(--accent);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .45), 0 4px 14px color-mix(in srgb, var(--accent) 35%, transparent);
}
:root[data-style="glass"] .cal button.sel {
  background: linear-gradient(180deg, rgba(255, 255, 255, .26), rgba(255, 255, 255, 0) 60%), var(--accent);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .45);
}
:root[data-style="glass"] .field :is(input, textarea, select) {
  background: var(--glass); border-color: var(--glass-rim);
  -webkit-backdrop-filter: var(--glass-blur); backdrop-filter: var(--glass-blur);
}

/* плавающая панель вкладок-«капсула» */
:root[data-style="glass"] .tabbar {
  left: 12px; right: 12px; bottom: calc(10px + var(--safe-b)); height: var(--tabbar-h);
  max-width: 560px; padding: 0 6px; border-radius: 32px; border-top: 0;
  background: linear-gradient(135deg, var(--glass-hi) 0%, transparent 60%), var(--glass-strong);
  -webkit-backdrop-filter: blur(28px) saturate(2);
  backdrop-filter: blur(28px) saturate(2);
  box-shadow: inset 0 1px 0 var(--glass-edge), inset 0 0 0 1px var(--glass-rim), 0 10px 34px rgba(30, 30, 90, .18);
}
:root[data-style="glass"][data-theme="dark"] .tabbar { box-shadow: inset 0 1px 0 var(--glass-edge), inset 0 0 0 1px var(--glass-rim), 0 10px 34px rgba(0, 0, 0, .5); }
:root[data-style="glass"] .tabbar a::before {
  top: 6px; width: calc(100% - 4px); left: 2px; height: 52px; margin-left: 0; border-radius: 26px;
  background: color-mix(in srgb, var(--accent) 14%, transparent);
  box-shadow: inset 0 1px 0 var(--glass-edge);
}
:root[data-style="glass"] .tabbar .dot { box-shadow: 0 0 0 2px var(--glass-strong); }
:root[data-style="glass"] main { padding-bottom: calc(var(--tabbar-h) + var(--safe-b) + 30px); }
:root[data-style="glass"] #toast { bottom: calc(var(--tabbar-h) + var(--safe-b) + 24px); border-radius: 999px; }

/* нижние листы - толстое стекло */
:root[data-style="glass"] .sheet {
  background: linear-gradient(180deg, var(--glass-hi) 0%, transparent 30%), var(--sheet-bg);
  -webkit-backdrop-filter: blur(34px) saturate(1.9);
  backdrop-filter: blur(34px) saturate(1.9);
  box-shadow: inset 0 1px 0 var(--glass-edge), 0 -10px 40px rgba(20, 20, 60, .18);
  border-radius: 28px 28px 0 0;
}
:root[data-style="glass"] .sheet-back { -webkit-backdrop-filter: blur(3px); backdrop-filter: blur(3px); }
:root[data-style="glass"] .sheet .btn[data-act="ok"] { box-shadow: inset 0 1px 0 rgba(255, 255, 255, .45), 0 6px 18px color-mix(in srgb, var(--accent) 35%, transparent); }

/* система просит меньше прозрачности - стекло становится матовым */
@media (prefers-reduced-transparency: reduce) {
  :root[data-style="glass"] { --glass: rgba(255, 255, 255, .92); --glass-strong: rgba(255, 255, 255, .96); --sheet-bg: #f6f7ff; }
  :root[data-style="glass"][data-theme="dark"] { --glass: rgba(30, 32, 46, .94); --glass-strong: rgba(26, 28, 42, .96); --sheet-bg: #161826; }
}
