:root {
  --bg: #f0f2f5;
  --bg-card: rgba(255, 255, 255, 0.85);
  --bg-header: rgba(255, 255, 255, 0.92);
  --bg-input: rgba(255, 255, 255, 0.9);
  --bg-hover: rgba(0, 0, 0, 0.04);
  --text: #1a1a2e;
  --text-secondary: #555;
  --text-muted: #999;
  --border: rgba(0, 0, 0, 0.08);
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
  --shadow-hover: 0 4px 12px rgba(0, 0, 0, 0.1);
  --accent: #5B8DEF;
  --accent-light: #7DA5F3;
  --accent-bg: rgba(91, 141, 239, 0.08);
  --scrollbar: rgba(0, 0, 0, 0.12);
  --scrollbar-hover: rgba(0, 0, 0, 0.3);
  --cat-header-bg: rgba(0, 0, 0, 0.02);
}

[data-theme="dark"] {
  --bg: #0f0f1a;
  --bg-card: rgba(25, 25, 45, 0.85);
  --bg-header: rgba(12, 12, 25, 0.95);
  --bg-input: rgba(30, 30, 55, 0.9);
  --bg-hover: rgba(255, 255, 255, 0.06);
  --text: #e0e0f0;
  --text-secondary: #999;
  --text-muted: #666;
  --border: rgba(255, 255, 255, 0.06);
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
  --shadow-hover: 0 4px 12px rgba(0, 0, 0, 0.5);
  --accent: #7DA5F3;
  --accent-light: #9BBBF7;
  --accent-bg: rgba(125, 165, 243, 0.12);
  --scrollbar: rgba(255, 255, 255, 0.15);
  --scrollbar-hover: rgba(255, 255, 255, 0.3);
  --cat-header-bg: rgba(255, 255, 255, 0.03);
}

*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }
html { scroll-behavior: smooth; overflow-y: scroll; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans SC", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  transition: background 0.3s, color 0.3s;
  overflow-x: hidden;
}
a { color: inherit; text-decoration: none; }

::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--scrollbar); border-radius: 3px; }
::selection { background: var(--accent); color: #fff; }

/* ── Header ── */
.header {
  position: sticky;
  top: 0;
  z-index: 40;
  background: var(--bg-header);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border);
  padding: 10px 24px;
  transition: background 0.3s;
}
.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  max-width: 1400px;
  margin: 0 auto;
  position: relative;
}
.header-logo {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 16px;
  font-weight: 700;
  color: var(--accent);
  flex-shrink: 0;
  text-decoration: none;
  cursor: pointer;
}
.header-logo svg {
  width: 26px;
  height: 26px;
}
.hp-toggle {
  display: inline-flex;
  align-items: center;
  cursor: pointer;
  color: var(--text-muted);
  padding: 4px;
  border-radius: 6px;
  transition: all 0.2s;
}
.hp-toggle:hover { color: var(--accent); background: var(--accent-bg); }
.hp-toggle.on { color: var(--accent); }
.search-area {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  max-width: 520px;
  width: 100%;
  display: flex;
  align-items: center;
  gap: 6px;
}

.engine-select { position: relative; flex-shrink: 0; }
.ef-btn {
  display: flex;
  align-items: center;
  gap: 4px;
  width: 115px;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-input);
  color: var(--text);
  font-size: 12px;
  cursor: pointer;
  outline: none;
  transition: border-color 0.2s;
  white-space: nowrap;
}
.ef-btn:hover { border-color: var(--accent); }
.ef-icon { width: 16px; height: 16px; border-radius: 3px; flex-shrink: 0; }
.ef-icon-fb {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--accent-bg);
  color: var(--accent);
  font-size: 10px;
  font-weight: 600;
}
.ef-label { flex: 1; text-align: center; }
.ef-arrow { font-size: 14px; color: var(--text-muted); transition: transform 0.2s; line-height: 1; }
.engine-select.open .ef-arrow { transform: rotate(180deg); }

.ef-dropdown {
  position: absolute;
  top: calc(100% + 4px);
  right: 0;
  min-width: 150px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 8px 30px rgba(0,0,0,0.12);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  z-index: 50;
  padding: 4px;
  opacity: 0;
  pointer-events: none;
  transform: translateY(-4px);
  transition: opacity 0.2s, transform 0.2s;
}
.ef-dropdown.open { opacity: 1; pointer-events: auto; transform: translateY(0); }

.eo {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 7px 10px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  font-size: 12px;
  cursor: pointer;
  text-align: left;
  transition: background 0.12s;
}
.eo:hover { background: var(--bg-hover); }
.eo.active { background: var(--accent-bg); color: var(--accent); font-weight: 600; }
.eo .ef-icon { width: 16px; height: 16px; }

