:root {
    --bg-color: #1a1a1d;
    --panel-bg: #2d2d30;
    --text-primary: #e0e0e0;
    --text-secondary: #a0a0a0;
    --accent-color: #4caf50;
    /* 靈力綠 */
    --gold-color: #ffd700;
    /* 金錢黃 */
    --border-color: #444;
    --font-main: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

body {
    margin: 0;
    padding: 0;
    background-color: var(--bg-color);
    color: var(--text-primary);
    font-family: var(--font-main);
    height: 100vh;
    overflow: hidden;
}

#app {
    display: flex;
    height: 100vh;
}

/* 資源面板 */
/* 資源面板 */
#resource-panel {
    width: 250px;
    background-color: var(--panel-bg);
    border-right: 1px solid var(--border-color);
    padding: 10px;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    flex-shrink: 0;
    /* 防止縮小 */
}

/* 右側日誌面板 */
#right-panel {
    width: 280px;
    background-color: var(--panel-bg);
    border-left: 1px solid var(--border-color);
    padding: 10px;
    display: flex;
    flex-direction: column;
    overflow-y: hidden;
    /* 內部容器滾動 */
    flex-shrink: 0;
}

#log-header h3 {
    margin: 0 0 10px 0;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border-color);
    color: var(--gold-color);
    text-align: center;
    font-size: 1.1em;
}

#log-list-container {
    flex: 1;
    overflow-y: auto;
    padding-right: 5px;
    /* 為滾動條留空間 */
}

#log-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

#log-list li {
    font-size: 0.85em;
    padding: 4px 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    color: #ccc;
    line-height: 1.4;
}

#log-list li:last-child {
    border-bottom: none;
}

/* 自定義滾動條 */
#log-list-container::-webkit-scrollbar {
    width: 6px;
}

#log-list-container::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.1);
}

#log-list-container::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 3px;
}

#log-list-container::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.3);
}

#resource-panel h2 {
    margin-top: 0;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 10px;
    text-align: center;
}

/* 資源標題區 */
#resources-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
}

#resources-header h2 {
    margin: 0;
    border: none;
    padding: 0;
}

/* 摺疊按鈕 */
.toggle-btn {
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 0.9em;
    transition: all 0.2s;
}

.toggle-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-primary);
}

.toggle-icon {
    display: inline-block;
    transition: transform 0.3s;
}

.toggle-icon.collapsed {
    transform: rotate(-90deg);
}

#resources-container.collapsed {
    max-height: 250px;
    overflow-y: auto;
}

/* 側邊欄日誌 */
#sidebar-log-container {
    margin-top: 15px;
    padding-top: 15px;
    border-top: 1px solid var(--border-color);
    flex-shrink: 0;
    height: 250px;
    display: flex;
    flex-direction: column;
}

#sidebar-log-container h3 {
    margin: 0 0 10px 0;
    font-size: 0.9em;
    color: var(--text-secondary);
}

#sidebar-log-list {
    list-style: none;
    padding: 0;
    margin: 0;
    overflow-y: auto;
    flex: 1;
    font-size: 0.8em;
    line-height: 1.6;
}

#sidebar-log-list li {
    padding: 3px 5px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    color: var(--text-secondary);
}

#sidebar-log-list li:last-child {
    border-bottom: none;
}

.grid-container {
    display: grid;
    grid-template-columns: 1fr;
    gap: 6px;
    /* 從 10px 減少到 6px，更緊密 */
}

.resource-item {
    background: #3a3a3e;
    padding: 6px 8px;
    /* 從 8px 減少到 6px 8px，更緊密 */
    border-radius: 4px;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 3px;
    /* 從 4px 減少到 3px */
    cursor: grab;
    user-select: none;
    transition: background 0.2s;
}

.res-info {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
}

.resource-item:active {
    cursor: grabbing;
    background: #4a4a4e;
}

.resource-item span.res-name {
    font-weight: bold;
    font-size: 0.9em;
    /* 稍微縮小字體 */
}

.resource-item span.res-value {
    font-family: monospace;
    font-size: 0.85em;
    /* 從 0.95em 減少到 0.85em */
    color: #ffd700;
}

/* 合成資源：添加頂部分隔線 */
.resource-item.not-clickable:first-of-type {
    margin-top: 12px;
    /* 與基礎資源分隔 */
    padding-top: 12px;
    border-top: 2px solid rgba(156, 39, 176, 0.3);
    /* 紫色分隔線 */
    position: relative;
}

