/* ============================================================
   Академия — читалка (Telegram Mini App)
   Свежая премиум-айдентика: сериф-тело + гротеск-хром.
   Тема свет/тьма следует за Telegram (или системой в браузере).
   ============================================================ */

/* -------------------- шрифты (self-hosted, с кириллицей) -------------------- */
/* Variable woff2 лежат в ./assets/fonts (см. README). Есть надёжный фолбэк. */

@font-face {
  font-family: 'Source Serif 4';
  font-style: normal;
  font-weight: 200 900;
  font-display: swap;
  src: url('./assets/fonts/source-serif-4-cyrillic.woff2') format('woff2-variations'),
       url('./assets/fonts/source-serif-4-cyrillic.woff2') format('woff2');
  unicode-range: U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}
@font-face {
  font-family: 'Source Serif 4';
  font-style: normal;
  font-weight: 200 900;
  font-display: swap;
  src: url('./assets/fonts/source-serif-4-latin.woff2') format('woff2-variations'),
       url('./assets/fonts/source-serif-4-latin.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+2013-2014, U+2018-2019, U+201C-201D, U+2026, U+2212;
}
@font-face {
  font-family: 'Source Serif 4';
  font-style: italic;
  font-weight: 200 900;
  font-display: swap;
  src: url('./assets/fonts/source-serif-4-italic-cyrillic.woff2') format('woff2-variations'),
       url('./assets/fonts/source-serif-4-italic-cyrillic.woff2') format('woff2');
  unicode-range: U+0400-045F, U+0490-0491;
}
@font-face {
  font-family: 'Source Serif 4';
  font-style: italic;
  font-weight: 200 900;
  font-display: swap;
  src: url('./assets/fonts/source-serif-4-italic-latin.woff2') format('woff2-variations'),
       url('./assets/fonts/source-serif-4-italic-latin.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+2013-2014, U+2018-2019, U+201C-201D, U+2026;
}
@font-face {
  font-family: 'Manrope';
  font-style: normal;
  font-weight: 400 800;
  font-display: swap;
  src: url('./assets/fonts/manrope-cyrillic.woff2') format('woff2-variations'),
       url('./assets/fonts/manrope-cyrillic.woff2') format('woff2');
  unicode-range: U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}
@font-face {
  font-family: 'Manrope';
  font-style: normal;
  font-weight: 400 800;
  font-display: swap;
  src: url('./assets/fonts/manrope-latin.woff2') format('woff2-variations'),
       url('./assets/fonts/manrope-latin.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+2013-2014, U+2018-2019, U+201C-201D, U+2026;
}

/* -------------------- токены темы -------------------- */

:root {
  --font-serif: 'Source Serif 4', Georgia, 'Times New Roman', serif;
  --font-sans: 'Manrope', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, system-ui, sans-serif;

  --measure: 40rem;          /* ширина контента */
  --pad-x: clamp(1.15rem, 5vw, 2rem);

  --radius-lg: 20px;
  --radius-md: 14px;
  --radius-sm: 10px;

  --ease: cubic-bezier(0.22, 0.61, 0.36, 1);
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);

  --fs-base: clamp(1.0625rem, 1.01rem + 0.38vw, 1.1875rem);

  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

/* Светлая (по умолчанию) */
:root, :root[data-theme='light'] {
  --bg: #faf8f3;
  --bg-elev: #ffffff;
  --surface: #ffffff;
  --surface-2: #f3efe6;
  --text: #211e18;
  --text-muted: #5c574e;
  --text-faint: #78736a;
  --border: rgba(26, 22, 15, 0.10);
  --border-strong: rgba(26, 22, 15, 0.17);
  --accent: #9a6512;          /* ссылки/интерактив (AA на бумаге) */
  --accent-solid: #855510;    /* фон кнопки */
  --on-accent: #ffffff;
  --accent-soft: rgba(154, 101, 18, 0.10);
  --sel: rgba(154, 101, 18, 0.16);
  --shadow: 0 1px 2px rgba(26, 22, 15, 0.05), 0 10px 30px -18px rgba(26, 22, 15, 0.28);
  --shadow-card: 0 1px 2px rgba(26, 22, 15, 0.04), 0 4px 18px -14px rgba(26, 22, 15, 0.22);
  --skeleton-a: #efeadf;
  --skeleton-b: #f7f3ec;
}

/* Тёмная */
:root[data-theme='dark'] {
  --bg: #111013;
  --bg-elev: #17161b;
  --surface: #1a191f;
  --surface-2: #221f28;
  --text: #ece7de;
  --text-muted: #9e988e;
  --text-faint: #8a8377;
  --border: rgba(255, 255, 255, 0.09);
  --border-strong: rgba(255, 255, 255, 0.16);
  --accent: #e9b45c;
  --accent-solid: #e9b45c;
  --on-accent: #1a1509;
  --accent-soft: rgba(233, 180, 92, 0.13);
  --sel: rgba(233, 180, 92, 0.24);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 14px 40px -20px rgba(0, 0, 0, 0.6);
  --shadow-card: 0 1px 2px rgba(0, 0, 0, 0.35), 0 8px 26px -18px rgba(0, 0, 0, 0.55);
  --skeleton-a: #1c1b21;
  --skeleton-b: #26242d;
}

/* Пока JS не выставил data-theme — уважаем системную тёмную */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    --bg: #111013; --bg-elev: #17161b; --surface: #1a191f; --surface-2: #221f28;
    --text: #ece7de; --text-muted: #9e988e; --text-faint: #8a8377;
    --border: rgba(255,255,255,0.09); --border-strong: rgba(255,255,255,0.16);
    --accent: #e9b45c; --accent-solid: #e9b45c; --on-accent: #1a1509;
    --accent-soft: rgba(233,180,92,0.13); --sel: rgba(233,180,92,0.24);
    --shadow: 0 1px 2px rgba(0,0,0,0.4), 0 14px 40px -20px rgba(0,0,0,0.6);
    --shadow-card: 0 1px 2px rgba(0,0,0,0.35), 0 8px 26px -18px rgba(0,0,0,0.55);
    --skeleton-a: #1c1b21; --skeleton-b: #26242d;
  }
}

/* -------------------- reset / база -------------------- */

*, *::before, *::after { box-sizing: border-box; }
* { margin: 0; }

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

body {
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  font-feature-settings: 'kern' 1;
  overflow-x: hidden;
  transition: background-color 0.4s var(--ease), color 0.4s var(--ease);
}

::selection { background: var(--sel); }

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

button { font: inherit; color: inherit; cursor: pointer; background: none; border: none; }

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

img { max-width: 100%; height: auto; display: block; }

/* -------------------- boot -------------------- */

.boot {
  min-height: 100dvh;
  display: grid;
  place-items: center;
}
.boot__spinner {
  width: 30px; height: 30px;
  border: 2.5px solid var(--border-strong);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* -------------------- layout -------------------- */

.view {
  max-width: var(--measure);
  margin-inline: auto;
  padding-inline: var(--pad-x);
  padding-bottom: calc(3rem + var(--safe-bottom));
}

/* -------------------- masthead (шапка списка) -------------------- */

.masthead {
  padding-top: calc(2.2rem + var(--safe-top));
  padding-bottom: 1.6rem;
}
.masthead__eyebrow {
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 0.7rem;
}
.masthead__title {
  font-family: var(--font-sans);
  font-weight: 800;
  font-size: clamp(2rem, 1.5rem + 2.4vw, 2.9rem);
  letter-spacing: -0.03em;
  line-height: 1.02;
}
.masthead__meta {
  margin-top: 0.7rem;
  color: var(--text-faint);
  font-size: 0.9rem;
  font-weight: 500;
}

/* -------------------- лента карточек -------------------- */

.feed { list-style: none; padding: 0; display: flex; flex-direction: column; gap: 0.85rem; }

.card {
  position: relative;
  display: flex;
  align-items: flex-start;
  gap: 0.9rem;
  padding: 1.15rem 1.2rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  color: inherit;
  transition: transform 0.4s var(--ease), border-color 0.3s var(--ease), box-shadow 0.4s var(--ease);
  -webkit-tap-highlight-color: transparent;
}
@media (hover: hover) {
  .card:hover { transform: translateY(-2px); border-color: var(--border-strong); box-shadow: var(--shadow); }
  .card:hover .card__title { color: var(--accent); }
}
.card:active { transform: scale(0.988); }

.card__body { flex: 1 1 auto; min-width: 0; }

.card__title {
  font-family: var(--font-sans);
  font-weight: 700;
  font-size: 1.14rem;
  letter-spacing: -0.015em;
  line-height: 1.25;
  color: var(--text);
  transition: color 0.25s var(--ease);
}
.card__excerpt {
  margin-top: 0.45rem;
  color: var(--text-muted);
  font-size: 0.95rem;
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.card__meta {
  margin-top: 0.8rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--text-faint);
  font-size: 0.8rem;
  font-weight: 500;
}
.card__time { display: inline-flex; align-items: center; gap: 0.34rem; }
.card__time .i { width: 0.9rem; height: 0.9rem; opacity: 0.8; }
.card__dot { opacity: 0.5; }

.card__status {
  flex: 0 0 auto;
  width: 22px; height: 22px;
  display: grid; place-items: center;
  color: var(--accent);
}
.card__status svg { width: 18px; height: 18px; }
.card.is-read { }
.card.is-read .card__title { color: var(--text-muted); }

.i svg { width: 100%; height: 100%; display: block; }
.i { display: inline-flex; }

/* -------------------- topbar (в статье) -------------------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  margin-inline: calc(var(--pad-x) * -1);
  padding: calc(0.7rem + var(--safe-top)) var(--pad-x) 0.7rem;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  -webkit-backdrop-filter: saturate(180%) blur(14px);
  backdrop-filter: saturate(180%) blur(14px);
  border-bottom: 1px solid transparent;
  transition: border-color 0.3s var(--ease);
}
.topbar__back {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-family: var(--font-sans);
  font-weight: 600;
  font-size: 0.92rem;
  color: var(--text-muted);
  padding: 0.4rem 0.2rem;
  min-height: 44px;
  transition: color 0.2s var(--ease), transform 0.2s var(--ease);
}
.topbar__back .i { width: 1.15rem; height: 1.15rem; transition: transform 0.3s var(--ease); }
.topbar__back:active { transform: translateX(-2px); }
.topbar__back:active .i { transform: translateX(-3px); }
@media (hover: hover) { .topbar__back:hover { color: var(--text); } }
.topbar__back.is-static { opacity: 0.5; }

/* -------------------- статья -------------------- */

.reader { padding-top: 1.4rem; }

.article__head { margin-bottom: 1.7rem; }
.article__meta {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  color: var(--text-faint);
  font-size: 0.82rem;
  font-weight: 500;
  margin-bottom: 0.9rem;
}
.article__time { display: inline-flex; align-items: center; gap: 0.36rem; }
.article__time .i { width: 0.92rem; height: 0.92rem; opacity: 0.8; }
.article__date::before { content: '·'; margin-right: 0.8rem; opacity: 0.5; }

.article__title {
  font-family: var(--font-serif);
  font-weight: 600;
  font-size: clamp(1.75rem, 1.3rem + 2.1vw, 2.5rem);
  line-height: 1.12;
  letter-spacing: -0.017em;
  text-wrap: balance;
}

/* -------------------- prose (тело статьи) — сердце дизайна -------------------- */

.prose {
  font-family: var(--font-serif);
  font-size: var(--fs-base);
  line-height: 1.72;
  color: var(--text);
  font-feature-settings: 'kern' 1, 'liga' 1, 'onum' 1;
}
.prose > * + * { margin-top: 1.15em; }

.prose p { text-wrap: pretty; }

.prose .lead {
  font-size: 1.2em;
  line-height: 1.6;
  color: var(--text);
  font-weight: 500;
}

.prose h2 {
  font-family: var(--font-sans);
  font-weight: 700;
  font-size: 1.42em;
  line-height: 1.22;
  letter-spacing: -0.02em;
  margin-top: 2.1em;
  color: var(--text);
}
.prose h3 {
  font-family: var(--font-sans);
  font-weight: 650;
  font-size: 1.16em;
  line-height: 1.3;
  letter-spacing: -0.01em;
  margin-top: 1.7em;
}
.prose h2 + p, .prose h3 + p { margin-top: 0.7em; }

.prose strong { font-weight: 650; color: var(--text); }
.prose em { font-style: italic; }

.prose a {
  color: var(--accent);
  text-decoration: underline;
  text-decoration-thickness: 1.5px;
  text-underline-offset: 2.5px;
  text-decoration-color: color-mix(in srgb, var(--accent) 45%, transparent);
  transition: text-decoration-color 0.2s var(--ease);
}
@media (hover: hover) { .prose a:hover { text-decoration-color: var(--accent); } }

.prose ul, .prose ol { padding-left: 1.3em; }
.prose li { margin-top: 0.5em; padding-left: 0.25em; }
.prose li::marker { color: var(--accent); font-weight: 600; }
.prose ul li::marker { content: '—  '; }

.prose blockquote {
  margin-inline: 0;
  padding: 0.2em 0 0.2em 1.25em;
  border-left: 3px solid var(--accent);
  font-style: italic;
  font-size: 1.14em;
  line-height: 1.55;
  color: var(--text);
}

.prose .callout {
  background: var(--accent-soft);
  border: 1px solid color-mix(in srgb, var(--accent) 24%, transparent);
  border-radius: var(--radius-md);
  padding: 1.05em 1.15em;
  font-size: 0.98em;
  line-height: 1.6;
}
.prose .callout > * + * { margin-top: 0.6em; }
.prose .callout strong { color: var(--accent); }

.prose hr {
  border: none;
  height: 1px;
  background: var(--border);
  margin-block: 2em;
}

.prose img { border-radius: var(--radius-md); margin-block: 1.6em; }

.prose code {
  font-family: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
  font-size: 0.88em;
  background: var(--surface-2);
  padding: 0.15em 0.4em;
  border-radius: 6px;
}

/* -------------------- подвал статьи -------------------- */

.article__foot {
  margin-top: 3rem;
  padding-top: 1.6rem;
  border-top: 1px solid var(--border);
}
.btn-back {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-family: var(--font-sans);
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--text-muted);
  padding: 0.7rem 1.05rem;
  min-height: 46px;
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  transition: color 0.2s var(--ease), border-color 0.2s var(--ease), transform 0.2s var(--ease);
}
.btn-back .i { width: 1.05rem; height: 1.05rem; }
.btn-back:active { transform: scale(0.97); }
@media (hover: hover) { .btn-back:hover { color: var(--text); border-color: var(--accent); } }

/* -------------------- прогресс чтения -------------------- */

.reading-progress {
  position: fixed;
  top: 0; left: 0;
  height: 3px;
  width: 100%;
  transform: scaleX(0);
  transform-origin: left center;
  background: linear-gradient(90deg, var(--accent), var(--accent-solid));
  z-index: 100;
  opacity: 0;
  transition: opacity 0.3s var(--ease);
  pointer-events: none;
}
.reading-progress.is-visible { opacity: 1; }

/* -------------------- состояния -------------------- */

.state {
  text-align: center;
  padding: clamp(3rem, 18vw, 6rem) 1rem;
  max-width: 22rem;
  margin-inline: auto;
}
.state__icon {
  width: 3.4rem; height: 3.4rem;
  margin: 0 auto 1.2rem;
  color: var(--accent);
  display: grid; place-items: center;
  background: var(--accent-soft);
  border-radius: 50%;
  padding: 0.85rem;
}
.state__icon svg { width: 100%; height: 100%; }
.state__icon--warn { color: var(--accent); }
.state__title {
  font-family: var(--font-sans);
  font-weight: 700;
  font-size: 1.3rem;
  letter-spacing: -0.02em;
}
.state__text { margin-top: 0.5rem; color: var(--text-muted); font-size: 0.98rem; line-height: 1.55; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-top: 1.5rem;
  font-family: var(--font-sans);
  font-weight: 650;
  font-size: 0.96rem;
  color: var(--on-accent);
  background: var(--accent-solid);
  padding: 0.8rem 1.5rem;
  min-height: 48px;
  border-radius: 999px;
  transition: transform 0.2s var(--ease), filter 0.2s var(--ease);
}
.btn:active { transform: scale(0.97); }
@media (hover: hover) { .btn:hover { filter: brightness(1.06); } }

/* -------------------- скелеты -------------------- */

.sk {
  background: linear-gradient(100deg, var(--skeleton-a) 30%, var(--skeleton-b) 50%, var(--skeleton-a) 70%);
  background-size: 300% 100%;
  animation: shimmer 1.5s var(--ease) infinite;
  border-radius: 7px;
}
@keyframes shimmer { from { background-position: 150% 0; } to { background-position: -150% 0; } }

.card--skeleton { flex-direction: column; align-items: stretch; gap: 0.7rem; pointer-events: none; }
.sk--line { height: 0.85rem; }
.sk--w40 { width: 40%; } .sk--w60 { width: 60%; } .sk--w90 { width: 90%; }
.sk--pill { width: 6rem; height: 0.85rem; margin-bottom: 1rem; }
.sk--title { width: 65%; height: 2.4rem; border-radius: 10px; }
.sk--headline { width: 85%; height: 2rem; border-radius: 9px; }
.prose--skeleton { display: flex; flex-direction: column; gap: 0.95rem; margin-top: 1.5rem; }
.prose--skeleton .sk--line { height: 1rem; }

/* -------------------- анимации входа -------------------- */

.feed__item.reveal {
  opacity: 0;
  animation: rise 0.55s var(--ease-out) both;
  animation-delay: calc(var(--i, 0) * 45ms);
}
@keyframes rise { from { opacity: 0; transform: translateY(16px); } to { opacity: 1; transform: none; } }

.reader.reveal-in { animation: fadein 0.5s var(--ease) both; }
@keyframes fadein { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* -------------------- reduced motion -------------------- */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
  .reading-progress { transition: none; }
}

/* -------------------- широкий экран (Telegram Desktop) -------------------- */

@media (min-width: 780px) {
  .masthead { padding-top: calc(3rem + var(--safe-top)); }
  .feed { gap: 1rem; }
}