.search-box { flex: 1; display: flex; min-width: 100px; }
.search-input {
  flex: 1;
  padding: 7px 12px;
  border: 1px solid var(--border);
  border-right: none;
  border-radius: 8px 0 0 8px;
  background: var(--bg-input);
  color: var(--text);
  font-size: 13px;
  outline: none;
  min-width: 0;
  transition: border-color 0.2s;
}
.search-input:focus { border-color: var(--accent); }
.search-btn {
  padding: 7px 10px;
  border: 1px solid var(--accent);
  border-radius: 0 8px 8px 0;
  background: var(--accent);
  color: #fff;
  font-size: 12px;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
.search-btn:hover { background: var(--accent-light); }

.header-actions { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.theme-toggle {
  width: 34px; height: 34px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: transparent;
  color: var(--text-secondary);
  font-size: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}
.theme-toggle:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-bg); }


/* ── Content ── */
.content { padding: 20px 24px 40px; max-width: 1400px; margin: 0 auto; }

.search-results-header {
  display: none;
  margin-bottom: 16px;
  padding: 10px 14px;
  background: var(--accent-bg);
  border-radius: 8px;
  color: var(--accent);
  font-size: 13px;
}
.search-results-header.show { display: block; text-align: center; }

/* ── Compact Category Grid ── */
.cat-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  align-items: start;
}

.cat-container {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.cat-container:hover { border-color: var(--accent); box-shadow: var(--shadow-hover); }

.cat-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--cat-header-bg);
}
.cat-icon { font-size: 16px; flex-shrink: 0; }
.cat-title { font-size: 14px; font-weight: 600; color: var(--text); flex: 1; }
.cat-count { font-size: 11px; color: var(--text-muted); flex-shrink: 0; }
.cl-add-import { cursor:pointer; flex-shrink:0; font-size:13px; padding:4px 6px; border-radius:6px; transition:background .15s; line-height:1; display:inline-flex; align-items:center; }
.cl-add-import:hover { background:var(--accent-bg); }

.cat-body {
  max-height: 280px;
  overflow-y: auto;
  scroll-behavior: smooth;
  scrollbar-width: thin;
  scrollbar-color: var(--scrollbar) transparent;
}
.cat-body::-webkit-scrollbar { width: 5px; }
.cat-body::-webkit-scrollbar-track { background: transparent; }
.cat-body::-webkit-scrollbar-thumb {
  background: var(--scrollbar);
  border-radius: 3px;
  min-height: 30px;
}
.cat-body:hover::-webkit-scrollbar-thumb { background: var(--scrollbar-hover); }

/* ── Compact List Items ── */
.cl-item {
  display: flex;
  align-items: center;
  gap: 6px;
  height: 28px;
  padding: 0 14px 0 10px;
  cursor: pointer;
  transition: background 0.12s;
  position: relative;
}
.cl-item:hover { background: var(--bg-hover); }
.cl-item:active { background: var(--accent-bg); }


