:root {
    --bg-dark: #1a1a2e;
    --bg-card: #16213e;
    --accent: #e94560;
    --accent-light: #ff6b6b;
    --text: #eaeaea;
    --text-muted: #a0a0a0;
    --brain-color: #4facfe;
    --guts-color: #00f260;
    --muscle-color: #ff6b6b;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    background: var(--bg-dark);
    color: var(--text);
    font-family: 'Segoe UI', 'Microsoft JhengHei', sans-serif;
    min-height: 100vh;
    display: flex;
    justify-content: center;
    padding: 20px;
}

#app {
    width: 100%;
    max-width: 480px;
}

header {
    text-align: center;
    margin-bottom: 24px;
}

header h1 {
    font-size: 1.8rem;
    margin-bottom: 4px;
}

.subtitle {
    color: var(--text-muted);
    font-size: 0.9rem;
}

.energy-info {
    display: flex;
    justify-content: space-between;
    background: var(--bg-card);
    padding: 12px 16px;
    border-radius: 8px;
    margin-bottom: 20px;
    font-size: 1.1rem;
}

.investment-area {
    background: var(--bg-card);
    padding: 16px;
    border-radius: 8px;
    margin-bottom: 16px;
    border-left: 4px solid var(--accent);
}

.investment-area[data-type="brain"] {
    border-color: var(--brain-color);
}

.investment-area[data-type="guts"] {
    border-color: var(--guts-color);
}

.investment-area[data-type="muscle"] {
    border-color: var(--muscle-color);
}

.investment-area h2 {
    font-size: 1.1rem;
    margin-bottom: 4px;
}

.cost-hint {
    color: var(--text-muted);
    font-size: 0.85rem;
    margin-bottom: 12px;
}

.slider-row {
    display: flex;
    align-items: center;
    gap: 12px;
}

.slider-row input[type="range"] {
    flex: 1;
    height: 8px;
    -webkit-appearance: none;
    background: #333;
    border-radius: 4px;
    cursor: pointer;
}

.slider-row input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 20px;
    height: 20px;
    background: var(--accent);
    border-radius: 50%;
    cursor: pointer;
}

.slider-value {
    font-size: 1.4rem;
    font-weight: bold;
    min-width: 2ch;
    text-align: right;
}

.reward-preview {
    margin-top: 8px;
    font-size: 0.95rem;
    color: var(--text-muted);
}

.reward-preview strong {
    color: var(--text);
}

.warning {
    background: #ff4444;
    color: white;
    padding: 10px;
    border-radius: 6px;
    text-align: center;
    margin-bottom: 16px;
}

.hidden {
    display: none !important;
}

.btn-primary,
.btn-secondary {
    width: 100%;
    padding: 14px;
    font-size: 1.1rem;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.2s;
}

.btn-primary {
    background: var(--accent);
    color: white;
}

.btn-primary:hover {
    background: var(--accent-light);
}

.btn-primary:disabled {
    background: #555;
    cursor: not-allowed;
}

.btn-secondary {
    background: #333;
    color: var(--text);
    margin-top: 12px;
}

.btn-secondary:hover {
    background: #444;
}

.result {
    background: var(--bg-card);
    padding: 20px;
    border-radius: 8px;
    margin-top: 20px;
}

.result h2 {
    text-align: center;
    margin-bottom: 16px;
    color: var(--accent);
}

.result ul {
    list-style: none;
}

.result li {
    padding: 8px 0;
    border-bottom: 1px solid #333;
    font-size: 1.05rem;
}

.result li:last-child {
    border-bottom: none;
}

.result strong {
    float: right;
    color: var(--accent);
}

/* Phase 2 新增樣式 */
.setup-form {
    margin-bottom: 16px;
}

.setup-form label {
    display: block;
    margin-bottom: 6px;
    color: var(--text-muted);
}

.setup-form select,
.setup-form input[type="text"] {
    width: 100%;
    padding: 10px;
    font-size: 1rem;
    border: none;
    border-radius: 6px;
    background: var(--bg-card);
    color: var(--text);
}

.handover-box {
    text-align: center;
    padding: 60px 20px;
}

.handover-box p {
    color: var(--text-muted);
    margin-bottom: 8px;
}

.handover-box h2 {
    font-size: 2rem;
    margin-bottom: 32px;
    color: var(--accent);
}

.current-player-info {
    display: flex;
    justify-content: space-between;
    background: var(--bg-card);
    padding: 10px 16px;
    border-radius: 8px;
    margin-bottom: 16px;
    font-size: 1rem;
}

.current-player-info span:first-child {
    font-weight: bold;
    color: var(--accent);
}

.result-table-wrapper {
    overflow-x: auto;
    margin-bottom: 20px;
}

