:root {
  --bg: #0a0a0f;
  --bg-card: #151520;
  --bg-elevated: #1c1c2e;
  --bg-input: #1a1a2a;
  --border: #2a2a3d;
  --border-hover: #3a3a55;
  --text: #eeeef5;
  --text-muted: #8888a0;
  --text-dim: #555568;
  --accent: #e6a040;
  --accent-dim: rgba(230, 160, 64, 0.12);
  --accent-glow: rgba(230, 160, 64, 0.25);
  --red: #ef4444;
  --green: #22c55e;
  --blue: #3b82f6;
  --radius: 14px;
  --radius-sm: 10px;
  --radius-xs: 6px;
  --shadow-card: 0 4px 24px rgba(0,0,0,.3);
  --nav-height: 64px;
  --transition: .2s cubic-bezier(.4,0,.2,1);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg); color: var(--text);
  min-height: 100vh; overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

a { color: var(--accent); text-decoration: none; }

/* ── Nav ── */
nav {
  position: sticky; top: 0; z-index: 100;
  background: rgba(10,10,15,.92); backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  height: var(--nav-height); display: flex; align-items: center;
  padding: 0 24px; gap: 16px;
}
nav .logo { font-size: 18px; font-weight: 800; color: var(--accent); white-space: nowrap; }
nav .nav-links { display: flex; gap: 8px; margin-left: auto; }
nav .nav-links button {
  background: none; border: none; color: var(--text-muted); cursor: pointer;
  padding: 8px 14px; border-radius: var(--radius-xs); font-size: 14px; font-weight: 500;
  transition: var(--transition);
}
nav .nav-links button:hover { color: var(--text); background: var(--bg-elevated); }
nav .nav-links button.active { color: var(--accent); background: var(--accent-dim); }

/* ── Main ── */
main { max-width: 1100px; margin: 0 auto; padding: 28px; }
.page { display: none; }
.page.active { display: block; }
.page-title { font-size: 24px; font-weight: 800; margin-bottom: 20px; }

/* ── Login ── */
.login-wrap {
  display: flex; justify-content: center; align-items: center;
  min-height: calc(100vh - var(--nav-height));
}
.login-box {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 40px; width: 360px;
  text-align: center;
}
.login-box h2 { margin-bottom: 24px; color: var(--accent); }
.login-box input {
  width: 100%; padding: 12px 16px; margin-bottom: 12px;
  background: var(--bg-input); border: 1px solid var(--border);
  border-radius: var(--radius-xs); color: var(--text); font-size: 14px; outline: none;
}
.login-box input:focus { border-color: var(--accent); }
.login-box button {
  width: 100%; padding: 12px; margin-top: 8px;
  background: var(--accent); color: #000; border: none;
  border-radius: var(--radius-xs); font-weight: 700; font-size: 15px;
  cursor: pointer; transition: var(--transition);
}
.login-box button:hover { opacity: 0.9; }
.login-error { color: var(--red); font-size: 13px; margin-top: 8px; }

/* ── Search type toggle ── */
.type-toggle { display: flex; gap: 6px; margin-bottom: 12px; }
.type-btn {
  padding: 8px 18px; background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius-xs); color: var(--text-muted); font-size: 14px;
  font-weight: 600; cursor: pointer; transition: var(--transition);
}
.type-btn:hover { border-color: var(--border-hover); color: var(--text); }
.type-btn.active { background: var(--accent-dim); border-color: var(--accent); color: var(--accent); }

/* ── Search ── */
.search-bar {
  display: flex; gap: 10px; margin-bottom: 20px;
}
.search-bar input {
  flex: 1; padding: 12px 18px;
  background: var(--bg-input); border: 1px solid var(--border);
  border-radius: var(--radius-sm); color: var(--text); font-size: 15px; outline: none;
}
.search-bar input:focus { border-color: var(--accent); }
.search-bar button {
  padding: 12px 24px; background: var(--accent); color: #000;
  border: none; border-radius: var(--radius-sm); font-weight: 700; cursor: pointer;
}

