/* ==================== 1. Global & Reset ==================== */
* {
    box-sizing: border-box;
}

body,
html {
    margin: 0;
    padding: 0;
    height: 100%;
    font-family: 'Inter', sans-serif;
    background: #111;
}

/* 動畫定義 */
@keyframes slideDown {
    from {
        transform: translateY(-30px);
        opacity: 0;
    }

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

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

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

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

/* ==================== 2. RPG Game Specific (GameBoy Style) ==================== */
/* 這是給 game.js 用的特殊頁面樣式，保留在最上方 */
/* 1. 確保 RPG 頁面鎖定視窗，禁止滑動 */
.rpg-body {
    background-color: #202020;
    color: white;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    height: 100vh;      /* 佔滿視窗高度 */
    width: 100vw;       /* 佔滿視窗寬度 */
    margin: 0;
    padding: 0;         /* 移除內距以免影響計算 */
    font-family: 'Courier New', Courier, monospace;
    overflow: hidden;   /* 關鍵！隱藏任何超出的捲軸 */
}

/* 2. 修正遊戲容器，避免邊框撐爆螢幕 */
#game-container {
    border: 10px solid #505050;
    border-radius: 10px;
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.5);
    background-color: #000;
    line-height: 0; /* 消除底部白邊 */

    /* [關鍵修正] 強制設定初始大小，避免 Phaser 慢慢縮放 */
    width: 100%;           /* 佔滿父容器寬度 */
    max-width: 800px;      /* PC 版最大寬度限制 (像 Switch 螢幕) */
    aspect-ratio: 4 / 3;   /* [新增] 鎖定長寬比，讓瀏覽器預留空間 */
    
    /* 讓它置中 */
    display: flex;
    justify-content: center;
    align-items: center;
    margin: 0 auto;        /* 水平置中 */
}

/* 確保 Canvas 圖片本身也會縮放 (雙重保險) */
#game-container canvas {
    width: 100% !important;
    height: 100% !important;
    object-fit: contain;
}

.instructions {
    margin-top: 10px;
    font-size: 12px; /* 手機版字改小一點 */
    color: #aaaaaa;
    text-transform: uppercase;
    letter-spacing: 1px;
    text-align: center;
}

/* 3. 修正虛擬控制器，讓它能適應手機寬度 */
#virtual-controller {
    display: flex;
    justify-content: space-between;
    
    width: 100%;       /* 改成 100% */
    max-width: 320px;  /* 最大才限制在 320px */
    padding: 0 20px;   /* 兩側加一點緩衝 */
    
    margin-top: 20px;
    user-select: none;
    box-sizing: border-box; /* 確保 padding 不會撐大寬度 */
}

/* 以下控制器按鈕樣式保持不變 */
.d-pad {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.middle-row {
    display: flex;
    gap: 20px;
}

.action-btn {
    display: flex;
    align-items: center;
}

#virtual-controller button {
    width: 50px;
    height: 50px;
    background: #444;
    color: white;
    border: none;
    border-radius: 5px;
    font-size: 20px;
    touch-action: manipulation;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent; /* 移除手機點擊的高亮藍框 */
}

#virtual-controller button:active {
    background: #666;
}

#btn-a {
    background: #a93b3b !important;
    border-radius: 50% !important;
}

/* ==================== 3. Menu View (Home Page) ==================== */
#view-menu {
    background: linear-gradient(135deg, #1a1a1a 0%, #2d3436 100%);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 40px 20px;
}

.menu-header {
    text-align: center;
    color: #fff;
    margin-bottom: 40px;
    animation: slideDown 0.8s ease-out;
}

.menu-title {
    font-size: 2.5rem;
    font-weight: 800;
    letter-spacing: 2px;
    margin: 0;
}

.menu-subtitle {
    font-size: 1rem;
    color: #aaa;
    margin-top: 10px;
    font-weight: 300;
}

.menu-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 25px;
    width: 100%;
    max-width: 1000px;
    padding-bottom: 80px;
}

