/* =============================================
   TOOLSITE — Main Stylesheet
   Pure CSS, no frameworks, no CDN
   ============================================= */

/* ── Custom Properties ─────────────────────── */
:root {
  /* Spacing scale */
  --space-xs:   0.25rem;
  --space-sm:   0.5rem;
  --space-md:   1rem;
  --space-lg:   1.5rem;
  --space-xl:   2.5rem;
  --space-2xl:  4rem;

  /* Typography */
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
               Helvetica, Arial, sans-serif;
  --font-mono: ui-monospace, "Cascadia Code", "Source Code Pro", monospace;
  --text-sm:   0.875rem;
  --text-base: 1rem;
  --text-lg:   1.125rem;
  --text-xl:   1.375rem;
  --text-2xl:  1.75rem;
  --text-3xl:  2.25rem;

  /* Radius */
  --radius-sm:  0.375rem;
  --radius-md:  0.625rem;
  --radius-lg:  1rem;
  --radius-full: 9999px;

  /* Transitions */
  --transition: 200ms ease;

  /* Layout */
  --max-width: 1200px;
  --header-h:  60px;
}

/* ── Light Theme (default) ─────────────────── */
:root,
[data-theme="light"] {
  --bg:           #ffffff;
  --bg-subtle:    #f5f5f7;
  --bg-card:      #ffffff;
  --border:       #e5e5ea;
  --border-focus: #0071e3;

  --text-primary:   #1d1d1f;
  --text-secondary: #6e6e73;
  --text-tertiary:  #aeaeb2;

  --accent:       #0071e3;
  --accent-hover: #0077ed;
  --accent-text:  #ffffff;

  --tag-bg:       #e5e5ea;
  --tag-text:     #1d1d1f;
  --tag-active-bg: #0071e3;
  --tag-active-text: #ffffff;

  --shadow-sm: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.05);
  --shadow-md: 0 4px 12px rgba(0,0,0,.08), 0 2px 4px rgba(0,0,0,.05);
  --shadow-lg: 0 12px 32px rgba(0,0,0,.10);

  --cookie-bg: #1d1d1f;
  --cookie-text: #f5f5f7;
}

/* ── Dark Theme ────────────────────────────── */
[data-theme="dark"] {
  --bg:           #000000;
  --bg-subtle:    #111111;
  --bg-card:      #1c1c1e;
  --border:       #2c2c2e;
  --border-focus: #0a84ff;

  --text-primary:   #f5f5f7;
  --text-secondary: #98989d;
  --text-tertiary:  #636366;

  --accent:       #0a84ff;
  --accent-hover: #409cff;
  --accent-text:  #ffffff;

  --tag-bg:       #2c2c2e;
  --tag-text:     #f5f5f7;
  --tag-active-bg: #0a84ff;
  --tag-active-text: #ffffff;

  --shadow-sm: 0 1px 3px rgba(0,0,0,.4);
  --shadow-md: 0 4px 12px rgba(0,0,0,.4);
  --shadow-lg: 0 12px 32px rgba(0,0,0,.5);

  --cookie-bg: #1c1c1e;
  --cookie-text: #f5f5f7;
}

/* ── System preference fallback ────────────── */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg:           #000000;
    --bg-subtle:    #111111;
    --bg-card:      #1c1c1e;
    --border:       #2c2c2e;
    --border-focus: #0a84ff;
    --text-primary:   #f5f5f7;
    --text-secondary: #98989d;
    --text-tertiary:  #636366;
    --accent:       #0a84ff;
    --accent-hover: #409cff;
    --accent-text:  #ffffff;
    --tag-bg:       #2c2c2e;
    --tag-text:     #f5f5f7;
    --tag-active-bg: #0a84ff;
    --tag-active-text: #ffffff;
    --shadow-sm: 0 1px 3px rgba(0,0,0,.4);
    --shadow-md: 0 4px 12px rgba(0,0,0,.4);
    --shadow-lg: 0 12px 32px rgba(0,0,0,.5);
  }
}

