:root {
  --bg: #0b0f19;
  --bg-elevated: #111827;
  --bg-card: #1a2234;
  --bg-hover: #243044;
  --border: #2a3548;
  --text: #e5e7eb;
  --text-muted: #9ca3af;
  --text-dim: #6b7280;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --accent-soft: rgba(59, 130, 246, 0.15);
  --success: #22c55e;
  --danger: #ef4444;
  --warning: #f59e0b;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
  --font: 'Inter', system-ui, -apple-system, sans-serif;
  --mono: 'JetBrains Mono', 'Fira Code', monospace;
}

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

html {
  scroll-behavior: smooth;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
}

a {
  color: inherit;
  text-decoration: none;
}

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 20px;
}

/* Header */
.header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(11, 15, 25, 0.85);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 64px;
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 1.25rem;
}

.logo-icon {
  font-size: 1.5rem;
}

.logo-text .accent {
  color: var(--accent);
}

.nav {
  display: flex;
  gap: 28px;
}

.nav a {
  color: var(--text-muted);
  font-size: 0.95rem;
  font-weight: 500;
  transition: color 0.2s;
}

.nav a:hover {
  color: var(--text);
}

.icon-btn {
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text);
  width: 40px;
  height: 40px;
  border-radius: 10px;
  cursor: pointer;
  font-size: 1.1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

.icon-btn:hover {
  background: var(--bg-hover);
}

/* Hero */
.hero {
  padding: 80px 0 60px;
  text-align: center;
  background: radial-gradient(ellipse at top, rgba(59, 130, 246, 0.12) 0%, transparent 60%);
}

.hero h1 {
  font-size: clamp(2rem, 5vw, 3.2rem);
  font-weight: 700;
  letter-spacing: -0.03em;
  margin-bottom: 12px;
  background: linear-gradient(135deg, #fff 0%, #93c5fd 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.hero-sub {
  color: var(--text-muted);
  font-size: 1.15rem;
  margin-bottom: 36px;
}

.search-box {
  position: relative;
  max-width: 640px;
  margin: 0 auto 40px;
}

.search-box input {
  width: 100%;
  padding: 16px 20px 16px 52px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 14px;
  color: var(--text);
  font-size: 1rem;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.search-box input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.search-box input::placeholder {
  color: var(--text-dim);
}

.search-icon {
  position: absolute;
  left: 18px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-dim);
}

.search-box kbd {
  position: absolute;
  right: 16px;
  top: 50%;
  transform: translateY(-50%);
  background: var(--bg-card);
  border: 1px solid var(--border);
  padding: 4px 8px;
  border-radius: 6px;
  font-size: 0.75rem;
  color: var(--text-dim);
  font-family: var(--font);
}

.hero-stats {
  display: flex;
  justify-content: center;
  gap: 48px;
}

.stat {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.stat-num {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--accent);
}

.stat-label {
  font-size: 0.85rem;
  color: var(--text-muted);
}

/* Sections */
.section {
  padding: 60px 0;
}

.section-alt {
  background: var(--bg-elevated);
}

.section-title {
  font-size: 1.75rem;
  font-weight: 700;
  margin-bottom: 8px;
  letter-spacing: -0.02em;
}

.section-sub {
  color: var(--text-muted);
  margin-bottom: 32px;
}

/* Tools Grid */
.tools-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px;
}

.tool-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.tool-card:hover {
  background: var(--bg-hover);
  border-color: var(--accent);
  transform: translateY(-2px);
  box-shadow: var(--shadow);
}

.tool-card .tool-icon {
  font-size: 1.6rem;
  margin-bottom: 4px;
}

.tool-card .tool-name {
  font-weight: 600;
  font-size: 0.95rem;
}

.tool-card .tool-desc {
  font-size: 0.8rem;
  color: var(--text-muted);
  line-height: 1.4;
}

.tool-card .tool-badge {
  display: inline-block;
  font-size: 0.7rem;
  padding: 2px 8px;
  border-radius: 20px;
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 500;
  margin-top: 4px;
  width: fit-content;
}

.tool-card.working .tool-badge {
  background: rgba(34, 197, 94, 0.15);
  color: var(--success);
}

/* Categories */
.categories-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 14px;
}

.category-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px 18px;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s;
}

.category-card:hover {
  border-color: var(--accent);
  background: var(--bg-hover);
}

.category-card .cat-icon {
  font-size: 2rem;
  margin-bottom: 10px;
}

.category-card .cat-name {
  font-weight: 600;
  margin-bottom: 4px;
}

.category-card .cat-count {
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* Filter bar */
.filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 28px;
}

.filter-btn {
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 8px 16px;
  border-radius: 20px;
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
}

.filter-btn:hover,
.filter-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}

