:root {
  --bg: #0b0b0e;
  --bg-soft: #101014;
  --panel: #16161c;
  --panel-hover: #1c1c24;
  --border: #26262f;
  --gold: #d4a94a;
  --gold-soft: #f0cd7d;
  --gold-dim: #8a6f34;
  --text: #f0efe9;
  --text-dim: #9a99a3;
  --text-faint: #6b6a74;
  --danger: #e2716f;
  --radius: 14px;
  --radius-sm: 8px;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }

body {
  margin: 0;
  background:
    radial-gradient(1200px 500px at 50% -100px, rgba(212,169,74,0.08), transparent),
    var(--bg);
  color: var(--text);
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  min-height: 100vh;
}

/* --- Top bar --- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(11,11,14,0.85);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.topbar-inner {
  max-width: 1100px;
  margin: 0 auto;
  padding: 16px 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
}

.brand {
  font-size: 17px;
  font-weight: 700;
  letter-spacing: 3px;
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 8px;
}
.brand-mark { color: var(--gold); font-size: 14px; }
.brand .accent { color: var(--gold); }

.sort-tabs {
  display: flex;
  gap: 4px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px;
}
.sort-tab {
  border: none;
  background: transparent;
  color: var(--text-dim);
  padding: 7px 16px;
  border-radius: 999px;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  white-space: nowrap;
}
.sort-tab:hover { color: var(--text); }
.sort-tab.active {
  background: var(--gold);
  color: #1a1408;
  font-weight: 600;
}

.auth-area { display: flex; align-items: center; gap: 10px; }
.user-badge {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  color: var(--text-dim);
}
.user-badge .dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: #6fce8f;
  box-shadow: 0 0 0 3px rgba(111,206,143,0.15);
}
.user-badge strong { color: var(--text); }
.link-btn {
  background: none; border: none; color: var(--text-faint);
  font-size: 12.5px; cursor: pointer; text-decoration: underline;
  padding: 0;
}
.link-btn:hover { color: var(--text); }

.modal-sm { max-width: 380px; }

.lock-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: var(--text-faint);
}

/* --- Hero --- */
.hero {
  max-width: 720px;
  margin: 56px auto 40px auto;
  padding: 0 28px;
  text-align: center;
}
.hero h1 {
  font-size: 32px;
  margin: 0 0 12px 0;
  letter-spacing: -0.5px;
  background: linear-gradient(180deg, var(--text) 30%, var(--text-dim));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.hero p {
  color: var(--text-dim);
  font-size: 15px;
  margin: 0 0 28px 0;
}

.searchwrap {
  position: relative;
  max-width: 520px;
  margin: 0 auto;
}
.search-icon {
  position: absolute;
  left: 16px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-faint);
  pointer-events: none;
}
#search {
  width: 100%;
  padding: 14px 16px 14px 44px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--text);
  font-size: 15px;
  transition: border-color 0.15s, box-shadow 0.15s;
}
#search:focus {
  outline: none;
  border-color: var(--gold-dim);
  box-shadow: 0 0 0 4px rgba(212,169,74,0.12);
}
#search::placeholder { color: var(--text-faint); }

/* --- Layout (sidebar + content) --- */
.layout {
  max-width: 1300px;
  margin: 0 auto;
  padding: 0 28px;
  display: flex;
  align-items: flex-start;
  gap: 28px;
}

.sidebar {
  width: 220px;
  flex-shrink: 0;
  position: sticky;
  top: 84px;
  max-height: calc(100vh - 100px);
  overflow-y: auto;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}
.sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}
.sidebar-head h3 {
  margin: 0;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-faint);
}

.cat-list { display: flex; flex-direction: column; gap: 2px; }
.cat-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  text-align: left;
  padding: 8px 10px;
  background: transparent;
  border: none;
  border-radius: var(--radius-sm);
  color: var(--text-dim);
  font-size: 13px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.cat-item:hover { background: var(--panel-hover); color: var(--text); }
.cat-item.active { color: var(--text); font-weight: 600; }

