/* CRITICAL FIX: Math Trick Container */
.math-trick {
    background: white;
    margin: 3rem 0;
    padding: 2.5rem;
    border-radius: 15px;
    box-shadow: 0 5px 20px rgba(0,0,0,0.08);
    border-left: 5px solid #667eea;
    position: relative;
    transition: transform 0.3s ease;
    overflow: visible; /* Allow elements to show outside */
    word-wrap: break-word;
    overflow-wrap: break-word;
    /* CRITICAL FIX: Enough top margin for number */
    margin-top: 4rem;
    /* CRITICAL FIX: Enough top padding */
    padding-top: 3rem;
}

/* CRITICAL FIX: Trick Number - No Overlap */
.trick-number {
    position: absolute;
    top: -20px; /* More negative to avoid overlap */
    right: 20px;
    background: #667eea;
    color: white;
    width: 42px;
    height: 42px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    font-size: 1.2rem;
    z-index: 100; /* Very high z-index */
    min-width: 42px;
    flex-shrink: 0;
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
    /* CRITICAL FIX: Ensure it's always visible */
    border: 2px solid white;
}

/* CRITICAL FIX: Example Box - No Overlap with Number */
.example-box {
    background: #f8f9fa;
    border: 2px dashed #667eea;
    border-radius: 10px;
    padding: 1.5rem;
    margin: 2rem 0;
    position: relative;
    overflow: visible;
    word-wrap: break-word;
    overflow-wrap: break-word;
    /* CRITICAL FIX: Leave space for trick number */
    margin-top: 2.5rem;
}

.example-box::before {
    content: "✨ Example";
    position: absolute;
    top: -12px;
    left: 20px; /* Keep on left side to avoid number */
    background: #667eea;
    color: white;
    padding: 6px 16px;
    border-radius: 15px;
    font-size: 0.9rem;
    font-weight: 600;
    z-index: 50; /* Lower than trick number */
    white-space: nowrap;
    box-shadow: 0 2px 8px rgba(102, 126, 234, 0.3);
    border: 1px solid white;
}

/* CRITICAL FIX: Math Trick Heading */
.math-trick h3 {
    color: #2c3e50;
    font-size: clamp(1.2rem, 3vw, 1.8rem);
    margin-bottom: 1rem;
    display: flex;
    align-items: center;
    gap: 10px;
    /* CRITICAL FIX: Space for trick number */
    padding-right: 70px; /* More space */
    word-wrap: break-word;
    overflow-wrap: break-word;
    line-height: 1.3;
    margin-top: 0; /* Start from top */
}

/* MOBILE FIXES */
@media (max-width: 768px) {
    .math-trick {
        padding: 1.5rem 1rem;
        margin: 2.5rem 0;
        border-radius: 12px;
        overflow: visible;
        position: relative;
        /* CRITICAL FIX: More top space on mobile */
        margin-top: 3.5rem;
        padding-top: 2rem;
    }

    .trick-number {
        width: 36px;
        height: 36px;
        font-size: 1rem;
        top: -18px;
        right: 15px;
        position: absolute;
        z-index: 150; /* Even higher on mobile */
        box-shadow: 0 3px 10px rgba(102, 126, 234, 0.5);
        border: 2px solid white;
    }

    .math-trick h3 {
        font-size: 1.4rem;
        line-height: 1.3;
        margin-bottom: 0.8rem;
        /* CRITICAL FIX: More space on mobile */
        padding-right: 60px;
        word-wrap: break-word;
        overflow-wrap: break-word;
    }

    .example-box {
        padding: 1rem;
        margin: 2rem 0; /* More top margin */
        position: relative;
        overflow: visible;
    }

    .example-box::before {
        font-size: 0.8rem;
        padding: 4px 12px;
        top: -10px;
        left: 15px;
        z-index: 75; /* Lower than trick number */
        border: 1px solid white;
    }
}

/* EXTRA SMALL SCREENS */
@media (max-width: 480px) {
    .math-trick {
        padding: 1.2rem 0.8rem;
        margin: 2.5rem 0;
        margin-top: 3.2rem; /* More space */
        padding-top: 1.8rem;
    }

    .trick-number {
        width: 34px;
        height: 34px;
        font-size: 0.9rem;
        right: 12px;
        top: -17px;
        z-index: 200; /* Highest on small screens */
    }

    .math-trick h3 {
        font-size: 1.2rem;
        padding-right: 55px;
    }

    .example-box {
        margin: 1.8rem 0; /* More margin */
    }

    .example-box::before {
        font-size: 0.75rem;
        padding: 3px 10px;
        top: -9px;
        left: 12px;
    }
}

/* CRITICAL FIX: First math trick needs extra space */
.math-trick:first-of-type {
    margin-top: 4.5rem !important;
}

@media (max-width: 768px) {
    .math-trick:first-of-type {
        margin-top: 4rem !important;
    }
}

@media (max-width: 480px) {
    .math-trick:first-of-type {
        margin-top: 3.5rem !important;
    }
}

/* CRITICAL FIX: Ensure no overlap with any floating elements */
.math-trick::before {
    content: '';
    position: absolute;
    top: -25px;
    right: 15px;
    width: 50px;
    height: 50px;
    z-index: 99; /* Just below trick number */
    pointer-events: none;
    /* This creates a "reserved space" */
}

/* CRITICAL FIX: Alternative positioning for very crowded layouts */
.math-trick.alt-layout .trick-number {
    top: 15px;
    right: 15px;
    position: absolute;
    /* This puts number inside the card instead of outside */
}

.math-trick.alt-layout {
    padding-top: 3.5rem; /* More space when number is inside */
}

/* CRITICAL FIX: Safe zone for all positioned elements */
.positioned-element-safe-zone {
    position: relative;
    overflow: visible;
    padding-top: 2rem;
    margin-top: 2rem;
}

/* CRITICAL FIX: Z-index hierarchy */
.trick-number { z-index: 100; }
.example-box::before { z-index: 50; }
.math-trick { z-index: 10; }
.main-content { z-index: 1; }

/* CRITICAL FIX: Responsive typography to prevent overflow */
@media (max-width: 360px) {
    .trick-number {
        width: 32px;
        height: 32px;
        font-size: 0.85rem;
    }
    
    .example-box::before {
        font-size: 0.7rem;
        padding: 2px 8px;
    }
}
