/* =========================================================================
   Grabarr — terminal theme (crimson on warm stone)
   Inspired by the ctrlTAB palette. Mono-first, sharp, dot-grid, red glow.
   Fonts: JetBrains Mono (everything) · Press Start 2P (brand mark)
   ========================================================================= */

:root, [data-theme="light"] {
  --bg:            #ffffff;
  --bg-tint:       #f8f9fa;
  --surface:       #ffffff;
  --surface-2:     #f8f9fa;
  --surface-3:     #e9ecef;
  --border:        rgba(0, 0, 0, .12);
  --border-strong: rgba(0, 0, 0, .24);
  --text:          #212529;
  --text-dim:      #495057;
  --text-faint:    #868e96;
  --accent:        #e2003d;
  --accent-strong: #ff1f57;
  --accent-contrast:#ffffff;
  --accent-soft:   rgba(226, 0, 61, .08);
  --accent-glow:   0 0 8px rgba(226, 0, 61, .35), 0 0 22px rgba(226, 0, 61, .10);
  --ok:   #16a34a;
  --err:  #f43f5e;
  --warn: #d97706;
  --neutral: #868e96;
  --dot:  rgba(0, 0, 0, .07);
  --shadow: 0 18px 44px -26px rgba(0, 0, 0, .30);
  color-scheme: light;
}

[data-theme="dark"] {
  --bg:            #1c1917;
  --bg-tint:       #231f1d;
  --surface:       #292524;
  --surface-2:     #231f1d;
  --surface-3:     #3f3a36;
  --border:        rgba(255, 255, 255, .10);
  --border-strong: rgba(255, 255, 255, .22);
  --text:          #fafaf9;
  --text-dim:      #a8a29e;
  --text-faint:    #78716c;
  --accent:        #e2003d;
  --accent-strong: #ff1f57;
  --accent-contrast:#ffffff;
  --accent-soft:   rgba(226, 0, 61, .16);
  --accent-glow:   0 0 8px rgba(226, 0, 61, .45), 0 0 24px rgba(226, 0, 61, .15);
  --ok:   #34d399;
  --err:  #fb7185;
  --warn: #fbbf24;
  --neutral: #78716c;
  --dot:  rgba(255, 255, 255, .04);
  --shadow: 0 18px 40px -22px rgba(0, 0, 0, .7);
  color-scheme: dark;
}

:root {
  --font-main: "JetBrains Mono", ui-monospace, "Cascadia Code", Consolas, monospace;
  --font-pixel: "Press Start 2P", var(--font-main);
  --radius: 3px;
  --maxw: 1440px;
}

/* ---- Base ---------------------------------------------------------------- */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }
html { scroll-behavior: smooth; }

body {
  min-height: 100vh;
  font-family: var(--font-main);
  font-size: 14px; line-height: 1.65;
  color: var(--text);
  background-color: var(--bg);
  background-image: radial-gradient(circle, var(--dot) 1px, transparent 1px);
  background-size: 28px 28px;
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  transition: background-color .25s ease, color .25s ease;
}

a { color: var(--accent); text-decoration: none; }
.muted { color: var(--text-dim); }
.error { color: var(--err); font-size: 12.5px; }
::selection { background: var(--accent); color: #fff; }

* { scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; }
*::-webkit-scrollbar { width: 11px; height: 11px; }
*::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 0; border: 3px solid var(--bg); }
:focus-visible { outline: 1px solid var(--accent); outline-offset: 2px; }

@keyframes cursor-blink { 0%, 100% { opacity: 1; } 50% { opacity: 0; } }

/* ---- Header -------------------------------------------------------------- */
header {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 24px;
  padding: 0 22px; height: 56px;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: saturate(140%) blur(16px);
  border-bottom: 1px solid var(--border);
  transition: background-color .25s ease, border-color .25s ease;
}
.brand {
  display: flex; align-items: center; gap: 11px;
  font-family: var(--font-pixel); font-size: .72rem; letter-spacing: .04em;
  color: var(--text); white-space: nowrap;
}
.brand-accent { color: var(--accent); }
.brand::after { content: "_"; color: var(--accent); font-family: var(--font-main); animation: cursor-blink .9s step-end infinite; margin-left: 2px; }
.brand-mark {
  position: relative; width: 26px; height: 26px;
  border-radius: var(--radius); background: var(--accent);
  box-shadow: var(--accent-glow); flex-shrink: 0;
}
.brand-mark::after {
  content: ""; position: absolute; top: 50%; left: 55%; transform: translate(-50%, -50%);
  border-style: solid; border-width: 5px 0 5px 8px;
  border-color: transparent transparent transparent #fff;
}

