/*
 * Shared text wrapping rules for NewAnime.
 *
 * Goals:
 * - keep Korean phrases together when space allows;
 * - allow natural Japanese line breaking;
 * - prevent long English titles, URLs, and labels from overflowing;
 * - let flex/grid children shrink instead of forcing horizontal overflow;
 * - preserve the intentional single-line title marquee once it activates.
 */

body {
  overflow-wrap: anywhere;
  hyphens: none;
}

html[lang^="ko"] body {
  word-break: keep-all;
  line-break: strict;
}

html[lang^="ja"] body {
  word-break: normal;
  line-break: strict;
}

html[lang^="en"] body {
  word-break: normal;
  line-break: auto;
}

/* Prefer readable line endings for all substantial copy and labels. */
:where(
  h1, h2, h3, h4,
  p, li, dt, dd,
  .hero-kicker,
  .eyebrow,
  .season-divider h2,
  .month-head h3,
  .title-scroll-inner,
  .undated-title-scroll-inner,
  .source-box,
  .source-list,
  .stream-dialog h4,
  .stream-dialog-desc,
  .stream-dialog-kicker,
  .streaming-region-heading,
  .streaming-region-note,
  .streaming-region-empty,
  .archive-hero h1,
  .archive-description,
  .archive-section-head h2,
  .archive-card h3,
  .archive-alt-title,
  .anime-localized h1,
  .alternate-titles,
  .detail-kicker,
  .panel-heading h2,
  .panel-note,
  .release-value,
  .changelog-group > h3,
  .changelog-entry-title,
  .changelog-entry p,
  .info-panel,
  .info-meta,
  .site-footer-links
) {
  text-wrap: pretty;
}

/* Grid/flex text columns must be allowed to shrink before their text can wrap. */
:where(
  .card,
  .card-top,
  .title-scroll,
  .undated-item,
  .undated-title-scroll,
  .month-head,
  .stream-dialog-head,
  .stream-dialog-head > div,
  .ott-option,
  .source-item,
  .source-link,
  .source-link > span:first-child,
  .site-menu-item,
  .detail-main,
  .anime-localized,
  .detail-panel,
  .panel-heading,
  .source-heading,
  .detail-actions,
  .detail-action,
  .streaming-list,
  .streaming-link,
  .streaming-link > span:first-child,
  .archive-section-head,
  .archive-card,
  .archive-card-body,
  .archive-nav,
  .archive-nav a,
  .changelog-day,
  .changelog-group,
  .changelog-entries,
  .changelog-entry,
  .info-panel,
  .site-footer-links
) {
  min-width: 0;
}

/* Controls with localized labels should wrap instead of clipping or widening the page. */
:where(
  .chip,
  .year-chip,
  .filter-toggle,
  #mobileToolbarToggle,
  #resetBtn,
  #undatedToggle,
  .site-menu-item,
  .detail-back,
  .detail-share,
  .detail-action,
  .streaming-link,
  .source-link,
  .archive-back,
  .archive-nav a,
  .changelog-source,
  .site-footer-links a
) {
  max-width: 100%;
  white-space: normal;
  overflow-wrap: anywhere;
}

/* Keep the icon/arrow side stable while the label is allowed to wrap. */
:where(
  .site-menu-icon,
  .filter-toggle-icon,
  #mobileToolbarIcon,
  #undatedArrow,
  .detail-action > span[aria-hidden="true"],
  .streaming-link > span:last-child,
  .source-link > span:last-child,
  .changelog-source > span[aria-hidden="true"]
) {
  flex: 0 0 auto;
}

#undatedToggle > span:first-child,
.site-menu-item > span:last-child,
.ott-option-name,
.ott-option-state,
.streaming-link > span:first-child,
.source-link > span:first-child,
.changelog-source {
  min-width: 0;
}

/* Compact metadata is intentionally kept on one line when possible. */
:where(
  .date,
  .month-count,
  .archive-card-date,
  .archive-count,
  .panel-label,
  .source-checked dt,
  .source-checked dd
) {
  white-space: nowrap;
  overflow-wrap: normal;
}

/* Long alternate titles and source labels may contain unbroken Latin tokens. */
:where(
  .alternate-titles,
  .archive-alt-title,
  .source-link small,
  .source-link strong,
  .changelog-entry-title,
  .changelog-entry p,
  .info-panel a
) {
  overflow-wrap: anywhere;
}

/* Preserve the homepage's deliberate single-line marquee after overflow detection. */
.title-scroll.is-overflowing .title-scroll-inner,
.undated-title-scroll.is-overflowing .undated-title-scroll-inner {
  white-space: nowrap;
  word-break: normal;
  overflow-wrap: normal;
  text-wrap: nowrap;
}

@media (max-width: 620px) {
  #mobileToolbarTitle,
  #undatedToggle > span:first-child,
  .panel-heading h2,
  .source-heading h2,
  .changelog-entry-title {
    min-width: 0;
    white-space: normal;
  }

  .month-head,
  .archive-section-head,
  .panel-heading,
  .source-heading {
    align-items: flex-start;
  }
}

/* Homepage card hierarchy refinement. Keep the existing horizontal card model,
   but give schedule, title, metadata and actions a clearer reading order. */
