/* Общие компоненты: кнопки, бейджи, чипы, карточка медиа, секции, листы, тост. */

/* ============ Кнопки ============ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  min-height: 52px;
  padding: 0 var(--sp-5);
  border-radius: var(--r-pill);
  font-size: var(--fs-body);
  font-weight: 700;
  letter-spacing: 0.01em;
  transition: transform var(--dur) var(--ease), background-color var(--dur) var(--ease);
}

.btn:active {
  transform: scale(0.98);
}

.btn--primary {
  background: var(--accent);
  color: var(--accent-ink);
}

.btn--soft {
  background: var(--surface-2);
  color: var(--text);
}

.btn--done {
  background: color-mix(in srgb, var(--status-color, var(--status-finished)) 18%, transparent);
  color: var(--status-color, var(--status-finished));
}

.btn--ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-2);
}

.btn--square {
  flex: 0 0 52px;
  width: 52px;
  padding: 0;
}

.btn--grow {
  flex: 1 1 auto;
}

.btn[disabled] {
  opacity: 0.5;
  pointer-events: none;
}

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: var(--tap);
  height: var(--tap);
  border-radius: var(--r-pill);
  color: var(--text);
  transition: transform var(--dur) var(--ease), background-color var(--dur) var(--ease);
}

.icon-btn:active {
  transform: scale(0.94);
}

.icon-btn--glass {
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  -webkit-backdrop-filter: var(--glass-filter);
  backdrop-filter: var(--glass-filter);
  box-shadow: var(--glass-shadow);
}

.link-btn {
  color: var(--accent);
  font-size: var(--fs-sm);
  font-weight: 700;
}

/* --- Иконки: размер по месту, цвет — currentColor --- */
.icon-btn--accent {
  color: var(--accent);
}

.icon-btn svg {
  width: 22px;
  height: 22px;
}

.btn svg {
  width: 20px;
  height: 20px;
}

.btn--square svg {
  width: 22px;
  height: 22px;
}

.result__add svg {
  width: 20px;
  height: 20px;
}

.view-toggle svg {
  width: 18px;
  height: 18px;
}

.library__badge svg {
  width: 16px;
  height: 16px;
}

.badge__star svg {
  width: 11px;
  height: 11px;
}

.score-pill svg {
  width: 13px;
  height: 13px;
}

.score-pill__icon {
  display: inline-grid;
  place-items: center;
}

.empty__art svg {
  width: 44px;
  height: 44px;
  color: var(--text-3);
}

/* ============ Бейджи ============ */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 22px;
  padding: 0 9px;
  border-radius: var(--r-pill);
  background: rgba(14, 12, 18, 0.62);
  color: var(--text);
  font-size: var(--fs-xs);
  font-weight: 700;
  letter-spacing: 0.01em;
}

/* Бейдж категории: тёмная плашка как у рейтинга, текст — в цвете категории. */
.badge--type {
  color: var(--cat, var(--text));
  font-weight: 600;
  background: rgba(23, 20, 27, 0.72);
}

/* Рейтинг: цифра того же цвета, что и звезда. */
.badge--rating {
  color: var(--rating);
}

.badge__star {
  display: inline-grid;
  place-items: center;
  color: var(--rating);
  font-size: 10px;
  line-height: 1;
}

/* Пилюля внешнего рейтинга (TMDB / RAWG / Google Books). */
.score-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 28px;
  padding: 0 11px;
  border-radius: var(--r-pill);
  background: rgba(242, 203, 107, 0.14);
  color: var(--rating);
  font-size: var(--fs-sm);
  font-weight: 800;
}

/* ============ Чипы ============ */
.chip {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 36px;
  padding: 0 14px;
  border: 1px solid var(--glass-border);
  border-radius: var(--r-pill);
  background: var(--glass-bg);
  -webkit-backdrop-filter: var(--glass-filter);
  backdrop-filter: var(--glass-filter);
  color: var(--text-2);
  font-size: var(--fs-sm);
  font-weight: 600;
  white-space: nowrap;
}

/* Тач-цель до 44px без визуального утолщения чипа. */
.chip::after {
  content: "";
  position: absolute;
  inset: -5px -2px;
}

.chip--active {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
  -webkit-backdrop-filter: none;
  backdrop-filter: none;
}

/* ============ Секции ============ */
.section {
  margin-top: var(--sp-7);
  padding: 0 var(--gutter);
}

.section__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-4);
  margin-bottom: var(--sp-3);
}

.section__title {
  font-size: var(--fs-h2);
  font-weight: 800;
  letter-spacing: -0.01em;
}

/* Заголовок, за которым сразу идёт контент (а не .section__head). */
.section > .section__title {
  margin-bottom: var(--sp-3);
}