/* 合成資源分隔標籤 */
.resource-item.not-clickable:first-of-type::before {
    content: '合成資源';
    position: absolute;
    top: -8px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--panel-bg);
    padding: 0 8px;
    font-size: 0.7em;
    color: rgba(156, 39, 176, 0.8);
    font-weight: bold;
}

.resource-item.not-clickable {
    opacity: 0.8;
}

.resource-item.not-clickable:hover {
    background: #3a3a3e;
}

/* 可點擊的資源項目（基礎資源） */
.resource-item[style*="cursor: pointer"] {
    cursor: pointer !important;
    transition: all 0.2s;
}

.resource-item[style*="cursor: pointer"]:hover {
    background: #4a4a4e;
    transform: translateX(5px);
    box-shadow: 0 2px 8px rgba(76, 175, 80, 0.3);
}

.resource-item[style*="cursor: pointer"]:active {
    transform: translateX(3px) scale(0.98);
    background: #5a5a5e;
}

/* 可點擊的資源名稱 */
.resource-item span.res-name.clickable {
    transition: all 0.2s;
    position: relative;
}

.resource-item[style*="cursor: pointer"]:hover span.res-name.clickable {
    color: var(--accent-color);
}

.resource-item[style*="cursor: pointer"]:active span.res-name.clickable {
    color: var(--gold-color);
}

@keyframes gatherPulse {
    0% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.2);
        color: var(--accent-color);
    }

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

.gather-pulse {
    animation: gatherPulse 0.3s ease;
}

/* Buff 狀態指示器動畫 */
@keyframes buff-pulse {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.6;
    }
}

/* 主內容區 */
#main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 20px;
    background-image: radial-gradient(circle at center, #252528 0%, #1a1a1d 100%);
}

.main-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 20px;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 10px;
    gap: 20px;
}

.main-header h1 {
    margin: 0;
    flex-shrink: 0;
}

/* 頂部日誌框 */
#top-log-container {
    flex: 1;
    max-width: 500px;
    background: transparent;
    /* 透明背景，與主背景融合 */
    border: none;
    /* 移除邊框 */
    border-radius: 0;
    padding: 0;
    height: 90px;
    /* 固定高度（約5行） */
    display: flex;
    flex-direction: column;
    overflow: hidden;
    /* 防止內容撐大容器 */
}

#top-log-container h3 {
    margin: 0 0 5px 0;
    font-size: 0.85em;
    color: rgba(255, 215, 0, 0.6);
    /* 半透明金色 */
    flex-shrink: 0;
    /* 標題不縮小 */
}

#top-log-list {
    list-style: none;
    padding: 0;
    margin: 0;
    overflow-y: auto;
    /* 內容超出時滾動 */
    overflow-x: hidden;
    flex: 1;
    font-size: 0.75em;
    line-height: 1.4;
    height: 100%;
    /* 填滿剩餘空間 */
}

#top-log-list li {
    padding: 2px 0;
    color: rgba(224, 224, 224, 0.7);
    /* 半透明文字 */
    border-bottom: none;
    /* 移除分隔線 */
    white-space: nowrap;
    /* 不換行 */
    overflow: hidden;
    text-overflow: ellipsis;
    /* 超出顯示省略號 */
}

#top-log-list li:last-child {
    border-bottom: none;
}

/* 自定義滾動條（可選） */
#top-log-list::-webkit-scrollbar {
    width: 4px;
}

#top-log-list::-webkit-scrollbar-track {
    background: transparent;
}

#top-log-list::-webkit-scrollbar-thumb {
    background: rgba(255, 215, 0, 0.3);
    border-radius: 2px;
}

#top-log-list::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 215, 0, 0.5);
}

.game-controls {
    display: flex;
    gap: 10px;
    flex-shrink: 0;
}

.btn {
    background: #333;
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    padding: 5px 15px;
    cursor: pointer;
    border-radius: 4px;
    transition: all 0.2s;
}

.btn:hover {
    background: #444;
    border-color: #666;
}

