/* ============================================================
   Характерники / The Casters — styles
   Mobile-first. Base = телефон; @media (min-width) = ширші екрани.
   ============================================================ */

/* ---------- Дисплейний шрифт: Unbounded (самохост, сабсет) ---------- */
@font-face {
  font-family: "Unbounded";
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url("assets/fonts/unbounded-700-cyrillic.woff2") format("woff2");
  unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}
@font-face {
  font-family: "Unbounded";
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url("assets/fonts/unbounded-700-latin.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA,
    U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193,
    U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Unbounded";
  font-style: normal;
  font-weight: 800;
  font-display: swap;
  src: url("assets/fonts/unbounded-800-cyrillic.woff2") format("woff2");
  unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}
@font-face {
  font-family: "Unbounded";
  font-style: normal;
  font-weight: 800;
  font-display: swap;
  src: url("assets/fonts/unbounded-800-latin.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA,
    U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193,
    U+2212, U+2215, U+FEFF, U+FFFD;
}

/* ---------- Токени ---------- */
:root {
  color-scheme: dark;
  --bg: #07080a;
  --ink: #f7efe5;
  --muted: #b8ada3;
  --line: rgba(247, 239, 229, 0.14);
  --red: #f03a45;
  --red-dark: #9f1f2a;
  --amber: #e7a65d;
  --shadow: 0 24px 76px rgba(0, 0, 0, 0.5);
  --display: "Unbounded", "Segoe UI", system-ui, sans-serif;
  --ui: "Segoe UI", system-ui, Arial, sans-serif;
}

/* ---------- Reset ---------- */
* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-width: 320px;
  overflow-x: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--ui);
}

a {
  color: inherit;
  text-decoration: none;
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
}

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

