/* book_adventure.css */

:root {
    --game-bg-dark: #000a14;
    --game-gold: #ffd700;
    --game-gold-glow: rgba(255, 215, 0, 0.6);
    --game-blue: #00bfff;
    --game-glass: rgba(16, 28, 45, 0.85);
    --game-border: 1px solid rgba(255, 215, 0, 0.3);
    --node-locked: #4a5568;
    --node-unlocked: #ffd700;
    --node-completed: #48bb78;
}

body {
    overflow-x: hidden;
    /* Prevent horizontal scroll on body, let map wrapper handle it */
}

/* Book Intro Section (Game Page Specific) */
.book-intro {
    display: flex;
    flex-direction: row;
    /* Side by side */
    align-items: center;
    gap: 40px;
    background: rgba(0, 17, 34, 0.6);
    border: 1px solid rgba(255, 215, 0, 0.2);
    border-radius: 12px;
    padding: 30px;
    backdrop-filter: blur(10px);
    margin-bottom: 20px;
}

.book-cover {
    flex: 0 0 200px;
    width: 200px;
    height: 280px;
    /* Force vertical aspect ratio */
    position: relative;
    border-radius: 8px;
    overflow: hidden;
    /* Crop external parts */
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.5);
    border: 1px solid rgba(255, 215, 0, 0.3);
    background: transparent;
}

.book-cover img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    /* Show full image without cropping */
    object-position: center;
    display: block;
    /* Removed mix-blend-mode as cropping is cleaner */
}

.book-info {
    flex: 1;
    text-align: left;
}

.book-info h2 {
    color: var(--game-gold);
    margin-bottom: 15px;
    font-size: 1.8rem;
}

.book-info p {
    color: #e2e8f0;
    margin-bottom: 15px;
    line-height: 1.7;
}

/* 遊戲主容器 */
.game-container {
    position: relative;
    width: 100%;
    height: auto;
    /* Fixed height window for the game -> Changed to auto for full page scroll */
    min-height: 100vh;
    margin-bottom: 0;
    /* padding-top removed as it's not top-level anymore */
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border-top: 1px solid rgba(255, 215, 0, 0.3);
    /* border-bottom removed to merge with footer */
    background: radial-gradient(circle at center, #0B1021 0%, #000 100%);
}

/* 抬頭顯示器 (HUD) - 改為頂部工具列 */
.game-hud {
    position: relative;
    /* Changed from absolute to relative */
    top: auto;
    left: auto;
    width: 100%;
    z-index: 20;
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    padding: 10px 20px;
    background: rgba(0, 10, 20, 0.8);
    border-bottom: 1px solid rgba(255, 215, 0, 0.2);
    gap: 15px;
    flex-wrap: wrap;
    /* Allow wrapping on small screens */
}

.hud-item {
    background: rgba(255, 255, 255, 0.05);
    /* Lighter bg for toolbar feel */
    border: 1px solid rgba(255, 215, 0, 0.2);
    backdrop-filter: blur(5px);
    padding: 5px 15px;
    border-radius: 20px;
    /* Pillow shape */
    color: #fff;
    box-shadow: none;
    min-width: auto;
    display: flex;
    align-items: center;
    gap: 10px;
}

.hud-item .label {
    font-size: 0.75rem;
    color: #a0aec0;
    margin: 0;
    white-space: nowrap;
}

.hud-item .value {
    font-size: 1rem;
    font-weight: 700;
    color: var(--game-gold);
    text-shadow: 0 0 5px var(--game-gold-glow);
    margin: 0;
    white-space: nowrap;
}

.hud-actions {
    display: flex;
    gap: 10px;
    margin-top: 0;
}

.btn-hud {
    padding: 5px 12px;
    background: rgba(0, 0, 0, 0.4);
    border: 1px solid #4a5568;
    color: #e2e8f0;
    border-radius: 15px;
    cursor: pointer;
    font-size: 0.8rem;
    transition: all 0.2s;
    white-space: nowrap;
}

.btn-hud:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: #cbd5e0;
}

.btn-hud.danger {
    border-color: #fc8181;
    color: #fc8181;
}

.btn-hud.danger:hover {
    background: rgba(252, 129, 129, 0.1);
}

/* 地圖容器 */
.game-map-wrapper {
    flex: 1;
    position: relative;
    overflow: auto;
    /* Enable scrolling for the map */
    background: transparent;
    cursor: grab;
    /* Hide Scrollbar but keep functionality */
    scrollbar-width: none;
    /* Firefox */
    -ms-overflow-style: none;
    /* IE and Edge */
}

.game-map-wrapper::-webkit-scrollbar {
    display: none;
    /* Chrome, Safari, etc. */
}

.game-map-wrapper:active {
    cursor: grabbing;
}

#game-canvas {
    display: block;
    /* Canvas size will be set by JS */
}

