/* 전역 스타일 */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary-color: #6c5ce7;
    --secondary-color: #a29bfe;
    --success-color: #00b894;
    --danger-color: #d63031;
    --background: #f5f6fa;
    --card-back: #2d3436;
    --card-front: #ffffff;
    --text-dark: #2d3436;
    --text-light: #636e72;
    --shadow: rgba(0, 0, 0, 0.1);
    --shadow-hover: rgba(0, 0, 0, 0.2);
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    padding: 20px;
    color: var(--text-dark);
}

.container {
    max-width: 1200px;
    margin: 0 auto;
}

/* 헤더 */
header {
    text-align: center;
    color: white;
    margin-bottom: 30px;
    animation: fadeInDown 0.6s ease-out;
}

header h1 {
    font-size: 2.5rem;
    margin-bottom: 10px;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
}

header p {
    font-size: 1.1rem;
    opacity: 0.9;
}

/* 게임 설정 패널 */
.setup-panel {
    background: white;
    border-radius: 15px;
    padding: 30px;
    margin-bottom: 30px;
    box-shadow: 0 10px 30px var(--shadow);
    animation: fadeIn 0.6s ease-out;
}

.input-group {
    margin-bottom: 25px;
}

.input-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: 600;
    color: var(--text-dark);
}

.input-group input {
    width: 100%;
    padding: 12px 15px;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    font-size: 1rem;
    transition: border-color 0.3s;
}

.input-group input:focus {
    outline: none;
    border-color: var(--primary-color);
}

.difficulty-group h3 {
    margin-bottom: 15px;
    color: var(--text-dark);
}

.difficulty-buttons {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 15px;
    margin-bottom: 20px;
}

