@font-face {
  font-family: "Mangas Menk Qagan";
  src: url("./fonts/menk-qagan.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Noto Sans Mongolian";
  src: url("/NotoSansMongolian-Regular.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

:root {
  color-scheme: dark;
  --background: #070a0e;
  --surface: #101b27;
  --surface-hover: #162d42;
  --border: #233b52;
  --ink: #ffffff;
  --muted: #aec3d5;
  --focus: #8ccaff;
  font-family: "Noto Sans SC", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--background);
  color: var(--ink);
}

* { box-sizing: border-box; }
html { min-width: 280px; min-height: 100%; scrollbar-color: #38546e var(--background); }
body { margin: 0; min-height: 100vh; }
button, select { font: inherit; }
button, a, select { -webkit-tap-highlight-color: transparent; }
button { cursor: pointer; }
a { color: inherit; }
[hidden] { display: none !important; }
::selection { background: var(--focus); color: var(--background); }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 4px; }
.catalogue { width: 100%; max-width: 1440px; margin: 0 auto; padding: 40px 32px 32px; }
.visually-hidden { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
.skip-link { position: fixed; top: 12px; left: 12px; z-index: 10; padding: 12px 16px; border-radius: 8px; background: var(--focus); color: var(--background); transform: translateY(-160%); }
.skip-link:focus { transform: translateY(0); }

.page-header { display: flex; align-items: center; justify-content: space-between; gap: 24px; padding-bottom: 32px; border-bottom: 1px solid var(--border); }
.brand { margin: 0 0 12px; font-size: 12px; font-weight: 600; letter-spacing: .18em; color: var(--muted); }
h1 { margin: 0; font-size: 36px; line-height: 1.25; font-weight: 600; letter-spacing: .04em; }
.back-link, .context-back { display: inline-flex; align-items: center; flex: 0 0 auto; gap: 8px; min-height: 44px; padding: 8px 12px; color: var(--muted); border: 1px solid var(--border); border-radius: 8px; text-decoration: none; font-size: 14px; line-height: 1.5; }
.back-link svg, .context-back svg { width: 20px; height: 20px; flex: 0 0 auto; }
.back-link:hover, .context-back:hover { color: var(--ink); border-color: var(--focus); background: var(--surface); }
.program-sources { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 24px; }
.program-sources [aria-current="page"] { color: var(--ink); border-color: #567c9d; background: var(--surface); }
.program-context { display: flex; align-items: flex-start; flex-wrap: wrap; gap: 24px; margin-top: 24px; padding: 0 0 24px; border-bottom: 1px solid var(--border); }
.context-back { align-self: flex-start; }
.context-heading { flex: 1 1 240px; min-width: 0; }
.pua-title { width: 100%; height: 144px; margin: 0; padding: 0 4px 8px; overflow: auto; font-family: "Mangas Menk Qagan", serif; font-size: 26px; line-height: 1.55; font-weight: 400; letter-spacing: 0; writing-mode: vertical-lr; text-orientation: sideways; word-break: keep-all; overflow-wrap: normal; scrollbar-width: thin; }
.context-title { height: 120px; font-size: 28px; }
.context-title-zh { margin: 12px 0 8px; font-size: 16px; line-height: 1.6; overflow-wrap: anywhere; }

.catalogue-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 24px; min-height: 1px; margin-top: 32px; }
.catalogue-grid:focus { outline-offset: 8px; }
.catalogue-entry { min-width: 0; }
.catalogue-card { display: flex; flex-direction: column; min-width: 0; height: 100%; border: 1px solid var(--border); border-radius: 12px; background: var(--surface); color: var(--ink); text-decoration: none; transition: border-color .15s, background-color .15s; }
.catalogue-card:hover { border-color: var(--focus); background: var(--surface-hover); }
.catalogue-card:focus-visible { border-color: var(--focus); }
.cover { position: relative; width: 100%; aspect-ratio: 16 / 9; overflow: hidden; border-radius: 11px 11px 0 0; background: #0c141d; }
.cover-image { display: block; width: 100%; height: 100%; object-fit: cover; }
.cover-fallback { display: flex; align-items: center; justify-content: center; flex-direction: column; gap: 12px; width: 100%; height: 100%; color: var(--muted); }
.cover-fallback svg { width: 40px; height: 40px; }
.cover-fallback span { font-size: 12px; }
.duration { position: absolute; right: 8px; bottom: 8px; padding: 4px 8px; border: 1px solid #ffffff35; border-radius: 4px; background: #070a0ee8; color: var(--ink); font-size: 12px; line-height: 1.5; font-variant-numeric: tabular-nums; }
.card-info { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: start; gap: 10px; flex: 1 1 auto; padding: 12px; }
.card-heading { min-width: 0; }
.card-heading .pua-title { height: auto; max-height: 180px; padding: 0 0 6px; white-space: pre; line-height: 1.25; }
.nmtv-title { height: auto; margin: 0; font-size: 16px; font-weight: 500; line-height: 1.5; overflow-wrap: anywhere; }
.nmtv-title-mn { font-family: "Noto Sans Mongolian", serif; text-orientation: mixed; }
.card-title-zh { margin: 6px 0 0; color: var(--muted); font-size: 13px; line-height: 1.6; overflow-wrap: anywhere; }
.card-date { display: flex; flex-direction: column; align-items: flex-end; gap: 2px; margin: 0; color: var(--muted); font-size: 12px; line-height: 1.6; font-variant-numeric: tabular-nums; white-space: nowrap; }
.more-row { display: flex; justify-content: center; margin-top: 32px; }
.action-button { min-height: 44px; padding: 12px 24px; border: 1px solid #567c9d; border-radius: 8px; background: var(--surface); color: var(--ink); line-height: 1.5; }
.action-button:hover { border-color: var(--focus); background: var(--surface-hover); }
.action-button:disabled { cursor: wait; opacity: .6; }
.catalogue-state { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16px; min-height: 256px; padding: 32px; margin-top: 32px; border: 1px solid var(--border); border-radius: 12px; background: #0b121b; color: var(--muted); text-align: center; }
.catalogue-state p { max-width: 65ch; margin: 0; font-size: 15px; line-height: 1.8; }
.loading-mark { width: 28px; height: 28px; border: 2px solid var(--border); border-top-color: var(--focus); border-radius: 50%; animation: loading-turn .8s linear infinite; }
.catalogue-state[data-kind="error"] .loading-mark, .catalogue-state[data-kind="empty"] .loading-mark { display: none; }
.noscript-note { color: var(--muted); line-height: 1.8; }
.page-footer { margin-top: 32px; padding-top: 24px; border-top: 1px solid var(--border); color: var(--muted); font-size: 12px; line-height: 1.8; }
.page-footer p { margin: 0; max-width: 65ch; }
@keyframes loading-turn { to { transform: rotate(360deg); } }

@media (max-width: 719px) {
  .catalogue { padding: 24px 16px; }
  .page-header { gap: 16px; padding-bottom: 24px; }
  .brand { margin-bottom: 8px; }
  h1 { font-size: 28px; }
  .back-link { padding: 8px; font-size: 12px; gap: 4px; }
  .back-link svg { width: 16px; height: 16px; }
  .program-context { gap: 16px; }
  .context-back { padding: 8px; }
  .context-heading { flex-basis: calc(100% - 128px); }
  .context-title { height: 120px; font-size: 26px; }
  .catalogue-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 24px 12px; margin-top: 24px; }
  .card-info { gap: 6px; padding: 10px 8px; }
  .pua-title { font-size: 24px; height: 144px; }
  .context-title { height: 120px; }
  .card-title-zh { font-size: 12px; }
  .card-date { font-size: 11px; }
  .duration { right: 4px; bottom: 4px; padding: 4px; font-size: 12px; }
}
@media (prefers-reduced-motion: reduce) {
  .catalogue-card { transition: none; }
  .loading-mark { animation-duration: 2s; }
}

/* Plain focus selectors remain visible on TV WebViews without :focus-visible. */
.catalogue-card.remote-focus, .catalogue-card:focus,
.back-link.remote-focus, .back-link:focus, .context-back.remote-focus, .context-back:focus,
#retry-load.remote-focus, #retry-load:focus, #load-more.remote-focus, #load-more:focus,
.page-footer a.remote-focus, .page-footer a:focus {
  outline:4px solid #8ccaff;
  outline-offset:4px;
  border-color:#8ccaff;
  box-shadow:0 0 0 3px #070a0e;
}
.catalogue-card.remote-focus { background:#162d42; }