/* ── Reset ─────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
  font-size: 16px;
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: 1.6;
  background: var(--bg);
  color: var(--text-primary);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  transition: background var(--transition), color var(--transition);
}

img, svg { display: block; max-width: 100%; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
button { cursor: pointer; font-family: inherit; }
ul, ol { list-style: none; }

/* ── Layout helpers ────────────────────────── */
.container {
  width: 100%;
  max-width: var(--max-width);
  margin-inline: auto;
  padding-inline: var(--space-lg);
}

.sr-only {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}

/* ── Header ────────────────────────────────── */
.site-header {
  position: sticky;
  top: 0;
  z-index: 100;
  height: var(--header-h);
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  transition: background var(--transition);
}

.site-header .container {
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-md);
}

.site-logo {
  font-size: var(--text-lg);
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.02em;
  text-decoration: none;
  flex-shrink: 0;
}
.site-logo:hover { text-decoration: none; }
.site-logo span { color: var(--accent); }

.header-nav {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

.header-nav a {
  font-size: var(--text-sm);
  color: var(--text-secondary);
  padding: var(--space-xs) var(--space-sm);
  border-radius: var(--radius-sm);
  transition: color var(--transition), background var(--transition);
}
.header-nav a:hover {
  color: var(--text-primary);
  background: var(--bg-subtle);
  text-decoration: none;
}

/* Theme toggle button */
.btn-theme {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  background: var(--bg-subtle);
  color: var(--text-secondary);
  transition: all var(--transition);
  padding: 0;
}
.btn-theme:hover {
  background: var(--border);
  color: var(--text-primary);
}
.btn-theme svg { width: 18px; height: 18px; pointer-events: none; }
.icon-sun  { display: none; }
.icon-moon { display: block; }
[data-theme="dark"] .icon-sun  { display: block; }
[data-theme="dark"] .icon-moon { display: none; }

/* ── Hero ──────────────────────────────────── */
.hero {
  padding: var(--space-2xl) 0 var(--space-xl);
  text-align: center;
}

.hero-title {
  font-size: clamp(var(--text-2xl), 5vw, var(--text-3xl));
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1.15;
  margin-bottom: var(--space-sm);
  color: var(--text-primary);
}
.hero-title span { color: var(--accent); }

.hero-sub {
  font-size: var(--text-lg);
  color: var(--text-secondary);
  margin-bottom: var(--space-xl);
  max-width: 540px;
  margin-inline: auto;
}

/* ── Search ────────────────────────────────── */
.search-wrap {
  position: relative;
  max-width: 520px;
  margin-inline: auto;
}

.search-wrap svg {
  position: absolute;
  left: var(--space-md);
  top: 50%;
  transform: translateY(-50%);
  width: 18px;
  height: 18px;
  color: var(--text-tertiary);
  pointer-events: none;
}

#tool-search {
  width: 100%;
  padding: 0.75rem var(--space-md) 0.75rem 2.75rem;
  font-size: var(--text-base);
  font-family: inherit;
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  color: var(--text-primary);
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
}
#tool-search::placeholder { color: var(--text-tertiary); }
#tool-search:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 20%, transparent);
  background: var(--bg-card);
}

/* ── Ad banner (top) ───────────────────────── */
.ad-banner {
  background: var(--bg-subtle);
  border: 1px dashed var(--border);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-tertiary);
  font-size: var(--text-sm);
  font-style: italic;
  min-height: 90px;
  margin-block: var(--space-lg);
  overflow: hidden;
}
.ad-banner--leaderboard { min-height: 90px; }
.ad-banner--rectangle   { min-height: 250px; max-width: 300px; }

/* ── Category tabs ─────────────────────────── */
.categories {
  padding-block: var(--space-lg);
}

.category-list {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-sm);
  justify-content: center;
}

.category-btn {
  padding: 0.375rem 0.875rem;
  font-size: var(--text-sm);
  font-weight: 500;
  border-radius: var(--radius-full);
  border: 1px solid var(--border);
  background: var(--tag-bg);
  color: var(--tag-text);
  transition: all var(--transition);
  white-space: nowrap;
}
.category-btn:hover {
  background: var(--border);
}
.category-btn.active,
.category-btn[aria-pressed="true"] {
  background: var(--tag-active-bg);
  color: var(--tag-active-text);
  border-color: var(--tag-active-bg);
}

/* ── Tools section ─────────────────────────── */
.tools-section {
  padding-bottom: var(--space-2xl);
  flex: 1;
}

