﻿/* ==========================================================================
   TakeAMindBreak.com — AdSense Guard & CLS Prevention Stylesheet
   ─────────────────────────────────────────────────────────────────────────
   PURPOSE:
     Reserves explicit pixel dimensions for every ad slot so the browser
     allocates layout space BEFORE the AdSense script loads. This eliminates
     Cumulative Layout Shift (CLS) — a Core Web Vital that directly affects
     Google Search ranking and AdSense approval.

   RULES:
     - All ad containers get solid opaque background cards (no transparency)
     - Z-index stack follows the immutable hierarchy from AGENTS.md:
         z-index: -1  → #ambientCanvas
         z-index:  5  → #touchTrailCanvas
         z-index: 10  → .activity-card (opaque cards)
         z-index: 12  → all ad containers  ← enforced here
         z-index: 20  → .site-header
     - pointer-events: none on both canvas layers (CSS fallback in addition to JS)
     - 40px safety margin is enforced in JS; CSS provides the opaque backing
   ========================================================================== */

/* ─── Canvas Safety Overrides (CSS fallback layer) ───────────────────────── */

/* Ambient background canvas — must always stay behind all content */
#ambientCanvas {
  position: fixed !important;
  top: 0 !important;
  left: 0 !important;
  width: 100vw !important;
  height: 100vh !important;
  z-index: -1 !important;
  pointer-events: none !important;
  display: block;
}

/* Touch trail overlay canvas — above content but below interactive cards/ads */
#touchTrailCanvas {
  position: fixed !important;
  top: 0 !important;
  left: 0 !important;
  width: 100vw !important;
  height: 100vh !important;
  z-index: 5 !important;
  pointer-events: none !important;
  display: block;
}

