/* CSS 스타일 대폭 리팩토링: 에셋 기반 UI 적용 (Image 1 스타일) */
:root {
    --cosy-font: 'Outfit', sans-serif;
}

#loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(240, 240, 240, 0.9);
    /* light gray */
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
}

.loading-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
    background: white;
    padding: 40px;
    border-radius: 30px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.1);
    border: 5px solid #ffd6a5;
}

.loading-spinner {
    width: 60px;
    height: 60px;
    border: 5px solid #f3f3f3;
    border-top: 5px solid #833471;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}

.loading-text {
    font-family: 'Outfit', sans-serif;
    font-weight: 800;
    font-size: 20px;
    color: #833471;
}

.loading-progress-bar {
    width: 250px;
    height: 12px;
    background: #f0f0f0;
    border-radius: 6px;
    overflow: hidden;
    border: 1px solid #ddd;
}

#loading-progress-fill {
    width: 0%;
    height: 100%;
    background: linear-gradient(90deg, #ffd6a5, #833471);
    transition: width 0.3s ease;
}

body,
html {
    background-color: #1a1c2c;
    margin: 0;
    padding: 0;
    overflow: hidden;
}

#game-container {
    width: 100vw;
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
}

#game-viewport {
    position: relative;
    width: 100%;
    height: 100%;
    max-width: 1280px;
    max-height: 720px;
    background-color: #000;
    overflow: hidden;
    /* --- Modern UI Overlay --- */
}

#ui-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 10;
    font-family: 'Outfit', 'Nanum Gothic', sans-serif;
    color: #4a3e35;
}

#ui-layer * {
    pointer-events: auto;
}

/* Skill Buttons & Action Bar */
.action-buttons {
    position: absolute;
    bottom: 30px;
    right: 30px;
    display: flex;
    flex-direction: column;
    gap: 15px;
    align-items: flex-end;
}

.skill-row {
    display: flex;
    gap: 12px;
}

.skill-btn,
.attack-btn {
    width: 60px;
    height: 60px;
    background: rgba(255, 255, 255, 0.9);
    border: 3px solid #fff;
    border-radius: 50%;
    /* Circular(50%) (v1.62 Reverted) */
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    position: relative;
    font-size: 24px;
    transition: transform 0.1s, background 0.2s;
    /* Removed overflow: hidden to prevent shortcut cropping */
}

.skill-btn:active,
.attack-btn:active {
    transform: scale(0.9);
    background: #ffd6a5;
}

.skill-btn.disabled,
.attack-btn.disabled {
    cursor: default;
    pointer-events: none;
    filter: grayscale(0.8) brightness(0.7);
}

.attack-btn {
    width: 90px;
    height: 90px;
    background: #fff4ba;
}

.shortcut-badge {
    position: absolute;
    top: -10px;
    /* Adjusted to top */
    left: 50%;
    transform: translateX(-50%);
    /* Centered top */
    background: #ff6b6b;
    color: white;
    font-size: 10px;
    padding: 2px 6px;
    border-radius: 8px;
    font-weight: bold;
    border: 2px solid white;
    z-index: 12;
    pointer-events: none;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.cooldown-overlay {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 100%;
    height: 100%;
    background: conic-gradient(rgba(0, 0, 0, 0.6) var(--cd-angle, 0deg), transparent 0);
    z-index: 10;
    pointer-events: none;
    border-radius: 50%;
}

.cooldown-time {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 16px;
    font-weight: bold;
    color: white;
    text-shadow: 0 0 5px black;
    z-index: 11;
    pointer-events: none;
}

.key-hint {
    position: absolute;
    top: -8px;
    right: -8px;
    background: #ff6b6b;
    color: white;
    font-size: 10px;
    padding: 2px 6px;
    border-radius: 8px;
    font-weight: bold;
    border: 2px solid white;
}

/* Utility Bar: Floating at Bottom Center */
.utility-bar {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 15px;
    background: rgba(255, 255, 255, 0.9);
    padding: 8px 20px;
    border-radius: 40px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    backdrop-filter: blur(10px);
    border: 2px solid rgba(255, 255, 255, 0.5);
    align-items: center;
}

.inventory-trigger,
.status-trigger {
    display: flex;
    flex-direction: column;
    align-items: center;
    cursor: pointer;
    padding: 5px 10px;
    border-radius: 12px;
    transition: background 0.2s;
}

.inventory-trigger:hover,
.status-trigger:hover {
    background: rgba(255, 214, 165, 0.4);
}

.inventory-trigger span,
.status-trigger span {
    font-size: 10px;
    font-weight: bold;
    margin-top: 2px;
}

/* Popups: Centered with Paper Aesthetic */
#popup-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    pointer-events: auto;
    /* Required to block game interaction */
}

.game-popup {
    background: #fdfaf6;
    /* Warm paper color */
    border-radius: 24px;
    width: 360px;
    max-width: 90%;
    padding: 25px;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.3);
    border: 5px solid #fff;
    position: relative;
}

