@font-face {
    font-family: 'Shadow Beamer';
    src: url('Shadow Beamer.ttf') format('truetype');
    font-display: swap;
}

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

body { 
    margin: 0; 
    padding: 0; 
    background: #0d1117; 
    display: flex; 
    justify-content: center; 
    align-items: center; 
    height: 100vh; 
    width: 100vw;
    font-family: 'Luckiest Guy', 'Shadow Beamer', 'Comic Sans MS', cursive, sans-serif; 
    overflow: hidden; 
    user-select: none;
    -webkit-user-select: none;
    touch-action: manipulation;
}

#app-container { 
    position: relative; 
    width: 100vw; 
    max-width: 177.78vh; /* 16:9 ratio LIM */
    height: 56.25vw; 
    max-height: 100vh; 
    background: #000; 
    overflow: hidden; 
    box-shadow: 0 0 40px rgba(0,0,0,0.8);
}

.hidden { 
    display: none !important; 
}

/* PRELOADER */
#preloader { 
    position: absolute; 
    inset: 0; 
    background: #1a1a24; 
    display: flex; 
    flex-direction: column;
    justify-content: center; 
    align-items: center; 
    z-index: 1000; 
    transition: opacity 0.5s ease; 
}
#loading-text { 
    font-size: 6vw; 
    color: #fff; 
    text-shadow: 3px 3px 0 #ff7300, 5px 5px 0 rgba(0,0,0,0.5); 
    letter-spacing: 0.05em;
}
.loading-sub {
    font-size: 1.5vw;
    color: #ffd700;
    margin-top: 1vw;
    letter-spacing: 0.1em;
}

/* TOP CONTROLS (Pill Toolbar) */
.top-bar-controls {
    position: absolute;
    top: 2.5%;
    left: 2.5%;
    right: 2.5%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    z-index: 150;
    pointer-events: none;
}
.control-group-left, .control-group-right {
    display: flex;
    gap: 0.8vw;
    align-items: center;
    pointer-events: auto;
}

.hud-btn {
    height: 3.6vw;
    min-width: 3.6vw;
    padding: 0 1vw;
    background: rgba(20, 24, 33, 0.75);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border: 2px solid rgba(255, 215, 0, 0.6);
    border-radius: 50px;
    color: #fff;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 0.4vw;
    font-family: inherit;
    font-size: 1.1vw;
    box-shadow: 0 4px 12px rgba(0,0,0,0.4);
    transition: transform 0.15s ease, background 0.2s ease, border-color 0.2s ease;
    touch-action: manipulation;
}
.hud-btn:hover {
    transform: scale(1.06);
    background: rgba(35, 42, 58, 0.9);
    border-color: #ffd700;
}
.hud-btn:active {
    transform: scale(0.96);
}
.hud-btn svg {
    width: 1.8vw;
    height: 1.8vw;
    fill: currentColor;
}

/* MUSIC SELECTOR DROPDOWN */
#music-select {
    height: 3.6vw;
    padding: 0 1.2vw;
    background: rgba(20, 24, 33, 0.75);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border: 2px solid rgba(255, 215, 0, 0.6);
    border-radius: 50px;
    color: #ffd700;
    font-family: inherit;
    font-size: 1.1vw;
    cursor: pointer;
    outline: none;
    box-shadow: 0 4px 12px rgba(0,0,0,0.4);
    touch-action: manipulation;
}
#music-select option {
    background: #1a1e29;
    color: #fff;
}

