/* ============================================================
   테마 변수
   ============================================================ */
:root {
    --bg-color: #0f0f0f;
    --card-bg: #1a1a1a;
    --text-color: #e0e0e0;
    --point-color: #d4af37;
    --input-bg: #252525;
    --input-text: #ffffff;
    --border-color: #333333;
    --footer-color: #666666;
    --green-color: #a8ff78;
    --dmg-player: #d4af37;
    --dmg-enemy: #ff6b6b;
    --card-bg-soft: #22262e;
    --sale-color: #e74c3c;
    --text-muted-color: #8a91a0;
    --bg-disabled: #2a2d33;
    --cash-color: #ffd700;
    --scrollbar-thumb: #3a3a3a;
    --scrollbar-thumb-hover: #666666;
}

html.light-mode {
    --bg-color: #f8f9fa;
    --card-bg: #ffffff;
    --text-color: #212529;
    --point-color: #b8860b;
    --input-bg: #ffffff;
    --input-text: #212529;
    --border-color: #dee2e6;
    --footer-color: #999999;
    --green-color: #5cc125;
    --dmg-player: #b8860b;
    --dmg-enemy: #e04040;
    --card-bg-soft: #f1f3f5;
    --sale-color: #d63031;
    --text-muted-color: #6c757d;
    --bg-disabled: #e9ecef;
    --cash-color: #daa520;
    --scrollbar-thumb: #dddddd;
    --scrollbar-thumb-hover: #999999;
}

/* ============================================================
   전역 스크롤바 — 기본은 연하게, 호버 시 강조.
   특정 컴포넌트가 더 구체적인 selector 로 덮어쓰면 그게 우선.
   ============================================================ */
::-webkit-scrollbar {
    width: 4px;
}
::-webkit-scrollbar-thumb {
    background: var(--scrollbar-thumb);
    border-radius: 2px;
    transition: background 0.3s ease;
}
::-webkit-scrollbar-thumb:hover {
    background: var(--scrollbar-thumb-hover);
}

input[type="number"] {
    -moz-appearance: textfield;
    appearance: textfield;
}
input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

/* ============================================================
   공통 레이아웃
   ============================================================ */
* {
    box-sizing: border-box;
}

body {
    background-color: var(--bg-color);
    color: var(--text-color);
    font-family: 'Pretendard', -apple-system, sans-serif;
    display: flex;
    flex-direction: column;
    height: 100dvh;
    overflow: hidden;
    max-width: 1200px;
    margin: 0 auto;
    border-left: 1px solid var(--border-color);
    border-right: 1px solid var(--border-color);
    transition: background-color 0.3s, color 0.3s;
    touch-action: manipulation;
}

.hidden {
    display: none !important;
}

/* ============================================================
   헤더 / 푸터
   ============================================================ */
header,
footer {
    background-color: var(--card-bg);
    border-bottom: 1px solid var(--border-color);
    padding: 0 20px;
    display: flex;
    align-items: center;
    flex-shrink: 0;
    flex-wrap: nowrap;
    overflow-x: auto;
}

header {
    height: 40px;
    justify-content: space-between;
}

footer {
    height: 50px;
    border-top: 1px solid var(--border-color);
    justify-content: space-around;
}

.header-logo {
    font-weight: bold;
    color: var(--point-color);
    letter-spacing: 2px;
}

.header-right {
    display: flex;
    gap: 15px;
    align-items: center;
}

.header-stats {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 2px;
    padding: 0 10px;
    border-left: 1px solid var(--border-color);
    border-right: 1px solid var(--border-color);
    font-size: 0.78rem;
    line-height: 1.2;
}

.header-ap {
    color: var(--point-color);
    font-weight: bold;
}

.ap-full-timer {
    font-size: 0.72rem;
    font-weight: normal;
    color: var(--footer-color);
    margin-left: 4px;
}

/* ============================================================
   메인 레이아웃
   ============================================================ */
main {
    display: flex;
    flex-direction: column;
    width: 100%;
    flex: 1;
    overflow: hidden;
    padding: 3px;
    background-color: var(--bg-color);
}

#content-view {
    flex: 1;
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
}