.popup-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    border-bottom: 2px dashed #ffd6a5;
    padding-bottom: 10px;
}

.popup-header h2 {
    font-size: 18px;
    color: #833471;
}

.close-popup {
    background: #ff6b6b;
    border: none;
    color: white;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    cursor: pointer;
    font-weight: bold;
    border: 2px solid white;
}

.inventory-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 12px;
    padding-bottom: 10px;
}

/* PC-only and Mobile-only helper classes */
.pc-only {
    display: block !important;
}

.mobile-only {
    display: none !important;
}

@media screen and (max-width: 900px) {
    .pc-only {
        display: none !important;
    }

    .mobile-only {
        display: flex !important;
    }
}

/* Popup Footer & Close Button */
.popup-footer {
    padding: 15px 0 5px 0;
    display: flex;
    justify-content: center;
    border-top: 2px dashed rgba(255, 214, 165, 0.5);
    margin-top: 10px;
}

.close-btn-bottom {
    background: linear-gradient(135deg, #ff9f43, #ee5253);
    color: white;
    border: none;
    padding: 12px 0;
    width: 160px;
    /* Fixed width to prevent vertical text */
    border-radius: 25px;
    font-size: 15px;
    font-weight: bold;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(238, 82, 83, 0.3);
    transition: all 0.2s ease;
    border: 2px solid rgba(255, 255, 255, 0.2);
    font-family: 'Outfit', 'Nanum Gothic', sans-serif;
    display: flex;
    justify-content: center;
    align-items: center;
    white-space: nowrap;
    /* Prevent vertical text */
}

.close-btn-bottom:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 15px rgba(238, 82, 83, 0.4);
    filter: brightness(1.1);
}

.close-btn-bottom:active {
    transform: translateY(1px);
}

.grid-item {
    aspect-ratio: 1;
    background: rgba(0, 0, 0, 0.05);
    border-radius: 12px;
    border: 2px solid rgba(0, 0, 0, 0.05);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    position: relative;
    font-size: 24px;
}

.item-icon {
    font-size: 28px;
}

.item-amount {
    position: absolute;
    bottom: 2px;
    right: 5px;
    font-size: 10px;
    font-weight: bold;
    color: #4a3e35;
    background: rgba(255, 255, 255, 0.8);
    padding: 0 4px;
    border-radius: 4px;
}

