:root {
  --bg: #08090d; --panel: #10131c; --card: #141826; --line: #232941;
  --text: #e8eaf2; --dim: #9aa3b8; --accent: #7c5cff; --accent2: #22d3ee;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.5 "Segoe UI", system-ui, sans-serif; }
.hidden { display: none !important; }

.top { padding: 22px clamp(16px, 4vw, 40px) 14px; border-bottom: 1px solid var(--line); background: linear-gradient(180deg, #0d1017, var(--bg)); position: sticky; top: 0; z-index: 5; }
.brand h1 { margin: 0; font-size: 22px; letter-spacing: .3px; }
.brand h1 span { color: var(--accent); }
.sub { margin: 2px 0 0; color: var(--dim); font-size: 12.5px; }
.controls { display: flex; gap: 10px; margin-top: 14px; flex-wrap: wrap; }
.controls input[type="search"] { flex: 1 1 260px; min-width: 200px; }
.controls input, .controls select { background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; font-size: 14px; outline: none; }
.controls input:focus, .controls select:focus { border-color: var(--accent); }
.meta { margin-top: 10px; color: var(--dim); font-size: 12.5px; }

main { padding: 20px clamp(16px, 4vw, 40px) 60px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 16px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; overflow: hidden; cursor: pointer; transition: transform .12s ease, border-color .12s; }
.card:hover { transform: translateY(-3px); border-color: var(--accent); }
.card:focus { outline: 2px solid var(--accent); outline-offset: 2px; }
.reel button:focus-visible, .reels-bar button:focus-visible, .modal .panel button:focus-visible, .modal .panel a:focus-visible { outline: 2px solid var(--accent2); outline-offset: 3px; }
.thumb { position: relative; aspect-ratio: 2/3; background: linear-gradient(135deg, #1b2140, #10131c); overflow: hidden; }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; position: relative; z-index: 1; }
.thumb.noimg img { display: none; }
.thumb .ini { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: var(--accent); font-size: 42px; font-weight: 700; opacity: .8; }
.thumb.img-loaded .ini { display: none; }
.ep-tag { position: absolute; right: 8px; top: 8px; background: rgba(8,9,13,.82); border: 1px solid var(--line); padding: 2px 8px; border-radius: 999px; font-size: 11.5px; }
.prov-tag { position: absolute; left: 8px; top: 8px; background: var(--accent); color: #fff; padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 600; }
.card .info { padding: 10px 12px 12px; }
.card h3 { margin: 0 0 6px; font-size: 13.5px; line-height: 1.35; max-height: 2.7em; overflow: hidden; }
.chips { display: flex; flex-wrap: wrap; gap: 4px; }
.chip { background: #1c2136; color: var(--dim); border-radius: 6px; padding: 1px 7px; font-size: 10.5px; }

.empty { text-align: center; color: var(--dim); padding: 60px 0; }
.pager { display: flex; align-items: center; justify-content: center; gap: 14px; margin-top: 26px; }
.pager button { background: var(--panel); border: 1px solid var(--line); color: var(--text); border-radius: 10px; padding: 9px 16px; cursor: pointer; }
.pager button:disabled { opacity: .4; cursor: default; }
.pager button:not(:disabled):hover { border-color: var(--accent); }
#pageinfo { color: var(--dim); font-size: 13px; }

/* Recently watched / resume */
.history { margin-bottom: 24px; }
.history-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.history-head h3 { margin: 0; font-size: 15px; }
.history-head h3 small { color: var(--dim); font-weight: 400; font-size: 12px; margin-left: 6px; }
.history-head button { background: var(--panel); border: 1px solid var(--line); color: var(--dim); border-radius: 8px; padding: 5px 12px; font: inherit; font-size: 12px; cursor: pointer; }
.history-head button:hover { border-color: var(--accent); color: var(--text); }
.history-head button[data-armed="1"] { border-color: #ff6b6b; color: #ff8f8f; }
.history-row { display: flex; gap: 12px; overflow-x: auto; padding: 2px 2px 8px; scroll-snap-type: x proximity; scrollbar-width: thin; }
.hcard { flex: 0 0 150px; background: var(--card); border: 1px solid var(--line); border-radius: 14px; overflow: hidden; cursor: pointer; scroll-snap-align: start; transition: border-color .12s, transform .12s; }
.hcard:hover { border-color: var(--accent); transform: translateY(-2px); }
.hcard:focus { outline: 2px solid var(--accent); outline-offset: 2px; }
.hthumb { position: relative; aspect-ratio: 2/3; background: linear-gradient(135deg, #1b2140, #10131c); overflow: hidden; }
.hthumb img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; z-index: 1; }
.hthumb.noimg img { display: none; }
.hthumb .ini { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: var(--accent); font-size: 42px; font-weight: 700; opacity: .8; }
.hresume { position: absolute; left: 6px; bottom: 6px; z-index: 2; background: rgba(8, 9, 13, .88); border: 1px solid var(--line); color: #fff; border-radius: 999px; padding: 2px 8px; font-size: 10.5px; font-weight: 600; }
.hdel { position: absolute; right: 4px; top: 4px; z-index: 2; width: 20px; height: 20px; border-radius: 50%; background: rgba(8, 9, 13, .72); border: 1px solid var(--line); color: var(--dim); font-size: 10px; line-height: 1; cursor: pointer; opacity: 0; transition: opacity .12s, color .12s; }
.hcard:hover .hdel, .hcard:focus-within .hdel, .hdel:focus { opacity: 1; }
.hdel:hover { color: #fff; border-color: var(--accent); }
.hinfo { padding: 10px 12px 12px; }
.hinfo h4 { margin: 0 0 4px; font-size: 13.5px; font-weight: 600; line-height: 1.35; max-height: 2.7em; overflow: hidden; }
.hinfo span { color: var(--dim); font-size: 11px; }

.modal { position: fixed; inset: 0; z-index: 20; display: flex; }
.modal .backdrop { position: absolute; inset: 0; background: rgba(4, 5, 9, .78); }
.modal .panel { position: relative; margin: auto; width: min(860px, 94vw); max-height: 92vh; overflow: auto; background: var(--panel); border: 1px solid var(--line); border-radius: 18px; padding: 22px; }
.modal .close { position: absolute; right: 14px; top: 12px; background: none; border: none; color: var(--dim); font-size: 18px; cursor: pointer; }
.head { display: flex; gap: 18px; }
.head img { width: 130px; aspect-ratio: 2/3; object-fit: cover; border-radius: 12px; background: #1b2140; flex: none; }
.head-info h2 { margin: 0 0 8px; font-size: 19px; }
.head-info p { color: var(--dim); font-size: 13.5px; max-height: 130px; overflow: auto; }
.badges { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.badge { border: 1px solid var(--line); background: #171c2e; border-radius: 999px; padding: 3px 10px; font-size: 11.5px; color: var(--text); }
.badge.acc { background: var(--accent); border-color: var(--accent); color: #fff; }

h3 { margin: 20px 0 10px; font-size: 15px; }
.episodes { display: grid; grid-template-columns: repeat(auto-fill, minmax(64px, 1fr)); gap: 8px; }
.episodes button { background: var(--card); border: 1px solid var(--line); color: var(--text); border-radius: 9px; padding: 8px 0; cursor: pointer; font-size: 13px; }
.episodes button:hover { border-color: var(--accent); }
.episodes button.active { background: var(--accent); border-color: var(--accent); }
.episodes button.loading { opacity: .5; pointer-events: none; }

.player-box { margin: 16px 0 4px; background: #000; border: 1px solid var(--line); border-radius: 14px; overflow: hidden; }
.player-box video { width: 100%; max-height: 70vh; display: block; background: #000; aspect-ratio: 9/16; margin: 0 auto; object-fit: contain; }
.player-bar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding: 10px; background: #0c0f18; }
.player-bar .qlabel { color: var(--dim); font-size: 12px; margin-right: 2px; }
.player-bar button { background: var(--card); border: 1px solid var(--line); color: var(--text); border-radius: 8px; padding: 5px 11px; font-size: 12px; cursor: pointer; }
.player-bar button.active { background: var(--accent); border-color: var(--accent); }
.player-bar a { color: var(--accent2); font-size: 12px; }
.player-bar .pnote { color: var(--accent2); font-size: 12px; }
.err { color: #ff8b8b; padding: 12px 14px; font-size: 13.5px; }
.spin { display: inline-block; width: 14px; height: 14px; border: 2px solid var(--dim); border-top-color: var(--accent); border-radius: 50%; animation: r 0.8s linear infinite; vertical-align: -2px; margin-right: 8px; }
@keyframes r { to { transform: rotate(360deg); } }

/* ---------------------------------------------------------------------------
   Polish: fonts, glass header, badges, hover-play, skeletons, scrollbar
--------------------------------------------------------------------------- */
body { font-family: 'DM Sans', ui-sans-serif, system-ui, 'Segoe UI', sans-serif; }
h1, h2, h3 { font-family: 'Space Grotesk', 'DM Sans', sans-serif; letter-spacing: .2px; }

.top { background: rgba(10, 12, 18, .72); backdrop-filter: blur(14px) saturate(1.3); -webkit-backdrop-filter: blur(14px) saturate(1.3); }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: #232941; border-radius: 8px; }
::-webkit-scrollbar-thumb:hover { background: #2e3660; }
::-webkit-scrollbar-track { background: transparent; }

.viewtoggle { display: flex; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.viewtoggle button { background: none; border: none; color: var(--dim); padding: 10px 14px; cursor: pointer; font-size: 13.5px; font-family: inherit; }
.viewtoggle button.active { background: var(--accent); color: #fff; }

.card { box-shadow: 0 4px 18px rgba(0, 0, 0, .35); }
.card:hover { box-shadow: 0 14px 34px rgba(0, 0, 0, .5); }
.rate-tag { position: absolute; left: 8px; bottom: 8px; z-index: 2; background: rgba(8, 9, 13, .82); border: 1px solid var(--line); padding: 2px 8px; border-radius: 999px; font-size: 11px; color: #ffd75e; }
.play-ov { position: absolute; inset: 0; z-index: 2; display: flex; align-items: center; justify-content: center; background: rgba(6, 8, 14, .35); opacity: 0; transition: opacity .15s; font-size: 30px; color: #fff; text-shadow: 0 2px 12px rgba(0, 0, 0, .6); pointer-events: none; }
.card:hover .play-ov, .card:focus-visible .play-ov { opacity: 1; }

.skel { border-radius: 14px; border: 1px solid var(--line); background: var(--card); overflow: hidden; }
.skel .sk-img { aspect-ratio: 2 / 3; background: linear-gradient(100deg, #141826 30%, #1d2440 50%, #141826 70%); background-size: 200% 100%; animation: sh 1.1s infinite linear; }
.skel .sk-line { height: 12px; margin: 10px 12px; border-radius: 6px; background: linear-gradient(100deg, #141826 30%, #1d2440 50%, #141826 70%); background-size: 200% 100%; animation: sh 1.1s infinite linear; }
.skel .sk-line.short { width: 60%; }
@keyframes sh { to { background-position: -200% 0; } }

/* ---------------------------------------------------------------------------
   Reels mode: full-screen vertical snap feed
--------------------------------------------------------------------------- */
body.reels-mode { overflow: hidden; }
body.reels-mode header.top, body.reels-mode main { display: none; }
.reels-root { position: fixed; inset: 0; z-index: 15; background: #000; }
.reels-bar { position: absolute; top: 0; left: 0; right: 0; z-index: 6; display: flex; align-items: center; gap: 10px; padding: 12px 16px; background: linear-gradient(180deg, rgba(0, 0, 0, .65), transparent); }
.reels-bar button { background: rgba(20, 24, 38, .75); color: var(--text); border: 1px solid var(--line); border-radius: 999px; padding: 8px 14px; cursor: pointer; font-size: 13px; font-family: inherit; backdrop-filter: blur(8px); }
.reels-bar button:hover { border-color: var(--accent); }
.reels-title { flex: 1; text-align: center; color: var(--dim); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.reels-feed { height: 100%; overflow-y: scroll; scroll-snap-type: y mandatory; scrollbar-width: none; }
.reels-feed::-webkit-scrollbar { display: none; }
.reel { position: relative; height: 100%; scroll-snap-align: start; scroll-snap-stop: always; overflow: hidden; background: #0a0c12; }
.reel-bg { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; filter: saturate(1.05); }
.reel-shade { position: absolute; inset: 0; background: linear-gradient(180deg, rgba(0, 0, 0, .55) 0%, transparent 22%, transparent 55%, rgba(0, 0, 0, .88) 100%); }
.reel-slot { position: absolute; inset: 0; z-index: 1; cursor: pointer; }
.reel-slot video { width: 100%; height: 100%; object-fit: contain; background: #000; }
.reel-flash { position: absolute; inset: 0; z-index: 2; display: flex; align-items: center; justify-content: center; font-size: 64px; color: rgba(255, 255, 255, .85); pointer-events: none; opacity: 0; }
.reel-flash.show { animation: flash .6s ease-out; }
@keyframes flash { 0% { opacity: .9; transform: scale(.8); } 100% { opacity: 0; transform: scale(1.15); } }
.reel-top { position: absolute; top: 64px; left: 14px; right: 14px; z-index: 3; display: flex; gap: 8px; }
.reel-top .prov-tag, .reel-top .ep-tag { position: static; }
.reel-side { position: absolute; right: 12px; bottom: 130px; z-index: 3; display: flex; flex-direction: column; gap: 10px; }
.rbtn { width: 44px; height: 44px; border-radius: 50%; display: flex; align-items: center; justify-content: center; background: rgba(20, 24, 38, .7); border: 1px solid var(--line); color: var(--text); font-size: 18px; cursor: pointer; text-decoration: none; backdrop-filter: blur(6px); }
.rbtn:hover { border-color: var(--accent); }
.reel-bottom { position: absolute; left: 0; right: 74px; bottom: 0; z-index: 3; padding: 18px 16px 26px; display: flex; flex-direction: column; gap: 8px; }
.reel-bottom h3 { margin: 0; font-size: 19px; text-shadow: 0 2px 10px rgba(0, 0, 0, .6); }
.reel-desc { margin: 0; color: #cfd5e6; font-size: 13px; line-height: 1.45; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; max-width: 560px; }
.reel-play { align-self: flex-start; margin-top: 4px; background: var(--accent); border: none; color: #fff; font-weight: 600; font-family: inherit; padding: 10px 18px; border-radius: 999px; cursor: pointer; font-size: 14px; box-shadow: 0 6px 20px rgba(124, 92, 255, .45); }
.reel-play:active { transform: scale(.97); }
.reel-prog { position: absolute; left: 0; right: 0; bottom: 0; height: 3px; background: rgba(255, 255, 255, .14); z-index: 4; }
.reel-prog i { display: block; height: 100%; width: 0%; background: var(--accent); }
.reel-note { position: absolute; inset: 0; z-index: 2; display: flex; align-items: center; justify-content: center; color: var(--dim); font-size: 14px; text-align: center; padding: 20px; background: rgba(8, 9, 13, .45); }
.reel-err { height: 100%; display: flex; align-items: center; justify-content: center; color: var(--dim); }
@media (min-width: 700px) {
  .reel { max-width: 460px; margin: 0 auto; border-left: 1px solid #16192a; border-right: 1px solid #16192a; }
}
