/* ==========================================================================
   Legend of Antigravity: Style Sheet
   ========================================================================== */

:root {
    --bg-dark: #0b0b14;
    --panel-bg: rgba(18, 18, 28, 0.75);
    --panel-border: rgba(255, 255, 255, 0.08);
    --text-primary: #f0f0f8;
    --text-secondary: #a0a0b0;
    
    /* 質感主題色彩 */
    --color-gold: #ffcf33;
    --color-gold-glow: rgba(255, 207, 51, 0.3);
    --color-hp: #ff4757;
    --color-mp: #2ed573; /* 使用綠色表示活力或藍色表示法力，這裡 MP 我們用魔力青色 #00d2d3 */
    --color-mp-cyan: #00d2d3;
    --color-exp: #ff9f43; /* 橘黃色為經驗 */
    --color-shadow: rgba(0, 0, 0, 0.4);
    
    /* 字型 */
    --font-main: 'Outfit', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* {
    box-sizing: border-box;
    user-select: none;
    -webkit-user-select: none;
}

body {
    margin: 0;
    padding: 0;
    background-color: #030307;
    color: var(--text-primary);
    font-family: var(--font-main);
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    overflow: hidden;
}

/* 遊戲容器 */
#game-container {
    position: relative;
    width: 800px;
    height: 600px;
    background-color: var(--bg-dark);
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.8), 
                0 0 30px rgba(0, 210, 211, 0.1);
    border-radius: 12px;
    overflow: hidden;
    max-width: 100vw;
    max-height: 100vh;
}

/* 畫布 */
canvas {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: contain;
    image-rendering: pixelated; /* 使像素畫風清晰不模糊 */
}

/* UI 覆蓋層 */
#ui-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none; /* 穿透點擊，允許直接點擊 Canvas */
    z-index: 10;
}

#ui-overlay * {
    pointer-events: auto; /* 恢復 UI 元素本身的點擊 */
}

/* --------------------------------------------------------------------------
   HUD: 頂部狀態欄
   -------------------------------------------------------------------------- */
#hud {
    position: absolute;
    top: 16px;
    left: 16px;
    right: 16px;
    height: 72px;
    display: flex;
    align-items: center;
    background: var(--panel-bg);
    border: 1px solid var(--panel-border);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-radius: 12px;
    padding: 8px 16px;
    box-shadow: 0 8px 32px var(--color-shadow);
    transition: all 0.3s ease;
}

/* 頭像 */
.hud-avatar {
    width: 48px;
    height: 48px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 26px;
    margin-right: 12px;
    box-shadow: inset 0 0 10px rgba(0,0,0,0.5);
}

/* 狀態資訊 */
.hud-info {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 4px;
}

.hud-row-top {
    display: flex;
    align-items: center;
    gap: 10px;
}

#player-name {
    font-weight: 600;
    font-size: 15px;
    color: var(--text-primary);
    text-shadow: 1px 1px 2px rgba(0,0,0,0.8);
}

#player-level {
    font-weight: 800;
    font-size: 11px;
    color: var(--color-gold);
    background: rgba(255, 207, 51, 0.15);
    padding: 2px 6px;
    border-radius: 4px;
    border: 1px solid rgba(255, 207, 51, 0.3);
}

/* 屬性條樣式 */
.stat-bar {
    width: 220px;
    height: 10px;
    background: rgba(0, 0, 0, 0.5);
    border-radius: 5px;
    overflow: hidden;
    position: relative;
    border: 1px solid rgba(255,255,255,0.05);
}

