/* Reset and base styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

/* Mobile-first approach */
:root {
    --primary-color: #3498db;
    --secondary-color: #2980b9;
    --text-color: #34495e;
    --background-start: #f5f7fa;
    --background-end: #c3cfe2;
    --container-width: min(95%, 800px);
}

html, body {
    height: 100%;
    width: 100%;
    overflow-x: hidden;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
    background: #F8E898;
    color: var(--text-color);
    line-height: 1.6;
}

.wrapper {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    padding: 1rem 1rem 2rem;
    gap: 3.5rem;
    position: relative;
}

h1 {
    font-family: 'Schoolbell', cursive;
    font-size: min(2.5rem, 10vw);
    color: var(--text-color);
    text-align: center;
    font-weight: 400;
    margin-top: 1.5rem;
    line-height: 1.3;
}

.wrapper p {
    margin-top: 0.5rem;
    color: var(--text-color);
    text-align: center;
    font-size: min(1.1rem, 4vw);
}

.dish-container {
    position: relative;
    width: 100%;
    max-width: 750px;
    margin: 0 auto;
    padding: 1rem 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    min-height: auto;
}

.dish-image {
    width: 85%;
    height: auto;
    position: absolute;
    top: 52%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 1;
    pointer-events: none;
}

.container {
    position: relative;
    width: var(--container-width);
    border-radius: 20px;
    padding: 0 1.5rem;
    margin: 0 auto;
    z-index: 2;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.cookies-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0;
    margin: 0 auto;
    max-width: 700px;
    position: relative;
    z-index: 3;
    align-items: center;
    justify-items: center;
    padding: 0;
    transform: scale(0.9);
}

.cookie-wrapper {
    position: relative;
    perspective: 1000px;
    cursor: pointer;
    transition: transform 0.3s ease;
    width: 100%;
    max-width: clamp(130px, 22vw, 180px);
    padding: 0;
    margin: -10px;
}

.cookie-wrapper:nth-child(1) .cookie-image {
    transform: rotate(-15deg);
}

.cookie-wrapper:nth-child(2) .cookie-image {
    transform: rotate(45deg);
}

.cookie-wrapper:nth-child(3) .cookie-image {
    transform: rotate(-8deg);
}

.cookie-wrapper:nth-child(4) .cookie-image {
    transform: rotate(15deg);
}

.cookie-wrapper:nth-child(5) .cookie-image {
    transform: rotate(-20deg);
}

.cookie-wrapper:nth-child(6) .cookie-image {
    transform: rotate(15deg);
}

.cookie-wrapper:hover .cookie-image {
    transform: rotate(0deg) scale(1.1);
}

.cookie-image {
    width: 100%;
    height: auto;
    aspect-ratio: 1;
    transition: transform 0.3s ease;
    -webkit-transform: translateZ(0);
    will-change: transform;
    object-fit: contain;
    padding: clamp(5px, 1vw, 10px);
}

.cookie-wrapper.disabled {
    opacity: 0.5;
    cursor: default;
    pointer-events: none;
}

.fortune-text {
    background: url('FortuneNote.png') no-repeat center center;
    background-size: 100% 100%;
    padding: 2rem 3rem;
    margin: 0;
    font-size: min(1.1rem, 4.5vw);
    min-height: 100px;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    line-height: 1.5;
    max-width: 500px;
    width: 90%;
    position: relative;
    z-index: 3;
    color: #2c3e50;
    font-weight: 500;
    opacity: 1;
    transform: translateY(0);
    transition: opacity 0.3s ease, transform 0.3s ease;
}

.hidden {
    opacity: 0;
    transform: translateY(-20px);
    pointer-events: none;
    position: absolute;
}

.button {
    background: var(--primary-color);
    color: white;
    border: none;
    padding: 0.8em 1.5em;
    border-radius: 50px;
    font-size: min(1rem, 4vw);
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    outline: none;
    position: relative;
    z-index: 3;
    margin-top: 1rem;
}

.button:hover {
    background: var(--secondary-color);
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
}

.button:active {
    transform: translateY(1px);
}

