/* Base resets and helpers */
*,
*::before,
*::after {
    box-sizing: border-box;
}

@media (max-width: 600px) {
    :root {
        --nav-height: 100px;
    }
}

html,
body {
    margin: 0;
    padding: 0;
}

body {
    font-family: system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
    line-height: 1.4;
}

.wrap {
    max-width: 1100px;
    margin: 125px auto;
    padding: 16px;
}

/* Hide heading from visual layout but keep it for screen readers */
.visually-hidden {
    position: absolute !important;
    height: 1px;
    width: 1px;
    overflow: hidden;
    clip: rect(1px, 1px, 1px, 1px);
    white-space: nowrap;
    border: 0;
    padding: 0;
    margin: -1px;
}

/* Flex grid: 6 cards total */
.flex-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
    /* space between cards */
}

/* Card sizing:
   - Desktop (default): 3 per row
   - Tablet: 2 per row
   - Mobile: 1 per row
*/
.card {
    position: relative;

    /* Button reset */
    display: flex;
    flex-direction: column;
    padding: 0;
    border: 0;
    background: none;
    font: inherit;
    text-align: left;
    cursor: pointer;
    color: inherit;

    /* 3 per row minus gaps */
    flex: 1 1 calc(33.333% - 16px);
    min-width: 0;
    /* prevent flex overflow */

    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 1px 3px rgba(15, 23, 42, 0.15);
    transition: box-shadow 160ms ease, transform 160ms ease;
}

/* Tablet breakpoint */
@media (max-width: 900px) {
    .card {
        flex-basis: calc(50% - 16px);
    }
}

/* Mobile breakpoint */
@media (max-width: 600px) {
    .card {
        flex-basis: 100%;
    }
}

/* Top media section (image + overlay) */
.card-media {
    position: relative;
    border-radius: 12px 12px 0 0;
    overflow: hidden;
    width: 100%;

    /* 300x225 aspect ratio = 4:3 = 75% */
    padding-bottom: 75%;
    height: 0;
    transition: padding-bottom 300ms ease, height 300ms ease;
}

/* When card is expanded, show only bottom 100px of the media */
.card[aria-expanded="true"] .card-media {
    height: 100px;
    padding-bottom: 0;
}

/* Image fills the media area */
.card-media img {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center;
    display: block;
    transition: object-position 300ms ease;
}

/* When expanded, keep image at original size but position to show bottom */
.card[aria-expanded="true"] .card-media img {
    position: absolute;
    height: auto;
    min-height: 100%;
    object-position: center bottom;
}

/* Translucent overlay with text */
.overlay {
    position: absolute;
    inset: 0;

    /* Subtle gradient + translucency; stronger on hover/focus */
    background: linear-gradient(to top,
            rgba(0, 0, 0, 0.55),
            rgba(0, 0, 0, 0.15));
    color: #fff;

    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    gap: 4px;

    padding: 14px;
    transition: background 160ms ease;
}

/* Overlay text styles */
.overlay h3 {
    margin: 0;
    font-size: 1.1rem;
    font-weight: 700;
}

.overlay p {
    margin: 0;
    font-size: 0.95rem;
    opacity: 0.9;
}

/* Donation details panel (collapsed by default) */
.card-details {
    padding: 12px 14px 16px;
    background: #f9fafb;
    color: #111827;
    font-size: 0.95rem;
    border-radius: 0 0 12px 12px;
    border-top: 1px solid #e5e7eb;

    max-height: 0;
    opacity: 0;
    overflow: hidden;
    transition: max-height 200ms ease, opacity 200ms ease;
}

/* Center forms and their submit images/buttons inside details */
.card-details form {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
}

.card-details input[type="image"],
.card-details .qrCodeImg,
.card-details input[type="submit"] {
    max-width: 280px;
    height: auto;
    margin: 0 auto;
}

/* Simple list styling inside details */
.card-details ul {
    margin: 8px 0 0;
    padding-left: 18px;
}

.card-details li {
    margin: 4px 0;
}

