/* =========================================
   1. 全局基礎設定 (通用)
   ========================================= */
* {
    box-sizing: border-box;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

body {
    margin: 0;
    background: #000;
    color: white;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    overflow: hidden;
    font-size: 14px;
}

/* 地圖背景 */
#map-container {
    width: 100vw;
    height: 100vh;
    background: radial-gradient(circle at center, #1a1a2e, #050510);
}

/* 國家路徑樣式 */
path.country {
    fill: #444;
    stroke: #111;
    stroke-width: 1px;
    transition: fill 0.5s, stroke 0.3s;
    cursor: pointer;
}

    path.country:hover {
        fill: #666;
    }

    path.country.selected {
        stroke: #00ccff !important;
        stroke-width: 3px !important;
        filter: drop-shadow(0 0 8px #00ccff);
    }

    path.country.high-risk {
        stroke: #ff3d00 !important;
        stroke-width: 2px !important;
        stroke-dasharray: 5, 3;
        animation: riskPulse 1s infinite;
    }

    path.country.event-active {
        stroke: #ffeb3b !important;
        stroke-width: 3px !important;
        animation: eventFlash 0.5s 3;
    }

path.locked {
    fill: #1a1a1a !important;
    opacity: 0.8;
    pointer-events: auto;
}

path.win-state {
    fill: #2e7d32 !important;
    stroke: #66bb6a !important;
    opacity: 0.6;
}

path.dead-state {
    fill: #3e2723 !important;
    stroke: #5d4037 !important;
    opacity: 0.8;
}

.lock-text {
    font-size: 8px;
    fill: #aaa;
    opacity: 0;
    pointer-events: none;
    text-anchor: middle;
    transition: opacity 0.5s;
}

@keyframes riskPulse {
    0% {
        stroke-opacity: 1;
    }

    50% {
        stroke-opacity: 0.4;
    }

    100% {
        stroke-opacity: 1;
    }
}

@keyframes eventFlash {
    0% {
        fill-opacity: 1;
    }

    50% {
        fill-opacity: 0.5;
    }

    100% {
        fill-opacity: 1;
    }
}

/* UI 層容器 */
#ui-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none; /* 讓點擊穿透到地圖 */
}

    #ui-layer > * {
        pointer-events: auto;
    }
/* UI 元素恢復點擊 */


/* =========================================
   2. 電腦版樣式 (Desktop / Original Look)
   ========================================= */

/* 新聞跑馬燈 - 電腦版全寬 */
.news-ticker-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 35px;
    background: rgba(0,0,0,0.9);
    border-bottom: 1px solid #333;
    display: flex;
    align-items: center;
    z-index: 200;
}

.news-label {
    background: #d32f2f;
    color: white;
    font-weight: bold;
    padding: 0 15px;
    height: 100%;
    display: flex;
    align-items: center;
    font-size: 14px;
    z-index: 201;
}

.news-content-wrapper {
    flex: 1;
    overflow: hidden;
    position: relative;
    height: 100%;
    display: flex;
    align-items: center;
}

.news-content {
    position: absolute;
    white-space: nowrap;
    color: #ccc;
    font-size: 14px;
    animation: newsScroll 20s linear infinite;
}

@keyframes newsScroll {
    0% {
        transform: translateX(100vw);
    }

    100% {
        transform: translateX(-100%);
    }
}

/* 頂部狀態欄 - 電腦版 */
.header {
    margin-top: 35px; /* 避開跑馬燈 */
    background: rgba(10, 20, 30, 0.95);
    padding: 10px 30px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 3px solid #4caf50;
    width: 100%;
    box-sizing: border-box;
}

.title {
    color: #4caf50;
    font-size: 24px;
    font-weight: bold;
    letter-spacing: 2px;
}

.date-display {
    text-align: center;
    background: rgba(0,0,0,0.3);
    padding: 5px 20px;
    border-radius: 5px;
    border: 1px solid #333;
}

.stats {
    display: flex;
    gap: 25px;
    font-size: 16px;
    font-weight: bold;
}