/* START SCREEN */
#start-screen { 
    position: absolute; 
    inset: 0; 
    background: url('image/intro.jpg') center/cover no-repeat; 
    z-index: 20; 
}
.intro-controls { 
    position: absolute; 
    bottom: 7%; 
    left: 50%; 
    transform: translateX(-50%); 
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.8vw;
}
#start-button { 
    font-family: inherit; 
    font-size: 2.4vw; 
    padding: 1vw 4.5vw; 
    border-radius: 50px; 
    border: 4px solid #fff; 
    cursor: pointer; 
    background: linear-gradient(45deg, #ff0055, #ff7300, #ffcc00, #00b0ff, #7928ca); 
    background-size: 300%; 
    color: #fff; 
    text-shadow: 2px 2px 4px rgba(0,0,0,0.6);
    box-shadow: 0 10px 25px rgba(0,0,0,0.5), inset 0 2px 4px rgba(255,255,255,0.4);
    animation: glow 8s linear infinite; 
    transition: transform 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    touch-action: manipulation;
}
#start-button:hover { 
    transform: scale(1.08); 
}
#start-button:active { 
    transform: scale(0.96); 
}
@keyframes glow { 
    0%, 100% { background-position: 0 0; } 
    50% { background-position: 300% 0; } 
}

.intro-secondary-btns {
    display: flex;
    gap: 1vw;
}
.secondary-btn {
    font-family: inherit;
    font-size: 1vw;
    padding: 0.5vw 1.6vw;
    background: rgba(0,0,0,0.6);
    border: 2px solid rgba(255,255,255,0.7);
    border-radius: 30px;
    color: #fff;
    cursor: pointer;
    backdrop-filter: blur(5px);
    transition: all 0.2s ease;
}
.secondary-btn:hover {
    background: rgba(0,0,0,0.85);
    border-color: #ffd700;
    color: #ffd700;
    transform: translateY(-2px);
}

/* GAME SCREEN */
#game-screen { 
    position: absolute; 
    inset: 0; 
    background: url('image/sfondo.png') center/cover no-repeat; 
    z-index: 10; 
}

/* HUD TEXTS POSITIONED ON THE CHALKBOARD BANNER (1920x1080) */
.hud-text { 
    position: absolute; 
    font-size: 2.3vw; 
    color: #43240e; 
    text-shadow: 1px 1px 0 #fff, 0 0 8px rgba(255, 235, 200, 0.8); 
    transform: translate(-50%, -50%); 
    pointer-events: none;
    font-weight: 900;
}

#level-display { 
    left: 28.96%; 
    top: 38.15%; 
}
#moves-counter { 
    left: 41.77%; 
    top: 38.15%; 
}
#timer { 
    left: 58.70%; 
    top: 38.15%; 
}

/* MUTE BUTTON ON THE CHALKBOARD HORN (76.15%, 35.74%) */
#mute-button { 
    position: absolute; 
    left: 76.15%; 
    top: 35.74%; 
    width: 6vw; 
    height: 6vw; 
    transform: translate(-50%, -50%); 
    background: transparent; 
    border: none; 
    cursor: pointer; 
    z-index: 30; 
    outline: none;
    border-radius: 50%;
    touch-action: manipulation;
}
#mute-button:hover {
    background: rgba(255, 255, 255, 0.15);
}
#mute-button.muted-state::after { 
    content: '✖'; 
    position: absolute; 
    top: 50%; 
    left: 50%; 
    transform: translate(-50%, -50%); 
    font-size: 3.4vw; 
    color: #e50914; 
    font-weight: 900; 
    text-shadow: 2px 2px 0 #fff, 0 0 10px rgba(255,0,0,0.6); 
    pointer-events: none;
}

/* ROTATING ANALOG CLOCK (X=50.21%, Y=36.67%) */
#analog-clock { 
    position: absolute; 
    left: 50.21%; 
    top: 36.67%; 
    width: 0;
    height: 0;
    z-index: 15; 
    pointer-events: none;
}

#second-hand { 
    position: absolute; 
    bottom: 0; 
    left: -0.06vw; 
    width: 0.12vw; 
    height: 2.7vw; 
    background: linear-gradient(to top, #1a1a1a 70%, #996515); 
    transform-origin: bottom center; 
    border-radius: 0.08vw;
    box-shadow: 1px 1px 3px rgba(0,0,0,0.5);
    transition: transform 0.2s cubic-bezier(0.4, 2.08, 0.55, 0.44);
    z-index: 18;
    pointer-events: none;
}
/* Counterweight at base */
#second-hand::before {
    content: '';
    position: absolute;
    top: 100%;
    left: -0.12vw;
    width: 0.36vw;
    height: 0.6vw;
    background: #111;
    border-radius: 50% 50% 20% 20%;
    box-shadow: 0 1px 2px rgba(0,0,0,0.4);
}
/* Antique Arrow Tip */
#second-hand::after {
    content: '';
    position: absolute;
    top: -0.35vw;
    left: -0.14vw;
    width: 0;
    height: 0;
    border-left: 0.2vw solid transparent;
    border-right: 0.2vw solid transparent;
    border-bottom: 0.4vw solid #b8860b;
}

