/* ======= 變數定義 (色彩與排版) ======= */
:root {
    /* 淺色模式 (預設) */
    --bg-color: #f7f9fc;
    --text-color: #333333;
    --card-bg: #ffffff;
    --nav-bg: #ffffff;
    --shadow: 0 4px 12px rgba(0,0,0,0.08);
    
    /* 兩區代表色 */
    --west-color: #1E88E5; /* 西區：藍色 */
    --west-bg: #e3f2fd;
    --east-color: #43A047; /* 東區：綠色 */
    --east-bg: #e8f5e9;

    /* 元件顏色 */
    --btn-primary: #ff7043;
    --btn-hover: #f4511e;
    
    --transition-speed: 0.4s;
}

/* 深色模式變數覆蓋 */
body.dark-mode {
    --bg-color: #121212;
    --text-color: #e0e0e0;
    --card-bg: #1e1e1e;
    --nav-bg: #1f1f1f;
    --shadow: 0 4px 12px rgba(0,0,0,0.5);
    
    --west-bg: #0d233a;
    --east-bg: #142e16;
}

/* ======= 全域設定 ======= */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: "PingFang TC", "Helvetica Neue", Helvetica, Arial, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    transition: background-color var(--transition-speed) ease, color var(--transition-speed) ease;
    line-height: 1.6;
}

/* ======= 導覽列 ======= */
#navbar {
    position: fixed;
    top: 0;
    width: 100%;
    height: 70px;
    background-color: var(--nav-bg);
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 5%;
    box-shadow: var(--shadow);
    z-index: 1000;
    transition: background-color var(--transition-speed) ease;
}

.logo {
    font-size: 1.5rem;
    font-weight: bold;
    cursor: pointer;
}

.nav-links {
    list-style: none;
    display: flex;
    gap: 15px;
}

.nav-links button {
    background: none;
    border: none;
    color: var(--text-color);
    font-size: 1rem;
    cursor: pointer;
    font-weight: 500;
    padding: 8px 12px;
    border-radius: 4px;
    transition: background 0.3s;
}

.nav-links button:hover {
    background-color: rgba(128, 128, 128, 0.1);
}

/* 深色模式按鈕 */
.theme-btn {
    background: transparent;
    border: 2px solid var(--text-color);
    border-radius: 50%;
    width: 40px;
    height: 40px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    color: var(--text-color);
    transition: transform 0.3s ease;
}
.theme-btn:active {
    transform: rotate(360deg) scale(0.9);
}

/* ======= 頁面切換機制 ======= */
#app-content {
    margin-top: 70px; /* 避開 navbar */
    min-height: calc(100vh - 70px);
}

.page {
    display: none;
    opacity: 0;
    transition: opacity 0.5s ease-in-out;
}

.page.active {
    display: block;
    opacity: 1;
    animation: fadeIn 0.5s forwards;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ======= 首頁與模組網格 ======= */
.home-hero {
    text-align: center;
    padding: 60px 20px 40px;
}

.home-hero h1 {
    font-size: 2.5rem;
    margin-bottom: 10px;
}

.module-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 20px;
    padding: 40px 5%;
}

.module-card {
    background-color: var(--card-bg);
    padding: 30px;
    text-align: center;
    border-radius: 12px;
    box-shadow: var(--shadow);
    cursor: pointer;
    font-weight: bold;
    font-size: 1.2rem;
    transition: transform 0.3s, box-shadow 0.3s;
}

.module-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 8px 20px rgba(0,0,0,0.15);
}

/* ======= 共用按鈕與結果卡片 ======= */
.action-btn {
    background-color: var(--btn-primary);
    color: white;
    border: none;
    padding: 12px 24px;
    font-size: 1.1rem;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.3s, transform 0.1s;
    margin-top: 15px;
}

.action-btn:hover {
    background-color: var(--btn-hover);
}

.action-btn:active {
    transform: scale(0.95);
}

.result-card {
    margin-top: 20px;
    padding: 15px 30px;
    background-color: var(--card-bg);
    border-left: 5px solid var(--btn-primary);
    border-radius: 8px;
    font-size: 1.3rem;
    font-weight: bold;
    box-shadow: var(--shadow);
    display: inline-block;
}

.result-card.hidden {
    display: none;
}