.bar-fill {
    height: 100%;
    width: 100%;
    transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.hp-bar .bar-fill {
    background: linear-gradient(90deg, #ff4757, #ff6b81);
    box-shadow: 0 0 8px rgba(255, 71, 87, 0.5);
}

.mp-bar {
    height: 8px;
    width: 180px;
}

.mp-bar .bar-fill {
    background: linear-gradient(90deg, #00d2d3, #0a3d62);
    box-shadow: 0 0 6px rgba(0, 210, 211, 0.4);
}

.exp-bar {
    height: 4px;
    width: 200px;
}

.exp-bar .bar-fill {
    background: linear-gradient(90deg, var(--color-exp), #ffa502);
}

.bar-text {
    position: absolute;
    top: 50%;
    left: 8px;
    transform: translateY(-50%);
    font-size: 8px;
    font-weight: 600;
    color: #fff;
    pointer-events: none;
    text-shadow: 1px 1px 1px #000;
}

/* HUD 右側金幣與背包 */
.hud-right {
    display: flex;
    align-items: center;
    gap: 16px;
}

.gold-display {
    display: flex;
    align-items: center;
    gap: 6px;
    background: rgba(0, 0, 0, 0.4);
    padding: 6px 12px;
    border-radius: 20px;
    border: 1px solid rgba(255, 255, 255, 0.05);
}

.gold-icon {
    font-size: 16px;
}

#gold-count {
    font-weight: 600;
    font-size: 14px;
    color: var(--color-gold);
}

/* 背包按鈕 */
#bag-toggle-btn {
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.15);
    color: var(--text-primary);
    padding: 8px 16px;
    border-radius: 8px;
    font-weight: 600;
    font-size: 13px;
    cursor: pointer;
    transition: all 0.2s ease;
}

#bag-toggle-btn:hover {
    background: rgba(255, 255, 255, 0.18);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

#bag-toggle-btn:active {
    transform: translateY(0);
}

/* --------------------------------------------------------------------------
   MAP TOAST: 地圖提示
   -------------------------------------------------------------------------- */
#map-toast {
    position: absolute;
    top: 104px;
    left: 50%;
    transform: translateX(-50%) translateY(-20px);
    background: rgba(0, 0, 0, 0.8);
    color: var(--color-gold);
    border: 1px solid var(--color-gold);
    border-radius: 20px;
    padding: 6px 20px;
    font-weight: 600;
    font-size: 14px;
    letter-spacing: 2px;
    opacity: 0;
    transition: all 0.5s ease;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.5), 0 0 10px var(--color-gold-glow);
    z-index: 5;
}

#map-toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* --------------------------------------------------------------------------
   INTERACTION PROMPT: 互動提示
   -------------------------------------------------------------------------- */
#interaction-prompt {
    position: absolute;
    bottom: 160px;
    left: 50%;
    transform: translateX(-50%);
    display: none; /* 由 JS 依距離顯示 */
    align-items: center;
    gap: 8px;
    background: rgba(0, 0, 0, 0.85);
    border: 1px solid var(--color-gold);
    border-radius: 30px;
    padding: 8px 16px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.5), 0 0 8px var(--color-gold-glow);
    animation: pulse 1.5s infinite;
}

.key-badge {
    background: var(--color-gold);
    color: #000;
    font-weight: 800;
    font-size: 13px;
    width: 24px;
    height: 24px;
    display: flex;
    justify-content: center;
    align-items: center;
    border-radius: 4px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.5);
}

#interaction-text {
    font-size: 13px;
    font-weight: 600;
    color: #fff;
}

/* --------------------------------------------------------------------------
   DIALOGUE: 對話窗
   -------------------------------------------------------------------------- */
#dialogue-box {
    position: absolute;
    bottom: 20px;
    left: 20px;
    right: 20px;
    height: 140px;
    background: var(--panel-bg);
    border: 1px solid var(--panel-border);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-radius: 12px;
    padding: 16px 20px;
    display: none; /* 由 JS 控制開關 */
    flex-direction: column;
    justify-content: space-between;
    box-shadow: 0 -8px 32px var(--color-shadow);
    z-index: 15;
    animation: slideUp 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.dialogue-header {
    margin-bottom: 6px;
}

#dialogue-speaker {
    font-weight: 800;
    font-size: 15px;
    color: var(--color-gold);
    text-shadow: 0 0 8px var(--color-gold-glow);
    border-left: 3px solid var(--color-gold);
    padding-left: 8px;
}

.dialogue-content {
    flex: 1;
    overflow-y: auto;
}

#dialogue-text {
    margin: 4px 0 0 0;
    font-size: 14px;
    line-height: 1.5;
    color: var(--text-primary);
}

#dialogue-options {
    display: flex;
    gap: 12px;
    margin-top: 10px;
}

.option-btn {
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.15);
    color: var(--text-primary);
    padding: 6px 16px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.option-btn:hover {
    background: var(--color-gold);
    color: #000;
    border-color: var(--color-gold);
    box-shadow: 0 0 10px var(--color-gold-glow);
}

.dialogue-footer {
    text-align: right;
    font-size: 11px;
    color: var(--text-secondary);
}

