@import url('https://fonts.googleapis.com/css2?family=Noto+Sans+KR:wght@400;700&display=swap');

:root {
    --font-size: clamp(14px, 2.2vh, 18px);
    --max-board-height: calc(100dvh - 340px);
    --board-table-side-length: min(95vw, var(--max-board-height));
    
    --long-short-ratio: 3.2;
    --short-length-number-in-board-table: calc(9 * var(--long-short-ratio) + 8);
    --short-length: calc(var(--board-table-side-length) / var(--short-length-number-in-board-table));
    --long-length: calc(var(--long-short-ratio) * var(--short-length));
    --wall-gap: calc(var(--short-length) * 0.25);
    --wall-length: calc(2 * var(--long-length) + var(--short-length) - 2 * var(--wall-gap));
    --wall-width: calc(var(--short-length) - 2 * var(--wall-gap));
    
    --color-text-main: #e0e0e0;
    --color-bg-main: #121212;
    --color-bg-box: #242424;
    
    /* 기본 맵 테마 */
    --grass-color: #2e4c31; 
    --line-color: #000000; 
}

/* 난이도별 맵 테마 동적 변경 */
body.map-level-novice { --grass-color: #4caf50; --line-color: #1b5e20; }
body.map-level-average { --grass-color: #795548; --line-color: #3e2723; }
body.map-level-good { --grass-color: #2e4c31; --line-color: #000000; }
body.map-level-strong { --grass-color: #5c0000; --line-color: #1a0000; }

@media only screen and (min-width: 768px) and (min-height: 768px) {
    :root { --font-size: 30px; }
}
@media only screen and (min-width: 768px), (orientation: landscape) {
    :root { --board-table-side-length: 65vmin; }
}

html { box-sizing: border-box; }
*, *:before, *:after { box-sizing: inherit; }

body {
    font-family: 'Noto Sans KR', sans-serif;
    color: var(--color-text-main);
    background-color: var(--color-bg-main); 
    margin: 0; padding: 0;
    overflow: hidden; 
    overscroll-behavior: none;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
    transition: background-color 0.5s ease;
}

a, a:link, a:visited { color: #5bc0de; text-decoration: none; transition: color 0.2s ease; }
a:hover, a:active { color: #8addff; }

.gridcontainer0 {
    display: flex; flex-direction: column; align-items: center; justify-content: space-between;
    width: 100%; height: 100dvh; padding-top: 55px; padding-bottom: 55px; box-sizing: border-box;
}

.gridcontainer1 { 
    display: flex; width: var(--board-table-side-length); justify-content: space-between; 
    align-items: center; margin-top: 10px; margin-bottom: 10px;
}

#board_table_container { 
    position: relative; box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5); 
    border-radius: 8px; flex-shrink: 0;
}

.gridcontainer2 { 
    display: flex; flex-direction: column; width: var(--board-table-side-length);
    gap: 10px; margin-top: 10px; margin-bottom: 10px;
}

table {
    table-layout: fixed; border-radius: 8px; background-color: var(--line-color); 
    border-collapse: collapse; text-align: center; width: var(--board-table-side-length);
    height: var(--board-table-side-length); padding: 0; overflow: hidden;
    transition: background-color 0.5s ease;
}

td { position: relative; padding: 0; }
tr.row { height: var(--long-length); }
td.col { width: var(--long-length); }
tr.between_rows { height: var(--short-length); }
td.between_cols { width: var(--short-length); }
tr.row td.col { background-color: var(--grass-color); border-radius: 4px; transition: background-color 0.5s ease; }

div.pawn {
    display: flex; align-items: center; justify-content: center;
    width: calc(var(--long-length) * 0.8); height: calc(var(--long-length) * 0.8);
    border-radius: 50%; margin: 10% auto; background-color: #2c2c2c; 
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.4); 
    transition: transform 0.2s ease, box-shadow 0.2s ease; z-index: 5;
    background-size: cover; background-position: center;
}

div.pawn.pawn0 { border: 2px solid #ffb300; background-image: url('rabbit.png'); background-color: #fff; }
div.pawn.pawn1 { border: 2px solid #a1887f; background-image: url('bear.png'); background-color: #fff; }

div.horizontal_wall, div.vertical_wall { display: inline-block; position: absolute; left: var(--wall-gap); top: var(--wall-gap); background-color: #8d6e63; border-radius: 4px; box-shadow: 0 2px 5px rgba(0, 0, 0, 0.6); z-index: 4; background-size: cover; background-position: center;}
div.horizontal_wall { width: var(--wall-length); height: var(--wall-width); }
div.vertical_wall { width: var(--wall-width); height: var(--wall-length); }

div.horizontal_wall.pawn0, div.vertical_wall.pawn0 { background-image: url('rabbit_wall.png'); background-color: #ffb300; }
div.horizontal_wall.pawn1, div.vertical_wall.pawn1 { background-image: url('bear_wall.png'); background-color: #8d6e63; }

div.horizontal_wall.shadow, div.vertical_wall.shadow { opacity: 0.6; background-color: #bcaaa4; background-image: none !important;}
div.pawn.shadow { opacity: 0.4; background-color: rgba(255, 255, 255, 0.2); box-shadow: none; border: 1px solid rgba(255,255,255,0.3); background-image: none !important;}

#number_of_left_walls_box { display: flex; align-items: center; justify-content: space-around; font-size: var(--font-size); font-weight: bold; background-color: var(--color-bg-box); color: var(--color-text-main); padding: 10px; border-radius: 12px; border: 1px solid #333; box-shadow: 0 4px 10px rgba(0,0,0,0.3); }
div.pawn.symbol { 
    width: calc(var(--font-size) * 2.5);  /* 가로 크기 증가 */
    height: calc(var(--font-size) * 2.5); /* 세로 크기 증가 */
    margin: 0 calc(var(--font-size) / 2) 0 0; /* 위아래 마진을 없애서 찌그러짐 방지 */
    border-width: 2px; 
    flex-shrink: 0; /* 박스 안에서 얼굴이 찌그러지는 현상 방지 */
    display: inline-flex; /* 텍스트와 가로 정렬 유지 */
    vertical-align: middle;
}
div.pawn.button { margin-left: var(--short-length); margin-right: var(--short-length); cursor: pointer; }
div.horizontal_wall.symbol { position: initial; vertical-align: middle; width: calc(var(--font-size) * 1.5); height: calc(var(--font-size) * 0.4); margin-left: calc(var(--font-size) / 6); margin-right: calc(var(--font-size) / 6); box-shadow: none; }
div.mul_sign_wall_num_container { display: inline-block; vertical-align: middle; }
div.multiplication_sign { display: inline; vertical-align: middle; margin-left: calc(var(--font-size) / 6); margin-right: calc(var(--font-size) / 6); color: #888; }
div.wall_num { display: inline-block; vertical-align: middle; width: var(--font-size); text-align: center; color: #fff; }

/* 팝업 창 전체 덮기 (모바일 삐져나감 원천 차단) */
.fade_box { 
    position: absolute; display: flex; flex-direction: column; align-items: center; justify-content: center; 
    top: 0; left: 0; width: 100%; height: 100%; font-size: calc(var(--font-size) * 1.1); font-weight: 700; 
    padding: 8%; box-sizing: border-box; text-align: center; z-index: -1; visibility: hidden; opacity: 0; 
    border-radius: 8px; box-shadow: inset 0 0 50px rgba(0,0,0,0.8); background-color: rgba(36, 36, 36, 0.95); 
    border: 1px solid #444; color: var(--color-text-main);
}
.fade_box.in { z-index: 10; visibility: visible; opacity: 1; animation-name: fade_in; animation-duration: 0.3s; }
@keyframes fade_in { 0% {opacity: 0;} 100% {opacity: 1;} }
.fade_box.inout { z-index: -1; visibility: hidden; opacity: 0; animation-name: fade_inout; }
@keyframes fade_inout { 0% {visibility: visible; z-index: 10; opacity: 0; transform: scale(0.95);} 15% {opacity: 1; transform: scale(1);} 85% {opacity: 1; transform: scale(1);} 100% {visibility: hidden; z-index: 10; opacity: 0; transform: scale(1.05);} }

/* 모바일 모달 내 P 태그 여백 초기화 */
.fade_box p { margin: 10px 0; line-height: 1.4; word-break: keep-all;}

#note_message_box{ background-color:rgba(192, 57, 43, 0.9); color: white; animation-duration: 3s; }
#game_result_message_box{ animation-duration: 10s; background-color: rgba(39, 174, 96, 0.95); color: white; }

.button_container.in_message_box { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; width: 100%; margin-top: 15px; }
.button_container.above.left { display: flex; align-items: center; justify-content: flex-start; gap: 5px;}
.button_container.above.right { display: flex; align-items: center; justify-content: flex-end; }
.button_container.below { display: flex; justify-content: center; align-items: center; gap: 5px;}

#current_mode_display { color: #5bc0de; font-size: calc(var(--font-size) * 0.75); font-weight: 700; text-align: right; line-height: 1.3; }

button { font-family: 'Noto Sans KR', sans-serif; cursor: pointer; }
button.button { display: inline-block; height: calc(2.8 * var(--font-size)); border: none; border-radius: 8px; padding: 0 10px; color: white; font-size: calc(var(--font-size) * 0.9); font-weight: 700; text-align: center; text-decoration: none; box-shadow: 0 4px 6px rgba(0,0,0,0.3); transition: all 0.3s ease; min-height: 40px; flex: 1; }
button.button:hover:not(:disabled) { transform: translateY(-2px); box-shadow: 0 6px 12px rgba(0,0,0,0.5); }
button.button:active:not(:disabled) { transform: translateY(0); box-shadow: 0 2px 4px rgba(0,0,0,0.2); }

/* 🚨 텍스트 삐져나감 해결: 고정 height 삭제, 줄바꿈 허용, 패딩 증가 🚨 */
button.ai_level, button.update, button.close, button.restart_yes_no { 
    display: flex; align-items: center; justify-content: center; 
    height: auto; width: 100%; max-width: 100%; 
    border: 1px solid #555; padding: 12px 10px; 
    background-color: #333; color: white; font-size: calc(var(--font-size) * 0.9); 
    font-weight: 700; text-align: center; text-decoration: none; border-radius: 8px; 
    box-shadow: 0 2px 4px rgba(0,0,0,0.2); transition: all 0.2s ease; 
    min-height: 48px; 
    white-space: normal; /* 글자가 길면 자연스럽게 아랫줄로 넘김 */
    word-break: keep-all; /* 단어 단위로 예쁘게 끊어짐 */
    line-height: 1.4;
}

button.ai_level:hover, button.restart_yes_no:hover, button.update:hover, button.close:hover { background-color: #444; border-color: #777; transform: translateY(-1px); }

button#update_now { background-color: #2980b9; color: white; border: none; }
button#update_now:hover { background-color: #1f618d; }
button#later { background-color: #555; color: white; border: none; }
button#later:hover { background-color: #666; }

button.close { background-color: #555; color: white; display: block; margin: 15px auto 0; border: none; width: 50%; }
button.close:hover { background-color: #666; }

.button.restart { background-color: #8e44ad; }
.button.undo { background-color: #d35400; }
.button.redo { background-color: #2c3e50; border: 1px solid #444; }
.button.cancel { background-color: var(--color-bg-box); color: #e74c3c; border: 2px solid #e74c3c; }
.button.cancel:hover:not(:disabled) { background-color: rgba(231, 76, 60, 0.1); }
.button.confirm { background-color: #27ae60; }
.button.aido { background-color: #2980b9; }

#message_box { position: relative; display: flex; align-items: center; justify-content: center; height: calc(3 * var(--font-size)); font-size: calc(var(--font-size) * 1.1); font-weight: bold; color: #ffffff; text-align: center; background-color: var(--color-bg-box); border-radius: 8px; border: 1px solid #333; box-shadow: 0 4px 10px rgba(0,0,0,0.3); overflow: hidden; margin-bottom: 5px; }
#progress_bar { position: absolute; z-index: 0; top: 0; left: 0; height: 100%; background-color: rgba(39, 174, 96, 0.3); transition: width 0.1s linear; }

span.no_wrap { white-space: nowrap; } span.thick { font-weight: 900; }
div.pawn.hidden { visibility: hidden; }
div.pawn.clicked { opacity: 0.8; transform: scale(0.95); box-shadow: 0 0 0 4px rgba(39, 174, 96, 0.5); }
.fade_box.in.hidden, button.button.hidden, input.hidden { display: none !important; }
.button:disabled { opacity: 0.3; cursor: not-allowed; transform: none !important; box-shadow: none !important; filter: grayscale(100%); }

input { width: calc(3 * var(--font-size)); border-radius: 4px; border: 1px solid #555; background: #222; color: #fff; padding: 5px; }
p.developed_by, p.release_date, p.last_updated { font-size: calc(0.6 * var(--font-size)); color: #888; }
p.release_date, p.last_updated { margin-block-start: 0.4em; margin-block-end: 0.4em; }

#ai_chat_bubble {
    position: absolute;
    transform: translateX(-50%); 
    background-color: #E50914; 
    color: #ffffff;
    padding: 8px 16px;
    border-radius: 20px;
    font-size: calc(var(--font-size) * 0.8);
    font-weight: 700;
    box-shadow: 0 5px 15px rgba(229, 9, 20, 0.6);
    z-index: 1000; 
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, transform 0.3s ease;
    pointer-events: none;
    white-space: nowrap;
}
#ai_chat_bubble.show { opacity: 1; visibility: visible; transform: translateX(-50%) translateY(-15px); }
#ai_chat_bubble::after { content: ''; position: absolute; top: 100%; left: 50%; margin-left: -8px; border-width: 8px 8px 0; border-style: solid; border-color: #E50914 transparent transparent transparent; }

@media (hover: hover) {
    /* 기존에 숨겨져 있던 버튼들을 PC에서도 보이게 강제 설정 */
    #confirm_button, #cancel_button { 
        display: inline-block !important; 
    }
    
    div.pawn.shadow:hover { opacity: 0.8; transform: scale(1.1); }
    div.pawn.button, button.ai_level, button.restart_yes_no, button.update { opacity: 0.9; }
    div.pawn.button:hover, button.ai_level:hover, button.restart_yes_no:hover, button.update:hover { opacity: 1; transform: translateY(-2px); }
}

.kakao_ad_area { position: fixed; left: 50%; top: 0; transform: translateX(-50%); width: 320px; height: 50px; display: block; z-index: 100; }
.kakao_ad_area2 { position: fixed; left: 50%; bottom: 0; transform: translateX(-50%); width: 320px; height: 50px; display: block; z-index: 100; }


/* PC/데스크탑 전용: 한 화면에 모든 버튼이 들어오게 강제 설정 */
@media only screen and (min-width: 1024px) {
    :root {
        /* 보드판이 차지하는 최대 높이를 화면의 55%로 제한하여 버튼 공간 확보 */
        --max-board-height: 55vh; 
        --board-table-side-length: min(90vw, var(--max-board-height));
    }

    .gridcontainer0 {
        height: 100dvh !important; /* 전체 화면 높이를 100%로 고정 */
        display: flex !important;
        flex-direction: column !important;
        justify-content: center !important; /* 요소들을 중앙으로 모음 */
        overflow: hidden !important; /* 스크롤바 발생 원천 차단 */
        gap: 10px !important; /* 요소 간 간격 최적화 */
    }

    /* 하단 버튼 영역이 잘 보이도록 여백 조정 */
    .gridcontainer2 {
        margin-top: 5px !important;
    }
}