#result-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}

#result-table th,
#result-table td {
    padding: 10px 8px;
    text-align: center;
    border-bottom: 1px solid #333;
}

#result-table th {
    background: var(--accent);
    color: white;
}

#result-table td:first-child {
    text-align: left;
    font-weight: bold;
}

/* 個人結果畫面 */
.personal-result-box {
    text-align: center;
    padding: 30px 20px;
}

.personal-result-box h2 {
    font-size: 1.8rem;
    color: var(--accent);
    margin-bottom: 8px;
}

.personal-result-list {
    list-style: none;
    text-align: left;
    background: var(--bg-card);
    padding: 16px;
    border-radius: 8px;
    margin: 20px 0;
}

.personal-result-list li {
    padding: 10px 0;
    border-bottom: 1px solid #333;
    font-size: 1rem;
}

.personal-result-list li:last-child {
    border-bottom: none;
}

.personal-result-list strong {
    color: var(--accent);
}

/* 事件畫面 */
.event-box {
    text-align: center;
    padding: 40px 20px;
}

.event-round {
    color: var(--text-muted);
    margin-bottom: 20px;
}

.event-icon {
    font-size: 4rem;
    margin-bottom: 16px;
}

.event-box h2 {
    font-size: 1.8rem;
    margin-bottom: 12px;
}

.event-desc {
    font-size: 1.2rem;
    color: var(--accent);
    margin-bottom: 32px;
}

/* 乘數標籤 */
.multiplier-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 0.85rem;
    font-weight: bold;
    margin-left: 8px;
    animation: pulse 1.5s ease-in-out infinite;
}

[data-type="brain"] .multiplier-badge {
    background: var(--brain-color);
    color: #000;
}

[data-type="guts"] .multiplier-badge {
    background: var(--guts-color);
    color: #000;
}

[data-type="muscle"] .multiplier-badge {
    background: var(--muscle-color);
    color: #000;
}

@keyframes pulse {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.7;
    }
}

/* 遊戲結束畫面 */
.game-over-box {
    text-align: center;
    padding: 40px 20px;
    background: var(--bg-card);
    border-radius: 12px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    border: 2px solid var(--accent);
}

.trophy {
    font-size: 5rem;
    margin-bottom: 16px;
    filter: drop-shadow(0 0 10px gold);
    animation: bounce 2s infinite;
}

@keyframes bounce {

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

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

.game-over-box h2 {
    font-size: 2.5rem;
    color: var(--accent);
    margin: 10px 0;
    text-shadow: 0 0 10px rgba(233, 69, 96, 0.5);
}

.winner-stat {
    font-size: 1.2rem;
    color: var(--text-muted);
    margin-bottom: 30px;
}

.winner-stat strong {
    color: var(--brain-color);
    font-size: 1.5rem;
}

#final-rank-table {
    width: 100%;
    margin-bottom: 30px;
    border-collapse: collapse;
}

#final-rank-table th {
    background: #2a2a4a;
    padding: 12px;
    color: var(--accent);
}

#final-rank-table td {
    padding: 12px;
    border-bottom: 1px solid #333;
}

#final-rank-table tr:first-child td {
    font-weight: bold;
    color: var(--accent);
    background: rgba(233, 69, 96, 0.1);
}

.action-buttons {
    display: flex;
    gap: 16px;
    justify-content: center;
}

.action-buttons button {
    max-width: 200px;
}

/* 行動階段畫面 */
.action-box {
    text-align: center;
    padding: 20px;
}

.ap-display {
    display: flex;
    justify-content: space-around;
    gap: 12px;
    margin-bottom: 24px;
    background: rgba(0, 0, 0, 0.2);
    padding: 12px;
    border-radius: 8px;
}

.ap-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    font-size: 1.1rem;
    color: var(--brain-color);
}

.ap-item:last-child {
    color: var(--muscle-color);
}

.ap-item strong {
    font-size: 1.6rem;
}

.ap-item .hint {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 2px;
}

.action-options {
    display: flex;
    gap: 16px;
    justify-content: center;
    flex-wrap: wrap;
    margin-bottom: 24px;
}

.action-card {
    background: var(--bg-card);
    border: 2px solid #333;
    border-radius: 12px;
    padding: 20px;
    width: 200px;
    cursor: pointer;
    transition: all 0.2s;
}

.action-card:hover:not(.disabled) {
    border-color: var(--accent);
    transform: translateY(-5px);
}

.action-card.disabled,
.action-card.locked {
    opacity: 0.5;
    cursor: not-allowed;
    filter: grayscale(1);
    position: relative;
}

.action-card.locked::after {
    content: '🔒';
    position: absolute;
    top: 10px;
    right: 10px;
    font-size: 1.2rem;
}

