  :root {
    --bg: #f4f5f7;
    --fg: #12151a;
    --muted: #6a7280;
    --line: #d9dce2;
    --card: #e6e8ed;
    --accent: #2f4fd8;
    --font: "Hanken Grotesk", system-ui, -apple-system, "Segoe UI", sans-serif;
    color-scheme: light;
  }
  @media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
      --bg: #0d0f12;
      --fg: #eceef2;
      --muted: #8b93a1;
      --line: #262a31;
      --card: #181b20;
      --accent: #8da2ff;
      color-scheme: dark;
    }
  }
  :root[data-theme="dark"] {
    --bg: #0d0f12;
    --fg: #eceef2;
    --muted: #8b93a1;
    --line: #262a31;
    --card: #181b20;
    --accent: #8da2ff;
    color-scheme: dark;
  }

  [hidden] { display: none !important; }

  * { box-sizing: border-box; }
  html { background: var(--bg); }
  body {
    margin: 0;
    background: var(--bg);
    color: var(--fg);
    font-family: var(--font);
    font-size: 15px;
    line-height: 1.5;
    padding-inline: max(16px, env(safe-area-inset-left, 0px)) max(16px, env(safe-area-inset-right, 0px));
    padding-block: 0 48px;
    min-height: 100vh;
  }
  main { max-width: 1100px; margin: 0 auto; }

  .search {
    position: sticky;
    top: 0;
    z-index: 50;
    background: var(--bg);
    padding-top: clamp(14px, 3vh, 24px);
    padding-bottom: 12px;
  }
  .brand {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    text-decoration: none;
    color: var(--fg);
    margin-bottom: 6px;
    user-select: none;
    width: fit-content;
    cursor: pointer;
    transition: opacity .15s ease;
  }
  .brand:hover { opacity: .75; }
  .brand-icon {
    width: 17px;
    height: 17px;
    color: var(--accent);
    flex-shrink: 0;
  }
  .brand-text {
    font-size: 14.5px;
    font-weight: 700;
    letter-spacing: -0.01em;
    color: var(--fg);
  }
  .search-wrap {
    position: relative;
    display: flex;
    align-items: center;
    width: 100%;
  }
  .search input {
    width: 100%;
    font: 500 clamp(20px, 3.5vw, 32px)/1.2 var(--font);
    letter-spacing: -0.01em;
    color: var(--fg);
    background: transparent;
    border: 0;
    border-bottom: 1.5px solid var(--line);
    border-radius: 0;
    padding: 10px 36px 12px 0;
    outline: none;
    transition: border-color .2s;
    -webkit-appearance: none;
    appearance: none;
  }
  .search input::placeholder { color: var(--muted); opacity: .7; }
  .search input:focus { border-bottom-color: var(--accent); }
  .search input::-webkit-search-cancel-button { display: none; }
  .search-clear {
    position: absolute;
    right: 0;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: 0;
    color: var(--muted);
    font-size: 24px;
    line-height: 1;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 50%;
    transition: color .15s;
  }
  .search-clear:hover { color: var(--fg); }
  .search-clear:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

  .label {
    margin: 32px 0 16px;
    font-size: 12px;
    font-weight: 600;
    letter-spacing: .09em;
    text-transform: uppercase;
    color: var(--muted);
  }

  .grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 22px 16px;
    margin: 0;
    padding: 0;
    list-style: none;
  }
  .item { min-width: 0; animation: rise .4s ease both; animation-delay: calc(var(--i, 0) * 25ms); }
  @keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

  .card {
    display: block;
    width: 100%;
    padding: 0;
    border: 0;
    background: none;
    color: inherit;
    font: inherit;
    text-align: left;
    cursor: pointer;
  }
  .poster {
    aspect-ratio: 2 / 3;
    width: 100%;
    background: var(--card);
    border-radius: 6px;
    overflow: hidden;
    display: grid;
    place-items: center;
    transition: transform .2s ease;
  }
  .poster img { width: 100%; height: 100%; object-fit: cover; display: block; }
  .poster span { padding: 12px; text-align: center; font-size: 13px; color: var(--muted); }
  .card:hover .poster { transform: translateY(-3px); }
  .card:focus-visible { outline: 2px solid var(--accent); outline-offset: 4px; border-radius: 6px; }
  .t { margin-top: 8px; font-weight: 500; font-size: 14px; line-height: 1.3; overflow-wrap: anywhere; }
  .m { margin-top: 2px; font-size: 12.5px; color: var(--muted); font-variant-numeric: tabular-nums; }
  .m b { color: var(--accent); font-weight: 600; }

  .note { color: var(--muted); margin: 8px 0; }

  .setup { max-width: 460px; }
  .setup p { margin: 0 0 12px; color: var(--muted); }
  .setup a { color: var(--accent); }
  .setup form { display: flex; gap: 8px; flex-wrap: wrap; }
  .setup input {
    flex: 1 1 220px; min-width: 0;
    font: inherit; color: var(--fg); background: transparent;
    border: 1px solid var(--line); border-radius: 6px; padding: 9px 12px;
  }
  .setup input:focus-visible, .setup button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
  .setup button {
    font: inherit; font-weight: 500; cursor: pointer;
    background: var(--fg); color: var(--bg);
    border: 0; border-radius: 6px; padding: 9px 16px;
  }

  footer {
    margin-top: 64px;
    font-size: 11.5px;
    color: var(--muted);
    display: flex; gap: 6px 14px; flex-wrap: wrap;
  }
  footer button {
    font: inherit; color: inherit; background: none; border: 0; padding: 0;
    cursor: pointer; text-decoration: underline;
  }

  dialog#dlg {
    width: min(760px, calc(100vw - 32px));
    max-height: calc(100dvh - 48px);
    padding: 0;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: var(--bg);
    color: var(--fg);
    overflow: auto;
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    margin: 0;
  }
  dialog#dlg::backdrop { background: rgba(8, 10, 14, .75); backdrop-filter: blur(6px); }
  .dlg-backdrop {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 260px;
    overflow: hidden;
    border-radius: 12px 12px 0 0;
    z-index: 0;
    pointer-events: none;
  }
  .dlg-backdrop img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    filter: blur(0px);
    transform: scale(1.04);
  }
  .dlg-backdrop::after {
    content: "";
    position: absolute;
    inset: 0;
    background: linear-gradient(
      to bottom,
      rgba(0,0,0,0.18) 0%,
      var(--bg) 100%
    );
  }
  .detail {
    display: grid;
    grid-template-columns: 180px minmax(0, 1fr);
    gap: 20px;
    padding: 20px 24px 24px;
    position: relative;
    z-index: 1;
    margin-top: 120px;
  }
  .detail .poster { border-radius: 8px; box-shadow: 0 8px 28px rgba(0,0,0,0.4); }
  .detail h2 { margin: 0; font-size: 22px; line-height: 1.2; letter-spacing: -0.01em; text-wrap: balance; }
  .detail .meta { margin: 6px 0 12px; color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }
  .detail .meta b { color: var(--accent); font-weight: 600; }
  .detail p { margin: 0 0 14px; max-width: 62ch; font-size: 14px; line-height: 1.6; }
  .detail a { color: var(--accent); font-weight: 500; }
  .close {
    position: absolute; top: 10px; right: 12px; z-index: 10;
    font: 400 22px/1 var(--font); color: #fff;
    background: rgba(0,0,0,0.45); border: 0; cursor: pointer;
    width: 32px; height: 32px; border-radius: 50%;
    display: grid; place-items: center;
    backdrop-filter: blur(4px);
    transition: background .15s;
  }
  .close:hover { background: rgba(0,0,0,0.7); }
  .close:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

  .cast-section { margin-top: 16px; grid-column: 1 / -1; }
  .cast-label {
    font-size: 11px;
    font-weight: 700;
    letter-spacing: .1em;
    text-transform: uppercase;
    color: var(--muted);
    margin-bottom: 10px;
  }
  .cast-pills {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
  }
  .cast-pill {
    font-size: 12px;
    padding: 4px 10px;
    border-radius: 20px;
    background: var(--card);
    border: 1px solid var(--line);
    color: var(--fg);
    line-height: 1.4;
  }
  .cast-pill span { color: var(--muted); font-size: 11px; }
  .actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin: 0 0 12px; }
  .actions select {
    flex: 1 1 150px; min-width: 0; max-width: 100%;
    font: inherit; color: var(--fg); background: var(--bg);
    border: 1px solid var(--line); border-radius: 6px; padding: 8px 10px;
  }
  .actions select:focus-visible, .play:focus-visible, .ext-link:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
  .play {
    font: inherit; font-weight: 500; cursor: pointer;
    background: var(--fg); color: var(--bg);
    border: 0; border-radius: 6px; padding: 9px 18px;
    transition: opacity .15s;
    display: inline-flex; align-items: center; gap: 6px;
  }
  .play:hover { opacity: .9; }
  .ext-link {
    font: inherit; font-size: 13.5px; font-weight: 500; text-decoration: none;
    color: var(--fg); background: transparent;
    border: 1px solid var(--line); border-radius: 6px; padding: 8px 14px;
    display: inline-flex; align-items: center; gap: 6px;
    transition: background .15s, border-color .15s;
  }
  .ext-link:hover { background: var(--card); }

  dialog#theater {
    width: 100vw;
    max-width: 100vw;
    height: 100vh;
    max-height: 100vh;
    margin: 0;
    padding: 0;
    border: 0;
    background: #000;
    color: #eceef2;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    z-index: 1000;
  }
  dialog#theater:not([open]) { display: none; }
  dialog#theater::backdrop { background: #000; }

  .theater-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 16px;
    background: #0d0f12;
    border-bottom: 1px solid #262a31;
    flex-shrink: 0;
    z-index: 10;
    flex-wrap: wrap;
  }
  .theater-left {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
    flex: 1 1 auto;
  }
  .theater-info {
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 1px;
  }
  .theater-title {
    font-size: 14.5px;
    font-weight: 600;
    color: #fff;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .theater-subtitle {
    font-size: 12px;
    color: #8b93a1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-variant-numeric: tabular-nums;
  }
  .theater-tv-controls {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
  }
  .theater-tv-controls[hidden] {
    display: none !important;
  }
  .theater-right {
    display: flex;
    align-items: center;
    gap: 8px;
  }
  .theater-btn {
    font: inherit;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    background: #181b20;
    color: #eceef2;
    border: 1px solid #262a31;
    border-radius: 6px;
    padding: 6px 12px;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    text-decoration: none;
    transition: background .15s, border-color .15s, opacity .15s;
    user-select: none;
    line-height: 1.4;
  }
  .theater-btn:hover:not(:disabled) {
    background: #262a31;
    color: #fff;
  }
  .theater-btn:focus-visible, .theater-select:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
  }
  .theater-btn:disabled {
    opacity: 0.35;
    cursor: not-allowed;
  }
  .theater-btn-primary {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
    font-weight: 600;
  }
  .theater-btn-primary:hover:not(:disabled) {
    opacity: .92;
    background: var(--accent);
    color: #fff;
  }
  .theater-btn-close {
    padding: 6px 10px;
    font-weight: 600;
  }
  .theater-select {
    font: inherit;
    font-size: 13px;
    color: #eceef2;
    background: #181b20;
    border: 1px solid #262a31;
    border-radius: 6px;
    padding: 6px 10px;
    max-width: 220px;
  }
  .theater-select option {
    background: #181b20;
    color: #eceef2;
  }
  .theater-notice {
    background: rgba(245, 158, 11, 0.14);
    border-bottom: 1px solid rgba(245, 158, 11, 0.35);
    color: #fbbf24;
    padding: 8px 18px;
    font-size: 12.5px;
    flex-shrink: 0;
  }
  .theater-notice a {
    color: #fff;
    text-decoration: underline;
    font-weight: 600;
    margin-left: 6px;
  }
  .theater-player {
    flex: 1 1 auto;
    position: relative;
    width: 100%;
    height: 100%;
    background: #000;
    overflow: hidden;
  }
  .theater-frame-wrap {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
  }
  .theater-frame-wrap iframe {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    border: 0;
  }
  .player-loader {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    color: #8b93a1;
    font-size: 14px;
    background: #0d0f12;
  }

  @media (max-width: 680px) {
    .theater-bar { padding: 8px 12px; gap: 8px; }
    .theater-btn-close .btn-text { display: none; }
    .theater-title { max-width: 150px; }
    .theater-select { max-width: 120px; font-size: 12px; padding: 5px 6px; }
    .theater-btn { padding: 5px 9px; font-size: 12px; }
  }
  .genres-bar {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding: 10px 0 2px;
    scrollbar-width: none;
    -ms-overflow-style: none;
  }
  .genres-bar::-webkit-scrollbar { display: none; }
  .genre-pill {
    font: inherit;
    font-size: 13px;
    font-weight: 500;
    padding: 5px 14px;
    border-radius: 20px;
    border: 1px solid var(--line);
    background: var(--card);
    color: var(--fg);
    cursor: pointer;
    white-space: nowrap;
    flex-shrink: 0;
    transition: background .15s, color .15s, border-color .15s;
  }
  .genre-pill:hover { background: var(--line); }
  .genre-pill.active {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
    font-weight: 600;
  }
  .genre-pill:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

  .history-section {
    margin-top: 20px;
    margin-bottom: 24px;
  }
  .section-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
  }
  .section-head .label { margin: 0; }
  .clear-history-btn {
    font: inherit;
    font-size: 12px;
    color: var(--muted);
    background: none;
    border: 0;
    cursor: pointer;
    padding: 0;
    text-decoration: underline;
  }
  .clear-history-btn:hover { color: var(--fg); }
  .history-scroll {
    display: flex;
    gap: 14px;
    overflow-x: auto;
    padding-bottom: 8px;
    scrollbar-width: thin;
  }
  .history-card {
    flex: 0 0 135px;
    display: flex;
    flex-direction: column;
    background: none;
    border: 0;
    padding: 0;
    color: inherit;
    font: inherit;
    text-align: left;
    cursor: pointer;
    position: relative;
  }
  .history-card .poster {
    aspect-ratio: 2 / 3;
    width: 100%;
    position: relative;
    border-radius: 6px;
    overflow: hidden;
    background: var(--card);
  }
  .history-card .ep-badge {
    position: absolute;
    bottom: 6px;
    right: 6px;
    background: rgba(0, 0, 0, 0.85);
    color: #fff;
    font-size: 11px;
    font-weight: 600;
    padding: 2px 6px;
    border-radius: 4px;
    backdrop-filter: blur(4px);
    border: 1px solid rgba(255, 255, 255, 0.15);
  }
  .history-card .t {
    margin-top: 6px;
    font-size: 13.5px;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .history-card .sub {
    font-size: 12px;
    color: var(--muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .history-card:hover .poster { transform: translateY(-3px); }

  dialog#trailerDlg {
    width: min(840px, calc(100vw - 32px));
    padding: 0;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: #000;
    color: #fff;
    overflow: hidden;
  }
  dialog#trailerDlg::backdrop { background: rgba(8, 10, 14, .85); }
  .trailer-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 16px;
    background: #0d0f12;
    border-bottom: 1px solid #262a31;
    position: relative;
  }
  .trailer-title {
    font-size: 14px;
    font-weight: 600;
    color: #eceef2;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .trailer-bar .close {
    position: static;
    color: #8b93a1;
    font-size: 24px;
    padding: 0 4px;
    line-height: 1;
  }
  .trailer-bar .close:hover { color: #fff; }
  .trailer-video-box {
    position: relative;
    width: 100%;
    aspect-ratio: 16 / 9;
    background: #000;
  }
  .trailer-frame-wrap {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
  }
  .trailer-frame-wrap iframe {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    border: 0;
  }
  .trailer-btn {
    font: inherit;
    font-size: 13.5px;
    font-weight: 500;
    cursor: pointer;
    background: transparent;
    color: var(--fg);
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 8px 14px;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    transition: background .15s, border-color .15s;
  }
  .trailer-btn:hover { background: var(--card); }
  .trailer-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

  @media (max-width: 560px) {
    .detail { grid-template-columns: 1fr; margin-top: 80px; }
    .detail .poster { max-width: 140px; }
    .dlg-backdrop { height: 180px; }
  }
  @media (prefers-reduced-motion: reduce) {
    .item { animation: none; }
    .poster { transition: none; }
  }
