/* ============================================
   FONOLOGIA GIOCO - Styles
   ============================================ */

/* Reset & Base */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html, body {
    height: 100%;
    overflow: hidden;
    font-family: 'Segoe UI', 'Comic Sans MS', Tahoma, sans-serif;
}

body {
    background: #1a1a2e;
}

/* ============================================
   ANIMATED BACKGROUND
   ============================================ */
.background-animated {
    position: fixed;
    top: -5%;
    left: -5%;
    width: 115%;
    height: 115%;
    z-index: -1;
    overflow: hidden;
}

.background-animated img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    animation: backgroundFloat 30s ease-in-out infinite;
}

@keyframes backgroundFloat {
    0%, 100% {
        transform: translate(0, 0) scale(1);
    }
    25% {
        transform: translate(2%, 1%) scale(1.02);
    }
    50% {
        transform: translate(-1%, 2%) scale(1.01);
    }
    75% {
        transform: translate(1%, -1%) scale(1.03);
    }
}

/* ============================================
   FLOATING LOGO
   ============================================ */
.floating-logo {
    display: inline-block;
    margin-bottom: 20px;
    z-index: 100;
    pointer-events: none;
}

.logo {
    height: 150px;
    width: auto;
    filter: drop-shadow(0 10px 30px rgba(0, 0, 0, 0.4));
    transform-origin: center center;
    transition: filter 0.3s ease;
}

.logo:hover {
    filter: drop-shadow(0 15px 40px rgba(255, 107, 107, 0.5));
}

/* ============================================
   FLOATING TOGGLE
   ============================================ */
.floating-toggle {
    float: right;
    margin-bottom: 20px;
    z-index: 100;
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.95), rgba(255, 255, 255, 0.85));
    padding: 12px 20px;
    border-radius: 50px;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.3),
                0 0 0 3px rgba(255, 107, 107, 0.3);
    animation: togglePulse 3s ease-in-out infinite;
}

@keyframes togglePulse {
    0%, 100% {
        box-shadow: 0 8px 30px rgba(0, 0, 0, 0.3),
                    0 0 0 3px rgba(255, 107, 107, 0.3);
    }
    50% {
        box-shadow: 0 8px 30px rgba(0, 0, 0, 0.4),
                    0 0 0 5px rgba(254, 202, 87, 0.4);
    }
}

/* Toggle Switch */
.toggle-label {
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    font-weight: 600;
    color: #333;
}

.toggle-label input {
    display: none;
}

.toggle-slider {
    width: 50px;
    height: 28px;
    background: #ccc;
    border-radius: 28px;
    position: relative;
    transition: all 0.3s ease;
}

.toggle-slider::before {
    content: '';
    position: absolute;
    width: 22px;
    height: 22px;
    background: white;
    border-radius: 50%;
    top: 3px;
    left: 3px;
    transition: all 0.3s ease;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
}

.toggle-label input:checked + .toggle-slider {
    background: linear-gradient(135deg, #ff6b6b, #feca57);
}

.toggle-label input:checked + .toggle-slider::before {
    transform: translateX(22px);
}

.toggle-text {
    font-size: 14px;
    color: #444;
}

/* ============================================
   MAIN CONTAINER
   ============================================ */
.main-container {
    height: 100vh;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 20px;
    padding-top: 20px;
    scrollbar-width: thin;
    scrollbar-color: #ff6b6b #ffffff33;
}

.main-container::-webkit-scrollbar {
    width: 10px;
}

.main-container::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 10px;
}