.section-header {
  display: flex;
  align-items: baseline;
  gap: var(--space-sm);
  margin-bottom: var(--space-lg);
}

.section-title {
  font-size: var(--text-xl);
  font-weight: 600;
  letter-spacing: -0.02em;
}

.tool-count {
  font-size: var(--text-sm);
  color: var(--text-tertiary);
}

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

/* Tool card */
.tool-card {
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
  padding: var(--space-lg);
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  text-decoration: none;
  color: inherit;
  box-shadow: var(--shadow-sm);
  transition: transform var(--transition), box-shadow var(--transition),
              border-color var(--transition);
  cursor: pointer;
}
.tool-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
  border-color: var(--accent);
  text-decoration: none;
}

.tool-icon {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-md);
  background: var(--bg-subtle);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
  flex-shrink: 0;
}

.tool-name {
  font-size: var(--text-base);
  font-weight: 600;
  color: var(--text-primary);
  line-height: 1.3;
}

.tool-desc {
  font-size: var(--text-sm);
  color: var(--text-secondary);
  line-height: 1.5;
  flex: 1;
}

.tool-tag {
  display: inline-block;
  font-size: 0.75rem;
  font-weight: 500;
  padding: 0.1875rem 0.5rem;
  border-radius: var(--radius-full);
  background: var(--tag-bg);
  color: var(--text-secondary);
  align-self: flex-start;
}

/* Empty state */
.tools-empty {
  grid-column: 1 / -1;
  text-align: center;
  padding: var(--space-2xl);
  color: var(--text-secondary);
}
.tools-empty p { margin-bottom: var(--space-sm); }
.tools-empty strong { color: var(--text-primary); }

/* Hidden card (search/filter) */
.tool-card[hidden] { display: none; }

/* ── Footer ────────────────────────────────── */
.site-footer {
  background: var(--bg-subtle);
  border-top: 1px solid var(--border);
  padding-block: var(--space-xl);
  font-size: var(--text-sm);
  color: var(--text-secondary);
}

.footer-inner {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-lg);
  justify-content: space-between;
  align-items: center;
}

.footer-links {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-md);
}
.footer-links a { color: var(--text-secondary); }
.footer-links a:hover { color: var(--text-primary); }

/* ── Cookie Banner ─────────────────────────── */
#cookie-banner {
  position: fixed;
  bottom: var(--space-md);
  left: 50%;
  transform: translateX(-50%);
  width: calc(100% - 2 * var(--space-lg));
  max-width: 680px;
  background: var(--cookie-bg);
  color: var(--cookie-text);
  padding: var(--space-lg);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  z-index: 9999;
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-md);
  align-items: center;
  justify-content: space-between;
  font-size: var(--text-sm);
}
#cookie-banner[hidden] { display: none; }

#cookie-banner p { flex: 1; min-width: 200px; line-height: 1.5; }
#cookie-banner a { color: #6c9ef8; }

.cookie-actions {
  display: flex;
  gap: var(--space-sm);
  flex-shrink: 0;
  flex-wrap: wrap;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.5rem 1rem;
  border-radius: var(--radius-sm);
  font-size: var(--text-sm);
  font-weight: 500;
  border: 1px solid transparent;
  transition: all var(--transition);
  white-space: nowrap;
}

.btn-primary {
  background: var(--accent);
  color: var(--accent-text);
  border-color: var(--accent);
}
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }

.btn-secondary {
  background: transparent;
  color: var(--cookie-text);
  border-color: rgba(255,255,255,.25);
}
.btn-secondary:hover { background: rgba(255,255,255,.1); }

/* ── Responsive ────────────────────────────── */
@media (max-width: 768px) {
  .hero { padding: var(--space-xl) 0 var(--space-lg); }
  .header-nav .nav-link { display: none; }
  .tools-grid {
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  }
  .footer-inner { flex-direction: column; align-items: flex-start; }
}

@media (max-width: 480px) {
  :root { --space-lg: 1rem; }
  .tools-grid { grid-template-columns: 1fr 1fr; }
  .tool-card { padding: var(--space-md); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: 0.01ms !important; }
  html { scroll-behavior: auto; }
}
