/**
 * AdLogic Cube Ad Styles
 * File: /wp-content/plugins/adlogic-by-elseandif/assets/css/cube-ads.css
 */

/* Cube Scene Container */
.adlogic-cube-scene {
    width: 300px;
    height: 250px;
    min-height: 250px;
    margin: 0; /* Remove auto centering for proper inline alignment */
    perspective: 1000px;
    position: relative;
    z-index: var(--adlogic-z-cube-base, 1000);
    isolation: isolate; /* Create isolated stacking context */
    /* Align top with other ads when side by side */
    vertical-align: top;
    overflow: visible !important; /* Ensure control bar is visible */
    margin-top: 0; /* Ensure scene starts right after control bar */
}

/* Responsive cube scene */
.adlogic-cube-scene.size-250x250 {
    width: 250px;
    height: 250px;
}

.adlogic-cube-scene.size-336x280 {
    width: 336px;
    height: 280px;
}

.adlogic-cube-scene.size-300x600 {
    width: 300px;
    height: 600px;
}

/* Mobile responsive */
@media (max-width: 480px) {
    .adlogic-cube-scene {
        width: 100%;
        max-width: 300px;
        height: 250px;
    }
}

/* The Cube */
.adlogic-cube {
    width: 100%;
    height: 100%;
    position: relative;
    transform-style: preserve-3d;
    transform: rotateX(0deg) rotateY(0deg);
    animation: adlogicRotateCube 16s infinite linear;
    transition: transform 0.5s ease-in-out;
}

/* Pause on hover */
.adlogic-cube-scene:hover .adlogic-cube {
    animation-play-state: paused;
}

/* Manual rotation controls */
.adlogic-cube.paused {
    animation-play-state: paused !important;
    -webkit-animation-play-state: paused !important;
}

.adlogic-cube.manual-control {
    animation: none;
    transition: transform 0.6s ease-in-out;
    -webkit-transition: -webkit-transform 0.6s ease-in-out;
}

/* Cube Faces */
.adlogic-cube__face {
    position: absolute;
    width: 100%;
    height: 100%;
    background: white;
    border: 1px solid #e5e7eb;
    box-sizing: border-box;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 16px;
    color: #6b7280;
    text-align: center;
    backface-visibility: hidden;
}

/* Face positioning for 300x250 (default) */
.adlogic-cube__face--front { 
    transform: rotateY(0deg) translateZ(150px); 
}

.adlogic-cube__face--back { 
    transform: rotateY(180deg) translateZ(150px); 
}

.adlogic-cube__face--right { 
    transform: rotateY(90deg) translateZ(150px); 
}

.adlogic-cube__face--left { 
    transform: rotateY(-90deg) translateZ(150px); 
}

.adlogic-cube__face--top { 
    transform: rotateX(90deg) translateZ(125px); 
}

.adlogic-cube__face--bottom { 
    transform: rotateX(-90deg) translateZ(125px); 
}

/* Adjust face positioning for 250x250 */
.adlogic-cube-scene.size-250x250 .adlogic-cube__face--front,
.adlogic-cube-scene.size-250x250 .adlogic-cube__face--back,
.adlogic-cube-scene.size-250x250 .adlogic-cube__face--right,
.adlogic-cube-scene.size-250x250 .adlogic-cube__face--left { 
    transform-origin: center;
}

.adlogic-cube-scene.size-250x250 .adlogic-cube__face--front { 
    transform: rotateY(0deg) translateZ(125px); 
}

.adlogic-cube-scene.size-250x250 .adlogic-cube__face--back { 
    transform: rotateY(180deg) translateZ(125px); 
}

.adlogic-cube-scene.size-250x250 .adlogic-cube__face--right { 
    transform: rotateY(90deg) translateZ(125px); 
}

.adlogic-cube-scene.size-250x250 .adlogic-cube__face--left { 
    transform: rotateY(-90deg) translateZ(125px); 
}

.adlogic-cube-scene.size-250x250 .adlogic-cube__face--top,
.adlogic-cube-scene.size-250x250 .adlogic-cube__face--bottom { 
    transform: rotateX(90deg) translateZ(125px); 
}

