body {
    font-family: Arial, sans-serif;
    display: flex;
    flex-direction: column;
    align-items: center;
    background-color: #f0f0f0;
    margin: 20px;
}

h1 {
    color: #333;
}

#sudoku-grid-container {
    display: grid;
    /* 기존 width, height, grid-template-columns, grid-template-rows를 아래와 같이 변경 */
    grid-template-columns: repeat(9, minmax(0, 1fr)); /* 각 셀이 동일한 비율로 확장/축소 */
    grid-template-rows: repeat(9, minmax(0, 1fr)); /* 각 셀이 동일한 비율로 확장/축소 */

    width: 90vw; /* 뷰포트 너비의 90% */
    max-width: 360px; /* 최대 너비는 360px (원래 크기 유지) */
    /* 높이는 JavaScript에서 동적으로 설정할 수 있도록 제거하거나, aspect-ratio 사용 */
    height: 90vw; /* 너비와 동일한 비율 유지 (정사각형) */
    max-height: 360px; /* 최대 높이도 360px */
    aspect-ratio: 1 / 1; /* 너비 대비 높이 비율을 1:1로 유지하여 항상 정사각형으로 만듦 */

    border: 3px solid #000;
    margin-bottom: 20px;
}

.sudoku-cell {
    /* 각 셀의 width와 height는 부모 그리드에 따라 자동으로 조절되므로 제거 */
    /* width: 40px; */
    /* height: 40px; */
    border: 1px solid #bbb;
    box-sizing: border-box;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 1.2em; /* 폰트 크기는 그대로 유지하거나 vw 단위로 변경 고려 */
    font-weight: bold;
    color: #333;
    position: relative;
}

.sudoku-cell input {
    /* input의 width, height는 100%로 유지하여 부모 셀에 맞게 조절 */
    width: 100%;
    height: 100%;
    text-align: center;
    /* 폰트 크기를 vw 단위로 변경하여 반응형으로 만듦 */
    font-size: clamp(16px, 5.5vw, 24px); /* 뷰포트 너비에 따라 폰트 크기 조절 */
    font-weight: bold;
    border: none;
    box-sizing: border-box;
    background-color: #ffffff00;
    outline: none;
    padding: 0;
    margin: 0;
    color: #333;
}

/* 3x3 블록 구분선 */
.sudoku-cell:nth-child(3n) {
    border-right: 3px solid #000;
}
.sudoku-cell:nth-child(9n) {
    border-right: 1px solid #bbb; /* 9번째 셀은 원래 얇은 선 유지 */
}
.sudoku-cell:nth-child(n + 19):nth-child(-n + 27),
.sudoku-cell:nth-child(n + 46):nth-child(-n + 54) {
    border-bottom: 3px solid #000;
}

/* 초기 고정된 숫자 스타일 */
.fixed-cell {
    background-color: #e0e0e0;
    color: #000;
}
.fixed-cell input {
    background-color: #e0e0e0;
    color: #000;
    cursor: default;
}

/* 잘못된 입력 시 스타일 */
.error {
    background-color: #ffcccc !important; /* 중요도를 높여서 다른 스타일을 덮어씀 */
    color: red !important;
}

/* --- 새로운 스타일 추가 --- */
.game-container {
    /* 이 클래스는 현재 HTML에 없지만, 추후 div로 감쌀 때 사용 가능 */
    background: rgba(255, 255, 255, 0.95);
    border-radius: 20px;
    padding: 30px;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.2);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.3);
    transition: transform 0.3s ease;
}

.game-container:hover {
    transform: translateY(-5px);
}

.controls {
    margin-bottom: 30px;
    text-align: center;
    display: flex;
    flex-direction: column;
    gap: 15px;
    align-items: center;
}

.input-group {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    justify-content: center;
}

.controls label {
    font-weight: 500;
    color: #555;
    font-size: 1.1em;
}

#seedInput {
    padding: 12px 16px;
    border: 2px solid #e0e0e0;
    border-radius: 25px;
    font-size: 1em;
    outline: none;
    transition: all 0.3s ease;
    background: rgba(255, 255, 255, 0.8);
    min-width: 200px;
}

#seedInput:focus {
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
    background: rgba(255, 255, 255, 1);
}

.button-group {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    justify-content: center;
}

.controls button {
    padding: 12px 24px;
    font-size: 1em;
    font-weight: 500;
    cursor: pointer;
    border: none;
    border-radius: 25px;
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-family: "Poppins", sans-serif;
}

#newGameButton {
    background: linear-gradient(45deg, #4caf50, #45a049);
    color: white;
    box-shadow: 0 4px 15px rgba(76, 175, 80, 0.3);
}