/* Expanded state driven by aria-expanded */
.card[aria-expanded="true"] {
    box-shadow: 0 4px 16px rgba(15, 23, 42, 0.2);
    transform: translateY(-2px);
}

.card[aria-expanded="true"] .card-details {
    max-height: 400px;
    /* big enough to fit typical content */
    opacity: 1;
}

/* When a card contains an iframe, allow the details to expand larger
   so the iframe isn't cramped. We add the `expanded-iframe` class via JS
   to the expanded card to trigger this behavior. */
.card.expanded-iframe {
    position: relative;
    z-index: 1;
    /* keep below header (header is z-index: 2) */
    margin-top: 20px;
}

.card.expanded-iframe .card-details {
    max-height: none;
    opacity: 1;
    width: 100%;
}

/* Taller iframe when expanded: aim to minimize internal scrolling.
   Uses near-full viewport height with an upper cap for very tall screens. */
.card.expanded-iframe .card-details iframe {
    display: block;
    width: 100%;
    max-width: 100%;
    height: min(135vh, 1250px);
    border: 0;
}

@media (max-width: 600px) {
    .card.expanded-iframe .card-details iframe {
        height: min(145vh, 1330px);
    }
}

/* Tablet and Desktop: allow iframe cards to expand horizontally and center them */
@media (min-width: 601px) {
    .flex-grid {
        /* center expanded card if present */
        justify-content: center;
    }

    .card.expanded-iframe {
        /* take most of the row so iframe has room - works for both 2-column and 3-column */
        flex: 0 0 85%;
        max-width: 1200px;
        margin: 20px auto 0;
    }

    /* Make sure the details area can overflow visible space when expanded */
    .card.expanded-iframe .card-details {
        overflow: visible;
        width: 100%;
    }
}

/* Desktop (3-column): slightly narrower for better centering */
@media (min-width: 900px) {
    .card.expanded-iframe {
        flex: 0 0 80%;
    }
}

/* Hover / focus polish (desktop-only effect really) */
.card:hover .overlay,
.card:focus-visible .overlay {
    background: linear-gradient(to top,
            rgba(0, 0, 0, 0.65),
            rgba(0, 0, 0, 0.25));
}

.card:hover .card-media img,
.card:focus-visible .card-media img {
    transform: scale(1.02);
    will-change: transform;
}

/* Keyboard focus ring for accessibility */
.card:focus-visible {
    outline: 3px solid #5b9dd9;
    outline-offset: 3px;
    border-radius: 14px;
}

/* Recycle4Charity box */
.recycle-box {
    display: flex;
    justify-content: center;
    align-items: stretch;
    width: 100%;
    margin: 8px auto 0;
    padding: 0 8px;
    box-sizing: border-box;
}

.recycle-link {
    position: relative;
    display: block;
    border: 2px solid #58875d;
    border-radius: 6px;
    max-width: 100%;
    background: #7dad17;
    cursor: pointer;
    font-family: Helvetica, Arial, sans-serif;
    text-decoration: none;
    text-align: center;
    overflow: hidden;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.15);
    transition: transform 160ms ease, box-shadow 160ms ease;
}

.recycle-link:hover,
.recycle-link:focus-visible {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
}

.recycle-link:focus-visible {
    outline: 3px solid #5b9dd9;
    outline-offset: 3px;
}

.recycle-heading {
    display: block;
    padding: 18px 16px 14px 16px;
    background: #7dad17;
    font-size: 1.05rem;
    line-height: 1.3;
    color: #fff;
    font-weight: 600;
}

.recycle-cta {
    display: block;
    padding: 16px;
    background: #f4f4f4;
    font-size: 0.95rem;
    line-height: 1.3;
    color: #7dad17;
    font-weight: 600;
    border-top: 1px solid rgba(88, 135, 93, 0.15);
}

@media (max-width: 600px) {
    .recycle-link {
        width: 100%;
    }

    .recycle-heading {
        font-size: 0.95rem;
        padding: 14px 12px 10px;
        line-height: 1.25;
    }

    .recycle-cta {
        font-size: 0.85rem;
        padding: 12px;
        line-height: 1.25;
    }
}