/* 기본 리셋 및 폰트 설정 */
:root {
    --color-primary: #3d3d3d;
    --color-accent: #f5a623;
    --color-background: #fdfdfd;
    --color-input-bg: #fff;
    --font-family: 'Noto Sans KR', sans-serif;
    --color-table-border: #e0e0e0;
    --color-table-header-bg: #f5f5f5; /* 새로운 테이블 헤더 색상 (사용되지 않음) */
}

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

body {
    font-family: var(--font-family);
    background-color: var(--color-background);
    color: var(--color-primary);
    height: 100dvh;
    width: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
    font-size: 90%;
}

#game-wrapper {
    display: flex;
    flex-direction: column;
    width: 100%;
    max-width: 600px;
    height: 100%;
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
    background-color: white;
    position: relative;
}

#location-info {
    padding: 15px;
    background-color: var(--color-primary);
    color: white;
    border-bottom: 3px solid var(--color-accent);
    flex-shrink: 0;
}

/* 상단 바 레이아웃: 양 끝 정렬 */
#location-container {
    display: flex;
    justify-content: space-between;
    align-items: center;
    height: 24px; /* 높이 고정으로 요소들 수직 중앙 정렬 */
    margin-bottom: 8px;
}

/* 오른쪽 상태창 그룹 (체력 + 타이머) */
#status-container {
    display: flex;
    align-items: center;
    gap: 8px; /* 체력과 타이머 사이 간격 */
}

/* [수정] 체력 스타일: 배지(Badge) 형태로 예쁘게 변경 */
#stamina-status {
    font-family: 'Courier New', monospace; /* 숫자 흔들림 없는 고정폭 폰트 */
    font-size: 0.85em;       /* 글자 크기 적당히 */
    font-weight: 500;       /* 굵게 */
    background-color: rgba(0, 0, 0, 0.2); /* 반투명 어두운 배경 */
    color: rgba(255, 255, 255, 0.9); /* 약간 투명한 흰색 */
    padding: 4px 8px;      /* 내부 여백 */
    border-radius: 6px;    /* 둥근 알약 모양 */
    display: flex;
    align-items: center;
    justify-content: center;
    letter-spacing: 2.0px;  /* 자간 살짝 넓힘 */
}

/* [수정] 타이머 스타일: 폰트 줄이고 깔끔하게 */
#play-timer {
    font-family: 'Courier New', monospace; /* 숫자 흔들림 없는 고정폭 폰트 */
    font-size: 0.85em;      /* 폰트 크기 축소 (요청사항 반영) */
    font-weight: 600;
    color: rgba(255, 255, 255, 0.9);
    background-color: rgba(0, 0, 0, 0.2); /* 반투명 어두운 배경 */
    padding: 4px 8px;
    border-radius: 6px;
    letter-spacing: 0.5px;  /* 자간 살짝 넓힘 */
}

#location-name {
    font-size: 1.2em;
    font-weight: 700;
}

/* [추가] 체력 상태 스타일 */
#stamina-status {
    font-size: 0.85em; /* 작은 글씨 */
    color: rgba(255, 255, 255, 0.9); /* 약간 투명한 흰색 */
    font-weight: 400;
}

#inventory-status {
    font-size: 0.9em;
}

#content-scroll-area {
    flex: 1;
    overflow-y: auto;
    padding: 15px;
    line-height: 1.6;
    -webkit-overflow-scrolling: touch;
}

.narrative-text {
    margin-bottom: 1em;
    font-weight: 400;
    color: #555;
    padding: 8px 10px;
    border-left: 3px solid #ccc;
    background-color: #fcfcfc;
    border-radius: 0 4px 4px 0;
}

.narrative-plain {
    margin-bottom: 1em;
    font-weight: 400;
    color: #555;
    padding: 8px 10px;
    /* border-left: 3px solid #ccc;  <-- 이 부분이 제거됨 */
    background-color: #fbfbfb; /* 배경색은 유지 (원하면 transparent로 변경 가능) */
    border-radius: 4px; /* 왼쪽 테두리가 없으므로 네 모서리 모두 둥글게 처리 */
}

.system-message {
    margin: 0.8em 0;
    font-style: italic;
    font-size: 0.9em;
    color: #888;
    padding: 8px 15px;
    background-color: #f0f0f0;
    border-radius: 4px;
    border: 1px dashed #ccc;
    text-align: center;
}

