/* 全局現代化基礎設定 */
:root {
    --primary: #007aff;
    --primary-dark: #0056b3;
    --success: #34c759;
    --success-dark: #28a745;
    --warning: #ff9500;
    --warning-dark: #e68a00;
    --danger: #ff3b30;
    --danger-dark: #d32f2f;
    --bg-color: #f2f2f7;
    --card-bg: #ffffff;
    --text-main: #1c1c1e;
    --text-muted: #8e8e93;
    --border-color: #e5e5ea;
    --input-border: #c7c7cc;
}

body { 
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; 
    background: var(--bg-color); 
    padding: 15px; 
    margin: 0; 
    padding-bottom: 120px; 
    color: var(--text-main); 
}

h2 { font-size: 22px; color: #000; margin-top: 5px; font-weight: 800; letter-spacing: 0.5px; }

/* 卡片模組化設計 */
.top-bar, .panel { 
    background: var(--card-bg); 
    padding: 18px; 
    border-radius: 16px; 
    margin-bottom: 15px; 
    box-shadow: 0 4px 12px rgba(0,0,0,0.04), 0 1px 2px rgba(0,0,0,0.02); 
    border: 1px solid rgba(0,0,0,0.02);
}

.panel-header { 
    display: flex; justify-content: space-between; align-items: center; 
    border-bottom: 1px solid var(--border-color); 
    padding-bottom: 10px; margin-bottom: 15px; 
}
.panel-title { font-size: 18px; font-weight: 700; color: var(--primary); margin: 0; }

/* 輸入框統一優化 (強制消除瀏覽器預設外距) */
select, .datetime-input { 
    width: 100%; 
    height: 46px;
    padding: 0 14px; 
    font-size: 16px; 
    border-radius: 10px; 
    border: 1.5px solid var(--input-border); 
    background: #fafafa; 
    margin: 0; /* 嚴格歸零，防止異常空隙 */
    -webkit-appearance: none; appearance: none; 
    box-sizing: border-box; 
    transition: all 0.2s ease;
    color: var(--text-main);
    font-family: inherit;
}
select:focus, .datetime-input:focus {
    border-color: var(--primary);
    background: #fff;
    box-shadow: 0 0 0 3px rgba(0,122,255,0.15);
    outline: none;
}

/* --- 時間排版區塊徹底重構 (改用 CSS Grid 解決 Chrome 異常拉伸與空隙) --- */
.time-input-container {
    display: grid;
    grid-template-columns: 1fr; /* 手機優先：單列直向網格 */
    gap: 12px; /* 鎖定間距，絕不拉伸 */
    margin-top: 12px;
    margin-bottom: 15px;
}
.time-input-parts {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
}
.time-input-parts > input {
    flex: 1; /* 均分剩餘空間 */
    text-align: center;
    min-width: 0; /* 防止輸入框文字過長撐破容器 */
}
.time-input-parts > span {
    font-weight: 600;
    color: var(--text-main);
    flex-shrink: 0; 
}

/* 電腦/平板版：雙列橫向網格 */
@media (min-width: 500px) {
    .time-input-container {
        grid-template-columns: 1.5fr 1fr; /* 左側日期佔比大一點 */
    }
}
/* ---------------------------------------------------- */

/* 表單與按鈕選項設計 */
.form-group { margin-bottom: 18px; }
.form-group label.title { display: block; font-size: 15px; font-weight: 700; margin-bottom: 10px; color: #3a3a3c; }

.grid-5, .grid-4 { display: grid; gap: 8px; }
.grid-5 { grid-template-columns: repeat(5, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }

.btn-check { 
    display: flex; align-items: center; justify-content: center; 
    background: var(--bg-color); 
    border: 1.5px solid transparent; 
    border-radius: 10px; 
    padding: 10px 0; 
    font-size: 14px; font-weight: 600;
    color: var(--text-muted); 
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1); 
    user-select: none; text-align: center; 
    -webkit-tap-highlight-color: transparent; 
}
input[type="checkbox"], input[type="radio"] { display: none; }

input[type="checkbox"]:checked + .btn-check, input[type="radio"]:checked + .btn-check { 
    background: #e5f1ff; 
    color: var(--primary) !important; 
    border-color: var(--primary); 
    font-weight: 700; 
}
input[type="checkbox"]:disabled + .btn-check { opacity: 0.5; }

.harm-group { display: flex; gap: 10px; margin-top: 8px; }
.harm-group label { flex: 1; }

.select-container { position: relative; }
.select-container::after { content: "▼"; font-size: 12px; color: var(--text-muted); position: absolute; right: 14px; top: 15px; pointer-events: none; }

/* 九宮格主體優化 */
.jiugong-grid { 
    display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; 
    background: #d1d1d6; border: 3px solid #d1d1d6; border-radius: 12px; 
    margin-top: 12px; align-items: stretch; overflow: hidden;
}
.jiugong-cell { 
    background: #fff; min-height: 140px; max-height: 200px; height: 100%; 
    padding: 8px; display: flex; flex-direction: column; 
    justify-content: flex-start; align-items: center; 
    box-sizing: border-box; overflow-y: auto; 
}
.cell-title { 
    font-size: 13px; font-weight: 800; color: var(--text-muted); 
    border-bottom: 2px solid var(--bg-color); width: 100%; 
    text-align: center; padding-bottom: 4px; margin-bottom: 6px; 
    flex-shrink: 0; 
}
.cell-content { font-size: 12px; width: 100%; text-align: left; line-height: 1.4; color: var(--text-main); word-wrap: break-word; flex-grow: 1; }
.cell-god-tag { background: #e1f5fe; color: #0288d1; padding: 2px 6px; border-radius: 4px; font-size: 11px; font-weight: bold; display: inline-block; margin-bottom: 4px; }

.god-info-block { margin-bottom: 8px; border-left: 3px solid var(--primary); padding-left: 6px; padding-bottom: 6px; border-bottom: 1px dashed var(--border-color); }
.god-info-block:last-child { border-bottom: none; margin-bottom: 0; padding-bottom: 0; }
.god-info-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 3px; font-size: 11.5px; }
.god-info-gan { margin-top: 4px; font-size: 11.5px; }

#cell_陰盤\(無中\) { background: #f9f9f9; justify-content: center; color: var(--text-muted); font-weight: bold; }

textarea#previewArea { 
    width: 100%; height: 250px; padding: 14px; font-family: monospace; font-size: 14px; 
    border-radius: 12px; border: 1.5px solid var(--input-border); background: #fafafa; 
    color: #333; box-sizing: border-box; resize: none; margin-top: 10px; 
}

/* 手機端極端尺寸微調 */
@media (max-width: 400px) {
    .jiugong-cell { min-height: 115px; padding: 5px; }
    .cell-title { font-size: 12px; padding-bottom: 3px; margin-bottom: 4px; }
    .cell-content { font-size: 11px; line-height: 1.3; }
    .god-info-grid { font-size: 10.5px; gap: 1px; letter-spacing: -0.2px; }
    .god-info-gan { font-size: 10.5px; margin-top: 2px; }
    .grid-5 { gap: 6px; }
    .grid-4 { gap: 6px; }
}

/* 操作按鈕美化 */
.inner-copy-btn, .auto-plot-btn { 
    width: 100%; padding: 14px; font-size: 16px; font-weight: bold; 
    border: none; border-radius: 12px; cursor: pointer; transition: 0.2s; 
    -webkit-tap-highlight-color: transparent; margin-top: 8px; 
}
.inner-copy-btn { background: var(--success); color: #fff; box-shadow: 0 4px 10px rgba(52, 199, 89, 0.2); margin-top: 12px; }
.inner-copy-btn:active { background: var(--success-dark); transform: scale(0.98); }

.auto-plot-btn { background: linear-gradient(135deg, #ff9f0a, #ff8a00); color: #fff; box-shadow: 0 4px 10px rgba(255, 149, 0, 0.25); }
.auto-plot-btn:active { background: var(--warning-dark); transform: scale(0.98); }

.copy-tool select { width: auto; padding: 6px 28px 6px 12px; font-size: 13px; height: 32px; border-radius: 8px; border: none; background: var(--bg-color); color: var(--text-main); font-weight: 600; }
.panel-header .select-container::after { top: 9px; right: 10px; font-size: 10px; color: var(--text-main); }

.bottom-bar { 
    position: fixed; bottom: 0; left: 0; right: 0; 
    background: rgba(255, 255, 255, 0.92); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
    padding: 15px 20px; border-top: 1px solid rgba(0,0,0,0.08); 
    display: flex; gap: 15px; z-index: 100; 
    padding-bottom: max(15px, env(safe-area-inset-bottom)); 
}
.bottom-bar button { 
    flex: 1; padding: 14px; font-size: 16px; font-weight: 700; 
    border-radius: 12px; border: none; cursor: pointer; transition: 0.2s; 
    -webkit-tap-highlight-color: transparent; 
}
.btn-clear { background: #ffebee; color: var(--danger); }
.btn-clear:active { background: #ffcdd2; transform: scale(0.98); }
.btn-copy { background: var(--success); color: #fff; box-shadow: 0 4px 10px rgba(52, 199, 89, 0.2); }
.btn-copy:active { background: var(--success-dark); transform: scale(0.98); }
