/* =====================================================================
   T-005 · Оглавление-разворот (toc.html)
   Только @layer screens, только токены, классы с префиксом .toc-…
   Новые токены (tokens.css → «Добавлено экранами»): --timeline-line,
   --timeline-now.
   ===================================================================== */
@layer screens {
  /* Демо-состояние (born | pregnancy) — без мигания до JS */
  [data-stage="born"] [data-stage-only="pregnancy"],
  [data-stage="pregnancy"] [data-stage-only="born"] { display: none; }

  /* Место под прилипающую кнопку «+ Добавить воспоминание» */
  .toc-spread { padding-bottom: calc(var(--tap-lg) + var(--space-7)); }

  /* ---------- Левая страница ---------- */
  .toc-left { display: flex; flex-direction: column; gap: var(--space-5); }
  /* Мобильный: сначала имя и прогресс, затем главы, timeline — после глав */
  @media (max-width: 899px) {
    .toc-left { display: contents; }
    .toc-right { order: 1; }
    .toc-timeline { order: 2; }
  }

  .toc-hero { display: flex; flex-direction: column; gap: var(--space-2); }
  .toc-hero__name { font-size: calc(var(--fs-2xl) * var(--font-display-scale)); }
  .toc-hero__age {
    font-size: calc(var(--fs-xl) * var(--font-display-scale));
    color: var(--color-secondary-ink);
  }
  .toc-hero__meta { font-size: var(--fs-sm); }

  .toc-section-title {
    font-size: calc(var(--fs-lg) * var(--font-display-scale));
    margin-bottom: var(--space-3);
  }

  /* Прогресс всей книги */
  .toc-stats {
    display: flex;
    align-items: center;
    gap: var(--space-4);
    padding: var(--space-3) var(--space-4);
    background: var(--texture-card), var(--color-surface);
    border: var(--border-width) var(--border-style) var(--color-line);
    border-radius: var(--radius-card);
    -webkit-backdrop-filter: blur(var(--glass-blur));
    backdrop-filter: blur(var(--glass-blur));
  }
  .toc-stats__text { min-width: 0; }
  .toc-stats__title { font-weight: 700; }
  .toc-ring { position: relative; flex: none; width: 64px; height: 64px; }
  .toc-ring svg { width: 100%; height: 100%; rotate: -90deg; }
  .toc-ring circle { fill: none; stroke-width: 6; }
  .toc-ring__track { stroke: var(--color-surface-2); }
  .toc-ring__fill {
    stroke: var(--color-accent);
    stroke-linecap: round;
    stroke-dasharray: calc(var(--fill, 0) * 1) 100;
  }
  .toc-ring__value {
    position: absolute; inset: 0;
    display: grid; place-items: center;
    font-size: var(--fs-xs);
    font-weight: 700;
    color: var(--color-accent-ink);
  }

  /* ---------- Timeline важных дат (ТЗ §13) ---------- */
  .toc-timeline__list { position: relative; }
  .toc-tl { position: relative; }
  /* линия между точками */
  .toc-tl::before {
    content: "";
    position: absolute;
    left: 10px;
    top: 0; bottom: 0;
    width: 2px;
    translate: -50% 0;
    background: var(--timeline-line);
  }
  .toc-tl:first-child::before { top: 50%; }
  .toc-tl:last-child::before { bottom: 50%; }
  .toc-tl--future::before {
    background: repeating-linear-gradient(180deg, var(--timeline-line) 0 4px, transparent 4px 8px);
  }
  .toc-tl__link {
    position: relative;
    display: grid;
    grid-template-columns: 20px minmax(0, 1fr);
    grid-template-rows: auto auto;
    column-gap: var(--space-3);
    align-items: center;
    min-height: var(--tap);
    padding-block: var(--space-1);
    color: var(--color-ink);
    text-decoration: none;
    border-radius: var(--radius-sm);
  }
  a.toc-tl__link:hover .toc-tl__title { text-decoration: underline; text-underline-offset: 0.18em; }
  .toc-tl__dot {
    grid-row: 1 / 3;
    justify-self: center;
    display: grid; place-items: center;
    width: 12px; height: 12px;
    border-radius: var(--radius-pill);
    background: var(--color-page);
    border: 2px solid var(--color-accent);
  }
  .toc-tl__date {
    font-size: var(--fs-xs);
    font-weight: 600;
    color: var(--color-ink-muted);
    line-height: 1.3;
  }
  .toc-tl__title { font-size: var(--fs-sm); line-height: 1.3; }

  .toc-tl--star .toc-tl__dot {
    width: 22px; height: 22px;
    border-color: var(--color-secondary);
    background: var(--color-secondary-soft);
    color: var(--color-secondary-ink);
  }
  .toc-tl--star .toc-tl__dot svg { width: 12px; height: 12px; fill: currentColor; }
  .toc-tl--star .toc-tl__title {
    font-family: var(--font-display);
    font-weight: var(--font-display-weight);
    font-size: calc(var(--fs-lg) * var(--font-display-scale));
    line-height: 1.1;
  }
  .toc-tl--now .toc-tl__dot {
    width: 14px; height: 14px;
    background: var(--color-accent);
    box-shadow: 0 0 0 6px var(--timeline-now);
  }
  .toc-tl--now .toc-tl__date { color: var(--color-accent-ink); text-transform: uppercase; letter-spacing: 0.1em; }
  .toc-tl--now .toc-tl__title { font-weight: 700; }
  .toc-tl--future .toc-tl__dot { border-style: dashed; border-color: var(--color-line-strong); }

  /* ---------- Правая страница: главы ---------- */
  .toc-right { container-type: inline-size; }
  .toc-right__title { margin-bottom: 0; }
  .toc-chapters {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: var(--space-4);
  }
  .toc-chapters__item { min-width: 0; display: grid; }
  .toc-chapters__item:nth-child(even) .chapter-card { rotate: calc(var(--tilt-card) * -1); }

  .toc-card__num {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-2);
    font-size: var(--fs-xs);
    font-weight: 700;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--color-secondary-ink);
  }
  .toc-card__status { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
  .toc-card__status--done { color: var(--color-accent-ink); font-weight: 600; }
  .toc-card__status svg { width: 16px; height: 16px; }

  /* «Идёт сейчас» */
  .toc-now {
    display: inline-flex;
    align-items: center;
    padding: 1px var(--space-2);
    border-radius: var(--radius-pill);
    background: var(--color-accent);
    color: var(--color-on-accent);
    letter-spacing: 0.04em;
  }
  .toc-card--now { border-color: var(--color-accent); box-shadow: var(--shadow-lg), 0 0 0 1px var(--color-accent); }

  /* Отметка незаполненного */
  .toc-flag {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 0 var(--space-2);
    min-height: 22px;
    border: 1px dashed currentColor;
    border-radius: var(--radius-pill);
    background: var(--color-secondary-soft);
    color: var(--color-secondary-ink);
    font-size: var(--fs-xs);
    font-weight: 600;
    line-height: 1.2;
    white-space: nowrap;
  }
  .toc-flag::before {
    content: "";
    width: 6px; height: 6px;
    border-radius: var(--radius-pill);
    border: 1.5px solid currentColor;
  }
  .toc-flag--future { background: transparent; color: var(--color-ink-muted); }

  /* Месяцы 2–12 — компактные главы-плитки */
  .toc-months {
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
    padding: var(--space-4);
    border: var(--border-width) dashed var(--color-line-strong);
    border-radius: var(--radius-card);
  }
  .toc-months__head { display: flex; flex-direction: column; gap: 2px; }
  .toc-months__grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(64px, 1fr));
    gap: var(--space-2);
  }
  .toc-month {
    display: grid;
    justify-items: center;
    align-content: center;
    gap: 1px;
    min-height: 80px;
    padding: var(--space-2) var(--space-1);
    border: 1px dashed var(--color-line-strong);
    border-radius: var(--radius-md);
    color: var(--color-ink-muted);
    text-decoration: none;
    text-align: center;
    transition: background-color var(--dur-fast), border-color var(--dur-fast), transform var(--dur-fast) var(--ease-out);
  }
  .toc-month:hover { background: var(--color-surface); border-color: var(--color-accent); transform: translateY(-2px); }
  .toc-month__num {
    font-family: var(--font-display);
    font-weight: var(--font-display-weight);
    font-size: calc(var(--fs-xl) * var(--font-display-scale));
    line-height: 1;
    color: var(--color-ink);
  }
  .toc-month__unit, .toc-month__date { font-size: var(--fs-xs); line-height: 1.2; }

  @container (min-width: 440px) {
    .toc-chapters { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .toc-chapters__item--feature, .toc-chapters__item--wide { grid-column: 1 / -1; }
  }

  /* ---------- Постоянная кнопка «+ Добавить воспоминание» ---------- */
  .toc-add {
    position: sticky;
    z-index: 5;
    bottom: 0;
    display: flex;
    justify-content: center;
    margin-top: calc(-1 * (var(--tap-lg) + var(--space-5)));
    padding: var(--space-3) var(--space-4) var(--space-4);
    pointer-events: none;
  }
  .toc-add__btn { pointer-events: auto; box-shadow: var(--shadow-lg); max-width: 100%; }
  @media (max-width: 899px) {
    .toc-add__btn { font-size: var(--fs-base); padding-inline: var(--space-5); white-space: normal; text-align: center; }
  }

  /* ---------- Появление (только transform/opacity) ---------- */
  @keyframes toc-rise { from { opacity: 0; transform: translateY(10px); } }
  .toc-left > *, .toc-right__title, .toc-chapters__item { animation: toc-rise 460ms var(--ease-out) both; }
  .toc-left > :nth-child(2) { animation-delay: 60ms; }
  .toc-left > :nth-child(3) { animation-delay: 120ms; }
  .toc-chapters__item:nth-child(1) { animation-delay: 80ms; }
  .toc-chapters__item:nth-child(2) { animation-delay: 130ms; }
  .toc-chapters__item:nth-child(3) { animation-delay: 180ms; }
  .toc-chapters__item:nth-child(4) { animation-delay: 230ms; }
  .toc-chapters__item:nth-child(5) { animation-delay: 280ms; }
  .toc-chapters__item:nth-child(6) { animation-delay: 320ms; }
  .toc-chapters__item:nth-child(7) { animation-delay: 360ms; }

  /* ---------- Десктоп: настоящий разворот ---------- */
  @media (min-width: 900px) {
    .toc-spread { padding-bottom: 0; }
    .toc-left, .toc-right { justify-content: flex-start; }
    .toc-left { padding-bottom: var(--space-7); }
    .toc-right { padding-bottom: calc(var(--tap-lg) + var(--space-7)); }
    /* Крупные карточки (Беременность, финал) остаются горизонтальными */
    .toc-chapters__item--feature .chapter-card {
      grid-template-columns: 132px minmax(0, 1fr);
      align-items: center;
      padding: var(--space-3);
    }
    .toc-chapters__item--feature .chapter-card .chapter-card__thumb { width: 132px; aspect-ratio: 1; }
    .toc-add { justify-content: flex-end; padding-inline: var(--space-6); }
  }
}