.btn-tiny {
    background: transparent;
    color: var(--text-primary);
    border: 1px solid #666;
    padding: 0 6px;
    font-size: 0.75em;
    border-radius: 3px;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-tiny:hover:not(:disabled) {
    background: rgba(255, 255, 255, 0.1);
    border-color: var(--text-primary);
}

.btn-tiny:disabled {
    cursor: default;
    opacity: 0.5;
}

/* 分頁導航 */
#tab-nav {
    display: flex;
    gap: 5px;
    margin-bottom: 20px;
}

.tab-btn {
    background: transparent;
    color: var(--text-secondary);
    border: none;
    border-bottom: 2px solid transparent;
    padding: 10px 20px;
    font-size: 1.1em;
    cursor: pointer;
}

.tab-btn:hover {
    color: var(--text-primary);
}

.tab-btn.active {
    color: var(--accent-color);
    border-bottom-color: var(--accent-color);
}

/* 分頁內容 */
#tab-content {
    flex: 1;
    overflow-y: auto;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 8px;
    padding: 20px;
}

.tab-view.hidden {
    display: none;
}

.tab-view.active {
    display: block;
    animation: fadeIn 0.3s ease;
}

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

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

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.modal.hidden {
    display: none;
}

.modal-content {
    background: var(--panel-bg);
    padding: 20px;
    border-radius: 8px;
    width: 500px;
    max-width: 90%;
    position: relative;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
}

.close-modal {
    position: absolute;
    right: 15px;
    top: 10px;
    font-size: 24px;
    cursor: pointer;
}

textarea {
    width: 100%;
    background: #222;
    color: #ccc;
    border: 1px solid #444;
    padding: 10px;
    box-sizing: border-box;
    margin-bottom: 10px;
    resize: vertical;
}

.hidden {
    display: none !important;
}

/* Building List */
.building-list {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.building-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
}

.building-item {
    background: #3a3a3e;
    padding: 8px 10px;
    border-radius: 6px;
    display: flex;
    flex-direction: column;
    /* 改為垂直排列 */
    justify-content: center;
    align-items: center;
    border: 1px solid #555;
    text-align: center;
    min-height: 80px;
    /* 固定高度 */
    cursor: help;
    /* 提示有 tooltip */
    position: relative;
    transition: all 0.2s;
}

.building-item:hover {
    background: #4a4a4e;
    border-color: #888;
    /* 改為淺灰色，不再強制變為綠色 */
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
}

.b-info.compact {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    width: 100%;
}

.b-title-line {
    display: block;
    text-align: left;
}

.b-name {
    margin: 0 !important;
    font-size: 1em !important;
    font-weight: bold;
    color: var(--gold-color);
}

.b-level {
    font-size: 0.75em;
    color: #aaa;
    font-weight: normal;
}

/* 在緊湊模式下隱藏詳細信息 */
.building-grid.compact .b-desc,
.building-grid.compact .b-effect,
.building-grid.compact .cost-tip,
.building-grid.compact .b-action {
    display: none !important;
}

/* 升級狀態指示（例如邊框顏色或小圖標） */
.building-item.upgrade-available {
    border-color: var(--accent-color);
    box-shadow: 0 0 5px rgba(76, 175, 80, 0.3);
}

/* 移除升級三角形標記 */

.b-info.compact {
    flex: 1;
}

/* 已在上方統一定義 */

.b-name {
    margin: 0 !important;
    min-width: auto !important;
    font-size: 1.1em;
}

.b-desc {
    font-size: 0.9em;
    color: #bbb;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 400px;
}

.b-level {
    font-size: 0.75em;
    color: #fff;
    background: #555;
    padding: 1px 5px;
    border-radius: 4px;
    flex-shrink: 0;
}

.b-action {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 5px;
    min-width: 150px;
}

.cost-tip {
    font-size: 0.8em;
    color: #aaa;
}

.b-effect {
    font-size: 0.85em;
    color: #4caf50;
    margin-top: 5px;
}

.upgrade-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    background: #2a2a2a;
}

/* Crafting Panel */
.crafting-list {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 15px;
}

@media (max-width: 1200px) {
    .crafting-list {
        grid-template-columns: 1fr;
    }
}

.crafting-item {
    background: #3a3a3e;
    padding: 15px;
    border-radius: 8px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border: 1px solid #555;
}

.craft-info h3 {
    margin: 0 0 8px 0;
    color: #9c27b0;
    /* 紫色代表煉製 */
}

.craft-info p {
    margin: 5px 0;
    font-size: 0.9em;
    color: #bbb;
}