/* Ad containers within faces */
.adlogic-cube-ad-container {
    width: 100%;
    height: 100%;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* GPT slot styles for cube faces */
.adlogic-cube__face .adlogic-gpt-slot,
.adlogic-cube__face .adlogic-cube-slot {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}

/* Ensure GPT content fills the face properly */
.adlogic-cube__face .adlogic-gpt-slot > div,
.adlogic-cube__face .adlogic-cube-slot > div {
    width: 100% !important;
    height: 100% !important;
    position: relative;
}

/* GPT ad divs */
.adlogic-cube__face [id^="div-gpt-ad-"] {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Placeholder content */
.adlogic-cube-placeholder {
    padding: 20px;
    text-align: center;
    color: #9ca3af;
    font-size: 14px;
}

.adlogic-cube-placeholder .face-number {
    display: block;
    font-size: 48px;
    font-weight: bold;
    color: #e5e7eb;
    margin-bottom: 10px;
}

/* Rotation Keyframes - Forward (Clockwise) */
@keyframes adlogicRotateCube {
    0% { transform: rotateY(0deg); }
    25% { transform: rotateY(-90deg); }
    50% { transform: rotateY(-180deg); }
    75% { transform: rotateY(-270deg); }
    100% { transform: rotateY(-360deg); }
}

/* Rotation Keyframes - Reverse (Counter-clockwise) */
@keyframes adlogicRotateCubeReverse {
    0% { transform: rotateY(0deg); }
    25% { transform: rotateY(90deg); }
    50% { transform: rotateY(180deg); }
    75% { transform: rotateY(270deg); }
    100% { transform: rotateY(360deg); }
}

/* Webkit prefix for older browsers */
@-webkit-keyframes adlogicRotateCube {
    0% { -webkit-transform: rotateY(0deg); }
    25% { -webkit-transform: rotateY(-90deg); }
    50% { -webkit-transform: rotateY(-180deg); }
    75% { -webkit-transform: rotateY(-270deg); }
    100% { -webkit-transform: rotateY(-360deg); }
}

@-webkit-keyframes adlogicRotateCubeReverse {
    0% { -webkit-transform: rotateY(0deg); }
    25% { -webkit-transform: rotateY(90deg); }
    50% { -webkit-transform: rotateY(180deg); }
    75% { -webkit-transform: rotateY(270deg); }
    100% { -webkit-transform: rotateY(360deg); }
}

/* Rotation speed variations */
.adlogic-cube.speed-slow {
    animation-duration: 24s;
}

.adlogic-cube.speed-normal {
    animation-duration: 16s;
}

.adlogic-cube.speed-fast {
    animation-duration: 10s;
}

.adlogic-cube.speed-custom {
    /* Animation duration will be set inline by JavaScript */
}

/* Rotation direction */
.adlogic-cube.direction-reverse {
    animation-direction: reverse;
}

/* OLD Cube Controls - DEPRECATED: Now using .adlogic-cube-control-bar above the cube */
/* These old controls are hidden to prevent duplicate/conflicting controls */
.adlogic-cube-controls {
    display: none !important; /* Hide old controls completely */
    position: absolute;
    bottom: -35px;
    left: 50%;
    transform: translateX(-50%);
    gap: 10px;
    z-index: var(--adlogic-z-cube-controls, 1002);
    opacity: 0;
    transition: opacity 0.3s ease;
}

.adlogic-cube-scene:hover .adlogic-cube-controls {
    display: none !important; /* Ensure old controls stay hidden on hover */
}

.adlogic-cube-control-btn {
    background: #3b82f6;
    color: white;
    border: none;
    border-radius: 50%;
    width: 30px;
    height: 30px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    transition: all 0.2s ease;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.adlogic-cube-control-btn:hover {
    background: #2563eb;
    transform: scale(1.1);
}

.adlogic-cube-control-btn:active {
    transform: scale(0.95);
}

/* Loading state */
.adlogic-cube__face.loading {
    background: #f9fafb;
}

.adlogic-cube__face.loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 30px;
    height: 30px;
    margin: -15px 0 0 -15px;
    border: 3px solid #e5e7eb;
    border-top-color: #3b82f6;
    border-radius: 50%;
    animation: adlogicSpin 1s linear infinite;
}

@keyframes adlogicSpin {
    to { transform: rotate(360deg); }
}

/* Error state */
.adlogic-cube__face.error {
    background: #fef2f2;
    color: #dc2626;
    font-size: 12px;
    padding: 10px;
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
    .adlogic-cube__face {
        background: #1f2937;
        border-color: #374151;
        color: #9ca3af;
    }
    
    .adlogic-cube__face.loading {
        background: #111827;
    }
    
    .adlogic-cube__face.error {
        background: #7f1d1d;
        color: #fca5a5;
    }
    
    .adlogic-cube-control-btn {
        background: #4b5563;
    }
    
    .adlogic-cube-control-btn:hover {
        background: #6b7280;
    }
}

/* NoAdCode Attribution for Cube */
.adlogic-cube-container {
    position: relative;
    display: inline-block;
    isolation: isolate; /* Create isolated stacking context */
}

/* Old NoAdCode branding styles removed - now using control bar branding */
/* The NoAdCode branding is now part of .adlogic-cube-controls below the cube */

/* Cube specific adjustments */
.adlogic-cube-scene {
    /* Remove extra padding-bottom */
    padding-bottom: 0;
}

/* Desktop - ensure proper alignment when side by side with other ads */
@media (min-width: 768px) {
    /* Align cube top with display ads */
    .adlogic-placement-wrapper:has(.adlogic-cube-scene) {
        vertical-align: top !important;
        /* No need for padding compensation since control bar is at top */
        padding-top: 0;
    }
}

/* In-content cube adjustments for proper vertical spacing */
/* NOTE: margin-top handled by wrapper (space for control bar above) */
.entry-content .adlogic-cube-scene,
.post-content .adlogic-cube-scene,
.page-content .adlogic-cube-scene {
    margin-top: 0;
    margin-bottom: 10px;
}

/* Mobile - ensure consistent alignment with extra vertical spacing */
/* NOTE: margin-top handled by wrapper (space for control bar above) */
@media (max-width: 767px) {
    .adlogic-cube-scene {
        /* REMOVED margin-left/right auto to prevent creative cropping */
        margin-left: 0 !important;
        margin-right: 0 !important;
        padding-left: 0 !important;
        padding-right: 0 !important;
        /* NO margin-top here - wrapper handles control bar space */
        margin-top: 0 !important;
        margin-bottom: 20px !important;
        display: inline-block; /* Allows parent text-align to center */
    }
}

/* Desktop - ensure proper left alignment when inline with other ads */
@media (min-width: 768px) {
    .adlogic-cube-scene {
        margin-left: 0 !important;
        margin-right: 0 !important;
    }
}

/* Print styles */
@media print {
    .adlogic-cube-scene {
        display: none;
    }
}

/* Sidebar specific styles */
.widget .adlogic-cube-scene {
    width: 250px;
    height: 250px;
    margin: 10px auto;
}

.widget .adlogic-cube__face--front,
.widget .adlogic-cube__face--back,
.widget .adlogic-cube__face--right,
.widget .adlogic-cube__face--left {
    transform-origin: center;
}

.widget .adlogic-cube__face--front { 
    transform: rotateY(0deg) translateZ(125px); 
}

.widget .adlogic-cube__face--back { 
    transform: rotateY(180deg) translateZ(125px); 
}

.widget .adlogic-cube__face--right { 
    transform: rotateY(90deg) translateZ(125px); 
}

.widget .adlogic-cube__face--left { 
    transform: rotateY(-90deg) translateZ(125px); 
}

/* In-content cube adjustments */
/* NOTE: margin-top handled by wrapper (space for control bar above) */
.entry-content .adlogic-cube-scene,
.post-content .adlogic-cube-scene,
.page-content .adlogic-cube-scene {
    /* REMOVED margin-left/right auto to prevent creative cropping */
    margin: 0 0 30px 0 !important; /* Bottom margin only - wrapper handles top */
    margin-left: 0 !important;
    margin-right: 0 !important;
    padding-left: 0 !important;
    padding-right: 0 !important;
    display: inline-block; /* Allows parent text-align to center */
}

/* Cube face content alignment */
.adlogic-cube__face iframe {
    width: 100%;
    height: 100%;
    border: none;
    display: block;
}

.adlogic-cube__face img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    border: none;
}

/* Google ads iframe containers */
.adlogic-cube__face div[id^="google_ads_iframe"] {
    width: 100% !important;
    height: 100% !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
}

/* Face numbering for debug mode */
body.adlogic-debug-mode-active .adlogic-cube__face::before {
    content: attr(data-face);
    position: absolute;
    top: 5px;
    right: 5px;
    background: rgba(59, 130, 246, 0.8);
    color: white;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: bold;
    z-index: var(--adlogic-z-cube-controls, 1002);
}
/* Cube Wrapper - Contains scene and control bar */
/* CRITICAL: These styles MUST override any conflicting styles from unified-container.css */
.adlogic-cube-wrapper,
.adlogic-container .adlogic-cube-wrapper,
.adlogic-cube-container .adlogic-cube-wrapper,
.adlogic-block-cube .adlogic-cube-wrapper {
    display: inline-block !important;
    position: relative !important; /* CRITICAL: Required for absolute positioning of control bar */
    overflow: visible !important; /* Ensure control bar is not cut off */
    padding-top: 0 !important; /* No padding - control bar positions itself above cube */
    margin-top: 35px !important; /* Space for control bar above */
    width: max-content !important; /* Width adjusts to cube scene content */
    box-sizing: border-box !important;
}

/* CRITICAL: Hide any duplicate NoAdCode branding that's not in control bar */
.adlogic-container[data-format="cube"] > .noadcode-branding,
.adlogic-block-cube > .noadcode-branding,
.adlogic-cube-container > .noadcode-branding,
.adlogic-container[data-format="cube"] .noadcode-branding:not(.adlogic-cube-control-bar .noadcode-link) {
    display: none !important;
}

/* Ensure the container has enough height for cube + control bar */
.adlogic-container[data-format="cube"] {
    min-height: 300px !important; /* 250px cube + 50px control bar space */
    overflow: visible !important;
    position: relative !important;
    display: inline-block !important;
    padding-top: 0 !important; /* Remove any padding that might interfere */
}

/* Only show NoAdCode branding in the control bar */
.adlogic-cube-control-bar .noadcode-link {
    display: inline-flex !important;
}

/* Integrated NoAdCode Control Bar for Cube - IMPORTANT: Override unified styles */
.adlogic-cube-control-bar {
    display: flex !important;
    visibility: visible !important;
    opacity: 1 !important;
    align-items: center;
    background: #1a1a1a !important; /* Match display ad black color */
    border-radius: 4px 4px 0 0; /* Round top corners instead of bottom */
    padding: 0.3em .5em 0.5em; /* Match display ad padding */
    width: 100%; /* Full width of wrapper which matches cube scene width */
    box-sizing: border-box;
    position: absolute !important; /* Position absolutely within wrapper */
    bottom: 100% !important; /* Position ABOVE the cube (outside wrapper at top) */
    left: 0 !important; /* Align with cube left edge */
    right: 0 !important;
    top: auto !important; /* Override any top positioning */
    z-index: 1003 !important; /* Slightly higher than cube controls standard to ensure visibility */
    height: auto; /* Let height be determined by content and padding */
    box-shadow:
        inset 0 -1px 0 rgba(255, 255, 255, 0.1),
        0 2px 8px rgba(0, 0, 0, 0.2); /* Match display ad shadow */
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-bottom: none; /* Remove bottom border instead of top */
    pointer-events: auto !important; /* Ensure it can receive clicks */
    margin: 0 !important; /* No margins needed with bottom:100% positioning */
}

/* NoAdCode Branding Section */
.adlogic-cube-control-bar .noadcode-section {
    display: flex !important;
    align-items: center;
    margin-right: auto;
    padding-right: 12px;
    border-right: 1px solid rgba(255, 255, 255, 0.1);
    opacity: 1 !important;
    visibility: visible !important;
}

.adlogic-cube-control-bar .noadcode-link {
    display: inline-flex !important;
    align-items: center;
    gap: 0.3em;
    color: #ffffff;
    text-decoration: none;
    font-size: clamp(9px, 2vw, 12px); /* Match display ad font size */
    font-weight: 500;
    letter-spacing: 0.3px;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; /* Match display ad font */
    transition: opacity 0.2s ease;
    /* CRITICAL: Override unified container absolute positioning */
    position: static !important;
    top: auto !important;
    left: auto !important;
    padding: 0 !important;
    margin: 0 !important;
    background: transparent !important;
    box-shadow: none !important;
    border-radius: 0 !important;
    opacity: 1 !important;
    visibility: visible !important;
}

.adlogic-cube-control-bar .noadcode-link:hover {
    opacity: 0.8;
    background: transparent !important;
    transform: none !important;
}

.adlogic-cube-control-bar .lightning-icon {
    color: #FFD700;
    font-size: 1.2em;
    line-height: 1;
    text-shadow: 0 0 6px rgba(255, 215, 0, 0.6); /* Match display ad shadow */
    animation: lightningPulse 10s infinite; /* Add lightning pulse animation */
}

/* Branding text styling to match display ads */
.adlogic-cube-control-bar .branding-text {
    line-height: 1;
    color: #ffffff;
}

/* NoAdCode text with lightning pulse animation to match display ads */
.adlogic-cube-control-bar .noadcode-text {
    display: inline-block;
    font-weight: 600;
    animation: textLightningPulse 10s infinite;
}

/* Control Buttons Section */
.adlogic-cube-control-bar .controls-section {
    display: flex !important;
    align-items: center;
    gap: 6px;
    margin-left: 12px;
    opacity: 1 !important;
    visibility: visible !important;
}

.adlogic-cube-control-bar button {
    width: 20px;
    height: 20px;
    border: none;
    background: rgba(255, 255, 255, 0.1);
    color: #ffffff;
    border-radius: 3px;
    cursor: pointer;
    display: flex !important;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    padding: 0;
    opacity: 1 !important;
    visibility: visible !important;
    margin: 0; /* Ensure no extra margin */
}

.adlogic-cube-control-bar button:hover {
    background: rgba(255, 255, 255, 0.2);
}

.adlogic-cube-control-bar button:active {
    transform: scale(0.9);
}

.adlogic-cube-control-bar button.active {
    background: rgba(102, 126, 234, 0.3);
}

/* Play/Pause toggle button icon visibility */
.adlogic-cube-control-bar .control-play-pause.playing .play-icon {
    display: none !important;
}

.adlogic-cube-control-bar .control-play-pause.playing .pause-icon {
    display: block !important;
}

.adlogic-cube-control-bar .control-play-pause:not(.playing) .play-icon {
    display: block !important;
}

.adlogic-cube-control-bar .control-play-pause:not(.playing) .pause-icon {
    display: none !important;
}

/* SVG Icons */
.adlogic-cube-control-bar button svg {
    width: 12px;
    height: 12px;
    pointer-events: none;
    fill: currentColor;
}

/* CRITICAL: Force control bar visibility for all cube containers */
.adlogic-block-cube .adlogic-cube-control-bar,
.adlogic-cube-container .adlogic-cube-control-bar,
.adlogic-container[data-format="cube"] .adlogic-cube-control-bar {
    display: flex !important;
    opacity: 1 !important;
    visibility: visible !important;
    pointer-events: auto !important;
}

/* Force all control bar children to be visible */
.adlogic-cube-control-bar * {
    opacity: 1 !important;
    visibility: visible !important;
}

/* Ensure the unified container doesn't hide our control bar */
.adlogic-container[data-format="cube"] {
    overflow: visible !important;
}

/* Make sure cube wrapper gets proper height allocation */
.adlogic-container[data-format="cube"] .adlogic-cube-wrapper {
    min-height: 300px !important;
    position: relative !important;
    display: inline-block !important;
}

/* Controls-only mode (no branding) - smaller and centered */
.adlogic-cube-control-bar.controls-only {
    width: fit-content !important;
    max-width: 120px; /* Just wide enough for the 3 control buttons */
    margin: 0px 0px 20px 0px !important; /* Bottom margin pushes control bar up above 3D cube perspective */
    left: 50% !important;
    right: auto !important; /* Remove right constraint */
    transform: translateX(-50%) !important;
    justify-content: center !important;
}

.adlogic-cube-control-bar.controls-only .controls-section {
    margin-left: 0 !important; /* Remove left margin when no branding */
    border: none !important; /* Remove any borders */
}

/* Mobile Responsive Control Bar */
@media (max-width: 480px) {
    .adlogic-cube-control-bar {
        padding: 0.4em 0.8em 0.5em; /* Match display ad mobile padding */
    }

    .adlogic-cube-control-bar .noadcode-link {
        font-size: clamp(8px, 2.5vw, 11px); /* Match display ad mobile font size */
    }

    .adlogic-cube-control-bar button {
        width: 18px;
        height: 18px;
    }

    .adlogic-cube-control-bar button svg {
        width: 10px;
        height: 10px;
    }

    .adlogic-cube-wrapper {
        /* Keep using margin-top approach same as desktop - DO NOT add padding-top */
        /* margin-top: 35px already set in main wrapper rule */
        padding-top: 0 !important;
    }

    .adlogic-cube-control-bar.controls-only {
        max-width: 100px; /* Slightly smaller on mobile */
    }
}