.action-card .icon {
    font-size: 3rem;
    margin-bottom: 10px;
}

.action-card h3 {
    color: var(--accent);
    margin-bottom: 8px;
}

.action-card .effect {
    color: var(--guts-color);
    font-weight: bold;
    margin-top: 8px;
}

.target-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 12px;
}

.btn-target {
    background: #333;
    color: white;
    border: none;
    padding: 8px;
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
}

.btn-target:hover {
    background: var(--accent);
}

.energy-badge {
    background: rgba(0, 0, 0, 0.3);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.9em;
}

.desc-text {
    text-align: left;
    line-height: 1.6;
    margin: 20px 0;
    color: var(--text-muted);
    background: var(--bg-card);
    padding: 16px;
    border-radius: 8px;
}

.desc-text strong {
    color: var(--text);
}

/* ========== 技術樹系統樣式 (Phase 2) ========== */

/* 頁籤切換 */
.action-tabs {
    display: flex;
    gap: 8px;
    margin-bottom: 20px;
    justify-content: center;
}

.tab-btn {
    padding: 10px 20px;
    background: var(--bg-card);
    border: 2px solid #333;
    border-radius: 8px;
    color: var(--text-muted);
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.2s;
}

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

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

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

/* 技術樹面板 */
.tech-tree-panel {
    background: var(--bg-card);
    border-radius: 12px;
    padding: 20px;
    margin-bottom: 20px;
}

.tech-tree-hint {
    text-align: center;
    color: var(--text-muted);
    margin-bottom: 16px;
    font-size: 0.9rem;
}

.tech-paths {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

/* 單條技術路徑 */
.tech-path {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 8px;
    padding: 12px;
    border-left: 4px solid var(--accent);
}

.tech-path[data-path="digestion"] {
    border-left-color: #ff6b35;
}

.tech-path[data-path="tools"] {
    border-left-color: #8b7355;
}

.tech-path[data-path="social"] {
    border-left-color: #9b59b6;
}

.tech-path[data-path="environment"] {
    border-left-color: #27ae60;
}

.tech-path-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 12px;
    cursor: pointer;
}

.tech-path-header:hover {
    opacity: 0.8;
}

.tech-path-icon {
    font-size: 1.5rem;
}

.tech-path-name {
    font-weight: bold;
    flex: 1;
}

.tech-path-progress {
    font-size: 0.85rem;
    color: var(--text-muted);
}

/* 技術節點列表 */
.tech-nodes {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding: 4px 0;
}

.tech-node {
    min-width: 80px;
    padding: 8px;
    background: rgba(0, 0, 0, 0.3);
    border: 2px solid #444;
    border-radius: 8px;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s;
    position: relative;
}

.tech-node:hover:not(.locked) {
    border-color: var(--accent);
    transform: scale(1.05);
}

.tech-node.unlocked {
    border-color: var(--guts-color);
    background: rgba(0, 242, 96, 0.1);
}

.tech-node.unlocked::after {
    content: '✓';
    position: absolute;
    top: -8px;
    right: -8px;
    background: var(--guts-color);
    color: #000;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8rem;
    font-weight: bold;
}

.tech-node.available {
    border-color: var(--accent);
    animation: glow 2s ease-in-out infinite;
}

@keyframes glow {

    0%,
    100% {
        box-shadow: 0 0 5px var(--accent);
    }

    50% {
        box-shadow: 0 0 15px var(--accent);
    }
}

.tech-node.locked {
    opacity: 0.4;
    cursor: not-allowed;
}

.tech-node-icon {
    font-size: 1.5rem;
    margin-bottom: 4px;
}

.tech-node-name {
    font-size: 0.75rem;
    line-height: 1.2;
    color: var(--text);
}

.tech-node-era {
    font-size: 0.6rem;
    color: #aaa;
    margin-top: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.tech-node-cost {
    font-size: 0.7rem;
    color: var(--muscle-color);
    margin-top: 4px;
}

/* 技術節點連接線 */
.tech-nodes::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 0;
    right: 0;
    height: 2px;
    background: #333;
    z-index: 0;
}

/* ========== 技術卡彈窗 ========== */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 20px;
}

.modal-content {
    background: var(--bg-card);
    border-radius: 16px;
    max-width: 400px;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
    border: 2px solid var(--accent);
}

.tech-modal-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 20px;
    background: rgba(0, 0, 0, 0.2);
    border-bottom: 1px solid #333;
}

.tech-modal-icon {
    font-size: 2.5rem;
}

.tech-modal-title-area {
    flex: 1;
}

.tech-modal-title-area h2 {
    font-size: 1.3rem;
    margin-bottom: 4px;
}