.user-input-log {
    margin: 0.8em 0;
    font-weight: 500;
    color: var(--color-primary);
    background-color: #fff8e8;
    padding: 8px 15px;
    border-radius: 4px;
    border: 1px solid var(--color-accent);
    border-left: 5px solid var(--color-accent);
    white-space: pre-wrap;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}

.user-input-log::before {
    content: '> ';
    color: var(--color-primary);
    margin-right: 5px;
    font-weight: 700;
}

/* === 퍼즐 컨테이너 스타일 === */
.puzzle-container {
    border: 1px dashed #ddd;
    margin: 15px 0;
    padding: 15px;
    background-color: #fafafa;
    border-radius: 8px;
}

.puzzle-title {
    color: var(--color-accent);
    font-size: 1.1em;
    margin-bottom: 5px;
    border-left: 4px solid var(--color-accent);
    padding-left: 10px;
}

.puzzle-hint {
    margin-top: 10px;
    font-size: 0.95em;
}

.visual-hint {
    background-color: #eee;
    height: 120px;
    margin-top: 15px;
    display: flex;
    justify-content: center;
    align-items: center;
    color: #aaa;
    font-style: italic;
    border-radius: 5px;
    box-shadow: inset 0 0 8px rgba(0, 0, 0, 0.1);
}

/* === 테이블 스타일 추가 (마크다운 표 렌더링용) === */
table {
    width: 100%;
    border-collapse: collapse;
    margin: 1.5em 0; /* 상하 여백 추가 */
    font-size: 0.95em;
    border-radius: 8px; /* 표 전체 둥근 모서리 */
    overflow: hidden; /* 둥근 모서리를 위해 필수 */
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.05);
}

th, td {
    padding: 12px 10px;
    border: 1px solid var(--color-table-border);
    text-align: center; /* 텍스트 중앙 정렬 */
    background-color: white; /* 기본 배경색 (일관성 유지) */
    font-weight: normal; /* th와 td의 굵기를 동일하게 */
}

th {
    /* 모든 th 스타일을 td와 동일하게 맞춤 */
    border-top: none;
    border-bottom: 1px solid var(--color-table-border);
    text-transform: none; /* 대문자 변환 제거 */
}

tr:nth-child(even) td { /* 짝수 행 td만 배경색 적용 */
    background-color: #f9f9f9; /* 짝수 행 배경색 */
}

tr:hover td { /* 호버 효과 */
    background-color: #f0f0f0;
}

/* 첫 번째 열, 마지막 열 테두리 복원 (일관성 유지) */
td:first-child, th:first-child {
    border-left: 1px solid var(--color-table-border);
}

td:last-child, th:last-child {
    border-right: 1px solid var(--color-table-border);
}

/* 전체 표 테두리를 위해, 맨 위와 맨 아래 행의 테두리도 보이도록 수정합니다. */
table tr:first-child th {
    border-top: none;
}
table tr:last-child td {
    border-bottom: 1px solid var(--color-table-border);
}


/* === 테이블 스타일 끝 === */


#input-area {
    position: relative;
    background-color: var(--color-input-bg);
    border-top: 2px solid #ddd;
    padding: 10px;
    display: flex;
    align-items: center;
    flex-shrink: 0;
    padding-bottom: calc(10px + env(safe-area-inset-bottom));
}

#user-input {
    flex-grow: 1;
    padding: 10px;
    font-size: 1em;
    border: 1px solid #ccc;
    border-radius: 4px;
    margin-right: 10px;
    outline: none;
    transition: border-color 0.3s;
}

#user-input:focus {
    border-color: var(--color-accent);
    box-shadow: 0 0 5px rgba(245, 166, 35, 0.5);
}

#submit-button {
    padding: 10px 15px;
    background-color: var(--color-accent);
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-weight: 700;
    white-space: nowrap;
    transition: background-color 0.15s, transform 0.1s;
}

#submit-button:hover {
    background-color: #e59a1f;
}

#submit-button:active {
    background-color: #d8901a;
    transform: translateY(1px);
}

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    border: 0;
}

:not(pre) > code {
    background-color: #e9e9e9;
    color: #c7254e;
    padding: 2px 4px;
    border-radius: 3px;
    font-family: 'Courier New', Courier, monospace;
    font-size: 0.9em;
    border: 1px solid #ddd;
}

/* === 로딩 화면 스타일 === */
#loading-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: var(--color-background);
    z-index: 9999; /* 모든 요소 위에 표시 */
    display: flex;
    justify-content: center;
    align-items: center;
    flex-direction: column;
    transition: opacity 0.5s ease-out; /* 페이드 아웃 효과 */
}

