/* ==========================================================================
   MEMORY FLASH - GAME INGATAN
   ========================================================================== */

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

:root {
    --primary-color: #592D3A;
    --secondary-color: #ffffff;
    --accent-gold: #ffd700;
    --success-color: #28a745;
    --danger-color: #dc3545;
    --warning-color: #ffc107;
    
    --gradient-primary: linear-gradient(135deg, var(--primary-color) 0%, #8B4B61 100%);
    --gradient-secondary: linear-gradient(135deg, var(--secondary-color) 0%, #f8f9fa 100%);
    --gradient-gold: linear-gradient(135deg, var(--accent-gold) 0%, #ffed4e 100%);
    --gradient-success: linear-gradient(135deg, var(--success-color) 0%, #20c997 100%);
    
    --shadow-soft: 0 8px 32px rgba(89, 45, 58, 0.1);
    --shadow-medium: 0 12px 48px rgba(89, 45, 58, 0.15);
    --shadow-strong: 0 20px 60px rgba(89, 45, 58, 0.25);
    
    --border-radius: 20px;
    --border-radius-small: 12px;
    --border-radius-large: 28px;
    
    --transition-fast: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    --transition-smooth: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    --transition-slow: all 0.6s cubic-bezier(0.4, 0, 0.2, 1);
}

body {
    font-family: 'Inter', 'Segoe UI', system-ui, -apple-system, sans-serif;
    background: var(--gradient-secondary);
    min-height: 100vh;
    color: var(--primary-color);
    overflow-x: hidden;
    position: relative;
}

/* Background Image Layout */
.background-image {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: url("background.png") no-repeat center center;
    background-size: cover;
    z-index: -2;
    filter: brightness(0.9);
}

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

.geometric-shape {
    position: absolute;
    background: var(--gradient-primary);
    opacity: 0.08;
    animation: shapeFloat 20s infinite ease-in-out;
}

.shape-1 {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    top: 20%;
    left: 5%;
    animation-delay: 0s;
}

.shape-2 {
    width: 60px;
    height: 60px;
    top: 70%;
    right: 10%;
    animation-delay: 5s;
    clip-path: polygon(50% 0%, 0% 100%, 100% 100%);
}

.shape-3 {
    width: 100px;
    height: 100px;
    top: 40%;
    right: 20%;
    animation-delay: 10s;
    border-radius: var(--border-radius);
    transform: rotate(45deg);
}

.shape-4 {
    width: 50px;
    height: 50px;
    bottom: 30%;
    left: 15%;
    animation-delay: 15s;
    clip-path: polygon(50% 0%, 100% 50%, 50% 100%, 0% 50%);
}

@keyframes shapeFloat {
    0%, 100% { 
        transform: translateY(0px) rotate(0deg) scale(1); 
    }
    25% { 
        transform: translateY(-30px) rotate(90deg) scale(1.1); 
    }
    50% { 
        transform: translateY(-60px) rotate(180deg) scale(1); 
    }
    75% { 
        transform: translateY(-30px) rotate(270deg) scale(0.9); 
    }
}

.particle-container {
    position: absolute;
    width: 100%;
    height: 100%;
}

.particle {
    position: absolute;
    width: 4px;
    height: 4px;
    background: var(--primary-color);
    border-radius: 50%;
    opacity: 0.3;
    animation: particleFloat 8s infinite linear;
}

.particle-1 { top: 10%; left: 20%; animation-delay: 0s; }
.particle-2 { top: 30%; left: 80%; animation-delay: 1.3s; }
.particle-3 { top: 60%; left: 10%; animation-delay: 2.6s; }
.particle-4 { top: 80%; left: 70%; animation-delay: 4s; }
.particle-5 { top: 20%; left: 60%; animation-delay: 5.3s; }
.particle-6 { top: 50%; left: 40%; animation-delay: 6.6s; }

@keyframes particleFloat {
    0% {
        transform: translateY(0) translateX(0) scale(1);
        opacity: 0;
    }
    10% {
        opacity: 0.3;
    }
    90% {
        opacity: 0.3;
    }
    100% {
        transform: translateY(-100vh) translateX(100px) scale(0);
        opacity: 0;
    }
}

.background-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(
        to bottom,
        rgba(255, 255, 255, 0.7),
        rgba(89, 45, 58, 0.7)
    );
    z-index: -1;
}

/* Main Container */
.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 2rem;
    position: relative;
    z-index: 1;
}

/* Header */
.header {
    text-align: center;
    margin-bottom: 2rem;
}

.logo-container {
    display: flex;
    justify-content: center;
    align-items: center;
    margin-bottom: 0.5rem;
}

.logo-img {
    max-width: 350px;
    height: auto;
    display: block;
}

.game-subtitle {
    font-size: 1.2rem;
    opacity: 0.8;
    font-weight: 300;
    color: var(--primary-color);
}

/* Main Layout */
.main-content {
    display: grid;
    grid-template-columns: 1fr 350px;
    gap: 2rem;
    align-items: start;
}

/* Game Section */
.game-section {
    position: relative;
}

.game-card {
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(20px);
    border: 1px solid rgba(89, 45, 58, 0.1);
    border-radius: var(--border-radius-large);
    padding: 2rem;
    box-shadow: var(--shadow-soft);
    transition: var(--transition-smooth);
    position: relative;
    overflow: hidden;
}

.game-card.active {
    box-shadow: var(--shadow-strong);
}

.game-info {
    display: flex;
    justify-content: center;
    align-items: center;
    margin-bottom: 2rem;
    padding: 1rem 2rem;
    background: rgba(89, 45, 58, 0.05);
    border-radius: var(--border-radius);
    backdrop-filter: blur(10px);
}

.game-stat {
    text-align: center;
}

.stat-label {
    font-size: 0.9rem;
    opacity: 0.7;
    margin-bottom: 0.5rem;
}

.stat-value {
    font-size: 2rem;
    font-weight: 800;
    font-family: 'Courier New', monospace;
}

.time-value {
    color: var(--success-color);
}

.time-value.danger {
    color: var(--danger-color);
    animation: pulse 0.5s infinite;
}

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

/* Game Area */
.game-area {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 400px;
    height: auto; /* Dibuat fleksibel */
    background: rgba(89, 45, 58, 0.05);
    border-radius: var(--border-radius);
    border: 2px dashed rgba(89, 45, 58, 0.3);
    overflow: hidden;
    transition: var(--transition-smooth);
    position: relative;
    padding: 10px; /* Menambahkan padding agar grid tidak terlalu menempel ke tepi */
}

.game-area.active {
    border-color: var(--primary-color);
}

/* Game Grid */
.game-grid {
    display: grid;
    /* Mengubah tata letak menjadi 4 kolom dan 3 baris */
    grid-template-columns: repeat(4, 1fr);
    grid-template-rows: repeat(3, 1fr);
    gap: 10px;
    width: 100%;
    max-width: 700px; /* Atur lebar maksimum agar grid tidak terlalu besar di desktop */
    height: 100%;
    perspective: 1000px;
}

/* Card Container */
.game-card-container {
    position: relative;
    width: 100%;
    /* Menyesuaikan rasio agar lebih cocok dengan tata letak 4x3 */
    aspect-ratio: 1 / 1.2; 
    cursor: pointer;
    transform-style: preserve-3d;
    transition: transform 0.6s cubic-bezier(0.4, 0, 0.2, 1);
}

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

.game-card-container.matched {
    cursor: default;
    animation: bounceScale 0.8s ease-out forwards;
}

@keyframes bounceScale {
    0% { transform: scale(1) rotateY(180deg); }
    50% { transform: scale(1.1) rotateY(180deg); }
    100% { transform: scale(1) rotateY(180deg); }
}

/* Card Face (Front & Back) */
.card-face {
    position: absolute;
    width: 100%;
    height: 100%;
    backface-visibility: hidden;
    border-radius: 12px;
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.1);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2rem;
    color: var(--primary-color);
    padding: 5px;
}

.card-front {
    background: var(--gradient-primary);
    transform: rotateY(0deg);
}

.card-back {
    background: var(--gradient-secondary);
    transform: rotateY(180deg);
    overflow: hidden;
}

.card-image {
    width: 100%;
    height: 100%;
    object-fit: contain;
    border-radius: 8px;
    box-shadow: inset 0 0 5px rgba(0,0,0,0.2);
}

/* Control Panel */
.control-panel {
    margin-top: 2rem;
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
}

.btn {
    background: var(--gradient-primary);
    border: none;
    padding: 1rem 3rem;
    border-radius: var(--border-radius);
    color: white;
    font-size: 1.2rem;
    font-weight: 700;
    cursor: pointer;
    transition: var(--transition-smooth);
    box-shadow: var(--shadow-soft);
    position: relative;
    overflow: hidden;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    width: 100%;
}
.btn:hover:not(:disabled) {
    transform: translateY(-3px);
    box-shadow: var(--shadow-strong);
}

.btn:active:not(:disabled) {
    transform: translateY(-1px);
}

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

.btn-secondary {
    background: #e0e0e0;
    color: var(--primary-color);
}
.btn-secondary:hover:not(:disabled) {
    background: #d0d0d0;
    box-shadow: var(--shadow-soft);
}

/* Tombol tersembunyi */
.hidden {
    display: none;
}

/* Game Message */
.game-message {
    text-align: center;
    margin-top: 2rem;
    opacity: 0.7;
    color: var(--primary-color);
}

.game-message i {
    font-size: 4rem;
    margin-bottom: 1rem;
    opacity: 0.3;
}

/* Player Input */
.player-section {
    margin-bottom: 1rem;
    width: 100%;
}

.input-group {
    position: relative;
}

.input-group input {
    width: 100%;
    padding: 1rem 1.5rem;
    background: rgba(89, 45, 58, 0.05);
    border: 2px solid rgba(89, 45, 58, 0.2);
    border-radius: var(--border-radius);
    color: var(--primary-color);
    font-size: 1.1rem;
    transition: var(--transition-fast);
    outline: none;
}

.input-group input:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 20px rgba(89, 45, 58, 0.15);
}

