/* ===== CSS 변수 및 기본 설정 ===== */
:root {
    /* 색상 */
    --primary-color: #4a6cf7;
    --primary-hover: #3b5ce5;
    --primary-light: #eef2ff;
    --secondary-color: #6c757d;
    --success-color: #28a745;
    --danger-color: #dc3545;
    --warning-color: #ffc107;

    /* 배경색 */
    --bg-primary: #f8f9fa;
    --bg-secondary: #ffffff;
    --bg-dark: #1a1a2e;

    /* 텍스트 색상 */
    --text-primary: #212529;
    --text-secondary: #6c757d;
    --text-muted: #adb5bd;

    /* 보드 색상 */
    --board-bg: #ffffff;
    --board-border: #333333;
    --cell-border: #cccccc;
    --cell-selected: #bbdefb;
    --cell-highlight: #e3f2fd;
    --cell-same-number: #fff9c4;
    --cell-error: #ffcdd2;
    --cell-fixed: #f5f5f5;
    --cell-odd: #fff3e0;
    --cell-even: #e8f5e9;

    /* 그림자 */
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.1);
    --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 25px rgba(0, 0, 0, 0.15);

    /* 애니메이션 */
    --transition-fast: 0.15s ease;
    --transition-normal: 0.3s ease;

    /* 보드 크기 */
    --cell-size: 50px;
    --cell-size-mobile: 42px;

    /* 폰트 */
    --font-family: 'Noto Sans KR', -apple-system, BlinkMacSystemFont, sans-serif;
}