/* ─── Ad Container Base: CLS Prevention ─────────────────────────────────── */
/* All ad wrappers share these foundational rules */
.ad-placeholder-container,
.ad-infeed-banner,
.ad-desktop-rectangle,
.mobile-sticky-ad {
  /* Solid opaque surface — canvases MUST NOT draw over ads */
  background-color: var(--bg-card, #FAF9F5);
  
  /* Immutable z-index: 12 per AGENTS.md stack */
  position: relative;
  z-index: 12;

  /* Layout containment prevents canvas particles from occluding ad pixels */
  isolation: isolate;

  /* Smooth transition when ad content loads (prevents jarring fills) */
  transition: background-color 0.3s ease;
}

[data-theme="dark"] .ad-placeholder-container,
[data-theme="dark"] .ad-infeed-banner,
[data-theme="dark"] .ad-desktop-rectangle,
[data-theme="dark"] .mobile-sticky-ad {
  background-color: var(--bg-card, #1B2A22);
}

/* ─── In-Feed Banner: 728×90 (Desktop) / 320×50 (Mobile) ────────────────── */
.ad-infeed-banner {
  width: 100%;
  /* Reserve the 728×90 standard leaderboard height; prevents CLS on load */
  min-height: 90px;
  max-width: 728px;
  margin: 2rem auto;
  border-radius: var(--radius-md, 16px);
  border: 1px solid var(--border-soft, rgba(28, 45, 36, 0.08));
  box-shadow: var(--shadow-sm, 0 2px 8px rgba(28, 45, 36, 0.04));
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 0.35rem;
  padding: 0.75rem 1rem;
  overflow: hidden;
  box-sizing: border-box;
  /* aspect-ratio keeps space reserved responsively */
  aspect-ratio: auto 728 / 90;
}

@media (max-width: 768px) {
  .ad-infeed-banner {
    /* Reserve 320×50 mobile banner space on small screens */
    min-height: 50px;
    aspect-ratio: auto 320 / 50;
    max-width: 320px;
    margin: 1.25rem auto;
  }
}

/* ─── Desktop Sidebar Rectangle: 300×250 ─────────────────────────────────── */
.ad-desktop-rectangle {
  /* Explicit pixel dimensions to prevent layout reflow */
  width: 300px;
  min-width: 300px;
  height: 250px;
  min-height: 250px;
  border-radius: var(--radius-md, 16px);
  border: 1px solid var(--border-soft, rgba(28, 45, 36, 0.08));
  box-shadow: var(--shadow-sm, 0 2px 8px rgba(28, 45, 36, 0.04));
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 0.35rem;
  padding: 0.75rem;
  overflow: hidden;
  box-sizing: border-box;
  flex-shrink: 0;
}

@media (max-width: 1024px) {
  .ad-desktop-rectangle {
    display: none; /* Hide sidebar ad on narrow viewports to prevent CLS */
  }
}

/* ─── Mobile Sticky Bottom Banner: 320×50 ────────────────────────────────── */
.mobile-sticky-ad {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  width: 100%;
  /* Reserve full 50px height to prevent body content jump */
  min-height: 50px;
  height: 54px; /* Match --mobile-ad-height CSS variable */
  z-index: 12;
  background-color: var(--bg-card, #FAF9F5);
  border-top: 1px solid var(--border-soft, rgba(28, 45, 36, 0.08));
  box-shadow: 0 -4px 20px rgba(28, 45, 36, 0.06);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1rem;
  gap: 0.5rem;
  box-sizing: border-box;
  transform: translateY(0);
  transition: transform 0.3s ease;
  /* Body must have padding-bottom set in responsive section below */
}

[data-theme="dark"] .mobile-sticky-ad {
  box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.3);
}

/* Collapsed state (dismissed via close button) */
.mobile-sticky-ad.collapsed {
  transform: translateY(110%);
  pointer-events: none;
}

/* Only show on mobile — desktop sees sidebar instead */
@media (min-width: 769px) {
  .mobile-sticky-ad {
    display: none;
  }
}

/* Reserve body padding on mobile so sticky ad doesn't cover page content */
@media (max-width: 768px) {
  body:has(.mobile-sticky-ad:not(.collapsed)) {
    padding-bottom: 60px;
  }
}

/* ─── Mobile Sticky Ad Inner Layout ─────────────────────────────────────── */
.mobile-ad-content {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex: 1;
  min-width: 0;
  overflow: hidden;
}

.mobile-ad-tag {
  flex-shrink: 0;
  font-size: 0.65rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-muted, #52665B);
  background: var(--accent-primary-light, rgba(107, 158, 130, 0.14));
  padding: 0.15rem 0.45rem;
  border-radius: 4px;
}

.mobile-ad-msg {
  font-size: 0.78rem;
  color: var(--text-muted, #52665B);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-weight: 500;
}

.ad-close-btn {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--bg-subtle, #E2ECE5);
  color: var(--text-muted, #52665B);
  font-size: 1rem;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  border: none;
  transition: background-color 0.2s ease;
}

.ad-close-btn:hover {
  background: var(--accent-primary-light, rgba(107, 158, 130, 0.2));
  color: var(--text-main, #1C2D24);
}

/* ─── Shared Ad Label Styles ─────────────────────────────────────────────── */
.ad-badge-label {
  font-size: 0.65rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-muted, #6B7C72);
  display: block;
}

.ad-notice-text {
  font-size: 0.75rem;
  color: var(--text-muted, #6B7C72);
  text-align: center;
  font-weight: 400;
  display: block;
}

/* ─── Loader Ad Container (mindful-loader overlay) ───────────────────────── */
/* .loader-ad-container rules are in mindful-loader.css — do not duplicate */

/* ─── AdSense Real Slot Override ──────────────────────────────────────────
   When live AdSense ins.adsbygoogle is injected, these rules ensure the
   actual ad unit fills the reserved space without breaking the layout.
   ─────────────────────────────────────────────────────────────────────── */
ins.adsbygoogle {
  display: block !important;
  width: 100% !important;
  /* Height is controlled by the AdSense data-ad-slot attributes */
}

/* ─── CLS Safety: Prevent ad container from jumping before AdSense loads ─── */
/* The ::before pseudo-element fills the space with a neutral placeholder
   that is invisible but holds the exact dimensions the ad will occupy.     */
.ad-infeed-banner::before,
.ad-desktop-rectangle::before {
  content: '';
  display: block;
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: repeating-linear-gradient(
    135deg,
    transparent 0px,
    transparent 8px,
    var(--border-subtle, rgba(28, 45, 36, 0.03)) 8px,
    var(--border-subtle, rgba(28, 45, 36, 0.03)) 9px
  );
  pointer-events: none;
  z-index: 0;
}

/* Ensure ad content always sits above the placeholder pattern */
.ad-infeed-banner > *,
.ad-desktop-rectangle > * {
  position: relative;
  z-index: 1;
}