/* --------------------------------------------------------------------------
   INVENTORY: 背包側面板
   -------------------------------------------------------------------------- */
#inventory-panel {
    position: absolute;
    top: 100px;
    right: 16px;
    width: 280px;
    height: 440px;
    background: var(--panel-bg);
    border: 1px solid var(--panel-border);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-radius: 12px;
    box-shadow: -8px 8px 32px var(--color-shadow);
    display: none; /* 由 JS 控制 */
    flex-direction: column;
    padding: 16px;
    z-index: 12;
    animation: slideInRight 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    padding-bottom: 8px;
}

.panel-header h3 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
    color: var(--color-gold);
}

.close-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-size: 18px;
    cursor: pointer;
    transition: color 0.2s;
}

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

.inventory-grid {
    flex: 1;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    grid-auto-rows: 50px;
    gap: 8px;
    overflow-y: auto;
    padding-right: 4px;
}

.item-slot {
    background: rgba(0, 0, 0, 0.4);
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: 8px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 20px;
    cursor: pointer;
    position: relative;
    transition: all 0.2s ease;
}

.item-slot:hover {
    background: rgba(255, 255, 255, 0.06);
    border-color: rgba(255, 255, 255, 0.2);
}

.item-slot.selected {
    border-color: var(--color-gold);
    box-shadow: 0 0 8px var(--color-gold-glow);
    background: rgba(255, 207, 51, 0.05);
}

.item-count {
    position: absolute;
    bottom: 2px;
    right: 4px;
    font-size: 9px;
    background: rgba(0,0,0,0.7);
    color: #fff;
    padding: 1px 4px;
    border-radius: 4px;
    font-weight: 600;
}

/* 物品說明區 */
.item-detail-box {
    height: 110px;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 8px;
    margin-top: 12px;
    padding: 10px;
    border: 1px solid rgba(255,255,255,0.03);
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.empty-detail {
    text-align: center;
    color: var(--text-secondary);
    font-size: 11px;
    margin: 0;
}

.item-detail-title {
    font-weight: 600;
    font-size: 13px;
    color: var(--color-gold);
    margin: 0 0 4px 0;
}

.item-detail-desc {
    font-size: 10px;
    color: var(--text-secondary);
    margin: 0 0 8px 0;
    line-height: 1.4;
}

.item-use-btn {
    background: var(--color-gold);
    color: #000;
    border: none;
    width: 100%;
    padding: 6px;
    border-radius: 6px;
    font-size: 11px;
    font-weight: 800;
    cursor: pointer;
    transition: all 0.2s;
}

.item-use-btn:hover {
    box-shadow: 0 0 10px var(--color-gold-glow);
    transform: translateY(-1px);
}

/* --------------------------------------------------------------------------
   TOUCH CONTROLS: 行動裝置操控
   -------------------------------------------------------------------------- */
#touch-controls {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 160px;
    display: none; /* JS 端在偵測到移動裝置時會設為 flex */
    justify-content: space-between;
    align-items: center;
    padding: 0 40px 20px 40px;
    z-index: 11;
}

#joystick-container {
    width: 100px;
    height: 100px;
    display: flex;
    justify-content: center;
    align-items: center;
}

#joystick-base {
    width: 80px;
    height: 80px;
    background: rgba(255, 255, 255, 0.1);
    border: 2px solid rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    position: relative;
    backdrop-filter: blur(8px);
}

#joystick-stick {
    width: 36px;
    height: 36px;
    background: #fff;
    border-radius: 50%;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    box-shadow: 0 4px 10px rgba(0,0,0,0.5);
    transition: background 0.2s;
}

#action-buttons {
    display: flex;
    align-items: center;
}

.action-btn {
    width: 68px;
    height: 68px;
    background: rgba(255, 207, 51, 0.85);
    border: 2px solid #fff;
    color: #000;
    border-radius: 50%;
    font-weight: 800;
    font-size: 13px;
    cursor: pointer;
    box-shadow: 0 4px 15px rgba(0,0,0,0.4);
    display: flex;
    justify-content: center;
    align-items: center;
}

.action-btn:active {
    transform: scale(0.92);
    background: var(--color-gold);
}

/* --------------------------------------------------------------------------
   SCREENS: 幕布覆蓋層
   -------------------------------------------------------------------------- */
.screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(5, 5, 8, 0.85);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 100;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.4s ease;
}