.status-content-wrapper {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.status-top {
    display: flex;
    gap: 15px;
    align-items: center;
}

.status-portrait {
    width: 80px;
    height: 80px;
    background: #ffd6a5;
    border-radius: 12px;
    border: 3px solid white;
}

.status-basic-info {
    flex: 1;
}

.exp-bar-container {
    margin-top: 5px;
    width: 100%;
}

.exp-label {
    font-size: 11px;
    font-weight: bold;
    color: #833471;
}

.exp-bar-bg {
    width: 100%;
    height: 10px;
    background: rgba(0, 0, 0, 0.1);
    border-radius: 5px;
    margin-top: 2px;
    overflow: hidden;
}

.exp-bar-fill {
    height: 100%;
    background: linear-gradient(90deg, #a29bfe, #6c5ce7);
    width: 0%;
    transition: width 0.3s ease;
}

.exp-remaining {
    font-size: 10px;
    color: #636e72;
    margin-top: 2px;
}

.status-stats-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 15px;
    border-top: 2px dashed #ffd6a5;
    padding-top: 15px;
}

.stat-main {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.stat-point-info {
    font-size: 12px;
    margin-bottom: 5px;
}

.stat-row-ui {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 12px;
    background: rgba(255, 255, 255, 0.5);
    padding: 6px 10px;
    border-radius: 8px;
    height: 32px;
}

.stat-value-container {
    display: flex;
    align-items: center;
    gap: 10px;
    justify-content: flex-end;
}

.stat-value {
    min-width: 25px;
    text-align: right;
    font-weight: 700;
}

.stat-controls-row {
    display: flex;
    gap: 5px;
    width: 50px;
    justify-content: flex-end;
}

.stat-up-btn,
.stat-down-btn {
    background: #ffd6a5;
    border: none;
    width: 22px;
    height: 22px;
    border-radius: 4px;
    cursor: pointer;
    font-weight: bold;
    display: flex;
    align-items: center;
    justify-content: center;
}

.stat-down-btn {
    background: #fab1a0;
}

.stat-up-btn:hover {
    background: #fab1a0;
}

.stat-down-btn:hover {
    background: #e17055;
    color: white;
}

.stat-derived {
    background: rgba(0, 0, 0, 0.03);
    border-radius: 12px;
    padding: 10px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    font-size: 11px;
}

.derived-row {
    display: flex;
    justify-content: space-between;
}

.derived-row span:last-child {
    font-weight: bold;
    color: #2d3436;
}

/* Skill Popup Styles */
.skill-content-wrapper {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.skill-point-info {
    font-size: 14px;
    font-weight: bold;
    color: #833471;
    background: #ffd6a533;
    padding: 8px 12px;
    border-radius: 12px;
    text-align: center;
    border: 1px dashed #ffd6a5;
}

.skill-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.skill-item {
    display: flex;
    align-items: center;
    gap: 12px;
    background: white;
    padding: 12px;
    border-radius: 16px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
    border: 2px solid #f0f0f0;
}

.skill-icon {
    width: 44px;
    height: 44px;
    background: rgba(0, 0, 0, 0.05);
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    border: 2px solid rgba(0, 0, 0, 0.05);
    flex-shrink: 0;
}

.skill-info {
    flex: 1;
}

.skill-name-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 4px;
}

.skill-name {
    font-weight: bold;
    font-size: 14px;
    color: #4a3e35;
}

.skill-level {
    font-size: 12px;
    font-weight: bold;
    color: #833471;
    background: #ffd6a5;
    padding: 2px 6px;
    border-radius: 8px;
}

.skill-desc {
    font-size: 11px;
    color: #636e72;
    margin: 0;
    line-height: 1.4;
}

.skill-desc small {
    color: #d35400;
}

.skill-up-btn {
    width: 32px;
    height: 32px;
    background: #ffd6a5;
    border: none;
    border-radius: 10px;
    font-size: 18px;
    font-weight: bold;
    color: #833471;
    cursor: pointer;
    box-shadow: 0 4px 0 #fab1a0;
    transition: transform 0.1s, box-shadow 0.1s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.skill-up-btn:active {
    transform: translateY(2px);
    box-shadow: 0 2px 0 #fab1a0;
}

.skill-up-btn:disabled {
    background: #eee;
    color: #aaa;
    box-shadow: 0 4px 0 #ddd;
    cursor: not-allowed;
}

.hidden {
    display: none !important;
}

/* Pointer Feedback */
#touch-pointer {
    position: absolute;
    width: 20px;
    height: 20px;
    background: rgba(255, 255, 255, 0.5);
    border: 2px solid white;
    border-radius: 50%;
    pointer-events: none;
    transform: translate(-50%, -50%);
    z-index: 1000;
}

/* Top Bar: Portrait & Stats */
.top-bar {
    position: absolute;
    top: 20px;
    left: 20px;
    display: flex;
    align-items: center;
    gap: 12px;
    background: rgba(255, 255, 255, 0.85);
    padding: 8px 16px;
    border-radius: 40px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
    backdrop-filter: blur(8px);
    border: 2px solid rgba(255, 255, 255, 0.5);
}

.portrait-container {
    width: 48px;
    height: 48px;
    background: #ffd6a5;
    border-radius: 50%;
    overflow: visible;
    /* Changed from hidden to show level badge */
    border: 2px solid #fff;
    position: relative;
}

.level-badge {
    position: absolute;
    bottom: -5px;
    right: -10px;
    background: #ffecd2;
    color: #833471;
    font-size: 10px;
    font-weight: 800;
    padding: 2px 6px;
    border-radius: 10px;
    border: 2px solid #fff;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
    white-space: nowrap;
    z-index: 5;
}

.portrait {
    width: 100%;
    height: 100%;
    background-image: url('../../assets/character_new.png');
    background-size: 400%;
    /* 4 columns */
    background-position: 0 0;
}

.stats-container {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.stat-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.stat-label {
    font-size: 10px;
    font-weight: 700;
    width: 20px;
}

.bar-bg {
    width: 100px;
    height: 16px;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 8px;
    overflow: hidden;
    position: relative;
    border: 1px solid rgba(255, 255, 255, 0.3);
}

.bar-text {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: white;
    font-size: 9px;
    font-weight: bold;
    text-shadow: 1px 1px 2px black;
    pointer-events: none;
    white-space: nowrap;
    z-index: 5;
}

.bar-fill {
    height: 100%;
    transition: width 0.3s ease;
}

.hp-fill {
    background: linear-gradient(90deg, #ff6b6b, #ee5253);
}

.mp-fill {
    background: linear-gradient(90deg, #48dbfb, #0abde3);
}

.exp-row {
    margin-top: -2px;
}

.exp-bg {
    width: 100px;
    height: 4px;
    background: rgba(0, 0, 0, 0.05);
}

.exp-fill {
    background: linear-gradient(90deg, #a29bfe, #6c5ce7);
}

/* Panels: Quest & Chat Stacking */
.left-ui-container {
    position: absolute;
    top: 110px;
    /* HP/MP 바와 겹치지 않게 하향 조정 */
    left: 20px;
    display: flex;
    flex-direction: column;
    gap: 15px;
    pointer-events: none;
    z-index: 50;
}

.left-ui-container>* {
    pointer-events: auto;
}

.quest-list-panel {
    background: rgba(253, 250, 246, 0.4);
    /* PC: 투명하게 (0.95 -> 0.4) */
    border-radius: 18px;
    width: 250px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
    backdrop-filter: blur(10px);
    border: 3px solid rgba(255, 255, 255, 0.5);
    overflow: hidden;
    animation: slideInLeft 0.5s ease-out;
}

@keyframes slideInLeft {
    from {
        opacity: 0;
        transform: translateX(-20px);
    }

    to {
        opacity: 1;
        transform: translateX(0);
    }
}

.quest-panel-header {
    background: rgba(255, 236, 210, 0.5);
    /* PC: 투명 헤더 */
    padding: 8px 15px;
    display: flex;
    align-items: center;
    gap: 8px;
    border-bottom: 2px solid rgba(255, 214, 165, 0.3);
}

.quest-panel-header h3 {
    margin: 0;
    font-size: 13px;
    font-weight: 800;
    color: #833471;
    letter-spacing: -0.5px;
}

.quest-header-icon {
    font-size: 14px;
}

.quest-items {
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    max-height: 200px;
    /* 기본값 */
    overflow-y: auto;
}

.quest-content {
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.quest-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    background: rgba(0, 0, 0, 0.03);
    border-radius: 12px;
    border: 1px solid rgba(0, 0, 0, 0.02);
    transition: all 0.2s;
}

.quest-item:hover {
    background: rgba(255, 214, 165, 0.3);
    border-color: #ffd6a5;
    transform: translateX(4px);
}

.quest-icon {
    font-size: 18px;
    flex-shrink: 0;
}

.quest-details {
    flex: 1;
}

.quest-title {
    font-size: 11px;
    font-weight: 700;
    color: #4a3e35;
    margin-bottom: 2px;
    word-break: keep-all;
    /* 단어 단위 개행 방지 */
    line-height: 1.3;
}

.quest-progress {
    font-size: 10px;
    color: #833471;
    font-weight: 600;
}

.quest-item.completed {
    background: rgba(46, 204, 113, 0.1);
    border-color: rgba(46, 204, 113, 0.2);
}

.quest-item.completed .quest-title {
    text-decoration: line-through;
    color: #7f8c8d;
}

.chat-window {
    width: 250px;
    height: 180px;
    background: rgba(253, 250, 246, 0.4);
    /* PC: 투명하게 (0.95 -> 0.4) */
    border-radius: 18px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
    border: 3px solid rgba(255, 255, 255, 0.5);
    backdrop-filter: blur(10px);
}

.chat-header {
    background: #ffecd2;
    padding: 6px 12px;
    font-size: 12px;
    font-weight: bold;
    display: flex;
    justify-content: space-between;
}

.chat-messages {
    flex: 1;
    padding: 10px;
    font-size: 12px;
    overflow-y: auto;
}

.chat-input-area {
    display: flex;
    padding: 8px;
    gap: 5px;
    border-top: 1px solid #eee;
}

.chat-input-area input {
    flex: 1;
    border: none;
    background: #f7f7f7;
    padding: 5px 10px;
    border-radius: 20px;
    font-size: 11px;
}

.send-btn {
    background: #ffd6a5;
    border: none;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    cursor: pointer;
}

/* Joystick & Buttons (Simplified) */
#joystick-container {
    position: absolute;
    bottom: 40px;
    left: 80px;
    z-index: 20;
}

#joystick-base {
    width: 100px;
    height: 100px;
    background: rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    backdrop-filter: blur(2px);
    border: 2px solid rgba(255, 255, 255, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
}

#joystick-stick {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 50px;
    height: 50px;
    background: #fff;
    border-radius: 50%;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
}

.action-buttons {
    align-items: flex-end;
}

.skill-row {
    display: flex;
    gap: 15px;
}

/* 5. 가방 아이콘: 배낭 형태 감성 (Image 1 하단 참고) */
.utility-bar {
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 20px;
}

.inventory-trigger,
.status-trigger {
    background: #fff;
    border: 4px solid #fcebb6;
    border-radius: 15px;
    padding: 10px 20px;
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: bold;
    color: #5a4a42;
    cursor: pointer;
    box-shadow: 0 4px 0 #fcebb6;
}

/* Minimap Styles */
#minimap-container {
    position: absolute;
    top: 20px;
    right: 20px;
    width: 150px;
    background: rgba(44, 62, 80, 0.6);
    /* 투명하게 변경 */
    border-radius: 12px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    backdrop-filter: blur(5px);
    border: none;
    /* v1.62 border removed from main container */
}

/* v1.62 Minimap Frame Layer Fix */
#minimap-container::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    border: 3px solid #fff;
    border-radius: 12px;
    pointer-events: none;
    z-index: 10;
}

.minimap-header {
    background: #2c3e50;
    color: #ecf0f1;
    font-size: 10px;
    font-weight: bold;
    text-align: center;
    padding: 4px 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

#minimapCanvas {
    width: 150px;
    height: 150px;
    background: transparent;
}

/* Joystick Logic (Updated for Dynamic Position) */
#joystick-area {
    position: fixed;
    top: 50px;
    /* Below Top Bar */
    left: 0;
    width: 60%;
    height: calc(100% - 150px);
    /* Leave room for bottom bar */
    z-index: 1000;
    pointer-events: auto;
    display: none;
    /* Only show on mobile */
}

#joystick-container {
    position: fixed;
    width: 150px;
    height: 150px;
    z-index: 1500;
    pointer-events: none;
    display: flex;
    justify-content: center;
    align-items: center;
}