.card.card-refined,
.undated-item.card-refined {
  --card-accent: rgba(142, 161, 255, .18);
}

.card .card-top,
.undated-item .card-top {
  flex-direction: column;
  align-items: stretch;
  justify-content: flex-start;
  gap: 7px;
}

.card .card-top .date,
.undated-item .card-top .date {
  order: 0;
  align-self: flex-start;
  padding: 4px 7px;
  color: #cfd6ff;
  background: rgba(142,161,255,.075);
  border-color: rgba(142,161,255,.13);
  letter-spacing: .015em;
}

.card .card-top .title-group,
.undated-item .card-top .title-group {
  order: 1;
  width: 100%;
  min-width: 0;
}

.card .title {
  font-size: 16px;
  line-height: 1.4;
  letter-spacing: -.012em;
}

.card .meta,
.undated-item .meta {
  gap: 5px;
  margin-top: 9px;
}

.card-tag-overflow-hidden {
  display: none !important;
}

.badge.badge-overflow {
  color: #aeb6c8;
  background: rgba(255,255,255,.022);
  border-style: dashed;
  border-color: rgba(255,255,255,.08);
}

.card .resource-actions,
.undated-item .resource-actions {
  gap: 6px;
  border-top-color: rgba(255,255,255,.05);
}

.card .resource-btn,
.undated-item .resource-btn {
  color: #cdd4ea;
  border-color: rgba(255,255,255,.075);
  background: rgba(255,255,255,.028);
}

.card a.resource-btn:hover,
.undated-item a.resource-btn:hover {
  color: #e9edff;
  border-color: rgba(142,161,255,.28);
  background: rgba(142,161,255,.085);
}

.card .stream-trigger:not(:disabled),
.undated-item .stream-trigger:not(:disabled) {
  color: #f3f5ff;
  border-color: rgba(142,161,255,.33);
  background: linear-gradient(135deg, rgba(142,161,255,.18), rgba(178,140,255,.11));
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.018);
}

.card .stream-trigger:not(:disabled):hover,
.undated-item .stream-trigger:not(:disabled):hover {
  border-color: rgba(142,161,255,.5);
  background: linear-gradient(135deg, rgba(142,161,255,.25), rgba(178,140,255,.15));
}

.card .resource-btn.disabled,
.undated-item .resource-btn.disabled,
.card .stream-trigger:disabled,
.undated-item .stream-trigger:disabled {
  opacity: .42;
  color: #616979;
  background: rgba(255,255,255,.012);
  border-color: rgba(255,255,255,.035);
}

.card .poster-frame,
.undated-item .poster-frame {
  transition: transform .2s ease, border-color .2s ease, box-shadow .2s ease;
  box-shadow: 0 7px 18px rgba(0,0,0,.18), inset 0 0 0 1px rgba(255,255,255,.012);
}

.card:hover .poster-frame,
.undated-item:hover .poster-frame {
  transform: translateY(-1px);
  border-color: rgba(142,161,255,.2);
  box-shadow: 0 10px 24px rgba(0,0,0,.25), 0 0 0 1px rgba(142,161,255,.035);
}

.card .poster-frame img,
.undated-item .poster-frame img {
  transition: transform .22s ease, filter .22s ease;
}

.card:hover .poster-frame img,
.undated-item:hover .poster-frame img {
  transform: scale(1.012);
  filter: brightness(1.025);
}

.card .anime-detail-poster-link,
.undated-item .anime-detail-poster-link {
  cursor: pointer;
}

.card .poster-frame .wishlist-toggle,
.undated-item .poster-frame .wishlist-toggle {
  opacity: .62;
  background: rgba(8,10,15,.25);
  border-color: rgba(255,255,255,.075);
  transition: opacity .18s ease, transform .18s ease, background .18s ease, border-color .18s ease;
}

.card:hover .poster-frame .wishlist-toggle,
.undated-item:hover .poster-frame .wishlist-toggle,
.card .poster-frame .wishlist-toggle:hover,
.card .poster-frame .wishlist-toggle:focus-visible,
.undated-item .poster-frame .wishlist-toggle:hover,
.undated-item .poster-frame .wishlist-toggle:focus-visible,
.card .poster-frame .wishlist-toggle.is-active,
.undated-item .poster-frame .wishlist-toggle.is-active {
  opacity: 1;
}

@media (hover: none) {
  .card .poster-frame .wishlist-toggle,
  .undated-item .poster-frame .wishlist-toggle {
    opacity: .78;
  }

  .card .poster-frame .wishlist-toggle.is-active,
  .undated-item .poster-frame .wishlist-toggle.is-active {
    opacity: 1;
  }
}

@media (max-width: 520px) {
  .card {
    padding: 12px 13px;
  }

  .card .card-top,
  .undated-item .card-top {
    gap: 6px;
  }

  .card .title {
    font-size: 14.5px;
    line-height: 1.42;
  }

  .card .card-top .date,
  .undated-item .card-top .date {
    padding: 3px 6px;
    font-size: 10px;
  }

  .card .meta,
  .undated-item .meta {
    margin-top: 8px;
  }

  .badge {
    padding: 4px 6px;
  }
}