.tabs { display: flex; gap: 6px; flex: 1; align-items: center; height: 100%; }
.tab {
  font-family: var(--font-main); font-size: 11.5px; font-weight: 500;
  letter-spacing: .12em; text-transform: uppercase;
  color: var(--text-dim); background: transparent; border: 0; cursor: pointer;
  padding: 6px 4px; height: 100%; position: relative;
  display: inline-flex; align-items: center; gap: 4px; transition: color .15s;
}
.tab::before { content: "// "; color: var(--text-faint); transition: color .15s; }
.tab:hover { color: var(--text); }
.tab:hover::before { color: var(--accent); }
.tab.active { color: var(--accent); }
.tab.active::before { content: "> "; color: var(--accent); }
.tab.active::after {
  content: ""; position: absolute; left: 0; right: 0; bottom: -1px; height: 2px;
  background: var(--accent); box-shadow: var(--accent-glow);
}
.badge {
  min-width: 16px; padding: 0 5px; font-size: 10.5px; font-weight: 700;
  background: var(--accent); color: #fff; border-radius: 0;
}
.badge:empty { display: none; }

.user { display: flex; align-items: center; gap: 10px; }
.username { color: var(--text-dim); font-size: 12px; letter-spacing: .04em; }
.username:not(:empty)::before { content: "@"; color: var(--text-faint); }

/* ---- Buttons ------------------------------------------------------------- */
.btn {
  font-family: var(--font-main); font-size: 12px; font-weight: 500;
  letter-spacing: .08em; text-transform: uppercase;
  color: var(--text-dim); background: transparent;
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 8px 13px; cursor: pointer; transition: color .15s, border-color .15s, background .15s;
}
.btn:hover:not(:disabled) { color: var(--text); border-color: var(--border-strong); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: .4; cursor: default; }
.btn.small { padding: 6px 11px; font-size: 11px; }
.btn.tiny { padding: 4px 9px; font-size: 12px; letter-spacing: 0; text-transform: none; }

.btn.primary {
  position: relative; overflow: hidden; z-index: 0;
  color: var(--accent); border-color: var(--accent); font-weight: 700;
}
.btn.primary::after {
  content: ""; position: absolute; inset: 0; z-index: -1; background: var(--accent);
  transform: translateX(-101%); transition: transform .25s cubic-bezier(.4, 0, .2, 1);
}
.btn.primary:hover:not(:disabled) { color: #fff; box-shadow: var(--accent-glow); }
.btn.primary:hover:not(:disabled)::after { transform: translateX(0); }

.btn.danger { color: var(--err); border-color: color-mix(in srgb, var(--err) 45%, var(--border)); }
.btn.danger:hover:not(:disabled) { color: var(--err); border-color: var(--err); background: color-mix(in srgb, var(--err) 10%, transparent); }

.icon-btn {
  display: inline-grid; place-items: center; width: 34px; height: 34px;
  color: var(--text-dim); background: transparent;
  border: 1px solid var(--border); border-radius: var(--radius); cursor: pointer;
  transition: color .15s, border-color .15s;
}
.icon-btn:hover { color: var(--accent); border-color: var(--accent); }
[data-theme="dark"] .i-moon { display: none; }
[data-theme="light"] .i-sun { display: none; }

/* ---- Main / search ------------------------------------------------------- */
main { max-width: var(--maxw); margin: 0 auto; padding: 26px 22px 64px; }

.searchbar { display: flex; gap: 12px; margin-bottom: 26px; }
.search-field { position: relative; flex: 1; }
.search-ico { display: none; }
.search-field::before {
  content: ">"; position: absolute; left: 14px; top: 50%; transform: translateY(-50%);
  color: var(--accent); font-weight: 700; pointer-events: none;
}
.search-field input {
  width: 100%; font-family: var(--font-main); font-size: 13.5px;
  color: var(--text); background: var(--surface-2);
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 12px 14px 12px 32px; transition: border-color .15s, box-shadow .15s;
}
.search-field input::placeholder { color: var(--text-faint); }
.search-field input:focus { outline: none; border-color: var(--accent); box-shadow: var(--accent-glow); }
#sort {
  font-family: var(--font-main); font-size: 12px; text-transform: uppercase; letter-spacing: .06em;
  color: var(--text); background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 0 12px; cursor: pointer;
}

