:root {
  --bg: #16181c;
  --bg-2: #1c1f24;
  --bg-3: #24282e;
  --line: #2e333a;
  --text: #e8eaed;
  --muted: #9aa3ad;
  --dim: #6b7480;
  --accent: #e5a00d;
  --accent-ink: #1a1300;
  --danger: #ef4444;
  --ok: #22c55e;
  --radius: 8px;
  --topbar-h: 60px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; }
button, input, select { font: inherit; color: inherit; }

/* ------------------------------------------------------------------ boot -- */

.boot { display: grid; place-items: center; min-height: 100vh; }

.spinner {
  width: 34px; height: 34px;
  border: 3px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ------------------------------------------------------------------ gate -- */

.gate { display: grid; place-items: center; min-height: 100vh; padding: 24px; }

.gate-card {
  width: min(420px, 100%);
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 40px 32px;
  text-align: center;
}
.gate-icon { font-size: 44px; line-height: 1; }
.gate-card h1 { margin: 14px 0 8px; font-size: 26px; letter-spacing: -.02em; }
.gate-card p { margin: 0 0 24px; color: var(--muted); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg-3);
  cursor: pointer;
  text-decoration: none;
  transition: background .15s, border-color .15s, transform .05s;
  white-space: nowrap;
}
.btn:hover { background: #2c3138; border-color: #3d444d; }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
.btn-primary:hover { background: #f0ae23; border-color: #f0ae23; }
.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn-danger { color: #fca5a5; }
.btn-danger:hover { background: #3a2020; border-color: #5b2b2b; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ---------------------------------------------------------------- topbar -- */

.topbar {
  position: sticky; top: 0; z-index: 40;
  display: flex; align-items: center; flex-wrap: wrap;
  gap: 10px 20px;
  min-height: var(--topbar-h);
  padding: 10px 20px;
  background: rgba(22, 24, 28, .92);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}

.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; letter-spacing: -.01em; flex: none; }
.brand-mark { font-size: 20px; }

/* min-width:0 is what lets this shrink inside the flex row instead of being
   squeezed to zero and taking the library tabs off-screen with it. */
.libnav { display: flex; gap: 2px; overflow-x: auto; scrollbar-width: none; flex: 1 1 auto; min-width: 0; }
.libnav::-webkit-scrollbar { display: none; }

.libnav button {
  padding: 7px 14px;
  border: 0; border-radius: 999px;
  background: transparent; color: var(--muted);
  cursor: pointer; white-space: nowrap;
  transition: background .15s, color .15s;
}
.libnav button:hover { color: var(--text); background: var(--bg-3); }
.libnav button.on { background: var(--bg-3); color: var(--text); font-weight: 600; }
.libnav .count { color: var(--dim); font-weight: 400; margin-left: 5px; font-size: 12px; }

.topbar-right { display: flex; align-items: center; gap: 10px; flex: none; margin-left: auto; }

/* Below this width the three controls plus the tab strip cannot share one row,
   so the tabs drop to a full-width second row instead of collapsing away. */
@media (max-width: 900px) {
  .libnav { order: 3; flex: 1 0 100%; }
  .topbar-right { flex: 1 1 auto; }
  .search { flex: 1 1 auto; min-width: 0; }
  .search input, .search input:focus { width: 100%; }
}

.search { position: relative; }
.search svg {
  position: absolute; left: 10px; top: 50%; transform: translateY(-50%);
  width: 15px; height: 15px; fill: none; stroke: var(--dim); stroke-width: 2;
  stroke-linecap: round; pointer-events: none;
}
.search input {
  width: 200px;
  padding: 8px 12px 8px 32px;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  outline: none;
  transition: width .2s, border-color .15s;
}
.search input:focus { width: 260px; border-color: #454c56; }

.sort {
  padding: 8px 10px;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  cursor: pointer;
}

.usermenu { position: relative; }
.avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--bg-3); border: 1px solid var(--line);
  display: grid; place-items: center;
  cursor: pointer; overflow: hidden; font-size: 13px; font-weight: 600;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }

.menu {
  position: absolute; right: 0; top: 40px;
  min-width: 190px;
  background: var(--bg-2); border: 1px solid var(--line);
  border-radius: 10px; padding: 6px;
  box-shadow: 0 12px 32px rgba(0,0,0,.5);
}
.menu-email { padding: 8px 10px; color: var(--dim); font-size: 12px; border-bottom: 1px solid var(--line); margin-bottom: 4px; word-break: break-all; }
.menu button {
  display: block; width: 100%; text-align: left;
  padding: 8px 10px; border: 0; border-radius: 6px;
  background: transparent; cursor: pointer;
}
.menu button:hover { background: var(--bg-3); }

/* ------------------------------------------------------------------ grid -- */

main { padding: 22px 20px 60px; }
@media (max-width: 600px) { main { padding: 16px 14px 50px; } }

.meta-line { color: var(--dim); font-size: 13px; margin-bottom: 16px; }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 20px 16px;
}
@media (max-width: 420px) { .grid { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 16px 12px; } }

.card { cursor: pointer; border: 0; background: none; padding: 0; text-align: left; }

.poster {
  position: relative;
  aspect-ratio: 2 / 3;
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--bg-3);
  transition: transform .18s ease, box-shadow .18s ease;
}
.card:hover .poster { transform: translateY(-4px); box-shadow: 0 14px 28px rgba(0,0,0,.55); }
.poster img { width: 100%; height: 100%; object-fit: cover; display: block; }
.poster .ph { display: grid; place-items: center; height: 100%; color: var(--dim); font-size: 28px; }

