<%- include('partials/public-header') %>

<style>
  *, *::before, *::after {
    box-sizing: border-box;
  }

  /* ── HERO SECTION ── */
  .hero-container {
    position: relative;
    overflow: hidden;
    padding: clamp(32px, 5vw, 48px) 0 20px;
  }

  .ambient-glow {
    position: absolute;
    top: -100px;
    left: 50%;
    transform: translateX(-50%);
    width: min(580px, 92vw);
    height: 320px;
    background: radial-gradient(circle, rgba(59, 130, 246, 0.22) 0%, rgba(16, 185, 129, 0.12) 50%, transparent 75%);
    filter: blur(70px);
    z-index: 0;
    pointer-events: none;
  }
  [data-theme="light"] .ambient-glow {
    background: radial-gradient(circle, rgba(37, 99, 235, 0.12) 0%, rgba(16, 185, 129, 0.06) 50%, transparent 75%);
  }

  .hero-content {
    position: relative;
    z-index: 1;
    text-align: center;
  }

  .hero-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 5px 14px;
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    color: var(--badge-text);
    border-radius: 30px;
    font-size: 0.8rem;
    font-weight: 700;
    margin-bottom: 14px;
  }

  .hero-content h1 {
    font-size: clamp(2rem, 5vw, 3.2rem);
    font-weight: 900;
    line-height: 1.15;
    letter-spacing: -0.035em;
    margin-bottom: 12px;
    color: var(--text);
    text-wrap: balance;
  }

  .hero-content h1 span {
    background: linear-gradient(135deg, #60a5fa 0%, #34d399 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    display: inline;
  }

  .hero-content p {
    color: var(--text-muted);
    font-size: clamp(0.95rem, 2vw, 1.05rem);
    max-width: 580px;
    margin: 0 auto 26px;
    line-height: 1.6;
    text-wrap: balance;
  }

  /* ── SEARCH BOX ── */
  .search-wrapper {
    max-width: 580px;
    margin: 0 auto 24px;
    position: relative;
  }

  .search-box-wrap {
    position: relative;
    display: flex;
    align-items: center;
  }

  .search-icon-svg {
    position: absolute;
    left: 18px;
    color: var(--text-muted);
    pointer-events: none;
    display: flex;
  }

  .search-input {
    width: 100%;
    height: 52px;
    padding: 0 75px 0 48px;
    font-size: 0.96rem;
    font-family: inherit;
    color: var(--text);
    background: var(--surface);
    border: 1.5px solid var(--border);
    border-radius: 14px;
    outline: none;
    box-shadow: 0 8px 24px -6px rgba(0, 0, 0, 0.35);
    transition: all 0.2s ease;
  }

  .search-input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 4px var(--primary-glow), 0 12px 28px -4px rgba(0, 0, 0, 0.4);
  }

  .search-actions {
    position: absolute;
    right: 12px;
    display: flex;
    align-items: center;
    gap: 6px;
  }

  .clear-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    padding: 4px;
    cursor: pointer;
    display: none;
    border-radius: 50%;
  }
  .clear-btn:hover { color: var(--text); }

  .kbd-shortcut {
    background: var(--glass-bg);
    border: 1px solid var(--border);
    color: var(--text-muted);
    font-size: 0.72rem;
    font-weight: 700;
    padding: 3px 7px;
    border-radius: 5px;
    user-select: none;
  }

  /* ── HORIZONTAL CATEGORY FILTER PILLS ── */
  .filter-pills {
    display: flex;
    gap: 8px;
    margin-bottom: 28px;
    overflow-x: auto;
    scrollbar-width: none;
    padding: 4px 0;
    justify-content: flex-start;
  }
  .filter-pills::-webkit-scrollbar { display: none; }

  @media (min-width: 680px) {
    .filter-pills { justify-content: center; flex-wrap: wrap; }
  }

  .pill-btn {
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text-muted);
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    transition: all 0.2s ease;
    flex-shrink: 0;
    font-family: inherit;
    text-decoration: none !important;
  }

  .pill-btn:hover { border-color: var(--primary); color: var(--text); }
  .pill-btn.active {
    background: var(--primary);
    color: #ffffff !important;
    border-color: var(--primary);
    box-shadow: 0 4px 12px var(--primary-glow);
  }
  .pill-btn.active svg { color: #ffffff !important; }

  /* ── GRID AD SLOT (IF CONFIGURED) ── */
  .grid-ad-box {
    background: var(--surface);
    border: 1px dashed var(--border);
    border-radius: var(--radius);
    padding: 12px;
    text-align: center;
    margin-bottom: 24px;
  }

  /* ── TOOLS GRID (RESPONSIVE CARDS) ── */
  .tools-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 20px;
    margin-bottom: 60px;
  }

  @media (min-width: 600px) {
    .tools-grid { grid-template-columns: repeat(2, 1fr); }
  }

  @media (min-width: 980px) {
    .tools-grid { grid-template-columns: repeat(3, 1fr); gap: 24px; }
  }

  .tool-card {
    background: var(--surface-card);
    border: 1px solid var(--border);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-radius: var(--radius);
    padding: 22px;
    display: flex;
    flex-direction: column;
    text-decoration: none !important;
    color: inherit;
    box-shadow: 0 8px 20px -6px rgba(0, 0, 0, 0.3);
    transition: transform 0.22s ease, border-color 0.22s ease, box-shadow 0.22s ease;
    position: relative;
  }

  .tool-card:hover, .tool-card:focus-visible {
    transform: translateY(-4px);
    border-color: var(--border-hover);
    box-shadow: 0 16px 32px -8px var(--primary-glow);
    outline: none;
    text-decoration: none !important;
  }

  .card-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
  }

  /* ── DYNAMIC SVG TOOL ICON BOX ── */
  .tool-icon-box {
    width: 48px;
    height: 48px;
    border-radius: 13px;
    background: linear-gradient(135deg, rgba(59, 130, 246, 0.15) 0%, rgba(16, 185, 129, 0.15) 100%);
    border: 1px solid rgba(255, 255, 255, 0.08);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--badge-text);
    box-shadow: inset 0 1px 1px rgba(255, 255, 255, 0.1);
    flex-shrink: 0;
  }
  .tool-icon-box svg {
    width: 24px !important;
    height: 24px !important;
    display: block;
  }

  .tool-tag {
    font-size: 0.72rem;
    font-weight: 700;
    padding: 3px 9px;
    border-radius: 12px;
    background: var(--badge-bg);
    color: var(--badge-text);
    text-transform: uppercase;
    letter-spacing: 0.04em;
  }

  .tool-card h2 {
    font-size: 1.18rem;
    font-weight: 800;
    letter-spacing: -0.02em;
    margin-bottom: 6px;
    color: var(--text);
  }

  /* 2-Line Strict Clamp */
  .tool-card p {
    font-size: 0.88rem;
    color: var(--text-muted);
    line-height: 1.45;
    margin-bottom: 18px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    text-overflow: ellipsis;
    min-height: calc(1.45em * 2);
  }

  /* Bottom Bar */
  .card-bottom {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-top: 14px;
    border-top: 1px solid var(--border);
    margin-top: auto;
  }

  .tool-usage {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    backdrop-filter: blur(8px);
    padding: 5px 10px;
    border-radius: 20px;
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--text-muted);
  }
  .tool-usage svg { color: var(--accent); }

  .open-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: var(--surface-hover);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 6px 12px;
    border-radius: 8px;
    font-size: 0.84rem;
    font-weight: 700;
    transition: all 0.2s ease;
    text-decoration: none !important;
  }

  .open-arrow {
    transition: transform 0.2s ease;
    color: var(--text-muted);
  }

  .tool-card:hover .open-btn {
    background: var(--primary);
    border-color: var(--primary);
    color: #ffffff;
  }

  .tool-card:hover .open-arrow {
    color: #ffffff;
    transform: translate(2px, -2px);
  }

  #noResults {
    grid-column: 1 / -1;
    text-align: center;
    padding: 48px 16px;
    display: none;
    color: var(--text-muted);
    font-size: 1.05rem;
    font-weight: 600;
  }

  @media (max-width: 580px) {
    .kbd-shortcut { display: none; }
    .search-input { padding-right: 44px; }
  }