/* ============ Горизонтальная лента ============ */
.rail {
  display: flex;
  gap: var(--sp-3);
  margin-inline: calc(var(--gutter) * -1);
  padding: 2px var(--gutter) var(--sp-2);
  overflow-x: auto;
  /* Мягкое прилипание к краю карточки, но без принудительной остановки. */
  scroll-snap-type: x proximity;
  /* Первая карточка встаёт на место отступа, а не под край экрана. */
  scroll-padding-inline: var(--gutter);
  /* Горизонтальный жест не «проваливается» в страницу. */
  overscroll-behavior-x: contain;
  /* Нативный свайп: и горизонталь, и вертикаль решает браузер, инерция естественная. */
  touch-action: pan-x pan-y;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

.rail::-webkit-scrollbar {
  display: none;
}

.rail__item {
  flex: 0 0 auto;
  scroll-snap-align: start;
}

/* ============ Карточка медиа ============ */
.media-card {
  position: relative;
  width: 148px;
  max-width: 100%;
  min-width: 0;
  aspect-ratio: 2 / 3;
  border: 1px solid var(--border);
  border-radius: var(--r-4);
  overflow: hidden;
  background: var(--surface);
}

.rail--wide .media-card {
  width: 168px;
}

.media-card__poster {
  position: absolute;
  inset: 0;
  background: linear-gradient(155deg, color-mix(in srgb, var(--cat, var(--surface-3)) 34%, var(--surface)), var(--surface) 58%, var(--bg));
}

.media-card__poster img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.media-card__shade {
  position: absolute;
  inset: 0;
  background: linear-gradient(to top, rgba(12, 10, 15, 0.95) 4%, rgba(12, 10, 15, 0.35) 44%, transparent 72%);
}

.media-card__badges {
  position: absolute;
  inset: 8px 8px auto;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--sp-2);
}

.media-card__body {
  position: absolute;
  inset: auto 0 0;
  padding: 10px 11px 12px;
}

.media-card__title {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  color: var(--text);
  font-size: 14px;
  font-weight: 700;
  line-height: 1.25;
  letter-spacing: -0.01em;
  overflow-wrap: anywhere;
}

.media-card__meta {
  margin-top: 3px;
  color: var(--text-2);
  font-size: var(--fs-xs);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.media-card__status {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: var(--sp-2);
  color: var(--status-color, var(--text-2));
  font-size: var(--fs-xs);
  font-weight: 600;
}

.media-card__dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--status-color, var(--accent));
}

/* Локальная запись ещё не подтверждена сервером. */
.card-pending {
  display: inline-block;
  flex: 0 0 auto;
  width: 6px;
  height: 6px;
  margin-left: 6px;
  border-radius: 50%;
  background: var(--accent-hi);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 25%, transparent);
  vertical-align: middle;
}

.media-card__progress {
  height: 3px;
  margin-top: 6px;
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.16);
  overflow: hidden;
}

.media-card__progress > i {
  display: block;
  height: 100%;
  border-radius: 2px;
  background: var(--cat, var(--accent));
}

/* ============ Создатели ============ */
.credits {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--sp-4) var(--sp-5);
}

.credits__name {
  font-size: var(--fs-sm);
  font-weight: 700;
}

.credits__role {
  margin-top: 2px;
  color: var(--text-2);
  font-size: var(--fs-xs);
}

/* ============ Актёры ============ */
.cast {
  width: 72px;
  text-align: center;
}

.cast .avatar {
  margin: 0 auto var(--sp-2);
}

.avatar {
  position: relative;
  display: grid;
  place-items: center;
  width: 56px;
  height: 56px;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: linear-gradient(140deg, var(--surface-3), var(--surface));
  font-size: 17px;
  font-weight: 800;
  color: var(--text);
  overflow: hidden;
}

/* Фото актёра: кружок сохраняет размер, инициалы видны до загрузки. */
.avatar__img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0;
}

.avatar__img--loaded {
  opacity: 1;
}

.cast__name {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  font-size: var(--fs-xs);
  font-weight: 600;
  line-height: 1.25;
}

.cast__role {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  margin-top: 3px;
  color: var(--text-3);
  font-size: 10px;
  line-height: 1.25;
}

/* ============ Детали: строки ключ → значение ============ */
.facts {
  border-top: 1px solid var(--border);
}

.facts__row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--sp-4);
  padding: 13px 0;
  border-bottom: 1px solid var(--border);
}

.facts__key {
  color: var(--text-2);
  font-size: var(--fs-sm);
}

.facts__val {
  font-size: var(--fs-sm);
  font-weight: 600;
  text-align: right;
}