/* ---- Poster grid --------------------------------------------------------- */
.grid { display: grid; gap: 18px; grid-template-columns: repeat(auto-fill, minmax(156px, 1fr)); }
.card { cursor: pointer; animation: cardIn .4s ease both; }
.card:nth-child(1) { animation-delay: .02s; } .card:nth-child(2) { animation-delay: .05s; }
.card:nth-child(3) { animation-delay: .08s; } .card:nth-child(4) { animation-delay: .11s; }
.card:nth-child(5) { animation-delay: .14s; } .card:nth-child(6) { animation-delay: .17s; }
.card:nth-child(7) { animation-delay: .20s; } .card:nth-child(8) { animation-delay: .23s; }
.card:nth-child(9) { animation-delay: .26s; } .card:nth-child(10) { animation-delay: .29s; }
.card:nth-child(11) { animation-delay: .32s; } .card:nth-child(12) { animation-delay: .35s; }
@keyframes cardIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

.poster {
  position: relative; aspect-ratio: 2 / 3; overflow: hidden;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius);
  display: grid; place-items: center;
  transition: transform .18s ease, box-shadow .18s ease, border-color .18s ease;
}
.poster::after { content: "▚"; font-size: 30px; color: var(--text-faint); opacity: .35; }
.poster img { position: relative; width: 100%; height: 100%; object-fit: cover; }
.card:hover .poster { transform: translateY(-4px); border-color: var(--accent); box-shadow: var(--accent-glow); }
.card-title {
  margin-top: 10px; font-size: 12.5px; font-weight: 500; color: var(--text);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.card:hover .card-title { color: var(--accent); }
.card-sub { font-size: 11px; color: var(--text-faint); margin-top: 2px; letter-spacing: .03em; }

/* ---- Pager --------------------------------------------------------------- */
.pager { display: flex; align-items: center; justify-content: center; gap: 18px; margin-top: 34px; }
#pageinfo { font-size: 12px; color: var(--text-dim); letter-spacing: .04em; }

/* ---- Modal --------------------------------------------------------------- */
.modal-overlay {
  position: fixed; inset: 0; z-index: 60; display: none;
  align-items: flex-start; justify-content: center; padding: 46px 16px; overflow-y: auto;
  background: color-mix(in srgb, var(--bg) 50%, rgba(0, 0, 0, .6));
  backdrop-filter: blur(5px);
}
.modal {
  position: relative; width: 100%; max-width: 860px;
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--radius);
  padding: 26px; box-shadow: var(--shadow); animation: modalIn .25s ease both;
}
@keyframes modalIn { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }
.modal-close {
  position: absolute; top: 14px; right: 14px; width: 32px; height: 32px;
  display: grid; place-items: center; color: var(--text-dim); font-size: 12px;
  background: transparent; border: 1px solid var(--border); border-radius: var(--radius); cursor: pointer;
}
.modal-close:hover { color: var(--accent); border-color: var(--accent); }

.detail { display: flex; gap: 24px; }
.detail-poster { flex: 0 0 200px; }
.detail-poster img { width: 200px; border-radius: var(--radius); border: 1px solid var(--border); display: block; }
.detail-info { min-width: 0; }
.detail-info h2 { margin: 2px 0 10px; font-size: 21px; font-weight: 800; line-height: 1.2; }
.detail-info h2::before { content: "# "; color: var(--accent); }
.detail-info p { margin: 0 0 12px; font-size: 13px; color: var(--text-dim); }
#dlmsg { font-size: 12px; color: var(--text-dim); }

/* ---- Seasons / episodes -------------------------------------------------- */
.seasons { margin-top: 22px; border-top: 1px solid var(--border); padding-top: 16px; }
.season { margin-bottom: 16px; }
.season-head { display: flex; align-items: center; gap: 12px; margin-bottom: 8px; }
.season-head b { font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; }
.season-head b::before { content: "> "; color: var(--accent); }
.eps { list-style: none; }
.eps li {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 7px 12px; font-size: 12.5px; border: 1px solid transparent;
}
.eps li:nth-child(odd) { background: var(--surface-2); }
.eps li:hover { border-color: var(--border); }
.eps li span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--text-dim); }