/* Center Jewel Cap on the clock pin */
#clock-cap {
    position: absolute;
    width: 0.6vw;
    height: 0.6vw;
    left: -0.3vw;
    top: -0.3vw;
    border-radius: 50%;
    background: radial-gradient(circle at 35% 35%, #ffd700, #b8860b 70%, #3e2723);
    box-shadow: 0 1px 4px rgba(0,0,0,0.7);
    z-index: 20;
    pointer-events: none;
}

/* LEVEL BANNER SUBTITLE */
#level-title-tag {
    position: absolute;
    top: 44.8%;
    left: 50%;
    transform: translateX(-50%);
    font-size: 1.1vw;
    color: #e2c290;
    text-shadow: 1px 1px 3px rgba(0,0,0,0.9);
    letter-spacing: 0.08em;
    pointer-events: none;
    z-index: 12;
}

/* GAME BOARD (7 COLUMNS x 2 ROWS = 14 CARDS) */
#game-board { 
    position: absolute; 
    top: 48%; 
    left: 5%; 
    width: 90%; 
    height: 48%; 
    display: grid; 
    grid-template-columns: repeat(7, 1fr); 
    grid-template-rows: repeat(2, 1fr);
    gap: 0.9vw; 
    z-index: 12;
}

.card-wrapper { 
    perspective: 1000px; 
    width: 100%;
    height: 100%;
}

.card { 
    width: 100%; 
    height: 100%; 
    position: relative; 
    transform-style: preserve-3d; 
    transition: transform 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275), box-shadow 0.3s ease; 
    cursor: pointer; 
    border-radius: 0.9vw;
    box-shadow: 0 6px 14px rgba(0,0,0,0.45);
    touch-action: manipulation;
}
.card:hover {
    transform: translateY(-4px) scale(1.02);
    box-shadow: 0 10px 20px rgba(0,0,0,0.6);
}
.card.flipped { 
    transform: rotateY(180deg); 
}
.card.matched {
    animation: matchSuccess 0.6s ease forwards;
    cursor: default;
}
@keyframes matchSuccess {
    0% { transform: rotateY(180deg) scale(1); }
    50% { transform: rotateY(180deg) scale(1.12); box-shadow: 0 0 25px #ffd700; }
    100% { transform: rotateY(180deg) scale(1); box-shadow: 0 0 12px rgba(255, 215, 0, 0.6); }
}

.card-face { 
    position: absolute; 
    inset: 0; 
    backface-visibility: hidden; 
    -webkit-backface-visibility: hidden;
    border-radius: 0.9vw; 
    overflow: hidden;
}

.card-back { 
    background: url('image/dorso.webp') center/cover no-repeat #2a1810; 
    border: 0.25vw solid #c59b27; 
    box-shadow: inset 0 0 10px rgba(0,0,0,0.5);
}

.card-front { 
    transform: rotateY(180deg); 
    background: #0f1c1f;
    border: 0.25vw solid #c59b27;
    box-shadow: inset 0 0 15px rgba(0,0,0,0.7);
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
    border-radius: 0.7vw;
}
.card-front img { 
    width: 100%; 
    height: 100%; 
    border-radius: 0.5vw; 
    object-fit: cover; 
    display: block;
}

/* ========================================================
   NUOVA SCHERMATA VITTORIA AD ALTO IMPATTO (SENZA FINALE.PNG)
   ======================================================== */
#win-modal { 
    position: absolute; 
    inset: 0; 
    background: rgba(10, 15, 25, 0.88); 
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    z-index: 80; 
    display: flex;
    justify-content: center;
    align-items: center;
    animation: winFadeIn 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}
