/* === 書法風格分析系統 - 全域樣式 === */

/* --- 引導 banner（跨頁面共用） --- */
.guide-banner {
    display: none;
    position: relative;
    background: linear-gradient(135deg, var(--bg-warm) 0%, #FFF3E0 100%);
    border: 1px solid var(--gold);
    border-radius: var(--radius-lg);
    padding: 1.1rem 2.5rem 1.1rem 1.5rem;
    margin-bottom: 1.5rem;
    animation: guideFadeIn 0.4s ease;
}
.guide-banner.show { display: block; }
@keyframes guideFadeIn {
    from { opacity: 0; transform: translateY(-8px); }
    to   { opacity: 1; transform: translateY(0); }
}
.guide-steps {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    flex-wrap: wrap;
    justify-content: center;
}
.guide-step {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 0.2rem;
    min-width: 100px;
    max-width: 140px;
    flex: 1;
}
.guide-num {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 2rem;
    height: 2rem;
    border-radius: 50%;
    background: var(--primary, #5a3e28);
    color: #fff;
    font-size: 0.95rem;
    font-weight: 700;
    flex-shrink: 0;
    margin-bottom: 0.2rem;
}
.guide-step strong { font-size: 0.9rem; color: var(--primary-dark); font-weight: 700; }
.guide-step p { font-size: 0.78rem; color: var(--text-muted); margin: 0; line-height: 1.4; }
.guide-arrow { font-size: 1.3rem; color: var(--gold); flex-shrink: 0; font-weight: 700; line-height: 1; align-self: center; margin-bottom: 0.5rem; }
.guide-close {
    position: absolute;
    top: 0.5rem; right: 0.6rem;
    background: none; border: none;
    color: var(--text-muted); font-size: 0.95rem;
    cursor: pointer; padding: 0.3rem 0.4rem;
    border-radius: 4px; line-height: 1;
    transition: color 0.15s, background 0.15s;
}
.guide-close:hover { color: var(--primary-dark); background: rgba(0,0,0,0.05); }

/* --- CSS 變數 ---
   設計概念：墨色（褐）+ 印泥硃砂（紅）+ 宣紙（米白）+ 金印章（金），
   對應書法的四種傳統媒材：墨、印泥、紙、金石篆刻。
--- */
:root {
    /* 主色：墨色 */
    --primary: #5B3A29;
    --primary-light: #8B6914;
    --primary-dark: #3E2723;

    /* 強調色：印泥硃砂紅 */
    --accent: #C62828;
    --accent-light: #EF5350;
    --accent-dark: #B71C1C;

    /* 點綴色：金印章色（原本散落在各檔案的 #FFD54F / #C8963A 統一成變數） */
    --gold: #D4A017;
    --gold-light: #FFD54F;

    /* 書法家識別色：仿國畫顏料命名，7 色經 CVD（色盲安全）驗證通過
       （固定順序指派給書法家，不循環使用，見 common.js CALLIGRAPHER_COLORS） */
    --pigment-1: #C6242E; /* 硃砂紅 cinnabar */
    --pigment-2: #A6790A; /* 藤黃 gamboge */
    --pigment-3: #1F7A4D; /* 石綠 malachite */
    --pigment-4: #0B849E; /* 石青 azurite */
    --pigment-5: #2A5FB0; /* 靛藍 indigo */
    --pigment-6: #9C2E7A; /* 紫檀 rosewood */
    --pigment-7: #8C4A0A; /* 赭石 ochre */

    /* 背景：宣紙 */
    --bg: #FAF6F0;
    --bg-card: #FFFFFF;
    --bg-dark: #F0EBE3;
    --bg-warm: #FFF8EC;

    /* 文字 */
    --text: #333333;
    --text-light: #666666;
    --text-muted: #999999;

    /* 邊框 */
    --border: #E0D6C8;
    --border-light: #F0EBE3;

    /* 陰影 */
    --shadow: 0 2px 8px rgba(91, 58, 41, 0.1);
    --shadow-hover: 0 4px 16px rgba(91, 58, 41, 0.15);
    --shadow-lg: 0 8px 28px rgba(91, 58, 41, 0.18);

    /* 圓角 */
    --radius: 8px;
    --radius-lg: 12px;
    --radius-sm: 5px;

    /* 間距尺度（1 = 4px） */
    --space-1: 0.25rem;
    --space-2: 0.5rem;
    --space-3: 0.75rem;
    --space-4: 1rem;
    --space-5: 1.5rem;
    --space-6: 2rem;
    --space-7: 3rem;
    --space-8: 4rem;

    /* 字級尺度 */
    --text-xs: 0.78rem;
    --text-sm: 0.88rem;
    --text-base: 1rem;
    --text-lg: 1.15rem;
    --text-xl: 1.4rem;
    --text-2xl: 1.85rem;
    --text-3xl: 2.4rem;
    --text-hero: clamp(2.6rem, 6vw, 4.2rem);

    /* 字體：標題用襯線（書卷氣、有書法的呼吸感），內文/UI 用無襯線（易讀、現代）
       兩者搭配才有層次對比，全站統一只用一種字體是「看起來很普通」的主因之一 */
    --font-display: 'Noto Serif TC', 'PMingLiU', '新細明體', serif;
    --font-body: 'Noto Sans TC', 'Microsoft YaHei', 'PingFang TC', sans-serif;

    /* 字距：標題略收緊、UI 標籤/眉題略放寬，兩種節奏製造層級感 */
    --tracking-tight: -0.01em;
    --tracking-wide: 0.08em;

    --transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    --transition-fast: all 0.15s ease;
    --max-width: 1200px;
    --nav-height: 64px;
}

/* --- Reset & Base --- */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 16px;
    scroll-behavior: smooth;
}

body {
    font-family: var(--font-body);
    background-color: var(--bg);
    /* 宣紙纖維感：用 SVG feTurbulence 疊一層極淡的雜訊紋理，取代原本死板的
       純色平面背景——這是「數位感」跟「有質地」最直接的差異之一，成本很低
       （純 CSS，沒有額外圖檔），但視覺上會讓整個網站感覺不那麼扁平 */
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='240' height='240'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.035'/%3E%3C/svg%3E");
    color: var(--text);
    line-height: 1.7;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* 標題一律用襯線顯示字體，跟內文的無襯線形成對比——這個對比本身就是層級感的來源，
   不需要額外裝飾就能讓標題「看起來像標題」 */
h1, h2, h3, h4,
.page-title, .hero-title, .card-title,
.section-heading, .section-heading-outside {
    font-family: var(--font-display);
    letter-spacing: var(--tracking-tight);
}

/* --- 導航列 --- */
.main-nav {
    background: var(--primary-dark);
    color: #fff;
    height: var(--nav-height);
    position: sticky;
    top: 0;
    z-index: 1000;
    box-shadow: 0 2px 12px rgba(0,0,0,0.15);
}

.nav-container {
    max-width: var(--max-width);
    margin: 0 auto;
    padding: 0 1.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 100%;
}

.nav-brand {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    text-decoration: none;
    color: #fff;
}

.brand-logo {
    width: 32px;
    height: 32px;
    min-width: 32px;
    min-height: 32px;
    max-width: 32px;
    max-height: 32px;
    object-fit: contain;
    border-radius: 6px;
    display: block;
    flex-shrink: 0;
}

.brand-icon {
    font-size: 1.8rem;
    font-weight: bold;
    color: var(--gold-light);
    text-shadow: 1px 1px 2px rgba(0,0,0,0.3);
}

.brand-text {
    font-family: var(--font-display);
    font-size: 1.15rem;
    font-weight: 700;
    letter-spacing: 0.05em;
}

.nav-toggle {
    display: none;
    background: none;
    border: none;
    color: #fff;
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0.5rem;
}

.nav-links {
    list-style: none;
    display: flex;
    gap: 0;
    flex-wrap: nowrap;
}

.nav-links a {
    position: relative;
    color: rgba(255,255,255,0.8);
    text-decoration: none;
    padding: 0.45rem 0.75rem;
    border-radius: var(--radius);
    transition: var(--transition);
    font-size: 0.88rem;
    letter-spacing: 0.5px;
    white-space: nowrap;
}

.nav-links a:hover {
    color: #fff;
    background: rgba(255,255,255,0.12);
}

.nav-links a.active {
    color: var(--gold-light);
    background: rgba(255,255,255,0.1);
    font-weight: 600;
}


/* --- 主要內容 --- */
.content {
    flex: 1;
    max-width: var(--max-width);
    margin: 0 auto;
    padding: 2rem 1.5rem;
    width: 100%;
}

/* --- 頁面標題 --- */
.page-header {
    text-align: center;
    margin-bottom: var(--space-6);
}

.page-title {
    position: relative;
    display: inline-block;
    font-size: var(--text-3xl);
    color: var(--primary-dark);
    margin-bottom: var(--space-2);
    font-weight: 700;
}

/* 印章式紅點——呼應「印泥硃砂」的設計概念，放在標題右上角，低調不搶戲 */
.page-title::after {
    content: '';
    position: absolute;
    top: -2px;
    right: -14px;
    width: 8px;
    height: 8px;
    border-radius: 2px;
    background: var(--accent);
    opacity: 0.85;
}

.page-subtitle {
    color: var(--text-light);
    font-size: var(--text-base);
}

.page-notice {
    display: inline-block;
    margin-top: 0.6rem;
    padding: 0.3rem 1rem;
    background: var(--bg-card, #faf6f0);
    border: 1px solid var(--border, #d4bfa0);
    border-radius: 99px;
    font-size: 0.85rem;
    color: var(--text-muted, #8a7560);
}

.char-limit-hint {
    font-size: 0.8rem;
    color: var(--text-muted, #8a7560);
    white-space: nowrap;
}

/* --- 卡片 ---
   背景用極淡的暖色漸層取代死板的純白，質地上更接近紙張，而不是一塊數位色塊 */
.card {
    background: linear-gradient(165deg, #FFFFFF 0%, var(--bg-warm) 130%);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    box-shadow: var(--shadow);
    transition: var(--transition);
}

.card:hover {
    box-shadow: var(--shadow-hover);
    border-color: var(--border-light);
}

.card-title {
    font-size: 1.25rem;
    color: var(--primary-dark);
    margin-bottom: 1rem;
    font-weight: 600;
    border-bottom: 2px solid var(--border-light);
    padding-bottom: 0.5rem;
}

/* --- 按鈕 --- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.6rem 1.5rem;
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 1rem;
    font-family: inherit;
    transition: var(--transition);
    letter-spacing: 1px;
    text-decoration: none;
}

.btn-primary {
    background: var(--primary);
    color: #fff;
}

.btn-primary:hover {
    background: var(--primary-dark);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(91,58,41,0.3);
}

.btn-accent {
    background: var(--accent);
    color: #fff;
}

.btn-accent:hover {
    background: #B71C1C;
    transform: translateY(-1px);
}

.btn-outline {
    background: transparent;
    color: var(--primary);
    border: 2px solid var(--primary);
}

.btn-outline:hover {
    background: var(--primary);
    color: #fff;
}

/* 按下的瞬間回饋——沒有這個，按鈕點下去跟沒點感覺一樣，互動會顯得死板 */
.btn-primary:active, .btn-accent:active, .btn-outline:active {
    transform: translateY(0) scale(0.97);
}

/* 鍵盤操作焦點框：只在鍵盤 tab 移動時顯示，滑鼠點擊不顯示，兩者都要顧到 */
.btn:focus-visible,
.filter-btn:focus-visible,
.cal-toggle:focus-visible,
a:focus-visible {
    outline: 2px solid var(--gold);
    outline-offset: 2px;
}

/* 次要/低風險動作（例如「清空」）——視覺權重弱於 primary/outline，避免跟主要操作搶焦點 */
.btn-ghost {
    background: transparent;
    color: var(--text-muted);
    border: none;
    text-decoration: underline;
    text-underline-offset: 2px;
}

.btn-ghost:hover {
    color: var(--primary);
}

.btn-sm {
    padding: 0.35rem 0.8rem;
    font-size: 0.85rem;
}

.btn-lg {
    padding: 0.8rem 2rem;
    font-size: 1.15rem;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

/* --- 表單元素 --- */
.input-group {
    margin-bottom: 1rem;
}

.input-group label {
    display: block;
    margin-bottom: 0.4rem;
    font-weight: 600;
    color: var(--primary-dark);
    font-size: 0.9rem;
}

.form-input {
    width: 100%;
    padding: 0.6rem 1rem;
    border: 2px solid var(--border);
    border-radius: var(--radius);
    font-size: 1rem;
    font-family: inherit;
    transition: var(--transition);
    background: #fff;
}

.form-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(91,58,41,0.1);
}

/* --- 勾選框 --- */
.checkbox-group {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
}

.checkbox-item {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    cursor: pointer;
}

.checkbox-item input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: var(--primary);
    cursor: pointer;
}

.checkbox-item label {
    cursor: pointer;
    font-size: 0.95rem;
}

/* --- 載入動畫 --- */
.loading {
    position: relative;
    min-height: 120px;
}

.loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 40px;
    height: 40px;
    margin: -20px 0 0 -20px;
    border: 4px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* --- 錯誤訊息 --- */
.error-msg {
    background: #FFEBEE;
    color: var(--accent);
    padding: 1rem 1.5rem;
    border-radius: var(--radius);
    border-left: 4px solid var(--accent);
    margin: 1rem 0;
}

/* --- 成功訊息 --- */
.success-msg {
    background: #E8F5E9;
    color: #2E7D32;
    padding: 1rem 1.5rem;
    border-radius: var(--radius);
    border-left: 4px solid #2E7D32;
    margin: 1rem 0;
}

/* --- 提示訊息 --- */
.info-msg {
    background: #FFF8E1;
    color: #F57F17;
    padding: 1rem 1.5rem;
    border-radius: var(--radius);
    border-left: 4px solid #F57F17;
    margin: 1rem 0;
}

/* --- 標籤 / 徽章 --- */
.badge {
    display: inline-block;
    padding: 0.2rem 0.6rem;
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: 600;
    letter-spacing: 0.5px;
}

.badge-dynasty {
    background: #FFF3E0;
    color: #E65100;
}

.badge-style {
    background: #E8EAF6;
    color: #283593;
}

.badge-count {
    background: #E0F2F1;
    color: #00695C;
}

/* --- 網格佈局 --- */
.grid-2 {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1.5rem;
}

.grid-3 {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1.5rem;
}

.grid-4 {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1.5rem;
}

/* --- 頁尾 --- */
.site-footer {
    background: var(--primary-dark);
    color: rgba(255,255,255,0.7);
    text-align: center;
    padding: 1.5rem;
    margin-top: auto;
}

.footer-container {
    max-width: var(--max-width);
    margin: 0 auto;
}

.footer-sub {
    font-size: 0.85rem;
    margin-top: 0.3rem;
    color: rgba(255,255,255,0.5);
}

/* --- 圖片容器 --- */
.img-container {
    text-align: center;
    padding: 1rem;
}

.img-container img {
    max-width: 100%;
    height: auto;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

/* --- 分隔線 --- */
.divider {
    border: none;
    border-top: 1px solid var(--border);
    margin: 1.5rem 0;
}

/* --- 捲動淡入：內容進入視窗時輕輕浮現，取代「整頁一次全部貼上」的死板感 ---
   只用在靜態渲染的區塊上（不是 JS 動態產生的內容，避免時機競爭問題） */
.reveal {
    opacity: 0;
    transform: translateY(18px);
    transition: opacity 0.7s ease, transform 0.7s ease;
}

.reveal.revealed {
    opacity: 1;
    transform: translateY(0);
}

@media (prefers-reduced-motion: reduce) {
    .reveal { opacity: 1; transform: none; transition: none; }
}

/* --- 響應式設計 --- */
@media (max-width: 768px) {
    .nav-toggle {
        display: block;
    }

    .nav-links {
        display: none;
        position: absolute;
        top: var(--nav-height);
        left: 0;
        right: 0;
        background: var(--primary-dark);
        flex-direction: column;
        padding: 1rem;
        gap: 0.5rem;
        box-shadow: 0 4px 12px rgba(0,0,0,0.2);
    }

    .nav-links.show {
        display: flex;
    }

    .nav-links a {
        padding: 0.75rem 1rem;
    }

    .content {
        padding: 1rem;
    }

    .page-title {
        font-size: 1.5rem;
    }

    .grid-2, .grid-3, .grid-4 {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 480px) {
    .brand-text {
        font-size: 0.9rem;
    }

    .page-title {
        font-size: 1.3rem;
    }
}

/* === 全局圖片放大模態 === */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.95);
    z-index: 9999;
    overflow: auto;
    animation: fadeIn 0.3s ease;
}

.modal.show {
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-content {
    position: relative;
    max-width: 90vw;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    animation: slideUp 0.3s ease;
}

.modal-content img {
    max-width: 100%;
    max-height: 85vh;
    object-fit: contain;
    border-radius: var(--radius-lg);
}

.modal-caption {
    color: #fff;
    margin-top: 1rem;
    font-size: 0.95rem;
    text-align: center;
}

.modal-close {
    position: absolute;
    top: -50px;
    right: 0;
    background: none;
    border: none;
    color: #fff;
    font-size: 2rem;
    cursor: pointer;
    transition: var(--transition);
    padding: 0.5rem;
}

.modal-close:hover {
    color: var(--gold-light);
    transform: scale(1.1);
}

/* 左右切換按鈕 */
.modal-nav {
    position: fixed;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(255,255,255,0.15);
    border: none;
    border-radius: 50%;
    width: 48px;
    height: 48px;
    font-size: 2rem;
    line-height: 1;
    color: #fff;
    cursor: pointer;
    transition: background 0.2s, opacity 0.2s;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0.6;
}
.modal-nav:hover { background: rgba(255,255,255,0.3); opacity: 1; }
.modal-prev { left: 16px; }
.modal-next { right: 16px; }

/* 圖片計數器 */
.modal-counter {
    color: rgba(255,255,255,0.6);
    font-size: 0.82rem;
    margin-top: 0.4rem;
    letter-spacing: 0.05em;
    text-align: center;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}
