/* ═══════════════════════════════════════════════════════
   Tool Hub v1.0.0 — Premium Layout Engine
   ~5KB | No framework | CSS custom properties
   ═══════════════════════════════════════════════════════ */

/* ── Reset scope ─────────────────────────────────────── */
.th-hub, .th-hub * { box-sizing: border-box; }

/* ── CSS tokens (overridable via style attr) ──────────── */
.th-hub {
  --th-cols: 3;
  --th-gap: 24px;
  --th-radius: 14px;
  --th-accent: #6366f1;
  --th-accent-r: 99;
  --th-accent-g: 102;
  --th-accent-b: 241;
  --th-card-bg: #111820;
  --th-card-border: #1c2a3a;
  --th-text-primary: #e6edf3;
  --th-text-secondary: #8b949e;
  --th-glow-size: 520px;
  --th-stagger-base: 60ms;

  position: relative;
  width: 100%;
  padding: 48px 0 56px;
  overflow: hidden;
}

/* ── Backgrounds ──────────────────────────────────────── */
.th-bg-dark   { background: #080b10; }
.th-bg-darker { background: #040608; }
.th-bg-none   { background: transparent; }

/* Grid dot pattern */
.th-grid-bg::after {
  content: '';
  position: absolute;
  inset: 0;
  background-image:
    radial-gradient(circle, rgba(var(--th-accent-r),var(--th-accent-g),var(--th-accent-b),.04) 1px, transparent 1px);
  background-size: 36px 36px;
  pointer-events: none;
  z-index: 0;
}

/* ── Glow orbs (pure CSS, GPU-accelerated) ───────────── */
.th-orb {
  position: absolute;
  border-radius: 50%;
  pointer-events: none;
  z-index: 0;
  will-change: transform;
  filter: blur(80px);
}
.th-orb-1 {
  width: var(--th-glow-size);
  height: var(--th-glow-size);
  top: -120px;
  left: -80px;
  background: radial-gradient(circle,
    rgba(var(--th-accent-r),var(--th-accent-g),var(--th-accent-b),.12) 0%,
    transparent 70%);
  animation: th-drift-1 18s ease-in-out infinite;
}
.th-orb-2 {
  width: calc(var(--th-glow-size) * .75);
  height: calc(var(--th-glow-size) * .75);
  bottom: -80px;
  right: -60px;
  background: radial-gradient(circle,
    rgba(var(--th-accent-r),var(--th-accent-g),var(--th-accent-b),.08) 0%,
    transparent 70%);
  animation: th-drift-2 24s ease-in-out infinite;
}
.th-cursor-orb {
  position: absolute;
  width: 300px;
  height: 300px;
  border-radius: 50%;
  background: radial-gradient(circle,
    rgba(var(--th-accent-r),var(--th-accent-g),var(--th-accent-b),.09) 0%,
    transparent 65%);
  filter: blur(40px);
  pointer-events: none;
  z-index: 0;
  transform: translate(-50%, -50%);
  transition: opacity .4s ease;
  opacity: 0;
  will-change: left, top;
}
.th-hub:hover .th-cursor-orb { opacity: 1; }

@keyframes th-drift-1 {
  0%,100% { transform: translate(0,0) scale(1); }
  33%      { transform: translate(60px,40px) scale(1.05); }
  66%      { transform: translate(-30px,70px) scale(.97); }
}
@keyframes th-drift-2 {
  0%,100% { transform: translate(0,0) scale(1); }
  40%      { transform: translate(-50px,-30px) scale(1.08); }
  70%      { transform: translate(30px,-60px) scale(.95); }
}

/* ── Header ───────────────────────────────────────────── */
.th-header {
  position: relative;
  z-index: 2;
  text-align: center;
  margin-bottom: 40px;
  padding: 0 24px;
}
.th-title {
  font-size: clamp(24px, 4vw, 38px);
  font-weight: 700;
  color: var(--th-text-primary);
  letter-spacing: -.02em;
  margin: 0 0 12px;
  line-height: 1.2;
  /* Gradient text using accent */
  background: linear-gradient(135deg,
    var(--th-text-primary) 0%,
    rgba(var(--th-accent-r),var(--th-accent-g),var(--th-accent-b),1) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.th-desc {
  font-size: 16px;
  color: var(--th-text-secondary);
  max-width: 560px;
  margin: 0 auto;
  line-height: 1.65;
}

/* ── Grid ─────────────────────────────────────────────── */
.th-grid {
  position: relative;
  z-index: 2;
  display: grid;
  grid-template-columns: repeat(var(--th-cols), minmax(0, 1fr));
  gap: var(--th-gap);
  padding: 0 24px;
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
}

/* Auto responsive */
.th-hub[style*="--th-cols:auto"] .th-grid,
.th-hub[style*="--th-cols: auto"] .th-grid {
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
}

/* ── Card item wrapper ────────────────────────────────── */
.th-item {
  /* Passes through by default — the child plugin card IS the card */
  position: relative;
}

/* ── STYLE: cards ─────────────────────────────────────── */
.th-style-cards .th-item > * {
  background: var(--th-card-bg) !important;
  border: 1px solid var(--th-card-border) !important;
  border-radius: var(--th-radius) !important;
  overflow: hidden;
}

/* ── STYLE: bordered ─────────────────────────────────── */
.th-style-bordered .th-item > * {
  background: var(--th-card-bg) !important;
  border: 2px solid var(--th-card-border) !important;
  border-radius: var(--th-radius) !important;
}

/* ── STYLE: glass ─────────────────────────────────────── */
.th-style-glass .th-item > * {
  background: rgba(255,255,255,.03) !important;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid rgba(255,255,255,.06) !important;
  border-radius: var(--th-radius) !important;
}

/* ── STYLE: minimal ──────────────────────────────────── */
.th-style-minimal .th-item > * {
  background: transparent !important;
  border: none !important;
}

/* ── Hover animations ─────────────────────────────────── */
.th-hover .th-item {
  transition: transform .25s cubic-bezier(.2,0,.2,1);
}
.th-hover .th-item > * {
  transition:
    border-color .25s ease,
    box-shadow   .25s ease !important;
}
.th-hover .th-item:hover {
  transform: translateY(-5px);
}
.th-hover .th-item:hover > * {
  border-color: rgba(var(--th-accent-r),var(--th-accent-g),var(--th-accent-b),.45) !important;
  box-shadow:
    0 0 0 1px rgba(var(--th-accent-r),var(--th-accent-g),var(--th-accent-b),.12),
    0 12px 40px rgba(0,0,0,.5),
    0 0 60px rgba(var(--th-accent-r),var(--th-accent-g),var(--th-accent-b),.08) !important;
}

/* Inner glow on hover — top edge shimmer */
.th-hover .th-item > *::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: linear-gradient(
    160deg,
    rgba(var(--th-accent-r),var(--th-accent-g),var(--th-accent-b),.07) 0%,
    transparent 50%
  );
  opacity: 0;
  transition: opacity .25s ease;
  pointer-events: none;
  z-index: 0;
}
.th-hover .th-item:hover > *::before { opacity: 1; }

/* ── Staggered entrance animation ────────────────────── */
@keyframes th-in {
  from { opacity: 0; transform: translateY(20px); }
  to   { opacity: 1; transform: translateY(0); }
}

.th-anim .th-item {
  opacity: 0;
  animation: th-in .5s cubic-bezier(.2,0,.2,1) forwards;
  animation-delay: calc(var(--th-i, 0) * var(--th-stagger-base));
}

/* ── Scroll reveal (JS adds .th-visible) ─────────────── */
.th-scroll-reveal .th-item {
  opacity: 0;
  transform: translateY(16px);
  transition: opacity .45s ease, transform .45s cubic-bezier(.2,0,.2,1);
}
/* Don't stack with entrance animation */
.th-anim.th-scroll-reveal .th-item {
  opacity: 0;
  transform: translateY(20px);
}
.th-scroll-reveal .th-item.th-visible,
.th-anim .th-item { /* anim handles itself via keyframe */
}
.th-scroll-reveal:not(.th-anim) .th-item.th-visible {
  opacity: 1;
  transform: translateY(0);
}

/* ── Empty state ─────────────────────────────────────── */
.th-empty {
  padding: 40px 24px;
  text-align: center;
  font-size: 14px;
  color: #4a6278;
}
.th-empty a { color: var(--th-accent); }

/* ── Responsive ──────────────────────────────────────── */
@media (max-width: 1100px) {
  .th-hub[style*="--th-cols:4"] .th-grid,
  .th-hub[style*="--th-cols: 4"] .th-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}
@media (max-width: 860px) {
  .th-hub[style*="--th-cols:3"] .th-grid,
  .th-hub[style*="--th-cols: 3"] .th-grid,
  .th-hub[style*="--th-cols:4"] .th-grid,
  .th-hub[style*="--th-cols: 4"] .th-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}
@media (max-width: 560px) {
  .th-grid {
    grid-template-columns: 1fr !important;
    padding: 0 16px;
  }
  .th-title { font-size: 24px; }
  .th-header { margin-bottom: 28px; }
  .th-hub { padding: 32px 0 40px; }
}

/* ── Reduced motion ──────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  .th-orb, .th-cursor-orb { animation: none !important; transition: none !important; }
  .th-anim .th-item { animation: none !important; opacity: 1 !important; }
  .th-hover .th-item { transition: none !important; }
  .th-scroll-reveal .th-item { opacity: 1 !important; transform: none !important; transition: none !important; }
}

/* ═══════════════════════════════════════════════════════
   Tool Hub — Child Plugin Card Normalisation
   Ensures thumbnails from all plugins display correctly
   inside the grid regardless of theme interference.
   ═══════════════════════════════════════════════════════ */

/* Prevent theme font/color overrides bleeding into cards */
.th-item a,
.th-item a:hover,
.th-item a:visited {
  text-decoration: none !important;
}

/* All plugin thumbnail anchors: fill the grid cell */
.th-item .kh-thumb,
.th-item .oa-thumb,
.th-item .th-thumb,
.th-item .prism-thumb,
.th-item .ta-thumb,
.th-item .ss-thumb,
.th-item [class$="-thumb"],
.th-item [class*="-thumb "] {
  display: block !important;
  width: 100% !important;
  max-width: 100% !important;
  height: 100% !important;
  box-sizing: border-box !important;
}

/* When style="cards" — ensure card wrapper doesn't double-border */
.th-style-cards .th-item .kh-thumb,
.th-style-cards .th-item .oa-thumb,
.th-style-cards .th-item .th-thumb,
.th-style-cards .th-item .prism-thumb,
.th-style-cards .th-item .ta-thumb,
.th-style-cards .th-item .ss-thumb,
.th-style-cards .th-item [class$="-thumb"],
.th-style-cards .th-item [class*="-thumb "] {
  border-radius: var(--th-radius) !important;
}

/* Fallback card appearance if plugin CSS fails to load entirely —
   covers any <a> inside .th-item that has no other styling */
.th-item > a:not([class]) {
  display: block;
  background: var(--th-card-bg);
  border: 1px solid var(--th-card-border);
  border-radius: var(--th-radius);
  padding: 20px;
  color: var(--th-text-primary);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  text-decoration: none;
}

/* Hover: override child plugin's own hover so hub's hover wins */
.th-hover .th-item:hover .kh-thumb,
.th-hover .th-item:hover .oa-thumb,
.th-hover .th-item:hover .th-thumb,
.th-hover .th-item:hover .prism-thumb,
.th-hover .th-item:hover .ta-thumb,
.th-hover .th-item:hover .ss-thumb,
.th-hover .th-item:hover [class$="-thumb"] {
  /* Let hub's box-shadow override the plugin's own hover shadow */
  transform: none !important; /* hub handles the lift on .th-item */
}