/* 選單卡片共用 */
.menu-card {
    cursor: pointer;
    padding: 20px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    height: 140px;
    transition: transform 0.3s, box-shadow 0.3s;
    position: relative;
    overflow: hidden;
    text-decoration: none;
}

.menu-card:hover {
    transform: translateY(-5px);
    z-index: 10;
}

.card-title {
    font-size: 1.5rem;
    margin-bottom: 5px;
    font-weight: bold;
    display: flex;
    align-items: center;
    gap: 10px;
}

.card-desc {
    font-size: 0.9rem;
    opacity: 0.8;
}

/* ==================== 4. Card / Theme Styles ==================== */
/* 這些樣式同時用於 Index 的卡片 以及 各個子頁面的風格 */

/* --- Terminal Style --- */
.card-terminal,
#view-terminal {
    background-color: #0d1117;
    color: #7ee787;
    font-family: 'JetBrains Mono', monospace;
}

.card-terminal {
    border: 1px solid #30363d;
    border-left: 5px solid #7ee787;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
}

.card-terminal:hover {
    box-shadow: 0 0 15px rgba(126, 231, 135, 0.4);
}

.card-terminal .card-title::before {
    content: ">";
    color: #58a6ff;
}

/* Terminal Page Specific */
#view-terminal {
    display: flex;
    /* Flex for centering content on the page */
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding: 20px;
    min-height: 100vh;
}

.term-container {
    width: 100%;
    max-width: 650px;
}

.term-line {
    margin-bottom: 8px;
    line-height: 1.5;
}

.term-success {
    color: #7ee787;
}

.term-accent {
    color: #58a6ff;
}

.term-prompt {
    color: #7ee787;
    margin-right: 10px;
}

#term-input {
    background: transparent;
    border: none;
    color: #c9d1d9;
    font-family: inherit;
    font-size: 1rem;
    flex: 1;
    outline: none;
    width: 80%;
}

.term-secret-link {
    color: #161b22;
    text-decoration: none;
    transition: color 0.5s;
    padding: 10px;
}

.term-secret-link:hover {
    color: #58a6ff;
}


/* --- Profile Style --- */
.card-profile {
    background-color: #fff;
    color: #2d3436;
    font-family: 'Inter', sans-serif;
    border-radius: 16px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
}

.card-profile:hover {
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
}

/* Profile Page Specific */
#view-profile {
    background: #f8f9fa;
    font-family: 'Inter', sans-serif;
    color: #333;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
}

.profile-card {
    background: white;
    padding: 50px;
    border-radius: 20px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.08);
    text-align: center;
    max-width: 450px;
    position: relative;
    animation: floatUp 0.8s ease-out;
}

.profile-avatar {
    width: 120px;
    height: 120px;
    border-radius: 50%;
    object-fit: cover;
    margin-bottom: 20px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.15);
}

.profile-btn {
    display: inline-block;
    padding: 12px 30px;
    background: #2d3436;
    color: white;
    text-decoration: none;
    border-radius: 50px;
    transition: transform 0.3s;
}

.profile-lock {
    position: absolute;
    top: 20px;
    right: 20px;
    color: #eee;
    font-size: 1.2rem;
    cursor: pointer;
    transition: color 0.3s;
    padding: 10px;
}

.profile-lock:hover {
    color: #2d3436;
}


/* --- Retro Style --- */
.card-retro {
    background-color: #c0c0c0;
    color: #000;
    font-family: 'VT323', monospace;
    border: 2px solid;
    border-color: #fff #808080 #808080 #fff;
    box-shadow: 4px 4px 0px rgba(0, 0, 0, 0.5);
}

.card-retro:active {
    border-color: #808080 #fff #fff #808080;
    transform: translate(2px, 2px);
    box-shadow: none;
}

.card-retro .card-title {
    font-size: 1.8rem;
}

