/* ═══ Конспекты Катюши ═══════════════════════════════════════════════════ */

:root {
  --bg:          #fbf2f4;
  --surface:     #ffffff;
  --line:        #f2dde3;
  --line-strong: #f0dae1;
  --line-soft:   #f7e6eb;
  --accent:      #e58fa6;
  --accent-soft: #e9b7c4;
  --link:        #a85b70;
  --link-hover:  #7d3d50;
  --ink:         #3d3035;
  --ink-serif:   #4a2f39;
  --ink-logo:    #5c3743;
  --muted:       #96707c;
  --muted-warm:  #836470;
  --muted-mono:  #a3808c;
  --muted-faint: #c39aa7;
  --muted-foot:  #b394a0;
  --soft:        #fbeef1;
  --soft-2:      #f8eef1;

  --serif: Lora, Georgia, 'Times New Roman', serif;
  --sans:  Manrope, -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, sans-serif;
  --mono:  'IBM Plex Mono', ui-monospace, SFMono-Regular, Menlo, monospace;

  --wrap:      1080px;
  --gutter:    28px;
  --header-h:  73px;
  --radius-lg: 22px;
  --radius-md: 16px;

  color-scheme: light;
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overflow-wrap: break-word;
}

::selection { background: #f6d5de; }

a { color: var(--link); text-decoration: none; }
a:hover { color: var(--link-hover); }

button { font: inherit; color: inherit; }

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

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

.wrap {
  max-width: var(--wrap);
  margin: 0 auto;
  padding-inline: max(var(--gutter), env(safe-area-inset-left), env(safe-area-inset-right));
}

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

/* ═══ header ═════════════════════════════════════════════════════════════ */

.site-header {
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(251, 242, 244, .92);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line-strong);
  padding-top: env(safe-area-inset-top);
}

.header-inner {
  display: flex;
  align-items: center;
  gap: 24px;
  padding-block: 18px;
}

.brand {
  display: flex;
  align-items: baseline;
  gap: 10px;
  flex-shrink: 0;
}

.brand-dot {
  width: 12px; height: 12px;
  border-radius: 50%;
  background: var(--accent);
  flex-shrink: 0;
  align-self: center;
}

.brand-name {
  font-family: var(--serif);
  font-style: italic;
  font-size: 26px;
  font-weight: 600;
  letter-spacing: -.01em;
  color: var(--ink-logo);
  white-space: nowrap;
}
.brand:hover .brand-name { color: var(--ink-logo); }

.search {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  padding: 10px 18px;
  min-width: 260px;
  box-shadow: 0 1px 2px rgba(140, 80, 100, .04);
  transition: border-color .16s ease;
}
.search:focus-within { border-color: var(--accent-soft); }

.search-icon {
  width: 9px; height: 9px;
  border: 2px solid #d9a2b2;
  border-radius: 50%;
  flex-shrink: 0;
}

.search input {
  border: none;
  outline: none;
  background: transparent;
  font: inherit;
  font-size: 15px;
  color: var(--ink);
  width: 100%;
  min-width: 0;
  -webkit-appearance: none;
  appearance: none;
}
.search input::placeholder { color: var(--muted-faint); }
.search input::-webkit-search-cancel-button { -webkit-appearance: none; }

/* ═══ page chrome ════════════════════════════════════════════════════════ */

.page { padding-block: 40px 80px; min-height: 60vh; }

.hero-title {
  margin: 0 0 10px;
  font-family: var(--serif);
  font-weight: 500;
  font-size: clamp(30px, 5.2vw, 44px);
  line-height: 1.1;
  letter-spacing: -.02em;
  color: var(--ink-serif);
  max-width: 16ch;
  text-wrap: pretty;
}

.hero-sub {
  margin: 0 0 40px;
  font-size: clamp(15px, 2vw, 17px);
  line-height: 1.6;
  color: var(--muted-warm);
  max-width: 46ch;
}

.page-title {
  margin: 0 0 6px;
  font-family: var(--serif);
  font-weight: 500;
  font-size: clamp(26px, 4.4vw, 38px);
  line-height: 1.15;
  letter-spacing: -.02em;
  color: var(--ink-serif);
}

