:root {
  --bg: #f4f5fa;
  --card: #ffffff;
  --text: #14161f;
  --muted: #6b7080;
  --line: #e4e6ee;
  --accent: #3b5bdb;
  --accent-soft: #e7ecff;
  --lk: #6741d9;
  --lk-soft: #efe9ff;
  --lk-card: #f7f3ff;
  --pz: #2b8a3e;
  --pz-soft: #e3f6e7;
  --pz-card: #f3fbf5;
  --exam: #e03131;
  --exam-soft: #ffe6e6;
  --exam-card: #fff4f4;
  --on-exam: #ffffff;
  --now: #3b5bdb;
  --now-bg: #3b5bdb;
  --sel-bg: #3b5bdb;
  --on-accent: #ffffff;
  --shadow: 0 1px 2px rgba(20, 22, 31, .05), 0 4px 16px rgba(20, 22, 31, .05);
  --radius: 16px;
  --tabbar-h: 58px;
  color-scheme: light dark;
}

/* Тёмная тема: по настройке iPhone, либо принудительно (Telegram задаёт data-theme) */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1117;
    --card: #1a1d27;
    --text: #eceef5;
    --muted: #9196a8;
    --line: #2a2e3b;
    --accent: #8ea6ff;
    --accent-soft: #232b4a;
    --lk: #b9a2ff;
    --lk-soft: #2c2445;
    --lk-card: #211e33;
    --pz: #69db7c;
    --pz-soft: #183a22;
    --pz-card: #18261e;
    --exam: #ff8787;
    --exam-soft: #4a1f22;
    --exam-card: #2e1c20;
    --on-exam: #2b0d0f;
    --now: #8ea6ff;
    --now-bg: #2b3a78;
    --sel-bg: #3d52a8;
    --on-accent: #0f1117;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1117;
  --card: #1a1d27;
  --text: #eceef5;
  --muted: #9196a8;
  --line: #2a2e3b;
  --accent: #8ea6ff;
  --accent-soft: #232b4a;
  --lk: #b9a2ff;
  --lk-soft: #2c2445;
  --lk-card: #211e33;
  --pz: #69db7c;
  --pz-soft: #183a22;
  --pz-card: #18261e;
  --exam: #ff8787;
  --exam-soft: #4a1f22;
  --exam-card: #2e1c20;
  --on-exam: #2b0d0f;
  --now: #8ea6ff;
  --now-bg: #2b3a78;
  --sel-bg: #3d52a8;
  --on-accent: #0f1117;
  --shadow: none;
  color-scheme: dark;
}
:root[data-theme="light"] { color-scheme: light; }

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  padding: env(safe-area-inset-top) 0 calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 12px);
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}

button { font: inherit; color: inherit; cursor: pointer; }

/* ---------- Header ---------- */
.top {
  position: sticky;
  top: 0;
  z-index: 5;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  -webkit-backdrop-filter: saturate(180%) blur(16px);
  backdrop-filter: saturate(180%) blur(16px);
  padding: 12px 16px 8px;
}
.top-row { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; max-width: 640px; margin: 0 auto; }
.eyebrow { font-size: 13px; color: var(--muted); font-weight: 500; }
h1 { margin: 2px 0 0; font-size: 28px; line-height: 1.15; letter-spacing: -.02em; }
.icon-btn {
  border: 0; background: var(--accent-soft); color: var(--accent);
  font-weight: 600; font-size: 15px; padding: 7px 14px; border-radius: 999px;
}

main { max-width: 640px; margin: 0 auto; padding: 0 16px; }

.tab { display: none; }
.tab.active { display: block; }