.craft-recipe {
    font-size: 0.85em;
    color: #4caf50;
    margin-top: 5px;
}

.craft-action {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 5px;
}

.craft-buttons {
    display: flex;
    justify-content: flex-end;
    gap: 4px;
    margin-top: 2px;
}

.craft-btn {
    background: #4a148c;
    color: var(--text-primary);
    border: 1px solid #6a1b9a;
    padding: 6px 12px;
    cursor: pointer;
    border-radius: 4px;
    transition: all 0.2s;
    font-size: 0.9em;
}

.craft-btn:hover:not(:disabled) {
    background: #6a1b9a;
    border-color: #9c27b0;
}

/* Skill List */
.skill-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 15px;
}

.skill-item {
    background: #3a3a3e;
    padding: 10px 15px;
    border-radius: 6px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border: 1px solid #555;
    transition: transform 0.2s, box-shadow 0.2s;
}

.skill-item:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    border-color: #00bcd4;
}

.skill-info.compact {
    flex: 1;
}

.learn-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    background: #2a2a2a;
}

.empty-message {
    text-align: center;
    color: var(--text-secondary);
    font-style: italic;
    padding: 40px;
}

/* 玩家資訊區域優化 */
.player-info {
    margin: 10px 0;
    padding: 10px;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 6px;
    font-size: 0.9em;
}

.player-info-line {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 5px;
    gap: 10px;
}

.mini-btn {
    padding: 2px 8px;
    font-size: 0.8em;
    border-radius: 3px;
    cursor: pointer;
    border: 1px solid #666;
    transition: all 0.2s;
    min-width: 60px;
    text-align: center;
}

.btn-active {
    background: #4caf50;
    color: white;
    border-color: #2e7d32;
}

.btn-active:hover {
    background: #66bb6a;
}

.btn-disabled {
    background: #444;
    color: #888;
    cursor: help;
    /* 顯示幫助符號以提示有 tooltip */
    opacity: 0.7;
}

.danger-btn {
    background: #d32f2f;
    color: white;
    border-color: #b71c1c;
    width: 100%;
    margin-top: 5px;
}

.danger-btn:hover {
    background: #ef5350;
}

/* Talents Section */
.talent-stats {
    display: flex;
    justify-content: space-around;
    background: rgba(0, 0, 0, 0.3);
    padding: 15px;
    border-radius: 8px;
    margin-bottom: 20px;
    border: 1px solid #444;
}

.stat-item {
    font-weight: bold;
    color: #ffd700;
}

#talent-dao-heart {
    color: #e67e22;
    text-shadow: 0 0 5px rgba(230, 126, 34, 0.5);
}

.talent-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 15px;
}

.talent-card {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid #444;
    border-radius: 8px;
    padding: 15px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    transition: transform 0.2s, background 0.2s;
}

.talent-card:hover {
    background: rgba(255, 255, 255, 0.08);
    transform: translateY(-2px);
}

.talent-info h3 {
    margin: 0 0 10px 0;
    color: #ffd700;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.talent-lvl {
    font-size: 0.7em;
    background: #e67e22;
    color: white;
    padding: 2px 6px;
    border-radius: 4px;
}

.talent-info p {
    font-size: 0.9em;
    color: #ccc;
    margin-bottom: 12px;
    line-height: 1.4;
}

.talent-cost {
    font-size: 0.8em;
    color: #aaa;
    margin-bottom: 10px;
}

.buy-talent-btn {
    width: 100%;
    background: #2980b9;
    color: white;
    padding: 8px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-weight: bold;
}

.buy-talent-btn:hover:not(.disabled) {
    background: #3498db;
}

.buy-talent-btn.disabled {
    background: #555;
    cursor: not-allowed;
    opacity: 0.6;
}

/* Debug Panel */
.debug-panel {
    max-width: 1200px;
    margin: 0 auto;
}

.debug-card {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid #444;
    border-radius: 8px;
    padding: 20px;
    transition: all 0.3s;
}

.debug-card:hover {
    background: rgba(255, 255, 255, 0.08);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.debug-card h3 {
    margin: 0 0 10px 0;
    font-size: 1.2em;
}

.debug-card p {
    margin: 0 0 15px 0;
    line-height: 1.5;
}

.debug-card .btn {
    transition: all 0.2s;
}

.debug-card .btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

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