/* 監控列表 - 電腦版 */
.region-list-container {
    position: absolute;
    top: 100px;
    right: 20px;
    width: 220px;
    background: rgba(20, 30, 40, 0.95);
    border: 1px solid #4caf50;
    border-radius: 8px;
    max-height: 60vh;
    display: flex;
    flex-direction: column;
    z-index: 150;
}

.list-header {
    padding: 10px;
    background: #1a1a1a;
    border-bottom: 1px solid #4caf50;
    cursor: pointer;
    font-weight: bold;
    display: flex;
    justify-content: space-between;
}

.list-content {
    flex: 1;
    overflow-y: auto;
    padding: 5px;
}

.region-list-container.collapsed .list-content {
    display: none;
}

.list-item {
    padding: 8px;
    margin-bottom: 5px;
    background: #222;
    border-radius: 4px;
    cursor: pointer;
    border-left: 3px solid #555;
}

    .list-item:hover {
        background: #333;
    }
    /* Risk Colors */
    .list-item.risk-low {
        border-left-color: #4caf50;
    }

    .list-item.risk-med {
        border-left-color: #ffeb3b;
    }

    .list-item.risk-high {
        border-left-color: #ff5555;
    }

    .list-item.risk-critical {
        border-left-color: #ff3d00;
        animation: pulseRed 1s infinite;
    }

/* 地區詳細面板 - 電腦版 */
#region-panel {
    position: absolute;
    bottom: 90px;
    left: 20px;
    width: 320px;
    background: rgba(20, 30, 40, 0.95);
    border: 1px solid #555;
    padding: 20px;
    border-radius: 10px;
    display: none;
    backdrop-filter: blur(5px);
    z-index: 160;
}

#r-name {
    margin: 0 0 15px 0;
    color: #4caf50;
    border-bottom: 1px solid #444;
    padding-bottom: 5px;
    font-size: 22px;
}

.stat-row {
    display: flex;
    justify-content: space-between;
    font-size: 14px;
    margin-bottom: 2px;
}

.bar-container {
    background: #222;
    height: 6px;
    margin: 0 0 12px 0;
    border-radius: 3px;
    overflow: hidden;
}

.bar-fill {
    height: 100%;
    transition: width 0.5s;
}

.sub-stats {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-top: 15px;
    font-size: 13px;
    color: #ccc;
}

.sub-stat {
    background: #333;
    padding: 5px;
    border-radius: 4px;
    text-align: center;
}

/* 事件通知 - 電腦版 (右下角) */
#event-toast {
    position: absolute;
    bottom: 100px;
    right: -400px;
    width: 320px;
    background: #222;
    color: white;
    border-left: 5px solid #d32f2f;
    padding: 15px;
    box-shadow: -5px 5px 20px rgba(0,0,0,0.8);
    transition: right 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    z-index: 50;
}

    #event-toast.show {
        right: 20px;
    }
/* 電腦版從右邊滑入 */

.event-header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 5px;
    font-size: 18px;
    font-weight: bold;
}

.event-desc {
    font-size: 14px;
    line-height: 1.4;
    margin-bottom: 8px;
}

.event-target {
    font-size: 12px;
    opacity: 0.8;
    color: #ccc;
}

/* 底部欄 - 電腦版 */
.footer {
    position: absolute;
    bottom: 0;
    width: 100%;
    background: rgba(10, 20, 30, 0.95);
    padding: 15px 30px;
    border-top: 1px solid #4caf50;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.support-badge {
    background: linear-gradient(45deg, #004d40, #00695c);
    padding: 8px 20px;
    border-radius: 20px;
    border: 2px solid #00ffcc;
    color: #00ffcc;
    font-weight: bold;
    font-size: 20px;
}

.btn {
    background: #2e7d32;
    color: white;
    border: none;
    padding: 12px 30px;
    font-size: 16px;
    font-weight: bold;
    cursor: pointer;
    border-radius: 5px;
}

    .btn:hover {
        background: #4caf50;
    }

/* 商店視窗 - 電腦版 */
#shop-modal {
    display: none;
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 800px;
    height: 600px; /* 固定大小 */
    background: #111;
    border: 2px solid #4caf50;
    z-index: 999;
    flex-direction: column;
    box-shadow: 0 0 50px rgba(0,0,0,0.9);
}

    #shop-modal[style*="display: block"] {
        display: flex !important;
    }