/* Modal */
.modal {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  z-index: 200;
  align-items: center;
  justify-content: center;
  padding: 20px;
  backdrop-filter: blur(4px);
}

.modal.open {
  display: flex;
}

.modal-content {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 16px;
  width: 100%;
  max-width: 900px;
  max-height: 90vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 24px;
  border-bottom: 1px solid var(--border);
}

.modal-header h3 {
  font-size: 1.2rem;
  font-weight: 600;
}

.modal-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.8rem;
  cursor: pointer;
  line-height: 1;
  padding: 0 6px;
}

.modal-close:hover {
  color: var(--text);
}

.modal-body {
  padding: 24px;
  overflow-y: auto;
  flex: 1;
}

/* Tool UI common styles */
.tool-ui {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.tool-ui label {
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: 6px;
  display: block;
}

.tool-ui textarea,
.tool-ui input[type="text"],
.tool-ui input[type="number"],
.tool-ui input[type="color"],
.tool-ui input[type="datetime-local"],
.tool-ui select {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: 12px 14px;
  font-family: var(--mono);
  font-size: 0.9rem;
  outline: none;
  transition: border-color 0.2s;
}

.tool-ui textarea:focus,
.tool-ui input:focus,
.tool-ui select:focus {
  border-color: var(--accent);
}

.tool-ui textarea {
  min-height: 160px;
  resize: vertical;
  line-height: 1.5;
}

.tool-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.btn {
  background: var(--accent);
  color: white;
  border: none;
  padding: 10px 20px;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  transition: background 0.2s;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.btn:hover {
  background: var(--accent-hover);
}

.btn-secondary {
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text);
}

.btn-secondary:hover {
  background: var(--bg-hover);
}

.btn-success {
  background: var(--success);
}

.btn-danger {
  background: var(--danger);
}

.tool-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

@media (max-width: 700px) {
  .tool-row {
    grid-template-columns: 1fr;
  }
}

.output-box {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px;
  font-family: var(--mono);
  font-size: 0.9rem;
  white-space: pre-wrap;
  word-break: break-all;
  min-height: 80px;
  max-height: 300px;
  overflow-y: auto;
}

.checkbox-group {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
}

.checkbox-group label {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-size: 0.9rem;
  color: var(--text);
}

.checkbox-group input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
}

.range-group {
  display: flex;
  align-items: center;
  gap: 12px;
}

.range-group input[type="range"] {
  flex: 1;
  accent-color: var(--accent);
}

