:root {
    --bg-primary: #0a0a1a;
    --bg-secondary: #12122a;
    --accent-gold: #ffd700;
    --accent-cyan: #00d4ff;
    --accent-purple: #a855f7;
    --accent-pink: #ff6b9d;
    --accent-green: #22c55e;
    --accent-orange: #ff8c00;
    --text-primary: #ffffff;
    --text-secondary: rgba(255,255,255,0.7);

    /* 체스 전용 변수 */
    --board-light: #e8d5b7;
    --board-dark: #b58863;
    --board-light-highlight: #f7ec9e;
    --board-dark-highlight: #d4a839;
    --board-light-move: #aed581;
    --board-dark-move: #7cb342;
    --board-light-capture: #ef9a9a;
    --board-dark-capture: #e57373;
    --board-light-check: #ff8a80;
    --board-dark-check: #ff5252;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
}

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

/* 배경 효과 */
.bg-effects {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 0;
}

.bg-orb {
    position: absolute;
    border-radius: 50%;
    filter: blur(100px);
    opacity: 0.3;
}

.bg-orb:nth-child(1) {
    width: 400px;
    height: 400px;
    background: var(--accent-purple);
    top: -150px;
    right: -100px;
}

.bg-orb:nth-child(2) {
    width: 300px;
    height: 300px;
    background: var(--accent-cyan);
    bottom: -100px;
    left: -100px;
}

