:root {
    --color-correct: #6aaa64;
    --color-present: #c9b458;
    --color-absent: #787c7e;
    --color-background: #ffffff;
    --color-text: #1a1a1b;
    --color-tile-border: #d3d6da;
    --color-key-bg: #d3d6da;
    --color-modal-background: rgba(0, 0, 0, 0.4);
    --font-main: 'Arial', sans-serif;
    --color-hint-button: #4285f4;
    --color-hint-button-disabled: #a0c2f9;
    --color-hint-counter: #4285f4;
}

/* ===== 기본 스타일 ===== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: var(--font-main);
}

html, body {
    width: 100%;
    min-height: 100vh;
    overflow-x: hidden;
    overflow-y: auto;
}

body {
    background-color: var(--color-background);
    color: var(--color-text);
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 0.5rem;
    touch-action: manipulation;
}

.container {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
    max-width: 500px;
    margin: 0 auto;
    padding: 0 1rem;
}

/* ===== 헤더 스타일 ===== */
header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    width: 100%;
    padding: 0.5rem 0;
    border-bottom: 1px solid var(--color-tile-border);
    margin-bottom: 0.5rem;
}

.header-left {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
}

.header-right {
    min-width: 100px;
    min-height: 100px;
}

h1 {
    font-size: clamp(1.5rem, 5vw, 2rem);
    font-weight: bold;
    letter-spacing: 0.2px;
    margin-bottom: 10px;
}

.game-subtitle {
    font-size: clamp(0.9rem, 3vw, 1.2rem);
    margin-bottom: -5px;
    color: #666;
}

/* ===== 버튼 스타일 ===== */
.menu-buttons {
    display: flex;
    margin-bottom: 8px;
}

.menu-buttons button {
    background: none;
    border: none;
    font-size: clamp(0.8rem, 3vw, 0.9rem);
    cursor: pointer;
    margin-right: 10px;
    color: var(--color-text);
    padding: 5px 10px;
}

.bottom-buttons {
    display: flex;
    gap: 10px;
    margin-bottom: 5px;
}

#hint-btn {
    background-color: var(--color-hint-button);
    color: white;
    border: none;
    border-radius: 4px;
    padding: 0.4rem 0.8rem;
    transition: background-color 0.3s;
    font-size: clamp(0.75rem, 3vw, 0.85rem);
    cursor: pointer;
}

#hint-btn:disabled {
    background-color: var(--color-hint-button-disabled);
    cursor: not-allowed;
    opacity: 0.7;
}

#new-game-btn-header {
    background-color: var(--color-correct);
    color: white;
    border: none;
    border-radius: 4px;
    padding: 0.4rem 0.8rem;
    transition: background-color 0.3s;
    font-size: clamp(0.75rem, 3vw, 0.85rem);
    cursor: pointer;
}

#new-game-btn-header:hover {
    background-color: #5c9956;
}

#new-game-btn {
    padding: 0.6rem 1.2rem;
    background-color: var(--color-correct);
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-weight: bold;
    font-size: 1rem;
    margin-top: 1rem;
}

/* ===== 힌트 카운터 ===== */
.hint-counter {
    margin-top: 1rem;
    font-size: 0.9rem;
    color: var(--color-hint-counter);
    font-weight: bold;
    visibility: hidden;
}

.hint-counter.visible {
    visibility: visible;
}

/* ===== 게임 보드 스타일 ===== */
.game-board {
    display: grid;
    grid-template-rows: repeat(6, 1fr);
    gap: min(1vw, 5px);
    margin-bottom: clamp(0.5rem, 2vh, 1rem);
    width: 100%;
    max-width: 350px;
    aspect-ratio: 5/6;
}

.row {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: min(1vw, 5px);
    height: 100%;
}

.tile {
    width: 100%;
    height: 100%;
    border: 2px solid var(--color-tile-border);
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: clamp(1rem, 7vw, 2rem);
    font-weight: bold;
    text-transform: uppercase;
    aspect-ratio: 1/1;
}

.tile.correct {
    background-color: var(--color-correct);
    color: white;
    border-color: var(--color-correct);
}

.tile.present {
    background-color: var(--color-present);
    color: white;
    border-color: var(--color-present);
}

.tile.absent {
    background-color: var(--color-absent);
    color: white;
    border-color: var(--color-absent);
}

.tile.filled {
    border-color: #878a8c;
}

/* ===== 키보드 스타일 ===== */
.keyboard {
    width: 100%;
    margin-top: min(1rem, 3vh);
    touch-action: manipulation;
}