.page-meta {
  margin: 0 0 32px;
  font-family: var(--mono);
  font-size: 14px;
  color: var(--muted);
}

.eyebrow {
  margin: 0 0 20px;
  font-family: var(--mono);
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--muted);
}

.back-link {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  color: var(--link);
  margin-bottom: 22px;
  min-height: 32px;
}
.back-link:hover { gap: 11px; }
.back-link span:first-child { transition: transform .16s ease; }

/* ═══ subjects ═══════════════════════════════════════════════════════════ */

.subject-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 16px;
}

.subject-card {
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-height: 172px;
  padding: 26px 24px 22px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  color: inherit;
  transition: transform .18s ease, border-color .18s ease, box-shadow .18s ease;
}
.subject-card:hover {
  transform: translateY(-3px);
  border-color: var(--accent-soft);
  box-shadow: 0 12px 26px rgba(150, 90, 110, .09);
  color: inherit;
}
.subject-card:active { transform: translateY(-1px); }

.subject-chip {
  width: 34px; height: 34px;
  border-radius: 12px;
  background: var(--accent);
}

.subject-name {
  font-family: var(--serif);
  font-size: 23px;
  font-weight: 600;
  color: var(--ink-serif);
  line-height: 1.15;
}

.subject-meta {
  font-family: var(--mono);
  font-size: 13px;
  color: var(--muted-mono);
}

/* ═══ topic rows ═════════════════════════════════════════════════════════ */

.topic-list { display: flex; flex-direction: column; gap: 10px; }

.topic-row {
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 20px 24px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  color: inherit;
  transition: border-color .16s ease;
}
.topic-row:hover { border-color: var(--accent); color: inherit; }

.topic-num {
  font-family: var(--mono);
  font-size: 13px;
  color: var(--muted-faint);
  width: 28px;
  flex-shrink: 0;
}

.topic-title {
  font-size: 17px;
  font-weight: 600;
  color: var(--ink);
  line-height: 1.3;
}

.topic-pages {
  font-size: 13px;
  color: var(--muted);
  white-space: nowrap;
}

.topic-open {
  font-size: 13px;
  font-weight: 600;
  color: var(--link);
  white-space: nowrap;
}

.topic-sub { font-size: 13px; color: var(--muted); }

.result-snippet {
  display: block;
  width: 100%;
  margin-top: 6px;
  font-size: 14px;
  line-height: 1.5;
  color: var(--muted-warm);
}
.result-snippet mark {
  background: #f9dde5;
  color: var(--ink-serif);
  border-radius: 3px;
  padding: 0 2px;
}

/* ═══ note view ══════════════════════════════════════════════════════════ */

.note-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 260px;
  gap: 28px;
  align-items: start;
}

.note-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  overflow: hidden;
  min-width: 0;
}

.note-head {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  padding: 16px 22px;
  border-bottom: 1px solid var(--line-soft);
}

.note-title {
  margin: 0;
  font-family: var(--serif);
  font-size: 20px;
  font-weight: 600;
  color: var(--ink-serif);
  line-height: 1.2;
}

.note-meta {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--muted-mono);
}

.pill {
  font-size: 13px;
  font-weight: 600;
  background: var(--soft);
  border: 1px solid #f0d6de;
  border-radius: 999px;
  padding: 8px 16px;
  color: var(--link);
  cursor: pointer;
  white-space: nowrap;
  transition: background .16s ease, border-color .16s ease;
}
.pill:hover { background: #f8e2e9; border-color: var(--accent-soft); }

.note-body { padding: 30px 34px 38px; }

.note-empty {
  padding: 44px 34px 52px;
  text-align: center;
  color: var(--muted);
}
.note-empty p { margin: 0 0 6px; }
.note-empty .hint { font-family: var(--mono); font-size: 13px; color: var(--muted-faint); }

/* section stepper under the note */
.section-pager {
  display: flex;
  gap: 12px;
  align-items: stretch;
  padding: 0 34px 30px;
}
.section-pager a {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 12px 16px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fffdfd;
  transition: border-color .16s ease;
}
.section-pager a:hover { border-color: var(--accent-soft); }
.section-pager .dir {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--muted-mono);
}
.section-pager .label {
  font-size: 14px;
  font-weight: 600;
  color: var(--ink-serif);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.section-pager .next { text-align: right; }

/* ═══ sidebar: contents + other topics ═══════════════════════════════════ */

.note-aside {
  position: sticky;
  top: calc(var(--header-h) + 24px);
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-width: 0;
}

.aside-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 20px;
}

