:root{
  --bg:#0f1115;
  --card:#171a21;
  --text:#e8e8ea;
  --muted:#a0a4ad;
  --border:rgba(255,255,255,0.08);
  --accent:#4ea1ff;
}

*{ box-sizing:border-box; }
html,body{ margin:0; padding:0; }
body{
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

a{ color:inherit; text-decoration:none; }
img{ display:block; }

main{
  max-width: 1100px;
  margin: 0 auto;
  padding: 14px;
}

h1{ margin: 8px 0 14px; font-size: 1.5rem; }
h2{ margin: 0 0 12px; font-size: 1.1rem; }

.small{ font-size: 0.88rem; }
.muted{ color: var(--muted); }

.row{ display:flex; gap:12px; align-items:center; flex-wrap:wrap; }
.between{ justify-content:space-between; }
.grow{ flex:1; min-width:0; }

.stack{ display:flex; flex-direction:column; gap:12px; }

input[type="text"],
input[type="password"],
select{
  width:100%;
  background: rgba(255,255,255,0.03);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 10px;
  padding: 10px 12px;
  outline: none;
}

.library-sort-select{ width:auto; min-width:180px; flex:0 0 auto; }
.btn{
  background: var(--accent);
  color: #0b0d10;
  border: none;
  border-radius: 10px;
  padding: 9px 12px;
  font-weight: 800;
  cursor:pointer;
}
.btn-ghost{
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 9px 12px;
  font-weight: 800;
  cursor:pointer;
}

.chk{
  display:flex;
  align-items:center;
  gap:8px;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  user-select:none;
}

.card{
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 12px;
}

.title{ font-weight: 800; line-height:1.2; }
.discover-title-link{ display:inline-block; }
.discover-title-link:hover{ text-decoration: underline; }

.flash-wrap{ margin: 12px 0; display:flex; flex-direction:column; gap:8px; }
.flash{
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: rgba(255,255,255,0.03);
}
.flash.ok{ border-color: rgba(78,161,255,0.35); }
.flash.error{ border-color: rgba(255,99,99,0.35); }

/* Topbar */
.topbar{
  position: sticky;
  top: 0;
  z-index: 50;
  background: rgba(15,17,21,0.92);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.topbar-inner{
  max-width: 1100px;
  margin: 0 auto;
  padding: 10px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.topbar-row1{ display:flex; align-items:center; gap:12px; }
.brand{ font-weight: 900; font-size: 1.05rem; }
.topbar-right{ margin-left:auto; display:flex; align-items:center; gap:10px; }
.pill{
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--muted);
}

/* Tabs */
.tabs{
  display:flex;
  gap: 0;
  padding: 4px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: rgba(255,255,255,0.03);
  overflow-x:auto;
  scrollbar-width:none;
}
.tabs::-webkit-scrollbar{ display:none; }
.tab{
  flex: 1 0 auto;
  text-align:center;
  padding: 10px 12px;
  border-radius: 12px;
  font-weight: 850;
  color: var(--muted);
  white-space: nowrap;
  min-width: 120px;
}
.tab.active{
  background: rgba(78,161,255,0.16);
  border: 1px solid rgba(78,161,255,0.28);
  color: var(--text);
}

/* Search */
.searchbar{
  display:flex;
  gap:10px;
  align-items:center;
  margin: 10px 0 12px;
}

/* Grid and poster sizing */
.grid{
  display:grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}
.poster{ width:100%; }
.poster-img{
  width:100%;
  height: 220px;
  object-fit: contain;
  border-radius: 12px;
  background: rgba(255,255,255,0.04);
}
.poster-placeholder{
  width:100%;
  height: 220px;
  border-radius: 12px;
  border: 1px dashed var(--border);
  background: rgba(255,255,255,0.03);
}
.card-body{ padding-top:10px; }

/* + button */
.icon-btn{
  width: 38px;
  height: 38px;
  display:flex;
  align-items:center;
  justify-content:center;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-weight: 900;
  font-size: 18px;
  background: rgba(255,255,255,0.03);
}

/* Modal */
.modal-backdrop{
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  display:flex;
  align-items:flex-end;
  justify-content:center;
  padding: 14px;
  z-index: 1000;
}
.modal{
  width: min(560px, 100%);
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 12px;
}
.modal-head{ display:flex; align-items:center; gap:10px; margin-bottom:8px; }
.modal-title{ font-weight: 900; font-size: 1.05rem; flex:1; }
.pill-row{ display:flex; gap:10px; flex-wrap:wrap; margin:10px 0 12px; }
.modal-actions{ display:flex; gap:10px; }

/* Show detail */
.action-row{ display:flex; gap:10px; flex-wrap:wrap; }
.action-row form{ flex: 1 1 220px; }
.action-row button{ width:100%; }

.episode-list{ display:flex; flex-direction:column; gap:10px; margin-top:10px; }
.episode-row{
  display:flex;
  justify-content:space-between;
  align-items:center;
  gap:12px;
  padding-top:10px;
  border-top: 1px solid var(--border);
}
.episode-row:first-child{ border-top:none; padding-top:0; }
.episode-info{ flex:1; min-width:0; }
.episode-actions{
  flex-shrink:0;
  display:flex;
  align-items:center;
  justify-content:flex-end;
}
.episode-actions form{ margin:0; }

.tag{
  display:inline-block;
  margin-left:8px;
  padding:2px 8px;
  border: 1px solid var(--border);
  border-radius: 999px;
  text-transform: uppercase;
  font-size: 0.72rem;
  letter-spacing: 0.02em;
  color: var(--muted);
}

/* Responsive */
@media (max-width: 900px){
  .grid{ grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .poster-img, .poster-placeholder{ height: 180px; }
}
@media (max-width: 600px){
  main{ padding:10px; }
  .topbar-inner{ padding:10px 10px; gap:8px; }
  .tab{ padding:9px 10px; min-width:110px; }

  .grid{ grid-template-columns: repeat(2, minmax(0, 1fr)); gap:10px; }
  .poster-img, .poster-placeholder{ height: 140px; }
}
@media (max-width: 360px){
  .grid{ grid-template-columns: 1fr; }
  .poster-img, .poster-placeholder{ height: 160px; }
}

.discover-user-row{ gap:8px; }
.discover-watch-chk{ font-size:0.82rem; padding:5px 8px; }
