:root {
  --bg: #12101a;
  --bg-soft: #1b1826;
  --card: #201c2e;
  --line: #322c46;
  --text: #ece8f5;
  --muted: #a49cbd;
  --accent: #ff9d4d;
  --accent-2: #ff6b6b;
  --ok: #4ec9a0;
  --warn: #ffcf6b;
  --danger: #ff6b6b;
  --mark: #6b4a12;
  --radius: 14px;
  --tab-h: 58px;
  color-scheme: dark;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #fdfbf7;
    --bg-soft: #f4efe6;
    --card: #ffffff;
    --line: #e4dccd;
    --text: #241f2e;
    --muted: #6b6379;
    --accent: #b8531a;
    --accent-2: #b3202e;
    --ok: #17795c;
    --warn: #8a5a00;
    --danger: #b3202e;
    --mark: #ffe9a8;
    color-scheme: light;
  }
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.55 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  overscroll-behavior-y: contain;
  padding-bottom: calc(var(--tab-h) + env(safe-area-inset-bottom));
  -webkit-font-smoothing: antialiased;
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  * { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}

.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  margin: -1px; padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
}

.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  background: var(--accent);
  color: #000;
  padding: 0.6rem 1rem;
  z-index: 100;
}
.skip-link:focus { left: 0; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 6px;
}

/* --- шапка --- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(180%) blur(14px);
  -webkit-backdrop-filter: saturate(180%) blur(14px);
  border-bottom: 1px solid var(--line);
  padding-top: env(safe-area-inset-top);
}
.topbar-inner { padding: 0.55rem 1rem 0.6rem; }
.topbar-title { margin: 0; font-size: 1.05rem; font-weight: 650; letter-spacing: -0.01em; }
.topbar-sub { margin: 0.1rem 0 0; font-size: 0.8rem; color: var(--muted); }

/* --- нижние вкладки --- */
.tabbar {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  z-index: 30;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: saturate(180%) blur(14px);
  -webkit-backdrop-filter: saturate(180%) blur(14px);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar a {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  height: var(--tab-h);
  font-size: 0.66rem;
  color: var(--muted);
  text-decoration: none;
  -webkit-tap-highlight-color: transparent;
}
.tabbar a[aria-current="page"] { color: var(--accent); font-weight: 600; }
.tab-ico { font-size: 1.15rem; line-height: 1; }

/* --- общее --- */
.view { padding: 0.9rem 1rem 2rem; max-width: 780px; margin: 0 auto; }
.view:focus { outline: none; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.85rem 0.95rem;
  margin: 0 0 0.75rem;
}
.card h3 { margin: 0 0 0.35rem; font-size: 0.98rem; }
.card p { margin: 0.25rem 0; }

.muted { color: var(--muted); }
.small { font-size: 0.82rem; }
.center { text-align: center; }

.badge {
  display: inline-block;
  padding: 0.12em 0.5em;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  color: var(--muted);
}
.badge.red { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 45%, transparent); }
.badge.amber { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 45%, transparent); }
.badge.ok { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 45%, transparent); }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.5rem 0.85rem;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--bg-soft);
  color: var(--text);
  font: inherit;
  font-size: 0.85rem;
  cursor: pointer;
  text-decoration: none;
  -webkit-tap-highlight-color: transparent;
}
.btn.primary { background: var(--accent); color: #1a1206; border-color: transparent; font-weight: 600; }
.btn:active { transform: translateY(1px); }
.btn-row { display: flex; flex-wrap: wrap; gap: 0.5rem; margin: 0.6rem 0; }

/* --- «сегодня» --- */
.hero {
  background: linear-gradient(135deg, #2a1740, #7a2230);
  color: #fff;
  border-radius: 18px;
  padding: 1rem 1.05rem 1.1rem;
  margin-bottom: 0.9rem;
}
.hero .kicker { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.08em; opacity: 0.8; }
.hero h2 { margin: 0.25rem 0 0.15rem; font-size: 1.35rem; line-height: 1.2; }
.hero .sub { margin: 0; opacity: 0.88; font-size: 0.9rem; }
.hero .big { font-size: 2.4rem; font-weight: 700; line-height: 1.05; margin: 0.4rem 0 0; }

.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li {
  display: grid;
  grid-template-columns: 3.6rem 1fr;
  gap: 0.6rem;
  padding: 0.55rem 0;
  border-bottom: 1px solid var(--line);
}
.timeline li:last-child { border-bottom: 0; }
.timeline .t { font-variant-numeric: tabular-nums; font-weight: 650; color: var(--muted); }
.timeline a { color: var(--text); text-decoration: none; }
.timeline li.now { background: color-mix(in srgb, var(--accent) 14%, transparent); border-radius: 10px; padding-left: 0.5rem; }
.timeline li.now .t { color: var(--accent); }
.timeline li.past { opacity: 0.5; }

/* --- список дней --- */
.day-list { display: grid; gap: 0.55rem; }
.day-item {
  display: grid;
  grid-template-columns: 2.6rem 1fr auto;
  align-items: center;
  gap: 0.7rem;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.7rem 0.8rem;
  text-decoration: none;
  color: var(--text);
}
.day-item .n { font-size: 1.4rem; text-align: center; }
.day-item .title { font-weight: 600; font-size: 0.95rem; }
.day-item .meta { color: var(--muted); font-size: 0.8rem; }
.day-item.is-today { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }

/* --- контент дня (рендер markdown) --- */
.md { font-size: 1rem; }
.md h1 { font-size: 1.4rem; margin: 1.2rem 0 0.4rem; line-height: 1.22; }
.md h2 {
  font-size: 1.13rem;
  margin: 1.6rem 0 0.5rem;
  padding-top: 0.7rem;
  border-top: 1px solid var(--line);
  line-height: 1.25;
  scroll-margin-top: 4.2rem;
}
.md h3 { font-size: 1rem; margin: 1.1rem 0 0.35rem; color: var(--accent); scroll-margin-top: 4.2rem; }
.md h4 { font-size: 0.92rem; margin: 0.9rem 0 0.3rem; }
.md p { margin: 0.5rem 0; }
.md ul, .md ol { margin: 0.45rem 0; padding-left: 1.15rem; }
.md li { margin: 0.22rem 0; }
.md ul.nested { margin: 0.2rem 0 0.2rem 0.5rem; }
.md hr { border: 0; border-top: 1px solid var(--line); margin: 1.2rem 0; }
.md code {
  background: var(--bg-soft);
  padding: 0.08em 0.35em;
  border-radius: 5px;
  font-size: 0.88em;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}
.md pre.code {
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.7rem 0.8rem;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  font-size: 0.78rem;
  line-height: 1.4;
}
.md pre.code code { background: none; padding: 0; }
.md blockquote {
  margin: 0.7rem 0;
  padding: 0.55rem 0.8rem;
  border-left: 3px solid var(--accent);
  background: var(--bg-soft);
  border-radius: 0 10px 10px 0;
}
.md blockquote p:first-child { margin-top: 0; }
.md blockquote p:last-child { margin-bottom: 0; }
.md .table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 0.6rem 0; }
.md table { border-collapse: collapse; width: 100%; font-size: 0.85rem; }
.md th, .md td {
  border: 1px solid var(--line);
  padding: 0.4rem 0.5rem;
  text-align: left;
  vertical-align: top;
}
.md th { background: var(--bg-soft); font-weight: 650; white-space: nowrap; }
.md strong { font-weight: 650; }
.md s { opacity: 0.55; }

/* --- задачи --- */
.md li.task { list-style: none; margin-left: -1.15rem; }
.task-row {
  display: grid;
  grid-template-columns: 1.35rem 1fr;
  gap: 0.5rem;
  align-items: start;
  padding: 0.28rem 0.3rem;
  border-radius: 8px;
  cursor: pointer;
}
.task-row input[type="checkbox"] {
  width: 1.25rem;
  height: 1.25rem;
  margin: 0.15rem 0 0;
  accent-color: var(--ok);
  flex: none;
}
.task-row input:checked ~ .task-text { opacity: 0.5; text-decoration: line-through; }
.md li.task.static { display: flex; gap: 0.5rem; align-items: baseline; }
.md li.task.static .box {
  width: 0.85rem; height: 0.85rem; flex: none;
  border: 1.5px solid var(--muted); border-radius: 4px; display: inline-block;
}
.md li.task.static .box.on { background: var(--ok); border-color: var(--ok); }

.progress {
  height: 8px;
  border-radius: 999px;
  background: var(--bg-soft);
  overflow: hidden;
  border: 1px solid var(--line);
}
.progress > i { display: block; height: 100%; background: var(--ok); transition: width 0.25s; }

/* --- поиск --- */
.search-box { position: sticky; top: 0; z-index: 10; padding: 0.2rem 0 0.7rem; background: var(--bg); }
.search-box input {
  width: 100%;
  font: inherit;
  font-size: 1rem;
  padding: 0.7rem 0.85rem;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--text);
  -webkit-appearance: none;
}
.result {
  display: block;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.65rem 0.8rem;
  margin-bottom: 0.5rem;
  text-decoration: none;
  color: var(--text);
}
.result .src { font-size: 0.72rem; color: var(--accent); font-weight: 600; }
.result .h { font-weight: 600; margin: 0.15rem 0; font-size: 0.92rem; }
.result .sn { font-size: 0.83rem; color: var(--muted); }
mark { background: var(--mark); color: inherit; border-radius: 3px; padding: 0 0.1em; }