/* ===== 리셋 및 기본 스타일 ===== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: var(--font-family);
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    line-height: 1.6;
}

/* ===== 헤더 ===== */
.header {
    background: var(--bg-secondary);
    box-shadow: var(--shadow-sm);
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-content {
    max-width: 1200px;
    margin: 0 auto;
    padding: 1rem 1.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.logo {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.logo-icon {
    font-size: 1.5rem;
}

.logo-text {
    font-size: 1.5rem;
    font-weight: 700;
    background: linear-gradient(135deg, var(--primary-color), #667eea);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.auth-buttons {
    display: flex;
    gap: 0.75rem;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.username {
    font-weight: 500;
    color: var(--text-primary);
}

/* ===== 버튼 ===== */
.btn {
    padding: 0.625rem 1.25rem;
    border-radius: 8px;
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition-fast);
    border: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

.btn-primary {
    background: var(--primary-color);
    color: white;
}

.btn-primary:hover {
    background: var(--primary-hover);
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.btn-outline {
    background: transparent;
    border: 1.5px solid var(--primary-color);
    color: var(--primary-color);
}

.btn-outline:hover {
    background: var(--primary-light);
}

.btn-large {
    padding: 1rem 2rem;
    font-size: 1.1rem;
}

.btn-full {
    width: 100%;
}

.btn-icon {
    font-size: 1.2rem;
}

/* ===== 메인 컨텐츠 ===== */
.main-content {
    max-width: 900px;
    margin: 0 auto;
    padding: 2rem 1rem;
}

/* ===== 설정 패널 ===== */
.settings-panel {
    background: var(--bg-secondary);
    border-radius: 16px;
    padding: 2rem;
    box-shadow: var(--shadow-md);
    display: flex;
    flex-direction: column;
    align-items: center;
}

.section-title {
    font-size: 1.5rem;
    font-weight: 600;
    margin-bottom: 1.5rem;
    text-align: center;
    color: var(--text-primary);
}

.settings-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 2rem;
    margin-bottom: 2rem;
}

.setting-group {
    background: var(--bg-primary);
    border-radius: 12px;
    padding: 1.25rem;
}

.setting-label {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 1rem;
    color: var(--text-primary);
}

/* 라디오 버튼 그룹 */
.radio-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.radio-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.75rem;
    border-radius: 8px;
    cursor: pointer;
    transition: background var(--transition-fast);
    position: relative;
}

.radio-item:hover {
    background: var(--bg-secondary);
}

.radio-item input {
    display: none;
}

.radio-custom {
    width: 20px;
    height: 20px;
    border: 2px solid var(--secondary-color);
    border-radius: 50%;
    position: relative;
    transition: all var(--transition-fast);
    flex-shrink: 0;
}

.radio-item input:checked+.radio-custom {
    border-color: var(--primary-color);
}

.radio-item input:checked+.radio-custom::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 10px;
    height: 10px;
    background: var(--primary-color);
    border-radius: 50%;
}

.radio-label {
    font-weight: 500;
    color: var(--text-primary);
}

.radio-desc {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-left: auto;
}

/* ===== 게임 영역 ===== */
.game-area {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.5rem;
}

/* 게임 정보 바 */
.game-info-bar {
    display: flex;
    justify-content: center;
    gap: 2rem;
    background: var(--bg-secondary);
    padding: 1rem 2rem;
    border-radius: 12px;
    box-shadow: var(--shadow-sm);
    flex-wrap: nowrap;
    overflow-x: auto;
}

.info-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.info-icon {
    font-size: 1.25rem;
}

.info-label {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.info-value {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-primary);
    font-variant-numeric: tabular-nums;
}

.mode-badge {
    background: var(--primary-light);
    padding: 0.5rem 1rem;
    border-radius: 20px;
}

.mode-text {
    font-weight: 600;
    color: var(--primary-color);
}

.difficulty-badge {
    background: #e8f5e9;
    padding: 0.5rem 1rem;
    border-radius: 20px;
}

.difficulty-text {
    font-weight: 600;
    color: #2e7d32;
}

/* ===== 스도쿠 보드 ===== */
.board-container {
    background: var(--bg-secondary);
    padding: 1rem;
    border-radius: 16px;
    box-shadow: var(--shadow-lg);
}

.sudoku-board {
    display: grid;
    grid-template-columns: repeat(9, var(--cell-size));
    grid-template-rows: repeat(9, var(--cell-size));
    border: 3px solid var(--board-border);
    background: var(--board-bg);
}

.cell {
    width: var(--cell-size);
    height: var(--cell-size);
    border: 1px solid var(--cell-border);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    font-weight: 500;
    cursor: pointer;
    transition: background var(--transition-fast);
    position: relative;
    user-select: none;
}

/* 3x3 박스 구분선 */
.cell:nth-child(3n) {
    border-right: 2px solid var(--board-border);
}

.cell:nth-child(n+19):nth-child(-n+27),
.cell:nth-child(n+46):nth-child(-n+54) {
    border-bottom: 2px solid var(--board-border);
}

/* 셀 상태 */
.cell.fixed {
    background: var(--cell-fixed);
    font-weight: 600;
}

.cell.selected {
    background: var(--cell-selected) !important;
}

.cell.highlighted {
    background: var(--cell-highlight);
}

/* 홀짝 모드 셀 - 주황색으로 통일 */
.cell.odd-cell,
.cell.even-cell {
    background: #ffe0b2;
    /* 주황색 계열 (Orange 100) */
}

.cell.same-number {
    background: var(--cell-same-number);
}

/* 대각선 모드 - 보드 전체에 X 점선 표시 */
.sudoku-board.diagonal-mode {
    position: relative;
}

.sudoku-board.diagonal-mode::before,
.sudoku-board.diagonal-mode::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 141.4%;
    height: 0;
    border-top: 3px dotted rgba(139, 92, 246, 0.7);
    transform-origin: top left;
    pointer-events: none;
    z-index: 10;
}

.sudoku-board.diagonal-mode::before {
    transform: rotate(45deg);
}

.sudoku-board.diagonal-mode::after {
    left: auto;
    right: 0;
    transform-origin: top right;
    transform: rotate(-45deg);
}

/* 메모 표시 */
.cell .notes {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(3, 1fr);
    width: calc(100% - 14px);
    height: calc(100% - 14px);
    padding: 0;
    margin: 7px;
    gap: 0;
}

.cell .notes span {
    font-size: 0.5rem;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

/* 킬러 모드 케이지 - 내부 점선 테두리 */
.cell .cage-border {
    position: absolute;
    top: 2px;
    left: 2px;
    right: 2px;
    bottom: 2px;
    pointer-events: none;
}

.cell .cage-border.cage-top {
    border-top: 1.5px dashed #9c27b0;
}

.cell .cage-border.cage-bottom {
    border-bottom: 1.5px dashed #9c27b0;
}

.cell .cage-border.cage-left {
    border-left: 1.5px dashed #9c27b0;
}

.cell .cage-border.cage-right {
    border-right: 1.5px dashed #9c27b0;
}

.cell .cage-sum {
    position: absolute;
    top: 0;
    left: 0;
    font-size: 0.55rem;
    font-weight: 600;
    color: #9c27b0;
    line-height: 1;
    z-index: 2;
    background: white;
    padding: 0 2px;
}

/* 대각선 모드 표시 */
.cell.diagonal {
    background: linear-gradient(135deg, rgba(74, 108, 247, 0.05) 0%, transparent 100%);
}

/* 애니메이션 */
@keyframes shake {

    0%,
    100% {
        transform: translateX(0);
    }

    25% {
        transform: translateX(-5px);
    }

    75% {
        transform: translateX(5px);
    }
}

@keyframes pop {
    0% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.2);
    }

    100% {
        transform: scale(1);
    }
}

.cell.correct {
    animation: pop 0.3s ease;
    background-color: #dcedc8;
    /* Success color light */
}

.cell.error {
    animation: shake 0.5s ease;
    background-color: var(--cell-error);
}

.cell.wrong-input {
    color: var(--danger-color);
    background-color: #ffebee;
}

/* ===== 숫자 입력 패드 ===== */
.number-pad {
    background: var(--bg-secondary);
    padding: 1.25rem;
    border-radius: 12px;
    box-shadow: var(--shadow-sm);
}

.number-buttons {
    display: flex;
    gap: 0.25rem;
    margin-bottom: 1rem;
    flex-wrap: nowrap;
    justify-content: center;
}

.num-btn {
    width: 36px;
    height: 44px;
    border: none;
    border-radius: 8px;
    background: var(--bg-primary);
    font-size: 1.1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition-fast);
    color: var(--text-primary);
    flex-shrink: 0;
}