.keyboard-row {
    display: flex;
    justify-content: center;
    width: 100%;
    margin-bottom: 0.5rem;
}

.key {
    background-color: var(--color-key-bg);
    border: none;
    border-radius: 4px;
    color: var(--color-text);
    font-size: clamp(0.65rem, 3vw, 0.9rem);
    font-weight: bold;
    margin: 0 min(0.2vw, 2px);
    padding: 0;
    height: clamp(2.8rem, 9vh, 3.8rem);
    flex: 1;
    min-width: min(6vw, 2rem);
    text-transform: uppercase;
    cursor: pointer;
    touch-action: manipulation;
    user-select: none;
}

.key.wide {
    flex: 1.5;
    font-size: clamp(0.6rem, 2.8vw, 0.8rem);
}

.key.correct {
    background-color: var(--color-correct);
    color: white;
}

.key.present {
    background-color: var(--color-present);
    color: white;
}

.key.absent {
    background-color: var(--color-absent);
    color: white;
}

.spacer {
    flex: 0.5;
}

.spacer.half {
    flex: 0.25;
}

/* ===== 메시지 스타일 ===== */
.message {
    position: fixed;
    top: 10%;
    left: 50%;
    transform: translateX(-50%);
    background-color: #000000;
    color: white;
    padding: 0.8rem 1.5rem;
    border-radius: 4px;
    font-weight: bold;
    opacity: 0;
    transition: opacity 0.3s;
    z-index: 100;
    text-align: center;
    max-width: 90%;
}

.message.show {
    opacity: 1;
}

/* ===== 기본 모달 스타일 ===== */
.modal {
    display: none;
    position: fixed;
    z-index: 999;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: var(--color-modal-background);
    overflow-y: auto;
}

.modal-content {
    background-color: #fefefe;
    position: fixed;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    padding: 1.2rem;
    border: 1px solid #888;
    border-radius: 8px;
    width: 90%;
    max-width: 400px;
    max-height: 90vh;
    overflow-y: auto;
    z-index: 1001;
}

.close {
    color: #aaa;
    float: right;
    font-size: 1.8rem;
    font-weight: bold;
    cursor: pointer;
}

.close:hover,
.close:focus {
    color: black;
    text-decoration: none;
}

/* ===== 힌트 모달 스타일 ===== */
.hint-container {
    text-align: center;
    padding: 1rem 0;
}

.hint-title {
    font-size: 1.2rem;
    font-weight: bold;
    margin-bottom: 1rem;
}

.hint-content {
    font-size: 1rem;
    line-height: 1.5;
    padding: 1rem;
    background-color: #f8f8f8;
    border-radius: 4px;
    margin-bottom: 1rem;
}

.hint-letter {
    font-weight: bold;
    font-size: 1.5rem;
    color: var(--color-hint-button);
    padding: 0.5rem;
    border: 2px solid var(--color-hint-button);
    border-radius: 4px;
    margin: 0.5rem;
    display: inline-block;
}

.hint-explanation {
    font-style: italic;
    color: #666;
    margin-top: 0.5rem;
}

/* ===== 통계 모달 스타일 ===== */
.stats-container {
    text-align: center;
}

.stats-container h2 {
    margin-bottom: 1rem;
    font-size: clamp(1.2rem, 5vw, 1.5rem);
}

.stats-container h3 {
    margin: 1rem 0;
    font-size: clamp(1rem, 4vw, 1.2rem);
}

.stats-row {
    display: flex;
    justify-content: space-around;
    margin: 1.2rem 0;
    flex-wrap: wrap;
}

.stat-box {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 0.5rem;
    flex: 1;
    min-width: 20%;
}

.stat-number {
    font-size: clamp(1.5rem, 6vw, 2.2rem);
    font-weight: bold;
}

.stat-label {
    font-size: clamp(0.7rem, 3vw, 0.8rem);
    margin-top: 0.3rem;
}

.graph-container {
    margin: 1.2rem 0;
    width: 100%;
}

.graph-row {
    display: flex;
    align-items: center;
    margin: 0.3rem 0;
    height: min(6vh, 30px);
}

.graph-label {
    width: 1.2rem;
    margin-right: 0.6rem;
    text-align: right;
    font-weight: bold;
}

.graph-bar {
    height: 100%;
    background-color: var(--color-correct);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: bold;
    padding: 0 0.5rem;
    border-radius: 2px;
    transition: width 0.5s;
    min-width: 2rem;
}