@keyframes winFadeIn {
    from { opacity: 0; transform: scale(0.96); }
    to { opacity: 1; transform: scale(1); }
}

.victory-card {
    position: relative;
    width: 52vw;
    max-width: 960px;
    background: linear-gradient(145deg, #fffdfa 0%, #fbf5e8 40%, #ede1c8 100%);
    border: 0.35vw solid #d4af37;
    border-radius: 2vw;
    padding: 2.2vw 3vw 2vw;
    display: flex;
    flex-direction: column;
    align-items: center;
    box-shadow: 0 25px 60px rgba(0,0,0,0.85), 0 0 45px rgba(212,175,55,0.4), inset 0 2px 4px rgba(255,255,255,0.8);
}

.victory-badge {
    position: absolute;
    top: -3.2vw;
    width: 6.4vw;
    height: 6.4vw;
    border-radius: 50%;
    background: linear-gradient(135deg, #ffd700 0%, #ff8c00 100%);
    border: 0.3vw solid #fff;
    display: flex;
    justify-content: center;
    align-items: center;
    box-shadow: 0 10px 25px rgba(255,140,0,0.5), inset 0 2px 5px rgba(255,255,255,0.6);
    animation: badgeFloat 3s ease-in-out infinite alternate;
}
@keyframes badgeFloat {
    0% { transform: translateY(0); }
    100% { transform: translateY(-6px); }
}
.victory-badge-icon {
    font-size: 3.4vw;
}

.victory-title {
    font-family: 'Luckiest Guy', cursive;
    font-size: 2.6vw;
    color: #78350f;
    text-shadow: 2px 2px 0 #fff;
    margin-top: 1.8vw;
    margin-bottom: 0.2vw;
    letter-spacing: 0.05em;
    text-align: center;
}

.star-rating {
    font-size: 3.6vw;
    color: #ffaa00;
    text-shadow: 0 3px 8px rgba(255, 170, 0, 0.5);
    letter-spacing: 0.25em;
    margin: 0.2vw 0 0.4vw;
    animation: starBounce 0.8s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}
@keyframes starBounce {
    0% { transform: scale(0); opacity: 0; }
    70% { transform: scale(1.25); }
    100% { transform: scale(1); opacity: 1; }
}

.victory-feedback {
    font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-size: 1.15vw;
    color: #573318;
    text-align: center;
    margin-bottom: 1.6vw;
    font-weight: 600;
    line-height: 1.4;
}

/* GRIGLIA STATISTICHE VITTORIA */
.victory-stats-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1.2vw;
    width: 100%;
    margin-bottom: 1.8vw;
}

.stat-box {
    background: rgba(255, 255, 255, 0.75);
    border: 0.15vw solid #d4af37;
    border-radius: 1.2vw;
    padding: 0.8vw 1.2vw;
    display: flex;
    align-items: center;
    gap: 0.9vw;
    box-shadow: 0 4px 12px rgba(0,0,0,0.06), inset 0 1px 2px rgba(255,255,255,0.8);
}
.stat-icon {
    font-size: 2.3vw;
}
.stat-data {
    display: flex;
    flex-direction: column;
}
.stat-label {
    font-size: 0.85vw;
    color: #8c6239;
    font-weight: 700;
    letter-spacing: 0.06em;
}
.stat-value {
    font-family: 'Luckiest Guy', cursive;
    font-size: 1.9vw;
    color: #2c1a0e;
}

/* PULSANTI AZIONE VITTORIA */
.victory-actions {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 1.2vw;
    width: 100%;
}

.victory-btn {
    font-family: 'Luckiest Guy', cursive;
    font-size: 1.35vw;
    padding: 0.8vw 2.2vw;
    border-radius: 50px;
    cursor: pointer;
    border: 3px solid #fff;
    box-shadow: 0 8px 20px rgba(0,0,0,0.3), inset 0 2px 4px rgba(255,255,255,0.4);
    transition: transform 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275), box-shadow 0.2s ease;
    touch-action: manipulation;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.4vw;
}
.victory-btn:hover {
    transform: scale(1.08) translateY(-2px);
    box-shadow: 0 12px 25px rgba(0,0,0,0.4);
}
.victory-btn:active {
    transform: scale(0.96);
}

