/* ========================================
   CSS Variables & Base Styles
======================================== */
:root {
    /* Colors */
    --color-primary: #6366f1;
    --color-primary-light: #818cf8;
    --color-primary-dark: #4f46e5;
    --color-secondary: #ec4899;
    --color-secondary-light: #f472b6;
    --color-accent: #06b6d4;
    --color-success: #10b981;
    --color-warning: #f59e0b;

    /* Backgrounds */
    --bg-dark: #d4f1d4;
    --bg-card: rgba(255, 255, 255, 0.3);
    --bg-glass: rgba(255, 255, 255, 0.4);

    /* Text Colors */
    --text-primary: #1a4d1a;
    --text-secondary: rgba(26, 77, 26, 0.8);
    --text-muted: rgba(26, 77, 26, 0.6);

    /* Borders */
    --border-light: rgba(26, 77, 26, 0.2);
    --border-focus: rgba(34, 139, 34, 0.5);

    /* Shadows */
    --shadow-glow: 0 0 40px rgba(99, 102, 241, 0.3);
    --shadow-card: 0 8px 32px rgba(0, 0, 0, 0.3);

    /* Spacing */
    --spacing-xs: 0.5rem;
    --spacing-sm: 1rem;
    --spacing-md: 1.5rem;
    --spacing-lg: 2rem;
    --spacing-xl: 3rem;

    /* Border Radius */
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 20px;
    --radius-full: 50%;

    /* Transitions */
    --transition-fast: 0.2s ease;
    --transition-medium: 0.3s ease;
    --transition-slow: 0.5s ease;
}

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

body {
    font-family: 'Noto Sans JP', 'Outfit', sans-serif;
    background: var(--bg-dark);
    color: var(--text-primary);
    min-height: 100vh;
    overflow-x: hidden;
    line-height: 1.6;
}

/* ========================================
   Background Effects
======================================== */
.background-effects {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: -1;
    overflow: hidden;
}

.gradient-orb {
    position: absolute;
    border-radius: 50%;
    filter: blur(80px);
    opacity: 0.4;
    animation: float 15s ease-in-out infinite;
}

.orb-1 {
    width: 400px;
    height: 400px;
    background: #90ee90;
    top: -100px;
    left: -100px;
    animation-delay: 0s;
}

.orb-2 {
    width: 500px;
    height: 500px;
    background: #98fb98;
    top: 50%;
    right: -150px;
    animation-delay: -5s;
}

.orb-3 {
    width: 350px;
    height: 350px;
    background: #7cfc00;
    bottom: -100px;
    left: 30%;
    animation-delay: -10s;
}

@keyframes float {

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

    33% {
        transform: translate(30px, -30px) scale(1.05);
    }

    66% {
        transform: translate(-20px, 20px) scale(0.95);
    }
}

/* ========================================
   Container & Layout
======================================== */
.container {
    max-width: 900px;
    margin: 0 auto;
    padding: var(--spacing-lg);
    min-height: 100vh;
}

.hidden {
    display: none !important;
}

/* ========================================
   Glass Panel Effect
======================================== */
.glass-panel {
    background: var(--bg-glass);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-card);
}

/* ========================================
   Header
======================================== */
.header {
    text-align: center;
    margin-bottom: var(--spacing-xl);
    padding-top: var(--spacing-lg);
}

.title {
    font-size: 3rem;
    font-weight: 700;
    background: linear-gradient(135deg, var(--color-primary-light), var(--color-secondary-light));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--spacing-xs);
}

.title-icon {
    font-size: 4rem;
    -webkit-text-fill-color: initial;
    animation: bounce 2s ease-in-out infinite;
}