.screen.active {
    opacity: 1;
    pointer-events: auto;
}

/* 開始畫面樣式 */
#start-screen {
    background: radial-gradient(circle at center, #1b1b2d 0%, #030307 100%);
}

.title-container {
    text-align: center;
    margin-bottom: 40px;
    animation: fadeInDown 0.8s ease-out;
}

.game-title {
    font-size: 56px;
    font-weight: 800;
    margin: 0;
    background: linear-gradient(135deg, #fff 30%, var(--color-gold) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    text-shadow: 0 0 30px rgba(255, 207, 51, 0.2);
    letter-spacing: 6px;
}

.game-subtitle {
    font-size: 14px;
    text-transform: uppercase;
    letter-spacing: 4px;
    color: var(--text-secondary);
    margin: 6px 0 0 0;
}

.menu-box {
    display: flex;
    flex-direction: column;
    gap: 16px;
    width: 220px;
    animation: fadeInUp 0.8s ease-out;
}

.menu-btn {
    padding: 14px 28px;
    border-radius: 8px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.25s ease;
    text-align: center;
    border: none;
}

.menu-btn.primary {
    background: linear-gradient(135deg, #ffcf33 0%, #ff9f43 100%);
    color: #0b0b14;
    box-shadow: 0 8px 25px rgba(255, 159, 67, 0.35);
}

.menu-btn.primary:hover {
    transform: translateY(-3px);
    box-shadow: 0 12px 30px rgba(255, 159, 67, 0.5);
}

.menu-btn.secondary {
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: var(--text-primary);
}

.menu-btn.secondary:hover {
    background: rgba(255, 255, 255, 0.12);
    transform: translateY(-2px);
}

.menu-btn:active {
    transform: translateY(0);
}

/* 幫助模態窗 */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(6px);
    z-index: 200;
    display: none;
    justify-content: center;
    align-items: center;
}

.modal.active {
    display: flex;
}

.modal-content {
    background: #12121d;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    padding: 24px 30px;
    max-width: 340px;
    width: 90%;
    text-align: left;
    box-shadow: 0 10px 40px rgba(0,0,0,0.8);
    animation: scaleIn 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.modal-content h3 {
    margin-top: 0;
    font-size: 18px;
    color: var(--color-gold);
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    padding-bottom: 8px;
}

.modal-content p {
    font-size: 13px;
    color: var(--text-secondary);
    line-height: 1.6;
    margin: 8px 0;
}

.modal-content strong {
    color: var(--text-primary);
}

.modal-content button {
    width: 100%;
    margin-top: 16px;
}

/* 遊戲結束與勝利幕布 */
.screen-title {
    font-size: 38px;
    font-weight: 800;
    margin-bottom: 10px;
    letter-spacing: 2px;
}

.screen-title.danger {
    color: var(--color-hp);
    text-shadow: 0 0 20px rgba(255, 71, 87, 0.3);
}

.screen-title.success {
    color: #2ed573;
    text-shadow: 0 0 20px rgba(46, 213, 115, 0.3);
}

.victory-box-content {
    text-align: center;
    background: var(--panel-bg);
    border: 1px solid var(--panel-border);
    padding: 30px 40px;
    border-radius: 16px;
    box-shadow: 0 8px 32px var(--color-shadow);
    max-width: 420px;
}

.victory-stats {
    background: rgba(0, 0, 0, 0.3);
    border-radius: 8px;
    padding: 12px;
    margin: 20px 0;
}

.victory-stats p {
    margin: 6px 0;
    font-size: 14px;
    color: var(--text-secondary);
}

.victory-stats span {
    color: #fff;
    font-weight: 600;
}

/* ==========================================================================
   ANIMATIONS & TRANSITIONS: 微動畫與特效
   ========================================================================== */
@keyframes pulse {
    0% { opacity: 0.9; transform: translateX(-50%) scale(1); }
    50% { opacity: 1; transform: translateX(-50%) scale(1.03); }
    100% { opacity: 0.9; transform: translateX(-50%) scale(1); }
}

@keyframes slideUp {
    from { transform: translateY(50px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

@keyframes slideInRight {
    from { transform: translateX(50px); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

@keyframes fadeInDown {
    from { transform: translateY(-30px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

@keyframes fadeInUp {
    from { transform: translateY(30px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

@keyframes scaleIn {
    from { transform: scale(0.9); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}