.container {
    position: relative;
    z-index: 10;
    max-width: 500px;
    margin: 0 auto;
    padding: 20px;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* 헤더 */
header {
    text-align: center;
    margin-bottom: 15px;
}

.header-top {
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    margin-bottom: 5px;
}

.back-btn {
    position: absolute;
    left: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 0.9rem;
    transition: color 0.3s;
    min-width: 44px;
    min-height: 44px;
    padding: 8px;
    margin-left: -8px;
    border-radius: 8px;
}

.back-btn:hover {
    color: var(--accent-cyan);
    background: rgba(255, 255, 255, 0.1);
}

.back-btn:active {
    background: rgba(255, 255, 255, 0.15);
}

.back-btn svg {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
}

h1 {
    font-family: 'Black Han Sans', sans-serif;
    font-size: 2.5rem;
    background: linear-gradient(135deg, var(--accent-gold), var(--accent-orange));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.subtitle {
    color: var(--text-secondary);
    font-size: 0.9rem;
    margin-top: 5px;
}

/* 게임 컨테이너 */
.game-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
}

/* 컨트롤 버튼 */
.controls {
    display: flex;
    justify-content: center;
    gap: 10px;
    width: 100%;
    margin-bottom: 10px;
}

.btn {
    font-family: 'Jua', sans-serif;
    font-size: 0.9rem;
    padding: 10px 20px;
    border: none;
    border-radius: 20px;
    cursor: pointer;
    transition: all 0.2s;
    min-height: 44px;
    background: rgba(255,255,255,0.1);
    color: var(--text-primary);
    border: 1px solid rgba(255,255,255,0.2);
}

.btn:hover {
    background: rgba(255,255,255,0.2);
    transform: scale(1.02);
}

.btn-new {
    background: linear-gradient(135deg, var(--accent-purple), #7c3aed);
    border: none;
    color: white;
}

.btn-new:hover {
    box-shadow: 0 5px 20px rgba(168, 85, 247, 0.4);
}

/* 플레이어 정보 */
.player-info {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    padding: 12px 16px;
    background: var(--bg-secondary);
    border-radius: 12px;
    border: 1px solid rgba(255,255,255,0.1);
}

/* 흑 플레이어 영역 - 검정색 배경 */
.player-info.black-side {
    background: linear-gradient(135deg, #1a1a1a, #2d2d2d);
    border: 1px solid rgba(255,255,255,0.15);
}

.player {
    display: flex;
    align-items: center;
    gap: 10px;
}

.player-icon {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.4rem;
    border: 2px solid transparent;
    transition: all 0.3s ease;
}

.player-icon.white {
    background: linear-gradient(135deg, #fff, #ddd);
    color: #333;
}

.player-icon.black {
    background: linear-gradient(135deg, #333, #111);
    color: #fff;
}

.player.active .player-icon {
    border-color: var(--accent-gold);
    box-shadow: 0 0 15px rgba(255, 215, 0, 0.4);
}

.player-details {
    display: flex;
    flex-direction: column;
}

.player-name {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-primary);
}

.player-status {
    font-size: 0.7rem;
    color: var(--text-secondary);
}

.player.active .player-status {
    color: var(--accent-gold);
}

.captured-pieces {
    display: flex;
    gap: 2px;
    font-size: 0.9rem;
    min-height: 20px;
    flex-wrap: wrap;
    max-width: 120px;
}

/* 체스보드 */
.board-wrapper {
    position: relative;
    padding: 8px;
    background: var(--bg-secondary);
    border-radius: 12px;
    border: 1px solid rgba(255,255,255,0.1);
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.4);
}

.board-container {
    position: relative;
}

.board {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    border-radius: 6px;
    overflow: hidden;
    width: calc(min(100vw - 56px, 352px));
    aspect-ratio: 1;
}

.cell {
    aspect-ratio: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2rem;
    cursor: pointer;
    position: relative;
    transition: background-color 0.15s ease;
    overflow: hidden;
    min-width: 0;
}

.cell.light { background: var(--board-light); }
.cell.dark { background: var(--board-dark); }

.cell.selected.light { background: var(--board-light-highlight); }
.cell.selected.dark { background: var(--board-dark-highlight); }

.cell.valid-move.light { background: var(--board-light-move); }
.cell.valid-move.dark { background: var(--board-dark-move); }

.cell.capture-move.light { background: var(--board-light-capture); }
.cell.capture-move.dark { background: var(--board-dark-capture); }

.cell.check.light { background: var(--board-light-check); }
.cell.check.dark { background: var(--board-dark-check); }

.cell.last-move::after {
    content: '';
    position: absolute;
    top: 2px;
    right: 2px;
    width: 8px;
    height: 8px;
    background: var(--accent-purple);
    border-radius: 50%;
    opacity: 0.7;
}

.cell .move-dot {
    position: absolute;
    width: 14px;
    height: 14px;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 50%;
}

.piece {
    font-size: 2.2rem;
    cursor: grab;
    transition: transform 0.1s ease;
    filter: drop-shadow(1px 2px 2px rgba(0, 0, 0, 0.3));
}

.piece:hover {
    transform: scale(1.1);
}

.piece.dragging {
    cursor: grabbing;
    transform: scale(1.2);
    opacity: 0.9;
}

.piece.white-piece {
    color: #fff;
    text-shadow:
        -1px -1px 0 #333,
        1px -1px 0 #333,
        -1px 1px 0 #333,
        1px 1px 0 #333,
        0 2px 4px rgba(0, 0, 0, 0.3);
}

.piece.black-piece {
    color: #1a1a1a;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.4);
}

/* 좌표 */
.coordinates {
    position: absolute;
    font-size: 0.55rem;
    font-weight: 600;
    opacity: 0.7;
}

.coord-file {
    bottom: 2px;
    right: 4px;
}

.coord-rank {
    top: 2px;
    left: 4px;
}

.cell.light .coordinates { color: var(--board-dark); }
.cell.dark .coordinates { color: var(--board-light); }

/* 상태바 */
.status-bar {
    width: 100%;
    padding: 10px 16px;
    background: var(--bg-secondary);
    border-radius: 10px;
    border: 1px solid rgba(255,255,255,0.1);
    text-align: center;
}

.status-text {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-primary);
}

.status-text.check {
    color: var(--accent-pink);
}

.status-text.thinking {
    color: var(--accent-cyan);
    animation: pulse 1s infinite;
}

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

/* 기보 */
.move-history {
    width: 100%;
    max-height: 80px;
    overflow-y: auto;
    padding: 8px 12px;
    background: var(--bg-secondary);
    border-radius: 10px;
    border: 1px solid rgba(255,255,255,0.1);
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.move-history::-webkit-scrollbar {
    width: 4px;
}

.move-history::-webkit-scrollbar-track {
    background: transparent;
}

.move-history::-webkit-scrollbar-thumb {
    background: rgba(255,255,255,0.2);
    border-radius: 2px;
}

.moves-list {
    display: flex;
    flex-wrap: wrap;
    gap: 4px 12px;
}

.move-pair {
    display: flex;
    gap: 6px;
}

.move-number {
    color: var(--text-secondary);
    opacity: 0.6;
}

.move {
    color: var(--text-primary);
}

/* 게임오버 모달 */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.85);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
    backdrop-filter: blur(8px);
}

.modal-overlay.active {
    opacity: 1;
    visibility: visible;
}

.modal-content {
    text-align: center;
    padding: 40px;
    background: var(--bg-secondary);
    border-radius: 24px;
    border: 1px solid rgba(255,255,255,0.1);
    box-shadow: 0 30px 60px rgba(0, 0, 0, 0.5);
    transform: scale(0.9);
    transition: transform 0.3s ease;
}

.modal-overlay.active .modal-content {
    transform: scale(1);
}

.modal-icon {
    font-size: 4rem;
    margin-bottom: 16px;
}

.modal-title {
    font-family: 'Black Han Sans', sans-serif;
    font-size: 1.8rem;
    color: var(--text-primary);
    margin-bottom: 8px;
}

.modal-subtitle {
    font-size: 1rem;
    color: var(--text-secondary);
    margin-bottom: 24px;
}

.modal-btn {
    font-family: 'Jua', sans-serif;
    padding: 14px 40px;
    font-size: 1rem;
    font-weight: 600;
    color: white;
    background: linear-gradient(135deg, var(--accent-purple), #7c3aed);
    border: none;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 4px 15px rgba(168, 85, 247, 0.4);
}

.modal-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(168, 85, 247, 0.5);
}

/* 프로모션 모달 */
.promotion-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    opacity: 0;
    visibility: hidden;
    transition: all 0.2s ease;
}