#newGameButton:hover {
    background: linear-gradient(45deg, #45a049, #4caf50);
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(76, 175, 80, 0.4);
}

#checkButton {
    background: linear-gradient(45deg, #2196f3, #1976d2);
    color: white;
    box-shadow: 0 4px 15px rgba(33, 150, 243, 0.3);
}

#checkButton:hover {
    background: linear-gradient(45deg, #1976d2, #2196f3);
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(33, 150, 243, 0.4);
}

#resetButton {
    background: linear-gradient(45deg, #ff9800, #f57c00);
    color: white;
    box-shadow: 0 4px 15px rgba(255, 152, 0, 0.3);
}

#resetButton:hover {
    background: linear-gradient(45deg, #f57c00, #ff9800);
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(255, 152, 0, 0.4);
}

#solveButton {
    /* 정답 보기 버튼 스타일 */
    background: linear-gradient(45deg, #f44336, #d32f2f);
    color: white;
    box-shadow: 0 4px 15px rgba(244, 67, 54, 0.3);
}

#solveButton:hover {
    background: linear-gradient(45deg, #d32f2f, #f44336);
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(244, 67, 54, 0.4);
}

.controls button:active {
    transform: translateY(0);
}

#currentSeedDisplay {
    /* 시드 표시 스타일 */
    margin-top: 10px;
    font-size: 1em;
    color: #666;
    font-weight: bold;
}

/* --- 셀 강조 스타일 --- */
.highlight-row input,
.highlight-col input,
.highlight-block input {
    background-color: #86fcb37e; /* 연한 파란색 배경 */
    transition: background-color 0.2s ease;
}

.highlight-selected {
    background-color: #4bc3ff; /* 선택된 셀은 더 진한 파란색 */
}

.sudoku-cell input.highlight-selected {
    background-color: #a7d9f7; /* Lighter blue to indicate selection */
}

/* Base highlight for related cells (new style or modified) */
.sudoku-cell.highlight {
    background-color: #e6f7ff; /* Lighter background for highlighted rows/cols/blocks */
}

/* --- Number Pad Styles --- */
#number-pad {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between; /* Center buttons horizontally */
    align-items: center;
    gap: 10px; /* Space between buttons */
    padding: 15px 0;
    width: 100%;
    box-sizing: border-box; /* Include padding in width */
    z-index: 1000; /* Ensure it's on top of other content */
}

#number-pad button {
    width: clamp(15%, 10px, 100vw);
    padding: 10px 0;
    font-size: 1.5em; /* Larger font size */
    font-weight: bold;
    border: 1px solid #bbb;
    border-radius: 8px; /* Rounded corners */
    background-color: #fff;
    cursor: pointer;
    transition: all 0.2s ease; /* Smooth transitions for hover/active */
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1); /* Subtle button shadow */
}

#number-pad button:hover {
    background-color: #e0e0e0;
    transform: translateY(-1px); /* Slight lift effect on hover */
}

#number-pad button:active {
    background-color: #d0d0d0;
    transform: translateY(0); /* Press-down effect */
    box-shadow: inset 0 2px 5px rgba(0, 0, 0, 0.2); /* Inset shadow when pressed */
}

/* Style for the 'Clear' button */
#number-pad button.clear-button {
    background-color: #f44336; /* Red background */
    color: white; /* White text */
    border-color: #d32f2f;
}
#number-pad button.clear-button:hover {
    background-color: #d32f2f;
}

/* Mobile-only visibility and grid padding */
.mobile-only {
    display: none;
}

#difficulty-select {
    padding: 12px 16px;
    border: 2px solid #e0e0e0;
    border-radius: 25px;
    font-size: 1em;
    outline: none;
    transition: all 0.3s ease;
    background: rgba(255, 255, 255, 0.8);
    min-width: 100%;
}

/* 잘못된 입력 시 스타일 */
.error {
    background-color: #d32f2f !important; /* 연한 빨강 */
}
.error input {
    /* ⭐️ 추가: .error 클래스가 적용된 셀 내부의 input 글자 색상을 변경 */
    color: #ffffff !important; /* 진한 빨강 */
}

@media (max-width: 768px) {
    .mobile-only {
        display: flex; /* Display number pad as flex on mobile */
    }

    /* Hide input caret and prevent text selection on mobile readonly inputs */
    .sudoku-cell input {
        caret-color: transparent;
        user-select: none;
        -webkit-user-select: none;
        -moz-user-select: none;
        -ms-user-select: none;
    }
}