:focus-visible {
  outline: 2px solid var(--red);
  outline-offset: 3px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* ============================================================
   LANDING
   ============================================================ */
.landing-page {
  position: relative;
  isolation: isolate;
  min-height: 100svh;
  background:
    radial-gradient(circle at 50% 12%, rgba(240, 58, 69, 0.15), transparent 20rem),
    linear-gradient(180deg, #08090c 0%, #07080a 58%, #030405 100%);
}

/* Декоративні «нитки долі» */
.fate-threads {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  overflow: hidden;
}

.fate-threads span {
  position: absolute;
  left: 50%;
  width: max(145vw, 640px);
  height: 1px;
  background: linear-gradient(
    90deg,
    transparent 0%,
    rgba(240, 58, 69, 0.08) 17%,
    rgba(255, 71, 82, 0.7) 48%,
    rgba(255, 176, 106, 0.16) 68%,
    transparent 100%
  );
  box-shadow:
    0 0 9px rgba(240, 58, 69, 0.42),
    0 0 28px rgba(240, 58, 69, 0.18);
  opacity: 0.48;
  transform-origin: center;
  animation: threadGlow 5.6s ease-in-out infinite;
}

/* Паралакс: --thread-t (0..1) ставить app.js при скролі. Нижні нитки
   підіймаються сильніше за верхні — на повному скролі сходяться у смугу
   ~13–28% зверху, звільняючи низ для контенту. Кути злегка вирівнюються —
   відчуття, що нитки існують у глибині простору. */
.fate-threads span:nth-child(1) { top: 19%; transform: translateX(-50%) translateY(calc(var(--thread-t, 0) * -6vh)) rotate(calc(-8deg * (1 - var(--thread-t, 0) * 0.35))); }
.fate-threads span:nth-child(2) { top: 31%; transform: translateX(-50%) translateY(calc(var(--thread-t, 0) * -15vh)) rotate(calc(6deg * (1 - var(--thread-t, 0) * 0.35))); animation-delay: 1.3s; }
.fate-threads span:nth-child(3) { top: 48%; transform: translateX(-50%) translateY(calc(var(--thread-t, 0) * -27vh)) rotate(calc(-3deg * (1 - var(--thread-t, 0) * 0.35))); animation-delay: 2.9s; }
.fate-threads span:nth-child(4) { top: 64%; transform: translateX(-50%) translateY(calc(var(--thread-t, 0) * -40vh)) rotate(calc(9deg * (1 - var(--thread-t, 0) * 0.35))); animation-delay: 4.2s; }
.fate-threads span:nth-child(5) { top: 78%; transform: translateX(-50%) translateY(calc(var(--thread-t, 0) * -52vh)) rotate(calc(-6deg * (1 - var(--thread-t, 0) * 0.35))); opacity: 0.32; animation-delay: 5.6s; }

/* Імпульс, що біжить уздовж нитки.
   Хаотичність: у кожної нитки свій період (взаємно прості числа,
   щоб цикли не синхронізувались) і своя затримка; частина ниток
   біжить у зворотному напрямку (animation-direction: reverse). */
.fate-threads span::after {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 16%;
  background: linear-gradient(
    90deg,
    transparent,
    rgba(255, 150, 130, 0.55) 35%,
    rgba(255, 220, 200, 0.95) 50%,
    rgba(255, 150, 130, 0.55) 65%,
    transparent
  );
  box-shadow: 0 0 16px rgba(255, 92, 100, 0.85);
  transform: translateX(-110%);
  opacity: 0;
  animation: threadPulse 16s ease-in-out infinite;
}

.fate-threads span:nth-child(1)::after { animation-duration: 13s; animation-delay: 2s; }
.fate-threads span:nth-child(2)::after { animation-duration: 19s; animation-delay: 8.5s; animation-direction: reverse; }
.fate-threads span:nth-child(3)::after { animation-duration: 11.5s; animation-delay: 14s; }
.fate-threads span:nth-child(4)::after { animation-duration: 23s; animation-delay: 5s; animation-direction: reverse; }
.fate-threads span:nth-child(5)::after { animation-duration: 17s; animation-delay: 11s; }

@keyframes threadGlow {
  0%, 100% { opacity: 0.34; filter: brightness(0.88); }
  50% { opacity: 0.62; filter: brightness(1.12); }
}

@keyframes threadPulse {
  0% { transform: translateX(-110%); opacity: 0; }
  4% { opacity: 1; }
  26% { opacity: 1; }
  30%, 100% { transform: translateX(640%); opacity: 0; }
}

/* Топбар */
.topbar {
  position: fixed;
  inset: 0 0 auto 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 58px;
  padding: 10px 14px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(7, 8, 10, 0.82);
  backdrop-filter: blur(10px);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.brand img,
.reader-header img {
  width: 32px;
  height: 32px;
  object-fit: cover;
  border-radius: 7px;
}

.brand strong {
  display: block;
  font-family: var(--display);
  font-weight: 700;
  font-size: 16px;
  line-height: 1;
  letter-spacing: -0.02em;
}

.brand small {
  display: block;
  margin-top: 3px;
  color: rgba(247, 239, 229, 0.58);
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

/* Вхідний екран: ковер + кнопка; нижче — розділи й теги */
.entry {
  position: relative;
  z-index: 1;
  display: grid;
  justify-items: center;
  align-content: center;
  gap: 24px;
  width: min(100%, 520px);
  min-height: 92svh;
  margin: 0 auto;
  padding: 76px 16px 36px;
  text-align: center;
}

.poster-card {
  width: fit-content;
  max-width: min(100%, 330px);
  background: #030405;
  box-shadow: var(--shadow);
}

.poster-card img {
  width: auto;
  max-height: min(62svh, 500px);
  height: auto;
  margin: 0 auto;
  object-fit: contain;
}

.primary-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  width: min(100%, 320px);
  min-height: 54px;
  padding: 14px 18px;
  border: 1px solid rgba(255, 118, 126, 0.64);
  color: var(--ink);
  font-size: 14px;
  font-weight: 900;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  background: linear-gradient(135deg, var(--red), var(--red-dark));
  box-shadow: 0 14px 36px rgba(159, 31, 42, 0.3);
  transition: transform 160ms ease, filter 160ms ease;
}

.primary-action:hover,
.primary-action:focus-visible {
  transform: translateY(-2px);
  filter: brightness(1.06);
}

/* Блоки під ковером: розділи, теги, жанри */
.home-sections {
  position: relative;
  z-index: 1;
  display: grid;
  gap: 30px;
  width: min(100%, 520px);
  margin: 0 auto;
  padding: 8px 16px 72px;
}

.home-heading {
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-align: left;
  text-transform: uppercase;
}

.ep-list {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.ep-item {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 56px;
  padding: 12px 16px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.03);
  transition: border-color 160ms ease, background 160ms ease;
}

.ep-item:hover,
.ep-item:focus-visible {
  border-color: rgba(247, 239, 229, 0.4);
  background: rgba(255, 255, 255, 0.06);
}

.ep-num {
  min-width: 20px;
  color: var(--muted);
  font-family: var(--display);
  font-weight: 700;
  font-size: 13px;
}

.ep-name {
  flex: 1;
  font-weight: 700;
  font-size: 14px;
  text-align: left;
}

.ep-status {
  min-width: 18px;
  color: var(--red);
  font-weight: 900;
  font-size: 14px;
  text-align: right;
}

.ep-item.viewed .ep-name {
  color: var(--muted);
}

/* Лічильники переглядів/лайків на плашках епізодів */
.ep-stats {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
}

.ep-stats[hidden] {
  display: none;
}

.ep-stat {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.stat-icon {
  width: 13px;
  height: 13px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
}

/* Сумарні перегляди/вподобання серії на головній */
.series-stats {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 18px;
  margin-top: -6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.series-stats[hidden] {
  display: none;
}

.series-stats .stat-icon {
  width: 16px;
  height: 16px;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.chip {
  display: inline-flex;
  align-items: center;
  padding: 8px 14px;
  border: 1px solid rgba(255, 255, 255, 0.05);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
  color: rgba(247, 239, 229, 0.88);
  font-size: 13px;
  line-height: 1.2;
  transition: border-color 160ms ease, background 160ms ease;
}

button.chip {
  cursor: help;
}

button.chip:hover,
button.chip:focus-visible,
button.chip[aria-expanded="true"] {
  border-color: rgba(255, 118, 126, 0.45);
  background: rgba(255, 255, 255, 0.09);
  color: var(--ink);
}

/* Бульбашка тултіпа: одна на сторінку, позиціюється з app.js */
.chip-tip {
  position: fixed;
  z-index: 40;
  max-width: min(80vw, 300px);
  padding: 10px 14px;
  border: 1px solid rgba(255, 118, 126, 0.35);
  border-radius: 10px;
  background: #15151c;
  color: var(--ink);
  font-size: 13px;
  line-height: 1.45;
  box-shadow:
    0 10px 30px rgba(0, 0, 0, 0.55),
    0 0 18px rgba(240, 58, 69, 0.12);
  opacity: 0;
  pointer-events: none;
  transition: opacity 140ms ease;
}

.chip-tip.show {
  opacity: 1;
}

.text-link {
  display: inline-flex;
  margin-top: 12px;
  color: rgba(247, 239, 229, 0.72);
  font-size: 13px;
  font-weight: 800;
  text-decoration: underline;
  text-decoration-color: rgba(240, 58, 69, 0.48);
  text-underline-offset: 4px;
}

.catalog-page {
  min-height: 100svh;
}

.catalog-shell {
  padding-top: 92px;
}

.catalog-intro {
  display: grid;
  gap: 14px;
  padding-bottom: 8px;
}

.catalog-intro .eyebrow {
  margin: 0;
  color: var(--red);
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.catalog-intro h1 {
  margin: 0;
  font-family: var(--display);
  font-size: clamp(26px, 8vw, 42px);
  font-weight: 800;
  line-height: 1.05;
}

.catalog-intro p:not(.eyebrow) {
  margin: 0;
  color: rgba(247, 239, 229, 0.78);
  font-size: 15px;
  line-height: 1.55;
}

.catalog-intro .primary-action {
  margin-top: 6px;
}

/* ============================================================
   READER
   ============================================================ */
.read-progress {
  position: fixed;
  inset: 0 auto auto 0;
  z-index: 30;
  width: 100%;
  height: 3px;
  transform: scaleX(var(--scroll-progress, 0));
  transform-origin: left;
  will-change: transform;
  background: linear-gradient(90deg, var(--red), var(--amber));
}

.reader-header {
  position: fixed;
  inset: 0 0 auto 0;
  z-index: 25;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 56px;
  padding: 10px 14px;
  background: rgba(5, 6, 8, 0.82);
  backdrop-filter: blur(10px);
  transition: transform 240ms ease;
}

/* Immersive: ховаємо шапку при скролі вниз */
.chrome-hidden .reader-header {
  transform: translateY(-100%);
}

.reader-header a {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  font-weight: 900;
}

.reader-header > span {
  display: block;
  min-width: 0;
  margin-left: 14px;
  overflow: hidden;
  color: var(--muted);
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0.04em;
  text-align: right;
  text-overflow: ellipsis;
  text-transform: uppercase;
  white-space: nowrap;
}

.reader-main {
  padding-top: 56px;
  background: #000;
}

.episode {
  width: min(100%, 760px);
  margin: 0 auto;
  background: #000;
}

.episode img {
  width: 100%;
  height: auto;
}

.reader-end {
  display: grid;
  justify-items: center;
  gap: 14px;
  width: min(100%, 760px);
  margin: 0 auto;
  padding: 56px 18px 80px;
  text-align: center;
  background: #050608;
}

.reader-end img {
  width: 64px;
  height: 64px;
  object-fit: cover;
  border-radius: 12px;
}

.reader-end h2 {
  margin: 0;
  font-family: var(--display);
  font-weight: 700;
  font-size: clamp(17px, 4.6vw, 24px);
  line-height: 1.15;
  letter-spacing: -0.01em;
}

.reader-end p {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 14px;
}

.like-btn {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  min-height: 48px;
  padding: 12px 22px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  font-size: 15px;
  background: rgba(255, 255, 255, 0.03);
  transition: border-color 160ms ease, color 160ms ease;
}

.like-btn:disabled {
  opacity: 0.5;
  cursor: default;
}

.like-btn:not(:disabled):hover,
.like-btn:not(:disabled):focus-visible {
  border-color: rgba(247, 239, 229, 0.4);
  color: var(--ink);
}

.like-heart {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  transition: transform 200ms ease;
}

.like-btn.liked {
  border-color: rgba(255, 118, 126, 0.55);
  color: var(--ink);
}

.like-btn.liked .like-heart {
  fill: var(--red);
  stroke: var(--red);
  transform: scale(1.12);
}

.like-count {
  font-weight: 700;
  min-width: 1ch;
}

/* Один ряд і на мобільному: «Перечитати» зліва, дія «далі» — справа */
.reader-actions {
  display: flex;
  justify-content: center;
  gap: 10px;
  width: 100%;
}

.reader-actions .primary-action,
.reader-actions .ghost-action {
  flex: 1 1 0;
  width: auto;
  min-width: 0;
  max-width: 260px;
  padding-inline: 12px;
}

.ghost-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  padding: 12px 18px;
  width: min(100%, 260px);
  border: 1px solid var(--line);
  color: var(--ink);
  font-size: 13px;
  font-weight: 900;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  background: rgba(255, 255, 255, 0.03);
  transition: border-color 160ms ease, background 160ms ease;
}

.ghost-action:hover,
.ghost-action:focus-visible {
  border-color: rgba(247, 239, 229, 0.4);
  background: rgba(255, 255, 255, 0.06);
}

/* Кнопка «нагору» */
.to-top {
  position: fixed;
  right: 16px;
  bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  z-index: 28;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  border: 1px solid rgba(255, 118, 126, 0.45);
  border-radius: 999px;
  color: var(--ink);
  font-size: 20px;
  line-height: 1;
  background: rgba(20, 12, 13, 0.82);
  backdrop-filter: blur(8px);
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.5);
  opacity: 0;
  transform: translateY(12px);
  pointer-events: none;
  transition: opacity 200ms ease, transform 200ms ease;
}

.to-top.show {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

/* ============================================================
   ↑ Більші екрани
   ============================================================ */
@media (min-width: 768px) {
  .topbar {
    min-height: 60px;
    padding: 10px clamp(18px, 4vw, 34px);
  }

  .brand img,
  .reader-header img {
    width: 34px;
    height: 34px;
  }

  .brand strong {
    font-size: 18px;
  }

  .entry {
    padding-top: 84px;
  }

  .poster-card {
    max-width: min(100%, 410px);
  }

  .poster-card img {
    width: min(100%, 410px);
    max-height: 62svh;
  }

  .reader-header {
    padding: 10px clamp(18px, 4vw, 28px);
  }

  .to-top {
    right: 24px;
    bottom: 24px;
  }
}

/* ============================================================
   Доступність: reduced-motion
   ============================================================ */
@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  .fate-threads span {
    animation: none;
  }

  .fate-threads span::after {
    animation: none;
    opacity: 0;
  }

  .reader-header,
  .to-top,
  .primary-action,
  .ghost-action,
  .like-btn,
  .like-heart,
  .ep-item,
  .chip,
  .chip-tip {
    transition: none;
  }
}