.input-group input::placeholder {
    color: rgba(89, 45, 58, 0.5);
}

/* Leaderboard */
.sidebar {
    position: relative;
}

.leaderboard-card {
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(20px);
    border: 1px solid rgba(89, 45, 58, 0.1);
    border-radius: var(--border-radius-large);
    padding: 2rem;
    box-shadow: var(--shadow-soft);
    height: fit-content;
}

.leaderboard-header {
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 2rem;
    gap: 1rem;
}

.leaderboard-header h2 {
    font-size: 1.5rem;
    font-weight: 800;
}

.trophy-icon {
    width: 50px;
    height: 50px;
    background: var(--gradient-gold);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    color: var(--primary-color);
    animation: trophy-rotate 3s ease-in-out infinite;
}

@keyframes trophy-rotate {
    0%, 100% { transform: rotate(0deg); }
    50% { transform: rotate(15deg); }
}

.leaderboard-content {
    max-height: 400px;
    overflow-y: auto;
}

.leaderboard-item {
    display: flex;
    align-items: center;
    padding: 1rem;
    margin-bottom: 0.5rem;
    background: rgba(89, 45, 58, 0.05);
    border-radius: var(--border-radius);
    transition: var(--transition-fast);
    backdrop-filter: blur(10px);
}

.leaderboard-item:hover {
    background: rgba(89, 45, 58, 0.1);
    transform: translateX(5px);
}