.main-container::-webkit-scrollbar-thumb {
    background: linear-gradient(180deg, #ff6b6b, #feca57);
    border-radius: 10px;
}

/* ============================================
   MASONRY GRID CONTAINER (Left to Right ordering)
   ============================================ */
.grid-container {
    position: relative;
    padding: 10px;
    clear: both;
    margin-bottom: 160px;
}

.grid-container .card {
    position: absolute;
    width: calc(20% - 16px);
    transition: top 0.4s ease, left 0.4s ease, transform 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

/* ============================================
   CARDS
   ============================================ */
.card {
    background: linear-gradient(145deg, #ffffff, #f0f0f0);
    border-radius: 25px;
    overflow: hidden;
    cursor: pointer;
    transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.15),
                inset 0 1px 0 rgba(255, 255, 255, 0.8);
    position: relative;
    animation: cardAppear 0.6s ease-out backwards;
}

.card:nth-child(1) { animation-delay: 0.02s; }
.card:nth-child(2) { animation-delay: 0.04s; }
.card:nth-child(3) { animation-delay: 0.06s; }
.card:nth-child(4) { animation-delay: 0.08s; }
.card:nth-child(5) { animation-delay: 0.1s; }
.card:nth-child(6) { animation-delay: 0.12s; }
.card:nth-child(7) { animation-delay: 0.14s; }
.card:nth-child(8) { animation-delay: 0.16s; }
.card:nth-child(9) { animation-delay: 0.18s; }
.card:nth-child(10) { animation-delay: 0.2s; }
.card:nth-child(n+11) { animation-delay: 0.22s; }

@keyframes cardAppear {
    0% {
        opacity: 0;
        transform: scale(0.5) rotate(-10deg);
    }
    100% {
        opacity: 1;
        transform: scale(1) rotate(0);
    }
}

/* AMPLIFIED Rainbow Border Effect */
.card::before {
    content: '';
    position: absolute;
    top: -6px;
    left: -6px;
    right: -6px;
    bottom: -6px;
    border-radius: 30px;
    background: linear-gradient(
        45deg,
        #ff0000d4, #00ffb5e0, #ffffff, #00ff00d6,
        #0000ff8c, #fff300, #9400d38a, #ff4d00f2
    );
    background-size: 400% 400%;
    z-index: -1;
    opacity: 0;
    transition: opacity 0.3s ease;
    animation: rainbowShift 3s linear infinite paused;
}

.card:hover {
    transform: scale(1.05);
    box-shadow:
        0 0 30px rgba(255, 107, 107, 0.6),
        0 0 60px rgba(254, 202, 87, 0.4),
        0 0 90px rgba(72, 219, 251, 0.3),
        0 20px 50px rgba(0, 0, 0, 0.3);
}

.card:hover::before {
    opacity: 1;
    animation-play-state: running;
}

@keyframes rainbowShift {
    0% {
        background-position: 0% 50%;
        filter: hue-rotate(0deg) brightness(1.1);
    }
    50% {
        background-position: 100% 50%;
        filter: hue-rotate(180deg) brightness(1.2);
    }
    100% {
        background-position: 0% 50%;
        filter: hue-rotate(360deg) brightness(1.1);
    }
}

.card-inner {
    padding: 6px;
    display: flex;
    flex-direction: column;
    align-items: center;
}

/* ============================================
   DOOR CONTAINER - 3D Perspective
   ============================================ */
.door-container {
    max-height:290px;
    position: relative;
    width: 100%;
    aspect-ratio: 3/4;
    perspective: 1000px;
    overflow: visible;
}

/* Hidden figurine behind the door */
.door-reveal {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: #ffffff;
    border-radius: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.figurine-image {
    max-width: 90%;
    max-height: 90%;
    object-fit: contain;
    transform: scale(0.85);
    opacity: 1;
    transition: none;
}

/* Door opening - figurine zooms */
.card.door-opening .figurine-image {
    animation: figurineZoomIn 0.6s cubic-bezier(0.175, 0.885, 0.32, 1.275) 0.35s forwards;
}

@keyframes figurineZoomIn {
    0% {
        transform: scale(0.85);
        opacity: 1;
    }
    60% {
        transform: scale(1.8);
        opacity: 0.5;
    }
    100% {
        transform: scale(4);
        opacity: 0;
    }
}

/* Door closing - figurine zooms out */
.card.door-closing .figurine-image {
    animation: figurineZoomOut 0.5s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

@keyframes figurineZoomOut {
    0% {
        transform: scale(4);
        opacity: 0;
    }
    40% {
        transform: scale(1.5);
        opacity: 0.5;
    }
    100% {
        transform: scale(0.85);
        opacity: 1;
    }
}

/* ============================================
   DOOR - The swinging door element
   ============================================ */
.door {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    transform-style: preserve-3d;
    transform-origin: left center;
    transition: transform 0.7s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 10;
}

.door.opening {
    transform: rotateY(-105deg);
}

.door.closing {
    transform: rotateY(0deg);
    transition: transform 0.5s cubic-bezier(0.4, 0, 0.2, 1) 0.4s;
}

/* Door Panel - Main visible surface */
.door-panel {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    border-radius: 18px;
    box-shadow:
        inset 0 0 40px rgba(0,0,0,0.15),
        0 10px 40px rgba(0,0,0,0.25);
    overflow: hidden;
    backface-visibility: hidden;
}

/* Door edge thickness when open */
.door::after {
    content: '';
    position: absolute;
    top: 0;
    left: 100%;
    width: 12px;
    height: 100%;
    background: linear-gradient(90deg, rgba(0,0,0,0.4), rgba(0,0,0,0.15));
    transform: rotateY(90deg);
    transform-origin: left center;
    border-radius: 0 4px 4px 0;
}

/* ============================================
   DOOR COLORS - 6 Vibrant Options
   ============================================ */
.door[data-color="1"] .door-panel {
    background: linear-gradient(145deg, #ff6b6b 0%, #ee5a5a 50%, #d94545 100%);
}
.door[data-color="2"] .door-panel {
    background: linear-gradient(145deg, #feca57 0%, #f39c12 50%, #e67e22 100%);
}
.door[data-color="3"] .door-panel {
    background: linear-gradient(145deg, #48dbfb 0%, #0abde3 50%, #0097b2 100%);
}
.door[data-color="4"] .door-panel {
    background: linear-gradient(145deg, #ff9ff3 0%, #f368e0 50%, #c44cbb 100%);
}
.door[data-color="5"] .door-panel {
    background: linear-gradient(145deg, #1dd1a1 0%, #10ac84 50%, #0a8967 100%);
}
.door[data-color="6"] .door-panel {
    background: linear-gradient(145deg, #a29bfe 0%, #6c5ce7 50%, #5341d0 100%);
}

/* Door Frame - Decorative border */
.door-frame {
    position: absolute;
    top: 10px;
    left: 10px;
    right: 10px;
    bottom: 10px;
    border: 5px solid rgba(255,255,255,0.35);
    border-radius: 12px;
    pointer-events: none;
}

/* Decorative Window on Door */
.door-window {
    position: absolute;
    top: 12%;
    left: 18%;
    width: 64%;
    height: 28%;
    background: linear-gradient(
        180deg,
        rgba(255,255,255,0.7) 0%,
        rgba(255,255,255,0.4) 50%,
        rgba(255,255,255,0.2) 100%
    );
    border-radius: 50% 50% 10px 10px;
    border: 4px solid rgba(255,255,255,0.5);
    box-shadow:
        inset 0 0 20px rgba(255,255,255,0.4),
        0 4px 15px rgba(0,0,0,0.1);
}

/* Door Handle */
.door-handle {
    position: absolute;
    right: 14%;
    top: 52%;
    width: 14px;
    height: 35px;
    background: linear-gradient(
        135deg,
        #ffd700 0%,
        #f5d742 30%,
        #d4a017 70%,
        #b8860b 100%
    );
    border-radius: 7px;
    box-shadow:
        3px 3px 8px rgba(0,0,0,0.35),
        inset 0 2px 4px rgba(255,255,255,0.6),
        inset 0 -2px 4px rgba(0,0,0,0.2);
}

/* Door Number - Centered on door */
.door-number {
    position: absolute;
    top: 55%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 65px;
    height: 65px;
    background: linear-gradient(145deg, #ffffff 0%, #f8f8f8 50%, #e8e8e8 100%);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 28px;
    font-weight: bold;
    color: #333;
    box-shadow:
        0 6px 25px rgba(0,0,0,0.35),
        inset 0 3px 6px rgba(255,255,255,0.9),
        inset 0 -2px 4px rgba(0,0,0,0.1);
    z-index: 5;
    animation: doorNumberPulse 2.5s ease-in-out infinite;
}

@keyframes doorNumberPulse {
    0%, 100% { transform: translate(-50%, -50%) scale(1); }
    50% { transform: translate(-50%, -50%) scale(1.08); }
}

/* Hover effect on door */
.card:hover .door-number {
    animation: doorNumberBounce 0.6s ease-in-out;
}

@keyframes doorNumberBounce {
    0%, 100% { transform: translate(-50%, -50%) scale(1); }
    30% { transform: translate(-50%, -50%) scale(1.15); }
    60% { transform: translate(-50%, -50%) scale(0.95); }
}

.card-phrase {
    display:none;
    margin-top: 12px;
    padding: 10px 12px;
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: white;
    border-radius: 15px;
    font-size: 13px;
    font-weight: 600;
    text-align: center;
    line-height: 1.4;
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.4);
    transition: all 0.4s ease;
    width: 100%;
}

/* Hidden phrases - collapse smoothly */
.card-phrase.hidden {
    margin-top: 0;
    padding: 0;
    height: 0;
    opacity: 0;
    overflow: hidden;
}

/* Compact card when phrase is hidden */
.card.compact .card-inner {
    padding: 8px;
}

/* ============================================
   MODAL
   ============================================ */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.9);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transition: all 0.4s ease;
}

.modal.active {
    opacity: 1;
    visibility: visible;
}

.modal-content {
    width: 90%;
    max-width: 900px;
    max-height: 90vh;
    background: linear-gradient(145deg, #2d2d44, #1a1a2e);
    border-radius: 30px;
    overflow: hidden;
    position: relative;
    transform: scale(0.7) rotate(-5deg);
    transition: transform 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    box-shadow: 0 30px 80px rgba(0, 0, 0, 0.5),
                0 0 0 5px rgba(255, 107, 107, 0.3),
                0 0 100px rgba(255, 107, 107, 0.1);
}

.modal.active .modal-content {
    transform: scale(1) rotate(0);
}

/* Close Button */
.modal-close {
    position: absolute;
    top: 15px;
    right: 15px;
    width: 60px;
    height: 60px;
    background: linear-gradient(135deg, #ff6b6b, #ee5a5a);
    border: none;
    border-radius: 50%;
    color: white;
    font-size: 36px;
    cursor: pointer;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    box-shadow: 0 5px 20px rgba(255, 107, 107, 0.5);
}

.modal-close:hover {
    transform: scale(1.1) rotate(90deg);
    box-shadow: 0 10px 30px rgba(255, 107, 107, 0.7);
}

/* Video Container */
.video-container {
    width: 100%;
    aspect-ratio: 16/9;
    background: #000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.video-container.hidden {
    display: none;
}

#videoPlayer {
    width: 100%;
    height: 100%;
    object-fit: contain;
    padding: 15px;
}

/* Image Container */
.image-container {
    width: 100%;
    aspect-ratio: 16/9;
    background: linear-gradient(135deg, #667eea, #764ba2);
    display: none;
    align-items: center;
    justify-content: center;
    padding: 20px;
    position: relative;
    overflow: hidden;
}

.image-container.visible {
    display: flex;
    animation: wowAppear 0.8s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes wowAppear {
    0% {
        opacity: 0;
    }
    50% {
        opacity: 1;
    }
    100% {
        opacity: 1;
    }
}

.image-container::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 200%;
    height: 200%;
    background: radial-gradient(circle, rgba(255,255,255,0.3) 0%, transparent 70%);
    animation: wowPulse 1.5s ease-out;
    transform: translate(-50%, -50%);
}

@keyframes wowPulse {
    0% {
        transform: translate(-50%, -50%) scale(0);
        opacity: 1;
    }
    100% {
        transform: translate(-50%, -50%) scale(1);
        opacity: 0;
    }
}

.modal-image {
    max-width: 80%;
    max-height: 100%;
    border-radius: 25px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4);
    cursor: pointer;
    transition: transform 0.3s ease;
    animation: imagePopIn 0.6s cubic-bezier(0.175, 0.885, 0.32, 1.275) 0.2s backwards;
}

@keyframes imagePopIn {
    0% {
        transform: scale(0) rotate(-20deg);
    }
    100% {
        transform: scale(1) rotate(0);
    }
}

.modal-image:hover {
    transform: scale(1.05);
}

/* Stars Effect */
.image-container .star {
    position: absolute;
    width: 20px;
    height: 20px;
    background: #feca57;
    clip-path: polygon(50% 0%, 61% 35%, 98% 35%, 68% 57%, 79% 91%, 50% 70%, 21% 91%, 32% 57%, 2% 35%, 39% 35%);
    animation: starFly 1s ease-out forwards;
}

@keyframes starFly {
    0% {
        transform: scale(0) rotate(0deg);
        opacity: 1;
    }
    100% {
        transform: scale(1.5) rotate(360deg) translateY(-100px);
        opacity: 0;
    }
}

/* Controls */
.modal-controls {
    display:none;
    /* display: flex;  */
    justify-content: center;
    gap: 20px;
    padding: 20px;
    background: rgba(0, 0, 0, 0.3);
}

.control-btn {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 15px 30px;
    border: none;
    border-radius: 50px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
}

.replay-btn {
    background: linear-gradient(135deg, #48dbfb, #0abde3);
    color: white;
    box-shadow: 0 5px 20px rgba(72, 219, 251, 0.4);
}

.replay-btn:hover {
    transform: translateY(-3px);
    box-shadow: 0 10px 30px rgba(72, 219, 251, 0.6);
}

.audio-btn {
    background: linear-gradient(135deg, #feca57, #ff9f43);
    color: white;
    box-shadow: 0 5px 20px rgba(254, 202, 87, 0.4);
}

.audio-btn:hover {
    transform: translateY(-3px);
    box-shadow: 0 10px 30px rgba(254, 202, 87, 0.6);
}

.control-btn svg {
    width: 24px;
    height: 24px;
}

/* Modal Phrase */
.modal-phrase {
    padding: 25px;
    text-align: center;
    font-size: 24px;
    font-weight: 700;
    color: white;
    background: linear-gradient(135deg, #667eea, #764ba2);
    text-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
    letter-spacing: 1px;
}

.modal-phrase.hidden {
    display: none;
}

/* ============================================
   RESPONSIVE DESIGN
   ============================================ */
@media (max-width: 1400px) {
    .grid-container .card {
        width: calc(25% - 15px);
    }
}

@media (max-width: 1100px) {
    .grid-container .card {
        width: calc(33.333% - 14px);
    }
}

@media (max-width: 768px) {
    .grid-container .card {
        width: calc(50% - 10px);
    }

    .main-container {
        margin-top: 50px;
    }

    .floating-logo {
        top: 10px;
        left: 10px;
    }

    .logo {
        height: 100px;
    }

    .floating-toggle {
        top: 15px;
        right: 15px;
        padding: 8px 15px;
    }

    .toggle-text {
        display: none;
    }

    .card-phrase {
        font-size: 11px;
        padding: 8px 10px;
    }

    .door-number {
        width: 50px;
        height: 50px;
        font-size: 22px;
    }

    .door-window {
        top: 10%;
        height: 24%;
    }

    .door-handle {
        width: 11px;
        height: 28px;
    }

    .modal-content {
        width: 95%;
        border-radius: 20px;
    }

    .modal-close {
        width: 45px;
        height: 45px;
        font-size: 28px;
    }

    .control-btn {
        padding: 12px 20px;
        font-size: 14px;
    }

    .control-btn span {
        display: none;
    }

    .modal-phrase {
        font-size: 18px;
        padding: 15px;
    }
}

@media (max-width: 480px) {
    .main-container {
        padding: 10px;
        margin-top: 20px;
    }

    .grid-container .card {
        width: calc(50% - 8px);
    }

    .card-inner {
        padding: 8px;
    }

    .logo {
        height: 80px;
    }

    .door-number {
        width: 40px;
        height: 40px;
        font-size: 18px;
    }

    .door-window {
        top: 8%;
        height: 22%;
        border-width: 3px;
    }

    .door-handle {
        width: 9px;
        height: 22px;
        right: 12%;
    }

    .door-frame {
        top: 6px;
        left: 6px;
        right: 6px;
        bottom: 6px;
        border-width: 3px;
    }
}
