/* ===========================
   Root Variables & Reset
   =========================== */
:root {
    /* Color Palette */
    --primary-red: #E63946;
    --primary-cream: #F1FAEE;
    --primary-light-blue: #A8DADC;
    --primary-medium-blue: #457B9D;
    --primary-dark-blue: #1D3557;
    
    /* Additional Colors */
    --white: #FFFFFF;
    --gray-light: #F8F9FA;
    --gray-medium: #6C757D;
    --gray-dark: #343A40;
    --success-green: #52C41A;
    --warning-yellow: #FAAD14;
    
    /* Shadows & Effects */
    --shadow-small: 0 2px 8px rgba(29, 53, 87, 0.1);
    --shadow-medium: 0 4px 16px rgba(29, 53, 87, 0.15);
    --shadow-large: 0 8px 32px rgba(29, 53, 87, 0.2);
    --shadow-glow: 0 0 20px rgba(168, 218, 220, 0.6);
    
    /* Transitions */
    --transition-fast: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    --transition-medium: 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    --transition-slow: 0.6s cubic-bezier(0.4, 0, 0.2, 1);
    
    /* Sizing */
    --card-size-desktop: 150px;
    --card-size-tablet: 110px;
    --card-size-mobile: 85px;
    --card-gap: 15px;
    --header-height: 140px;
}

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

body {
    font-family: 'Poppins', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: linear-gradient(135deg, var(--primary-cream) 0%, var(--primary-light-blue) 100%);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    overflow-x: hidden;
    position: relative;
}

/* ===========================
   Intro Overlay
   =========================== */
.intro-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(135deg, var(--primary-dark-blue) 0%, var(--primary-medium-blue) 100%);
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: fadeIn 0.5s ease;
}

.intro-overlay.hidden {
    animation: fadeOut 0.5s ease forwards;
}

.intro-content {
    text-align: center;
    color: var(--white);
    max-width: 600px;
    padding: 2rem;
}

.intro-title {
    font-size: 3rem;
    font-weight: 700;
    margin-bottom: 1rem;
    animation: slideDown 0.8s ease;
}

.intro-subtitle {
    font-size: 1.2rem;
    font-weight: 300;
    margin-bottom: 2rem;
    opacity: 0;
    animation: fadeIn 1s ease 0.5s forwards;
}

.intro-loader {
    display: flex;
    justify-content: center;
    gap: 1rem;
    margin-bottom: 2rem;
}

.loader-pill {
    width: 30px;
    height: 35px;
    background: var(--primary-light-blue);
    border-radius: 50% 50% 40% 40%;
    position: relative;
    animation: bounce 1.5s infinite ease-in-out;
}

.loader-pill::before {
    content: '';
    position: absolute;
    bottom: -3px;
    left: 50%;
    transform: translateX(-50%);
    width: 12px;
    height: 8px;
    background: inherit;
    border-radius: 0 0 50% 50%;
}

.loader-pill:nth-child(2) {
    animation-delay: 0.2s;
    background: var(--primary-red);
}

.loader-pill:nth-child(3) {
    animation-delay: 0.4s;
    background: var(--primary-cream);
}

.start-btn {
    padding: 1rem 3rem;
    font-size: 1.2rem;
    font-weight: 600;
    background: var(--primary-red);
    color: var(--white);
    border: none;
    border-radius: 50px;
    cursor: pointer;
    transition: var(--transition-fast);
    animation: pulse 2s infinite;
    opacity: 0;
    animation: fadeIn 1s ease 1s forwards, pulse 2s infinite 1s;
}

.start-btn:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-large);
}

/* ===========================
   Game Container
   =========================== */
.game-container {
    width: 100%;
    max-width: 1400px;
    margin: 0 auto;
    padding: 1rem;
    padding-bottom: 2rem;
    flex: 1;
}

/* ===========================
   Header
   =========================== */
.game-header {
    background: var(--white);
    border-radius: 20px;
    padding: 1.5rem;
    margin-bottom: 1rem;
    box-shadow: var(--shadow-medium);
    animation: slideDown 0.6s ease;
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 1rem;
}

.game-title {
    font-size: 2rem;
    color: var(--primary-dark-blue);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.pill-icon {
    animation: rotate 3s linear infinite;
}

.stats-container {
    display: flex;
    gap: 2rem;
    flex-wrap: wrap;
}

.stat-item {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.stat-label {
    font-size: 0.875rem;
    color: var(--gray-medium);
    font-weight: 500;
}

.stat-value {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--primary-medium-blue);
}

.reset-btn {
    padding: 0.75rem 1.5rem;
    background: var(--primary-red);
    color: var(--white);
    border: none;
    border-radius: 12px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    transition: var(--transition-fast);
}

.reset-btn:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-medium);
}