.minimap-footer {
    font-size: 9px;
    color: #bdc3c7;
    text-align: center;
    padding: 2px 0;
    background: rgba(0, 0, 0, 0.2);
}

/* Global UI Fixes & Protection */
#ui-layer,
.menu-btn,
.skill-btn,
.attack-btn,
.quest-list-panel,
.chat-window,
#minimap-container {
    user-select: none !important;
    -webkit-user-select: none !important;
    -moz-user-select: none !important;
    -ms-user-select: none !important;
    -webkit-tap-highlight-color: transparent;
}

/* Specific fix for emojis inside buttons to prevent selection highlight */
.inner-icon,
.menu-icon,
.paw-icon,
.bag-icon,
.char-icon {
    pointer-events: none;
}

/* Minimap Menu Style (Unified Premium Look) */
.minimap-menu {
    position: absolute;
    top: 215px;
    /* Positioned below minimap (20px top + 150px canvas + approx 45px header/footer) */
    right: 20px;
    width: 150px;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    /* Changed from 4 to 3 */
    background: rgba(255, 255, 255, 0.6);
    border: 3px solid #fff;
    border-radius: 4px;
    /* Shorter corners as base */
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
    backdrop-filter: blur(5px);
    z-index: 100;
}

.menu-btn {
    pointer-events: auto !important;
    padding: 8px 0;
    text-align: center;
    cursor: pointer;
    border-right: 1px solid #ffd6a5;
    transition: background 0.2s, transform 0.1s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.menu-icon {
    font-size: 20px;
    filter: drop-shadow(0 2px 2px rgba(0, 0, 0, 0.1));
    transition: transform 0.2s;
}

.menu-btn:hover .menu-icon {
    transform: scale(1.2);
}

.menu-btn:active {
    background: #ffd6a5;
    transform: scale(0.95);
}

.menu-btn:last-child {
    border-right: none;
}

.chat-controls {
    display: flex;
    gap: 8px;
}

.minimize-btn {
    cursor: pointer;
    font-weight: bold;
    color: #833471;
    padding: 0 4px;
    transition: opacity 0.2s;
}

.minimize-btn:hover {
    opacity: 0.7;
}

/* Mobile Responsiveness (Galaxy S23 etc) - v0.7 Layout */
@media screen and (max-width: 900px) {
    .top-bar {
        top: 10px;
        left: 10px;
        transform: scale(0.7);
        transform-origin: top left;
        z-index: 100;
    }

    /* Left Side UI: Vertical stacking */
    .left-ui-container {
        position: absolute;
        top: 70px;
        left: 10px;
        display: flex;
        flex-direction: column;
        gap: 10px;
        transform: scale(0.6);
        /* 세로 모드에서 너무 크지 않게 배율 하향 (0.75 -> 0.6) */
        transform-origin: top left;
        z-index: 1100;
        pointer-events: none;
    }

    .quest-list-panel,
    .chat-window {
        position: relative !important;
        top: 0 !important;
        left: 0 !important;
        pointer-events: auto !important;
        background: rgba(253, 250, 246, 0.6) !important;
        border-width: 4px !important;
        width: 180px !important;
    }

    /* Mobile Portrait UI Layout Refinement */
    @media screen and (orientation: portrait) {

        /* 하단 중앙: 가방/스킬/내정보 바 - Safe Area 적용 (아이콘만) */
        body #ui-layer .minimap-menu {
            position: fixed !important;
            top: auto !important;
            bottom: calc(25px + env(safe-area-inset-bottom)) !important;
            left: 50% !important;
            transform: translateX(-50%) !important;

            display: flex !important;
            flex-direction: row !important;
            gap: 20px !important;

            background: none !important;
            border: none !important;
            padding: 0 !important;
            backdrop-filter: none !important;
            box-shadow: none !important;

            z-index: 2000 !important;
            width: auto !important;
            height: fit-content !important;
            max-width: none !important;
            flex-wrap: nowrap !important;
        }

        /* 전체화면 모드 시 하단 아이콘 위치 상향 조정 */
        body.is-fullscreen #ui-layer .minimap-menu {
            bottom: calc(85px + env(safe-area-inset-bottom)) !important;
        }

        /* 하단바 버튼: 아이콘만 표시 */
        body #ui-layer .minimap-menu .menu-btn {
            width: auto !important;
            height: auto !important;
            background: none !important;
            border: none !important;
            border-radius: 0 !important;
            box-shadow: none !important;

            margin: 0 !important;
            padding: 0 !important;
            display: flex !important;
            align-items: center !important;
            justify-content: center !important;
        }

        body #ui-layer .minimap-menu .menu-icon {
            font-size: 32px !important;
            filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.3)) !important;
        }

        /* 전체화면 버튼: 미니맵 아래 아이콘만 표시 (Safe Area 적용) */
        body #ui-layer #btn-fullscreen {
            position: fixed !important;
            top: calc(180px + env(safe-area-inset-top)) !important;
            right: calc(20px + env(safe-area-inset-right)) !important;
            left: auto !important;
            bottom: auto !important;

            width: auto !important;
            height: auto !important;
            background: none !important;
            border: none !important;
            box-shadow: none !important;
            backdrop-filter: none !important;

            z-index: 2000 !important;
            display: flex !important;
            align-items: center !important;
            justify-content: center !important;

            padding: 0 !important;
            transform: none !important;
        }

        /* 전체화면 모드 시 전체화면 버튼 위치 조정용 (사용자 조정 가능) */
        body.is-fullscreen #ui-layer #btn-fullscreen {
            top: calc(210px + env(safe-area-inset-top)) !important;
            right: calc(20px + env(safe-area-inset-right)) !important;
        }

        body #ui-layer #btn-fullscreen .menu-icon {
            font-size: 28px !important;
            filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.3)) !important;
        }
    }

    .chat-window {
        height: 140px;
    }

    .chat-messages {
        height: 80px;
        font-size: 11px;
    }

    .shortcut-badge {
        display: none !important;
    }

    #minimap-container {
        top: calc(10px + env(safe-area-inset-top));
        /* 상단 안전 영역 확보 */
        right: calc(10px + env(safe-area-inset-right));
        width: 110px;
        border-radius: 12px;
        z-index: 100;
        background: rgba(30, 39, 46, 0.3) !important;
        /* 더 투명하게 변경 */
        overflow: visible !important;
        /* 버튼 분리를 위해 */
        transform: scale(0.95);
        transform-origin: top right;
        display: flex;
        flex-direction: column;
        backdrop-filter: blur(2px) !important;
        /* 블러 약화 */
        border: none !important;
        /* v1.62 */
    }

    #minimap-container::after {
        border-color: rgba(255, 255, 255, 0.8) !important;
    }

    #minimapCanvas {
        width: 100%;
        height: auto;
        aspect-ratio: 1/1;
        display: block;
    }

    /* Joystick & Buttons: Positioned further to edges and smaller scale for Portrait */
    #joystick-area {
        display: block !important;
    }

    #joystick-container {
        display: none;
        /* Hidden until touch */
        opacity: 0.8;
        transform: scale(0.9) !important;
        position: fixed !important;
        bottom: auto !important;
        left: auto !important;
    }

    .action-buttons {
        right: 20px;
        bottom: 110px;
        transform: scale(1.0);
        /* 크기 축소 */
        transform-origin: bottom right;
        opacity: 0.6;
    }
}