.badge {
  position: absolute; right: 6px; top: 6px;
  padding: 3px 7px; border-radius: 5px;
  background: rgba(0,0,0,.75); backdrop-filter: blur(4px);
  font-size: 11px; font-weight: 600;
}
.badge-eps { left: 6px; right: auto; background: rgba(229,160,13,.9); color: var(--accent-ink); }

.card-title { margin-top: 8px; font-size: 13px; line-height: 1.35; }
.card-sub { color: var(--dim); font-size: 12px; }

.empty { padding: 80px 0; text-align: center; color: var(--muted); }

.more { display: grid; place-items: center; padding: 30px 0; }

/* --------------------------------------------------------------- detail -- */

.sheet-backdrop {
  position: fixed; inset: 0; z-index: 60;
  background: rgba(0,0,0,.72);
  backdrop-filter: blur(3px);
  overflow-y: auto;
  padding: 40px 20px;
}
@media (max-width: 720px) { .sheet-backdrop { padding: 0; } }

.sheet {
  max-width: 900px; margin: 0 auto;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 14px;
  overflow: hidden;
}

.hero { position: relative; }
.hero-art { height: 240px; background-size: cover; background-position: center 22%; background-color: var(--bg-3); }
.hero-art::after {
  content: ''; position: absolute; inset: 0;
  background: linear-gradient(to bottom, rgba(28,31,36,.25) 0%, rgba(28,31,36,.85) 65%, var(--bg-2) 100%);
}
.hero-close {
  position: absolute; right: 12px; top: 12px; z-index: 2;
  width: 34px; height: 34px; border-radius: 50%;
  background: rgba(0,0,0,.6); border: 0; color: #fff;
  font-size: 20px; line-height: 1; cursor: pointer;
}
.hero-close:hover { background: rgba(0,0,0,.85); }

.hero-body { position: relative; z-index: 1; display: flex; gap: 22px; padding: 0 26px 22px; margin-top: -110px; }
.hero-poster { width: 150px; flex: none; border-radius: var(--radius); overflow: hidden; box-shadow: 0 10px 26px rgba(0,0,0,.55); background: var(--bg-3); aspect-ratio: 2/3; }
.hero-poster img { width: 100%; height: 100%; object-fit: cover; display: block; }
.hero-info { flex: 1; min-width: 0; padding-top: 92px; }
.hero-info h2 { margin: 0 0 6px; font-size: 26px; letter-spacing: -.02em; }
.facts { display: flex; flex-wrap: wrap; gap: 8px; color: var(--muted); font-size: 13px; margin-bottom: 12px; align-items: center; }
.facts .dot { color: var(--dim); }
.pill { padding: 2px 8px; border: 1px solid var(--line); border-radius: 999px; font-size: 12px; }
.overview { color: var(--muted); font-size: 14px; margin: 0 0 14px; }