@keyframes breakCookie {
    0% { transform: rotate(0) scale(1); }
    50% { transform: rotate(180deg) scale(1.2); }
    100% { transform: rotate(360deg) scale(1); }
}

.cookie-image.clicked {
    animation: breakCookie 1s ease forwards;
}

/* Media Queries */
@media screen and (max-width: 600px) {
    h1 {
        font-family: 'Schoolbell', cursive;
        font-size: min(2rem, 10vw);
        line-height: 1.3;
    }

    .wrapper {
        padding: 2rem 0.5rem 1.5rem;
        gap: 3.5rem;
    }

    .dish-container {
        padding: 2rem 0;
    }

    .dish-image {
        width: 120%;
    }

    .cookie-wrapper {
        max-width: clamp(110px, 30vw, 150px);
        margin: -8px;
    }

    .cookies-grid {
        transform: scale(1.1);
    }

    h1 {
        margin-top: 1rem;
        margin-bottom: 0;
    }

    .container {
        padding: 0.5rem;
    }

    .fortune-text {
        padding: 1.5rem 2rem;
        min-height: 80px;
        font-size: min(1rem, 4.2vw);
        width: 95%;
    }

    .button {
        margin-top: 1.5rem;
    }

    .rotate-button {
        width: 40px;
        height: 40px;
        position: relative;
        bottom: auto;
        right: auto;
        margin-top: 1rem;
    }
}

@media screen and (min-width: 601px) and (max-width: 900px) {
    .wrapper {
        padding: 1.25rem 1rem 2rem;
        gap: 3rem;
    }

    .rotate-button {
        width: 42px;
        height: 42px;
        position: relative;
        bottom: auto;
        right: auto;
        margin-top: 1.5rem;
    }

    .dish-container {
        padding: 1rem 0;
        max-width: 560px;
    }

    .dish-image {
        width: 110%;
    }

    .cookies-grid {
        transform: scale(1);
    }

    .cookie-wrapper {
        max-width: clamp(120px, 25vw, 160px);
        margin: -8px;
    }

    .fortune-text {
        padding: 1.75rem 2.5rem;
        width: 92%;
    }

    .button {
        margin-top: 1.75rem;
    }
}

/* Touch device optimizations */
@media (hover: none) {
    .cookie-wrapper:hover {
        transform: none;
    }

    .cookie-wrapper:hover .cookie-image {
        transform: none;
    }

    .button:hover {
        transform: none;
        box-shadow: none;
    }
}

/* Tablet and larger screens */
@media screen and (min-width: 768px) {
    .container {
        padding: 2rem;
    }

    .fortune-text {
        padding: 1.5rem;
        margin: 1rem auto;
        font-size: 1.2rem;
        min-height: 100px;
    }

    .button {
        font-size: 1.1rem;
        padding: 1em 2em;
    }
}

/* Landscape mode optimization */
@media screen and (max-height: 600px) and (orientation: landscape) {
    .wrapper {
        padding: 0.5rem;
    }

    .container {
        padding: 1rem;
    }

    .cookie-container {
        margin: 1rem auto;
    }

    .fortune-text {
        margin: 1rem auto;
        min-height: 60px;
        padding: 0.8rem;
    }
}

/* High-DPI screens 
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    .container {
        box-shadow: 
            0 10px 30px rgba(0, 0, 0, 0.1),
            0 6px 10px rgba(0, 0, 0, 0.08);
    }
} */

.highlight {
    font-style: italic;
    color: #C26511;
}

.rotate-button {
    background: transparent;
    border: none;
    width: 45px;
    height: 45px;
    cursor: pointer;
    transition: all 0.3s ease;
    outline: none;
    position: fixed;
    bottom: 40px;
    right: 40px;
    z-index: 3;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.redo-icon {
    width: 100%;
    height: 100%;
    object-fit: contain;
    transition: transform 0.3s ease;
}

.rotate-button:hover .redo-icon {
    transform: rotate(180deg);
}

.rotate-button:active .redo-icon {
    transform: rotate(360deg);
}

@media screen and (max-width: 900px) {
    .rotate-button {
        position: relative;
        bottom: auto;
        right: auto;
        margin-top: 1rem;
    }
}