/* Landscape mode dedicated tweaks */
@media screen and (orientation: landscape) and (max-height: 500px) {
    .left-ui-container {
        display: flex !important;
        top: 65px;
        left: 10px;
        transform: scale(0.65);
        gap: 8px;
    }

    /* 가로모드 퀘스트창 높이 확대 */
    .quest-list-panel {
        width: 180px !important;
        max-height: 180px !important;
    }

    .quest-items {
        max-height: 140px !important;
    }

    /* Landscape Chat: Centered at bottom, 3줄 출력 */
    .chat-window {
        position: fixed !important;
        left: 50% !important;
        bottom: 15px !important;
        transform: translateX(-50%) scale(0.75) !important;
        width: 450px !important;
        height: 130px !important;
        background: rgba(253, 250, 246, 0.85) !important;
        z-index: 1000;
    }

    .chat-messages {
        height: 70px !important;
        font-size: 11px !important;
        line-height: 1.4 !important;
    }

    .top-bar {
        top: 10px;
        left: 10px;
        transform: scale(0.7) !important;
    }

    #minimap-container {
        width: 110px !important;
        top: 10px;
        right: 15px;
        transform: scale(0.85) !important;
        display: flex !important;
        flex-direction: column !important;
        background: rgba(30, 39, 46, 0.3) !important;
        /* 가로 모드에서도 투명하게 */
        backdrop-filter: blur(2px) !important;
    }

    #minimapCanvas {
        height: 110px !important;
        order: 2 !important;
    }

    .minimap-header {
        order: 1 !important;
    }

    .minimap-footer {
        order: 3 !important;
        display: block !important;
        font-size: 10px;
        text-align: center;
        background: rgba(0, 0, 0, 0.3);
        color: #fff;
    }

    /* Landscape Menu: 한 줄로 미니맵 왼쪽에 배치 (겹치지 않게) */
    body #ui-layer .minimap-menu {
        position: absolute !important;
        top: 10px !important;
        right: 130px !important;
        /* 미니맵 왼쪽으로 충분히 이동 */
        bottom: auto !important;
        left: auto !important;
        transform: none !important;
        display: flex !important;
        flex-direction: row !important;
        gap: 8px !important;
        background: none !important;
        border: none !important;
        box-shadow: none !important;
        padding: 0 !important;
        width: auto !important;
        z-index: 110 !important;
    }

    body #ui-layer .minimap-menu .menu-btn {
        background: rgba(253, 250, 246, 0.85) !important;
        border: 2px solid #fff !important;
        border-radius: 8px !important;
        width: 36px !important;
        height: 36px !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        margin: 0 !important;
        position: static !important;
        padding: 6px !important;
    }

    .minimap-menu .menu-icon {
        font-size: 18px !important;
    }

    #btn-fullscreen {
        position: static !important;
    }

    #joystick-area {
        display: block !important;
        width: 50% !important;
        height: 100% !important;
        top: 0 !important;
    }

    #joystick-container {
        display: none;
        left: auto !important;
        bottom: auto !important;
        transform: scale(1.0) !important;
    }

    .action-buttons {
        right: 50px;
        bottom: 25px;
        transform: scale(0.9) !important;
    }
}

