* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Arial', sans-serif;
    background-color: #f5f5f5;
    color: #333;
    line-height: 1.6;
}

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

h1 {
    text-align: center;
    margin-bottom: 30px;
    color: #2c3e50;
    font-size: 2.5em;
}

.input-guide {
    text-align: center;
    margin-top: -20px; /* h1과의 간격 조정 */
    margin-bottom: 20px;
    font-size: 0.9em;
    color: #555;
}

.main-content {
    display: flex;
    flex-direction: row;
    justify-content: center;
    align-items: flex-start;
    gap: 20px;
    margin-bottom: 30px;
}

.puzzle-container {
    display: flex;
    justify-content: center;
    overflow-x: auto;
    min-width: auto; /* 변경: 내부 wrapper가 min-width를 가짐 */
}

.puzzle-wrapper {
    min-width: 600px;
    display: flex;
    justify-content: flex-start;
    border: 3px solid #CCC;
}

.hint-area {
    width: 300px; /* 데스크톱 힌트 영역 너비 */
    padding: 15px;
    border: 1px solid #ddd;
    border-radius: 8px;
    background-color: #f9f9f9;
    /* display: none; /* 기본 숨김은 미디어쿼리에서 제어 */
    /* margin-bottom: 20px; /* 아래 요소와의 간격, 모바일에서만 필요시 조정 */
}

.hint-area h4 {
    margin-top: 0;
    margin-bottom: 10px;
    color: #2c3e50;
    border-bottom: 1px solid #eee;
    padding-bottom: 5px;
}

#current-clues-display .clue-item {
    margin-bottom: 8px;
    padding: 6px;
    background-color: #fff;
    border: 1px solid #eee;
    border-radius: 4px;
    font-size: 0.9em;
}

#current-clues-display .clue-item .clue-number {
    font-weight: bold;
    color: #3498db;
    margin-right: 5px;
}

.crossword-grid {
    border-collapse: collapse;
    background-color: white;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    border-radius: 8px;
    overflow: hidden;
}

.crossword-grid td {
    width: 30px;
    height: 28px;
    border: 1px solid #ddd;
    text-align: center;
    vertical-align: middle;
    position: relative;
    font-size: 24px;
    font-weight: bold;
    line-height: 1;
}

.crossword-grid td.black {
    background-color: #333;
    border-color: #333;
}

.crossword-grid td.white {
    background-color: #fff;
    border: 1px solid #ccc; /* 셀 테두리 */
    position: relative; /* 자식 요소를 absolute positioning 하기 위함 */
}

.crossword-grid td.white:hover {
    background-color: #e8f4fd;
}

.crossword-grid td.active {
    background-color: #3498db !important;
    color: white;
}

.crossword-grid input {
    width: 100%;
    height: 100%;
    border: none;
    text-align: center;
    font-weight: bold;
    font-size: 18px; /* 입력 글자 크기 */
    font-family: 'Malgun Gothic', sans-serif; /* 한글 폰트 */
    box-sizing: border-box; /* 패딩, 테두리 포함 크기 계산 */
    padding: 0;
    background-color: transparent; /* input 배경 투명하게 */
    position: relative; /* z-index 적용 위해 */
    z-index: 2; /* cell-number 보다 위에 있도록 */
}

.crossword-grid input:focus {
    outline: none;
    background-color: transparent !important; /* 포커스 시 배경 투명 유지 */
}

/* 헤더 셀 스타일 */
.crossword-grid th.header-cell {
    width: 30px;
    height: 30px;
    border: 1px solid #ddd;
    text-align: center;
    vertical-align: middle;
    background-color: #f8f9fa;
    font-size: 12px;
    font-weight: bold;
    color: #495057;
}

.crossword-grid th.number-header {
    background-color: #e9ecef;
    color: #2c3e50;
}

.crossword-grid th.letter-header {
    background-color: #e9ecef;
    color: #2c3e50;
}

/* 가로세로 줄 하이라이트 */
.crossword-grid td.highlight-row {
    background-color: #bbdefb !important;
}

.crossword-grid td.highlight-col {
    background-color: #bbdefb !important;
}

.crossword-grid td.highlight-current {
    background-color: #90caf9 !important;
}

/* 헤더 하이라이트 효과 */
.crossword-grid th.highlight-header {
    background-color: #90caf9 !important;
    color: #1565c0 !important;
}