</style>

<!-- =============================================
     HERO SECTION WITH AMBIENT GLOW
     ============================================= -->
<section class="hero-container">
  <div class="ambient-glow" aria-hidden="true"></div>
  
  <div class="container hero-content">
    <div class="hero-badge">
      <%= (typeof landing !== 'undefined' && landing.heroBadge) ? landing.heroBadge : '⚡ 100% Free & Client-Side Secure' %>
    </div>
    
    <h1>
      <%= (typeof landing !== 'undefined' && landing.heroTitle) ? landing.heroTitle : 'Smarter Online Tools for' %>
      <span>Creators</span>
    </h1>
    
    <p>
      <%= (typeof landing !== 'undefined' && landing.heroSubtitle) ? landing.heroSubtitle : 'Blazing-fast utilities built with privacy, no installations, and zero data tracking.' %>
    </p>

    <!-- Glow Search Box -->
    <div class="search-wrapper">
      <div class="search-box-wrap">
        <span class="search-icon-svg" aria-hidden="true">
          <svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round"><circle cx="11" cy="11" r="8"></circle><line x1="21" y1="21" x2="16.65" y2="16.65"></line></svg>
        </span>
        <input 
          type="search" 
          id="toolSearch" 
          class="search-input" 
          placeholder="<%= (typeof landing !== 'undefined' && landing.searchPlaceholder) ? landing.searchPlaceholder : 'Search tools... (e.g. CSS, JS, Count)' %>" 
          aria-label="Search online tools"
          autocomplete="off"
          spellcheck="false"
        >
        <div class="search-actions">
          <button class="clear-btn" id="clearSearch" aria-label="Clear search">
            <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5"><line x1="18" y1="6" x2="6" y2="18"></line><line x1="6" y1="6" x2="18" y2="18"></line></svg>
          </button>
          <span class="kbd-shortcut" title="Press / to search">/</span>
        </div>
      </div>
    </div>

    <!-- Category Filter Pills -->
    <nav class="filter-pills" aria-label="Tool Categories">
      <button type="button" class="pill-btn active" data-filter="all">
        <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><rect x="3" y="3" width="7" height="7"></rect><rect x="14" y="3" width="7" height="7"></rect><rect x="14" y="14" width="7" height="7"></rect><rect x="3" y="14" width="7" height="7"></rect></svg>
        All Tools
      </button>
      <button type="button" class="pill-btn" data-filter="developer">
        <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><polyline points="16 18 22 12 16 6"></polyline><polyline points="8 6 2 12 8 18"></polyline></svg>
        Developer
      </button>
      <button type="button" class="pill-btn" data-filter="text">
        <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"></path><polyline points="14 2 14 8 20 8"></polyline></svg>
        Text & Content
      </button>
      <button type="button" class="pill-btn" data-filter="security">
        <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10z"></path></svg>
        Security
      </button>
      <button type="button" class="pill-btn" data-filter="image">
        <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><rect x="3" y="3" width="18" height="18" rx="2" ry="2"></rect><circle cx="8.5" cy="8.5" r="1.5"></circle><polyline points="21 15 16 10 5 21"></polyline></svg>
        Image & Media
      </button>
      <button type="button" class="pill-btn" data-filter="utility">
        <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><circle cx="12" cy="12" r="3"></circle><path d="M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 0 1 0 2.83 2 2 0 0 1-2.83 0l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 0 1-2 2 2 2 0 0 1-2-2v-.09A1.65 1.65 0 0 0 9 19.4a1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 0 1-2.83 0 2 2 0 0 1 0-2.83l.06-.06a1.65 1.65 0 0 0 .33-1.82 1.65 1.65 0 0 0-1.51-1H3a2 2 0 0 1-2-2 2 2 0 0 1 2-2h.09A1.65 1.65 0 0 0 4.6 9a1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 0 1 0-2.83 2 2 0 0 1 2.83 0l.06.06a1.65 1.65 0 0 0 1.82.33H9a1.65 1.65 0 0 0 1-1.51V3a2 2 0 0 1 2-2 2 2 0 0 1 2 2v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 0 1 2.83 0 2 2 0 0 1 0 2.83l-.06.06a1.65 1.65 0 0 0-.33 1.82V9a1.65 1.65 0 0 0 1.51 1H21a2 2 0 0 1 2 2 2 2 0 0 1-2 2h-.09a1.65 1.65 0 0 0-1.51 1z"></path></svg>
        Utilities
      </button>
    </nav>
  </div>