.btn-primary {
    background: linear-gradient(135deg, #10b981 0%, #059669 100%);
    color: #fff;
    text-shadow: 1px 1px 2px rgba(0,0,0,0.5);
}

.btn-secondary {
    background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
    color: #fff;
    text-shadow: 1px 1px 2px rgba(0,0,0,0.5);
}

.btn-tertiary {
    background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%);
    color: #fff;
    text-shadow: 1px 1px 2px rgba(0,0,0,0.5);
}

/* MODAL DIALOGS (Credits & Instructions) */
dialog.custom-modal {
    margin: auto;
    padding: 0;
    border: none;
    border-radius: 1.5vw;
    background: transparent;
    max-width: 55vw;
    width: 90%;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.8);
    overflow: hidden;
}
dialog.custom-modal::backdrop {
    background: rgba(0, 0, 0, 0.75);
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
}
.modal-inner {
    background: linear-gradient(135deg, #fdfbf7 0%, #ebedee 100%);
    border: 0.35vw solid #c59b27;
    border-radius: 1.5vw;
    padding: 2.2vw;
    color: #1e293b;
    font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    position: relative;
}
.modal-inner h2 {
    font-family: 'Luckiest Guy', cursive, sans-serif;
    color: #1e3a8a;
    font-size: 2vw;
    text-align: center;
    margin-bottom: 1.2vw;
    letter-spacing: 0.05em;
}
.modal-close-btn {
    position: absolute;
    top: 1vw;
    right: 1.2vw;
    background: #e2e8f0;
    border: 2px solid #94a3b8;
    width: 2.4vw;
    height: 2.4vw;
    border-radius: 50%;
    font-size: 1.4vw;
    line-height: 1;
    cursor: pointer;
    font-weight: bold;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: all 0.2s ease;
}
.modal-close-btn:hover {
    background: #fee2e2;
    color: #dc2626;
    border-color: #f87171;
    transform: scale(1.1);
}

/* CREDITS CONTENT */
.credits-panel {
    text-align: center;
    line-height: 1.5;
}
.credits-panel .role-badge {
    display: inline-block;
    background: #dbeafe;
    color: #1e40af;
    font-weight: 700;
    font-size: 0.95vw;
    padding: 0.3vw 1vw;
    border-radius: 20px;
    margin-bottom: 0.8vw;
}
.credits-panel h3 {
    font-size: 1.5vw;
    color: #0f172a;
    margin-bottom: 0.4vw;
}
.credits-panel p {
    font-size: 1vw;
    color: #475569;
    margin: 0.3vw 0;
}
.credits-panel .links {
    margin-top: 1vw;
    font-size: 1.1vw;
}
.credits-panel .links a {
    color: #2563eb;
    text-decoration: underline;
    font-weight: 600;
}
.credits-panel .synergy-quote {
    margin-top: 1.2vw;
    padding-top: 1vw;
    border-top: 1px dashed #cbd5e1;
    font-size: 0.9vw;
    color: #64748b;
    font-style: italic;
}

/* RULES / HOW TO PLAY CONTENT */
.rules-content {
    font-size: 1.1vw;
    line-height: 1.6;
    color: #334155;
}
.rules-content ul {
    list-style: none;
    padding: 0;
    margin: 1vw 0;
    display: flex;
    flex-direction: column;
    gap: 0.8vw;
}
.rules-content li {
    display: flex;
    align-items: center;
    gap: 0.8vw;
    background: #f8fafc;
    padding: 0.8vw 1.2vw;
    border-radius: 0.8vw;
    border-left: 4px solid #3b82f6;
}
.rules-content .icon {
    font-size: 1.6vw;
}

/* CONFETTI CANVAS */
#confetti-canvas {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 95;
}

/* ACCESSIBILITY & PREFERS-REDUCED-MOTION */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}