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

:root {
  color-scheme: dark;
  --background: #070a0e;
  --surface: #101b27;
  --surface-hover: #162638;
  --border: #233b52;
  --focus: #8ccaff;
  --ink: #ffffff;
  --muted: #a6bfd4;
  --quiet: #86a8c4;
  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 { min-height: 100vh; margin: 0; }
button, input { font: inherit; }
button, a { -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: 5px; }
.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: none; }

.page-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 24px; padding-bottom: 32px; border-bottom: 1px solid var(--border); }
.brand { margin: 0 0 12px; color: var(--quiet); font-size: 12px; font-weight: 600; letter-spacing: .18em; }
h1 { display: flex; align-items: center; gap: 16px; margin: 0; font-size: 36px; font-weight: 600; line-height: 1.2; letter-spacing: .04em; }
.heading-mn { display: inline-block; height: 64px; font-family: "Mangas Mongolian", serif; font-size: 24px; font-weight: 400; writing-mode: vertical-lr; text-orientation: sideways; line-height: 1.5; letter-spacing: 0; }
.intro { margin: 16px 0 0; color: var(--muted); font-size: 14px; line-height: 1.7; }
.back-link { display: flex; align-items: center; gap: 8px; flex: 0 0 auto; min-height: 44px; margin-top: 24px; padding: 8px 12px; border: 1px solid var(--border); border-radius: 8px; color: var(--muted); text-decoration: none; font-size: 14px; transition: color .15s, border-color .15s; }
.back-link svg { width: 20px; height: 20px; }
.back-link:hover { color: var(--ink); border-color: var(--quiet); }

.catalogue-controls { display: flex; align-items: center; justify-content: space-between; gap: 24px; margin: 28px 0 24px; }
.search-form { position: relative; display: flex; align-items: center; width: 100%; max-width: 520px; min-height: 48px; }
.search-icon { position: absolute; width: 20px; height: 20px; left: 16px; color: var(--quiet); pointer-events: none; }
#movie-search { width: 100%; min-height: 48px; border: 1px solid var(--border); border-radius: 8px; padding: 12px 48px 12px 48px; background: var(--surface); color: var(--ink); caret-color: var(--focus); font-size: 15px; }
#movie-search::placeholder { color: var(--muted); opacity: 1; }
#movie-search::-webkit-search-cancel-button { -webkit-appearance: none; }
#movie-search:focus-visible { outline-offset: 2px; }
.clear-button { position: absolute; right: 4px; display: flex; align-items: center; justify-content: center; width: 40px; height: 40px; border: 0; border-radius: 6px; background: transparent; color: var(--muted); }
.clear-button svg { width: 20px; height: 20px; }
.clear-button:hover { color: var(--ink); background: var(--surface-hover); }
.result-count { flex: 0 0 auto; margin: 0; color: var(--muted); font-size: 14px; font-variant-numeric: tabular-nums; line-height: 1.5; }

.movie-grid { margin-top: 28px; display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 24px 20px; min-height: 1px; }
.movie-grid:focus { outline-offset: 8px; }
.movie-entry { min-width: 0; }
.movie-card { display: grid; grid-template-columns: minmax(0, 1fr) 48px; min-width: 0; height: 100%; overflow: hidden; border: 1px solid var(--border); border-radius: 12px; background: var(--surface); color: var(--ink); text-decoration: none; transition: border-color .15s, background-color .15s; }
.movie-card:hover { background: var(--surface-hover); border-color: var(--quiet); }
.movie-card:focus-visible { outline-offset: 4px; border-color: var(--focus); }
.poster { position: relative; width: 100%; aspect-ratio: 2 / 3; overflow: hidden; background: #0c141d; }
.poster-image { display: block; width: 100%; height: 100%; object-fit: cover; object-position: center; }
.poster-landscape .poster-image { object-fit: contain; }
.poster-fallback { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16px; width: 100%; height: 100%; color: var(--quiet); }
.poster-fallback svg { width: 44px; height: 44px; stroke-width: 1.2; }
.poster-fallback span { font-size: 12px; letter-spacing: .08em; }
.duration { position: absolute; right: 8px; bottom: 8px; max-width: calc(100% - 16px); padding: 4px 8px; border: 1px solid #ffffff35; border-radius: 6px; background: #070a0ee8; color: var(--ink); font-size: 12px; line-height: 1.5; font-variant-numeric: tabular-nums; }
.movie-info { position: relative; }
.movie-title {
  position: absolute;
  inset: 0;
  margin: 0;
  padding: 8px 2px 8px 7px;
  overflow-x: hidden;
  overflow-y: auto;
  scrollbar-width: thin;
  font-family: "Mangas Mongolian", serif;
  font-size: 21px;
  font-weight: 400;
  line-height: 1.25;
  writing-mode: vertical-lr;
  text-orientation: sideways;
  white-space: nowrap;
}

.catalogue-state { display: flex; min-height: 260px; flex-direction: column; align-items: center; justify-content: center; gap: 16px; padding: 32px; border: 1px solid var(--border); border-radius: 12px; background: #0b121b; text-align: center; color: var(--muted); }
.catalogue-state p { margin: 0; max-width: 48ch; line-height: 1.8; font-size: 15px; }
.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; }
.retry-button { min-height: 44px; padding: 10px 20px; border: 1px solid var(--quiet); border-radius: 8px; background: var(--surface); color: var(--ink); }
.retry-button:hover { border-color: var(--focus); background: var(--surface-hover); }
.retry-button:disabled { cursor: wait; opacity: .6; }
.noscript-note { padding: 24px; color: var(--muted); line-height: 1.8; }
.page-footer { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 12px 24px; padding-top: 24px; margin-top: 40px; border-top: 1px solid var(--border); color: var(--quiet); font-size: 12px; line-height: 1.8; }
.page-footer p { margin: 0; }
.page-footer a { color: var(--muted); text-decoration-color: #54738f; text-underline-offset: 4px; }
.page-footer a:hover { color: var(--ink); }
@keyframes loading-turn { to { transform: rotate(360deg); } }

@media (max-width: 1199px) {
  .movie-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}
@media (max-width: 719px) {
  .catalogue { padding: 24px 16px; }
  .page-header { gap: 16px; padding-bottom: 24px; }
  h1 { font-size: 30px; gap: 12px; }
  .brand { margin-bottom: 8px; }
  .heading-mn { height: 56px; font-size: 21px; }
  .intro { max-width: 24ch; font-size: 13px; margin-top: 12px; }
  .back-link { margin-top: 20px; padding: 8px; font-size: 12px; gap: 4px; }
  .back-link svg { width: 18px; height: 18px; }
  .catalogue-controls { align-items: stretch; flex-direction: column; gap: 12px; margin: 20px 0; }
  .search-form { max-width: none; }
  .result-count { font-size: 13px; }
  .movie-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px 12px; }
  .movie-card { grid-template-columns: minmax(0, 1fr) 42px; }
  .movie-title { font-size: 20px; }
  .page-footer { margin-top: 32px; padding-top: 20px; }
}
@media (max-width: 359px) {
  .catalogue { padding-right: 12px; padding-left: 12px; }
  .page-header { gap: 8px; }
  .back-link { border-color: transparent; padding-right: 0; padding-left: 4px; }
  .back-link span { max-width: 3em; }
  .movie-grid { gap: 16px 8px; }
  .movie-card { grid-template-columns: minmax(0, 1fr) 38px; }
  .movie-title { font-size: 18px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* Plain focus selectors remain visible on TV WebViews without :focus-visible. */
.movie-card.remote-focus, .movie-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;
}
.movie-card.remote-focus { background:#162d42; }