@keyframes bounce {

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

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

.subtitle {
    font-size: 1rem;
    font-weight: 400;
    color: var(--text-secondary);
    -webkit-text-fill-color: initial;
    letter-spacing: 0.2em;
    text-transform: uppercase;
}

/* ========================================
   Upload Section
======================================== */
.upload-section {
    padding: var(--spacing-lg);
    text-align: center;
}

.section-title {
    font-size: 1.5rem;
    margin-bottom: var(--spacing-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--spacing-sm);
}

.icon {
    font-size: 1.5rem;
}

.upload-description {
    color: var(--text-secondary);
    margin-bottom: var(--spacing-lg);
}

.upload-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: var(--spacing-md);
    margin-bottom: var(--spacing-lg);
}

@media (max-width: 768px) {
    .upload-grid {
        grid-template-columns: repeat(3, 1fr);
    }
}

@media (max-width: 480px) {
    .upload-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

.upload-slot {
    position: relative;
    aspect-ratio: 1;
    border-radius: var(--radius-md);
    overflow: hidden;
}

.file-input {
    position: absolute;
    opacity: 0;
    width: 100%;
    height: 100%;
    cursor: pointer;
    z-index: 2;
}

.upload-label {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: var(--bg-card);
    border: 2px dashed var(--border-light);
    border-radius: var(--radius-md);
    transition: all var(--transition-medium);
    cursor: pointer;
}

.upload-slot:hover .upload-label {
    border-color: var(--color-primary);
    background: rgba(99, 102, 241, 0.1);
}

.upload-icon {
    font-size: 2rem;
    color: var(--text-muted);
    transition: var(--transition-fast);
}

.upload-slot:hover .upload-icon {
    color: var(--color-primary);
    transform: scale(1.1);
}

.upload-text {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-top: var(--spacing-xs);
}

.preview-image {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: var(--radius-md);
    opacity: 0;
    transition: opacity var(--transition-medium);
}

.upload-slot.has-image .preview-image {
    opacity: 1;
}

.upload-slot.has-image .upload-label {
    opacity: 0;
}

.upload-status {
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin-bottom: var(--spacing-lg);
}

#upload-count {
    color: var(--color-primary-light);
    font-weight: 600;
    font-size: 1.1rem;
}

/* ========================================
   Buttons
======================================== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--spacing-xs);
    padding: 1rem 2rem;
    font-size: 1rem;
    font-weight: 600;
    font-family: inherit;
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all var(--transition-medium);
    text-decoration: none;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-primary {
    background: linear-gradient(135deg, var(--color-primary), var(--color-secondary));
    color: white;
    box-shadow: 0 4px 20px rgba(99, 102, 241, 0.4);
}

.btn-primary:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 8px 30px rgba(99, 102, 241, 0.5);
}

.btn-primary:active:not(:disabled) {
    transform: translateY(0);
}

.btn-secondary {
    background: var(--bg-glass);
    color: var(--text-primary);
    border: 1px solid var(--border-light);
}

.btn-secondary:hover:not(:disabled) {
    background: rgba(255, 255, 255, 0.15);
}

.btn-outline {
    background: transparent;
    color: var(--text-primary);
    border: 1px solid var(--border-light);
}

.btn-outline:hover:not(:disabled) {
    background: var(--bg-glass);
    border-color: var(--color-primary);
}

.btn-icon {
    font-size: 1.2rem;
}

/* ========================================
   Game Section
======================================== */
.game-section {
    animation: fadeIn 0.5s ease;
}

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

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

.game-stats {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: var(--spacing-md);
    padding: var(--spacing-md);
    margin-bottom: var(--spacing-lg);
}

.stat {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}

.stat-icon {
    font-size: 1.5rem;
}

.stat-label {
    font-size: 0.75rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.1em;
}

