:root {
  color-scheme: dark;
  --bg: #080910;
  --panel: #13141d;
  --panel-2: #1b1c28;
  --line: #2a2c3a;
  --text: #f8f6ff;
  --muted: #a6a6b8;
  --accent: #ad9cff;
  --accent-2: #7d62ff;
  --success: #9de2b7;
  font-family: Inter, "Segoe UI", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { width: 100%; max-width: 100%; overflow-x: hidden; }
body {
  margin: 0;
  min-height: 100vh;
  background: radial-gradient(circle at 82% -8%, #302555 0, transparent 34%), var(--bg);
  color: var(--text);
}
body.player-open { overflow: hidden; }
button, input { font: inherit; }
button { min-height: 44px; cursor: pointer; -webkit-tap-highlight-color: transparent; touch-action: manipulation; }

header {
  position: sticky;
  top: 0;
  z-index: 10;
  height: 76px;
  padding: 0 max(22px, calc((100vw - 1180px) / 2));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  border-bottom: 1px solid #ffffff0c;
  background: #090a10dc;
  backdrop-filter: blur(18px);
}
header > div { display: flex; align-items: center; gap: 10px; white-space: nowrap; min-width: 0; }
.logo {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 12px;
  background: linear-gradient(145deg, var(--accent), var(--accent-2));
  color: #171126;
  font-weight: 900;
  box-shadow: 0 8px 24px #795cff35;
}
header small { padding-left: 10px; border-left: 1px solid var(--line); color: var(--muted); font-size: 12px; }

form { display: flex; gap: 8px; width: 100%; max-width: 420px; }
.search-field { position: relative; flex: 1; min-width: 0; }
input {
  width: 100%;
  min-width: 0;
  height: 46px;
  padding: 11px 43px 11px 15px;
  border: 1px solid var(--line);
  border-radius: 14px;
  outline: none;
  background: var(--panel);
  color: var(--text);
}
input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px #aa98ff1c; }
#clear-search {
  position: absolute;
  top: 3px;
  right: 3px;
  min-width: 40px;
  min-height: 40px;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 20px;
}
#clear-search:disabled { visibility: hidden; }
button {
  padding: 10px 15px;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: var(--panel-2);
  color: var(--text);
}
button:hover, button:focus-visible { border-color: #7669a8; outline: none; }
.search-submit, .primary { min-width: 68px; border-color: transparent; background: var(--accent); color: #171126; font-weight: 800; }

main { max-width: 1180px; margin: auto; padding: 34px 22px 64px; }
.hero {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 34px;
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: 26px;
  background: linear-gradient(120deg, #1c192b, #11131b);
}
.eyebrow { margin: 0; color: var(--accent); font-size: 12px; font-weight: 800; letter-spacing: .14em; }
.hero h1 { margin: 5px 0; font-size: clamp(28px, 5vw, 52px); }
.hero p { margin: 8px 0; color: var(--muted); }
.health { min-width: 170px; padding: 12px 16px; border-radius: 14px; background: #101219; color: var(--success); }
.section-title { display: flex; align-items: end; justify-content: space-between; margin-bottom: 14px; }
.section-title h2 { margin: 0; }
.section-title span { color: var(--muted); font-size: 13px; }

.catalog { display: grid; grid-template-columns: repeat(auto-fill, minmax(155px, 1fr)); gap: 18px; min-width: 0; }
.anime-card { width: 100%; min-width: 0; max-width: 100%; padding: 0; overflow: hidden; border: 0; background: transparent; text-align: left; }
.anime-card:active { transform: scale(.98); }
.poster { position: relative; min-width: 0; aspect-ratio: 3 / 4; overflow: hidden; border: 1px solid var(--line); border-radius: 18px; background: var(--panel); }
.poster::after { position: absolute; inset: 0; content: ""; background: linear-gradient(180deg, transparent 60%, #07080b9c); pointer-events: none; }
.poster img { display: block; width: 100%; max-width: 100%; height: 100%; min-width: 0; object-fit: cover; transition: transform .25s ease; }
.anime-card:hover .poster img { transform: scale(1.025); }
.poster span { position: absolute; z-index: 1; right: 8px; bottom: 8px; left: 8px; padding: 7px 9px; overflow: hidden; border-radius: 9px; background: #080912db; font-size: 11px; text-overflow: ellipsis; white-space: nowrap; }
.anime-card h3 { width: 100%; margin: 9px 3px; overflow: hidden; font-size: 14px; text-overflow: ellipsis; white-space: nowrap; }
.skeleton { height: 260px; border-radius: 18px; background: linear-gradient(90deg, var(--panel), #242532, var(--panel)); background-size: 200%; animation: shine 1.2s infinite; }
@keyframes shine { to { background-position: -200%; } }
.pager { display: flex; align-items: center; justify-content: center; gap: 14px; margin: 32px; }
.pager button:disabled { cursor: default; opacity: .35; }
.empty { grid-column: 1 / -1; padding: 60px; color: var(--muted); text-align: center; }

dialog {
  width: min(920px, calc(100% - 24px));
  max-height: calc(100dvh - 30px);
  padding: 0 25px 25px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 25px;
  background: #101119;
  color: var(--text);
  box-shadow: 0 28px 100px #000c;
}
dialog::backdrop { background: #030409d6; backdrop-filter: blur(7px); }
.dialog-bar { position: sticky; top: 0; z-index: 2; display: flex; align-items: center; justify-content: space-between; min-height: 64px; background: #101119f4; backdrop-filter: blur(14px); color: var(--muted); font-size: 13px; }
.icon-button { display: grid; place-items: center; width: 44px; min-width: 44px; height: 44px; padding: 0; font-size: 26px; line-height: 1; }
.detail-head { display: grid; grid-template-columns: 160px 1fr; gap: 22px; margin: 10px 0 24px; }
.detail-head img { width: 100%; aspect-ratio: 3 / 4; object-fit: cover; border-radius: 18px; background: var(--panel); }
.detail-head h2 { margin: 0 0 8px; font-size: 28px; }
.detail-head p { margin: 7px 0; color: var(--muted); line-height: 1.65; }
.line-tabs, .episodes, .source-buttons { display: flex; flex-wrap: wrap; gap: 9px; }
.line-tabs button, .source-buttons button { border-radius: 999px; }
.line-tabs button.active, .source-buttons button.active { border-color: transparent; background: var(--accent); color: #171126; font-weight: 800; }
.episodes { display: grid; grid-template-columns: repeat(auto-fill, minmax(88px, 1fr)); margin-top: 16px; }
.episodes button { min-width: 0; }
.episodes button:active { background: var(--accent); color: #171126; }

.player-dialog { width: min(1060px, calc(100% - 16px)); padding: 18px; overflow: auto; }
.player-top { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 13px; }
.player-heading { min-width: 0; display: grid; gap: 3px; }
.player-heading span { color: var(--accent); font-size: 11px; font-weight: 800; letter-spacing: .12em; }
.player-heading strong { overflow: hidden; font-size: 16px; text-overflow: ellipsis; white-space: nowrap; }
.player-actions { display: flex; gap: 8px; flex: 0 0 auto; }
.tool-button { display: flex; align-items: center; gap: 7px; min-width: 86px; padding: 8px 13px; }
.tool-button span { font-size: 20px; }
.tool-button b { font-size: 13px; }
.video-wrap { position: relative; aspect-ratio: 16 / 9; overflow: hidden; border: 1px solid #23242f; border-radius: 17px; background: #000; }
.video-wrap video { display: block; width: 100%; height: 100%; background: #000; object-fit: contain; }
#video-message { position: absolute; inset: 0; display: none; place-items: center; padding: 28px; background: #07080dea; text-align: center; }
.message-card { display: grid; place-items: center; max-width: 520px; }
.message-card p { margin: 13px 0; color: #e4e1ec; line-height: 1.55; }
.loader { width: 28px; height: 28px; border: 3px solid #ffffff26; border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
#retry-source { display: none; border-color: #7969bb; color: var(--accent); }
.source-panel { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-top: 13px; padding: 13px 14px; border: 1px solid var(--line); border-radius: 15px; background: #0d0e15; }
.source-panel > div:first-child { display: grid; gap: 4px; flex: 0 0 auto; }
.source-panel span { font-size: 13px; font-weight: 750; }
.source-panel small { color: var(--muted); font-size: 11px; }
.source-buttons { justify-content: flex-end; }
.source-buttons button { min-height: 38px; padding: 7px 13px; font-size: 13px; }
details { margin-top: 12px; border: 1px solid var(--line); border-radius: 14px; background: #0b0c12; }
summary { min-height: 44px; padding: 13px 15px; cursor: pointer; color: var(--muted); font-size: 13px; }
pre { margin: 0; padding: 0 15px 15px; overflow: auto; color: #bdb7d8; font-size: 12px; white-space: pre-wrap; word-break: break-word; }
#toast { position: fixed; z-index: 100; bottom: max(22px, env(safe-area-inset-bottom)); left: 50%; max-width: calc(100% - 32px); padding: 11px 16px; border: 1px solid #ffffff1b; border-radius: 999px; background: #242331f2; box-shadow: 0 12px 36px #0008; opacity: 0; pointer-events: none; transform: translate(-50%, 14px); transition: .2s ease; }
#toast.show { opacity: 1; transform: translate(-50%, 0); }
body.busy { cursor: progress; }
body.busy button:not(#close-player):not([data-close]) { pointer-events: none; }

.player-dialog:fullscreen { width: 100vw; height: 100vh; max-width: none; max-height: none; padding: 0; border: 0; border-radius: 0; background: #000; }
.player-dialog:fullscreen .player-top { position: absolute; z-index: 4; top: env(safe-area-inset-top); right: 0; left: 0; margin: 0; padding: 12px 16px; background: linear-gradient(#000c, transparent); }
.player-dialog:fullscreen .video-wrap { width: 100%; height: 100%; aspect-ratio: auto; border: 0; border-radius: 0; }
.player-dialog:fullscreen .source-panel, .player-dialog:fullscreen details { display: none; }
.player-dialog.theater-mode { position: fixed; inset: 0; width: 100dvw; height: 100dvh; max-width: none; max-height: none; margin: 0; padding: 0; overflow: hidden; border: 0; border-radius: 0; background: #000; }
.player-dialog.theater-mode .player-top { position: absolute; z-index: 4; top: env(safe-area-inset-top); right: env(safe-area-inset-right); left: env(safe-area-inset-left); margin: 0; padding: 12px 16px; background: linear-gradient(#000c, transparent); }
.player-dialog.theater-mode .video-wrap { width: 100%; height: 100%; aspect-ratio: auto; border: 0; border-radius: 0; }
.player-dialog.theater-mode .source-panel, .player-dialog.theater-mode details { display: none; }

@media (max-width: 650px) {
  header { height: auto; padding: 12px 14px 14px; align-items: stretch; flex-direction: column; gap: 10px; }
  header small { display: none; }
  form { max-width: none; }
  main { padding: 18px 13px 52px; }
  .hero { display: block; margin-bottom: 28px; padding: 20px; border-radius: 21px; }
  .hero h1 { font-size: 29px; }
  .hero p { font-size: 13px; line-height: 1.5; }
  .health { margin-top: 16px; font-size: 13px; }
  .catalog { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
  .poster { border-radius: 13px; }
  .anime-card h3 { margin-right: 0; margin-left: 0; font-size: 12px; }
  .skeleton { height: auto; aspect-ratio: 3 / 4; }
  dialog { width: 100%; max-height: calc(100dvh - 10px); margin-bottom: 0; padding: 0 15px 18px; border-radius: 23px 23px 0 0; }
  .detail-head { grid-template-columns: 102px 1fr; gap: 14px; margin-top: 4px; }
  .detail-head h2 { font-size: 20px; }
  .detail-head p { max-height: 112px; overflow: auto; font-size: 13px; }
  .episodes { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .player-dialog { width: 100%; padding: 10px; }
  .player-heading strong { max-width: 53vw; }
  .tool-button { min-width: 48px; padding: 8px 11px; }
  .tool-button b { display: none; }
  .video-wrap { border-radius: 13px; }
  .source-panel { align-items: stretch; flex-direction: column; gap: 10px; }
  .source-buttons { justify-content: flex-start; overflow-x: auto; flex-wrap: nowrap; padding-bottom: 2px; }
  .source-buttons button { flex: 0 0 auto; }
  .empty { padding: 45px 10px; }
}

@media (orientation: landscape) and (max-height: 650px) {
  .player-dialog[open] { width: 100dvw; height: 100dvh; max-width: none; max-height: none; margin: 0; padding: 0; overflow: hidden; border: 0; border-radius: 0; background: #000; }
  .player-dialog[open] .player-top { position: absolute; z-index: 4; top: env(safe-area-inset-top); right: env(safe-area-inset-right); left: env(safe-area-inset-left); margin: 0; padding: 10px 14px; background: linear-gradient(#000c, transparent); }
  .player-dialog[open] .video-wrap { width: 100%; height: 100%; aspect-ratio: auto; border: 0; border-radius: 0; }
  .player-dialog[open] .source-panel, .player-dialog[open] details { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
