/* ===== CSS Variables ===== */
:root {
  --bg: #f0f2f5;
  --bg-card: #ffffff;
  --bg-hover: #f8f9fb;
  --bg-input: #ffffff;
  --bg-header: rgba(255,255,255,0.85);
  --bg-tag: #eef1f6;
  --text: #1a1a2e;
  --text-secondary: #6b7280;
  --text-muted: #9ca3af;
  --border: #e5e7eb;
  --border-hover: #d1d5db;
  --primary: #6366f1;
  --primary-light: #818cf8;
  --primary-bg: rgba(99,102,241,0.08);
  --accent: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  --accent-text: #ffffff;
  --shadow: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-hover: 0 4px 12px rgba(0,0,0,0.1), 0 2px 6px rgba(0,0,0,0.06);
  --shadow-lg: 0 10px 30px rgba(0,0,0,0.08), 0 4px 12px rgba(0,0,0,0.04);
  --radius: 12px;
  --radius-sm: 8px;
  --radius-lg: 16px;
  --transition: 0.2s ease;
  --max-width: 1200px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans SC", "PingFang SC", "Microsoft YaHei", sans-serif;
  --font-mono: "SF Mono", "Fira Code", "Cascadia Code", "JetBrains Mono", Consolas, monospace;
}

[data-theme="dark"] {
  --bg: #0d0d17;
  --bg-card: #181828;
  --bg-hover: #20203a;
  --bg-input: #1a1a2e;
  --bg-header: rgba(13,13,23,0.85);
  --bg-tag: #252540;
  --text: #e2e2ef;
  --text-secondary: #9298b8;
  --text-muted: #6b7196;
  --border: #2a2a40;
  --border-hover: #3a3a55;
  --primary: #818cf8;
  --primary-light: #a5b4fc;
  --primary-bg: rgba(129,140,248,0.12);
  --shadow: 0 1px 3px rgba(0,0,0,0.3), 0 1px 2px rgba(0,0,0,0.2);
  --shadow-hover: 0 4px 12px rgba(0,0,0,0.4), 0 2px 6px rgba(0,0,0,0.3);
  --shadow-lg: 0 10px 30px rgba(0,0,0,0.5), 0 4px 12px rgba(0,0,0,0.3);
}

/* ===== Reset ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
  transition: background 0.3s, color 0.3s;
}
a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }
input, textarea { font-family: inherit; }
kbd {
  font-family: var(--font-mono);
  font-size: 12px;
  padding: 2px 6px;
  border-radius: 4px;
  background: var(--bg-tag);
  color: var(--text-muted);
  border: 1px solid var(--border);
}

/* ===== Header ===== */
.header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--bg-header);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}
.header-inner {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 0 20px;
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
}
.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 20px;
  white-space: nowrap;
}
.logo-icon { font-size: 28px; }
.logo-text {
  background: var(--accent);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.header-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1;
  justify-content: flex-end;
}
.search-box {
  position: relative;
  display: flex;
  align-items: center;
  max-width: 400px;
  width: 100%;
}
.search-icon {
  position: absolute;
  left: 12px;
  color: var(--text-muted);
  pointer-events: none;
}
.search-box input {
  width: 100%;
  height: 40px;
  padding: 0 40px 0 40px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  color: var(--text);
  font-size: 14px;
  outline: none;
  transition: var(--transition);
}
.search-box input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-bg);
}
.search-kbd {
  position: absolute;
  right: 10px;
  pointer-events: none;
}
.theme-toggle {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-card);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
  flex-shrink: 0;
}
.theme-toggle:hover {
  border-color: var(--border-hover);
  background: var(--bg-hover);
}
.icon-moon { display: none; }
[data-theme="dark"] .icon-sun { display: none; }
[data-theme="dark"] .icon-moon { display: block; }

/* ===== Main Tabs ===== */
.main-tabs {
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 64px;
  z-index: 90;
}
.tabs-inner {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 0 20px;
  display: flex;
  gap: 4px;
}
.tab-btn {
  padding: 12px 20px;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 15px;
  font-weight: 500;
  color: var(--text-secondary);
  border-bottom: 2px solid transparent;
  transition: var(--transition);
}
.tab-btn:hover { color: var(--text); }
.tab-btn.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

/* ===== Views ===== */
main { display: none; }
main.active { display: block; }

/* ===== Category Bar ===== */
.category-bar {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 20px 20px 0;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.cat-btn {
  padding: 6px 16px;
  border-radius: 20px;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-secondary);
  background: var(--bg-tag);
  transition: var(--transition);
  white-space: nowrap;
}
.cat-btn:hover { color: var(--text); background: var(--border); }
.cat-btn.active {
  background: var(--accent);
  color: var(--accent-text);
}

