* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

@font-face {
    font-family: 'Dancing Script';
    src: url('assets/fonts/DancingScript.ttf') format('truetype');
    font-weight: 400 700;
    font-display: swap;
}

body {
    font-family: 'Dancing Script', cursive;
    background-color: #f5f5f5;
    overflow-x: hidden;
}

.grid-container {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 20px;
    width: 100%;
    min-height: 100vh;
    padding: 20px;
}

/* Desktop: 3-column layout */
@media (min-width: 900px) {
    .grid-container {
        grid-template-columns: repeat(3, 1fr);
        gap: 30px;
        padding: 30px;
    }
}

/* Tablet: 2-column layout */
@media (min-width: 600px) and (max-width: 899px) {
    .grid-container {
        grid-template-columns: repeat(2, 1fr);
        gap: 25px;
        padding: 25px;
    }
}

/* Mobile: 1-column layout */
@media (max-width: 599px) {
    .grid-container {
        grid-template-columns: 1fr;
        gap: 15px;
        padding: 15px;
    }
}

.tile {
    aspect-ratio: 1;
    perspective: 1000px;
    position: relative;
    width: 90%;
    margin: 0 auto;
    background: transparent;
}

/* Fallback for iOS that doesn't support aspect-ratio */
@supports not (aspect-ratio: 1) {
    .tile::before {
        content: '';
        display: block;
        padding-bottom: 100%;
    }

    .tile-inner {
        position: absolute;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
    }
}

/* Mobile: full width */
@media (max-width: 599px) {
    .tile {
        width: 100%;
    }

    /* iOS Safari fix: ensure proper sizing */
    .tile-inner {
        min-height: 100%;
    }

    .tile-image {
        position: relative;
    }

    .tile-image img {
        position: absolute;
        top: 0;
        left: 0;
    }
}

.tile-inner {
    position: relative;
    width: 100%;
    height: 100%;
    transition: transform 0.6s;
    transform-style: preserve-3d;
    background: transparent;
    border-radius: 12px;
}

/* Floating shadow on desktop only - applied to inner */
@media (min-width: 600px) {
    .tile-inner {
        transition: transform 0.6s, box-shadow 0.3s ease;
    }
    
    .tile:hover .tile-inner {
        transform: rotateY(180deg);
        box-shadow: 0 12px 30px rgba(0, 0, 0, 0.2);
    }
    
    .tile-inner:not(:hover) {
        box-shadow: 0 8px 20px rgba(0, 0, 0, 0.15);
    }
    
    .tile:hover {
        transform: translateY(-5px);
    }
}

/* Desktop hover effect */
@media (min-width: 600px) {
    .tile:hover .tile-inner {
        transform: rotateY(180deg);
    }
}

/* Mobile: Enable tap-to-flip for non-clickable tiles */
@media (max-width: 599px) {
    /* Flipped state - applied via JavaScript on tap */
    .tile.flipped .tile-inner {
        transform: rotateY(180deg);
    }

    /* Clickable tiles don't flip on mobile, only open modal */
    .tile.clickable .tile-inner {
        transform: none !important;
    }

    /* Add transition for smooth flipping */
    .tile-inner {
        transition: transform 0.6s;
    }
}

.tile-front,
.tile-back {
    position: absolute;
    width: 100%;
    height: 100%;
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding: 2rem;
    text-align: center;
    border-radius: 12px;
    overflow: hidden;
}

.tile-front {
    z-index: 2;
    transform: rotateY(0deg);
}

.tile-back {
    transform: rotateY(180deg);
}

/* Text tiles - dark background with light text */
.tile-text {
    background-color: #1a1a1a;
    color: #ffffff;
}

.tile-text h2 {
    font-size: 2.5rem;
    font-weight: 700;
    margin-bottom: 1rem;
    letter-spacing: 0.05em;
}

.tile-text h3 {
    font-size: 2rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
}

.tile-text p {
    font-size: 1.1rem;
    line-height: 1.6;
    opacity: 0.9;
}

/* Image tiles - no background */
.tile-image {
    background-color: transparent;
    padding: 0;
    overflow: hidden;
}

.tile-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    -webkit-object-fit: cover;
    display: block;
    /* iOS fix: prevent image shrinking */
    min-width: 100%;
    min-height: 100%;
}

/* Text overlay for tiles with text on color or image backgrounds */
.tile-text-overlay {
    position: absolute;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding: 2rem;
    text-align: center;
    z-index: 1;
}

.tile-text-overlay h2 {
    font-size: 2.5rem;
    font-weight: 700;
    margin-bottom: 1rem;
    letter-spacing: 0.05em;
}

.tile-text-overlay h3 {
    font-size: 2rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
}

.tile-text-overlay p {
    font-size: 1.1rem;
    line-height: 1.6;
    opacity: 0.9;
}

/* Color tiles - bright colors with dark text */
.tile-color {
    color: #1a1a1a;
    font-weight: 600;
}

.tile-color h2 {
    font-size: 3rem;
    font-weight: 700;
    letter-spacing: 0.05em;
}

.tile-color p {
    font-size: 1.2rem;
    line-height: 1.6;
    max-width: 80%;
}

/* Responsive text sizing */
@media (max-width: 599px) {
    .tile-text h2,
    .tile-color h2 {
        font-size: 2rem;
    }
    
    .tile-text h3 {
        font-size: 1.5rem;
    }
    
    .tile-text p,
    .tile-color p {
        font-size: 1rem;
    }
    
    .tile-front,
    .tile-back {
        padding: 1.5rem;
    }
}

/* Smooth transitions */
.tile-inner,
.tile-front,
.tile-back {
    transition: all 0.3s ease;
}

/* Optional: Add subtle shadow on hover */
@media (min-width: 600px) {
    .tile:hover {
        z-index: 10;
    }
}

/* Clickable tiles cursor */
.tile.clickable {
    cursor: pointer;
}

/* Modal styles */
.tile-modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    background-color: rgba(0, 0, 0, 0.9);
    animation: fadeIn 0.3s;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.tile-modal.active {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.tile-modal-content {
    background-color: white;
    border-radius: 12px;
    max-width: 800px;
    width: 100%;
    max-height: 90vh;
    overflow: auto;
    position: relative;
    animation: slideIn 0.3s;
}

@keyframes slideIn {
    from {
        transform: translateY(-50px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.tile-modal-close {
    position: absolute;
    top: 15px;
    right: 20px;
    color: #333;
    font-size: 35px;
    font-weight: bold;
    cursor: pointer;
    z-index: 1001;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: white;
    transition: background 0.3s;
}

.tile-modal-close:hover,
.tile-modal-close:focus {
    background: #f0f0f0;
}

.tile-modal-image {
    width: 100%;
    max-height: 500px;
    overflow: hidden;
    border-radius: 12px 12px 0 0;
}

.tile-modal-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.tile-modal-text {
    padding: 30px;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    color: #333;
    line-height: 1.6;
    font-size: 16px;
}

.tile-modal-text h2 {
    margin-bottom: 15px;
    font-size: 24px;
}

.tile-modal-text p {
    margin-bottom: 10px;
}

/* Responsive modal */
@media (max-width: 599px) {
    .tile-modal-content {
        max-width: 95%;
    }

    .tile-modal-text {
        padding: 20px;
        font-size: 14px;
    }

    .tile-modal-image {
        max-height: 300px;
    }
}