/* ===========================
   Progress Bar
   =========================== */
.progress-container {
    position: relative;
    background: var(--white);
    border-radius: 50px;
    height: 30px;
    margin-bottom: 2rem;
    box-shadow: var(--shadow-small);
    overflow: hidden;
}

.progress-bar {
    position: absolute;
    left: 0;
    top: 0;
    height: 100%;
    background: linear-gradient(90deg, var(--primary-medium-blue) 0%, var(--primary-light-blue) 100%);
    border-radius: 50px;
    width: 0%;
    transition: width var(--transition-medium);
}

.progress-text {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    font-weight: 600;
    color: var(--primary-dark-blue);
    font-size: 0.875rem;
}

/* ===========================
   Game Board
   =========================== */
.game-board {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: var(--card-gap);
    padding: 2rem;
    padding-bottom: 3rem;
    background: rgba(255, 255, 255, 0.9);
    border-radius: 20px;
    box-shadow: var(--shadow-large);
    margin: 0 auto 1rem;
    animation: fadeIn 0.8s ease;
}

/* ===========================
   Cards
   =========================== */
.card {
    position: relative;
    width: var(--card-size-desktop);
    height: var(--card-size-desktop);
    cursor: pointer;
    transform-style: preserve-3d;
    transition: transform var(--transition-medium);
    animation: cardEntrance 0.6s ease backwards;
}

.match-number {
    position: absolute;
    top: 5px;
    right: 5px;
    width: 28px;
    height: 28px;
    background: var(--white);
    border: 2px solid var(--primary-medium-blue);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.875rem;
    color: var(--primary-medium-blue);
    z-index: 10;
    box-shadow: var(--shadow-small);
    opacity: 0;
    transform: rotateY(180deg) scale(0);
    transition: opacity var(--transition-medium), transform var(--transition-medium);
}

.match-number.show {
    opacity: 1;
    transform: rotateY(180deg) scale(1);
}

.card:nth-child(n) {
    animation-delay: calc(0.03s * var(--index));
}

.card.flipped {
    transform: rotateY(180deg);
}

.card.matched {
    animation: matchGlow 0.6s ease;
    pointer-events: none;
}