/* 검정색 셀의 하이라이트 효과 */
.crossword-grid td.black.highlight-row,
.crossword-grid td.black.highlight-col {
    background-color: #555 !important;
}

.crossword-grid td.black.highlight-current {
    background-color: #666 !important;
}

.cell-number {
    position: absolute;
    top: 1px;
    left: 2px;
    font-size: 10px; /* 이미지와 유사한 크기로 조정 */
    color: #333; /* 약간 더 진한 색으로 */
    pointer-events: none; /* 숫자 위로 마우스 이벤트가 가지 않도록 */
    z-index: 1; 
}

/* input에 값이 있을 때 (placeholder가 보이지 않을 때) cell-number 숨기기 */
.crossword-grid td.white input:not(:placeholder-shown) + .cell-number {
    display: none;
}

/* input의 placeholder는 투명하게 처리하여 보이지 않도록 함 */
.crossword-grid td.white input::placeholder {
  color: transparent;
}

/* 현재 활성화된 셀 스타일 */
.active {
    background-color: #e0f7fa; /* 연한 하늘색 배경 */
    /* box-shadow: 0 0 5px rgba(0, 150, 255, 0.5); */
}

/* 활성/포커스 된 셀의 input 배경도 투명하게 유지 */
.crossword-grid td.white.active input {
    background-color: transparent !important; 
}

.controls {
    text-align: center;
    margin-bottom: 30px;
}

.btn {
    padding: 12px 24px;
    margin: 0 10px;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-size: 16px;
    font-weight: bold;
    transition: all 0.3s ease;
}

.btn-primary {
    background-color: #3498db;
    color: white;
}

.btn-primary:hover {
    background-color: #2980b9;
}

.btn-secondary {
    background-color: #95a5a6;
    color: white;
}

.btn-secondary:hover {
    background-color: #7f8c8d;
}

.btn-warning {
    background-color: #f39c12;
    color: white;
}

.btn-warning:hover {
    background-color: #e67e22;
}