</section>

<!-- =============================================
     MAIN TOOLS GRID CONTAINER
     ============================================= -->
<main id="main-content" class="container">
  
  <!-- Dynamic Grid Ad Slot -->
  <% if (typeof landing !== 'undefined' && landing.ads && landing.ads.gridAd) { %>
    <div class="grid-ad-box">
      <%- landing.ads.gridAd %>
    </div>
  <% } %>

  <section class="tools-grid" id="toolsGrid">
    
    <% if (typeof tools !== 'undefined' && tools.length > 0) { %>
      <% tools.forEach(function(tool) { %>
        <a href="/tool/<%= tool.slug %>" class="tool-card" data-category="<%= (tool.category || 'utility').toLowerCase() %>">
          <div class="card-top">
            
            <!-- DYNAMIC SVG ICON (FROM ADMIN OR FALLBACK) -->
            <div class="tool-icon-box" aria-hidden="true">
              <% if (tool.iconSvg && tool.iconSvg.trim().startsWith('<svg')) { %>
                <%- tool.iconSvg %>
              <% } else { %>
                <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round"><polyline points="16 18 22 12 16 6"></polyline><polyline points="8 6 2 12 8 18"></polyline></svg>
              <% } %>
            </div>

            <span class="tool-tag"><%= tool.badge || 'Instant' %></span>
          </div>

          <h2><%= tool.name %></h2>
          <p><%= (tool.seo && tool.seo.metaDescription) ? tool.seo.metaDescription : (tool.name + ' utility engine with zero server latency.') %></p>
          
          <div class="card-bottom">
            <div class="tool-usage">
              <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><path d="M13 2L3 14h9l-1 8 10-12h-9l1-8z"></path></svg>
              <span><%= (tool.usageCount || 0).toLocaleString() %> uses</span>
            </div>
            
            <span class="open-btn">
              <span>Open Tool</span>
              <svg class="open-arrow" width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><line x1="7" y1="17" x2="17" y2="7"></line><polyline points="7 7 17 7 17 17"></polyline></svg>
            </span>
          </div>
        </a>
      <% }); %>
    <% } else { %>
      <div style="grid-column: 1 / -1; text-align: center; padding: 48px; color: var(--text-muted);">
        <p>No tools available yet. Add tools via the Admin Panel!</p>
      </div>
    <% } %>

    <div id="noResults">
      <p>No tools found matching your query.</p>
    </div>

  </section>

</main>

<%- include('partials/public-footer') %>