/* Anglican shared styles: layout, theme, typography, office components. */
* { box-sizing: border-box; margin: 0; padding: 0; }
:root {
    color-scheme: light;
    --ease-out: cubic-bezier(.23, 1, .32, 1);
    --control-height: 42px;
}
html { font-size: 16px; -webkit-text-size-adjust: 100%; }
body { 
    font-family: -apple-system, "PingFang TC", "Microsoft JhengHei", "Noto Sans TC", sans-serif; 
    background: var(--page-bg); 
    color: var(--text-main); 
    min-height: 100vh;
    font-optical-sizing: auto;
    text-rendering: optimizeLegibility;
    -webkit-font-smoothing: antialiased;
    transition: background-color 220ms var(--ease-out), color 220ms var(--ease-out); 
}
a { color: inherit; text-decoration: none; }
.topbar { 
    text-align: center; 
    padding: 24px max(16px, env(safe-area-inset-right)) 16px max(16px, env(safe-area-inset-left));
    background: var(--topbar-bg);
    -webkit-backdrop-filter: blur(20px) saturate(160%);
    backdrop-filter: blur(20px) saturate(160%);
    border-bottom: 1px solid var(--border-light); 
    transition: background-color 220ms var(--ease-out); 
}
.topbar h1 { 
    font-size: clamp(2rem, 7vw, 2.35rem);
    line-height: 1.12;
    font-weight: 500; 
    margin-bottom: 18px;
    letter-spacing: .06em;
    color: var(--rubric-red);
}
.topbar nav { display: flex; gap: 8px; justify-content: center; align-items: center; flex-wrap: wrap; }
.topbar .ym { color: var(--text-muted); font-size: 14px; background: var(--btn-container); padding: 5px 12px; border-radius: 8px; }
.nav-btn {
    display: inline-flex;
    min-height: 34px;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 6px 12px;
    border: 1px solid transparent;
    border-radius: 10px;
    background: var(--btn-container);
    color: var(--text-main);
    font: inherit;
    font-size: 14px;
    line-height: 1;
    cursor: pointer;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    transition: background-color 160ms ease, border-color 160ms ease, transform 120ms var(--ease-out);
}
.nav-btn-secondary { background: transparent; border-color: var(--border-light); }
.nav-btn:active { transform: scale(.97); }
.topbar-actions { display: inline-flex; gap: 8px; }
.container { max-width: 680px; margin: 24px auto; padding: 0 16px calc(48px + env(safe-area-inset-bottom)); }
.card { 
    border: 1px solid var(--card-border);
    border-radius: 24px; 
    padding: 24px; 
    box-shadow: var(--card-shadow);
    background-color: var(--card-bg); 
    transition: background-color 220ms var(--ease-out), border-color 220ms var(--ease-out); 
}
.card .sub { font-size: 14px; opacity: .8; margin-top: 4px; }
.card hr { border: none; border-top: 1px solid rgba(128,128,128,.4); margin: 18px 0; }
.card ul { list-style: none; }
.card li { font-size: 14px; padding: 3px 0; }
.card li.transferred { font-style: italic; }
.office-selector,
.day-nav { width: 100%; margin-inline: auto; }
.office-selector {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 4px;
    margin-bottom: 16px;
    padding: 4px;
    border: 1px solid var(--border-light);
    border-radius: 14px;
    background: var(--btn-container);
}
.office-btn {
    display: flex;
    min-width: 0;
    min-height: var(--control-height);
    align-items: center;
    justify-content: center;
    padding: 8px 4px;
    border: 1px solid transparent;
    border-radius: 10px;
    background: transparent;
    color: var(--text-main);
    font-size: 15px;
    line-height: 1.2;
    text-decoration: none;
    -webkit-tap-highlight-color: transparent;
    transition: background-color 160ms ease, border-color 160ms ease, color 160ms ease, transform 120ms var(--ease-out), box-shadow 160ms ease;
}
.office-btn.active {
    border-color: var(--rubric-red);
    background: var(--rubric-red);
    box-shadow: 0 1px 3px rgba(0, 0, 0, .14);
    color: #fff;
    font-weight: 600;
}
.office-btn:active { transform: scale(.97); }
.day-nav { display: flex; align-items: center; justify-content: center; margin: 0 0 24px; gap: 8px; }
.day-nav a { 
    flex: 1; 
    display: inline-flex;
    min-width: 0;
    min-height: var(--control-height);
    align-items: center;
    justify-content: center;
    text-align: center; 
    background: var(--card-bg); 
    color: var(--text-main); 
    border: 1px solid var(--border-light);
    border-radius: 11px; 
    padding: 8px 10px; 
    font-size: 14px; 
    transition: background-color 160ms ease, border-color 160ms ease, transform 120ms var(--ease-out);
}
.day-nav a:active { transform: scale(.98); }
.day-nav form { display: inline-flex; flex: 1 1 auto; min-width: 0; margin: 0; }
.day-nav input[type="date"] {
    flex: 1 1 auto;
    width: 100%;
    min-width: 0;
    min-height: var(--control-height);
    margin: 0;
    padding: 0 10px;
    border: 1px solid var(--border-light);
    border-radius: 11px;
    outline: none;
    background: var(--card-bg);
    color: var(--text-main);
    font: inherit;
    font-size: 14px;
    cursor: pointer;
}
.office-card { margin-top: 0; padding: 34px 28px; }
.office-jump-wrap { margin-top: 16px; }
.office-jump {
    display: block;
    width: 100%;
    padding: 14px 24px;
    border-radius: 13px;
    background: var(--rubric-red);
    box-shadow: 0 2px 8px rgba(80, 0, 0, .14);
    color: #fff;
    font-size: 15px;
    font-weight: 600;
    letter-spacing: .08em;
    text-align: center;
    -webkit-tap-highlight-color: transparent;
    transition: filter 160ms ease, transform 120ms var(--ease-out);
}
.office-jump:active { transform: scale(.985); }
.lang-dropdown { position: relative; }
.lang-dropdown summary { list-style: none; }
.lang-dropdown summary::-webkit-details-marker { display: none; }
.menu-chevron { font-size: 12px; transition: transform 180ms var(--ease-out); }
.lang-dropdown[open] .menu-chevron { transform: rotate(180deg); }
.lang-content {
    position: absolute;
    top: calc(100% + 7px);
    right: 0;
    z-index: 100;
    min-width: 132px;
    overflow: hidden;
    padding: 5px;
    border: 1px solid var(--card-border);
    border-radius: 13px;
    background: var(--menu-bg);
    -webkit-backdrop-filter: blur(20px) saturate(160%);
    backdrop-filter: blur(20px) saturate(160%);
    box-shadow: 0 14px 36px rgba(0, 0, 0, .16);
    transform-origin: top right;
}
.lang-content a { display: block; padding: 9px 11px; border-radius: 8px; color: var(--text-main); font-size: 14px; text-align: left; }
.lang-content .lang-compare { color: var(--link-color); font-weight: 600; }
.menu-divider { height: 1px; margin: 4px 6px; background: var(--border-light); }
/* 月表 */
table.month { width: 100%; border-collapse: collapse; background: var(--card-bg); border-radius: 12px; overflow: hidden; box-shadow: 0 1px 4px rgba(0,0,0,.08); }
table.month td { padding: 9px 10px; border-bottom: 1px solid var(--border-light); font-size: 14px; vertical-align: middle; }
table.month tr:last-child td { border-bottom: none; }
table.month td.day { width: 52px; text-align: center; font-weight: 700; }
table.month td.day .wd { display: block; font-size: 11px; font-weight: 400; color: var(--text-muted); }
table.month tr.sunday td.day, table.month tr.sunday td.day .wd { color: var(--rubric-red); }
.color-bar { display: inline-block; width: 5px; height: 34px; border-radius: 2px; margin-right: 8px; vertical-align: middle; }
.rank-tag { display: inline-block; font-size: 11px; font-weight: 600; padding: 1px 6px; border-radius: 4px; margin-left: 6px; }
.comm-line { font-size: 12px; color: var(--text-muted); margin-top: 2px; margin-left: 13px; }
.trans-line { font-size: 12px; color: #fd7e14; margin-top: 2px; margin-left: 13px; }
.month-nav { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.month-nav .cur { font-size: 16px; font-weight: 600; }
.hint { text-align: center; color: var(--text-muted); font-size: 12px; margin-top: 16px; }
/* 定義 EB Garamond 正規體 */
@font-face {
    font-family: 'EB Garamond';
    src: url('../../fonts/EBGaramond-Medium.ttf') format('truetype');
    font-weight: 500;
    font-style: normal;
    font-display: swap;
}

/* 定義 EB Garamond 斜體 */
@font-face {
    font-family: 'EB Garamond';
    src: url('../../fonts/EBGaramond-Italic.ttf') format('truetype');
    font-weight: normal;
    font-style: italic;
    font-display: swap;
}

/* 定義 EB Garamond 粗體 */
@font-face {
    font-family: 'EB Garamond';
    src: url('../../fonts/EBGaramond-Bold.ttf') format('truetype');
    font-weight: bold;
    font-style: normal;
    font-display: swap;
}

/* 定義 EB Garamond 粗斜體 */
@font-face {
    font-family: 'EB Garamond';
    src: url('../../fonts/EBGaramond-BoldItalic.ttf') format('truetype');
    font-weight: bold;
    font-style: italic;
    font-display: swap;
}
/* ==================== 禮儀書共用排版樣式 ==================== */
/* 左右對照雙欄排版 */
.bilingual-row {
    display: flex;
    gap: 24px;
    margin-bottom: 12px;
}
.bilingual-col {
    flex: 1;
    min-width: 0;
    text-align: justify;
}
@media (max-width: 600px) {
    .bilingual-row { flex-direction: column; gap: 8px; }
}

/* 英文專屬：首字下沉 (Drop Cap) 佔據兩行 */
.en-drop-cap::first-letter {
    float: left;
    color: var(--rubric-red);
    font-size: 2.8em;
    line-height: 0.75;
    padding-top: 4px;
    padding-right: 6px;
    font-weight: bold;
}

/* 英文古典標題字體共用類別 */
.bcp-en-title {
    font-family: 'EB Garamond', serif;
}
/* ==================== 全域色彩變數 ==================== */
/* 1. 預設 (淺色模式) / 強制淺色模式 */
:root, html[data-theme="light"] {
    --page-bg: #f5f5f7;          
    --card-bg: #ffffff;          
    --text-main: #000000;        
    --text-en: #333333;          
    --text-muted: #555555;       
    --rubric-red: #800000;       
    --border-light: #eaeaea;     
    --btn-container: #e9e9eb;    
    --btn-border: #d1d1d6;
    --btn-active-bg: #c5c5c9;
    --btn-active-text: #000000;
    --topbar-bg: rgba(255, 255, 255, .82);
    --menu-bg: rgba(255, 255, 255, .92);
    --card-border: rgba(0, 0, 0, .055);
    --card-shadow: 0 12px 34px rgba(0, 0, 0, .075), 0 1px 2px rgba(0, 0, 0, .04);
    --link-color: #0066cc;
}

/* 2. 強制深色模式 */
html[data-theme="dark"] {
    color-scheme: dark;
    --page-bg: #000000;          
    --card-bg: #1c1c1e;          
    --text-main: #ffffff;        
    --text-en: #e5e5ea;          
    --text-muted: #8e8e93;       
    --rubric-red: #ff6961;       
    --border-light: #38383a;     
    --btn-container: #2c2c2e;    
    --btn-border: #38383a;
    --btn-active-bg: #636366;
    --btn-active-text: #ffffff;
    --topbar-bg: rgba(28, 28, 30, .84);
    --menu-bg: rgba(44, 44, 46, .94);
    --card-border: rgba(255, 255, 255, .09);
    --card-shadow: 0 16px 40px rgba(0, 0, 0, .34);
    --link-color: #64a8ff;
}

/* 3. 自動模式 (跟隨系統深色) */
@media (prefers-color-scheme: dark) {
    html:not([data-theme="light"]) {
        color-scheme: dark;
        --page-bg: #000000;          
        --card-bg: #1c1c1e;          
        --text-main: #ffffff;        
        --text-en: #e5e5ea;          
        --text-muted: #8e8e93;       
        --rubric-red: #ff6961;       
        --border-light: #38383a;     
        --btn-container: #2c2c2e;    
        --btn-border: #38383a;
        --btn-active-bg: #636366;
        --btn-active-text: #ffffff;
        --topbar-bg: rgba(28, 28, 30, .84);
        --menu-bg: rgba(44, 44, 46, .94);
        --card-border: rgba(255, 255, 255, .09);
        --card-shadow: 0 16px 40px rgba(0, 0, 0, .34);
        --link-color: #64a8ff;
    }
}
/* ==================== 字體：全部使用系統默認字體 ==================== */
/* 確保所有導航按鈕、下拉選單、日期選擇器使用各個系統預設字體 */
.topbar .nav-btn,
.topbar select,
.topbar input[type="date"],
.office-content a,
.lang-content a,
.office-dropdown button {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif !important;
}

/* Shared office components. Special rubrics and canticles keep their own overrides. */
.office-module { margin-top: 32px; margin-bottom: 32px; }
.office-title { text-align: center; margin-top: 0; margin-bottom: 36px; font-size: 2.2em; color: var(--text-main, #222); letter-spacing: 2px; }
.office-feast-subtitle { text-align: center; margin: -24px 0 36px; color: var(--text-muted, #888); font-size: 17px; letter-spacing: 1px; font-style: italic; }
.office-section-heading { text-align: center; margin-bottom: 16px; }
.office-section-title { margin: 0; color: var(--rubric-red); font-size: 1.2em; font-weight: bold; }
.office-options { background: var(--btn-container); padding: 4px; border-radius: 8px; display: inline-flex; flex-wrap: wrap; justify-content: center; gap: 4px; border: 1px solid var(--btn-border); max-width: 100%; }
.office-options-row { display: flex; justify-content: center; margin: 8px 0 16px; }
.office-response { display: flex; gap: 6px; align-items: flex-start; }
.office-response-label { color: var(--rubric-red); font-weight: bold; white-space: nowrap; }
.office-mark { color: var(--rubric-red); white-space: nowrap; }
.office-empty { text-align: center; color: var(--text-muted); padding: 30px; }

.office-choice {
    border: none; border-radius: 6px; padding: 6px 16px;
    font-size: 15px; cursor: pointer;
    transition: background-color 160ms ease, color 160ms ease, transform 120ms var(--ease-out);
    white-space: nowrap; font-family: inherit; line-height: 1.2;
    background: transparent; color: var(--text-muted); font-weight: normal;
    flex-shrink: 0;
}
.office-choice:active { transform: scale(.97); }
.office-choice.is-active { background: var(--rubric-red); color: #ffffff; font-weight: 500; }
.office-choice:focus-visible,
.nav-btn:focus-visible,
.office-btn:focus-visible,
.day-nav a:focus-visible,
.day-nav input[type="date"]:focus-visible,
.office-jump:focus-visible,
.lang-content a:focus-visible,
.lectionary-search:focus-visible {
    outline: 2px solid var(--rubric-red); outline-offset: 3px;
}
.office-paragraph { margin-bottom: var(--paragraph-gap, 16px); }
.office-text { color: var(--text-main); line-height: var(--text-leading, 1.6); text-align: var(--text-align, justify); font-weight: normal; }
.office-text-secondary { color: var(--text-en); line-height: var(--text-leading, 1.4); font-family: 'EB Garamond', serif; }
.office-text-en { font-family: 'EB Garamond', serif; }
.office-rubric { color: var(--rubric-red); font-weight: 500; }
.office-rubric.office-text-en, .office-rubric.office-text-secondary { font-style: italic; }

/* 經課表 */
.lectionary-table-tools {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 16px;
}
.lectionary-search-label {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}
.lectionary-search {
    flex: 1;
    min-width: 0;
    height: 38px;
    padding: 0 12px;
    color: var(--text-main);
    background: var(--card-bg);
    border: 1px solid var(--btn-border);
    border-radius: 8px;
    font: inherit;
}
.lectionary-search:focus {
    outline: 2px solid var(--rubric-red);
    outline-offset: 2px;
}
.lectionary-count {
    flex: 0 0 auto;
    color: var(--text-muted);
    font-size: 13px;
}
.lectionary-table-scroll {
    width: 100%;
    overflow-x: auto;
    border: 1px solid var(--border-light);
    border-radius: 10px;
}
.lectionary-table {
    width: 100%;
    min-width: 600px;
    border-collapse: collapse;
    background: var(--card-bg);
    font-size: 13px;
    line-height: 1.45;
}
.lectionary-table th,
.lectionary-table td {
    padding: 9px 10px;
    border-right: 1px solid var(--border-light);
    border-bottom: 1px solid var(--border-light);
    text-align: left;
    vertical-align: top;
}
.lectionary-table th:last-child,
.lectionary-table td:last-child { border-right: 0; }
.lectionary-table tbody tr:last-child td { border-bottom: 0; }
.lectionary-table th {
    position: sticky;
    top: 0;
    z-index: 1;
    color: var(--rubric-red);
    background: var(--btn-container);
    font-weight: 600;
    white-space: nowrap;
}
.lectionary-office { width: 54px; white-space: nowrap; }
.lectionary-name { vertical-align: middle !important; font-weight: 500; }
.lectionary-empty { color: var(--text-muted); }
.lectionary-table .lectionary-group-row th {
    position: static;
    color: #ffffff;
    background: var(--rubric-red);
    border-right: 0;
    font-size: 15px;
    letter-spacing: 1px;
}
.lectionary-table .lectionary-section-row th {
    position: static;
    padding: 10px;
    color: var(--rubric-red);
    background: var(--btn-container);
    border-right: 0;
    font-size: 14px;
    letter-spacing: .3px;
}
.lectionary-table .lectionary-variant-row th {
    position: static;
    padding: 8px 10px 6px 20px;
    color: var(--rubric-red);
    background: var(--card-bg);
    border-right: 0;
    font-size: 13px;
}
.lectionary-antiphon {
    display: block;
    margin-top: 5px;
    color: var(--rubric-red);
    font-size: 12px;
}
@media (max-width: 600px) {
    .lectionary-table-tools { align-items: stretch; flex-direction: column; }
    .lectionary-count { text-align: right; }
}

@media (hover: hover) and (pointer: fine) {
    .nav-btn:hover,
    .day-nav a:hover,
    .lang-content a:hover { background: var(--btn-active-bg); }
    .office-btn:not(.active):hover { background: var(--card-bg); }
    .office-jump:hover { filter: brightness(1.08); }
    .lectionary-table tbody tr:hover { background: var(--btn-container); }
}

@media (max-width: 520px) {
    :root { --control-height: 44px; }
    .topbar { padding-top: 20px; }
    .topbar h1 { margin-bottom: 16px; }
    .container { margin-top: 16px; padding-inline: 12px; }
    .office-selector { gap: 3px; }
    .office-btn { font-size: 14px; }
    .day-nav { gap: 6px; }
    .day-nav a { padding-inline: 7px; font-size: 13px; }
    .day-nav input[type="date"] { padding-inline: 7px; font-size: 13px; }
    .office-card { padding: 30px 22px; border-radius: 22px; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { scroll-behavior: auto !important; transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; }
}

@media (prefers-reduced-transparency: reduce) {
    .topbar, .lang-content { background: var(--card-bg); -webkit-backdrop-filter: none; backdrop-filter: none; }
}

@media (prefers-contrast: more) {
    .card, .nav-btn, .office-selector, .day-nav a, .day-nav input[type="date"], .lang-content { border-color: currentColor; }
}