.shop-header {
    padding: 15px 20px;
    background: #1a1a1a;
    border-bottom: 1px solid #444;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}

.shop-tabs {
    display: flex;
    background: #222;
    border-bottom: 1px solid #444;
    flex-shrink: 0;
}

.tab-btn {
    flex: 1;
    background: transparent;
    border: none;
    color: #888;
    padding: 15px;
    font-size: 16px;
    cursor: pointer;
    border-bottom: 3px solid transparent;
}

    .tab-btn.active {
        color: #fff;
        border-bottom-color: #4caf50;
        background: #2a2a2a;
    }

.close-btn {
    background: transparent;
    border: none;
    color: white;
    font-size: 24px;
    cursor: pointer;
}

.card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 15px;
    padding: 20px;
    overflow-y: auto;
}

.card {
    background: #1e1e1e;
    padding: 15px;
    border: 1px solid #333;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    min-height: 120px;
    position: relative;
}

    .card:hover {
        border-color: #4caf50;
        background: #252525;
    }

    .card h3 {
        margin: 0 0 5px 0;
        color: #4caf50;
        font-size: 16px;
    }

    .card p {
        font-size: 12px;
        color: #aaa;
        margin-bottom: 10px;
    }

.card-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 12px;
    margin-top: auto;
}

.cost {
    color: #ffeb3b;
    font-weight: bold;
}

.card-tag {
    position: absolute;
    top: 5px;
    right: 5px;
    font-size: 10px;
    padding: 2px 6px;
    border-radius: 4px;
    font-weight: bold;
}

.tag-local {
    background: #004d40;
    color: #4caf50;
}

.tag-global {
    background: #311b92;
    color: #b388ff;
}

.tag-special {
    background: #b71c1c;
    color: #ff8a80;
}

/* 訊息與 Game Over */
#msg-box {
    position: absolute;
    top: 100px;
    width: 100%;
    text-align: center;
    pointer-events: none;
    z-index: 100;
}

#msg-text {
    background: #ff9800;
    color: #000;
    padding: 10px 40px;
    border-radius: 30px;
    font-size: 18px;
    font-weight: bold;
    opacity: 0;
    transition: opacity 0.5s;
}

.bubble {
    position: absolute;
    width: 45px;
    height: 45px;
    background: radial-gradient(circle at 30% 30%, #aaffaa, #006600);
    border-radius: 50%;
    border: 2px solid #fff;
    box-shadow: 0 0 15px #66ff66;
    cursor: pointer;
    pointer-events: auto;
    animation: popIn 0.4s;
    z-index: 80;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 20px;
}

@keyframes popIn {
    from {
        transform: scale(0)
    }

    to {
        transform: scale(1)
    }
}

#game-over-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.95);
    z-index: 2000;
    display: flex;
    justify-content: center;
    align-items: center;
}

.game-over-content {
    background: #111;
    border: 2px solid #4caf50;
    padding: 40px;
    border-radius: 10px;
    text-align: center;
    max-width: 600px;
    width: 90%;
}

.end-stats-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    margin: 30px 0;
}

.end-stat-box {
    background: #222;
    padding: 15px;
    border-radius: 8px;
    border: 1px solid #333;
}

.rank-text {
    font-size: 60px;
    font-weight: bold;
    color: #ffeb3b;
    margin: 10px 0;
}

.large-btn {
    width: 100%;
    padding: 15px;
    font-size: 20px;
    margin-top: 20px;
}


/* =================================================================
   3. 手機/平板 橫屏優化 (Mobile Landscape Tweaks)
   當螢幕寬度小於 1024px 時，套用這些樣式覆蓋上面的設定
   ================================================================= */