@media (max-width: 720px) {
  .hero-body { flex-direction: column; margin-top: -70px; padding: 0 18px 18px; }
  .hero-poster { width: 110px; }
  .hero-info { padding-top: 0; }
}

.sheet-section { padding: 0 26px 26px; }
@media (max-width: 720px) { .sheet-section { padding: 0 18px 20px; } }

.season { border: 1px solid var(--line); border-radius: 10px; margin-bottom: 10px; overflow: hidden; }
.season-head {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 12px 14px; border: 0; background: var(--bg-3); cursor: pointer; text-align: left;
}
.season-head:hover { background: #2c3138; }
.season-head .chev { transition: transform .18s; color: var(--dim); }
.season.open .chev { transform: rotate(90deg); }
.season-head .grow { flex: 1; font-weight: 600; }
.season-head .sub { color: var(--dim); font-size: 12px; font-weight: 400; }

.season-body { display: none; }
.season.open .season-body { display: block; }

.file-row {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 14px;
  border-top: 1px solid var(--line);
}
.file-row:hover { background: rgba(255,255,255,.02); }
.file-num { width: 42px; flex: none; color: var(--dim); font-variant-numeric: tabular-nums; font-size: 13px; }
.file-main { flex: 1; min-width: 0; }
.file-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 14px; }
.file-meta { color: var(--dim); font-size: 12px; margin-top: 2px; }

.toolbar { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }

.toast {
  position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%);
  z-index: 90;
  background: var(--bg-3); border: 1px solid var(--line);
  padding: 10px 16px; border-radius: 999px;
  box-shadow: 0 10px 30px rgba(0,0,0,.5);
}

/* ----------------------------------------------------------------- admin -- */

/* Rendered straight into #app, so it carries its own page padding — there is
   no <main> wrapper on this view. */
.admin { max-width: 980px; margin: 0 auto; padding: 24px 20px 60px; }
@media (max-width: 600px) { .admin { padding: 16px 14px 50px; } }
.admin h2 { font-size: 20px; margin: 28px 0 12px; }
.admin h2:first-child { margin-top: 0; }

/* Tables scroll inside the panel on narrow screens rather than forcing the
   whole page to scroll sideways. */
.panel { background: var(--bg-2); border: 1px solid var(--line); border-radius: 12px; overflow-x: auto; }
.panel > table { min-width: 520px; }

table { width: 100%; border-collapse: collapse; }
th, td { padding: 11px 14px; text-align: left; border-bottom: 1px solid var(--line); font-size: 14px; }
th { color: var(--dim); font-weight: 500; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
tbody tr:last-child td { border-bottom: 0; }
td.right, th.right { text-align: right; }

.status { padding: 3px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.status.pending { background: #3a3010; color: #f4c752; }
.status.approved { background: #12331f; color: #6ee7a0; }
.status.denied { background: #3a1c1c; color: #fca5a5; }

.who { display: flex; align-items: center; gap: 10px; }
.who img { width: 30px; height: 30px; border-radius: 50%; }
.who .nm { font-weight: 500; }
.who .em { color: var(--dim); font-size: 12px; }

.switch { display: flex; align-items: center; gap: 10px; cursor: pointer; }
.switch input { appearance: none; width: 38px; height: 22px; border-radius: 999px; background: var(--bg-3); border: 1px solid var(--line); position: relative; cursor: pointer; transition: background .15s; }
.switch input::after { content: ''; position: absolute; left: 2px; top: 2px; width: 16px; height: 16px; border-radius: 50%; background: var(--muted); transition: transform .15s, background .15s; }
.switch input:checked { background: var(--accent); border-color: var(--accent); }
.switch input:checked::after { transform: translateX(16px); background: #fff; }

.hint { color: var(--dim); font-size: 13px; margin: 6px 0 0; }
.back { margin-bottom: 18px; }
