/* Flash Cards Container */
.flash-cards-section {
    max-width: 800px;
    margin: 2rem auto 4rem;
    padding: 0 1rem;
    perspective: 1000px;
    /* Enable 3D space */
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}

body:not(.flash-mode-active) .flash-cards-section {
    cursor: pointer;
}

body:not(.flash-mode-active) .flash-cards-section:hover {
    transform: scale(1.02);
}

/* Card Wrapper needed for positioning arrows relative to it */
.card-wrapper {
    position: relative;
    width: 100%;
    aspect-ratio: 1.8 / 1;
    /* Classic flashcard ratio */
}

/* The Card Itself */
.flash-card {
    width: 100%;
    height: 100%;
    position: relative;
    transform-style: preserve-3d;
    transition: transform 0.6s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    /* Bouncy flip */
    cursor: pointer;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.08);
    border-radius: 20px;
}

.flash-card.is-flipped {
    transform: rotateY(180deg);
}

/* Common Face Styles */
.card-face {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    -webkit-backface-visibility: hidden;
    -moz-backface-visibility: hidden;
    backface-visibility: hidden;
    /* Hide back when flipped */
    border-radius: 20px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
    padding: 2rem;
    background: white;
    border: 2px solid var(--border);
    /* Prevent text selection during swipe */
    user-select: none;
    -webkit-user-select: none;
}

/* Front Face */
.card-front {
    z-index: 2;
    transform: rotateY(0deg) translateZ(1px);
    /* Fix for Firefox backface-visibility bug */
}

/* Back Face */
.card-back {
    transform: rotateY(180deg) translateZ(1px);
    background: #f8fafc;
    /* Slightly different bg for back */
    display: flex;
    flex-direction: column;
    justify-content: center;
}

/* Typography on Card */
.card-label {
    font-size: 0.9rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--text-muted);
    margin-bottom: 1rem;
    font-weight: 700;
}

.card-title {
    font-size: 1.8rem;
    font-weight: 800;
    color: var(--text-primary);
    font-family: 'Space Grotesk', sans-serif;
    line-height: 1.3;
}

.card-math {
    font-family: serif;
    /* Math looks better in serif */
    font-size: 2.2rem;
    color: var(--accent-primary);
    margin-bottom: 1rem;
}

.card-gift {
    font-size: 1rem;
    color: #166534;
    background: #f0fdf4;
    padding: 0.5rem 1rem;
    border-radius: 20px;
    font-weight: 600;
}

/* Navigation Controls (Desktop mainly) */
.card-nav-btn {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: white;
    border: 1px solid var(--border);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    color: var(--text-primary);
    transition: all 0.2s;
    z-index: 10;
}

.card-nav-btn:hover {
    background: var(--bg-secondary);
    transform: translateY(-50%) scale(1.1);
}

.nav-prev {
    left: -60px;
}

.nav-next {
    right: -60px;
}

/* --- FULL SCREEN FLASH CARD MODE --- */
body.flash-mode-active {
    overflow: hidden !important;
    /* Lock background scrolling */
}