/* ============ Шторка ============ */
.sheet {
  position: fixed;
  inset: auto 0 0 0;
  width: min(430px, 100%);
  max-height: 78dvh;
  margin: 0 auto;
  padding: 0;
  border: 0;
  border-radius: var(--r-5) var(--r-5) 0 0;
  background: var(--surface);
  color: var(--text);
}

/* Стеклянная шторка статуса — те же переменные, что у нижней панели и поиска. */
.sheet--glass {
  border: 1px solid var(--glass-border);
  background: var(--glass-bg);
  -webkit-backdrop-filter: var(--glass-filter);
  backdrop-filter: var(--glass-filter);
  box-shadow: var(--glass-shadow);
}

.sheet[open] {
  display: flex;
  flex-direction: column;
}

.sheet::backdrop {
  background: rgba(9, 8, 12, 0.62);
  backdrop-filter: blur(2px);
}

.sheet__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-4);
  padding: var(--sp-4) var(--gutter) var(--sp-3);
  border-bottom: 1px solid var(--border);
}

.sheet__title {
  font-size: var(--fs-h2);
  font-weight: 800;
}

.sheet__body {
  padding: var(--sp-4) var(--gutter) calc(var(--sp-6) + var(--safe-bottom));
  overflow-y: auto;
}

/* ============ Сетка оценок ============ */
.rating-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: var(--sp-2);
}

.rating-grid__item {
  min-height: var(--tap);
  border: 1px solid var(--border);
  border-radius: var(--r-2);
  background: var(--surface-2);
  font-weight: 700;
}

.rating-grid__item--active {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--accent-ink);
}

/* ============ Карточка «Похожее»: постер и название под ним ============ */
.poster-card {
  width: 108px;
  max-width: 100%;
  min-width: 0;
}

.poster-card__img {
  position: relative;
  aspect-ratio: 2 / 3;
  border: 1px solid var(--border);
  border-radius: var(--r-2);
  overflow: hidden;
  background: linear-gradient(160deg, color-mix(in srgb, var(--cat, var(--surface-3)) 32%, var(--surface-2)), var(--surface-2));
}

.poster-card__badge {
  position: absolute;
  top: 6px;
  left: 6px;
}

.poster-card__img img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.poster-card__title {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  margin-top: var(--sp-2);
  color: var(--text);
  font-size: var(--fs-xs);
  font-weight: 600;
  line-height: 1.3;
  overflow-wrap: anywhere;
}

/* ============ Компактная карточка «В планах» ============ */
.compact-card {
  display: flex;
  align-items: center;
  gap: 11px;
  height: 100%;
  min-width: 0;
  max-width: 100%;
  min-height: 84px;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: var(--r-3);
  background:
    radial-gradient(120% 160% at 100% 0%, color-mix(in srgb, var(--cat, var(--accent)) 10%, transparent), transparent 62%),
    color-mix(in srgb, var(--surface) 82%, transparent);
  overflow: hidden;
  transition:
    transform 180ms var(--ease),
    border-color 180ms ease-out;
}

.card-link:active .compact-card {
  transform: scale(0.99);
}

@media (hover: hover) {
  .card-link:hover .compact-card {
    border-color: var(--border-strong);
  }
}

.compact-card__poster {
  flex: 0 0 48px;
  width: 48px;
  aspect-ratio: 2 / 3;
  border: 1px solid var(--border);
  border-radius: 9px;
  overflow: hidden;
  background: linear-gradient(
    155deg,
    color-mix(in srgb, var(--cat, var(--surface-3)) 40%, var(--surface-2)),
    var(--surface-2)
  );
}

.compact-card__poster img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.compact-card__body {
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  justify-content: center;
  gap: 1px;
  min-width: 0;
}

.compact-card__type {
  color: var(--cat, var(--accent-soft));
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.compact-card__title {
  overflow: hidden;
  color: var(--text);
  font-size: 14px;
  font-weight: 700;
  line-height: 1.2;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.compact-card__meta {
  overflow: hidden;
  color: var(--text-2);
  font-size: 11px;
  line-height: 1.3;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.compact-card__rating {
  display: flex;
  align-items: center;
  gap: 3px;
  margin-top: 2px;
  color: var(--rating);
  font-size: 11px;
  font-weight: 700;
}

.compact-card__star {
  display: inline-grid;
  place-items: center;
}

.compact-card__star svg {
  width: 10px;
  height: 10px;
}

/* ============ Полный список актёров в шторке ============ */
.cast-list {
  display: grid;
  gap: var(--sp-3);
}

.cast-row {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
}

.cast-row .avatar {
  width: 44px;
  height: 44px;
  font-size: 14px;
}

.cast-row__text {
  display: grid;
  gap: 2px;
}

.cast-row__name {
  font-size: var(--fs-sm);
  font-weight: 700;
}

.cast-row__role {
  color: var(--text-2);
  font-size: var(--fs-xs);
}

/* ============ Офлайн-баннер ============ */
.offline-banner {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  padding: calc(6px + var(--safe-top)) var(--gutter) 6px;
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--surface-2) 92%, transparent);
  color: var(--text-2);
  font-size: var(--fs-xs);
  font-weight: 600;
  text-align: center;
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
}

.offline-banner::before {
  content: "";
  flex: 0 0 auto;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--rating);
}

