﻿:root {
    --primary-color: #FF9F1C;
    /* Joyful Orange */
    --secondary-color: #2EC4B6;
    /* Friendly Teal */
    --success-color: #6BCB77;
    /* Soft Green */
    --accent-color: #FFBF69;
    /* Soft Yellow */
    --error-color: #FF5E5B;
    /* Coral Red */
    --text-color: #2D3436;
    /* Dark Grey */
    --bg-color: #F7F1E3;
    /* Cream */
    --font-family: 'Rubik', sans-serif;
    --card-radius: 25px;
    --btn-radius: 50px;
}

body {
    margin: 0;
    font-family: var(--font-family);
    background: #FFEFBA;
    /* fallback for old browsers */
    background: -webkit-linear-gradient(to right, #FFFFFF, #FFEFBA);
    /* Chrome 10-25, Safari 5.1-6 */
    background: linear-gradient(to right, #FFFFFF, #FFEFBA);
    /* W3C, IE 10+/ Edge, Firefox 16+, Chrome 26+, Opera 12+, Safari 7+ */
    color: var(--text-color);
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    min-height: 100dvh;
    overflow-x: hidden;
    overflow-y: auto;
    direction: var(--direction, rtl);
}

/* LTR Support */
html[dir="ltr"] {
    --direction: ltr;
}

html[dir="rtl"] {
    --direction: rtl;
}

#app {
    width: 100%;
    max-width: 700px;
    text-align: center;
    padding: 20px;
}

.screen {
    display: none;
    flex-direction: column;
    align-items: center;
    gap: 20px;
    width: 100%;
}

.screen.active {
    display: flex;
    animation: slideUp 0.5s ease-out;
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

h1 {
    font-size: 3rem;
    color: var(--primary-color);
    text-shadow: 2px 2px 0px #FFF, 4px 4px 0px rgba(0, 0, 0, 0.1);
    margin-bottom: 20px;
    font-weight: 900;
}

h2 {
    color: #666;
    font-size: 1.5rem;
    margin-bottom: 20px;
}

/* --- Buttons --- */
button {
    background-color: var(--primary-color);
    color: white;
    border: none;
    padding: 15px 35px;
    font-size: 1.3rem;
    font-family: var(--font-family);
    font-weight: 700;
    border-radius: var(--btn-radius);
    cursor: pointer;
    box-shadow: 0 8px 15px rgba(255, 159, 28, 0.3);
    transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
    margin: 8px;
    border-bottom: 5px solid rgba(0, 0, 0, 0.1);
    /* 3D effect */
}

button:hover {
    transform: translateY(-3px) scale(1.02);
    box-shadow: 0 12px 20px rgba(255, 159, 28, 0.4);
}

button:active {
    transform: translateY(1px);
    border-bottom-width: 2px;
    box-shadow: 0 5px 10px rgba(0, 0, 0, 0.2);
}

.home-btn {
    background-color: var(--secondary-color);
    padding: 10px 20px;
    font-size: 1rem;
    box-shadow: 0 5px 10px rgba(46, 196, 182, 0.3);
}

.restart-btn {
    background-color: var(--accent-color);
    color: #5d4037;
    /* Brownish */
    box-shadow: 0 5px 10px rgba(255, 191, 105, 0.4);
}

/* --- Cards --- */
.card {
    background: #FFFFFF;
    border-radius: var(--card-radius);
    padding: 30px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.08);
    /* Soft diffuse shadow */
    width: 100%;
    margin-bottom: 25px;
    border: 2px solid rgba(255, 255, 255, 0.8);
    position: relative;
    overflow: hidden;
}

/* Decorative Card Elements? */
.card::before {
    content: '';
    position: absolute;
    top: -50px;
    left: -50px;
    width: 100px;
    height: 100px;
    background: var(--accent-color);
    border-radius: 50%;
    opacity: 0.2;
}

.emoji {
    font-size: 7rem;
    display: block;
    margin-bottom: 10px;
    filter: drop-shadow(0 10px 10px rgba(0, 0, 0, 0.1));
    animation: float 3s ease-in-out infinite;
}

/* Image Assets */
.game-asset-image {
    max-width: 100%;
    max-height: 250px;
    object-fit: contain;
    border-radius: 15px;
    filter: drop-shadow(0 5px 10px rgba(0, 0, 0, 0.1));
}

@keyframes float {

    0%,
    100% {
        transform: translateY(0);
    }

    50% {
        transform: translateY(-15px);
    }
}

#target-word {
    font-size: 4.5rem;
    margin: 10px 0;
    color: var(--text-color);
    font-weight: 700;
}

/* --- Mode Selection --- */
.mode-selector {
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    gap: 15px;
}

.mode-btn {
    background: white;
    color: #888;
    border: 3px solid #eee;
    padding: 15px 25px;
    font-size: 1.1rem;
    border-radius: 20px;
    box-shadow: none;
    border-bottom: 3px solid #eee;
}