.result-message {
    text-align: center;
    margin-bottom: 30px;
    padding: 15px;
    border-radius: 5px;
    font-size: 18px;
    font-weight: bold;
    min-height: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.result-message.success {
    background-color: #d4edda;
    color: #155724;
    border: 1px solid #c3e6cb;
}

.result-message.error {
    background-color: #f8d7da;
    color: #721c24;
    border: 1px solid #f5c6cb;
}

.clues-container {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 30px;
    margin-top: 30px;
}

.clues-section h3 {
    color: #2c3e50;
    margin-bottom: 15px;
    font-size: 1.5em;
    border-bottom: 2px solid #3498db;
    padding-bottom: 5px;
}

.clues {
    background-color: white;
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.clue-item {
    margin-bottom: 10px;
    padding: 8px;
    border-radius: 4px;
    transition: background-color 0.2s ease;
}

.clue-item:hover {
    background-color: #f8f9fa;
}

.clue-number {
    font-weight: bold;
    color: #3498db;
    margin-right: 8px;
}

@media (max-width: 768px) {
    .container {
        padding: 6px;
        padding-bottom: 200px; /* 하단 패널을 위한 여백 */
    }
    
    h1 {
        font-size: 2em;
    }
    
    .main-content {
        flex-direction: column; 
        align-items: center; 
    }

    .hint-area {
        display: block !important; /* 모바일에서 보이도록 변경 */
        width: 100%; /* 모바일에서 전체 너비 사용 */
        margin-top: 20px; /* 퍼즐 컨테이너 아래 간격 */
        margin-bottom: 20px; /* 컨트롤 버튼 위 간격 */
        /* order 속성은 .main-content와 .hint-area가 같은 flex container의 자식일 때 유효 */
        /* 현재 DOM 구조에서는 .container를 flex로 만들고 .main-content, .hint-area, .controls 순서를 조정해야 함 */
    }
    
    .puzzle-container {
        width: 100%; 
        justify-content: flex-start;
    }

    .puzzle-wrapper {
        min-width: 600px;
    }
    
    .crossword-grid td,
    .crossword-grid th {
        width: 25px;
        height: 25px;
        font-size: 10px;
    }
    
    .crossword-grid input {
        font-size: 20px;
    }
    
    .clues-container {
        grid-template-columns: 1fr;
        gap: 20px;
    }
    
    .btn {
        padding: 10px 20px;
        font-size: 14px;
        margin: 5px;
    }
    
    /* 모바일에서 숨은 단어 패널 스타일 조정 */
    .hidden-word-panel {
        padding: 15px;
    }
    
    .hidden-word-message {
        font-size: 22px;
        margin-bottom: 12px;
    }
    
    .selected-letters {
        min-height: 50px;
        padding: 12px;
        font-size: 20px;
    }
}

@media (min-width: 769px) {
    .main-content {
        flex-direction: row; /* 데스크톱에서는 가로 배치 */
        align-items: flex-start;
    }
    .hint-area {
        display: block; /* 데스크톱에서 보임 */
        width: 300px; /* 데스크톱 너비 복원 */
        margin-top: 0; /* 데스크톱에서는 상단 마진 제거 */
        margin-left: 20px; /* 퍼즐과의 간격 */
        margin-bottom: 0;
    }
}

/* 정답 보기 버튼 숨기기 */
#show-answer {
    display: none;
}

/* 빛나는 글자 효과 */
.glowing-letter {
    animation: glow 1.5s ease-in-out infinite alternate;
    background-color: #ffeb3b !important;
    color: #d32f2f !important;
    font-weight: bold !important;
    cursor: pointer !important;
    box-shadow: 0 0 10px #ffeb3b !important;
    border: 2px solid #ffc107 !important;
    border-radius: 4px !important;
}

@keyframes glow {
    from {
        box-shadow: 0 0 10px #ffeb3b, 0 0 20px #ffeb3b, 0 0 30px #ffeb3b;
    }
    to {
        box-shadow: 0 0 20px #ffc107, 0 0 30px #ffc107, 0 0 40px #ffc107;
    }
}

/* 숨은 단어 패널 - 화면 하단 고정 */
.hidden-word-panel {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-top: 3px solid #fff;
    box-shadow: 0 -5px 20px rgba(0,0,0,0.3);
    padding: 20px;
    z-index: 1000;
    backdrop-filter: blur(10px);
}

/* 숨은 단어 표시 메시지 */
.hidden-word-message {
    text-align: center;
    margin: 0 0 15px 0;
    font-size: 16px;
    font-weight: bold;
    color: #ffffff;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.5);
    animation: pulse 2s ease-in-out infinite;
}

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

/* 선택된 글자들 표시 영역 */
.selected-letters {
    text-align: center;
    margin: 0;
    font-size: 24px;
    font-weight: bold;
    color: #2c3e50;
    min-height: 60px;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 10px;
    background: rgba(255,255,255,0.9);
    border-radius: 12px;
    padding: 15px;
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.1);
}

.selected-letter {
    display: inline-block;
    padding: 8px 12px;
    background: linear-gradient(45deg, #3498db, #2980b9);
    color: white;
    border-radius: 8px;
    box-shadow: 0 4px 8px rgba(0,0,0,0.3);
    animation: slideIn 0.5s ease-out;
}

@keyframes slideIn {
    from {
        transform: translateY(-50px) scale(0.5);
        opacity: 0;
    }
    to {
        transform: translateY(0) scale(1);
        opacity: 1;
    }
}

/* 최종 축하 화면 */
.final-celebration {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(45deg, #ff6b6b, #4ecdc4, #45b7d1, #f9ca24);
    background-size: 400% 400%;
    animation: gradientShift 3s ease infinite;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 9999;
    color: white;
}

@keyframes gradientShift {
    0% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
    100% { background-position: 0% 50%; }
}

.final-celebration h1 {
    font-size: 2em;
    margin-bottom: 20px;
    animation: bounce 1s ease-in-out infinite;
}

.final-celebration p {
    font-size: 1.4em;
    animation: fadeInUp 2s ease-out;
}

@keyframes bounce {
    0%, 20%, 50%, 80%, 100% { transform: translateY(0); }
    40% { transform: translateY(-30px); }
    60% { transform: translateY(-15px); }
}

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

/* 오류 메시지 스타일 */
.error-message {
    text-align: center;
    margin: 15px 0 0 0;
    padding: 12px;
    background-color: #ffebee;
    color: #c62828;
    border: 2px solid #e57373;
    border-radius: 8px;
    font-weight: bold;
    animation: shake 0.5s ease-in-out;
    font-size: 16px;
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-10px); }
    75% { transform: translateX(10px); }
} 