/* ============ Тост ============ */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(96px + var(--safe-bottom));
  z-index: 60;
  display: flex;
  align-items: center;
  gap: var(--sp-4);
  width: calc(100% - 32px);
  max-width: 398px;
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: var(--r-3);
  background: var(--surface-2);
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translate(-50%, 12px);
  pointer-events: none;
  transition: opacity var(--dur) var(--ease), transform var(--dur) var(--ease);
}

.toast--visible {
  opacity: 1;
  transform: translate(-50%, 0);
  pointer-events: auto;
}

.toast__text {
  flex: 1 1 auto;
  font-size: var(--fs-sm);
}

.toast__action {
  flex: 0 0 auto;
  color: var(--accent);
  font-size: var(--fs-sm);
  font-weight: 700;
}

/* ============ Пустое состояние ============ */
.empty {
  display: grid;
  justify-items: center;
  gap: var(--sp-3);
  padding: var(--sp-8) var(--gutter);
  text-align: center;
}

.empty__art {
  width: 168px;
  height: 168px;
  border-radius: 50%;
  background: radial-gradient(circle at 50% 45%, var(--surface-2), var(--bg) 72%);
  display: grid;
  place-items: center;
}

.empty__title {
  font-size: var(--fs-h2);
  font-weight: 800;
}

.empty__text {
  max-width: 280px;
  color: var(--text-2);
  font-size: var(--fs-sm);
}

/* ============ Случайный выбор ============ */
.random-pick {
  display: flex;
  align-items: flex-start;
  gap: var(--sp-4);
}

.random-pick__poster {
  display: grid;
  place-items: center;
  flex: 0 0 108px;
  width: 108px;
  aspect-ratio: 2 / 3;
  border: 1px solid var(--border);
  border-radius: var(--r-3);
  overflow: hidden;
  background: linear-gradient(
    155deg,
    color-mix(in srgb, var(--cat, var(--surface-3)) 34%, var(--surface-2)),
    var(--surface-2)
  );
  color: var(--text-2);
  font-size: 30px;
  font-weight: 800;
}

.random-pick__poster img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.random-pick__info {
  display: grid;
  align-content: start;
  gap: 5px;
  min-width: 0;
  padding-top: 2px;
}

.random-pick__title {
  font-size: var(--fs-h1);
  font-weight: 800;
  line-height: 1.15;
  letter-spacing: -0.01em;
  overflow-wrap: anywhere;
}

.random-pick__meta {
  color: var(--text-2);
  font-size: var(--fs-sm);
}

.random-pick__status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--status-color, var(--text-2));
  font-size: var(--fs-xs);
  font-weight: 700;
}

.random-pick__status::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--status-color, var(--accent));
}

.random-pick__actions {
  display: grid;
  grid-template-columns: 1.2fr 1fr;
  gap: var(--sp-2);
  margin-top: var(--sp-5);
}

.random-empty {
  display: grid;
  justify-items: center;
  gap: var(--sp-3);
  padding: var(--sp-4) 0 var(--sp-2);
  text-align: center;
}

.random-empty__art {
  display: grid;
  place-items: center;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: color-mix(in srgb, var(--accent) 14%, transparent);
  color: var(--accent-soft);
}

.random-empty__art svg {
  width: 28px;
  height: 28px;
}

.random-empty__title {
  font-size: var(--fs-h2);
  font-weight: 800;
}

.random-empty__text {
  max-width: 280px;
  color: var(--text-2);
  font-size: var(--fs-sm);
}

/* ============ IGDB: плитки 2:3 и заглушка без постера ============ */
.result__poster,
.detail__poster,
.compact-card__poster {
  position: relative;
}

.poster-fallback {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--text-dim);
  opacity: 0.55;
  pointer-events: none;
}

.poster-fallback svg {
  width: 28px;
  height: 28px;
}

/* В детали обложка остаётся 3:4 — там важен весь постер, а не плитка. */
.detail[data-type="game"] .detail__poster {
  aspect-ratio: 3 / 4;
}
