/* ==========================================================================
   1. 全域變數與字體定義 (溫馨童話青蛙村風格)
   ========================================================================== */
:root {
    --bg-overlay: rgba(245, 242, 235, 0.85); /* 溫暖的淺色羊皮紙遮罩 */
    --frog-green: #5c9c38;               /* 活潑青蛙綠 */
    --leaf-light: #89c542;               /* 嫩荷葉綠 */
    --wood-brown: #755229;               /* 橡木樁褐 */
    --pond-blue: #4ba3e3;                /* 澄澈池塘藍 */
    --berry-red: #d9534f;                /* 樹莓警告紅 */
    --paper-tint: #fbf7ed;               /* 仿手繪羊皮紙底色 */
    --font-main: 'Comic Sans MS', 'Chalkboard SE', '華康少女體', sans-serif;
    --base-font-size: 19px;
}

/* ==========================================================================
   2. 基礎底色與通用佈局
   ========================================================================== */
* { 
    box-sizing: border-box; 
    font-family: var(--font-main);
}

header {
    background-color: #ffffff;
    padding: 15px 30px;
    box-shadow: 0 4px 15px rgba(45, 106, 79, 0.1);
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 3px solid #52b788;
    z-index: 10;
}

body {
    margin: 0;
    padding: 0;
    background-image: linear-gradient(var(--bg-overlay), var(--bg-overlay)), url('../img/bg01.png');
    background-size: cover;
    background-position: center;
    background-attachment: fixed;
    color: #3e2723; 
    font-size: var(--base-font-size);
    line-height: 1.8;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    padding-top: 85px; 
    text-align: center; 
}

.terminal-container {
    max-width: 1200px;
    margin: 30px auto;
    padding: 0 20px;
    width: 100%;
    
    /* 新增這兩行：確保裡面的區塊在主流星網頁上不會跑偏 */
    display: flex;
    flex-direction: column;
    align-items: center; 
}

/* 雙欄排版 */
.mission-layout, .sorting-layout {
    display: flex;
    gap: 30px;
    justify-content: center;
    margin-top: 30px;
    flex-wrap: wrap;
}

.decoder-panel, .map-panel {
    flex: 1;
    min-width: 450px;
    background: rgba(255, 255, 255, 0.9);
    padding: 30px;
    border: 4px solid var(--frog-green);
    border-radius: 24px; /* 圓潤的邊角更可愛 */
    box-shadow: 0 8px 20px rgba(92, 156, 56, 0.15);
}

/* ==========================================================================
   3. 🐸 全域大自然傳送導覽列 (整合上一題/下一題/全部題數)
   ========================================================================== */
.frog-nav {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 70px;
    background: rgba(255, 255, 255, 0.92);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border-bottom: 4px solid var(--frog-green);
    box-shadow: 0 4px 15px rgba(92, 156, 56, 0.15);
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 30px;
    z-index: 9999;
}

.nav-brand {
    font-weight: bold;
    font-size: 1.2rem;
    color: var(--wood-brown);
}

.nav-progress {
    font-weight: bold;
    font-size: 1rem;
    background: #edf7ed;
    color: var(--frog-green);
    padding: 6px 16px;
    border-radius: 20px;
    border: 2px dashed var(--leaf-light);
}

.nav-buttons {
    display: flex;
    gap: 12px;
    align-items: center;
}

/* 導覽列特製胖嘟嘟小按鈕 */
.nav-btn {
    text-decoration: none;
    font-size: 0.95rem;
    font-weight: bold;
    padding: 8px 18px;
    border-radius: 25px;
    transition: all 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: none;
}

.nav-btn.home {
    background: var(--paper-tint);
    color: var(--wood-brown);
    border: 2px solid var(--wood-brown);
}

.nav-btn.prev {
    background: #f3f0e9;
    color: #5d4037;
    border-bottom: 3px solid #bdae93;
}

.nav-btn.next {
    background: linear-gradient(135deg, var(--leaf-light), var(--frog-green));
    color: white;
    border-bottom: 3px solid #3d6b24;
}

.nav-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0,0,0,0.1);
}