/* Common landscape/short screen adjustments */
@media screen and (max-height: 500px) and (min-width: 900px) {

    /* PC but very short window */
    .left-ui-container {
        transform: scale(0.7);
        top: 90px;
    }
}

/* Confirm & Reward Modal Styles */
.confirm-modal-overlay,
#confirm-modal {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2100;
    pointer-events: auto;
    backdrop-filter: blur(4px);
}

.confirm-content,
.reward-content {
    background: #fdfaf6;
    padding: 30px;
    border-radius: 24px;
    text-align: center;
    box-shadow: 0 15px 40px rgba(0, 0, 0, 0.3);
    border: 4px solid white;
    width: 280px;
    animation: modal-pop 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes modal-pop {
    from {
        transform: scale(0.8);
        opacity: 0;
    }

    to {
        transform: scale(1);
        opacity: 1;
    }
}

.reward-content h2 {
    color: #27ae60;
    margin-bottom: 10px;
    font-size: 20px;
}

.reward-content p {
    color: #2c3e50;
    font-weight: bold;
    margin-bottom: 20px;
}

.confirm-btn {
    background: #27ae60;
    color: white;
    border: none;
    padding: 10px 25px;
    border-radius: 12px;
    font-weight: bold;
    cursor: pointer;
    box-shadow: 0 4px 0 #219150;
    transition: transform 0.1s;
}

.confirm-btn:active {
    transform: translateY(2px);
    box-shadow: 0 2px 0 transparent;
}

#confirm-message {
    margin-bottom: 20px;
    font-size: 14px;
    font-weight: bold;
    color: #4a3e35;
    line-height: 1.5;
}