/* Retro Page Specific */
#view-retro {
    background-color: #008080;
    font-family: 'VT323', monospace;
    display: flex;
    flex-direction: column;
    height: 100vh;
}

.desktop-area {
    flex: 1;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    align-items: flex-start;
    position: relative;
}

.desktop-icon {
    width: 80px;
    text-align: center;
    color: white;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.desktop-icon:hover .icon-label {
    background: #000080;
    border: 1px dotted white;
}

.icon-img {
    font-size: 2.5rem;
    margin-bottom: 5px;
    text-shadow: 2px 2px 0px rgba(0, 0, 0, 0.5);
}

.retro-window {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 300px;
    background: #c0c0c0;
    border: 2px solid;
    border-color: #dfdfdf #404040 #404040 #dfdfdf;
    box-shadow: 4px 4px 10px rgba(0, 0, 0, 0.5);
    display: flex;
    flex-direction: column;
}

.win-header {
    background: #000080;
    color: white;
    padding: 4px 8px;
    font-weight: bold;
    display: flex;
    justify-content: space-between;
}

.taskbar {
    height: 40px;
    background: #c0c0c0;
    border-top: 2px solid #dfdfdf;
    display: flex;
    align-items: center;
    padding: 2px;
}


/* --- Manga Style --- */
.card-manga {
    background-color: #fff;
    color: #000;
    font-family: 'Bangers', cursive;
    border: 3px solid #000;
    box-shadow: 5px 5px 0px #000;
    background-image: radial-gradient(#000 1px, transparent 1px);
    background-size: 10px 10px;
}

.card-manga .card-content {
    background: #fff;
    padding: 5px 10px;
    border: 2px solid #000;
    transform: rotate(-1deg);
}

.card-manga:hover {
    transform: rotate(1deg) scale(1.05);
}

.card-manga .card-title {
    letter-spacing: 1px;
    font-size: 1.6rem;
}

/* Manga Page Specific */
#view-manga {
    background-color: #fff;
    background-image: radial-gradient(#000 1px, transparent 1px);
    background-size: 20px 20px;
    font-family: 'Bangers', cursive;
    display: flex;
    justify-content: center;
    align-items: center;
    color: #000;
    min-height: 100vh;
}

.comic-page {
    display: grid;
    grid-template-columns: 1fr 1.5fr;
    grid-template-rows: 1fr 1fr;
    gap: 15px;
    width: 90%;
    max-width: 800px;
    height: 80vh;
    padding: 15px;
    background: #fff;
    border: 4px solid #000;
    box-shadow: 10px 10px 0px #000;
}

.panel {
    border: 3px solid #000;
    position: relative;
    overflow: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
    background: #fff;
}

.panel-1 {
    grid-row: 1 / 3;
    /* 注意：圖片路徑需根據實際位置調整 */
    background: url('../personalpage/bg4.png') center/cover;
    filter: grayscale(100%) contrast(120%);
}

.panel-2 {
    flex-direction: column;
    padding: 20px;
    text-align: center;
}

.panel-3 {
    background: #000;
    color: #fff;
}

.comic-btn {
    background: #ff0000;
    color: #fff;
    font-family: 'Bangers', cursive;
    font-size: 1.5rem;
    padding: 10px 20px;
    border: 3px solid #000;
    text-decoration: none;
    transform: rotate(2deg);
    transition: transform 0.2s;
    display: inline-block;
    margin-top: 10px;
}

.comic-btn:hover {
    transform: scale(1.1) rotate(0deg);
    background: #ff4444;
}


/* --- RPG Style (Scroll & Quest) --- */
.card-rpg {
    background-color: #f4e4bc;
    color: #3e2723;
    font-family: 'Cinzel', serif;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
    overflow: visible;
    margin: 10px 0;
    border-radius: 2px;
    background-image: url('https://www.transparenttextures.com/patterns/wood-pattern.png');
}

.card-rpg::before {
    content: '';
    position: absolute;
    top: -12px;
    left: -5%;
    width: 110%;
    height: 18px;
    background: linear-gradient(to right, #5d4037, #8d6e63, #5d4037);
    border-radius: 10px;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.5);
    z-index: 2;
}

.card-rpg::after {
    content: '';
    position: absolute;
    bottom: -12px;
    left: -5%;
    width: 110%;
    height: 18px;
    background: linear-gradient(to right, #5d4037, #8d6e63, #5d4037);
    border-radius: 10px;
    box-shadow: 0 -2px 5px rgba(0, 0, 0, 0.5);
    z-index: 2;
}

.card-rpg:hover {
    transform: scale(1.02);
    background-color: #efe0b5;
}

.card-rpg .card-title i {
    color: #d32f2f;
    filter: drop-shadow(1px 1px 0 rgba(0, 0, 0, 0.3));
}

/* RPG Page Specific (The Scroll View) */
#view-rpg {
    background: #2b2b2b url('https://www.transparenttextures.com/patterns/wood-pattern.png');
    font-family: 'Cinzel', serif;
    display: flex;
    justify-content: center;
    align-items: center;
    color: #3e2723;
    min-height: 100vh;
}

.scroll-container {
    position: relative;
    width: 350px;
    animation: unroll 1s ease-out;
    margin: 20px 0;
}

.scroll-paper {
    background: #f4e4bc;
    padding: 40px 30px;
    text-align: center;
    box-shadow: 0 0 30px rgba(0, 0, 0, 0.5);
    border-radius: 5px;
    position: relative;
    background-image: linear-gradient(#d7c69a 1px, transparent 1px), linear-gradient(90deg, #d7c69a 1px, transparent 1px);
    background-size: 20px 20px;
}

.scroll-top,
.scroll-bottom {
    height: 30px;
    background: #5d4037;
    border-radius: 15px;
    position: absolute;
    left: -20px;
    right: -20px;
    box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.5);
}

.scroll-top {
    top: -15px;
}

.scroll-bottom {
    bottom: -15px;
}

.quest-item {
    margin: 15px 0;
    padding: 10px;
    border: 1px dashed #8d6e63;
    cursor: pointer;
    transition: background 0.3s;
    display: flex;
    align-items: center;
    text-decoration: none;
    color: #3e2723;
}

.quest-item:hover {
    background: rgba(141, 110, 99, 0.2);
}

@keyframes unroll {
    from {
        height: 0;
        opacity: 0;
    }

    to {
        height: auto;
        opacity: 1;
    }
}

/* ==================== 5. RWD ==================== */
@media (max-width: 768px) {
    .menu-title {
        font-size: 2rem;
    }

    .comic-page {
        grid-template-columns: 1fr;
        grid-template-rows: 200px auto auto;
        height: auto;
        margin: 20px 0 80px 0;
    }

    .panel-1 {
        grid-row: 1;
    }
}


/* 對話框樣式 */
#dialog-box {
    position: absolute;
    bottom: 20px; /* 距離底部 */
    left: 50%;
    transform: translateX(-50%);
    width: 90%;
    max-width: 600px;
    height: 100px;
    background-color: white; /* 外框白 */
    border: 4px solid #000;  /* 內框黑邊 */
    border-radius: 8px;
    z-index: 100; /* 確保浮在最上面 */
    padding: 4px;
    box-shadow: 0 0 10px rgba(0,0,0,0.5);
    font-family: 'Courier New', monospace; /* 復古字體 */
}

#dialog-content {
    background-color: white;
    color: black;
    height: 100%;
    padding: 10px;
    font-size: 18px;
    line-height: 1.5;
    border: 2px solid #000; /* 內層細黑邊 */
    border-radius: 4px;
    box-sizing: border-box;
    white-space: pre-wrap; /* 保留換行 */
}

#dialog-next {
    position: absolute;
    bottom: 10px;
    right: 15px;
    color: red;
    animation: blink 1s infinite;
}

@keyframes blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0; }
}