.difficulty-btn {
    padding: 15px;
    border: 2px solid #e0e0e0;
    background: white;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.3s;
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.difficulty-btn:hover {
    border-color: var(--primary-color);
    transform: translateY(-2px);
    box-shadow: 0 5px 15px var(--shadow);
}

.difficulty-btn.active {
    border-color: var(--primary-color);
    background: var(--primary-color);
    color: white;
}

.diff-title {
    font-size: 1.1rem;
    font-weight: 600;
}

.diff-desc {
    font-size: 0.9rem;
    opacity: 0.8;
}

.start-btn {
    width: 100%;
    padding: 15px;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: 10px;
    font-size: 1.1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s;
}

.start-btn:hover {
    background: #5f4dd1;
    transform: translateY(-2px);
    box-shadow: 0 5px 15px var(--shadow-hover);
}

/* 게임 정보 패널 */
.game-info {
    background: white;
    border-radius: 15px;
    padding: 20px;
    margin-bottom: 30px;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 20px;
    box-shadow: 0 5px 15px var(--shadow);
    animation: fadeIn 0.6s ease-out;
}

.info-item {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.info-label {
    font-size: 0.85rem;
    color: var(--text-light);
    font-weight: 500;
}

.info-value {
    font-size: 1.3rem;
    font-weight: 700;
    color: var(--primary-color);
}

.new-game-btn {
    margin-left: auto;
    padding: 10px 20px;
    background: var(--danger-color);
    color: white;
    border: none;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s;
}

.new-game-btn:hover {
    background: #c0392b;
    transform: translateY(-2px);
}

/* 게임 보드 */
.game-board {
    display: grid;
    gap: 15px;
    margin-bottom: 40px;
    perspective: 1000px;
    animation: fadeIn 0.6s ease-out;
    max-width: 100%;
    margin-left: auto;
    margin-right: auto;
    padding: 0 20px;
}

.game-board.easy {
    grid-template-columns: repeat(4, minmax(100px, 140px));
    max-width: 640px;
}

.game-board.medium {
    grid-template-columns: repeat(4, minmax(100px, 140px));
    max-width: 640px;
}

.game-board.hard {
    grid-template-columns: repeat(6, minmax(80px, 120px));
    max-width: 800px;
}

/* 카드 */
.card {
    aspect-ratio: 3/4;
    width: 100%;
    cursor: pointer;
    position: relative;
    transform-style: preserve-3d;
    transition: transform 0.6s;
}

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

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

.card.disabled {
    pointer-events: none;
}

.card-inner {
    position: absolute;
    width: 100%;
    height: 100%;
    transform-style: preserve-3d;
}

.card-front,
.card-back {
    position: absolute;
    width: 100%;
    height: 100%;
    backface-visibility: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 10px;
    box-shadow: 0 4px 8px var(--shadow);
    font-size: 3rem;
    transition: all 0.3s;
}

.card-front {
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    color: white;
    font-weight: 700;
}

.card-back {
    background: var(--card-front);
    transform: rotateY(180deg);
}

.card:not(.flipped):not(.matched):hover .card-front {
    transform: scale(1.05);
    box-shadow: 0 6px 12px var(--shadow-hover);
}

/* 리더보드 */
.leaderboard-section {
    background: white;
    border-radius: 15px;
    padding: 30px;
    box-shadow: 0 10px 30px var(--shadow);
    animation: fadeIn 0.6s ease-out;
}

.leaderboard-section h2 {
    text-align: center;
    margin-bottom: 20px;
    color: var(--text-dark);
}

.leaderboard-tabs {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
    border-bottom: 2px solid #e0e0e0;
}

.tab-btn {
    padding: 10px 20px;
    background: none;
    border: none;
    border-bottom: 3px solid transparent;
    cursor: pointer;
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-light);
    transition: all 0.3s;
}

.tab-btn:hover {
    color: var(--primary-color);
}

.tab-btn.active {
    color: var(--primary-color);
    border-bottom-color: var(--primary-color);
}

.leaderboard-tab {
    display: none;
}

.leaderboard-tab.active {
    display: block;
}

.leaderboard-table {
    width: 100%;
    border-collapse: collapse;
}

.leaderboard-table th,
.leaderboard-table td {
    padding: 12px;
    text-align: left;
    border-bottom: 1px solid #e0e0e0;
}

.leaderboard-table th {
    background: var(--background);
    font-weight: 600;
    color: var(--text-dark);
}

.leaderboard-table tr:hover {
    background: var(--background);
}

.rank-badge {
    display: inline-block;
    width: 30px;
    height: 30px;
    line-height: 30px;
    text-align: center;
    border-radius: 50%;
    font-weight: 700;
}

.rank-1 { background: #f1c40f; color: white; }
.rank-2 { background: #bdc3c7; color: white; }
.rank-3 { background: #cd7f32; color: white; }

.loading {
    text-align: center;
    padding: 30px;
    color: var(--text-light);
}

.no-data {
    text-align: center;
    padding: 30px;
    color: var(--text-light);
}

/* 모달 */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    animation: fadeIn 0.3s ease-out;
}

.modal-content {
    background: white;
    border-radius: 20px;
    padding: 40px;
    max-width: 500px;
    width: 90%;
    text-align: center;
    animation: slideUp 0.3s ease-out;
}

.modal-content h2 {
    color: var(--primary-color);
    margin-bottom: 15px;
    font-size: 2rem;
}

.modal-message {
    color: var(--text-light);
    margin-bottom: 30px;
    font-size: 1.1rem;
}

.modal-stats {
    display: flex;
    flex-direction: column;
    gap: 15px;
    margin-bottom: 30px;
    padding: 20px;
    background: var(--background);
    border-radius: 10px;
}

.stat {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.stat-label {
    font-weight: 600;
    color: var(--text-dark);
}

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

.modal-buttons {
    display: flex;
    gap: 15px;
}

.modal-btn {
    flex: 1;
    padding: 12px;
    border: none;
    border-radius: 10px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s;
}

.modal-btn.primary {
    background: var(--primary-color);
    color: white;
}

.modal-btn.primary:hover {
    background: #5f4dd1;
    transform: translateY(-2px);
}

.modal-btn.secondary {
    background: var(--text-light);
    color: white;
}

.modal-btn.secondary:hover {
    background: #535c68;
    transform: translateY(-2px);
}

/* 유틸리티 클래스 */
.hidden {
    display: none !important;
}

/* 애니메이션 */
@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

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

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

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

/* 반응형 디자인 */
@media (max-width: 768px) {
    header h1 {
        font-size: 2rem;
    }
    
    header p {
        font-size: 1rem;
    }
    
    .setup-panel,
    .leaderboard-section {
        padding: 20px;
    }
    
    .difficulty-buttons {
        grid-template-columns: 1fr;
    }
    
    .game-info {
        justify-content: center;
    }
    
    .new-game-btn {
        margin-left: 0;
        width: 100%;
    }
    
    .game-board {
        gap: 10px;
        padding: 0 10px;
    }
    
    .game-board.easy {
        grid-template-columns: repeat(4, minmax(70px, 1fr));
        max-width: 100%;
    }
    
    .game-board.medium {
        grid-template-columns: repeat(4, minmax(70px, 1fr));
        max-width: 100%;
    }
    
    .game-board.hard {
        grid-template-columns: repeat(4, minmax(70px, 1fr));
        max-width: 100%;
    }
    
    .card-front,
    .card-back {
        font-size: 2rem;
    }
    
    .modal-content {
        padding: 30px 20px;
    }
    
    .modal-buttons {
        flex-direction: column;
    }
    
    .leaderboard-table {
        font-size: 0.9rem;
    }
    
    .leaderboard-table th,
    .leaderboard-table td {
        padding: 8px;
    }
}

@media (max-width: 480px) {
    body {
        padding: 10px;
    }
    
    header h1 {
        font-size: 1.5rem;
    }
    
    .game-board {
        gap: 8px;
        padding: 0 5px;
    }
    
    .game-board.easy {
        grid-template-columns: repeat(3, minmax(60px, 1fr));
    }
    
    .game-board.medium {
        grid-template-columns: repeat(3, minmax(60px, 1fr));
    }
    
    .game-board.hard {
        grid-template-columns: repeat(3, minmax(60px, 1fr));
    }
    
    .card-front,
    .card-back {
        font-size: 1.5rem;
        border-radius: 8px;
    }
}