#confirm-message small {
    display: block;
    margin-top: 5px;
    color: #ff6b6b;
    font-weight: normal;
    font-size: 11px;
}

.confirm-buttons {
    display: flex;
    gap: 12px;
    justify-content: center;
}

.confirm-buttons button {
    padding: 8px 20px;
    border-radius: 12px;
    border: none;
    cursor: pointer;
    font-weight: bold;
    transition: transform 0.1s;
}

#confirm-yes {
    background: #ffd6a5;
    color: #833471;
    box-shadow: 0 4px 0 #fab1a0;
}

#confirm-no {
    background: #eee;
    color: #666;
    box-shadow: 0 4px 0 #ddd;
}

.confirm-buttons button:active {
    transform: translateY(2px);
    box-shadow: 0 2px 0 transparent;
}

/* Skill Tooltip Styles */
#skill-tooltip {
    position: absolute;
    background: rgba(253, 250, 246, 0.95);
    border: 2px solid #ffd6a5;
    padding: 12px;
    border-radius: 12px;
    width: 200px;
    pointer-events: none;
    z-index: 1100;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
    font-family: 'Outfit', sans-serif;
    transform: translate(10px, -110%);
}

.tooltip-name {
    font-weight: bold;
    color: #833471;
    margin-bottom: 4px;
    border-bottom: 1px dashed #ffd6a5;
    padding-bottom: 4px;
    font-size: 13px;
}

/* 사망 모달 스타일 */
#death-modal {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    backdrop-filter: blur(5px);
}

.death-content {
    background: #2c3e50;
    padding: 40px;
    border-radius: 30px;
    text-align: center;
    box-shadow: 0 0 50px rgba(0, 0, 0, 0.5);
    border: 5px solid #e74c3c;
    width: 300px;
    color: white;
}

.death-icon {
    font-size: 60px;
    margin-bottom: 20px;
    animation: pulse-death 2s infinite;
}