/* ===== Links Grid ===== */
.links-container {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 20px;
}
.link-section { margin-bottom: 32px; }
.link-section-title {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 14px;
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
}
.link-section-title .section-icon { font-size: 20px; }
.links-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 12px;
}
.link-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  transition: var(--transition);
  position: relative;
  overflow: hidden;
}
.link-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: var(--accent);
  transform: scaleX(0);
  transform-origin: left;
  transition: transform 0.3s;
}
.link-card:hover {
  border-color: var(--border-hover);
  box-shadow: var(--shadow-hover);
  transform: translateY(-2px);
}
.link-card:hover::before { transform: scaleX(1); }
.link-card-featured {
  border-color: var(--primary);
  background: var(--primary-bg);
}
.link-card-featured::before { transform: scaleX(1); }
.link-card-featured .link-icon { background: var(--primary); }
.link-card-featured .link-name { color: var(--primary); }
.link-icon {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  flex-shrink: 0;
  background: var(--bg-tag);
}
.link-info { min-width: 0; flex: 1; }
.link-name {
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.link-desc {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ===== No Results ===== */
.no-results {
  text-align: center;
  padding: 80px 20px;
  color: var(--text-muted);
}
.no-results p { margin-top: 12px; font-size: 16px; }

/* ===== Tools View ===== */
.tool-tabs {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 20px 20px 0;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.tool-tab {
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 500;
  color: var(--text-secondary);
  background: var(--bg-card);
  border: 1px solid var(--border);
  transition: var(--transition);
  display: flex;
  align-items: center;
  gap: 6px;
}
.tool-tab:hover { border-color: var(--border-hover); color: var(--text); }
.tool-tab.active {
  background: var(--accent);
  color: var(--accent-text);
  border-color: transparent;
}
.tool-content {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 20px;
}
.tool-panel {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow);
}
.tool-panel-title {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 4px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.tool-panel-desc {
  font-size: 14px;
  color: var(--text-secondary);
  margin-bottom: 20px;
}
.tool-row {
  display: flex;
  gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
  align-items: center;
}
.tool-textarea {
  width: 100%;
  min-height: 160px;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  color: var(--text);
  font-size: 14px;
  font-family: var(--font-mono);
  resize: vertical;
  outline: none;
  transition: var(--transition);
}
.tool-textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-bg);
}
.tool-input {
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  color: var(--text);
  font-size: 14px;
  outline: none;
  transition: var(--transition);
  flex: 1;
  min-width: 120px;
}
.tool-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-bg);
}
.tool-btn {
  padding: 10px 20px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
  background: var(--accent);
  color: var(--accent-text);
  transition: var(--transition);
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.tool-btn:hover { opacity: 0.9; transform: translateY(-1px); }
.tool-btn.secondary {
  background: var(--bg-tag);
  color: var(--text);
  border: 1px solid var(--border);
}
.tool-btn.secondary:hover { background: var(--border); }
.tool-output {
  width: 100%;
  min-height: 80px;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  font-family: var(--font-mono);
  white-space: pre-wrap;
  word-break: break-all;
  margin-top: 8px;
}
.tool-label {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-secondary);
  min-width: 80px;
}
.tool-select {
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  color: var(--text);
  font-size: 14px;
  outline: none;
}
.tool-result-box {
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  font-family: var(--font-mono);
  font-size: 14px;
  word-break: break-all;
  margin-top: 8px;
}
.tool-stat {
  display: flex;
  justify-content: space-between;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}
.tool-stat:last-child { border-bottom: none; }
.tool-stat-label { color: var(--text-secondary); }
.tool-stat-value { font-weight: 600; font-family: var(--font-mono); }
.color-preview {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-sm);
  border: 2px solid var(--border);
  flex-shrink: 0;
}

/* ===== Footer ===== */
.footer {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-muted);
  font-size: 14px;
}
.footer a { color: var(--primary); }
.footer a:hover { text-decoration: underline; }

/* ===== Responsive ===== */
@media (max-width: 768px) {
  .header-inner { padding: 0 12px; gap: 8px; }
  .logo-text { display: none; }
  .search-box { max-width: none; }
  .search-kbd { display: none; }
  .tabs-inner { padding: 0 12px; }
  .tab-btn { padding: 10px 14px; font-size: 14px; }
  .category-bar { padding: 16px 12px 0; }
  .links-container { padding: 16px 12px; }
  .links-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
  .link-card { padding: 12px; }
  .tool-tabs { padding: 16px 12px 0; }
  .tool-content { padding: 16px 12px; }
  .tool-panel { padding: 16px; }
}
@media (max-width: 480px) {
  .links-grid { grid-template-columns: 1fr; }
}

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

/* ===== Animations ===== */
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
.link-card, .tool-panel { animation: fadeIn 0.3s ease; }