body.flash-mode-active .flash-cards-section {
    position: fixed !important;
    top: 0 !important;
    bottom: 0 !important;
    left: 60px !important;
    /* Preserve exactly the left rail */
    right: 0 !important;
    width: calc(100vw - 60px) !important;
    max-width: none !important;
    height: 100vh !important;
    z-index: 9999 !important;
    /* Cover everything else */
    background: var(--bg-main, #fafafa) !important;
    margin: 0 !important;
    padding: 2rem 5% !important;
    /* Add some comfortable breathing room */
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    overflow-y: auto;
    /* Allow scrolling if card is too tall for small screens */
}

@media (max-width: 768px) {
    body.flash-mode-active .flash-cards-section {
        left: 60px !important;
        transform: none !important;
        margin: 0 !important;
        padding: 1rem 5% !important;
        width: calc(100vw - 60px) !important;
    }
}

/* In flash mode, the wrapper needs to be contained so it doesn't grow infinitely */
body.flash-mode-active .card-wrapper {
    max-width: 1200px;
    /* ENLARGED: Let the card be massive if space permits */
    width: 95%;
    /* Take up most of the container */
    height: 60vh;
    /* Make the card very tall */
    min-height: 400px;
    margin: 0 auto;
    flex-shrink: 0;
}

/* Close Button Header Container */
.flash-header-actions {
    display: none;
    width: 100%;
    max-width: 1200px;
    justify-content: flex-end;
    margin-bottom: 2rem;
}

body.flash-mode-active .flash-header-actions {
    display: flex;
    /* Show only when in flash mode */
}

.flash-close-btn {
    background: white;
    border: 1px solid var(--border-strong, #e5e7eb);
    color: var(--text-secondary, #4b5563);
    border-radius: 50%;
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
    transition: all 0.2s;
}

.flash-close-btn:hover {
    background: #fef2f2;
    color: #ef4444;
    border-color: #ef4444;
    transform: scale(1.05);
}

/* Tap Hint / Swipe Hint */
.interaction-hint {
    text-align: center;
    margin-top: 1.5rem;
    color: var(--text-muted);
    font-size: 0.9rem;
    display: flex;
    justify-content: center;
    gap: 1.5rem;
}

.hint-icon {
    font-size: 1.1rem;
    vertical-align: middle;
}

/* Visual Plot Additions */
.card-visual {
    width: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    margin-bottom: 0.5rem;
    min-height: 100px;
}

.circle-plot {
    position: relative;
    width: 140px;
    height: 140px;
    margin-top: 5px;
    flex-shrink: 0;
}

.circle-plot-circle {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    border: 2px solid var(--text-primary);
    border-radius: 50%;
}

.circle-plot-center {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 6px;
    height: 6px;
    background: var(--text-primary);
    border-radius: 50%;
    transform: translate(-50%, -50%);
}

.circle-plot-radius {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 50%;
    height: 2px;
    background: var(--text-primary);
    transform-origin: left center;
    transform: rotate(-35deg);
}

.circle-plot-center-label {
    position: absolute;
    top: 58%;
    left: 50%;
    transform: translateX(-50%);
    font-size: 1rem;
    white-space: nowrap;
}

.circle-plot-radius-label {
    position: absolute;
    top: 25%;
    left: 60%;
    font-size: 1.1rem;
    white-space: nowrap;
}

/* Specific Classes for Line Equation Layout */
.card-visual-flex {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-wrap: wrap;
    gap: 2rem;
    width: 100%;
}

.card-visual-svg-container {
    flex-shrink: 0;
    background-color: #fdfaf6;
    border: 1px solid #eaddcf;
    border-radius: 16px;
    padding: 2rem 1.5rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.5rem;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.02);
    max-width: 310px;
}

.card-visual-text {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    text-align: left;
    font-size: 1rem;
    line-height: 1.5;
    padding-bottom: 1rem;
    max-width: 400px;
}

/* Mobile Responsiveness */
@media (max-width: 768px) {
    .flash-cards-section {
        /* Safer approach: Exact width of screen minus the 60px left rail */
        width: calc(100vw - 60px) !important;
        position: relative !important;
        /* Center relative to the available space */
        left: 50% !important;
        transform: translateX(-50%) !important;
        margin: 2rem 0 !important;
        padding: 0 10px !important;
    }

    .card-wrapper {
        /* Remove fixed aspect ratio to allow growth */
        aspect-ratio: auto !important;
        width: 100% !important;
        min-height: 480px !important;
        height: auto !important;
        max-height: 85vh !important;
    }

    .flash-card {
        height: 100% !important;
        /* Fill wrapper */
        min-height: 480px !important;
    }

    .card-title {
        font-size: 1.4rem !important;
        padding: 0 0.5rem;
    }

    .card-math {
        font-size: 1.5rem !important;
        /* Fixed robust size */
        white-space: nowrap !important;
        /* Force single line to trigger scroll */
        max-width: 100%;
        line-height: normal !important;
        padding: 1rem 0 !important;
        /* Ensure MathJax scales down if still too wide */
        /* Remove flex here to allow block layout */
        display: block !important;
        text-align: center;
        overflow-x: auto !important;
        /* FORCE SCROLL */
        overflow-y: hidden !important;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: thin;
        /* Replace margin: 0 with vertical spacing to prevent overlap */
        margin: 1.5rem 0 1rem !important;
        width: 100% !important;
    }

    /* Flexbox centering for faces */
    .card-face {
        position: absolute !important;
        /* Keep absolute for flip effect */
        top: 0;
        left: 0;
        width: 100% !important;
        height: 100% !important;
        display: flex !important;
        flex-direction: column !important;
        justify-content: flex-start !important;
        align-items: center !important;
        /* Add padding to prevent text touching edges */
        padding: 1.5rem 1rem !important;
        overflow-y: auto !important;
        overflow-x: hidden !important;
        /* Allow vertical scrolling if content is too tall */
    }

    .card-face>div {
        flex-shrink: 0 !important;
    }

    .card-front {
        justify-content: center !important;
        /* Keep front content centered */
    }

    /* Target the visual output wrapping element specifically for mobile */
    .card-visual>div {
        flex-direction: column !important;
        gap: 1rem !important;
    }

    .card-visual>div>div:first-child {
        padding: 1rem !important;
    }

    .card-visual-text {
        padding-bottom: 2.5rem !important;
    }

    .nav-prev,
    .nav-next {
        display: none;
    }
}