.nav-btn.next:hover {
    background: linear-gradient(135deg, var(--pond-blue), #217cb3);
    border-bottom-color: #14557d;
}

.nav-btn:active {
    transform: translateY(1px);
    border-bottom-width: 1px;
}

/* 舊版 HUD 保留相容樣式 (若某些舊頁面仍在使用) */
#global-hud {
    display: flex;
    justify-content: space-between;
    padding: 15px 30px;
    background: var(--frog-green);
    border-bottom: 4px solid var(--wood-brown);
    font-size: 1.1rem;
    color: #ffffff;
    box-shadow: 0 4px 10px rgba(0,0,0,0.1);
    border-radius: 0 0 15px 15px;
}

.hud-item {
    font-weight: bold;
    text-shadow: 1px 1px 2px rgba(0,0,0,0.2);
}

.blink { 
    animation: blinker 1.5s infinite; 
    color: #fffb00; 
}

@keyframes blinker {
    50% { opacity: 0.6; }
}

/* ==========================================================================
   4. 溫馨繪本風標題 與 冒險地圖排版 (新增首頁圖示網格)
   ========================================================================== */
.glitch-text {
    font-size: 3rem;
    text-align: center;
    margin-bottom: 10px;
    color: var(--frog-green);
    text-shadow: 2px 2px 0px #fff, 4px 4px 0px var(--leaf-light);
    font-weight: bold;
}

.page-title {
    font-size: 1.8rem;
    text-align: center;
    color: var(--wood-brown);
    margin-bottom: 30px;
}

.panel-header {
    color: var(--wood-brown);
    border-bottom: 3px dashed var(--leaf-light);
    margin-bottom: 20px;
    padding-bottom: 8px;
    font-size: 1.4rem;
    font-weight: bold;
}

/* 首頁專屬大卡片與關卡地圖網格 */
.intro-card {
    background: rgba(255, 255, 255, 0.9);
    border-radius: 24px;
    padding: 30px;
    border: 3px solid var(--leaf-light);
    box-shadow: 0 8px 20px rgba(92, 156, 56, 0.1);
    
    /* 核心修改：設定最大寬度，並讓左右外邊距自動平分（置中） */
    max-width: 600px;           /* 或是設定 width: 80% 等 */
    margin: 0 auto 35px auto;   /* 順序為：上 右 下 左 (保有原本的下邊距 35px) */
}

.map-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 20px;
    margin-top: 20px;
}