/* ---------- Now card ---------- */
.now:empty { display: none; }
.now {
  margin: 8px 0 14px;
  padding: 14px 16px;
  border-radius: var(--radius);
  background: var(--now-bg);
  color: #fff;
}
.now .label { font-size: 13px; opacity: .85; font-weight: 500; }
.now .subj { font-size: 18px; font-weight: 650; margin-top: 2px; line-height: 1.25; }
.now .meta { font-size: 14px; opacity: .9; margin-top: 4px; }
.now .bar { height: 5px; border-radius: 3px; background: rgba(255,255,255,.28); margin-top: 10px; overflow: hidden; }
.now .bar > i { display: block; height: 100%; background: #fff; border-radius: 3px; }

/* ---------- Day strip ---------- */
.days {
  display: flex; gap: 8px; overflow-x: auto;
  margin: 0 -16px; padding: 4px 16px 10px;
  scroll-snap-type: x proximity; scrollbar-width: none;
}
.days::-webkit-scrollbar { display: none; }
.day {
  flex: 0 0 auto; width: 52px; scroll-snap-align: center;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 8px 0 7px; border-radius: 14px; border: 0;
  background: var(--card); box-shadow: var(--shadow);
}
.day .dw { font-size: 12px; color: var(--muted); text-transform: uppercase; font-weight: 600; }
.day .dn { font-size: 19px; font-weight: 650; }
.day .dot { width: 5px; height: 5px; border-radius: 50%; background: transparent; }
.day.has .dot { background: var(--muted); opacity: .5; }
.day.has-exam { outline: 1.5px solid var(--exam); outline-offset: -1.5px; }
.day.has-exam .dot { background: var(--exam); opacity: 1; }
.day.empty .dn { color: var(--muted); font-weight: 500; }
.day.today .dn { color: var(--accent); }
.day.sel { background: var(--sel-bg); }
.day.sel .dw, .day.sel .dn { color: #fff; }
.day.sel .dot { background: #fff; opacity: .9; }

.day-head { display: flex; align-items: baseline; justify-content: space-between; margin: 6px 2px 10px; }
.day-head h2 { margin: 0; font-size: 20px; letter-spacing: -.01em; }
.day-head span { color: var(--muted); font-size: 14px; }

/* ---------- Pairs ---------- */
.pairs, .exams { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }

.pair {
  display: grid; grid-template-columns: 54px 1fr; gap: 12px;
  background: var(--card); border-radius: var(--radius); padding: 14px 14px 14px 12px;
  box-shadow: var(--shadow); position: relative;
}
.pair .time { text-align: right; font-variant-numeric: tabular-nums; }
.pair .t1 { font-weight: 650; font-size: 16px; }
.pair .t2 { color: var(--muted); font-size: 13px; }
.pair .n { color: var(--muted); font-size: 11px; margin-top: 4px; }
.pair .body { border-left: 3px solid var(--line); padding-left: 12px; min-width: 0; }
/* Цвет карточки по типу: лекция — фиолетовый, практика — зелёный, зачёт/экзамен — красный */
.pair .body { border-left-width: 4px; }
.pair.lk { background: var(--lk-card); }
.pair.pz { background: var(--pz-card); }
.pair.lk .body { border-color: var(--lk); }
.pair.pz .body { border-color: var(--pz); }
.pair.is-exam { background: var(--exam-card); outline: 1.5px solid var(--exam); outline-offset: 0; }
.pair.is-exam .body { border-color: var(--exam); }
.pair.is-exam .subj { color: var(--exam); }
.pair.is-exam.current { outline: 2.5px solid var(--exam); }
.pair.is-exam.current::after { background: var(--exam); color: var(--on-exam); }
.pair .subj { font-weight: 600; font-size: 16px; line-height: 1.3; }
.pair .who { color: var(--muted); font-size: 14px; margin-top: 3px; }
.pair .tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; align-items: center; }
.room { font-size: 13px; font-weight: 600; padding: 2px 8px; border-radius: 999px; background: var(--bg); }

.pair.past { opacity: .5; }
.pair.current { outline: 2px solid var(--now); outline-offset: 0; }
.pair.current::after {
  content: "Идёт сейчас"; position: absolute; top: -9px; right: 12px;
  background: var(--now); color: var(--on-accent); font-size: 11px; font-weight: 700;
  padding: 2px 8px; border-radius: 999px;
}

.break { text-align: center; color: var(--muted); font-size: 12px; margin: -4px 0; }

.badge { font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 999px; white-space: nowrap; }
.badge.lk { background: var(--lk-soft); color: var(--lk); }
.badge.pz { background: var(--pz-soft); color: var(--pz); }
.badge.exam { background: var(--exam); color: var(--on-exam); }

.empty-day {
  text-align: center; padding: 36px 16px; color: var(--muted);
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
}
.empty-day b { display: block; color: var(--text); font-size: 18px; margin-bottom: 4px; }

/* ---------- Exams ---------- */
.section-title { font-size: 20px; margin: 18px 2px 10px; letter-spacing: -.01em; }
.exam-item {
  display: flex; gap: 14px; align-items: center;
  background: var(--card); border-radius: var(--radius); padding: 12px 14px; box-shadow: var(--shadow);
}
.exam-item.done { opacity: .5; }
.exam-date { flex: 0 0 48px; text-align: center; border-radius: 12px; background: var(--exam-soft); color: var(--exam); padding: 6px 0; }
.exam-date b { display: block; font-size: 20px; line-height: 1.1; }
.exam-date span { font-size: 11px; font-weight: 600; text-transform: uppercase; }
.exam-item .subj { font-weight: 600; line-height: 1.3; }
.exam-item .who { color: var(--muted); font-size: 14px; margin-top: 2px; }
button.exam-item { width: 100%; text-align: left; border: 0; }

/* ---------- Info ---------- */
.note { background: var(--accent-soft); color: var(--text); border-radius: 12px; padding: 10px 12px; font-size: 14px; margin-bottom: 12px; }
.note:empty { display: none; }
.step-n { flex: 0 0 26px; height: 26px; border-radius: 50%; background: var(--accent); color: var(--on-accent); font-weight: 700; font-size: 14px; display: grid; place-items: center; }
.legend { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 8px; font-size: 15px; }
.legend .badge { margin-right: 6px; }
.facts { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; margin: 0; background: var(--card); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); font-size: 15px; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

/* ---------- Tab bar ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; justify-content: space-around;
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: color-mix(in srgb, var(--card) 88%, transparent);
  -webkit-backdrop-filter: saturate(180%) blur(16px);
  backdrop-filter: saturate(180%) blur(16px);
  border-top: 1px solid var(--line);
}
.tabbar button {
  flex: 1; max-width: 160px; border: 0; background: none;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--muted); font-size: 11px; font-weight: 600;
}
.tabbar svg { width: 25px; height: 25px; }
.tabbar button.active { color: var(--accent); }

.admin-link {
  display: flex; gap: 12px; align-items: center; margin: 18px 0 8px;
  background: var(--card); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow);
  color: var(--text); text-decoration: none;
}
.admin-link[hidden] { display: none; }
.admin-link svg { flex: 0 0 26px; height: 26px; color: var(--accent); }
.admin-link span { display: flex; flex-direction: column; }
.admin-link small { color: var(--muted); font-size: 13px; margin-top: 2px; }
.exams-hint { margin: 8px 2px 12px; }