.loader-content {
    text-align: center;
    width: 80%;
    max-width: 400px;
}

.loading-title {
    font-size: 1.5em;
    color: var(--color-primary);
    margin-bottom: 20px;
    font-weight: 700;
}

/* 진행바 컨테이너 */
.progress-container {
    width: 100%;
    height: 10px;
    background-color: #e0e0e0;
    border-radius: 5px;
    overflow: hidden;
    position: relative;
    margin-bottom: 15px;
}

/* 움직이는 진행바 (애니메이션) */
.progress-bar {
    width: 30%;
    height: 100%;
    background-color: var(--color-accent); /* 노란/주황 계열 강조색 */
    border-radius: 5px;
    position: absolute;
    left: -30%;
    animation: loading 1.5s infinite ease-in-out;
}

#loading-message {
    color: #666;
    font-size: 0.9em;
    font-style: italic;
    min-height: 1.2em; /* 텍스트 변경 시 높이 흔들림 방지 */
}

/* 진행바 애니메이션 키프레임 */
@keyframes loading {
    0% {
        left: -30%;
        width: 30%;
    }
    50% {
        width: 60%;
    }
    100% {
        left: 100%;
        width: 30%;
    }
}

/* === 모바일 전용 버튼 스타일 === */

/* 기본적으로 PC에서는 숨김 */
#mobile-scroll-group,
#btn-mobile-tab {
    display: none;
}

/* 1. Tab 버튼 스타일 (입력 버튼 왼쪽) */
#btn-mobile-tab {
    background-color: #f0f0f0;
    color: var(--color-primary);
    border: 1px solid #ccc;
    border-radius: 4px;
    padding: 10px 12px;
    margin-right: 5px; /* 입력 버튼과의 간격 */
    font-size: 0.9em;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
}

#btn-mobile-tab:active {
    background-color: #e0e0e0;
}

/* 2. 스크롤 버튼 그룹 (둥둥 떠 있는 반투명 버튼) */
#mobile-scroll-group {
    position: absolute;
    right: 10px;

    /* [수정] -115px에서 -95px로 변경 (너무 높지 않게) */
    top: -95px;

    flex-direction: column;
    gap: 8px;
    z-index: 50;
    pointer-events: none;
}

/* 2. 스크롤 버튼 스타일 (투명도 + 주황빛 유지) */
/* 2. 스크롤 버튼 스타일 (초투명 모드) */
.scroll-float-btn {
    pointer-events: auto;
    width: 38px;
    height: 38px;
    border-radius: 50%;

    /* [수정] 배경: 거의 투명함 (0.15 -> 0.05) */
    background-color: rgba(0, 0, 0, 0.05);

    /* [수정] 테두리: 아주 희미한 회색으로 변경 (주황색 빼서 눈에 덜 띄게) */
    border: 1px solid rgba(0, 0, 0, 0.1);

    /* [수정] 화살표: 반투명한 주황색 (0.9 -> 0.6) */
    color: rgba(245, 166, 35, 0.6);

    /* [제거] 블러 효과 제거 (뒤의 글씨가 뭉개지지 않고 선명하게 보임) */
    backdrop-filter: none;

    font-size: 1.1em;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;

    /* 그림자도 최소화 */
    box-shadow: none;
    transition: all 0.2s;
}

/* 눌렀을 때만 확실하게 보임 */
.scroll-float-btn:active {
    background-color: var(--color-accent); /* 진한 주황색 */
    color: white;
    border-color: transparent;
    transform: scale(0.95);
    box-shadow: 0 2px 5px rgba(0,0,0,0.2);
}


.game-img {
    display: block;          /* 블록 요소로 변경 (가운데 정렬 필수) */
    height: auto;            /* 비율 유지 */
    margin: 5px auto;   /* 위아래 10px 여백, 좌우 중앙 정렬 */

    border-radius: 7px;     /* 모서리 둥글게 */
    box-shadow: 0 4px 12px rgba(0,0,0,0.1); /* 그림자로 입체감 (배경과 분리) */

    max-width: 100%;         /* 화면보다 커지는 것 방지 */
}

/* === 너비 옵션 4가지 === */
.w-40 { width: 40%; }
.w-60 { width: 60%; }
.w-80 { width: 80%; }
.w-100 { width: 100%; }