.num-btn:hover {
    background: var(--primary-light);
    color: var(--primary-color);
    transform: translateY(-2px);
}

.num-btn.disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.action-buttons {
    display: flex;
    gap: 0.75rem;
    justify-content: center;
}

.action-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.25rem;
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: 10px;
    background: var(--bg-primary);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.action-btn:hover {
    background: var(--primary-light);
}

.action-btn.active {
    background: var(--primary-color);
    color: white;
}

.action-icon {
    font-size: 1.25rem;
}

.action-label {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.action-btn.active .action-label {
    color: white;
}

/* ===== 게임 액션 버튼 ===== */
.game-actions {
    display: flex;
    gap: 1rem;
}

/* ===== 모달 ===== */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1000;
    align-items: center;
    justify-content: center;
}

.modal.active {
    display: flex;
}

.modal-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
}

.modal-content {
    position: relative;
    background: var(--bg-secondary);
    padding: 2rem;
    border-radius: 16px;
    max-width: 400px;
    width: 90%;
    box-shadow: var(--shadow-lg);
    animation: modalIn 0.3s ease;
}

@keyframes modalIn {
    from {
        opacity: 0;
        transform: translateY(-20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.modal-close {
    position: absolute;
    top: 1rem;
    right: 1rem;
    width: 32px;
    height: 32px;
    border: none;
    background: var(--bg-primary);
    border-radius: 50%;
    font-size: 1.25rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background var(--transition-fast);
}

.modal-close:hover {
    background: var(--cell-error);
}

.modal-title {
    font-size: 1.5rem;
    font-weight: 600;
    margin-bottom: 1.5rem;
    text-align: center;
}

.modal-buttons {
    display: flex;
    gap: 1rem;
    justify-content: center;
    margin-top: 1.5rem;
}

.modal-buttons .btn {
    min-width: 100px;
}

/* 폼 스타일 */
.form-group {
    margin-bottom: 1rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
    color: var(--text-primary);
}

.form-group input {
    width: 100%;
    padding: 0.75rem 1rem;
    border: 1.5px solid #dee2e6;
    border-radius: 8px;
    font-size: 1rem;
    transition: border-color var(--transition-fast);
}

.form-group input:focus {
    outline: none;
    border-color: var(--primary-color);
}

.form-error {
    color: var(--danger-color);
    font-size: 0.875rem;
    margin-bottom: 1rem;
    min-height: 1.25rem;
}


/* ===== 저장된 게임 목록 ===== */
.saved-games-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    max-height: 400px;
    overflow-y: auto;
    padding-right: 5px;
}

.saved-game-item {
    background: var(--bg-primary);
    padding: 1rem;
    border-radius: 12px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border: 1px solid var(--cell-border);
    transition: all var(--transition-fast);
}

.saved-game-item:hover {
    border-color: var(--primary-color);
    box-shadow: var(--shadow-sm);
}

.saved-game-info h4 {
    margin: 0 0 0.25rem 0;
    font-size: 1rem;
    color: var(--text-primary);
}

.saved-game-meta {
    font-size: 0.8rem;
    color: var(--text-secondary);
    display: flex;
    gap: 0.75rem;
}

.saved-game-actions {
    display: flex;
    gap: 0.5rem;
}

.empty-message {
    text-align: center;
    padding: 2rem;
    color: var(--text-muted);
}

/* ===== 통계 탭 및 테이블 ===== */
.stats-tabs {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1rem;
    border-bottom: 2px solid var(--bg-primary);
    padding-bottom: 0.5rem;
    overflow-x: auto;
}

.stats-tab {
    padding: 0.5rem 1rem;
    border: none;
    background: transparent;
    font-weight: 600;
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: 8px;
    transition: all var(--transition-fast);
    white-space: nowrap;
}

.stats-tab:hover {
    background: var(--bg-primary);
    color: var(--primary-color);
}

.stats-tab.active {
    background: var(--primary-light);
    color: var(--primary-color);
}

.stats-table-container {
    overflow-x: auto;
    margin-bottom: 1.5rem;
}

.stats-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}

.stats-table th,
.stats-table td {
    padding: 0.75rem;
    text-align: center;
    border-bottom: 1px solid var(--bg-primary);
}

.stats-table th {
    font-weight: 600;
    color: var(--text-secondary);
    background: var(--bg-primary);
}

.stats-table td {
    color: var(--text-primary);
}

.stats-total-summary {
    background: var(--bg-primary);
    padding: 1rem;
    border-radius: 12px;
    display: flex;
    justify-content: center;
}

/* ===== 통계 모달 ===== */
.stats-content {
    max-width: 600px;
    max-height: 80vh;
    overflow-y: auto;
}

.stats-section {
    margin-bottom: 1.5rem;
}

.stats-section h3 {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 0.75rem;
    border-bottom: 1px solid #eee;
    padding-bottom: 0.5rem;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.75rem;
}

.stats-item {
    display: flex;
    justify-content: space-between;
    padding: 0.5rem 0.75rem;
    background: var(--bg-primary);
    border-radius: 8px;
}

.stats-label {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.stats-value {
    font-weight: 600;
    color: var(--primary-color);
}

/* 일시정지 모달 */
.pause-content {
    text-align: center;
}

.pause-content p {
    color: var(--text-secondary);
    margin-bottom: 1.5rem;
}

/* ===== 컨페티 ===== */
#confettiCanvas {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 2000;
}

/* ===== 반응형 디자인 ===== */
@media (max-width: 768px) {
    .header-content {
        padding: 0.75rem 1rem;
    }

    .logo-text {
        font-size: 1.25rem;
    }

    .settings-grid {
        grid-template-columns: 1fr;
        gap: 1rem;
    }

    .settings-panel {
        padding: 1.5rem;
    }

    .sudoku-board {
        grid-template-columns: repeat(9, var(--cell-size-mobile));
        grid-template-rows: repeat(9, var(--cell-size-mobile));
    }

    .cell {
        width: var(--cell-size-mobile);
        height: var(--cell-size-mobile);
        font-size: 1.2rem;
    }

    .cell .notes span {
        font-size: 0.5rem;
    }

    .cell .cage-sum {
        font-size: 0.5rem;
    }

    .game-info-bar {
        gap: 0.75rem;
        padding: 0.75rem 1rem;
    }

    .info-label {
        display: none;
    }

    .mode-badge,
    .difficulty-badge {
        padding: 0.4rem 0.6rem;
        font-size: 0.8rem;
    }

    .info-value {
        font-size: 1rem;
    }

    .info-icon {
        font-size: 1.2rem;
    }

    .num-btn {
        width: 40px;
        height: 40px;
        font-size: 1.1rem;
    }

    .action-btn {
        padding: 0.5rem 1rem;
    }

    .board-container {
        padding: 0.5rem;
    }
}

@media (max-width: 400px) {
    :root {
        --cell-size-mobile: 34px;
    }

    .settings-panel {
        text-align: center;
    }

    .number-buttons {
        gap: 0.2rem;
    }

    .num-btn {
        width: 32px;
        height: 38px;
        font-size: 1rem;
    }
}

/* ===== 유틸리티 ===== */
.text-center {
    text-align: center;
}

.mb-1 {
    margin-bottom: 0.5rem;
}

.mb-2 {
    margin-bottom: 1rem;
}

.mb-3 {
    margin-bottom: 1.5rem;
}

/* 로딩 스피너 */
.loading-spinner {
    width: 50px;
    height: 50px;
    border: 5px solid var(--bg-primary);
    border-top: 5px solid var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto;
}

@keyframes spin {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}

/* ===== 게임 완료 모달 스타일 ===== */
.complete-content {
    text-align: center;
    padding: 2.5rem 2rem;
    max-width: 450px !important;
    /* 넓이 약간 확보 */
}

.complete-icon {
    font-size: 4rem;
    margin-bottom: 1rem;
    animation: bounce 1s infinite alternate;
}

.complete-title {
    margin-bottom: 0.5rem;
    font-size: 1.8rem;
    color: var(--primary-color);
}

.complete-message {
    color: var(--text-secondary);
    margin-bottom: 2rem;
}

.complete-stats {
    background-color: var(--bg-primary);
    border-radius: 12px;
    padding: 1.5rem;
    margin-bottom: 2rem;
    display: grid;
    gap: 1rem;
}

.stat-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem 0;
    border-bottom: 1px solid rgba(0, 0, 0, 0.05);
}

.stat-item:last-child {
    border-bottom: none;
}

.stat-label {
    color: var(--text-secondary);
    font-size: 0.95rem;
}

.stat-value {
    font-weight: 600;
    font-size: 1.1rem;
    color: var(--text-primary);
}

/* 소요 시간 강조 */
#completeTime {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--primary-color);
}

/* 바운스 애니메이션 */
@keyframes bounce {
    from {
        transform: translateY(0);
    }

    to {
        transform: translateY(-10px);
    }
}