/* 玩家 Avatar */
.player-avatar {
    position: absolute;
    width: 40px;
    height: 40px;
    transform: translate(-50%, -50%);
    /* Center on coordinates */
    transition: top 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275), left 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    z-index: 10;
    pointer-events: none;
    /* Let clicks pass through to canvas */
}

.player-avatar img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    filter: drop-shadow(0 0 10px var(--game-gold));
}

.avatar-glow {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 100%;
    height: 100%;
    transform: translate(-50%, -50%);
    border-radius: 50%;
    background: radial-gradient(circle, var(--game-gold-glow) 0%, transparent 70%);
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0% {
        transform: translate(-50%, -50%) scale(1);
        opacity: 0.8;
    }

    50% {
        transform: translate(-50%, -50%) scale(1.5);
        opacity: 0.4;
    }

    100% {
        transform: translate(-50%, -50%) scale(1);
        opacity: 0.8;
    }
}

/* Tooltip */
.node-tooltip {
    position: absolute;
    background: rgba(0, 10, 20, 0.95);
    border: 1px solid var(--game-gold);
    padding: 10px 15px;
    border-radius: 8px;
    color: #fff;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.2s;
    z-index: 20;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.5);
    min-width: 150px;
    transform: translate(-50%, -130%);
    /* Position above cursor/node */
}

.node-tooltip.visible {
    opacity: 1;
}

#tooltip-title {
    font-size: 0.9rem;
    color: var(--game-gold);
    margin: 0 0 5px 0;
}

#tooltip-desc {
    font-size: 0.8rem;
    color: #cbd5e0;
    margin: 0 0 5px 0;
}

.tooltip-status {
    font-size: 0.7rem;
    padding: 2px 6px;
    border-radius: 4px;
    display: inline-block;
    text-transform: uppercase;
}

.status-locked {
    background: #2d3748;
    color: #a0aec0;
}

.status-unlocked {
    background: #d69e2e;
    color: #fff;
}

.status-completed {
    background: #38a169;
    color: #fff;
}

/* Modal Styles */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(5px);
}

.modal.active {
    display: flex;
}

.modal-content {
    background: rgba(16, 28, 45, 0.95);
    border: 1px solid var(--game-gold);
    border-radius: 12px;
    width: 90%;
    max-width: 800px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 0 30px rgba(255, 215, 0, 0.2);
    animation: slideIn 0.3s ease-out;
}

.reader-modal-content {
    max-width: 900px;
    height: 85vh;
}

@keyframes slideIn {
    from {
        transform: translateY(20px);
        opacity: 0;
    }

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

.modal-header {
    padding: 15px 20px;
    border-bottom: 1px solid rgba(255, 215, 0, 0.2);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h2 {
    color: var(--game-gold);
    font-size: 1.2rem;
    margin: 0;
}

.modal-close {
    background: none;
    border: none;
    color: #a0aec0;
    font-size: 1.5rem;
    cursor: pointer;
    transition: color 0.2s;
}

.modal-close:hover {
    color: #fff;
}

.modal-body {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    color: #e2e8f0;
    font-size: 1.1rem;
    line-height: 1.8;
}

/* Reader Content Styling */
#reader-body {
    font-family: 'Noto Serif TC', serif;
    text-align: justify;
}

#reader-body p {
    margin-bottom: 1em;
    text-indent: 2em;
}

#reader-body h3 {
    color: var(--game-gold);
    margin-top: 1.5em;
    margin-bottom: 0.5em;
    text-align: center;
}

.modal-footer {
    padding: 15px 20px;
    border-top: 1px solid rgba(255, 215, 0, 0.2);
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

/* Buttons */
.btn {
    padding: 10px 20px;
    border-radius: 6px;
    font-weight: 600;
    cursor: pointer;
    border: none;
    transition: all 0.2s;
}

.btn-primary {
    background: linear-gradient(135deg, #b7950b 0%, #ffd700 100%);
    color: #1a202c;
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(255, 215, 0, 0.4);
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: #fff;
}

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.2);
}

.btn-glow {
    animation: btnPulse 2s infinite;
}

@keyframes btnPulse {
    0% {
        box-shadow: 0 0 5px rgba(255, 215, 0, 0.5);
    }

    50% {
        box-shadow: 0 0 20px rgba(255, 215, 0, 0.8);
    }

    100% {
        box-shadow: 0 0 5px rgba(255, 215, 0, 0.5);
    }
}

.hidden {
    display: none !important;
}

/* Quiz Styling */
.quiz-question {
    margin-bottom: 20px;
}

.quiz-q-text {
    font-size: 1.2rem;
    font-weight: bold;
    margin-bottom: 15px;
    color: #fff;
}