#game-container {
    display: flex;
    flex-direction: column;
    height: 100dvh;
    width: 100%;
}

/* ============================================================
   내비게이션
   ============================================================ */
.nav-btn {
    background: none;
    border: none;
    color: var(--text-color);
    font-size: 15px;
    cursor: pointer;
    opacity: 0.7;
    white-space: nowrap;
    flex-shrink: 0;
    padding: 0 4px;
    text-align: center;
}

.nav-btn-key {
    display: inline;
    font-size: 0.85em;
    opacity: 0.75;
    font-weight: normal;
}

.nav-btn:hover {
    opacity: 1;
    color: var(--point-color);
}

/* ============================================================
   공통 테이블
   ============================================================ */
.inventory-table,
.monster-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.88rem;
}

.inventory-table th,
.monster-table th,
.skill-list-table thead th {
    background: var(--card-bg);
    color: var(--point-color);
    padding: 8px 8px;
    text-align: left;
    border-bottom: 2px solid var(--border-color);
    font-weight: 500;
}

.inventory-table td,
.monster-row td,
.skill-list-table tbody td {
    padding: 10px 12px;
    color: var(--text-color);
    border-bottom: 1px solid var(--border-color);
    vertical-align: middle;
}

.inventory-table tr:hover,
.monster-row:hover,
.skill-list-table tbody tr:hover {
    background: rgba(212, 175, 55, 0.05);
}

/* ============================================================
   캐릭터 생성
   ============================================================ */
.container {
    width: 90%;
    max-width: 450px;
    margin: auto;
    padding: 25px;
    background-color: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
}

.input-group {
    margin-bottom: 20px;
}

.input-group input {
    width: 100%;
    padding: 12px;
    background: var(--input-bg);
    border: 1px solid var(--border-color);
    color: var(--input-text);
    border-radius: 6px;
    margin-top: 8px;
}

.nickname-msg {
    font-size: 0.85rem;
    margin-top: 5px;
}

.selection-group {
    margin-bottom: 15px;
}

.selection-group p {
    margin: 0 0 8px 0;
    font-size: 14px;
    color: var(--point-color);
}

.submit-btn {
    width: 100%;
    padding: 15px;
    background-color: var(--point-color);
    border-radius: 6px;
    margin-top: 10px;
}

/* ── 캐릭터 생성 스프라이트 미리보기 ── */
.sprite-preview-section {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin: 16px 0 8px;
    gap: 6px;
}

.sprite-preview-section canvas {
    background: var(--bg-color);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    image-rendering: pixelated;
}

.sprite-anim-label {
    font-size: 0.78rem;
    color: var(--footer-color);
    text-transform: uppercase;
    letter-spacing: 1px;
}

/* ============================================================
   공통 유틸
   ============================================================ */
.placeholder {
    color: var(--footer-color);
    font-size: 0.85rem;
    text-align: center;
    grid-column: 1 / -1;
    padding: 20px;
}

.stat-badge {
    background: rgba(255, 215, 0, 0.1);
    color: var(--point-color);
    font-size: 0.65rem;
    padding: 1px 5px;
    border-radius: 3px;
    border: 1px solid rgba(255, 215, 0, 0.3);
}

.mobile-spacer {
    display: none;
}

.batch-action-bar {
    position: sticky;
    bottom: 16px;
    align-self: center;
    margin: 8px auto 0;
    width: fit-content;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 10px 18px;
    background: var(--card-bg);
    border: 1px solid var(--point-color);
    border-radius: 8px;
    font-size: 0.88rem;
    font-weight: bold;
    color: var(--point-color);
    z-index: 50;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.35);
    max-width: calc(100% - 32px);
}

.batch-action-bar.hidden {
    display: none;
}

.shop-check,
.inv-check {
    width: 16px;
    height: 16px;
    cursor: pointer;
    accent-color: var(--point-color);
}