.card.matched .card-front {
    background: linear-gradient(135deg, var(--success-green) 0%, #73d13d 100%);
    box-shadow: var(--shadow-glow);
}

.card-face {
    position: absolute;
    width: 100%;
    height: 100%;
    backface-visibility: hidden;
    border-radius: 15px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    box-shadow: var(--shadow-small);
    transition: var(--transition-fast);
}

.card-back {
    background: linear-gradient(135deg, var(--primary-dark-blue) 0%, var(--primary-medium-blue) 100%);
    color: var(--white);
    font-size: 2rem;
}

.card-back::before {
    content: '🦷';
    font-size: 3.5rem;
    animation: pulse 2s infinite;
}

.card-front {
    background: var(--white);
    color: var(--primary-dark-blue);
    transform: rotateY(180deg);
    font-size: 1rem;
    padding: 0.75rem;
    text-align: center;
    border: 2px solid var(--primary-light-blue);
    line-height: 1.3;
}

.card-front.term {
    font-weight: 600;
}

.card-front.description {
    font-weight: 500;
}

/* Color variations */
.card-front.color-purple {
    background: linear-gradient(135deg, #9b59b6, #bb8fce);
    color: var(--white);
    border-color: #8e44ad;
}

.card-front.color-blue {
    background: linear-gradient(135deg, #3498db, #5dade2);
    color: var(--white);
    border-color: #2980b9;
}

.card-front.color-orange {
    background: linear-gradient(135deg, #e67e22, #f39c12);
    color: var(--white);
    border-color: #d35400;
}

.card-front.color-yellow {
    background: linear-gradient(135deg, #f1c40f, #f9e79f);
    color: #333;
    border-color: #f39c12;
}

.card-front.color-light-purple {
    background: linear-gradient(135deg, #d2b4de, #e8daef);
    color: #333;
    border-color: #bb8fce;
}

.card-front.color-light-orange {
    background: linear-gradient(135deg, #f8b88b, #fad7a0);
    color: #333;
    border-color: #e67e22;
}

.card-front.color-green {
    background: linear-gradient(135deg, #27ae60, #52c41a);
    color: var(--white);
    border-color: #229954;
}

.card:hover:not(.flipped):not(.matched) {
    transform: translateY(-5px);
}

.card:hover:not(.flipped):not(.matched) .card-back {
    box-shadow: var(--shadow-large);
}

/* ===========================
   Educational Popup
   =========================== */
.edu-popup {
    background: var(--white);
    border-radius: 20px;
    padding: 1.5rem 2rem;
    box-shadow: var(--shadow-medium);
    margin: 0 auto 2rem;
    opacity: 0;
    visibility: hidden;
    max-height: 0;
    overflow: hidden;
    transition: opacity var(--transition-medium), visibility var(--transition-medium), max-height var(--transition-medium);
    border-left: 4px solid var(--primary-light-blue);
}

.edu-popup.show {
    opacity: 1;
    visibility: visible;
    max-height: 200px;
}

.edu-content {
    width: 100%;
}

.edu-title {
    color: var(--primary-dark-blue);
    margin-bottom: 0.5rem;
    font-size: 1.2rem;
    font-weight: 600;
}

.edu-text {
    color: var(--gray-dark);
    line-height: 1.6;
    font-size: 1rem;
}

/* ===========================
   Win Screen
   =========================== */
.win-screen {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(29, 53, 87, 0.95);
    z-index: 2000;
    display: none;
    align-items: center;
    justify-content: center;
}

.win-screen.show {
    display: flex;
    animation: fadeIn 0.5s ease;
}

.win-content {
    background: var(--white);
    border-radius: 30px;
    padding: 3rem;
    max-width: 600px;
    width: 90%;
    text-align: center;
    position: relative;
    animation: bounceIn 0.8s ease;
}

.win-animation {
    position: absolute;
    top: -50px;
    left: 50%;
    transform: translateX(-50%);
    width: 100px;
    height: 100px;
}

.confetti {
    position: absolute;
    width: 10px;
    height: 10px;
    background: var(--primary-red);
    animation: confetti 2s infinite;
}

.confetti:nth-child(2) {
    left: 20px;
    background: var(--primary-light-blue);
    animation-delay: 0.2s;
}

.confetti:nth-child(3) {
    left: 40px;
    background: var(--primary-medium-blue);
    animation-delay: 0.4s;
}

.confetti:nth-child(4) {
    left: 60px;
    background: var(--success-green);
    animation-delay: 0.6s;
}

.confetti:nth-child(5) {
    left: 80px;
    background: var(--warning-yellow);
    animation-delay: 0.8s;
}

.win-title {
    font-size: 2.5rem;
    color: var(--primary-dark-blue);
    margin-bottom: 1rem;
}

.win-subtitle {
    font-size: 1.2rem;
    color: var(--gray-medium);
    margin-bottom: 2rem;
}

.win-stats {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1.5rem;
    margin-bottom: 2rem;
    padding: 1.5rem;
    background: var(--gray-light);
    border-radius: 15px;
}

.win-stat {
    display: flex;
    flex-direction: column;
}

.win-stat-label {
    font-size: 0.875rem;
    color: var(--gray-medium);
    margin-bottom: 0.25rem;
}

.win-stat-value {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--primary-medium-blue);
}

.win-actions {
    display: flex;
    gap: 1rem;
    justify-content: center;
}

.play-again-btn,
.share-btn {
    padding: 1rem 2rem;
    border: none;
    border-radius: 12px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition-fast);
}

.play-again-btn {
    background: var(--primary-red);
    color: var(--white);
}

.share-btn {
    background: var(--primary-medium-blue);
    color: var(--white);
}

.play-again-btn:hover,
.share-btn:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-medium);
}

/* ===========================
   Sound Toggle
   =========================== */
.sound-toggle {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background: var(--white);
    border: none;
    box-shadow: var(--shadow-medium);
    cursor: pointer;
    transition: var(--transition-fast);
    z-index: 50;
    display: flex;
    align-items: center;
    justify-content: center;
}

.sound-toggle svg {
    color: var(--primary-dark-blue);
}

.sound-toggle:hover {
    transform: scale(1.1);
    box-shadow: var(--shadow-large);
}

/* ===========================
   Star Particle Animation
   =========================== */
.star-particle {
    position: fixed;
    font-size: 1.5rem;
    pointer-events: none;
    z-index: 1000;
    animation: starBurst 1s ease-out forwards;
}

@keyframes starBurst {
    0% {
        transform: translate(0, 0) scale(0) rotate(0deg);
        opacity: 1;
    }
    50% {
        opacity: 1;
    }
    100% {
        transform: translate(var(--end-x), var(--end-y)) scale(1.5) rotate(360deg);
        opacity: 0;
    }
}

/* ===========================
   Animations
   =========================== */
@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

@keyframes fadeOut {
    from {
        opacity: 1;
    }
    to {
        opacity: 0;
        visibility: hidden;
    }
}

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

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

@keyframes bounce {
    0%, 100% {
        transform: translateY(0);
    }
    50% {
        transform: translateY(-20px);
    }
}

@keyframes pulse {
    0%, 100% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.05);
    }
}

@keyframes rotate {
    from {
        transform: rotate(0deg);
    }
    to {
        transform: rotate(360deg);
    }
}

@keyframes matchGlow {
    0% {
        transform: scale(1) rotateY(180deg);
    }
    50% {
        transform: scale(1.1) rotateY(180deg);
        box-shadow: 0 0 30px var(--primary-light-blue);
    }
    100% {
        transform: scale(1) rotateY(180deg);
    }
}

@keyframes cardEntrance {
    from {
        opacity: 0;
        transform: scale(0.8) rotateZ(10deg);
    }
    to {
        opacity: 1;
        transform: scale(1) rotateZ(0deg);
    }
}

@keyframes bounceIn {
    0% {
        transform: scale(0);
        opacity: 0;
    }
    50% {
        transform: scale(1.05);
    }
    100% {
        transform: scale(1);
        opacity: 1;
    }
}

@keyframes confetti {
    0% {
        transform: translateY(0) rotate(0deg);
        opacity: 1;
    }
    100% {
        transform: translateY(100px) rotate(720deg);
        opacity: 0;
    }
}

/* ===========================
   Media Queries
   =========================== */
@media (max-width: 1200px) {
    .game-board {
        grid-template-columns: repeat(6, 1fr);
    }
}

@media (max-width: 768px) {
    :root {
        --card-size-desktop: var(--card-size-tablet);
    }

    .game-title {
        font-size: 1.5rem;
    }

    .stats-container {
        gap: 1rem;
    }

    .stat-value {
        font-size: 1.2rem;
    }

    .game-board {
        grid-template-columns: repeat(4, 1fr);
        padding: 1.5rem;
        padding-bottom: 2.5rem;
        gap: 10px;
        margin-bottom: 0.75rem;
    }

    .card-front {
        font-size: 0.75rem;
    }

    .win-stats {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 480px) {
    :root {
        --card-size-desktop: var(--card-size-mobile);
    }

    .header-content {
        flex-direction: column;
        text-align: center;
    }

    .game-board {
        grid-template-columns: repeat(3, 1fr);
        gap: 8px;
        padding: 1rem;
        padding-bottom: 2rem;
        margin-bottom: 0.5rem;
    }

    .card-back::before {
        font-size: 1.5rem;
    }

    .card-front {
        font-size: 0.65rem;
        padding: 0.25rem;
    }

    .edu-popup {
        padding: 1rem 1.5rem;
        margin-bottom: 1rem;
    }

    .edu-popup.show {
        max-height: 250px;
    }

    .edu-title {
        font-size: 1rem;
    }

    .edu-text {
        font-size: 0.875rem;
    }

    .win-content {
        padding: 2rem 1rem;
    }
}

/* ===========================
   Print Styles
   =========================== */
@media print {
    body {
        background: white;
    }
    
    .sound-toggle,
    .reset-btn,
    .intro-overlay,
    .win-screen {
        display: none;
    }
}

/* ===========================
   Accessibility
   =========================== */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border-width: 0;
}

/* Focus styles for keyboard navigation */
button:focus-visible,
.card:focus-visible {
    outline: 3px solid var(--primary-medium-blue);
    outline-offset: 2px;
}

/* ===========================
   Footer
   =========================== */
.game-footer {
    background: linear-gradient(135deg, var(--primary-dark-blue) 0%, var(--primary-medium-blue) 100%);
    padding: 2rem 1rem;
    color: var(--white);
    text-align: center;
    width: 100%;
    margin-top: auto;
}

.footer-content {
    max-width: 800px;
    margin: 0 auto;
}

.footer-text {
    font-size: 1.2rem;
    font-weight: 600;
    margin-bottom: 1.5rem;
    color: var(--primary-cream);
}

.footer-image {
    border-radius: 12px;
    overflow: hidden;
    box-shadow: var(--shadow-large);
    max-width: 600px;
    margin: 0 auto;
}

.student-work-img {
    width: 100%;
    height: auto;
    display: block;
    transition: transform var(--transition-medium);
}

.student-work-img:hover {
    transform: scale(1.02);
}

@media (max-width: 768px) {
    .footer-text {
        font-size: 1rem;
    }

    .footer-image {
        max-width: 100%;
    }
}