.quiz-options {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.quiz-option {
    padding: 12px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
}

.quiz-option:hover {
    background: rgba(255, 215, 0, 0.1);
    border-color: rgba(255, 215, 0, 0.5);
}

.quiz-option.selected {
    background: rgba(255, 215, 0, 0.2);
    border-color: var(--game-gold);
    color: var(--game-gold);
}

.quiz-option.correct {
    background: rgba(72, 187, 120, 0.3);
    border-color: #48bb78;
}

.quiz-option.wrong {
    background: rgba(245, 101, 101, 0.3);
    border-color: #f56565;
}

/* Level Up Overlay */
.levelup-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.9);
    z-index: 2000;
    display: flex;
    justify-content: center;
    align-items: center;
}

.levelup-content {
    text-align: center;
    animation: zoomIn 0.5s ease-out;
}

.levelup-text {
    font-size: 4rem;
    color: var(--game-gold);
    text-transform: uppercase;
    text-shadow: 0 0 20px var(--game-gold);
    margin: 0;
}

.levelup-sub {
    font-size: 1.5rem;
    color: #fff;
    margin: 10px 0 30px 0;
}

@keyframes zoomIn {
    from {
        transform: scale(0.5);
        opacity: 0;
    }

    to {
        transform: scale(1);
        opacity: 1;
    }
}

/* Mobile Responsive For Intro */
@media (max-width: 768px) {
    .book-intro {
        flex-direction: column;
        text-align: center;
        gap: 15px;
        padding: 20px;
    }

    .book-info {
        text-align: center;
    }

    .book-cover {
        flex: 0 0 auto;
        width: 100%;
        max-width: 180px;
        height: auto;
        margin-bottom: 0;
    }

    .book-cover img {
        height: auto;
        max-height: 50vh;
    }

    .game-hud {
        left: 10px;
        right: 10px;
        top: 10px;
        flex-direction: row;
        flex-wrap: wrap;
        justify-content: space-between;
    }

    .hud-item {
        min-width: unset;
        flex: 1;
    }

    .hud-actions {
        width: 100%;
        justify-content: center;
    }

    /* 優化手機端頁面流程，避免過長導致 footer 被遺忘 */
    .hero {
        min-height: 30vh !important;
        padding: calc(var(--nav-height) + 20px) 0 20px !important;
    }

    .section {
        padding: 30px 0 !important;
    }

    .book-intro {
        margin-bottom: 0 !important;
    }

    .game-container {
        height: auto;
        /* 稍微縮小遊戲視窗，讓下方內容更易被察覺 */
        margin-bottom: 0;
    }
}

/* ========================================
   🐉 龍角色對話框樣式
   ======================================== */
.dragon-dialog {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    top: 0;
    background: rgba(0, 0, 0, 0.7);
    z-index: 2000;
    align-items: flex-end;
    justify-content: center;
    backdrop-filter: blur(3px);
    padding: 20px;
    padding-bottom: 40px;
}

.dragon-dialog.active {
    display: flex;
}