@media screen and (max-width: 1024px) {

    /* 新聞跑馬燈：縮短寬度 */
    .news-ticker-container {
        width: 35vw;
        border-right: 1px solid #333;
        border-bottom-right-radius: 10px;
    }

    @keyframes newsScroll {
        0% {
            transform: translateX(35vw);
        }

        100% {
            transform: translateX(-100%);
        }
    }

    /* 頂部狀態欄：浮動置中 */
    .header {
        position: absolute;
        top: 0;
        left: 50%;
        transform: translateX(-50%);
        margin-top: 0; /* 移除間距 */
        background: linear-gradient(180deg, rgba(0,0,0,0.9) 0%, transparent 100%);
        border-bottom: none;
        width: 50vw;
        padding: 5px;
        flex-direction: column;
        pointer-events: none; /* 防止遮擋地圖 */
    }

    .title {
        font-size: 14px;
        margin-bottom: 2px;
        text-shadow: 0 2px 2px black;
    }

    .date-display {
        background: transparent;
        border: none;
        padding: 0;
        font-size: 12px;
    }

    .stats {
        margin-top: 2px;
        gap: 15px;
        font-size: 12px;
        text-shadow: 1px 1px 2px black;
    }

    /* 事件通知 (手機版)：改為底部中央浮現，避開頂部擁擠 */
    #event-toast {
        top: auto !important;
        right: auto !important;
        left: 50% !important;
        bottom: 80px !important; /* 在按鈕上方 */
        transform: translateX(-50%) translateY(20px); /* 初始位置 */

        width: 90vw !important;
        max-width: 400px;
        background: rgba(15, 15, 15, 0.95) !important;
        border-left: 5px solid #d32f2f;
        border-top: 1px solid #333;
        border-right: 1px solid #333;
        border-bottom: 1px solid #333;
        border-radius: 8px;
        box-shadow: 0 5px 20px rgba(0,0,0,0.8);
        opacity: 0;
        transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
        pointer-events: none;
        z-index: 1000;
    }

        #event-toast.show {
            opacity: 1;
            transform: translateX(-50%) translateY(0);
            pointer-events: auto;
        }

        #event-toast.global-event {
            border-left-color: #aa00ff !important;
            background: rgba(49, 0, 74, 0.95) !important;
        }

    /* 監控列表：縮小尺寸，避開頂部 */
    .region-list-container {
        top: 50px;
        right: 10px;
        width: 180px;
        max-height: 45vh;
    }

    .list-header {
        padding: 8px;
        font-size: 12px;
    }

    .list-item {
        padding: 5px;
    }

    .item-name {
        font-size: 12px;
    }

    /* 地區詳細面板：垂直置中於左側，不擋中間 */
    #region-panel {
        top: 50%;
        transform: translateY(-50%);
        bottom: auto;
        left: 15px;
        width: 220px;
        padding: 12px;
    }

    #r-name {
        font-size: 16px;
        margin-bottom: 10px;
    }

    .stat-row {
        font-size: 12px;
    }

    .bar-container {
        height: 5px;
        margin-bottom: 8px;
    }

    /* 底部欄：更透明，節省空間 */
    .footer {
        background: transparent;
        border-top: none;
        padding: 10px;
        pointer-events: none;
    }

        .footer > * {
            pointer-events: auto;
        }

    .support-badge {
        font-size: 14px;
        padding: 6px 15px;
        margin-right: auto;
        background: rgba(0, 77, 64, 0.9);
    }

    .btn {
        padding: 8px 16px;
        font-size: 14px;
    }

    /* 商店視窗：滿版響應式 */
    #shop-modal {
        width: 85vw;
        height: 85vh;
        border-radius: 10px;
    }

    .card-grid {
        grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); /* 卡片變小 */
        gap: 10px;
        padding: 10px;
    }

    .card {
        min-height: 100px;
    }

        .card h3 {
            font-size: 14px;
        }

    /* Game Over 視窗調整 */
    .game-over-content {
        width: 85vw;
        padding: 20px;
    }

    .rank-text {
        font-size: 40px;
    }
}