#shop-check-all,
#inv-check-all {
    width: 16px;
    height: 16px;
    cursor: pointer;
    accent-color: var(--point-color);
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(4px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.battle-btn,
.battle-back-btn,
.tournament-btn,
.board-write-btn,
.board-submit-btn,
.board-search-btn,
.shop-buy-btn,
.bs-learn-btn,
.submit-btn,
.quest-claim-btn {
    background: var(--point-color);
    color: var(--input-text);
    border: none;
    font-weight: bold;
    cursor: pointer;
}

.battle-btn:hover,
.battle-back-btn:hover,
.tournament-btn:hover,
.board-write-btn:hover,
.board-submit-btn:hover,
.board-search-btn:hover,
.shop-buy-btn:hover,
.bs-learn-btn:hover,
.submit-btn:hover,
.quest-claim-btn:hover {
    opacity: 0.85;
}

/* ── 캐릭터 선택 그리드 (애니메이션 카드) ── */
.animation-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    margin-top: 8px;
}

.animation-card {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 12px 8px;
    background: var(--input-bg);
    border: 2px solid var(--border-color);
    border-radius: 8px;
    cursor: pointer;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.animation-card:hover {
    border-color: var(--point-color);
}

.animation-card.selected {
    border-color: var(--point-color);
    box-shadow: 0 0 0 2px var(--point-color);
}

.animation-card canvas {
    image-rendering: pixelated;
    background: transparent;
}

.animation-card .anim-card-name {
    font-size: 0.82rem;
    color: var(--text-color);
    font-weight: 500;
    text-align: center;
}

.animation-card input[type="radio"] {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

button {
    white-space: nowrap;
}

/* ============================================================
   설정 모달
   ============================================================ */
.settings-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
}

.settings-modal-overlay.hidden {
    display: none;
}

.settings-modal {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    width: 360px;
    max-width: 92vw;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}

.settings-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px 12px;
    border-bottom: 1px solid var(--border-color);
}

.settings-modal-header h3 {
    margin: 0;
    font-size: 1rem;
}

.settings-modal-close {
    background: none;
    border: none;
    color: var(--text-color);
    font-size: 1.2rem;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
}

.settings-modal-close:hover {
    background: var(--input-bg);
}

.settings-modal-body {
    padding: 16px 20px;
}

.settings-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 0;
    border-bottom: 1px solid var(--border-color);
}

.settings-row:last-child {
    border-bottom: none;
}

.settings-label {
    font-size: 0.9rem;
    font-weight: bold;
    color: var(--text-color);
}

.settings-toggle-btn {
    background: var(--input-bg);
    border: 1px solid var(--border-color);
    color: var(--text-color);
    padding: 6px 14px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.85rem;
    font-family: 'Pretendard', sans-serif;
    min-width: 80px;
    text-align: center;
}

.settings-link-btn {
    display: inline-block;
    text-decoration: none;
    line-height: 1.4;
}

.settings-toggle-btn:hover {
    border-color: var(--point-color);
    color: var(--point-color);
}

.settings-volume-group {
    display: flex;
    align-items: center;
    gap: 10px;
}

.settings-slider {
    width: 120px;
    accent-color: var(--point-color);
    cursor: pointer;
}

.settings-volume-value {
    font-size: 0.82rem;
    color: var(--text-muted-color);
    min-width: 36px;
    text-align: right;
}

/* 설정 버튼 */
#settings-btn {
    background: none;
    border: none;
    font-size: 1.2rem;
    cursor: pointer;
    padding: 4px;
    line-height: 1;
}

/* ============================================================
   공용 확인 모달
   ============================================================ */
.confirm-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.55);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10001; /* 설정 모달(9999)보다 위 */
}

.confirm-modal-overlay.hidden {
    display: none;
}

.confirm-modal {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    width: 320px;
    max-width: 92vw;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.35);
}

.confirm-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 18px 10px;
    border-bottom: 1px solid var(--border-color);
}

.confirm-modal-header h3 {
    margin: 0;
    font-size: 0.95rem;
    color: var(--text-color);
}

.confirm-modal-close {
    background: none;
    border: none;
    color: var(--text-color);
    font-size: 1rem;
    cursor: pointer;
    padding: 2px 6px;
    border-radius: 4px;
}

.confirm-modal-close:hover {
    background: var(--input-bg);
}

.confirm-modal-body {
    padding: 18px 18px 6px;
}