/* ===== 도움말 모달 스타일 ===== */
.help-container {
    padding: 0.6rem;
}

.help-section {
    margin-bottom: 1.2rem;
}

.help-title {
    font-weight: bold;
    margin-bottom: 0.6rem;
}

.help-section ul {
    padding-left: 1.5rem;
    margin-bottom: 0.8rem;
}

.help-section li {
    margin-bottom: 0.4rem;
}

.help-section p {
    margin-bottom: 0.8rem;
}

.example-row {
    display: flex;
    margin: 0.6rem 0;
}

.example-tile {
    width: 2.5rem;
    height: 2.5rem;
    border: 2px solid var(--color-tile-border);
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 1.2rem;
    font-weight: bold;
    margin-right: 0.3rem;
    text-transform: uppercase;
}

/* ===== 헤더 오른쪽 공간 (룰렛+주역) 스타일 ===== */
.header-center-right {
    display: flex;
    flex-direction: row;
    align-items: flex-start;
    gap: 12px;
    max-width: 420px;
    min-height: 0;
    margin: 0;
    padding: 0;
}

.header-center-right .main-container {
    display: flex;
    flex-direction: row;
    gap: 12px;
    width: 100%;
    padding: 0;
    margin: 0;
    background: none;
    box-shadow: none;
}

.header-center-right .roulette-section,
.header-center-right .hexagram-section {
    min-width: 120px;
    max-width: 180px;
    flex: 1 1 0;
    padding: 0;
}

/* 룰렛 요소 소형화 */
.header-center-right .roulette-section h1,
.header-center-right .hexagram-section h1 {
    font-size: 1rem;
    margin-bottom: 0.3rem;
}

.header-center-right .result-box {
    width: 60px;
    padding: 2px;
    margin-bottom: 6px;
    font-size: 0.9rem;
}

.header-center-right .result-display {
    font-size: 1.1rem;
    padding: 2px;
}

.header-center-right .roulette-container {
    width: 70px;
    height: 70px;
    margin: 0 auto 6px auto;
    position: relative;
}

.header-center-right .roulette {
    width: 70px;
    height: 70px;
}

.header-center-right .pointer {
    position: absolute;
    left: 50%;
    top: auto;
    bottom: 3px;
    width: 0;
    height: 0;
    border-left: 3.5px solid transparent;
    border-right: 3.5px solid transparent;
    border-top: 6px solid #f44;
    border-bottom: none;
    transform: translateX(-50%);
    z-index: 2;
}

.header-center-right .center {
    position: absolute;
    left: 50%;
    top: 50%;
    width: 10px;
    height: 10px;
    background: #fff;
    border: 2px solid #888;
    border-radius: 50%;
    transform: translate(-50%, -50%);
    z-index: 2;
}

.header-center-right #spinButton {
    font-size: 0.85rem;
    padding: 0.2rem 0.6rem;
    margin-top: 4px;
    margin-bottom: 4px;
    min-width: 0;
    width: 100%;
    box-sizing: border-box;
}

/* 주역 요소 소형화 */
.header-center-right .hexagram-container {
    max-width: 120px;
    padding: 6px;
    border-radius: 10px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}

.header-center-right .hexagram-status {
    font-size: 0.8rem;
    margin-bottom: 4px;
}

.header-center-right .hexagram-lines {
    gap: 4px;
    margin-bottom: 0;
}

.header-center-right .hexagram-line {
    height: 12px;
    font-size: 0.7rem;
}

.header-center-right .line-position {
    left: -14px;
    font-size: 0.7rem;
}

.header-center-right .yang-line {
    height: 3px;
}

.header-center-right .yin-line {
    height: 3px;
}

.header-center-right .yin-line-part {
    height: 3px;
}

/* ===== 언어 선택 버튼 ===== */
.header-lang-selector {
    margin-top: 12px;
    width: 100%;
    display: flex;
    justify-content: center;
}

.header-lang-buttons {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    grid-template-rows: 1fr;
    gap: 2px;
    width: 80px;
}

.header-lang-buttons .lang-btn {
    padding: 2px 0;
    border-radius: 7px;
    border: none;
    background: #f0f0f0;
    font-size: 10px;
    font-weight: bold;
    cursor: pointer;
    color: #666;
    transition: all 0.2s;
    min-width: 0;
    min-height: 0;
}

.header-lang-buttons .lang-btn.active {
    background-color: var(--color-correct);
    color: white;
    animation: blink 1.5s infinite;
}

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

