:root {
    --text-size: 18px;      
    --ui-font-size: 1.1em;  
    --ui-scale: 1.15;       
    --primary-color: #007bff;
    --primary-hover: #0056b3;
    --bg-color: #f8f9fa;
    --surface-color: #ffffff;
    --text-main: #212529;
    --text-muted: #6c757d;
    --border-color: #e9ecef;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background-color: var(--bg-color); color: var(--text-main);
    margin: 0; padding: 70px 10px calc(220px + env(safe-area-inset-bottom)) 10px;
    box-sizing: border-box; line-height: 1.6; transition: font-size 0.3s;
}

/* 頂部標題區塊 */
.header-container { 
    position: fixed; top: 0; left: 0; width: 100%;
    display: flex; justify-content: space-between; align-items: center; 
    padding: 12px 15px; background-color: rgba(255, 255, 255, 0.92);
    backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
    border-bottom: 1px solid rgba(0, 0, 0, 0.08); box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
    z-index: 50; box-sizing: border-box; transition: transform 0.4s cubic-bezier(0.25, 0.8, 0.25, 1);
}
.header-container.hidden { transform: translateY(-100%); }
h1 { margin: 0; font-size: 1.3em; color: var(--text-muted); display: flex; align-items: center; font-weight: 600; }
.mayren-logo {
    background: linear-gradient(135deg, #1e3c72 0%, #2a5298 100%); color: #ffffff !important;
    text-decoration: none; font-weight: bold; font-size: 0.8em; 
    padding: 4px 10px; border-radius: 6px; margin-right: 12px; box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}
.top-settings-btn { color: #adb5bd; cursor: pointer; padding: 5px; z-index: 10; display: flex; align-items: center; }
.current-chapter-title {
    margin-top: 10px; margin-bottom: 15px; font-size: calc(var(--text-size) * 1.3); 
    color: var(--primary-color); border-bottom: 3px solid var(--primary-color); 
    padding-bottom: 5px; display: inline-block; font-weight: 700;
}

/* 經文表格 */
table { 
    width: 100%; border-collapse: separate; border-spacing: 0; 
    background-color: var(--surface-color); border-radius: 12px; overflow: hidden; 
    box-shadow: 0 4px 12px rgba(0,0,0,0.05); margin-bottom: 50px; 
}
th, td { padding: 12px 10px; text-align: left; font-size: var(--text-size); border-bottom: 1px solid var(--border-color); }
tr:last-child td { border-bottom: none; }
th { background-color: #f1f3f5; color: var(--text-muted); font-weight: 600; font-size: 0.9em; }
td:first-child { font-weight: bold; color: var(--primary-color); width: 45px; text-align: center; background-color: #fdfdfe; border-right: 1px solid var(--border-color); }

/* 底部列 */
.bottom-fixed-bar {
    position: fixed; bottom: 0; left: 0; width: 100%; background-color: rgba(255, 255, 255, 0.92);
    backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
    border-top: 1px solid rgba(0, 0, 0, 0.08); box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.06); z-index: 50;
    padding-top: calc(12px * var(--ui-scale)); padding-bottom: calc((15px * var(--ui-scale)) + env(safe-area-inset-bottom)); 
    box-sizing: border-box; transition: transform 0.4s cubic-bezier(0.25, 0.8, 0.25, 1);
}
.bottom-fixed-bar.hidden { transform: translateY(100%); }
.bottom-fixed-bar::after {
    content: ''; position: absolute; top: 100%; left: 0; width: 100%; height: 50vh;
    background-color: rgba(255, 255, 255, 0.92); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
}
.book-tabs { display: flex; overflow-x: auto; white-space: nowrap; gap: 12px; padding: 0 15px calc(12px * var(--ui-scale)) 15px; scrollbar-width: none; }
.book-tabs::-webkit-scrollbar { display: none; }
.book-tab {
    font-size: var(--ui-font-size);
    padding: calc(8px * var(--ui-scale)) calc(18px * var(--ui-scale));
    background-color: #f1f3f5;
    border-radius: 8px; /* 稍微減少圓角以符合 grid-item 的風格 */
    text-decoration: none;
    color: #495057;
    flex-shrink: 0;
    font-weight: 600;
    border-left: 4px solid #ced4da; /* 預設邊框 */
    transition: all 0.3s ease;
    box-sizing: border-box;
    display: flex;
    align-items: center;
}

/* 修改 active 狀態：保持主色調，但強化視覺 */
.book-tab.active {
    background-color: var(--primary-color) !important;
    color: white !important;
    border-left-color: #004a99 !important; /* 深藍邊框 */
    box-shadow: 0 4px 10px rgba(0,123,255,0.3);
}
.chapter-badge { background-color: rgba(255,255,255,0.2); border-radius: 12px; padding: 2px 8px; font-size: 0.8em; margin-left: 6px; }

/* 底部按鈕 */
.bottom-nav-buttons { display: flex; justify-content: center; align-items: center; gap: 12px; padding: 0 10px; }
.button {
    font-size: calc(1em * var(--ui-scale)); padding: calc(10px * var(--ui-scale)) calc(18px * var(--ui-scale));
    background-color: var(--primary-color); color: white; border: none; border-radius: 8px; cursor: pointer; text-decoration: none; font-weight: 600; box-shadow: 0 2px 6px rgba(0,123,255,0.3);
}
.button.disabled { background-color: #dee2e6; color: #adb5bd; cursor: not-allowed; box-shadow: none; }
.home-button { background: linear-gradient(135deg, #343a40 0%, #1d2124 100%) !important; }

/* Sheet 彈出選單 */
.sheet-overlay {
    position: fixed; top: 0; left: 0; width: 100%; height: 100dvh;
    background-color: rgba(0, 0, 0, 0.6); z-index: 999; opacity: 0; visibility: hidden; transition: opacity 0.4s ease; 
}
.sheet-overlay.active { opacity: 1; visibility: visible; }
.sheet-content {
    position: absolute; bottom: -100%; left: 0; width: 100%; background-color: var(--surface-color); 
    border-radius: 24px 24px 0 0; padding: 10px 20px 30px 20px; box-sizing: border-box; 
    max-height: 85vh; display: flex; flex-direction: column; transition: bottom 0.4s cubic-bezier(0.25, 0.8, 0.25, 1);
}
.sheet-overlay.active .sheet-content { bottom: 0; }
.sheet-content::after { content: ''; position: absolute; top: 100%; left: 0; width: 100%; height: 50vh; background-color: var(--surface-color); }
.sheet-header { text-align: center; padding-bottom: 15px; border-bottom: 1px solid var(--border-color); margin-bottom: 15px; touch-action: none; }
.sheet-body { overflow-y: auto; flex-grow: 1; padding-bottom: env(safe-area-inset-bottom); }
.drag-handle { width: 40px; height: 5px; background-color: #dee2e6; border-radius: 3px; margin: 5px auto 15px auto; }

/* 經卷選單排版與色彩 */
.grid-container { display: grid; grid-template-columns: repeat(auto-fill, minmax(65px, 1fr)); gap: 10px; margin-bottom: 20px;}
.grid-item {
    display: flex; justify-content: center; align-items: center; background-color: var(--bg-color); 
    border: 1px solid var(--border-color); border-radius: 10px; height: 50px; 
    text-decoration: none; color: var(--text-main); font-weight: 600; box-sizing: border-box;
}
.category-header { font-size: 1.05em; font-weight: bold; color: var(--text-muted); margin: 15px 0 10px 5px; padding-bottom: 3px; border-bottom: 2px solid var(--border-color); }
.settings-group { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }
.settings-btn { padding: 12px; border: 1px solid var(--border-color); background: var(--bg-color); border-radius: 10px; flex: 1; font-weight: 500; cursor: pointer; color: var(--text-main); }
.settings-btn.active { background: var(--primary-color); color: white; border-color: var(--primary-color); box-shadow: 0 2px 6px rgba(0,123,255,0.3); }