/* ==========================================================================
   SPEEDMATH - ADVERTISEMENT STYLES (Refactored & Optimized)
   AdSense slot styling with consent-aware placeholders
   ========================================================================== */

/* Import CSS Variables */
@import url('variables.css');

/* ==========================================================================
   1. BASE AD CONTAINER
   ========================================================================== */

.ad-container {
  margin: var(--space-6) auto;
  text-align: center;
  max-width: 100%;
  overflow: hidden;
  padding: 0 var(--space-4);
  transition: opacity var(--transition-base);
}

/* Ad Label (Advertisement Text) */
.ad-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: var(--space-2);
  font-weight: var(--fw-medium);
  opacity: 0.7;
}

/* Ad Slot Container (legacy placeholder — not used in production) */
.ad-slot {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  position: relative;
}

.ad-slot:hover {
  border-color: rgba(148, 163, 184, 0.25);
  background: rgba(148, 163, 184, 0.05);
}

/* Placeholder Text for Empty Slots */
.ad-placeholder-text {
  color: var(--text-muted);
  font-size: 0.75rem;
  font-weight: var(--fw-medium);
  opacity: 0.5;
  pointer-events: none;
}

/* ==========================================================================
   2. DARK MODE SUPPORT
   ========================================================================== */

[data-theme="dark"] .ad-slot {
  background: rgba(255, 255, 255, 0.03);
  border-color: rgba(255, 255, 255, 0.1);
}

[data-theme="dark"] .ad-slot:hover {
  background: rgba(255, 255, 255, 0.05);
  border-color: rgba(255, 255, 255, 0.15);
}

[data-theme="dark"] .ad-label {
  color: #6b7280;
}

[data-theme="dark"] .ad-placeholder-text {
  color: #6b7280;
}

/* ==========================================================================
   3. SPECIFIC AD SLOT TYPES
   ========================================================================== */

/* Header Banner Ad (970x90 or 728x90) */
.ad-header {
  max-width: 970px;
  margin: var(--space-6) auto;
}

.ad-header .ad-slot {
  min-height: 90px;
  width: 100%;
}

/* Practice Page Top/Bottom Ads (Leaderboard) */
.ad-practice-top,
.ad-practice-bottom {
  max-width: 1200px;
  margin: var(--space-8) auto;
}

.ad-practice-top .ad-slot,
.ad-practice-bottom .ad-slot {
  min-height: 100px;
  width: 100%;
}

/* Sidebar Ad (300x250 or 300x600) */
.ad-sidebar {
  max-width: 300px;
  margin: var(--space-6) auto;
}

.ad-sidebar .ad-slot {
  min-height: 250px;
  max-width: 300px;
  width: 100%;
}

/* Inline Content Ad (Within Text/Content) */
.ad-inline {
  max-width: 970px;
  margin: var(--space-8) auto;
}

.ad-inline .ad-slot {
  min-height: 150px;
  max-width: 100%;
}

/* Content Inline (Smaller In-Article Ad) */
.ad-content-inline {
  max-width: 728px;
  margin: var(--space-6) auto;
}

.ad-content-inline .ad-slot {
  min-height: 90px;
  width: 100%;
}

/* ==========================================================================
   4. AD LOADING STATES
   ========================================================================== */

/* Loading State */
.ad-slot.ad-loading {
  position: relative;
  overflow: hidden;
}

.ad-slot.ad-loading::before {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(
    90deg,
    transparent,
    rgba(148, 163, 184, 0.1),
    transparent
  );
  animation: adShimmer 1.5s infinite;
}

@keyframes adShimmer {
  0% {
    left: -100%;
  }
  100% {
    left: 100%;
  }
}

/* Loaded State */
.ad-slot.ad-loaded {
  border: none;
  background: transparent;
  padding: 0;
}

/* Error State (Ad Failed to Load) */
.ad-slot.ad-error {
  border-color: rgba(239, 68, 68, 0.2);
  background: rgba(239, 68, 68, 0.05);
}

.ad-slot.ad-error .ad-placeholder-text {
  color: var(--color-error);
  opacity: 0.6;
}

/* ==========================================================================
   5. CONSENT-AWARE STYLING
   ========================================================================== */

/* Hidden when consent not given */
.ad-container[data-consent="false"] {
  display: none !important;
}

/* Hide container + label when AdSense does not fill the slot */
.ad-container:has(ins.adsbygoogle[data-ad-status="unfilled"]) {
  display: none !important;
}

/* Hide label until ins is filled — prevents label floating alone */
.ad-container .ad-label {
  display: none;
}
.ad-container:has(ins.adsbygoogle[data-ad-status="filled"]) .ad-label {
  display: block;
}

/* Consent Required Message */
.ad-consent-required {
  padding: var(--space-4);
  border-radius: var(--radius-md);
  background: rgba(59, 130, 246, 0.05);
  border: 1px solid rgba(59, 130, 246, 0.2);
  text-align: center;
}

.ad-consent-required-text {
  font-size: 0.85rem;
  color: var(--text-soft);
  margin-bottom: var(--space-2);
}

.ad-consent-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-full);
  border: 1px solid rgba(59, 130, 246, 0.3);
  background: rgba(59, 130, 246, 0.1);
  color: var(--accent-primary);
  font-size: 0.85rem;
  font-weight: var(--fw-semibold);
  cursor: pointer;
  transition: all var(--transition-base);
}

.ad-consent-btn:hover {
  background: rgba(59, 130, 246, 0.15);
  border-color: rgba(59, 130, 246, 0.4);
}

/* ==========================================================================
   6. RESPONSIVE DESIGN
   ========================================================================== */

/* Tablet (960px and below) */
@media (max-width: 960px) {
  .ad-container {
    margin: var(--space-4) auto;
    padding: 0 var(--space-3);
  }

  .ad-header,
  .ad-inline {
    max-width: 728px;
  }

  .ad-header .ad-slot {
    min-height: 90px;
  }
}

/* Mobile (640px and below) */
@media (max-width: 640px) {
  .ad-container {
    margin: var(--space-3) auto;
    padding: 0 var(--space-2);
  }

  /* Adjust header ad for mobile (320x50 or 320x100) */
  .ad-header .ad-slot {
    min-height: 60px;
  }

  /* Hide sidebar ads on mobile */
  .ad-sidebar {
    display: none;
  }

  /* Reduce inline ad height */
  .ad-inline .ad-slot,
  .ad-content-inline .ad-slot {
    min-height: 100px;
  }

  /* Reduce practice page ad height */
  .ad-practice-top .ad-slot,
  .ad-practice-bottom .ad-slot {
    min-height: 80px;
  }

  /* Smaller label text */
  .ad-label {
    font-size: 0.65rem;
    margin-bottom: var(--space-1);
  }
}

/* Extra Small Mobile (480px and below) */
@media (max-width: 480px) {
  .ad-header .ad-slot {
    min-height: 50px;
  }

  .ad-placeholder-text {
    font-size: 0.7rem;
  }
}

/* ==========================================================================
   7. PRINT STYLES
   ========================================================================== */

@media print {
  .ad-container {
    display: none !important;
  }
}

/* ==========================================================================
   8. ACCESSIBILITY
   ========================================================================== */

/* Skip Ad for Screen Readers */
.ad-skip-link {
  position: absolute;
  left: -9999px;
  z-index: 999;
}

.ad-skip-link:focus {
  position: static;
  left: auto;
}

/* Reduced Motion Support */
@media (prefers-reduced-motion: reduce) {
  .ad-slot,
  .ad-slot::before,
  .ad-consent-btn {
    animation: none !important;
    transition: none !important;
  }
}