/* ===== 룰렛/주역점 모달 스타일 ===== */
.iching-modal-overlay {
    display: none;
    position: fixed;
    z-index: 2000;
    left: 0;
    top: 0;
    width: 100vw;
    height: 100vh;
    background-color: rgba(0,0,0,0.5);
    justify-content: center;
    align-items: center;
}

.iching-modal-overlay[style*="display: flex"] {
    display: flex !important;
}

.iching-modal {
    position: relative;
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 4px 24px rgba(0,0,0,0.18);
    padding: 20px 16px 16px 16px;
    min-width: 260px;
    max-width: 95vw;
    max-height: 90vh;
    overflow-y: auto;
    z-index: 2100;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.iching-modal-title {
    font-size: 1.1rem;
    font-weight: bold;
    margin-bottom: 12px;
    text-align: center;
}

.iching-modal-content {
    width: 100%;
    margin-bottom: 12px;
    text-align: left;
    flex: 1 1 auto;
}

.iching-modal-footer {
    display: flex;
    justify-content: center;
    gap: 10px;
    margin-top: auto;
    width: 100%;
    align-self: flex-end;
}

/* ===== 질문 카드 스타일 ===== */
.question-item {
    padding: 12px;
    margin-bottom: 10px;
    border: 1px solid #ddd;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
}

.question-item:hover {
    background-color: #f8f9fa;
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.05);
}

.question-item.selected {
    background-color: #e6f0ff;
    border-color: #5B9BFF;
    box-shadow: 0 2px 5px rgba(91, 155, 255, 0.2);
}

/* ===== 미디어 쿼리 - 작은 화면 ===== */
@media (max-width: 400px) {
    .keyboard-row {
        margin-bottom: 0.3rem;
    }
    
    .key {
        height: clamp(2.5rem, 8vh, 3.5rem);
        margin: 0 1px;
        border-radius: 3px;
    }
    
    .example-tile {
        width: 2rem;
        height: 2rem;
        font-size: 1rem;
    }
    
    .header-right {
        min-width: 80px;
        min-height: 80px;
    }
    
    .game-subtitle {
        margin-bottom: -3px;
    }
    
    h1 {
        margin-bottom: 6px;
    }
    
    .menu-buttons {
        margin-bottom: 5px;
    }
    
    .bottom-buttons {
        gap: 5px;
    }
    
    #hint-btn, #new-game-btn-header {
        padding: 0.3rem 0.6rem;
        font-size: clamp(0.7rem, 2.8vw, 0.8rem);
    }
}

@media (max-width: 320px) {
    .container {
        padding: 0 0.5rem;
    }
    
    .key {
        font-size: 0.6rem;
        height: 2.5rem;
    }
    
    .key.wide {
        font-size: 0.55rem;
    }
    
    .menu-buttons button {
        padding: 0.3rem;
    }
}

