:root {
  --bg: #09090c;
  --surface: rgba(17, 17, 23, .82);
  --surface-2: rgba(28, 28, 37, .9);
  --border: rgba(255, 255, 255, .09);
  --text: #ececf1;
  --muted: #a3a3b5;
  --accent: #7c5cff;
  --accent-2: #6a48ff;
  --ink: #ffffff;
  --radius: 16px;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; min-height: 100vh; background: var(--bg); color: var(--text);
  font: 15px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

/* Backdrop */
.backdrop { position: fixed; inset: 0; width: 100%; height: 100%; object-fit: cover; object-position: center 20%; z-index: 0; opacity: .55; }
.shade { position: fixed; inset: 0; z-index: 0;
  background: linear-gradient(180deg, rgba(9,9,12,.55) 0%, rgba(9,9,12,.78) 38%, rgba(9,9,12,.96) 70%, var(--bg) 100%); }
.page { position: relative; z-index: 1; min-height: 100vh; display: flex; flex-direction: column; }

/* Header / footer */
.bar { width: 100%; max-width: 760px; margin: 0 auto; padding: 16px 16px 0; }
.brand { display: inline-flex; align-items: center; gap: 10px; font-weight: 700; font-size: 16px; letter-spacing: -.01em; }
.brand-mark { width: 22px; height: 22px; border-radius: 7px; background: linear-gradient(135deg, var(--accent), #c06cff); position: relative; flex: none; }
.brand-mark::after { content: ""; position: absolute; left: 6px; top: 5px; width: 10px; height: 12px;
  background: linear-gradient(#fff, #fff) center 0 / 2px 8px no-repeat, linear-gradient(#fff, #fff) center 100% / 10px 2px no-repeat; }
.foot { margin-top: auto; padding: 28px 16px 32px; text-align: center; color: var(--muted); font-size: 13px; }

.wrap { width: 100%; max-width: 760px; margin: 0 auto; padding: 0 16px; }

/* Hero */
.hero { display: flex; gap: 18px; align-items: flex-end; padding: 36px 0 22px; }
.poster { width: 112px; height: auto; aspect-ratio: 2 / 3; object-fit: cover; border-radius: 12px; flex: none;
  box-shadow: 0 12px 40px rgba(0,0,0,.55); border: 1px solid var(--border); background: #15151c; }
.hero-text { min-width: 0; }
.facts { margin: 0 0 6px; color: var(--muted); font-size: 13px; }
.hero h1 { margin: 0; font-size: clamp(24px, 6vw, 36px); line-height: 1.1; letter-spacing: -.02em; overflow-wrap: anywhere; }
.ep-line { margin: 8px 0 0; font-size: 16px; }
.overview { margin: 10px 0 0; color: #cfcfdb; font-size: 14px; display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden; }

/* Episode navigation */
.ep-nav { display: flex; align-items: center; gap: 8px; margin: 0 0 16px; }
.ep-step { flex: none; width: 46px; height: 46px; display: grid; place-items: center; border-radius: 50%;
  background: var(--surface-2); border: 1px solid var(--border); }
.ep-step svg { width: 22px; height: 22px; fill: currentColor; }
.ep-step:not(.off):hover { border-color: var(--accent); }
.ep-step.off { opacity: .3; }
.ep-pick { flex: 1; min-width: 0; display: flex; gap: 8px; margin: 0; }
.sel { position: relative; display: block; min-width: 0; }
.sel.grow { flex: 1; }
.sel select { appearance: none; -webkit-appearance: none; width: 100%; height: 46px; padding: 0 34px 0 14px; border-radius: 12px;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text); font: 600 14px/1 inherit; text-overflow: ellipsis; cursor: pointer; }
.sel::after { content: ""; position: absolute; right: 14px; top: 50%; width: 8px; height: 8px; margin-top: -6px;
  border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted); transform: rotate(45deg); pointer-events: none; }
.sel select:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.sel option { background: #15151c; color: var(--text); }

/* Cards */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin: 0 0 14px;
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.card h2 { margin: 0; font-size: 17px; letter-spacing: -.01em; }
.note { margin: 12px 2px 0; color: var(--muted); font-size: 13px; }
.msg h1, .msg h2 { margin: 0 0 6px; font-size: 20px; }
.msg p { margin: 0; color: #cfcfdb; }
.wrap > .msg:first-child { margin-top: 28px; }
.msg-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 16px !important; }

/* Buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; height: 42px; padding: 0 18px; border-radius: 11px;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text); font: 600 14px/1 inherit; cursor: pointer; }
.btn:hover { border-color: var(--accent); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--ink); }

/* Embedded-subtitle picker */
.embed { display: flex; align-items: center; gap: 10px; font-size: 13px; color: var(--muted); }
.embed .sel select { height: 36px; font-size: 13px; border-radius: 10px; min-width: 120px; }

/* Quality list */
.q-list, .sub-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.q { display: flex; gap: 8px; }
.q-main { flex: 1; min-width: 0; display: flex; align-items: center; gap: 14px; min-height: 64px; padding: 10px 14px;
  border-radius: 13px; background: linear-gradient(180deg, var(--accent), var(--accent-2)); color: var(--ink);
  box-shadow: 0 6px 22px color-mix(in srgb, var(--accent) 28%, transparent); transition: transform .12s, filter .12s; }
.q-main:hover { filter: brightness(1.08); }
.q-main:active { transform: scale(.985); }
.q-icon { width: 38px; height: 38px; flex: none; display: grid; place-items: center; border-radius: 10px; background: rgba(255,255,255,.16); }
.q-icon svg { width: 22px; height: 22px; fill: currentColor; }
.q-text { display: flex; flex-direction: column; min-width: 0; }
.q-text b { font-size: 16px; letter-spacing: -.01em; }
.q-text small { font-size: 13px; opacity: .85; }
.q-tag { margin-left: auto; flex: none; font: 700 11px/1 inherit; letter-spacing: .04em; text-transform: uppercase; padding: 6px 8px; border-radius: 7px; background: rgba(0,0,0,.22); }
.q-alt { flex: none; width: 64px; display: grid; place-items: center; border-radius: 13px; background: var(--surface-2); border: 1px solid var(--border);
  font: 700 13px/1 inherit; }
.q-alt:hover { border-color: var(--accent); }

/* Subtitles */
.sub-group { border-top: 1px solid var(--border); }
.sub-group:first-of-type { border-top: 0; }
.sub-group summary { list-style: none; display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 12px 2px; cursor: pointer; font-weight: 600; }
.sub-group summary::-webkit-details-marker { display: none; }
.sub-group summary::after { content: ""; width: 8px; height: 8px; margin-left: 4px; border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted); transform: rotate(45deg); transition: transform .15s; }
.sub-group[open] summary::after { transform: rotate(-135deg); }
.sub-group summary .count { margin-left: auto; font-size: 12px; color: var(--muted); background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px; padding: 2px 9px; }
.sub-group .sub-list { padding: 0 0 14px; gap: 8px; }
.sub { display: flex; gap: 8px; }
.sub-main { flex: 1; min-width: 0; display: flex; align-items: center; gap: 12px; min-height: 52px; padding: 8px 12px; border-radius: 12px;
  background: var(--surface-2); border: 1px solid var(--border); }
.sub-main:hover, .sub-alt:hover { border-color: var(--accent); }
.sub-icon { width: 32px; height: 32px; flex: none; display: grid; place-items: center; border-radius: 9px; background: color-mix(in srgb, var(--accent) 22%, transparent); color: #cbbfff; }
.sub-icon svg { width: 18px; height: 18px; fill: currentColor; }
.sub-text { display: flex; flex-direction: column; min-width: 0; }
.sub-text b { font-size: 14px; }
.sub-text small { font-size: 12px; color: var(--muted); }
.sub-alt { flex: none; width: 64px; display: grid; place-items: center; border-radius: 12px; background: var(--surface-2); border: 1px solid var(--border); font: 700 12px/1 inherit; color: var(--muted); }

/* "Starting…" feedback */
a.busy { pointer-events: none; }
a.busy .q-icon svg, a.busy .sub-icon svg { display: none; }
a.busy .q-icon::after, a.busy .sub-icon::after { content: ""; width: 18px; height: 18px; border-radius: 50%;
  border: 2.5px solid currentColor; border-right-color: transparent; animation: spin .7s linear infinite; }
a.busy.q-alt, a.busy.sub-alt { opacity: .55; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { a.busy .q-icon::after, a.busy .sub-icon::after { animation-duration: 2s; } }

@media (max-width: 520px) {
  .hero { padding-top: 24px; gap: 14px; }
  .poster { width: 92px; }
  .q-tag { display: none; }
  .q-alt, .sub-alt { width: 56px; }
  .embed { width: 100%; justify-content: space-between; }
}
@media (max-width: 360px) {
  .ep-pick { flex-direction: column; }
}