.mode-btn.selected {
    background: white;
    color: var(--primary-color);
    border-color: var(--primary-color);
    box-shadow: 0 10px 20px rgba(255, 159, 28, 0.15);
    transform: translateY(-3px);
}

/* --- Level Buttons --- */
.level-buttons {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 15px;
    width: 100%;
}

.level-buttons button {
    background: white;
    color: var(--text-color);
    border: 2px solid var(--secondary-color);
    box-shadow: 0 5px 0 var(--secondary-color);
    margin: 5px 0;
    width: 100%;
    max-width: 400px;
    /* Wider and uniform */
    box-sizing: border-box;
}

.level-buttons button:hover {
    background: var(--secondary-color);
    color: white;
}

/* --- Match Game Grid --- */
.word-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    width: 100%;
}

.word-grid-btn {
    background: white;
    border: 3px solid #eee;
    padding: 20px;
    font-size: 2rem;
    border-radius: 20px;
    cursor: pointer;
    transition: all 0.2s;
    box-shadow: 0 5px 0 #eee;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    color: #555;
}

.word-grid-btn:hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 0 #eee;
}

.word-grid-btn:active {
    transform: translateY(2px);
    box-shadow: 0 2px 0 #eee;
}

.word-grid-btn.correct {
    background: var(--success-color);
    color: white;
    border-color: #55b560;
    /* Darker green */
    box-shadow: 0 5px 0 #55b560;
    animation: bounce 0.6s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.word-grid-btn.wrong {
    background: var(--error-color);
    color: white;
    border-color: #e04a47;
    box-shadow: 0 5px 0 #e04a47;
    animation: shake 0.4s;
}

@keyframes bounce {

    0%,
    100% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.1);
    }
}

@keyframes shake {

    0%,
    100% {
        transform: translateX(0);
    }

    25% {
        transform: translateX(-8px);
    }

    75% {
        transform: translateX(8px);
    }
}

/* --- Memory Game --- */
.memory-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 15px;
    width: 100%;
    margin-top: 10px;
    perspective: 1000px;
}

.memory-card {
    height: 120px;
    cursor: pointer;
    position: relative;
    transform-style: preserve-3d;
    transition: transform 0.8s cubic-bezier(0.4, 0.0, 0.2, 1);
}

.memory-card.flipped {
    /* No transform on container */
}

.memory-card.matched {
    transform: scale(0.95);
    opacity: 0.8;
    filter: grayscale(0.5);
    /* Optional: visual clue it's done */
}

/* The visual layers */
.memory-card-inner {
    width: 100%;
    height: 100%;
    position: absolute;
    /* Wrapper isn't really needed if card rotates, but existing structure uses it.
       Let's adapt to existing structure:
       .memory-card -> .memory-card-inner (rotates) -> front/back faces
    */
}

/* CORRECTION: Existing JS rotates .memory-card-inner, NOT .memory-card */
/* So .memory-card should be container, .memory-card-inner rotates */
.memory-card {
    perspective: 1000px;
    transform: none;
    /* Reset */
    transition: none;
}

.memory-card-inner {
    position: relative;
    width: 100%;
    height: 100%;
    text-align: center;
    transition: transform 0.8s;
    transform-style: preserve-3d;
}

.memory-card.flipped .memory-card-inner {
    transform: rotateX(180deg);
}

.memory-card.matched .memory-card-inner {
    transform: rotateX(180deg);
}

.memory-card-front,
.memory-card-back {
    position: absolute;
    width: 100%;
    height: 100%;
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
    border-radius: 15px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    border: 3px solid white;
}

.memory-card-front {
    background-color: var(--primary-color);
    background-image:
        radial-gradient(circle at 20% 20%, rgba(255, 255, 255, 0.2) 2px, transparent 2.5px),
        radial-gradient(circle at 80% 50%, rgba(255, 255, 255, 0.2) 2px, transparent 2.5px);
    background-size: 20px 20px;
    color: white;
    font-size: 3rem;
    transform: rotateX(0deg);
}

.memory-card-back {
    background-color: white;
    transform: rotateX(180deg);
    font-size: 2rem;
    font-weight: bold;
    color: var(--text-color);
}

.memory-card-back img {
    max-width: 90%;
    max-height: 90%;
    object-fit: contain;
}

/* --- Overlays & Feedback --- */
.overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(5px);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 200;
    animation: fadeIn 0.3s;
}