/* ===== 미디어 쿼리 - 모바일 (600px 이하) ===== */
@media (max-width: 600px) {
    .container {
        padding: 0 0.3rem;
        max-width: 100vw;
    }
    
    header {
        margin-bottom: 0.3rem;
        padding: 0.2rem 0;
    }
    
    .game-board {
        margin-bottom: 0.5rem;
        margin-top: 0.2rem;
    }
    
    /* 헤더 오른쪽 영역 (룰렛+주역) 모바일 최적화 */
    .header-center-right {
        max-width: 98vw;
        gap: 6px;
        max-height: 160px;
        min-height: 140px;
    }
    
    .header-center-right .main-container {
        gap: 6px;
        margin: 0;
        padding: 0;
        min-height: 0;
    }
    
    .header-center-right .roulette-section,
    .header-center-right .hexagram-section {
        min-width: 90px;
        max-width: 120px;
        min-height: 140px;
        max-height: 150px;
        padding: 4px;
        margin: 2px 0;
    }
    
    /* 룰렛 요소 모바일 크기 조정 */
    .header-center-right .roulette-container,
    .header-center-right .roulette {
        width: 48px;
        height: 48px;
    }
    
    .header-center-right .center {
        width: 7px;
        height: 7px;
    }
    
    .header-center-right .pointer {
        border-left: 2.5px solid transparent;
        border-right: 2.5px solid transparent;
        border-top: 4px solid #f44;
        border-bottom: none;
        top: auto;
        bottom: 2px;
    }
    
    /* 주역 요소 모바일 크기 조정 */
    .header-center-right .hexagram-container {
        max-width: 80px;
        padding: 2px;
    }
    
    .header-center-right .hexagram-line {
        height: 8px;
        font-size: 0.6rem;
    }
    
    .header-center-right .line-position {
        left: -10px;
        font-size: 0.6rem;
    }
    
    /* 모바일에서 룰렛 버튼 숨기기 */
    .header-center-right #spinButton {
        display: none !important;
    }
    
    /* 모달 모바일 최적화 */
    .iching-modal {
        min-width: 180px;
        padding: 6px 2px 6px 2px;
        min-height: 60vh;
        height: 80vh;
    }
    
    .iching-modal-title {
        font-size: 1rem;
        margin-bottom: 6px;
    }
    
    .iching-modal-content {
        margin-bottom: 12px;
        flex: 1 1 0;
        min-height: 0;
        width: 100%;
        display: flex;
        flex-direction: column;
        padding-bottom: 10px;
    }
    
    .iching-modal-content > div {
        flex: 1 1 0;
        width: 100%;
    }
    
    .iching-modal-content.info-modal-content {
        flex: none !important;
        min-height: 0 !important;
        height: auto !important;
        margin-bottom: 0 !important;
    }
    
    .iching-modal-footer {
        margin-top: 10px !important;
        padding-top: 8px;
        border-top: 1px solid #f0f0f0;
        flex-shrink: 0;
    }
    
    /* 질문 카드 모바일 최적화 */
    .question-item {
        padding: 6px 10px !important;
        margin-bottom: 4px !important;
        min-height: 40px !important;
        max-height: 50px !important;
        font-size: 13px !important;
        line-height: 1.2 !important;
        display: flex !important;
        align-items: center !important;
        justify-content: flex-start !important;
        text-align: left !important;
        white-space: normal !important;
        word-wrap: break-word !important;
        box-sizing: border-box !important;
    }

    /* 키워드 영역 하단 여백 추가 */
    .keywords-list {
        margin-bottom: 15px !important;
        padding-bottom: 10px !important;
    }
    
    /* 해석 모달 전체 패딩 조정 */
    #interpretationModalOverlay .iching-modal-content {
        overflow-y: auto;
        max-height: calc(80vh - 120px);
    }

}

/* ===== 미디어 쿼리 - 큰 화면 ===== */
@media (min-width: 768px) {
    .container {
        padding: 0 2rem;
    }
    
    .game-board {
        margin-bottom: 2.5rem;
    }
    
    .keyboard {
        max-width: 500px;
    }
    
    .key {
        margin: 0 3px;
    }
}

@media (min-height: 900px) {
    .game-board {
        max-height: 70vh;
    }
}

/* ===== 다크 모드 지원 ===== */
@media (prefers-color-scheme: dark) {
    :root {
        --color-background: #121213;
        --color-text: #ffffff;
        --color-tile-border: #3a3a3c;
        --color-key-bg: #818384;
        --color-hint-button: #5c9aff;
        --color-hint-button-disabled: #3a4e73;
        --color-hint-counter: #5c9aff;
    }
    
    .modal-content {
        background-color: #121213;
        border-color: #3a3a3c;
    }
    
    .close {
        color: #ffffff;
    }
    
    .close:hover, 
    .close:focus {
        color: #d7dadc;
    }
    
    .hint-content {
        background-color: #2e2e2e;
    }
    
    .game-subtitle {
        color: #aaa;
    }
}

/* ===== 접근성 개선 ===== */
@media (prefers-reduced-motion) {
    .tile, 
    .key, 
    .message, 
    .graph-bar {
        transition: none;
    }
}

/* 푸터 스타일 */
.site-footer {
    margin-top: 2rem;
    padding: 1.5rem 0;
    background-color: #f8f9fa;
    border-top: 1px solid #e9ecef;
}

.footer-nav {
    margin-bottom: 1rem;
}

.footer-menu {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 1rem;
}

.footer-menu li {
    margin: 0;
}

.footer-menu a {
    color: #495057;
    text-decoration: none;
    font-size: 0.9rem;
    transition: color 0.2s ease;
}

.footer-menu a:hover {
    color: #6aaa64;
}

.footer-copyright {
    text-align: center;
    color: #6c757d;
    font-size: 0.8rem;
}

/* 모바일 대응 */
@media (max-width: 768px) {
    .footer-menu {
        flex-direction: column;
        align-items: center;
        gap: 0.5rem;
    }
    
    .footer-menu li {
        margin: 0.25rem 0;
    }
}