.promotion-modal.active {
    opacity: 1;
    visibility: visible;
}

.promotion-choices {
    display: flex;
    gap: 12px;
    padding: 20px;
    background: var(--bg-secondary);
    border-radius: 16px;
    border: 1px solid rgba(255,255,255,0.1);
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.4);
}

.promotion-choice {
    width: 60px;
    height: 60px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2.5rem;
    background: var(--board-light);
    border: 3px solid transparent;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.promotion-choice:hover {
    border-color: var(--accent-purple);
    transform: scale(1.1);
}

/* 시작 오버레이 */
.overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.9);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 200;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
    backdrop-filter: blur(10px);
}

.overlay.show {
    opacity: 1;
    visibility: visible;
}

.overlay-content {
    text-align: center;
    padding: 40px 30px;
    background: var(--bg-secondary);
    border-radius: 24px;
    border: 1px solid rgba(255,255,255,0.1);
    box-shadow: 0 30px 60px rgba(0, 0, 0, 0.5);
    max-width: 90%;
    width: 340px;
}

.overlay-content h2 {
    font-family: 'Black Han Sans', sans-serif;
    font-size: 2rem;
    background: linear-gradient(135deg, var(--accent-gold), var(--accent-orange));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 24px;
}

/* 모드 선택 */
.mode-label,
.difficulty-label {
    font-size: 0.95rem;
    color: var(--text-secondary);
    margin-bottom: 16px;
}