.aside-label {
  margin: 0 0 14px;
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--muted-mono);
}

.aside-list { display: flex; flex-direction: column; gap: 4px; }

.aside-link {
  border-radius: 10px;
  padding: 9px 12px;
  font-size: 14px;
  line-height: 1.35;
  color: #6b545c;
  transition: background .14s ease;
}
.aside-link:hover { background: var(--soft); color: #6b545c; }
.aside-link.is-current {
  color: #8a4f60;
  background: var(--soft);
  font-weight: 600;
}

/* table of contents */
.toc { display: flex; flex-direction: column; gap: 2px; max-height: 52vh; overflow-y: auto; }
.toc-link {
  display: block;
  border-radius: 10px;
  padding: 8px 12px;
  font-size: 14px;
  line-height: 1.35;
  color: #6b545c;
  border-left: 2px solid transparent;
  transition: background .14s ease, color .14s ease, border-color .14s ease;
}
.toc-link:hover { background: var(--soft); color: var(--link-hover); }
.toc-link.lvl-2 { padding-left: 22px; font-size: 13.5px; }
.toc-link.lvl-3 { padding-left: 34px; font-size: 13px; color: var(--muted); }
.toc-link.is-active {
  background: var(--soft);
  color: #8a4f60;
  font-weight: 600;
  border-left-color: var(--accent);
}

/* mobile/tablet: contents collapse into a disclosure */
.toc-toggle { display: none; }

/* ═══ prose (rendered markdown) ══════════════════════════════════════════ */

.prose { font-size: 16.5px; line-height: 1.72; color: var(--ink); }
.prose > *:first-child { margin-top: 0; }
.prose > *:last-child { margin-bottom: 0; }

.prose h1, .prose h2, .prose h3, .prose h4, .prose h5, .prose h6 {
  font-family: var(--serif);
  color: var(--ink-serif);
  line-height: 1.25;
  letter-spacing: -.01em;
  scroll-margin-top: calc(var(--header-h) + 20px);
}
.prose h1 { font-size: 30px; font-weight: 600; margin: 42px 0 14px; }
.prose h2 {
  font-size: 24px;
  font-weight: 600;
  margin: 38px 0 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--line-soft);
}
.prose h3 { font-size: 20px; font-weight: 600; margin: 30px 0 10px; }
.prose h4 { font-size: 17px; font-weight: 600; margin: 24px 0 8px; }
.prose h5, .prose h6 { font-size: 15px; font-weight: 600; margin: 20px 0 6px; }

.prose p { margin: 0 0 16px; }
.prose strong { font-weight: 700; color: var(--ink-serif); }
.prose em { font-style: italic; }
.prose del { color: var(--muted); }

.prose ul, .prose ol { margin: 0 0 16px; padding-left: 26px; }
.prose li { margin-bottom: 7px; }
.prose li > ul, .prose li > ol { margin: 7px 0 0; }
.prose ul { list-style: none; padding-left: 22px; }
.prose ul > li { position: relative; }
.prose ul > li::before {
  content: '';
  position: absolute;
  left: -16px;
  top: .68em;
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--accent-soft);
}
.prose ol { list-style: decimal; }
.prose ol > li::marker { color: var(--muted-faint); font-family: var(--mono); font-size: .9em; }

.prose blockquote {
  margin: 22px 0;
  padding: 14px 20px;
  border-left: 3px solid var(--accent);
  background: var(--soft-2);
  border-radius: 0 12px 12px 0;
  color: var(--muted-warm);
}
.prose blockquote p:last-child { margin-bottom: 0; }