/* ── Cards (torrent results / library items) ── */
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 16px;
}
.card {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 18px; cursor: pointer;
  transition: var(--transition); position: relative;
}
.card:hover { border-color: var(--border-hover); transform: translateY(-2px); box-shadow: var(--shadow-card); }
.card-title { font-size: 15px; font-weight: 700; margin-bottom: 6px; line-height: 1.3; }
.card-meta { font-size: 13px; color: var(--text-muted); display: flex; flex-wrap: wrap; gap: 8px; margin-top: 6px; }
.card-meta span { display: flex; align-items: center; gap: 4px; }
.card-indexer {
  display: inline-block; font-size: 11px; font-weight: 600;
  padding: 2px 8px; border-radius: 3px;
  background: var(--accent-dim); color: var(--accent);
}
.card-actions { margin-top: 12px; display: flex; gap: 8px; }
.btn {
  padding: 8px 16px; border: none; border-radius: var(--radius-xs);
  font-size: 13px; font-weight: 600; cursor: pointer; transition: var(--transition);
}
.btn-primary { background: var(--accent); color: #000; }
.btn-primary:hover { opacity: 0.9; }
.btn-secondary { background: var(--bg-elevated); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { border-color: var(--border-hover); }
.btn-danger { background: var(--red); color: #fff; }

/* ── Library cards ── */
.lib-card {
  display: flex; gap: 16px; background: var(--bg-card);
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px; cursor: pointer; transition: var(--transition);
}
.lib-card:hover { border-color: var(--border-hover); }
.lib-card img {
  width: 80px; height: 80px; border-radius: var(--radius-xs);
  object-fit: cover; background: var(--bg-elevated); flex-shrink: 0;
}
.lib-card-body { flex: 1; min-width: 0; }
.lib-card-title { font-size: 15px; font-weight: 700; margin-bottom: 4px; }
.lib-card-author { font-size: 13px; color: var(--text-muted); margin-bottom: 4px; }
.lib-card-meta { font-size: 12px; color: var(--text-dim); display: flex; gap: 10px; }

/* ── Downloads list ── */
.dl-item {
  display: flex; align-items: center; gap: 14px;
  padding: 14px; background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius-sm); margin-bottom: 8px;
}
.dl-item .dl-name { flex: 1; font-size: 14px; font-weight: 500; }
.dl-item .dl-progress {
  width: 120px; height: 6px; background: var(--bg-elevated);
  border-radius: 3px; overflow: hidden;
}
.dl-item .dl-progress-fill { height: 100%; background: var(--accent); transition: width .3s; }
.dl-item .dl-status { font-size: 12px; color: var(--text-muted); min-width: 60px; text-align: right; }

/* ── Toast ── */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--bg-elevated); color: var(--text); border: 1px solid var(--border);
  padding: 12px 24px; border-radius: var(--radius-sm);
  font-size: 14px; z-index: 9999; opacity: 0; transition: opacity .3s;
  pointer-events: none;
}
.toast.show { opacity: 1; }

/* ── Empty state ── */
.empty-state { text-align: center; padding: 60px 20px; color: var(--text-muted); }
.empty-state p { font-size: 15px; }

/* ── Skeleton ── */
.skeleton {
  background: linear-gradient(90deg, var(--bg-card) 25%, var(--bg-elevated) 50%, var(--bg-card) 75%);
  background-size: 200% 100%; animation: shimmer 1.5s infinite;
  border-radius: var(--radius); min-height: 100px;
}
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

/* ── Ebook file browser ── */
.ebook-breadcrumb {
  display: flex; gap: 4px; align-items: center; margin-bottom: 16px;
  font-size: 14px; color: var(--text-muted); flex-wrap: wrap;
}
.ebook-breadcrumb a { cursor: pointer; }
.ebook-breadcrumb a:hover { color: var(--text); }
.ebook-breadcrumb .sep { color: var(--text-dim); }