.mode-buttons,
.difficulty-buttons {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.mode-btn,
.difficulty-btn {
    font-family: 'Jua', sans-serif;
    font-size: 1.1rem;
    padding: 16px 24px;
    border: none;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.2s ease;
    min-height: 56px;
}

.mode-btn {
    background: linear-gradient(135deg, var(--accent-purple), #7c3aed);
    color: white;
}

.mode-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(168, 85, 247, 0.4);
}

.mode-btn[data-mode="pvp"] {
    background: linear-gradient(135deg, var(--accent-cyan), #0891b2);
}

.mode-btn[data-mode="pvp"]:hover {
    box-shadow: 0 8px 25px rgba(0, 212, 255, 0.4);
}

/* Resume Overlay */
.resume-content {
    text-align: center;
}

.resume-content .saved-info {
    color: var(--text-secondary);
    margin-bottom: 24px;
    font-size: 0.95rem;
}

.resume-buttons {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.btn-resume {
    background: linear-gradient(135deg, var(--accent-cyan), #0891b2);
    color: white;
    font-family: 'Jua', sans-serif;
    font-size: 1.1rem;
    padding: 16px 24px;
    border: none;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.2s ease;
    min-height: 56px;
}

.btn-resume:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(0, 212, 255, 0.4);
}

.btn-new-game {
    background: rgba(255,255,255,0.1);
    color: var(--text-primary);
    border: 1px solid rgba(255,255,255,0.2);
    font-family: 'Jua', sans-serif;
    font-size: 1rem;
    padding: 14px 24px;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn-new-game:hover {
    background: rgba(255,255,255,0.15);
}

/* 난이도 선택 섹션 */
.difficulty-section {
    margin-top: 24px;
    padding-top: 24px;
    border-top: 1px solid rgba(255,255,255,0.1);
}

.difficulty-section.hidden {
    display: none;
}

.difficulty-btn {
    background: rgba(255,255,255,0.1);
    color: var(--text-primary);
    border: 1px solid rgba(255,255,255,0.2);
}

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

.difficulty-btn[data-difficulty="easy"] {
    border-color: var(--accent-green);
    color: var(--accent-green);
}

.difficulty-btn[data-difficulty="easy"]:hover {
    background: rgba(34, 197, 94, 0.2);
    box-shadow: 0 8px 25px rgba(34, 197, 94, 0.3);
}

.difficulty-btn[data-difficulty="normal"] {
    border-color: var(--accent-gold);
    color: var(--accent-gold);
}

.difficulty-btn[data-difficulty="normal"]:hover {
    background: rgba(255, 215, 0, 0.2);
    box-shadow: 0 8px 25px rgba(255, 215, 0, 0.3);
}

.difficulty-btn[data-difficulty="hard"] {
    border-color: var(--accent-pink);
    color: var(--accent-pink);
}

.difficulty-btn[data-difficulty="hard"]:hover {
    background: rgba(255, 107, 157, 0.2);
    box-shadow: 0 8px 25px rgba(255, 107, 157, 0.3);
}

/* 난이도 배지 */
.difficulty-badge {
    display: inline-block;
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.difficulty-badge.easy {
    background: rgba(34, 197, 94, 0.2);
    color: var(--accent-green);
}

.difficulty-badge.normal {
    background: rgba(255, 215, 0, 0.2);
    color: var(--accent-gold);
}

.difficulty-badge.hard {
    background: rgba(255, 107, 157, 0.2);
    color: var(--accent-pink);
}

.difficulty-badge.pvp {
    background: rgba(0, 212, 255, 0.2);
    color: var(--accent-cyan);
}

/* 게임 설명 */
.game-content {
    margin-top: 20px;
    padding: 20px;
    background: var(--bg-secondary);
    border-radius: 16px;
    border: 1px solid rgba(255,255,255,0.1);
}

.game-content h2 {
    font-family: 'Black Han Sans', sans-serif;
    font-size: 1.3rem;
    color: var(--accent-gold);
    margin-bottom: 10px;
}

.game-content p {
    color: var(--text-secondary);
    font-size: 0.9rem;
    line-height: 1.6;
    margin-bottom: 15px;
}

.tip-box {
    background: rgba(255,255,255,0.05);
    border-radius: 10px;
    padding: 15px;
}

.tip-box p {
    margin-bottom: 8px;
}

.tip-box p:last-child {
    margin-bottom: 0;
}

/* 푸터 */
footer {
    text-align: center;
    padding: 20px;
    color: var(--text-secondary);
    font-size: 0.8rem;
}

footer a {
    color: var(--text-secondary);
    text-decoration: none;
}

footer a:hover {
    color: var(--accent-cyan);
}

/* 모바일 대응 */
@media (max-width: 600px) {
    .container {
        padding: 15px;
    }

    h1 {
        font-size: 2rem;
    }

    .board {
        width: calc(100vw - 30px);
    }

    .piece {
        font-size: 1.8rem;
    }

    .player-info {
        padding: 10px 12px;
    }

    .captured-pieces {
        max-width: 90px;
        font-size: 0.8rem;
    }

    .game-content {
        display: none;
    }

    footer {
        display: none;
    }
}

@media (max-width: 400px) {
    .piece {
        font-size: 1.6rem;
    }

    .cell .move-dot {
        width: 10px;
        height: 10px;
    }

    .player-name {
        font-size: 0.8rem;
    }

    .player-icon {
        width: 30px;
        height: 30px;
        font-size: 1.2rem;
    }
}

@media (max-height: 700px) {
    .game-container {
        gap: 8px;
    }

    .move-history {
        max-height: 60px;
    }

    .game-content {
        display: none;
    }
}