/* ---- Downloads ----------------------------------------------------------- */
.dl-toolbar { display: flex; justify-content: flex-end; margin-bottom: 16px; }
.downloads { display: flex; flex-direction: column; gap: 10px; }
.dl {
  display: flex; align-items: center; gap: 16px;
  background: var(--surface); border: 1px solid var(--border);
  border-left: 3px solid var(--neutral); border-radius: var(--radius); padding: 13px 16px;
}
.dl.downloading { border-left-color: var(--accent); }
.dl.done { border-left-color: var(--ok); }
.dl.error { border-left-color: var(--err); }
.dl.canceled { border-left-color: var(--neutral); opacity: .65; }
.dl-main { flex: 1; min-width: 0; }
.dl-title { font-size: 13px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dl-bar { height: 6px; margin: 8px 0; background: var(--surface-3); border-radius: 0; overflow: hidden; }
.dl-fill { height: 100%; width: 0; background: var(--accent); transition: width .5s ease; }
.dl.done .dl-fill { background: var(--ok); }
.dl.error .dl-fill { background: var(--err); }
.dl.canceled .dl-fill { background: var(--neutral); }
.dl.downloading .dl-fill {
  background-color: var(--accent); box-shadow: var(--accent-glow);
  background-image: linear-gradient(110deg, transparent 30%, rgba(255, 255, 255, .35) 50%, transparent 70%);
  background-size: 220% 100%; animation: shimmer 1.3s linear infinite;
}
@keyframes shimmer { from { background-position: 220% 0; } to { background-position: -120% 0; } }
.dl-meta { font-size: 11px; color: var(--text-faint); margin-top: 2px; text-transform: uppercase; letter-spacing: .04em; }

/* ---- Login --------------------------------------------------------------- */
.login-body { display: grid; place-items: center; min-height: 100vh; padding: 20px; }
.login-toggle { position: fixed; top: 20px; right: 20px; }
.login-card {
  width: 350px; padding: 38px 32px; display: flex; flex-direction: column; gap: 13px;
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--radius);
  box-shadow: var(--shadow); animation: modalIn .35s ease both;
}
.login-brand { display: flex; justify-content: center; margin-bottom: 6px; }
.login-brand .brand-mark { width: 48px; height: 48px; }
.login-brand .brand-mark::after { border-width: 8px 0 8px 13px; }
.login-card h1 { text-align: center; font-size: 17px; font-weight: 800; letter-spacing: .04em; text-transform: uppercase; }
.login-sub { text-align: center; margin: -6px 0 8px; font-size: 12px; color: var(--text-faint); }
.login-sub::before { content: "// "; }
.login-card input {
  font-family: var(--font-main); font-size: 13.5px; color: var(--text);
  background: var(--bg-tint); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px;
}
.login-card input:focus { outline: none; border-color: var(--accent); box-shadow: var(--accent-glow); }
.login-card .btn { margin-top: 6px; padding: 12px; }
.login-card .error { text-align: center; min-height: 16px; }

/* ---- Theme switch: radial reveal (View Transitions API) ----------------- */
@keyframes theme-reveal {
  from { clip-path: circle(0 at var(--theme-x, 50%) var(--theme-y, 50%)); }
  to   { clip-path: circle(160vmax at var(--theme-x, 50%) var(--theme-y, 50%)); }
}
::view-transition-new(root) { animation: theme-reveal .5s cubic-bezier(.4, 0, .2, 1); }
::view-transition-old(root) { animation: none; z-index: -1; }

/* ---- Motion & responsive ------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  *, ::view-transition-new(root), ::view-transition-old(root) { animation: none !important; transition: none !important; }
}
@media (max-width: 680px) {
  header { flex-wrap: wrap; height: auto; padding: 10px 16px; gap: 14px; }
  .tabs { order: 3; flex-basis: 100%; }
  .detail { flex-direction: column; }
  .detail-poster, .detail-poster img { width: 150px; flex-basis: auto; }
}