.cat-check {
  width: 15px;
  height: 15px;
  border-radius: 4px;
  border: 1px solid var(--border);
  flex-shrink: 0;
  position: relative;
}
.cat-item.active .cat-check {
  background: var(--gold);
  border-color: var(--gold);
}
.cat-item.active .cat-check::after {
  content: '';
  position: absolute;
  left: 4px; top: 1px;
  width: 4px; height: 8px;
  border: solid #1a1408;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}
.cat-item[data-cat=""] .cat-check { display: none; }

.content { flex: 1; min-width: 0; }

/* --- Grid of cards --- */
.grid {
  padding: 0 0 20px 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 18px;
}

.status {
  grid-column: 1 / -1;
  text-align: center;
  color: var(--text-dim);
  padding: 80px 0;
  font-size: 14px;
}

.card {
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  transition: transform 0.18s ease, border-color 0.18s ease, box-shadow 0.18s ease;
}
.card:hover {
  transform: translateY(-3px);
  border-color: var(--gold-dim);
  box-shadow: 0 12px 30px -12px rgba(0,0,0,0.6);
}

.card-thumb {
  width: 100%;
  aspect-ratio: 16 / 9;
  background: #000 linear-gradient(135deg, #1c1c24, #0b0b0e);
  overflow: hidden;
  position: relative;
}
.card-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.card-body {
  padding: 16px 18px 18px 18px;
  display: flex;
  flex-direction: column;
  flex: 1;
  gap: 8px;
}

.card-title {
  font-size: 15.5px;
  font-weight: 600;
  margin: 0;
  line-height: 1.35;
}

.card-author {
  font-size: 12px;
  color: var(--text-faint);
  margin: -4px 0 0 0;
}

.card-desc {
  font-size: 13px;
  color: var(--text-dim);
  margin: 0;
  line-height: 1.5;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  flex: 1;
}

.card-tags {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.tag {
  padding: 3px 10px;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--text-dim);
  font-size: 10.5px;
  letter-spacing: 0.2px;
}

.card-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 6px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.card-stats {
  font-size: 11.5px;
  color: var(--text-faint);
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.card-stats strong { color: var(--text-dim); font-weight: 600; }

/* --- Buttons --- */
.btn {
  padding: 9px 18px;
  border-radius: var(--radius-sm);
  border: none;
  background: var(--gold);
  color: #1a1408;
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
}
.btn:hover { background: var(--gold-soft); }
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn.secondary { background: var(--panel); border: 1px solid var(--border); color: var(--text); }
.btn.secondary:hover { border-color: var(--gold-dim); background: var(--panel-hover); }
.btn.danger-confirm { background: var(--danger); color: #fff; }
.btn.danger-confirm:hover { background: #ea8a88; }
.btn.full { width: 100%; }

/* --- Pager --- */
.pager {
  margin: 8px 0 24px 0;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 18px;
}
#pageLabel { color: var(--text-faint); font-size: 13px; min-width: 60px; text-align: center; }

.site-footer {
  text-align: center;
  color: var(--text-faint);
  font-size: 12px;
  padding: 24px 0 40px 0;
}

/* --- Modal --- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(6,6,8,0.7);
  backdrop-filter: blur(3px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
  animation: fadeIn 0.15s ease;
}
.modal-overlay.hidden { display: none; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.modal {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  width: 100%;
  max-width: 560px;
  max-height: 85vh;
  overflow-y: auto;
  padding: 28px;
  position: relative;
  box-shadow: 0 30px 80px -20px rgba(0,0,0,0.7);
}

.modal-close {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  color: var(--text-dim);
  font-size: 18px;
  cursor: pointer;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.15s, border-color 0.15s;
}
.modal-close:hover { color: var(--text); border-color: var(--gold-dim); }

.modal h2 { margin: 0 0 4px 0; font-size: 20px; padding-right: 30px; }

.modal-desc {
  font-size: 13px;
  color: var(--text-dim);
  line-height: 1.65;
  max-height: 180px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px;
  margin: 16px 0;
  background: var(--bg-soft);
}
.modal-desc img { max-width: 100%; border-radius: 6px; }

.field { margin-bottom: 4px; }
label {
  display: block;
  font-size: 11.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: var(--text-faint);
  margin: 16px 0 6px 0;
}

select, .modal input {
  width: 100%;
  padding: 10px 12px;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 13.5px;
  transition: border-color 0.15s;
}
select:focus, .modal input:focus { outline: none; border-color: var(--gold-dim); }

.modal-actions {
  display: flex;
  gap: 10px;
  margin-top: 22px;
  justify-content: flex-end;
}

.warn-box {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  background: rgba(226,113,111,0.08);
  border: 1px solid rgba(226,113,111,0.3);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font-size: 12.5px;
  line-height: 1.5;
  margin-top: 16px;
  color: #f0b8b8;
}

.install-status {
  margin-top: 14px;
  font-size: 13px;
  color: var(--text-dim);
  min-height: 18px;
}
.install-status.ok { color: #8fd19e; }
.install-status.error { color: var(--danger); }

/* --- Responsive --- */
@media (max-width: 900px) {
  .layout { flex-direction: column; }
  .sidebar {
    width: 100%;
    position: static;
    max-height: none;
  }
  .cat-list { flex-direction: row; flex-wrap: wrap; }
  .cat-item { width: auto; }
}

@media (max-width: 640px) {
  .topbar-inner { flex-direction: column; align-items: stretch; gap: 12px; }
  .hero h1 { font-size: 24px; }
  .grid { grid-template-columns: 1fr; }
}

/* --- Scrollbar --- */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 8px; }
::-webkit-scrollbar-thumb:hover { background: var(--gold-dim); }