@keyframes pulse-death {
    0% {
        transform: scale(1);
        filter: drop-shadow(0 0 0 #e74c3c);
    }

    50% {
        transform: scale(1.1);
        filter: drop-shadow(0 0 20px #e74c3c);
    }

    100% {
        transform: scale(1);
        filter: drop-shadow(0 0 0 #e74c3c);
    }
}

.death-content h2 {
    font-size: 24px;
    color: #e74c3c;
    margin-bottom: 10px;
}

#death-timer-text {
    font-size: 14px;
    color: #bdc3c7;
    margin-bottom: 20px;
}

#retry-btn {
    background: #e74c3c;
    color: white;
    border: none;
    padding: 12px 30px;
    border-radius: 12px;
    font-size: 18px;
    font-weight: bold;
    cursor: pointer;
    box-shadow: 0 4px 0 #c0392b;
    transition: transform 0.1s, box-shadow 0.1s;
}

#retry-btn:active {
    transform: translateY(2px);
    box-shadow: 0 2px 0 #c0392b;
}

#retry-btn.hidden {
    display: none;
}

.tooltip-desc {
    font-size: 11px;
    color: #4a3e35;
    line-height: 1.4;
}

.current-effect {
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px dashed #ffd6a5;
    color: #2980b9;
    font-weight: bold;
}

/* README Content in History Modal */
.readme-content {
    text-align: left;
    line-height: 1.6;
    color: #333;
}

.readme-content h1,
.readme-content h2,
.readme-content h3 {
    margin-top: 20px;
    color: #2c3e50;
    border-bottom: 2px solid #ecf0f1;
    padding-bottom: 5px;
}

.readme-content ul {
    padding-left: 20px;
}

.readme-content img {
    max-width: 100%;
    height: auto;
    border-radius: 8px;
    margin: 10px 0;
}

.readme-content a {
    pointer-events: none;
    cursor: default;
    color: #833471;
    text-decoration: none;
}

/* 퀘스트 보상 버튼 */
.quest-claim-btn {
    display: inline-flex;
    /* v1.62 */
    margin-left: 8px;
    padding: 2px 8px;
    background: #4ade80;
    color: white;
    border: none;
    border-radius: 4px;
    font-size: 10px;
    font-weight: bold;
    cursor: pointer;
    box-shadow: 0 2px 0 #22c55e;
    vertical-align: middle;
    white-space: nowrap;
    /* v1.62 */
    flex-shrink: 0;
    /* v1.62 */
}

.quest-claim-btn:hover {
    background: #22c55e;
}

/* 버전 정보 아이콘 */
.version-info {
    position: absolute;
    top: calc(5px + env(safe-area-inset-top));
    /* 상단 바와 정렬 유지 */
    right: calc(160px + env(safe-area-inset-right));
    /* 미니맵 왼쪽 위치 유지 */
    background: rgba(45, 52, 54, 0.8);
    color: #f1c40f;
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 12px;
    font-family: 'Outfit', sans-serif;
    font-weight: bold;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
    transition: transform 0.2s, background 0.2s;
    cursor: pointer;
    z-index: 2000;
}

/* 전체화면 모드 시 버전 정보 위치 조정용 (사용자 조정 가능) */
body.is-fullscreen .version-info {
    top: calc(15px + env(safe-area-inset-top));
    right: calc(160px + env(safe-area-inset-right));
}

.version-info:hover {
    transform: scale(1.05);
    background: rgba(45, 52, 54, 0.95);
}

/* 히스토리 모달 내부 스타일 */
.history-content {
    max-width: 400px;
    width: 90%;
    max-height: 80vh;
    overflow-y: auto;
    background: #ffffff;
    padding: 30px;
    border-radius: 24px;
    box-shadow: 0 15px 40px rgba(0, 0, 0, 0.3);
    border: 4px solid white;
    font-family: 'Outfit', sans-serif;
}

.history-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 2px solid #ddd;
    margin-bottom: 15px;
    padding-bottom: 10px;
    position: sticky;
    top: -30px;
    /* Padding adjustment */
    background: #ffffff;
    z-index: 10;
    margin-top: -10px;
}

.close-history {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: #666;
}

.history-item {
    margin-bottom: 20px;
    padding-left: 10px;
    border-left: 3px solid #3498db;
}

.history-v {
    font-weight: bold;
    color: #2980b9;
    font-size: 16px;
}

.history-date {
    font-size: 12px;
    color: #95a5a6;
    margin-left: 10px;
}

.history-logs {
    margin-top: 5px;
    padding-left: 20px;
    font-size: 13px;
    color: #34495e;
    list-style: disc;
}

.history-logs li {
    margin-bottom: 4px;
}

/* Stat Buttons Disabled State */
.stat-up-btn.disabled,
.stat-down-btn.disabled {
    background: #dfe6e9 !important;
    color: #b2bec3 !important;
    cursor: default !important;
    box-shadow: none !important;
    transform: none !important;
}

/* Stat Prediction Highlight */
.stat-predict-inc {
    color: #2ecc71 !important;
    font-weight: bold;
}