.checkmark {
    font-size: 5rem;
    color: var(--success-color);
    text-shadow: 0 5px 15px rgba(107, 203, 119, 0.4);
    animation: popIn 0.5s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

@keyframes popIn {
    0% {
        transform: scale(0);
        opacity: 0;
    }

    80% {
        transform: scale(1.1);
        opacity: 1;
    }

    100% {
        transform: scale(1);
    }
}

/* Mic Icon */
.mic-icon {
    font-size: 3rem;
    background: white;
    width: 90px;
    height: 90px;
    line-height: 90px;
    border-radius: 50%;
    margin: 0 auto 15px;
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.1);
    transition: all 0.3s;
    cursor: pointer;
    color: #ccc;
    position: relative;
}

.mic-icon.listening {
    color: white;
    background: var(--error-color);
    box-shadow: 0 10px 25px rgba(255, 94, 91, 0.4);
    animation: pulse 1.5s infinite;
}

@keyframes pulse {
    0% {
        box-shadow: 0 0 0 0 rgba(255, 94, 91, 0.7);
    }

    70% {
        box-shadow: 0 0 0 20px rgba(255, 94, 91, 0);
    }

    100% {
        box-shadow: 0 0 0 0 rgba(255, 94, 91, 0);
    }
}

/* --- Mobile --- */
@media (max-width: 600px) {
    h1 {
        font-size: 2.2rem;
    }

    #target-word {
        font-size: 3.5rem;
    }

    .level-buttons button,
    .mode-btn {
        width: 100%;
        margin: 5px 0;
    }

    .word-grid {
        gap: 10px;
    }

    .word-grid-btn {
        padding: 15px;
        font-size: 1.5rem;
    }

    .game-asset-image {
        max-height: 150px;
    }

    .memory-card {
        height: 100px;
    }

    .screen {
        gap: 10px;
    }
}

/* Footer Credits */
footer {
    opacity: 0.6;
    font-size: 0.8rem;
    margin-top: 30px;
}

footer a {
    color: var(--text-color);
}

/* Utilities */
.hidden {
    display: none !important;
}

.shake {
    animation: shake 0.5s;
}

/* --- Hangman Game --- */
.word-display {
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    gap: 15px;
    direction: rtl;
    /* Ensure Hebrew flows right to left */
    min-height: 80px;
    align-items: flex-end;
    /* Align to bottom for the lines */
}

.hangman-char {
    display: inline-block;
    min-width: 45px;
    height: 60px;
    border-bottom: 5px solid var(--text-color);
    text-align: center;
    font-weight: 900;
    font-size: 2.5rem;
    color: var(--primary-color);
    line-height: 60px;
    transition: all 0.3s;
    margin: 0 2px;
}

.hangman-char.revealed {
    border-bottom-color: var(--success-color);
    transform: translateY(-5px);
    text-shadow: 1px 1px 0 rgba(0, 0, 0, 0.1);
}

/* Empty State Animation/Visibility */
.hangman-char:not(.revealed) {
    border-bottom-style: dashed;
    border-bottom-color: #ccc;
    background: rgba(0, 0, 0, 0.03);
    /* Slight grey background to show the slot */
    border-radius: 5px 5px 0 0;
}

.keyboard-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(40px, 1fr));
    gap: 8px;
    max-width: 600px;
    margin: 20px auto;
    direction: rtl;
}

.hangman-key {
    background: white;
    border: 2px solid #ddd;
    border-bottom: 4px solid #ccc;
    /* Thicker bottom for 3D feel */
    border-radius: 8px;
    font-size: 1.5rem;
    padding: 10px 5px;
    cursor: pointer;
    transition: all 0.1s;
    font-family: var(--font-family);
    color: var(--text-color);
    /* Ensure text is visible */
    font-weight: bold;
    margin: 0;
    min-height: 50px;
}

.hangman-key:active {
    transform: translateY(2px);
    border-bottom-width: 2px;
}

.hangman-key.used {
    background: #f0f0f0;
    color: #ccc;
    border-color: #eee;
    box-shadow: none;
    cursor: default;
    transform: translateY(2px);
    border-bottom-width: 2px;
}

.hangman-key.correct {
    background: var(--success-color);
    color: white;
    border-color: #55b560;
}

.hangman-key.wrong {
    background: var(--error-color);
    color: white;
    border-color: #d64542;
    opacity: 0.8;
}

/* Ensure Image within container is centered and contained */
#hangman-image-container {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    /* Ensure it takes full width for centering to work */
}

#hangman-image-container img.game-asset-image {
    max-width: 100%;
    max-height: 250px;
    object-fit: contain;
    border-radius: 15px;
    filter: drop-shadow(0 5px 15px rgba(0, 0, 0, 0.1));
    display: block;
    margin: 0 auto;
}

#hangman-image-container .emoji {
    font-size: 6rem;
    display: block;
    margin: 0 auto;
}

.full-word-reveal {
    font-size: 4rem;
    color: var(--primary-color);
    animation: popIn 0.8s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    display: inline-block;
    padding: 10px 30px;
    background: white;
    border-radius: 20px;
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.1);
}