.stats-row {
  display: flex;
  gap: 20px;
  flex-wrap: wrap;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.stats-row strong {
  color: var(--text);
}

/* Footer */
.footer {
  background: var(--bg-elevated);
  border-top: 1px solid var(--border);
  padding: 50px 0 30px;
  margin-top: 40px;
}

.footer-grid {
  display: grid;
  grid-template-columns: 2fr 1fr 1fr;
  gap: 40px;
  margin-bottom: 40px;
}

.footer-desc {
  color: var(--text-muted);
  margin-top: 12px;
  font-size: 0.9rem;
  max-width: 300px;
}

.footer h4 {
  font-size: 0.95rem;
  margin-bottom: 14px;
  color: var(--text);
}

.footer ul {
  list-style: none;
}

.footer ul li {
  margin-bottom: 8px;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.footer ul a:hover {
  color: var(--accent);
}

.footer-bottom {
  border-top: 1px solid var(--border);
  padding-top: 24px;
  text-align: center;
  color: var(--text-dim);
  font-size: 0.85rem;
}

/* Responsive */
@media (max-width: 768px) {
  .nav {
    display: none;
  }
  
  .hero {
    padding: 50px 0 40px;
  }
  
  .hero-stats {
    gap: 28px;
  }
  
  .footer-grid {
    grid-template-columns: 1fr;
    gap: 30px;
  }
  
  .tools-grid {
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  }
}

/* Utility */
.hidden {
  display: none !important;
}

.success-msg {
  color: var(--success);
  font-size: 0.85rem;
  margin-top: 8px;
}

.error-msg {
  color: var(--danger);
  font-size: 0.85rem;
  margin-top: 8px;
}

/* ========== Light Theme ========== */
[data-theme="light"] {
  --bg: #f4f6fb;
  --bg-elevated: #ffffff;
  --bg-card: #ffffff;
  --bg-hover: #eef2f7;
  --border: #d8dee9;
  --text: #1e293b;
  --text-muted: #64748b;
  --text-dim: #94a3b8;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-soft: rgba(37, 99, 235, 0.12);
  --success: #16a34a;
  --danger: #dc2626;
  --warning: #d97706;
  --shadow: 0 4px 24px rgba(15, 23, 42, 0.08);
}

[data-theme="light"] .header {
  background: rgba(255, 255, 255, 0.9);
}

[data-theme="light"] .hero {
  background: radial-gradient(ellipse at top, rgba(37, 99, 235, 0.08) 0%, transparent 60%);
}

[data-theme="light"] .hero h1 {
  background: linear-gradient(135deg, #0f172a 0%, #2563eb 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

[data-theme="light"] .tool-card,
[data-theme="light"] .cat-card,
[data-theme="light"] .modal-content,
[data-theme="light"] .search-box input,
[data-theme="light"] textarea,
[data-theme="light"] input,
[data-theme="light"] select {
  background: var(--bg-card);
  color: var(--text);
}

[data-theme="light"] .output-box {
  background: #f1f5f9;
  color: var(--text);
}

[data-theme="light"] .badge-working {
  background: rgba(22, 163, 74, 0.12);
  color: #16a34a;
}


/* Search dropdown — results stay under input, no forced scroll */
.search-box { position: relative; }
.search-dropdown {
  display: none;
  position: absolute;
  left: 0;
  right: 0;
  top: calc(100% + 8px);
  z-index: 50;
  max-height: 360px;
  overflow-y: auto;
  background: var(--bg-card, #121a2b);
  border: 1px solid var(--border, #2a3548);
  border-radius: 12px;
  box-shadow: 0 12px 40px rgba(0,0,0,0.45);
  padding: 6px;
}
.search-dropdown.open { display: block; }
.search-dropdown-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  text-align: left;
  padding: 10px 12px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--text, #e8eef7);
  cursor: pointer;
  font: inherit;
}
.search-dropdown-item:hover,
.search-dropdown-item:focus {
  background: var(--bg-hover, #1a2438);
  outline: none;
}
.search-dd-icon { font-size: 1.25rem; flex-shrink: 0; }
.search-dd-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.search-dd-text strong { font-size: 0.95rem; font-weight: 600; }
.search-dd-text small {
  font-size: 0.78rem;
  color: var(--text-muted, #8b9bb4);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.search-dropdown-empty {
  padding: 16px;
  text-align: center;
  color: var(--text-muted, #8b9bb4);
  font-size: 0.9rem;
}


/* Mobile category accordion — less scrolling */
.empty-tools {
  color: var(--text-muted);
  text-align: center;
  padding: 24px;
  grid-column: 1 / -1;
}
.cat-group {
  grid-column: 1 / -1;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg-card);
  margin-bottom: 10px;
  overflow: hidden;
}
.cat-group-header {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border: none;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  text-align: left;
}
.cat-group-left {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}
.cat-group-icon { font-size: 1.25rem; }
.cat-group-name { font-size: 0.95rem; }
.cat-group-count {
  font-size: 0.75rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(59, 130, 246, 0.15);
  color: var(--accent, #3b82f6);
}
.cat-group-chevron {
  font-size: 0.7rem;
  opacity: 0.6;
  transition: transform 0.2s;
}
.cat-group.open .cat-group-chevron { transform: rotate(180deg); }
.cat-group-body {
  display: none;
  padding: 0 12px 12px;
}
.cat-group.open .cat-group-body { display: block; }
.cat-group-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 10px;
}

@media (max-width: 768px) {
  .filter-bar-sticky {
    position: sticky;
    top: 56px;
    z-index: 40;
    background: var(--bg, #0b0f19);
    padding: 10px 0;
    margin: 0 -4px 12px;
    overflow-x: auto;
    flex-wrap: nowrap;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .filter-bar-sticky::-webkit-scrollbar { display: none; }
  .filter-bar-sticky .filter-btn {
    flex-shrink: 0;
    white-space: nowrap;
  }
  #all-tools .tools-grid {
    display: block;
  }
  .section-title { font-size: 1.35rem; }
  .tool-card { padding: 14px; }
  /* Popular: fewer columns feel denser */
  #popular .tools-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
  }
  .categories-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
  }
}

@media (min-width: 769px) {
  .cat-group { border: none; background: transparent; margin: 0; }
  .cat-group-header { display: none; }
  .cat-group-body { display: contents !important; }
}

/* Tool help / SEO block under modal UI */
.tool-guide {
  margin-top: 28px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 0.92rem;
  line-height: 1.65;
}
.tool-guide h3 {
  color: var(--text);
  font-size: 1rem;
  margin: 16px 0 8px;
}
.tool-guide p { margin-bottom: 10px; }
.tool-guide ol, .tool-guide ul {
  padding-left: 1.25rem;
  margin: 0 0 12px;
}
.tool-guide li { margin-bottom: 6px; }
.tool-guide-note {
  font-size: 0.8rem;
  opacity: 0.85;
  margin-top: 12px;
}

.tool-loading {
  padding: 48px 20px;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.95rem;
}