.prose code {
  font-family: var(--mono);
  font-size: .89em;
  background: var(--soft);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: .12em .38em;
  color: #8a4f60;
}

.prose pre {
  margin: 0 0 20px;
  padding: 16px 18px;
  background: #fdf7f9;
  border: 1px solid var(--line);
  border-radius: 14px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.prose pre code {
  background: none;
  border: none;
  padding: 0;
  font-size: 13.5px;
  line-height: 1.65;
  color: #5c4750;
}

.prose hr {
  border: none;
  border-top: 1px solid var(--line-strong);
  margin: 34px 0;
}

.prose img {
  max-width: 100%;
  height: auto;
  border-radius: 14px;
  border: 1px solid var(--line);
  margin: 6px 0;
}

.md-table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: 0 0 20px;
  border: 1px solid var(--line);
  border-radius: 14px;
}
.prose table { border-collapse: collapse; width: 100%; font-size: 15px; }
.prose th, .prose td {
  padding: 11px 16px;
  text-align: left;
  border-bottom: 1px solid var(--line-soft);
}
.prose th {
  background: var(--soft-2);
  font-weight: 600;
  color: var(--ink-serif);
  white-space: nowrap;
}
.prose tbody tr:last-child td { border-bottom: none; }

/* ═══ states ═════════════════════════════════════════════════════════════ */

.empty-state {
  background: var(--surface);
  border: 1px dashed var(--accent-soft);
  border-radius: var(--radius-lg);
  padding: 48px 28px;
  text-align: center;
  color: var(--muted);
}
.empty-state h2 {
  margin: 0 0 8px;
  font-family: var(--serif);
  font-size: 22px;
  font-weight: 600;
  color: var(--ink-serif);
}
.empty-state p { margin: 0 auto; max-width: 42ch; line-height: 1.6; }

.loading {
  padding: 60px 0;
  text-align: center;
  font-family: var(--mono);
  font-size: 13px;
  color: var(--muted-faint);
}

/* ═══ footer ═════════════════════════════════════════════════════════════ */

.site-footer {
  border-top: 1px solid var(--line-strong);
  padding-block: 26px;
  padding-bottom: calc(26px + env(safe-area-inset-bottom));
}
.footer-inner { display: flex; gap: 16px; flex-wrap: wrap; align-items: center; }
.footer-brand {
  font-family: var(--serif);
  font-style: italic;
  font-size: 15px;
  color: var(--muted);
}
.footer-meta { font-family: var(--mono); font-size: 12px; color: var(--muted-foot); }
.footer-link { font-family: var(--mono); font-size: 12px; color: var(--muted-foot); }
.footer-link:hover { color: var(--link); }

/* ═══ tablet — iPad portrait ═════════════════════════════════════════════ */

