:root {
  --bg: #f4f6f8; --card-bg: #ffffff; --text-main: #1f2937; --text-sub: #6b7280;
  --primary: #3b82f6; --primary-hover: #2563eb; --success: #10b981; --danger: #ef4444;
  --border: #e5e7eb; --shadow: 0 4px 6px -1px rgba(0,0,0,0.1);
  --radius: 12px; --radius-sm: 8px; --transition: all 0.2s cubic-bezier(0.4,0,0.2,1); --item-h: 52px;
}
[data-theme="dark"] {
  --bg: #0f1115; --card-bg: #181a20; --text-main: #e6e8eb; --text-sub: #8a92a3;
  --border: #2d313a; --shadow: 0 4px 12px rgba(0,0,0,0.4); --primary: #6366f1; --primary-hover: #4f46e5;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg); color: var(--text-main); padding: 16px; line-height: 1.5;
  transition: background 0.3s, color 0.3s;
}
.container { max-width: 900px; margin: 0 auto; }
.top-bar { display: flex; justify-content: flex-end; align-items: center; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.sync-status { display: inline-flex; align-items: center; gap: 4px; font-size: 0.75rem; color: var(--text-sub); margin-right: auto; }
.sync-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--success); display: inline-block; }
.sync-dot.local { background: var(--text-sub); }
.sync-dot.error { background: var(--danger); }
.card {
  background: var(--card-bg); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 16px; margin-bottom: 16px; border: 1px solid var(--border); transition: background 0.3s, border-color 0.3s;
}
.card-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; flex-wrap: wrap; gap: 8px; }
.card-title { font-weight: 600; font-size: 1rem; display: flex; align-items: center; gap: 8px; }
.engine-list { display: flex; flex-wrap: wrap; gap: 8px; max-height: 200px; overflow-y: auto; padding: 4px; }
.engine-item {
  padding: 6px 12px; background: var(--bg); border: 1px solid var(--border);
  border-radius: 20px; font-size: 0.85rem; cursor: pointer; transition: var(--transition); user-select: none; position: relative;
}
.engine-item:hover { border-color: var(--primary); transform: translateY(-1px); }
.engine-item.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.engine-item.dragging { opacity: 0.4; }
.engine-item.drag-over { border-color: var(--success); border-style: dashed; transform: scale(1.05); }
.engine-item .drag-handle { display: none; cursor: grab; margin-right: 4px; opacity: 0.5; }
.engine-item.draggable .drag-handle { display: inline; }
.engine-item.draggable:active .drag-handle { cursor: grabbing; }
.btn-sm {
  padding: 6px 12px; font-size: 0.8rem; border: 1px solid var(--border);
  background: var(--card-bg); color: var(--text-main); border-radius: 6px;
  cursor: pointer; transition: var(--transition); display: inline-flex; align-items: center; gap: 4px;
}
.btn-sm:hover { background: var(--bg); border-color: var(--text-sub); }
.btn-sm.danger { color: var(--danger); border-color: rgba(239,68,68,0.3); }
.btn-sm.danger:hover { background: rgba(239,68,68,0.1); }
.btn-sm.primary { color: var(--primary); border-color: rgba(59,130,246,0.4); }
.btn-sm.primary:hover { background: rgba(59,130,246,0.1); }
.btn-sm.success { color: var(--success); border-color: rgba(16,185,129,0.4); }
.btn-sm.success:hover { background: rgba(16,185,129,0.1); }
.btn-sm:disabled { opacity: 0.5; cursor: not-allowed; }
.theme-toggle { background: none; border: none; cursor: pointer; font-size: 1.2rem; padding: 4px; transition: transform 0.2s; color: var(--text-sub); }
.theme-toggle:hover { transform: scale(1.1); color: var(--primary); }
textarea {
  width: 100%; min-height: 80px; padding: 12px; border: 1px solid var(--border);
  border-radius: var(--radius-sm); font-size: 0.95rem; resize: vertical; background: var(--bg); color: var(--text-main); transition: var(--transition);
}
textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(59,130,246,0.15); }
.keyword-footer { display: flex; justify-content: space-between; align-items: center; margin-top: 12px; flex-wrap: wrap; gap: 10px; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; }
.btn {
  padding: 8px 14px; border: none; border-radius: var(--radius-sm); font-weight: 500;
  cursor: pointer; transition: var(--transition); display: inline-flex; align-items: center; gap: 6px; font-size: 0.85rem;
}
.btn:active { transform: scale(0.96); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { background: #059669; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #dc2626; }
.btn-secondary { background: var(--bg); color: var(--text-main); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--border); }
.meta { color: var(--text-sub); font-size: 0.85rem; white-space: nowrap; }
.results-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.results-list { border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--bg); overflow: hidden; }
.virtual-list { position: relative; height: 100%; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.virtual-list-inner { position: relative; }
.virtual-item {
  position: absolute; left: 0; right: 0; display: flex; justify-content: space-between; align-items: center;
  padding: 10px 12px; border-bottom: 1px solid var(--border); transition: background 0.15s; background: var(--card-bg);
}
.virtual-item:last-child { border-bottom: none; }
.virtual-item:hover { background: rgba(59,130,246,0.05); }
.virtual-item.visited { background: rgba(16,185,129,0.08); }
.virtual-item.visited::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; background: var(--success); }
.result-link { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-right: 10px; color: var(--primary); cursor: pointer; font-weight: 500; font-size: 0.9rem; }
.result-link:hover { text-decoration: underline; }
.visited .result-link { color: var(--text-sub); text-decoration: none; opacity: 0.7; }
.result-actions { display: flex; gap: 6px; flex-shrink: 0; }
.action-btn {
  padding: 4px 10px; font-size: 0.75rem; border-radius: 6px; cursor: pointer;
  border: 1px solid var(--border); background: var(--card-bg); color: var(--text-sub); transition: var(--transition); display: flex; align-items: center; gap: 4px; white-space: nowrap;
}
.action-btn:hover { border-color: var(--primary); color: var(--primary); }
.action-btn.open:hover { background: var(--primary); color: #fff; border-color: var(--primary); }
.visited .action-btn.open { background: var(--success); color: #fff; border-color: var(--success); cursor: default; }
.visited .action-btn.open:hover { background: var(--success); }
.empty-tip { padding: 30px; text-align: center; color: var(--text-sub); font-size: 0.9rem; }
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.5); backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center; opacity: 0; visibility: hidden; transition: all 0.3s; z-index: 100;
}
.modal-overlay.show { opacity: 1; visibility: visible; }
.modal { background: var(--card-bg); padding: 24px; border-radius: var(--radius); width: 90%; max-width: 500px; transform: translateY(20px); transition: all 0.3s; box-shadow: var(--shadow); }
.modal-overlay.show .modal { transform: translateY(0); }
.modal h3 { margin-bottom: 16px; }
.modal input, .modal textarea {
  width: 100%; padding: 10px; border: 1px solid var(--border); border-radius: var(--radius-sm); margin-bottom: 12px; background: var(--bg); color: var(--text-main); font-family: inherit; font-size: 0.9rem;
}
.modal input:focus, .modal textarea:focus { outline: none; border-color: var(--primary); }
.modal textarea { min-height: 180px; resize: vertical; font-family: monospace; font-size: 0.82rem; }
.modal-footer { display: flex; gap: 10px; justify-content: flex-end; }
.modal-hint { color: var(--text-sub); font-size: 0.8rem; margin-bottom: 12px; }
.modal-error { color: var(--danger); font-size: 0.85rem; margin-bottom: 8px; min-height: 1.2em; }
.site-footer { max-width: 900px; margin: 24px auto 16px; padding: 12px 16px; text-align: center; color: var(--text-sub); font-size: 0.8rem; border-top: 1px solid var(--border); }
.site-footer a { color: var(--text-sub); text-decoration: none; margin: 0 6px; transition: color 0.2s; }
.site-footer a:hover { color: var(--primary); text-decoration: underline; }
.site-footer .sep { color: var(--border); margin: 0 2px; }
.friend-links-section { max-width: 900px; margin: 0 auto 20px; padding: 0 16px; text-align: center; }
.friend-links-label { display: inline-block; font-size: 0.7rem; color: var(--text-sub); letter-spacing: 1px; text-transform: uppercase; margin-bottom: 10px; position: relative; padding: 0 16px; }
.friend-links-label::before, .friend-links-label::after { content: ''; position: absolute; top: 50%; width: 30px; height: 1px; background: var(--border); }
.friend-links-label::before { right: 100%; }
.friend-links-label::after { left: 100%; }
.friend-links-list { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; }
.friend-link-card { display: inline-flex; align-items: center; gap: 6px; padding: 8px 16px; background: var(--card-bg); border: 1px solid var(--border); border-radius: 24px; text-decoration: none; color: var(--text-main); font-size: 0.82rem; font-weight: 500; transition: var(--transition); box-shadow: 0 1px 3px rgba(0,0,0,0.04); }
.friend-link-card:hover { border-color: var(--primary); color: var(--primary); transform: translateY(-2px); box-shadow: 0 6px 16px rgba(0,0,0,0.1); }
.friend-link-card .friend-icon { width: 22px; height: 22px; border-radius: 6px; background: var(--primary); color: #fff; display: inline-flex; align-items: center; justify-content: center; font-size: 0.65rem; font-weight: 700; flex-shrink: 0; }
.friend-link-card .friend-desc { font-size: 0.7rem; color: var(--text-sub); font-weight: 400; margin-left: 2px; }
.toast-container { position: fixed; top: 20px; left: 50%; transform: translateX(-50%); z-index: 200; display: flex; flex-direction: column; gap: 8px; pointer-events: none; }
.toast { background: var(--card-bg); color: var(--text-main); padding: 10px 16px; border-radius: var(--radius-sm); box-shadow: var(--shadow); font-size: 0.85rem; border: 1px solid var(--border); opacity: 0; transform: translateY(-10px); transition: all 0.3s; pointer-events: auto; }
.toast.show { opacity: 1; transform: translateY(0); }
.toast.success { border-left: 3px solid var(--success); }
.toast.error { border-left: 3px solid var(--danger); }
.toast.info { border-left: 3px solid var(--primary); }
@keyframes fadeIn { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; transform: translateY(0); } }
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-sub); }
@media (max-width: 640px), (pointer: coarse) {
  body { padding: 10px; font-size: 14px; }
  .card { padding: 10px; margin-bottom: 10px; border-radius: 8px; }
  .card-title { font-size: 0.85rem; }
  .engine-list { max-height: 100px; }
  .engine-item { padding: 4px 8px; font-size: 0.75rem; border-radius: 14px; }
  textarea { min-height: 50px; font-size: 14px; padding: 8px; }
  .btn { padding: 10px 12px; font-size: 0.85rem; border-radius: 6px; }
  .actions { gap: 6px; }
  .actions .btn { flex: 1; min-width: calc(50% - 3px); justify-content: center; }
  .meta { width: 100%; text-align: center; font-size: 0.75rem; margin-top: 4px; }
  .keyword-footer { flex-direction: column; align-items: stretch; }
  #pendingListContainer, #visitedListContainer { height: 180px !important; }
  .virtual-item { padding: 8px 10px; }
  .action-btn { padding: 6px 8px; font-size: 0.7rem; }
  .result-link { font-size: 0.75rem; }
  .modal { padding: 12px; }
  .modal h3 { font-size: 0.9rem; }
  .modal input, .modal textarea { padding: 10px; font-size: 14px; }
  .btn-sm { padding: 6px 10px; font-size: 0.75rem; }
  .engine-item, .btn, .action-btn { touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
  .engine-item:active, .btn:active, .action-btn:active { transform: scale(0.97); }
  .site-footer { font-size: 0.7rem; padding: 10px; }
}
.is-mobile body { padding: 8px; }
.is-mobile .card { padding: 10px; margin-bottom: 10px; }
.is-mobile .btn { padding: 12px 10px; min-height: 44px; }
