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

:root {
    --primary: #6366f1;
    --primary-dark: #4f46e5;
    --secondary: #8b5cf6;
    --accent: #ec4899;
    --bg-dark: #0f172a;
    --bg-medium: #1e293b;
    --bg-light: #334155;
    --text-primary: #f1f5f9;
    --text-secondary: #cbd5e1;
    --text-muted: #94a3b8;
    --border-color: #475569;
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --user-color: #3b82f6;
    --ai-color: #ef4444;
    --gold: #fbbf24;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: linear-gradient(135deg, #0f172a 0%, #1e1b4b 50%, #0f172a 100%);
    color: var(--text-primary);
    min-height: 100vh;
    overflow-x: hidden;
}

.hidden {
    display: none !important;
}

/* ===== 시작 화면 ===== */
.start-screen {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
    background: radial-gradient(ellipse at top, #312e81 0%, #0f172a 70%);
}

.start-content {
    background: rgba(30, 41, 59, 0.7);
    backdrop-filter: blur(20px);
    border: 1px solid rgba(99, 102, 241, 0.3);
    border-radius: 24px;
    padding: 3rem;
    max-width: 700px;
    width: 100%;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
    animation: fadeInUp 0.8s ease;
}

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

.logo {
    text-align: center;
    margin-bottom: 0.5rem;
}

.logo i {
    font-size: 4rem;
    background: linear-gradient(135deg, var(--gold), var(--accent));
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    margin-bottom: 1rem;
    display: inline-block;
    animation: float 3s ease-in-out infinite;
}

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

.logo h1 {
    font-family: 'Cinzel', serif;
    font-size: 2.5rem;
    font-weight: 700;
    background: linear-gradient(135deg, #fff, #cbd5e1);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    letter-spacing: 1px;
}

.subtitle {
    text-align: center;
    color: var(--text-secondary);
    margin-bottom: 2.5rem;
    font-size: 1.1rem;
}

.difficulty-selector,
.color-selector {
    margin-bottom: 2rem;
}

.difficulty-selector h3,
.color-selector h3 {
    font-size: 1.1rem;
    margin-bottom: 1rem;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.difficulty-buttons {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 0.75rem;
}

.difficulty-btn {
    background: rgba(51, 65, 85, 0.5);
    border: 2px solid transparent;
    border-radius: 12px;
    padding: 1rem 0.5rem;
    color: var(--text-primary);
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.4rem;
    font-family: inherit;
}

.difficulty-btn i {
    font-size: 1.5rem;
    color: var(--text-muted);
}

.difficulty-btn span {
    font-weight: 600;
    font-size: 0.95rem;
}

.difficulty-btn small {
    color: var(--text-muted);
    font-size: 0.8rem;
}

.difficulty-btn:hover {
    background: rgba(99, 102, 241, 0.2);
    transform: translateY(-2px);
}

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

.difficulty-btn.active i {
    color: #fff;
}

.color-buttons {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

.color-btn {
    background: rgba(51, 65, 85, 0.5);
    border: 2px solid var(--border-color);
    border-radius: 16px;
    padding: 2rem 1rem;
    color: var(--text-primary);
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    font-family: inherit;
}

.piece-icon {
    font-size: 4rem;
    line-height: 1;
}

.white-btn .piece-icon {
    color: #f1f5f9;
    text-shadow: 0 0 20px rgba(255, 255, 255, 0.3);
}

.black-btn .piece-icon {
    color: #1e293b;
    text-shadow: 0 0 20px rgba(0, 0, 0, 0.5);
}

.color-name {
    font-size: 1.2rem;
    font-weight: 700;
    margin-top: 0.5rem;
}

.color-btn small {
    color: var(--text-muted);
    font-size: 0.85rem;
}

.color-btn:hover {
    transform: translateY(-4px);
    border-color: var(--primary);
    box-shadow: 0 10px 30px rgba(99, 102, 241, 0.3);
}

.white-btn:hover {
    background: linear-gradient(135deg, rgba(241, 245, 249, 0.1), rgba(99, 102, 241, 0.2));
}

.black-btn:hover {
    background: linear-gradient(135deg, rgba(15, 23, 42, 0.5), rgba(99, 102, 241, 0.2));
}

/* ===== 모바일 버전 링크 ===== */
.mobile-link {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    margin-top: 1.5rem;
    padding: 0.75rem 1rem;
    background: rgba(51, 65, 85, 0.4);
    border: 1px solid rgba(99, 102, 241, 0.2);
    border-radius: 10px;
    color: var(--text-muted);
    text-decoration: none;
    font-size: 0.9rem;
    transition: all 0.2s ease;
}

.mobile-link:hover {
    background: rgba(99, 102, 241, 0.15);
    color: var(--text-primary);
    border-color: var(--primary);
    transform: translateY(-2px);
}

.mobile-link i {
    color: var(--primary);
}

/* ===== 게임 화면 ===== */
.game-screen {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.game-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 2rem;
    background: rgba(15, 23, 42, 0.8);
    backdrop-filter: blur(20px);
    border-bottom: 1px solid rgba(99, 102, 241, 0.2);
}

.header-left {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.header-icon {
    font-size: 1.8rem;
    color: var(--gold);
}

.game-header h1 {
    font-family: 'Cinzel', serif;
    font-size: 1.4rem;
    font-weight: 700;
}

.header-right {
    display: flex;
    gap: 0.5rem;
}

.header-btn {
    background: rgba(51, 65, 85, 0.5);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 0.6rem 1.2rem;
    border-radius: 8px;
    cursor: pointer;
    font-family: inherit;
    font-size: 0.9rem;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.header-btn:hover {
    background: var(--primary);
    border-color: var(--primary);
    transform: translateY(-1px);
}

.header-btn.danger:hover {
    background: var(--danger);
    border-color: var(--danger);
}

/* ===== 메인 컨테이너 ===== */
.main-container {
    flex: 1;
    display: grid;
    grid-template-columns: 320px 1fr 320px;
    gap: 1.5rem;
    padding: 1.5rem;
    max-width: 1600px;
    margin: 0 auto;
    width: 100%;
}

/* ===== 사이드 패널 ===== */
.side-panel {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.player-card,
.stats-card,
.captured-card,
.moves-card,
.chart-card {
    background: rgba(30, 41, 59, 0.7);
    backdrop-filter: blur(20px);
    border: 1px solid rgba(99, 102, 241, 0.2);
    border-radius: 16px;
    padding: 1.25rem;
}

.player-card {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.user-card {
    border-color: rgba(59, 130, 246, 0.4);
    background: linear-gradient(135deg, rgba(59, 130, 246, 0.1), rgba(30, 41, 59, 0.7));
}

.ai-card {
    border-color: rgba(239, 68, 68, 0.4);
    background: linear-gradient(135deg, rgba(239, 68, 68, 0.1), rgba(30, 41, 59, 0.7));
}

.player-avatar {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.8rem;
    flex-shrink: 0;
}

.user-card .player-avatar {
    background: linear-gradient(135deg, var(--user-color), #1e40af);
}

.ai-card .player-avatar {
    background: linear-gradient(135deg, var(--ai-color), #991b1b);
}

.player-info {
    flex: 1;
}

.player-info h3 {
    font-size: 1.1rem;
    margin-bottom: 0.2rem;
}

.player-info p {
    color: var(--text-muted);
    font-size: 0.9rem;
}

.player-status {
    font-size: 0.8rem;
    padding: 0.3rem 0.7rem;
    border-radius: 20px;
    background: rgba(51, 65, 85, 0.5);
    color: var(--text-secondary);
}

.player-card.active .player-status {
    background: var(--success);
    color: #fff;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.6; }
}

/* ===== 통계 카드 ===== */
.stats-card h3,
.captured-card h3,
.moves-card h3,
.chart-card h3 {
    font-size: 1rem;
    margin-bottom: 1rem;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.win-rate-container {
    margin-bottom: 1rem;
}

.win-rate-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.5rem;
    font-size: 0.9rem;
}

.rate-label {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    color: var(--text-secondary);
}

.rate-value {
    font-weight: 700;
    font-size: 1rem;
}

.rate-bar {
    height: 12px;
    background: rgba(51, 65, 85, 0.5);
    border-radius: 6px;
    overflow: hidden;
    display: flex;
    margin: 0.5rem 0;
    position: relative;
}

.rate-fill {
    height: 100%;
    transition: width 0.6s cubic-bezier(0.4, 0, 0.2, 1);
}

.user-fill {
    background: linear-gradient(90deg, var(--user-color), #60a5fa);
}

.ai-fill {
    background: linear-gradient(90deg, #f87171, var(--ai-color));
}

.evaluation-info {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 0.5rem;
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid rgba(99, 102, 241, 0.2);
}

.eval-item {
    text-align: center;
    padding: 0.5rem;
    background: rgba(51, 65, 85, 0.3);
    border-radius: 8px;
}

.eval-label {
    display: block;
    font-size: 0.7rem;
    color: var(--text-muted);
    margin-bottom: 0.3rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.eval-value {
    display: block;
    font-size: 1rem;
    font-weight: 700;
    color: var(--text-primary);
}

/* ===== 잡은 기물 ===== */
.captured-section {
    margin-bottom: 0.75rem;
}

.captured-label {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-bottom: 0.4rem;
}

.captured-pieces {
    min-height: 32px;
    padding: 0.5rem;
    background: rgba(51, 65, 85, 0.3);
    border-radius: 8px;
    font-size: 1.5rem;
    line-height: 1;
    word-spacing: -4px;
    letter-spacing: -2px;
}

/* ===== 보드 섹션 ===== */
.board-section {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    gap: 1rem;
}

.board-wrapper {
    position: relative;
    width: 100%;
    max-width: 600px;
    aspect-ratio: 1;
}

.chess-board {
    width: 100%;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
}

/* chessboard.js 커스터마이징 */
.white-1e1d7 {
    background-color: #f0d9b5 !important;
    color: #b58863 !important;
}

.black-3c85d {
    background-color: #b58863 !important;
    color: #f0d9b5 !important;
}

.highlight-square {
    box-shadow: inset 0 0 4px 4px rgba(99, 102, 241, 0.7) !important;
}

.highlight-move {
    box-shadow: inset 0 0 4px 4px rgba(16, 185, 129, 0.7) !important;
}

.highlight-check {
    box-shadow: inset 0 0 6px 6px rgba(239, 68, 68, 0.8) !important;
}

.thinking-overlay {
    position: absolute;
    inset: 0;
    background: rgba(15, 23, 42, 0.7);
    backdrop-filter: blur(4px);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
}

.thinking-spinner {
    text-align: center;
    color: #fff;
}

.thinking-spinner i {
    font-size: 3rem;
    color: var(--accent);
    margin-bottom: 1rem;
}

.thinking-spinner p {
    font-size: 1.1rem;
    font-weight: 600;
}

.game-status {
    width: 100%;
    max-width: 600px;
}

.status-message {
    text-align: center;
    padding: 0.75rem 1.5rem;
    background: rgba(30, 41, 59, 0.7);
    border: 1px solid rgba(99, 102, 241, 0.3);
    border-radius: 12px;
    font-size: 1rem;
    font-weight: 500;
}

.status-message.check {
    background: rgba(239, 68, 68, 0.2);
    border-color: var(--danger);
    color: #fca5a5;
}

.status-message.checkmate {
    background: rgba(251, 191, 36, 0.2);
    border-color: var(--gold);
    color: var(--gold);
}

/* ===== 기보 ===== */
.moves-list {
    max-height: 200px;
    overflow-y: auto;
    background: rgba(51, 65, 85, 0.3);
    border-radius: 8px;
    padding: 0.75rem;
    font-family: 'Courier New', monospace;
    font-size: 0.9rem;
}

.no-moves {
    color: var(--text-muted);
    text-align: center;
    font-style: italic;
}

.move-row {
    display: grid;
    grid-template-columns: 30px 1fr 1fr;
    gap: 0.5rem;
    padding: 0.3rem 0;
    border-bottom: 1px solid rgba(71, 85, 105, 0.3);
}

.move-row:last-child {
    border-bottom: none;
}

.move-num {
    color: var(--text-muted);
    font-weight: 600;
}

.move-white,
.move-black {
    color: var(--text-primary);
    padding: 0.2rem 0.4rem;
    border-radius: 4px;
}

.move-white.last-move,
.move-black.last-move {
    background: rgba(99, 102, 241, 0.3);
}

/* 스크롤바 */
.moves-list::-webkit-scrollbar {
    width: 6px;
}

.moves-list::-webkit-scrollbar-track {
    background: transparent;
}

.moves-list::-webkit-scrollbar-thumb {
    background: rgba(99, 102, 241, 0.5);
    border-radius: 3px;
}

/* ===== 차트 ===== */
.chart-container {
    height: 180px;
    position: relative;
}

/* ===== 모달 ===== */
.modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.modal-content {
    background: linear-gradient(135deg, #1e293b, #0f172a);
    border: 1px solid rgba(99, 102, 241, 0.3);
    border-radius: 24px;
    padding: 2.5rem;
    max-width: 450px;
    width: 90%;
    text-align: center;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
    animation: scaleIn 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes scaleIn {
    from {
        opacity: 0;
        transform: scale(0.8);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

.result-icon {
    font-size: 4rem;
    margin-bottom: 1rem;
}

.result-icon.win {
    color: var(--gold);
    animation: bounce 1s ease;
}

.result-icon.lose {
    color: var(--text-muted);
}

.result-icon.draw {
    color: var(--primary);
}

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

#result-title {
    font-size: 2rem;
    font-family: 'Cinzel', serif;
    margin-bottom: 0.5rem;
}

#result-message {
    color: var(--text-secondary);
    margin-bottom: 1.5rem;
}

.result-stats {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    margin-bottom: 1.5rem;
    padding: 1rem;
    background: rgba(51, 65, 85, 0.3);
    border-radius: 12px;
}

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

.stat-label {
    display: block;
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-bottom: 0.3rem;
}

.stat-value {
    display: block;
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--gold);
}

.modal-buttons {
    display: flex;
    gap: 0.75rem;
}

.modal-btn {
    flex: 1;
    background: rgba(51, 65, 85, 0.5);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 0.8rem 1.2rem;
    border-radius: 10px;
    cursor: pointer;
    font-family: inherit;
    font-size: 0.95rem;
    font-weight: 600;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
}

.modal-btn:hover {
    transform: translateY(-2px);
}

.modal-btn.primary {
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    border-color: transparent;
}

/* 프로모션 모달 */
.promotion-content h2 {
    margin-bottom: 0.5rem;
}

.promotion-content p {
    color: var(--text-secondary);
    margin-bottom: 1.5rem;
}

.promotion-pieces {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 0.75rem;
}

.promotion-btn {
    background: rgba(51, 65, 85, 0.5);
    border: 2px solid var(--border-color);
    border-radius: 12px;
    padding: 1rem 0.5rem;
    cursor: pointer;
    transition: all 0.2s ease;
    color: var(--text-primary);
    font-family: inherit;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.3rem;
}

.big-piece {
    font-size: 2.5rem;
    line-height: 1;
}

.promotion-btn:hover {
    border-color: var(--primary);
    background: rgba(99, 102, 241, 0.2);
    transform: translateY(-2px);
}

.promotion-btn span:last-child {
    font-size: 0.85rem;
}

/* ===== 반응형 ===== */
@media (max-width: 1280px) {
    .main-container {
        grid-template-columns: 280px 1fr 280px;
        gap: 1rem;
    }
}

@media (max-width: 1024px) {
    .main-container {
        grid-template-columns: 1fr;
        max-width: 700px;
    }
    
    .side-panel {
        flex-direction: row;
        flex-wrap: wrap;
    }
    
    .player-card,
    .stats-card,
    .captured-card,
    .moves-card,
    .chart-card {
        flex: 1;
        min-width: 280px;
    }
}

@media (max-width: 768px) {
    .game-header {
        padding: 0.75rem 1rem;
    }
    
    .game-header h1 {
        font-size: 1.1rem;
    }
    
    .header-btn {
        padding: 0.5rem 0.8rem;
        font-size: 0.85rem;
    }
    
    .header-btn span,
    .header-btn .btn-text {
        display: none;
    }
    
    .main-container {
        padding: 1rem;
        gap: 1rem;
    }
    
    .side-panel {
        flex-direction: column;
    }
    
    .start-content {
        padding: 2rem 1.5rem;
    }
    
    .logo h1 {
        font-size: 2rem;
    }
    
    .difficulty-buttons {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .color-buttons {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 480px) {
    .difficulty-buttons {
        grid-template-columns: 1fr 1fr;
    }
    
    .promotion-pieces {
        grid-template-columns: 1fr 1fr;
    }
    
    .modal-content {
        padding: 1.5rem;
    }
    
    #result-title {
        font-size: 1.5rem;
    }
}