.rank-badge {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    margin-right: 1rem;
    font-size: 1.1rem;
}

.rank-1 .rank-badge {
    background: var(--gradient-gold);
    color: var(--primary-color);
}

.rank-2 .rank-badge {
    background: linear-gradient(135deg, #c0c0c0, #e8e8e8);
    color: var(--primary-color);
}

.rank-3 .rank-badge {
    background: linear-gradient(135deg, #cd7f32, #d4915a);
    color: white;
}

.rank-other .rank-badge {
    background: rgba(89, 45, 58, 0.2);
    color: white;
}

.player-info {
    flex: 1;
    color: var(--primary-color);
}

.player-name {
    font-weight: 700;
    font-size: 1.1rem;
    margin-bottom: 0.3rem;
}

.player-score {
    font-family: 'Courier New', monospace;
    font-size: 1.5rem;
    font-weight: 800;
    color: var(--warning-color);
}

/* Toast Notifications */
.toast-container {
    position: fixed;
    top: 2rem;
    right: 2rem;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.toast {
    background: var(--gradient-success);
    color: white;
    padding: 1rem 1.5rem;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-strong);
    display: flex;
    align-items: center;
    gap: 1rem;
    transform: translateX(400px);
    opacity: 0;
    transition: var(--transition-smooth);
    backdrop-filter: blur(20px);
}

.toast.show {
    transform: translateX(0);
    opacity: 1;
}

.toast.success { background: var(--gradient-success); }
.toast.error { background: linear-gradient(135deg, var(--danger-color), #e74c3c); }
.toast.warning { background: linear-gradient(135deg, var(--warning-color), #ffed4e); color: var(--primary-color); }

.toast i {
    font-size: 1.2rem;
}

.toast-message {
    flex: 1;
    font-weight: 600;
    font-size: 0.9rem;
}

/* Responsive Design */
@media (max-width: 1024px) {
    .main-content {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 768px) {
    .container {
        padding: 1rem;
    }
    
    .game-area {
        min-height: 400px; 
    }

    .game-grid {
        gap: 8px;
        padding: 8px;
        max-width: 400px;
    }
}

/* Database Status Indicator - Hidden */
.db-status {
    display: none;
    position: fixed;
    top: 20px;
    left: 20px;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(20px);
    padding: 10px 15px;
    border-radius: var(--border-radius-small);
    box-shadow: var(--shadow-soft);
    align-items: center;
    gap: 8px;
    font-size: 0.85rem;
    font-weight: 600;
    z-index: 1000;
    transition: var(--transition-smooth);
    border: 2px solid transparent;
}

.db-status.online {
    color: var(--success-color);
    border-color: var(--success-color);
    background: rgba(40, 167, 69, 0.1);
}

.db-status.offline {
    color: var(--danger-color);
    border-color: var(--danger-color);
    background: rgba(220, 53, 69, 0.1);
}

.db-status.connecting {
    color: var(--warning-color);
    border-color: var(--warning-color);
    background: rgba(255, 193, 7, 0.1);
}

.db-status.connecting i {
    animation: spin 1s linear infinite;
}

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

/* Loading Spinner Improvements */
.spinner {
    width: 20px;
    height: 20px;
    border: 2px solid rgba(89, 45, 58, 0.3);
    border-top: 2px solid var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-right: 10px;
}

.loading {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
    color: var(--primary-color);
    opacity: 0.7;
}

/* Error States */
.error-message {
    background: rgba(220, 53, 69, 0.1);
    border: 1px solid var(--danger-color);
    border-radius: var(--border-radius);
    padding: 1rem;
    color: var(--danger-color);
    text-align: center;
    margin: 1rem 0;
}

.success-message {
    background: rgba(40, 167, 69, 0.1);
    border: 1px solid var(--success-color);
    border-radius: var(--border-radius);
    padding: 1rem;
    color: var(--success-color);
    text-align: center;
    margin: 1rem 0;
}

/* Connection Status in Leaderboard */
.leaderboard-status {
    text-align: center;
    padding: 1rem;
    font-size: 0.9rem;
    opacity: 0.7;
    border-top: 1px solid rgba(89, 45, 58, 0.1);
    margin-top: 1rem;
}

/* Responsive adjustments for mobile */
@media (max-width: 768px) {
    .db-status {
        top: 10px;
        left: 10px;
        font-size: 0.8rem;
        padding: 8px 12px;
    }
    
    .toast-container {
        top: 1rem;
        right: 1rem;
        left: 1rem;
    }
    
    .toast {
        width: 100%;
        margin: 0;
    }
    
    .game-area {
        min-height: 400px;
    }

    .game-grid {
        gap: 8px;
        padding: 8px;
        max-width: 400px;
    }
}