:root {
  --bg: var(--tg-theme-secondary-bg-color, #f2f1ed);
  --surface: var(--tg-theme-section-bg-color, var(--tg-theme-bg-color, #fff));
  --text: var(--tg-theme-text-color, #1d1c1a);
  --muted: var(--tg-theme-hint-color, #77746c);
  --line: color-mix(in srgb, var(--text) 11%, transparent);
  --accent: var(--tg-theme-button-color, #2c5f8a);
  --accent-text: var(--tg-theme-button-text-color, #fff);
  --danger: var(--tg-theme-destructive-text-color, #b3392f);
  --g5: #2f7d4f;
  --g4: #3b6ea5;
  --g3: #b07415;
  --g2: #b3392f;
  --radius: 14px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: var(--tg-theme-secondary-bg-color, #161615);
    --surface: var(--tg-theme-section-bg-color, var(--tg-theme-bg-color, #21201e));
    --text: var(--tg-theme-text-color, #eeece6);
    --muted: var(--tg-theme-hint-color, #96938b);
    --accent: var(--tg-theme-button-color, #6ea6d6);
    --accent-text: var(--tg-theme-button-text-color, #10222f);
    --g5: #6cbf8c;
    --g4: #7fb0e0;
    --g3: #dba84f;
    --g2: #e4796e;
  }
}

:root[data-theme="dark"] {
  --g5: #6cbf8c;
  --g4: #7fb0e0;
  --g3: #dba84f;
  --g2: #e4796e;
}

* { box-sizing: border-box; }

/* Листают пальцем, полоса прокрутки только мешает. */
html { scrollbar-width: none; }
html::-webkit-scrollbar { display: none; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

main {
  max-width: 560px;
  margin: 0 auto;
  padding: 18px 16px calc(84px + env(safe-area-inset-bottom));
}

button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
button:focus-visible, input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.header { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; margin-bottom: 4px; }
h1 { font-size: 24px; line-height: 1.2; font-weight: 650; margin: 0; letter-spacing: -0.01em; }
.sub { color: var(--muted); font-size: 13px; margin: 0 0 20px; }
.link { color: var(--accent); font-size: 14px; white-space: nowrap; }
.link[disabled] { color: var(--muted); }

h2 { font-size: 13px; font-weight: 600; color: var(--muted); margin: 24px 0 8px; }

.num { font-variant-numeric: tabular-nums; }

.notice {
  background: var(--surface);
  border-left: 3px solid var(--g3);
  border-radius: 6px;
  padding: 10px 12px;
  margin-bottom: 16px;
  font-size: 14px;
}
.notice--bad { border-color: var(--danger); }

.card, .list { background: var(--surface); border-radius: var(--radius); }

.card {
  display: grid;
  grid-template-columns: 52px 1fr;
  gap: 2px 12px;
  width: 100%;
  text-align: left;
  padding: 14px;
  margin-bottom: 8px;
}
.card .grade { grid-row: span 4; font-size: 25px; line-height: 1.15; font-weight: 650; }
.card__warn { margin-top: 6px; font-size: 13px; color: var(--danger); }
.card__name { font-weight: 600; }
.card__meta { color: var(--muted); font-size: 13px; }
.card__way { margin-top: 6px; font-size: 14px; }
.card__way b { font-weight: 600; }

.grade--5 { color: var(--g5); }
.grade--4 { color: var(--g4); }
.grade--3 { color: var(--g3); }
.grade--2, .grade--1 { color: var(--g2); }
.grade--x { color: var(--muted); }

.list { overflow: hidden; }
.row {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 11px 14px;
  text-align: left;
  border-bottom: 1px solid var(--line);
}
.row:last-child { border-bottom: 0; }
.row__main { flex: 1; min-width: 0; }
.row__name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row__meta { color: var(--muted); font-size: 13px; }
.row__grade { font-weight: 650; font-size: 17px; min-width: 24px; text-align: right; }

.empty { color: var(--muted); text-align: center; padding: 48px 16px; }

/* Экран предмета */
.back { color: var(--accent); margin-bottom: 14px; display: block; }
.summary { display: flex; align-items: center; gap: 14px; margin-bottom: 10px; }
.summary .grade { font-size: 52px; line-height: 1; font-weight: 650; }
.figures { display: flex; gap: 18px; }
.figures div { font-size: 12px; color: var(--muted); }
.figures b { display: block; font-size: 18px; color: var(--text); font-weight: 600; }
.explain { margin: 0 0 6px; }
.warn { color: var(--danger); font-size: 14px; margin: 6px 0 0; }
.hint { color: var(--muted); font-size: 13px; margin: 6px 0 0; }

.panel { background: var(--surface); border-radius: var(--radius); padding: 14px; }
.way { padding: 6px 0; }
.way + .way { border-top: 1px solid var(--line); }

.sim__buttons { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-top: 10px; }
.sim__btn {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 9px 0;
  text-align: center;
  font-weight: 600;
}
.sim__btn:active { background: var(--line); }
.sim__added { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 10px; min-height: 24px; color: var(--muted); font-size: 13px; }
.sim__result { margin-top: 10px; font-weight: 600; }

.mark { display: grid; grid-template-columns: 28px 1fr; gap: 0 10px; padding: 10px 14px; border-bottom: 1px solid var(--line); }
.mark:last-child { border-bottom: 0; }
.mark .grade { font-size: 18px; font-weight: 650; }
.mark__meta { color: var(--muted); font-size: 13px; }
.mark__topic { font-size: 14px; }
.chip {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  padding: 0 5px;
  border-radius: 4px;
  border: 1px solid currentColor;
  margin-right: 4px;
}

/* Лента */
.event { display: grid; grid-template-columns: 28px 1fr; gap: 0 10px; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.event:last-child { border-bottom: 0; }
.event .grade { font-size: 20px; font-weight: 650; }
.event__unseen .event__name::after {
  content: "";
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent);
  margin-left: 6px;
  vertical-align: middle;
}
.event__name { font-weight: 600; }

/* Дневник */
.week-nav { display: flex; align-items: center; gap: 8px; margin-bottom: 18px; }
.week-nav__title { flex: 1; text-align: center; }
.week-nav__name { font-size: 20px; font-weight: 650; }
.week-nav__dates { color: var(--muted); font-size: 13px; }
.week-nav__arrow {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: var(--surface);
  color: var(--accent);
  font-size: 26px;
  line-height: 1;
}
.week-nav__arrow[disabled] { color: var(--muted); opacity: 0.4; cursor: default; }
.day { margin-bottom: 14px; }
.day__title { font-size: 15px; font-weight: 600; margin: 0 0 6px; display: flex; align-items: baseline; gap: 8px; }
.day__today { font-size: 12px; font-weight: 600; color: var(--accent); }
.day__note { color: var(--muted); font-size: 14px; margin: -2px 0 6px; }
.day--off .day__title { color: var(--muted); }
.day__extra { color: var(--muted); font-size: 12px; margin: 8px 0 4px; }
.lesson { display: grid; grid-template-columns: 18px 1fr; gap: 0 10px; padding: 11px 14px; border-bottom: 1px solid var(--line); }
.lesson:last-child { border-bottom: 0; }
.lesson__num { color: var(--muted); font-size: 14px; padding-top: 1px; }
.lesson__head { display: flex; align-items: baseline; gap: 4px; flex-wrap: wrap; }
.lesson__subject { font-weight: 600; margin-right: auto; }
.lesson__time { color: var(--muted); font-size: 12px; }
.lesson__hw { margin-top: 4px; white-space: pre-wrap; overflow-wrap: anywhere; }
.lesson__none { margin-top: 2px; color: var(--muted); font-size: 13px; }
.lesson__topic { margin-top: 4px; color: var(--muted); font-size: 13px; }
.lesson__changed { margin-top: 4px; color: var(--g3); font-size: 13px; }
.file { display: inline-block; margin: 6px 6px 0 0; padding: 4px 9px; border: 1px solid var(--line); border-radius: 8px; color: var(--accent); font-size: 14px; text-decoration: none; overflow-wrap: anywhere; }
.file--missing { color: var(--muted); }

.settings-link {
  display: flex;
  justify-content: space-between;
  width: 100%;
  margin-top: 28px;
  padding: 12px 14px;
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--muted);
  font-size: 14px;
}

/* Первый вход */
.form label { display: block; font-size: 13px; color: var(--muted); margin: 14px 0 4px; }
.form input {
  width: 100%;
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 11px 12px;
}
.primary {
  display: block;
  width: 100%;
  margin-top: 20px;
  padding: 13px;
  border-radius: 12px;
  background: var(--accent);
  color: var(--accent-text);
  font-weight: 600;
}
.primary[disabled] { opacity: 0.6; }
.secondary {
  display: block;
  width: 100%;
  margin-top: 10px;
  padding: 12px;
  border-radius: 12px;
  border: 1px solid var(--line);
  color: var(--accent);
  font-weight: 600;
}
.secondary[disabled] { color: var(--muted); }
.secondary--danger { color: var(--danger); }
.form select {
  width: 100%;
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 11px 12px;
}
.form__note { color: var(--muted); font-size: 13px; margin-top: 14px; }
.form__error { color: var(--danger); font-size: 14px; margin-top: 10px; }

.tabs {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  justify-content: center;
  background: var(--surface);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabs[hidden] { display: none; }
.tab { flex: 1; max-width: 280px; padding: 14px 0; color: var(--muted); font-weight: 500; }
.tab--active { color: var(--accent); font-weight: 600; }
.badge {
  display: inline-block;
  min-width: 18px;
  margin-left: 6px;
  padding: 0 5px;
  border-radius: 9px;
  background: var(--accent);
  color: var(--accent-text);
  font-size: 12px;
  line-height: 18px;
}
.badge[hidden] { display: none; }