.tech-modal-path {
    font-size: 0.85rem;
    color: var(--text-muted);
}

.modal-close {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.8rem;
    cursor: pointer;
    padding: 0;
    line-height: 1;
}

.modal-close:hover {
    color: var(--accent);
}

.tech-modal-body {
    padding: 20px;
}

.tech-description {
    font-size: 1rem;
    margin-bottom: 12px;
    line-height: 1.5;
}

.tech-flavor {
    font-style: italic;
    color: var(--text-muted);
    font-size: 0.9rem;
    margin-bottom: 16px;
    padding-left: 12px;
    border-left: 2px solid #444;
}

.tech-effects {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 8px;
    padding: 12px;
    margin-bottom: 12px;
}

.tech-effects h4 {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 8px;
}

.tech-effect-item {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 8px 0;
    font-size: 0.95rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.tech-effect-item:last-child {
    border-bottom: none;
}

.tech-effect-item .effect-icon {
    font-size: 1.1rem;
    color: var(--guts-color);
}

.tech-effect-item .effect-value {
    color: var(--accent-light);
    font-weight: bold;
}

.tech-requirements {
    font-size: 0.9rem;
    color: var(--text-muted);
}

.tech-requirements .req-met {
    color: var(--guts-color);
}

.tech-requirements .req-missing {
    color: var(--accent);
}

.tech-modal-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    background: rgba(0, 0, 0, 0.2);
    border-top: 1px solid #333;
}

.tech-cost {
    font-size: 1rem;
}

.tech-cost strong {
    color: var(--muscle-color);
    font-size: 1.2rem;
}

.tech-modal-footer .btn-primary {
    width: auto;
    padding: 10px 24px;
}

.tech-modal-footer .btn-primary:disabled {
    background: #444;
}

/* 升級成功動畫 */
@keyframes unlockSuccess {
    0% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.1);
        box-shadow: 0 0 30px var(--guts-color);
    }

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

.tech-node.just-unlocked {
    animation: unlockSuccess 0.5s ease-out;
}

/* AP 扣除動畫 */
@keyframes apDeduct {
    0% {
        transform: scale(1);
        color: var(--muscle-color);
    }

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

    100% {
        transform: scale(1);
        color: var(--muscle-color);
    }
}

.ap-display.deducting {
    animation: apDeduct 0.3s ease-out;
}

/* 演化時代瀏覽器 */
.evo-browser {
    margin: 20px 0 16px;
}

.evo-browser-title {
    font-size: 1rem;
    color: var(--accent);
    margin-bottom: 10px;
    text-align: center;
}

.evo-era-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.evo-era-card {
    background: var(--bg-card);
    border-radius: 10px;
    overflow: hidden;
    border-left: 3px solid var(--accent);
    cursor: pointer;
    transition: border-color 0.2s;
}

.evo-era-card:hover,
.evo-era-card.active {
    border-left-color: var(--muscle-color);
}

.evo-era-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
}

.evo-era-icon {
    font-size: 1.3rem;
    flex-shrink: 0;
}

.evo-era-info {
    flex: 1;
    min-width: 0;
}

.evo-era-name {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-primary);
}

.evo-era-period {
    font-size: 0.7rem;
    color: var(--text-secondary);
}

.evo-era-arrow {
    font-size: 0.8rem;
    color: var(--text-secondary);
    transition: transform 0.2s;
}

.evo-era-card.active .evo-era-arrow {
    transform: rotate(90deg);
}

.evo-era-techs {
    display: none;
    padding: 0 12px 10px;
    gap: 6px;
    flex-wrap: wrap;
}

.evo-era-card.active .evo-era-techs {
    display: flex;
}

.evo-era-tech-chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    background: rgba(255, 255, 255, 0.08);
    padding: 4px 10px;
    border-radius: 14px;
    font-size: 0.75rem;
    color: var(--text-primary);
}

.evo-era-tech-chip .chip-path {
    font-size: 0.65rem;
    color: var(--text-secondary);
}

/* ========== 跨路線收斂節點 ========== */
.tech-convergence {
    margin-top: 16px;
    padding: 12px;
    border: 2px solid #ffd700;
    border-radius: 8px;
    background: rgba(255, 215, 0, 0.05);
}

.convergence-label {
    font-size: 0.9em;
    color: #ffd700;
    margin-bottom: 8px;
    font-weight: bold;
}

.convergence-nodes {
    display: flex;
    justify-content: center;
}

/* 技術路線分支行 */
.branch-row {
    display: flex;
    gap: 8px;
    border-left: 2px dashed #666;
    padding-left: 8px;
    margin-left: 4px;
    margin-top: 8px;
}