@media (max-width: 1023px) {
  :root { --gutter: 24px; }

  .note-layout { grid-template-columns: minmax(0, 1fr); gap: 16px; }

  /* Dissolve the side column so its two cards become grid items in their own
     right: contents goes above the note (jumping sections stays one tap away),
     other topics below it — the reader reaches the конспект without scrolling
     past a list of everything else. */
  .note-aside { display: contents; }
  .toc-card { order: -1; }
  .note-card { order: 0; }
  .other-topics { order: 1; }
  .toc-card { padding: 0; overflow: hidden; }
  .toc-toggle {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 15px 20px;
    background: none;
    border: none;
    cursor: pointer;
    text-align: left;
    font-family: var(--mono);
    font-size: 11px;
    letter-spacing: .1em;
    text-transform: uppercase;
    color: var(--muted-mono);
    min-height: 48px;
  }
  .toc-toggle .current-section {
    flex: 1;
    min-width: 0;
    font-family: var(--sans);
    font-size: 14px;
    letter-spacing: 0;
    text-transform: none;
    font-weight: 600;
    color: var(--ink-serif);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .toc-toggle .chevron { transition: transform .2s ease; color: var(--muted-faint); }
  .toc-card.is-open .toc-toggle .chevron { transform: rotate(180deg); }

  .toc-card .aside-label { display: none; }
  .toc-card .toc {
    max-height: min(46vh, 340px);
    padding: 0 12px 14px;
  }
  .toc-card:not(.is-open) .toc { display: none; }

  .note-body { padding: 26px 26px 32px; }
  .section-pager { padding: 0 26px 26px; }
}

/* ═══ phone — iPhone 14 (390 × 844) ══════════════════════════════════════ */

@media (max-width: 700px) {
  :root { --gutter: 16px; --header-h: 122px; }

  .header-inner {
    flex-wrap: wrap;
    gap: 12px;
    padding-block: 12px;
  }
  .brand-name { font-size: 21px; }
  .spacer, .header-spacer { display: none; }
  .search {
    order: 3;
    width: 100%;
    min-width: 0;
    padding: 11px 16px;
  }
  .search input { font-size: 16px; } /* keeps iOS from zooming on focus */

  .page { padding-block: 28px 56px; }
  .hero-sub { margin-bottom: 28px; }

  .subject-grid { grid-template-columns: 1fr; gap: 12px; }
  .subject-card {
    min-height: 0;
    flex-direction: row;
    align-items: center;
    gap: 16px;
    padding: 18px 20px;
    border-radius: 18px;
  }
  .subject-card:hover { transform: none; }
  .subject-chip { width: 30px; height: 30px; border-radius: 10px; flex-shrink: 0; }
  .subject-name { font-size: 19px; }
  .subject-card .spacer { display: none; }
  .subject-meta { margin-left: auto; text-align: right; font-size: 12px; }

  .topic-row {
    gap: 12px;
    padding: 16px 18px;
    flex-wrap: wrap;
    border-radius: 14px;
  }
  .topic-num { width: 24px; }
  .topic-title { font-size: 16px; flex: 1; min-width: 0; }
  .topic-pages { font-size: 12px; }
  .topic-open { display: none; }
  .topic-row .spacer { display: none; }

  .note-card { border-radius: 18px; }
  .note-head { padding: 14px 18px; gap: 10px; }
  .note-title { font-size: 18px; width: 100%; }
  .note-head .spacer { display: none; }
  .note-body { padding: 22px 18px 28px; }
  .prose { font-size: 16px; line-height: 1.68; }
  .prose h1 { font-size: 24px; margin-top: 32px; }
  .prose h2 { font-size: 21px; margin-top: 30px; }
  .prose h3 { font-size: 18px; }
  .prose pre { border-radius: 12px; padding: 14px; }
  .prose blockquote { padding: 12px 16px; }

  .section-pager { padding: 0 18px 22px; flex-direction: column; }
  .section-pager .next { text-align: left; }

  .aside-card { border-radius: 18px; padding: 18px; }
  .toc-card { padding: 0; }

  /* Comfortable thumb targets — every tappable row gets at least 44px. */
  .toc-link, .aside-link {
    display: flex;
    align-items: center;
    min-height: 44px;
    padding-block: 10px;
  }
  .back-link { min-height: 44px; margin-bottom: 14px; }
  .footer-link { display: inline-flex; align-items: center; min-height: 44px; }

  .footer-inner { gap: 8px; }
  .footer-inner .spacer { display: none; }
  .footer-meta, .footer-link { width: 100%; }
}

/* Landscape phones: keep the sticky header from eating the viewport. */
@media (max-height: 480px) and (orientation: landscape) {
  .site-header { position: static; }
  .note-aside { position: static; }
}

/* ═══ print / save as PDF ════════════════════════════════════════════════ */

@media print {
  .site-header, .site-footer, .note-aside, .back-link, .section-pager, .pill { display: none !important; }
  body { background: #fff; }
  .page { padding: 0; }
  .note-card { border: none; border-radius: 0; }
  .note-head { padding: 0 0 12px; border-bottom: 1px solid #ddd; }
  .note-body { padding: 18px 0 0; }
  .note-layout { display: block; }
  .prose { font-size: 12pt; }
  .prose h1, .prose h2, .prose h3 { break-after: avoid; }
  .prose pre, .prose blockquote, .md-table-wrap, .prose img { break-inside: avoid; }
  a { color: inherit; text-decoration: none; }
}