.anim-bounce {
    animation: bounceIn 0.6s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes bounceIn {
    0% { opacity: 0; transform: scale(0.3); }
    50% { opacity: 1; transform: scale(1.05); }
    70% { transform: scale(0.9); }
    100% { transform: scale(1); }
}

/* ======= 家鄉優勢區塊 & 抽籤區塊 ======= */
.advantage-section, .lottery-section {
    text-align: center;
    padding: 30px 20px;
    margin: 20px auto;
    max-width: 600px;
    background-color: var(--card-bg);
    border-radius: 12px;
    box-shadow: var(--shadow);
}

/* ======= 樂透抽籤機視覺實作 ======= */
.lottery-machine {
    position: relative;
    width: 150px;
    height: 200px;
    margin: 20px auto;
}

.globe {
    width: 150px;
    height: 150px;
    border-radius: 50%;
    border: 4px solid #ccc;
    background: rgba(255, 255, 255, 0.1);
    position: relative;
    overflow: hidden;
    z-index: 2;
    box-shadow: inset 0 0 20px rgba(0,0,0,0.1);
}

body.dark-mode .globe {
    border-color: #555;
    background: rgba(0, 0, 0, 0.2);
}

.ball {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    position: absolute;
    bottom: 10px;
}

.ball-1 { background-color: #FF5252; left: 20px; }
.ball-2 { background-color: #4CAF50; left: 60px; }
.ball-3 { background-color: #2196F3; left: 100px; }

.machine-base {
    width: 100px;
    height: 50px;
    background-color: #555;
    margin: 0 auto;
    position: relative;
    border-radius: 0 0 20px 20px;
    z-index: 1;
}

.chute {
    width: 40px;
    height: 30px;
    background-color: #333;
    position: absolute;
    bottom: 10px;
    right: -20px;
    border-radius: 10px;
    transform: rotate(-30deg);
}

.dropped-ball {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background-color: #FFC107;
    position: absolute;
    bottom: -10px;
    right: 0px;
    z-index: 3;
}

.dropped-ball.hidden {
    display: none;
}

/* 抽獎機運作動畫 */
.globe.rolling .ball {
    animation: shakeBall 0.5s infinite alternate ease-in-out;
}
.globe.rolling .ball-1 { animation-delay: 0.1s; }
.globe.rolling .ball-2 { animation-delay: 0.2s; }
.globe.rolling .ball-3 { animation-delay: 0.3s; }

@keyframes shakeBall {
    0% { transform: translate(0, 0) rotate(0deg); }
    50% { transform: translate(20px, -40px) rotate(180deg); }
    100% { transform: translate(-20px, -20px) rotate(360deg); }
}

.dropped-ball.dropping {
    display: block;
    animation: dropBall 1s ease-out forwards;
}

@keyframes dropBall {
    0% { transform: translate(-30px, -50px); opacity: 0; }
    50% { opacity: 1; }
    100% { transform: translate(30px, 40px); opacity: 1; }
}

/* ======= 雙欄對照排版 (Split Screen) ======= */
.split-screen {
    display: flex;
    width: 100%;
    min-height: calc(100vh - 70px);
}

.panel {
    flex: 1;
    padding: 40px 5%;
    transition: background-color var(--transition-speed);
}

.west-panel {
    background-color: var(--west-bg);
}

.west-panel h2 {
    color: var(--west-color);
    border-bottom: 2px solid var(--west-color);
    padding-bottom: 10px;
    margin-bottom: 20px;
}

.east-panel {
    background-color: var(--east-bg);
}

.east-panel h2 {
    color: var(--east-color);
    border-bottom: 2px solid var(--east-color);
    padding-bottom: 10px;
    margin-bottom: 20px;
}

/* 資訊卡片 */
.card {
    background-color: var(--card-bg);
    border-radius: 12px;
    padding: 20px;
    margin-bottom: 20px;
    box-shadow: var(--shadow);
}

.card h3 {
    margin-bottom: 15px;
}

.placeholder-img {
    width: 100%;
    border-radius: 8px;
    margin-bottom: 15px;
    object-fit: cover;
}

.map-iframe {
    width: 100%;
    height: 250px;
    border: 0;
    border-radius: 8px;
}

.chart-container {
    position: relative;
    width: 100%;
    height: 300px;
}

/* ======= 響應式設計 (RWD) ======= */
@media (max-width: 768px) {
    .nav-links {
        display: none; /* 手機版可考慮改為漢堡選單，此處簡化隱藏，保留首頁網格導航 */
    }
    .split-screen {
        flex-direction: column;
    }
    .panel {
        min-height: auto;
    }
}