.map-node {
    background: #ffffff;
    border: 3px solid #e0dcd3;
    border-radius: 20px;
    padding: 20px;
    text-decoration: none;
    color: inherit;
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.map-node:hover {
    border-color: var(--frog-green);
    transform: translateY(-5px);
    box-shadow: 0 10px 20px rgba(92, 156, 56, 0.15);
}

.map-node.active {
    border-color: var(--frog-green);
    background: var(--paper-tint);
}

.map-node .emoji { 
    font-size: 2.2rem; 
}

.map-node h3 { 
    font-size: 1.2rem; 
    color: var(--wood-brown); 
    margin: 0; 
}

.map-node p { 
    font-size: 0.95rem; 
    color: #5d4037; 
    margin: 0; 
    line-height: 1.5; 
}

/* ==========================================================================
   5. 胖嘟嘟圓角按鈕
   ========================================================================== */
.btn-primary {
    display: inline-block;
    padding: 14px 40px;
    font-size: 1.25rem;
    font-weight: bold;
    border-radius: 30px;
    margin: 10px;
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    border: none;
    border-bottom: 5px solid #6b421e; /* 營造木頭厚度感 */
    color: white;
    background: var(--wood-brown);
    cursor: pointer;
    text-decoration: none;
    text-align: center;
    box-shadow: 0 5px 10px rgba(0,0,0,0.15);
}
.btn-primary:hover {
    background: var(--leaf-light);
    border-bottom: 5px solid var(--frog-green);
    transform: translateY(-3px);
    box-shadow: 0 8px 15px rgba(137, 197, 66, 0.4);
}
.btn-primary:active {
    transform: translateY(2px);
    border-bottom-width: 1px;
}

/* ==========================================================================
   6. 故事繪本與筆記本區塊
   ========================================================================== */
.ancient-notebook {
    background: var(--paper-tint);
    color: #4e342e;
    padding: 30px;
    border: 3px solid var(--wood-brown);
    border-radius: 20px;
    margin: 25px 0;
    box-shadow: 5px 5px 0px rgba(139, 90, 43, 0.15);
}

.handwriting {
    font-size: 1.4rem;
    color: var(--wood-brown);
    font-weight: bold;
    margin-bottom: 20px;
    display: block;
    border-bottom: 2px dashed rgba(139, 90, 43, 0.3);
    padding-bottom: 10px;
}

.symbol {
    font-size: 2.2rem;
    margin-right: 15px;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 50px;
    height: 50px;
}

.desc strong {
    font-size: 1.3rem;
    color: var(--frog-green);
    display: block;
    margin-bottom: 5px;
}

.desc p {
    font-size: 1.05rem;
    color: #5d4037;
    line-height: 1.6;
    margin: 0;
}

.logic-horizontal-container {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 30px;
    flex-wrap: wrap;
}

.logic-visual-box {
    flex: 1;
    max-width: 45%;
    min-width: 300px;
}

.logic-definition-box {
    flex: 1.2;
    border-left: 3px dashed var(--leaf-light);
    padding-left: 25px;
    min-width: 300px;
}

.decoder-guide-img {
    width: 100%;
    height: auto;
    border-radius: 12px;
}

/* ==========================================================================
   7. 荷葉地圖網格與 SVG 樹狀圖
   ========================================================================== */
.interactive-grid {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    gap: 6px;
    background: #e0f2f1;
    padding: 12px;
    border: 4px solid var(--frog-green);
    border-radius: 16px;
}

.cell {
    aspect-ratio: 1;
    background: #ffffff;
    border: 1px solid #b2dfdb;
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.2s;
}

/* 點亮時變成漂亮的池塘藍 */
.cell.active {
    background: var(--pond-blue);
    box-shadow: inset 0 0 8px rgba(255,255,255,0.8);
    border-color: #1976d2;
}

#quadtree-svg {
    width: 100%;
    height: 400px;
    background: #fffdf6;
    border: 3px solid var(--wood-brown);
    border-radius: 16px;
    display: block;
}

/* SVG 樹枝與小果實節點 */
.node-root { fill: var(--wood-brown); stroke: #5d4037; stroke-width: 2; }
.node-water { fill: var(--pond-blue) !important; stroke: #fff; stroke-width: 2; }
.node-dry { fill: #d7ccc8; stroke: #8d6e63; stroke-width: 2; }
.node-mixed { fill: #fffde7; stroke: var(--frog-green); stroke-width: 2; stroke-dasharray: 3; }
.vine { stroke: var(--frog-green); stroke-width: 4; stroke-linecap: round; opacity: 0.8; }
.node-label { fill: var(--wood-brown); font-size: 14px; font-weight: bold; }

/* ==========================================================================
   8. 濾水材料卡片與過濾籃樣式
   ========================================================================== */
.materials-pool {
    background: #f1f8e9;
    border: 3px dashed var(--leaf-light);
    padding: 20px;
    border-radius: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.material-card {
    background: #ffffff;
    border: 2px solid var(--leaf-light);
    padding: 12px 20px;
    border-radius: 12px;
    cursor: grab;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 4px 6px rgba(0,0,0,0.05);
}
.material-card:active { cursor: grabbing; }

.filter-tower {
    background: #e8f5e9;
    border: 4px solid var(--wood-brown);
    padding: 20px;
    border-radius: 20px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.tower-slot {
    background: rgba(255, 255, 255, 0.7);
    border: 2px dashed var(--frog-green);
    height: 65px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #757575;
    font-size: 0.95rem;
}

.tower-slot.drag-over {
    border-color: var(--pond-blue);
    background: #e1f5fe;
}

/* ==========================================================================
   9. 頁尾風格
   ========================================================================== */
#global-footer {
    text-align: center;
    padding: 25px;
    font-size: 0.95rem;
    color: #6d4c41;
    background: rgba(255,255,255,0.4);
    border-top: 2px dashed rgba(139, 90, 43, 0.2);
    margin-top: auto; 
}