.cl-num {
  width: 18px;
  text-align: right;
  color: var(--text-muted);
  font-size: 11px;
  flex-shrink: 0;
  font-variant-numeric: tabular-nums;
}
.cl-icon {
  width: 16px;
  height: 16px;
  border-radius: 4px;
  flex-shrink: 0;
  object-fit: contain;
}
.cl-icon-fallback {
  width: 16px;
  height: 16px;
  border-radius: 4px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--accent-bg);
  color: var(--accent);
  font-size: 9px;
  font-weight: 600;
}
.cl-title {
  flex: 1;
  font-size: 13px;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cl-desc {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 0 1 auto;
  min-width: 0;
}

/* ── Add Link ── */
.cl-add {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  height: 28px;
  font-size: 12px;
  color: var(--text-muted);
  cursor: pointer;
  border-top: 1px dashed var(--border);
  transition: all 0.15s;
}
.cl-add:hover { color: var(--accent); border-color: var(--accent); background: var(--accent-bg); }

/* ── Custom Link Actions ── */
.cl-actions {
  display: none;
  gap: 1px;
  flex-shrink: 0;
}
.cl-item:hover .cl-actions { display: flex; }
.cl-act {
  width: 18px; height: 18px;
  border: none;
  border-radius: 4px;
  background: transparent;
  color: var(--text-muted);
  font-size: 10px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
}
.cl-act:hover { background: var(--accent); color: #fff; }
.cl-act.del:hover { background: #e74c3c; }

/* ── Empty / Search Results ── */
.empty-state { text-align: center; padding: 60px 20px; color: var(--text-muted); }
.empty-state-icon { font-size: 40px; margin-bottom: 8px; }
.empty-state-text { font-size: 14px; }

/* ── Back to Top ── */
.back-to-top {
  position: fixed; bottom: 20px; right: 20px;
  width: 38px; height: 38px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg-card);
  backdrop-filter: blur(10px);
  color: var(--text-secondary);
  font-size: 18px;
  cursor: pointer;
  display: none;
  align-items: center;
  justify-content: center;
  transition: all 0.3s;
  z-index: 30;
  box-shadow: var(--shadow);
}
.back-to-top.show { display: flex; }
.back-to-top:hover { background: var(--accent); color: #fff; border-color: var(--accent); transform: translateY(-2px); }

/* ── Modal ── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.5);
  backdrop-filter: blur(4px);
  z-index: 100;
  display: none;
  align-items: center;
  justify-content: center;
}
.modal-overlay.show { display: flex; }
.modal {
  background: var(--bg-card);
  backdrop-filter: blur(20px);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 24px;
  width: 90%;
  max-width: 400px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
  animation: slideUp 0.25s ease;
}
.modal-title { font-size: 16px; font-weight: 600; margin-bottom: 16px; }
.modal-field { margin-bottom: 12px; }
.modal-label { display: block; font-size: 12px; color: var(--text-secondary); margin-bottom: 4px; }
.modal-input {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-input);
  color: var(--text);
  font-size: 13px;
  outline: none;
  transition: border-color 0.2s;
}
.modal-input:focus { border-color: var(--accent); }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; }
.modal-btn {
  padding: 7px 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
  transition: all 0.2s;
}
.modal-btn:hover { background: var(--bg-hover); }
.modal-btn.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.modal-btn.primary:hover { background: var(--accent-light); }

.age-gate {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(0,0,0,0.75);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
}
.age-gate-box {
  background: var(--bg-card);
  backdrop-filter: blur(24px);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 36px 32px;
  width: 90%;
  max-width: 400px;
  text-align: center;
  box-shadow: 0 24px 80px rgba(0,0,0,0.4);
}
.age-gate-icon { font-size: 48px; margin-bottom: 12px; }
.age-gate-title { font-size: 20px; font-weight: 700; color: var(--text); margin-bottom: 16px; }
.age-gate-text { font-size: 14px; color: var(--text-secondary); line-height: 1.7; }
.age-gate-actions { display: flex; gap: 10px; justify-content: center; margin-top: 24px; }

.modal ol { margin: 6px 0 0 18px; padding: 0; }
.modal li { margin-bottom: 3px; font-size: 13px; color: var(--text-secondary); }
.modal li strong { color: var(--text); }
.modal code { background: var(--bg); padding: 1px 6px; border-radius: 4px; font-size: 12px; }

/* ── Toast ── */
.toast {
  position: fixed; bottom: 70px; left: 50%; transform: translateX(-50%);
  padding: 8px 20px;
  background: var(--text);
  color: var(--bg);
  border-radius: 8px;
  font-size: 13px;
  z-index: 200;
  opacity: 0;
  transition: opacity 0.3s;
  pointer-events: none;
}
.toast.show { opacity: 1; }

/* ── Animations ── */
@keyframes slideUp { from { opacity: 0; transform: translateY(16px); } to { opacity: 1; transform: translateY(0); } }
@keyframes fadeInScale { from { opacity: 0; transform: scale(0.97); } to { opacity: 1; transform: scale(1); } }

/* ── Responsive ── */
@media (max-width: 900px) {
  .cat-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .header { padding: 8px 12px; }
  .header-inner { flex-wrap: wrap; gap: 8px; }
  .search-area { position: static; transform: none; order: 2; width: 100%; max-width: 100%; }
  .header-actions { order: 1; margin-left: auto; }
  .content { padding: 12px; }
  .cat-body { max-height: 280px; }
}
@media (max-width: 480px) {
  .engine-select .ef-btn { width: 70px; padding: 5px 4px; font-size: 11px; }
  .engine-select .ef-icon { width: 12px; height: 12px; }
  .engine-select .ef-label { font-size: 11px; }
  .engine-select .ef-arrow { font-size: 10px; }
  .search-input { font-size: 12px; padding: 6px 10px; }
  .search-btn { padding: 6px 8px; }
  .search-btn svg { width: 12px; height: 12px; }
  .ef-dropdown { position: fixed; right: 8px; top: auto; min-width: 120px; }
}
@media (max-width: 480px) {
  .cat-grid { grid-template-columns: 1fr; }
}