.dragon-dialog-container {
    display: flex;
    align-items: flex-end;
    gap: 0;
    max-width: 700px;
    width: 100%;
    animation: dragonBounceIn 0.6s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes dragonBounceIn {
    0% {
        transform: translateY(100%) scale(0.8);
        opacity: 0;
    }

    60% {
        transform: translateY(-10%) scale(1.05);
        opacity: 1;
    }

    100% {
        transform: translateY(0) scale(1);
        opacity: 1;
    }
}

/* 龍角色圖片 */
.dragon-character {
    flex: 0 0 200px;
    /* 增加寬度 */
    position: relative;
    z-index: 2;
    margin-right: -40px;
    margin-bottom: -20px;
    /* 讓龍更往下沉一點 */
    animation: dragonFloat 3s ease-in-out infinite;
}

@keyframes dragonFloat {

    0%,
    100% {
        transform: translateY(0);
    }

    50% {
        transform: translateY(-8px);
    }
}

.dragon-image {
    width: 200px;
    /* 稍微放大一點因為中國龍比較長條 */
    height: auto;
    filter: drop-shadow(0 0 10px rgba(255, 215, 0, 0.5));
    mix-blend-mode: screen;
    /* 關鍵：讓黑色背景變透明，保留發光部分 */
}

/* 對話泡泡 */
.dragon-speech-bubble {
    flex: 1;
    background: linear-gradient(135deg, rgba(255, 248, 230, 0.98) 0%, rgba(255, 240, 200, 0.98) 100%);
    border-radius: 20px;
    border: 3px solid #FFD700;
    box-shadow:
        0 10px 40px rgba(0, 0, 0, 0.3),
        0 0 30px rgba(255, 215, 0, 0.2),
        inset 0 2px 0 rgba(255, 255, 255, 0.8);
    padding: 25px 30px;
    position: relative;
    min-height: 120px;
    animation: bubblePop 0.4s ease-out 0.2s both;
}

@keyframes bubblePop {
    0% {
        transform: scale(0.9);
        opacity: 0;
    }

    100% {
        transform: scale(1);
        opacity: 1;
    }
}

/* 對話泡泡的小尖角 */
.dragon-speech-bubble::before {
    content: '';
    position: absolute;
    left: -15px;
    bottom: 30px;
    border: 15px solid transparent;
    border-right-color: #FFD700;
    border-left: none;
}

.dragon-speech-bubble::after {
    content: '';
    position: absolute;
    left: -10px;
    bottom: 33px;
    border: 12px solid transparent;
    border-right-color: rgba(255, 248, 230, 0.98);
    border-left: none;
}

.speech-bubble-content {
    margin-bottom: 20px;
}

.dragon-title {
    color: #B8860B;
    font-size: 1.3rem;
    margin: 0 0 12px 0;
    font-family: 'Noto Serif TC', serif;
    font-weight: 700;
    text-shadow: 1px 1px 0 rgba(255, 255, 255, 0.5);
}

.dragon-message {
    color: #4A4A4A;
    font-size: 1.1rem;
    line-height: 1.7;
    margin: 0;
    font-family: 'Noto Sans TC', sans-serif;
}

.dragon-buttons {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    padding-top: 10px;
    border-top: 1px solid rgba(184, 134, 11, 0.2);
}

.dragon-buttons .btn {
    padding: 10px 24px;
    font-size: 1rem;
    border-radius: 25px;
    font-weight: 600;
    transition: all 0.3s;
}

.dragon-buttons .btn-primary {
    background: linear-gradient(135deg, #FFD700 0%, #FFA500 100%);
    color: #5D4037;
    border: 2px solid #B8860B;
}

.dragon-buttons .btn-primary:hover {
    transform: translateY(-3px) scale(1.05);
    box-shadow: 0 8px 25px rgba(255, 165, 0, 0.5);
}

.dragon-buttons .btn-secondary {
    background: rgba(255, 255, 255, 0.8);
    border: 2px solid #CBD5E0;
    color: #4A5568;
}

.dragon-buttons .btn-secondary:hover {
    background: rgba(255, 255, 255, 1);
    border-color: #A0AEC0;
}

/* 響應式調整 */
@media (max-width: 600px) {
    .dragon-dialog {
        padding: 15px;
        padding-bottom: 20px;
    }

    .dragon-dialog-container {
        flex-direction: column;
        align-items: center;
    }

    .dragon-character {
        flex: none;
        margin-right: 0;
        margin-bottom: -50px;
        /* 龍頭的位置調整 */
        z-index: 3;
    }

    .dragon-image {
        width: 140px;
        /* 稍微放大 */
    }

    .dragon-speech-bubble {
        padding: 50px 20px 20px 20px;
    }

    .dragon-speech-bubble::before,
    .dragon-speech-bubble::after {
        display: none;
    }

    .dragon-title {
        font-size: 1.1rem;
        text-align: center;
    }

    .dragon-message {
        font-size: 1rem;
        text-align: center;
    }

    .dragon-buttons {
        justify-content: center;
    }
}

/* ========================================
   📱 手機版字體與閱讀體驗優化
   ======================================== */
@media (max-width: 768px) {

    /* 1. 閱讀視窗優化 */
    .modal-body {
        font-size: 1.25rem !important;
        /* 加大內文字體 (約 20px) */
        padding: 15px !important;
        /* 減少邊距，增加閱讀寬度 */
    }

    #reader-body p {
        line-height: 1.9 !important;
        /* 增加行高，提升閱讀舒適度 */
        margin-bottom: 1.5em !important;
        /* 段落間距加大 */
    }

    #reader-body h3 {
        font-size: 1.6rem !important;
        /* 章節標題加大 */
        margin-top: 1em !important;
    }

    /* 2. 龍對話框優化 */
    .dragon-message {
        font-size: 1.2rem !important;
        line-height: 1.6 !important;
    }

    .dragon-title {
        font-size: 1.4rem !important;
    }

    /* 3. 按鈕優化 (更好點擊) */
    .btn {
        font-size: 1.1rem !important;
        padding: 12px 20px !important;
    }

    .dragon-buttons .btn {
        font-size: 1.05rem !important;
        padding: 10px 18px !important;
    }

    /* 4. HUD 數值優化 */
    .hud-item .label {
        font-size: 0.85rem !important;
    }

    .hud-item .value {
        font-size: 1.1rem !important;
    }

    /* 5. Tooltip 優化 */
    .node-tooltip {
        padding: 12px 18px !important;
    }

    #tooltip-title {
        font-size: 1.1rem !important;
        margin-bottom: 8px !important;
    }

    #tooltip-desc {
        font-size: 0.95rem !important;
    }
}