.ebook-item {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 16px; background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius-sm); margin-bottom: 6px; cursor: pointer;
  transition: var(--transition);
}
.ebook-item:hover { border-color: var(--border-hover); }
.ebook-icon { font-size: 20px; width: 28px; text-align: center; flex-shrink: 0; }
.ebook-name { flex: 1; font-size: 14px; font-weight: 500; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ebook-meta { font-size: 12px; color: var(--text-muted); white-space: nowrap; display: flex; gap: 10px; }
.ebook-ext {
  font-size: 11px; font-weight: 600; padding: 2px 6px;
  border-radius: 3px; text-transform: uppercase;
}
.ebook-ext.epub { background: rgba(34,197,94,.15); color: var(--green); }
.ebook-ext.pdf { background: rgba(239,68,68,.15); color: var(--red); }
.ebook-ext.mobi { background: rgba(59,130,246,.15); color: var(--blue); }
.ebook-ext.azw3 { background: rgba(59,130,246,.15); color: var(--blue); }
.ebook-dl-btn {
  padding: 6px 12px; background: var(--accent); color: #000; border: none;
  border-radius: var(--radius-xs); font-size: 12px; font-weight: 600;
  cursor: pointer; white-space: nowrap;
}
.ebook-dl-btn:hover { opacity: 0.9; }

/* ── Settings ── */
.settings-section {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); margin-bottom: 16px; overflow: hidden;
}
.section-header {
  padding: 16px 20px; font-size: 15px; font-weight: 700;
  cursor: pointer; display: flex; align-items: center; gap: 8px;
  transition: var(--transition);
}
.section-header:hover { background: var(--bg-elevated); }
.section-header::before { content: '\25B6'; font-size: 10px; transition: transform .2s; }
.section-header.open::before { transform: rotate(90deg); }
.section-body { padding: 0 20px 20px; }
.setting-group { margin-bottom: 12px; }
.setting-group label { display: block; font-size: 13px; color: var(--text-muted); margin-bottom: 4px; font-weight: 500; }
.setting-input {
  width: 100%; padding: 10px 14px;
  background: var(--bg-input); border: 1px solid var(--border);
  border-radius: var(--radius-xs); color: var(--text); font-size: 14px; outline: none;
}
.setting-input:focus { border-color: var(--accent); }
.subsection-title { font-size: 14px; font-weight: 700; color: var(--accent); margin: 16px 0 10px; }
.save-status { font-size: 13px; color: var(--green); margin-left: 10px; }

.user-row {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 14px; background: var(--bg-elevated);
  border-radius: var(--radius-xs); margin-bottom: 6px;
}
.user-row .user-name { flex: 1; font-size: 14px; font-weight: 500; }
.user-row .user-badge {
  font-size: 11px; font-weight: 600; padding: 2px 8px;
  border-radius: 3px; background: var(--accent-dim); color: var(--accent);
}
.user-row .btn { padding: 4px 10px; font-size: 12px; }

.add-user-form { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.add-user-form .setting-input { width: auto; flex: 1; min-width: 150px; }
.checkbox-label { font-size: 13px; color: var(--text-muted); display: flex; align-items: center; gap: 6px; cursor: pointer; }

.disk-row {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 14px; background: var(--bg-elevated);
  border-radius: var(--radius-xs); margin-bottom: 6px; cursor: pointer;
  transition: var(--transition);
}
.disk-row:hover { background: var(--bg-input); }
.disk-row .disk-name { flex: 1; font-size: 14px; font-weight: 500; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.disk-row .disk-size { font-size: 13px; color: var(--text-muted); white-space: nowrap; }
.disk-row .disk-files { font-size: 12px; color: var(--text-dim); white-space: nowrap; }
.disk-subfolders { padding-left: 24px; }

.settings-version { text-align: center; color: var(--text-dim); font-size: 12px; margin-top: 24px; padding: 12px; }

.confirm-overlay {
  position: fixed; top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,.7); z-index: 9998;
  display: flex; justify-content: center; align-items: center;
}
.confirm-box {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 28px; max-width: 400px; width: 90%;
}
.confirm-box h3 { margin-bottom: 12px; }
.confirm-box p { font-size: 14px; color: var(--text-muted); margin-bottom: 16px; line-height: 1.5; }
.confirm-box .confirm-actions { display: flex; gap: 8px; justify-content: flex-end; }

/* ── Iframe pages (Player / Reader) ── */
.iframe-page {
  padding: 0 !important; max-width: none !important;
  margin: 0 !important; position: fixed;
  top: var(--nav-height); left: 0; right: 0; bottom: 0;
}
.iframe-page iframe {
  width: 100%; height: 100%; border: none; background: var(--bg);
}
.iframe-page.active { display: block; }

/* ── Responsive ── */
@media (max-width: 600px) {
  main { padding: 16px; }
  .card-grid { grid-template-columns: 1fr; }
  nav { padding: 0 14px; }
  nav .logo { font-size: 16px; }
  .add-user-form { flex-direction: column; }
  .add-user-form .setting-input { width: 100%; }
}