.confirm-modal-body p {
    margin: 0;
    font-size: 0.88rem;
    color: var(--text-color);
    line-height: 1.55;
    white-space: pre-wrap;
}

/* ════════════════════════════════════════
   크레딧 모달 (settings-modal 톤을 따라감)
   ════════════════════════════════════════ */
.credits-modal-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
}
.credits-modal-overlay.hidden { display: none; }
.credits-modal {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    width: 420px;
    max-width: 92vw;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}
.credits-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px 12px;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}
.credits-modal-header h3 { margin: 0; font-size: 1rem; }
.credits-modal-close {
    background: none;
    border: none;
    color: var(--text-color);
    font-size: 1.2rem;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
}
.credits-modal-close:hover { background: var(--input-bg); }
.credits-modal-body {
    padding: 16px 20px 20px;
    overflow-y: auto;
}
.credits-section { padding: 10px 0; border-bottom: 1px solid var(--border-color); }
.credits-section:last-of-type { border-bottom: none; }
.credits-section-title {
    margin: 0 0 6px 0;
    font-size: 0.9rem;
    font-weight: bold;
    color: var(--point-color);
}
.credits-section-body {
    margin: 0;
    font-size: 0.85rem;
    color: var(--text-color);
    line-height: 1.5;
}
.credits-section-license {
    margin: 4px 0 0 0;
    font-size: 0.78rem;
    color: var(--footer-color);
}
.credits-section-body a,
.credits-section-license a {
    color: var(--point-color);
    text-decoration: underline;
    text-underline-offset: 2px;
}
.credits-section-body a:hover,
.credits-section-license a:hover { opacity: 0.8; }
.credits-footer {
    margin: 14px 0 0 0;
    font-size: 0.78rem;
    color: var(--footer-color);
    text-align: center;
    font-style: italic;
}

.confirm-suppress-row {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 12px;
    padding: 6px 8px;
    background: var(--input-bg);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-size: 0.8rem;
    color: var(--footer-color);
    cursor: pointer;
    user-select: none;
}
.confirm-suppress-row:hover { color: var(--text-color); border-color: var(--point-color); }
.confirm-suppress-row.hidden { display: none; }
.confirm-suppress-row input[type="checkbox"] { width: 14px; height: 14px; cursor: pointer; flex-shrink: 0; }

.confirm-modal-footer {
    display: flex;
    gap: 8px;
    padding: 12px 18px 16px;
}

.confirm-btn {
    flex: 1;
    padding: 8px 0;
    border-radius: 6px;
    font-size: 0.88rem;
    font-family: 'Pretendard', sans-serif;
    font-weight: 500;
    cursor: pointer;
    transition: opacity 0.15s, border-color 0.15s;
}

.confirm-btn.cancel {
    background: transparent;
    color: var(--text-color);
    border: 1px solid var(--border-color);
}

.confirm-btn.cancel:hover {
    border-color: var(--point-color);
    color: var(--point-color);
}

.confirm-btn.ok {
    background: var(--point-color);
    color: var(--input-text);
    border: 1px solid var(--point-color);
}

.confirm-btn.ok:hover {
    opacity: 0.85;
}

/* 파괴적 액션 (로그아웃, 삭제 등) */
.confirm-btn.ok.danger {
    background: #a32d2d;
    border-color: #a32d2d;
    color: #fceae9;
}

.confirm-btn.ok.danger:hover {
    opacity: 0.85;
}

/* 로그아웃 버튼 hover 시 빨간 톤 */
.settings-logout-btn:hover {
    border-color: #a32d2d !important;
    color: #a32d2d !important;
}

body.mobile-layout .animation-grid {
    grid-template-columns: repeat(2, 1fr);
}

/* ── 모바일: 캐릭터 생성 컨테이너 ── */
body.mobile-layout #create-character-section {
    width: 100%;
    max-width: none;
    height: 100%;
    margin: 0;
    padding: 16px;
    border: none;
    border-radius: 0;
    box-shadow: none;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

/* 모바일: 스프라이트 미리보기 캔버스 — 컨테이너 폭 안에 안전하게 */
body.mobile-layout #sprite-canvas {
    max-width: 100%;
    height: auto;
}