.stat-value {
    font-size: 1.8rem;
    font-weight: 700;
    background: linear-gradient(135deg, var(--color-primary-light), var(--color-accent));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.stat-suffix {
    font-size: 1rem;
    color: var(--text-muted);
}

/* ========================================
   Game Board
======================================== */
.game-board {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: var(--spacing-md);
    margin-bottom: var(--spacing-lg);
    perspective: 1000px;
}

@media (max-width: 600px) {
    .game-board {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* ========================================
   Cards
======================================== */
.card {
    aspect-ratio: 1;
    position: relative;
    cursor: pointer;
    transform-style: preserve-3d;
    transition: transform 0.6s cubic-bezier(0.4, 0, 0.2, 1);
}

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

.card.matched {
    cursor: default;
}

.card-face {
    position: absolute;
    inset: 0;
    border-radius: var(--radius-md);
    backface-visibility: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.card-back {
    background: linear-gradient(135deg, var(--color-primary-dark), var(--color-primary));
    border: 2px solid var(--color-primary-light);
    box-shadow: 0 4px 20px rgba(99, 102, 241, 0.3);
}

.card-back::before {
    content: '?';
    font-size: 3rem;
    font-weight: 700;
    color: rgba(255, 255, 255, 0.3);
}

.card-back::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, transparent 40%, rgba(255, 255, 255, 0.1) 50%, transparent 60%);
    animation: shimmer 3s infinite;
}

@keyframes shimmer {
    0% {
        transform: translateX(-100%);
    }

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

.card:hover:not(.flipped):not(.matched) .card-back {
    box-shadow: 0 8px 30px rgba(99, 102, 241, 0.5);
    border-color: var(--color-secondary-light);
}

.card-front {
    transform: rotateY(180deg);
    background: var(--bg-glass);
    border: 2px solid var(--border-light);
}

.card-front img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.card.matched .card-front {
    border-color: var(--color-success);
    box-shadow: 0 0 30px rgba(16, 185, 129, 0.5);
}

.card.matched::after {
    content: '✓';
    position: absolute;
    top: 8px;
    right: 8px;
    width: 24px;
    height: 24px;
    background: var(--color-success);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8rem;
    color: white;
    z-index: 10;
    animation: pop 0.3s ease;
}

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

    50% {
        transform: scale(1.2);
    }

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

/* ========================================
   Game Controls
======================================== */
.game-controls {
    display: flex;
    justify-content: center;
    gap: var(--spacing-md);
    flex-wrap: wrap;
}

/* ========================================
   Modal
======================================== */
.modal {
    position: fixed;
    inset: 0;
    background: rgba(180, 230, 180, 0.9);
    backdrop-filter: blur(10px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    animation: modalFadeIn 0.4s ease;
}

@keyframes modalFadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

.modal-content {
    padding: var(--spacing-xl);
    text-align: center;
    max-width: 400px;
    width: 90%;
    animation: modalSlideIn 0.4s ease;
}

@keyframes modalSlideIn {
    from {
        transform: translateY(-50px) scale(0.9);
        opacity: 0;
    }

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

.victory-animation {
    margin-bottom: var(--spacing-md);
}

.confetti {
    display: inline-block;
    font-size: 2.5rem;
    animation: confettiBounce 1s ease infinite;
}

.confetti:nth-child(1) {
    animation-delay: 0s;
}

.confetti:nth-child(2) {
    animation-delay: 0.2s;
}

.confetti:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes confettiBounce {

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

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

.modal-title {
    font-size: 2.5rem;
    margin-bottom: var(--spacing-xs);
    background: linear-gradient(135deg, var(--color-warning), var(--color-secondary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.modal-subtitle {
    color: var(--text-secondary);
    margin-bottom: var(--spacing-lg);
}

.final-stats {
    display: flex;
    justify-content: center;
    gap: var(--spacing-xl);
    margin-bottom: var(--spacing-lg);
}

.final-stat {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.final-stat-label {
    font-size: 0.8rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.1em;
}

.final-stat-value {
    font-size: 2rem;
    font-weight: 700;
    color: var(--color-accent);
}

.modal-buttons {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-sm);
}

/* ========================================
   Responsive Adjustments
======================================== */
@media (max-width: 600px) {
    .container {
        padding: var(--spacing-md);
    }

    .title {
        font-size: 2rem;
    }

    .title-icon {
        font-size: 3rem;
    }

    .game-stats {
        padding: var(--spacing-sm);
    }

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

    .btn {
        padding: 0.8rem 1.5rem;
        font-size: 0.9rem;
    }
}