/* --- брони --- */
.kv { display: grid; grid-template-columns: auto 1fr; gap: 0.2rem 0.6rem; font-size: 0.86rem; margin: 0.4rem 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.code-chip {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.9rem;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.25rem 0.5rem;
  cursor: pointer;
  color: var(--text);
}
.warn-box {
  border-left: 3px solid var(--warn);
  background: color-mix(in srgb, var(--warn) 10%, transparent);
  padding: 0.45rem 0.65rem;
  border-radius: 0 8px 8px 0;
  font-size: 0.85rem;
  margin-top: 0.5rem;
}
.section-title { margin: 1.4rem 0 0.6rem; font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.09em; color: var(--muted); }

/* --- навигация по дню --- */
.daynav { display: flex; justify-content: space-between; gap: 0.5rem; margin: 1.4rem 0 0; }
.daynav a { flex: 1; text-align: center; }
.daynav .spacer { flex: 1; }

details.toc { margin: 0.4rem 0 0.8rem; border: 1px solid var(--line); border-radius: var(--radius); background: var(--card); }
details.toc summary { padding: 0.6rem 0.8rem; cursor: pointer; font-weight: 600; font-size: 0.9rem; }
details.toc ol { margin: 0; padding: 0 0.9rem 0.7rem 1.6rem; }
details.toc li { margin: 0.25rem 0; }
details.toc a { color: var(--text); text-decoration: none; font-size: 0.88rem; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--tab-h) + env(safe-area-inset-bottom) + 12px);
  transform: translateX(-50%);
  background: var(--card);
  border: 1px solid var(--line);
  color: var(--text);
  padding: 0.55rem 0.9rem;
  border-radius: 999px;
  font-size: 0.85rem;
  z-index: 50;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.35);
}
