/*
Theme Name: Chronicle Timeline
Theme URI: https://example.com/chronicle-timeline
Author: Chronicle Timeline
Author URI: https://example.com/
Description: 通用版历史 / 事件时间线主题。自定义文章类型 timeline_event，按历史年份（支持公元前负数、约、时间段）排序，竖向时间轴、类型筛选、年份跳转、历史上的今天、详情页前因后果与同期事件。白色界面，无需任何插件，PHP 7.4 / WordPress 6.4 / 6.5 兼容。
Version: 1.0.0
Requires at least: 6.0
Tested up to: 6.5
Requires PHP: 7.4
License: GNU General Public License v2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
Text Domain: chronicle-timeline
Tags: timeline, history, events, custom-post-type, custom-colors, responsive, accessibility-ready
*/

/* ============ 变量与基础 ============ */
:root {
    --ct-primary: #8c2f1b;
    --ct-primary-dark: #6f2413;
    --ct-accent: #b7791f;
    --ct-bg: #ffffff;
    --ct-surface: #ffffff;
    --ct-surface-2: #f5f5f5;
    --ct-text: #1a1a1a;
    --ct-muted: #666666;
    --ct-border: #e5e7eb;
    --ct-line: #d1d5db;
    --ct-shadow: 0 2px 10px rgba(0, 0, 0, 0.06);
    --ct-radius: 10px;
    --ct-max: 1080px;
}
* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
    margin: 0;
    background: var(--ct-bg);
    color: var(--ct-text);
    font-family: "Noto Serif SC", "Songti SC", Georgia, "Times New Roman", serif;
    font-size: 16px;
    line-height: 1.75;
}
a { color: var(--ct-primary); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; height: auto; }
h1, h2, h3, h4 { line-height: 1.35; margin: 0 0 0.6em; }
p { margin: 0 0 1em; }
button, input, select { font: inherit; }
:focus-visible { outline: 3px solid var(--ct-accent); outline-offset: 2px; }
.screen-reader-text { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; }

.ct-wrap { max-width: var(--ct-max); margin: 0 auto; padding: 0 20px; }
.ct-narrow { max-width: 760px; margin: 0 auto; padding: 0 20px; }

/* ============ 页眉页脚 ============ */
.site-header { background: var(--ct-surface); border-bottom: 3px double var(--ct-line); position: sticky; top: 0; z-index: 50; }
.site-header-inner { max-width: var(--ct-max); margin: 0 auto; padding: 14px 20px; display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.site-branding a { color: var(--ct-text); }
.site-title { font-size: 1.5rem; margin: 0; letter-spacing: 0.05em; }
.site-title a:hover { text-decoration: none; color: var(--ct-primary); }
.site-description { color: var(--ct-muted); font-size: 0.85rem; margin: 2px 0 0; }
.main-nav { margin-left: auto; }
.main-nav ul { list-style: none; margin: 0; padding: 0; display: flex; gap: 18px; flex-wrap: wrap; }
.main-nav a { color: var(--ct-text); }
.main-nav a:hover { color: var(--ct-primary); }
.site-footer { border-top: 3px double var(--ct-line); margin-top: 56px; padding: 28px 0 36px; background: var(--ct-surface); color: var(--ct-muted); font-size: 0.9rem; }
.site-footer a { color: var(--ct-muted); }

/* ============ 首页头 / 筛选 ============ */
.ct-hero { padding: 36px 0 8px; text-align: center; }
.ct-hero h1 { font-size: 2rem; margin-bottom: 6px; }
.ct-hero p { color: var(--ct-muted); max-width: 640px; margin: 0 auto; }
.ct-chip { display: inline-block; padding: 6px 14px; border: 1px solid var(--ct-border); border-radius: 999px; background: var(--ct-surface); color: var(--ct-text); font-size: 0.9rem; }
.ct-chip:hover { text-decoration: none; border-color: var(--ct-primary); }
.ct-chip.is-active { background: var(--ct-primary); border-color: var(--ct-primary); color: #fff; }
.ct-filters { background: var(--ct-surface); border: 1px solid var(--ct-border); border-radius: var(--ct-radius); box-shadow: var(--ct-shadow); padding: 16px; margin: 18px 0 8px; }
.ct-filters form { display: flex; gap: 10px; flex-wrap: wrap; align-items: end; }
.ct-field { display: flex; flex-direction: column; gap: 4px; font-size: 0.85rem; color: var(--ct-muted); }
.ct-field input, .ct-field select { background: var(--ct-bg); color: var(--ct-text); border: 1px solid var(--ct-border); border-radius: 6px; padding: 8px 10px; min-width: 120px; }
.ct-btn { background: var(--ct-primary); color: #fff; border: 0; border-radius: 6px; padding: 9px 18px; cursor: pointer; }
.ct-btn:hover { background: var(--ct-primary-dark); }
.ct-btn-ghost { background: transparent; color: var(--ct-primary); border: 1px solid var(--ct-primary); }
.ct-count { color: var(--ct-muted); font-size: 0.9rem; margin: 14px 0 0; }
.ct-year-jump { display: flex; gap: 6px; flex-wrap: wrap; margin: 16px 0 0; }
.ct-year-jump a { font-size: 0.85rem; padding: 3px 9px; border: 1px solid var(--ct-border); border-radius: 999px; background: var(--ct-surface); color: var(--ct-text); }
.ct-year-jump a:hover { border-color: var(--ct-primary); color: var(--ct-primary); text-decoration: none; }

/* ============ 历史上的今天 ============ */
.ct-today { background: var(--ct-surface-2); border-left: 4px solid var(--ct-accent); border-radius: 8px; padding: 16px 18px; margin: 22px 0; }
.ct-today h2 { font-size: 1.05rem; margin-bottom: 8px; }
.ct-today ul { margin: 0; padding-left: 18px; }
.ct-today li { margin-bottom: 4px; }

/* ============ 时间轴 ============ */
.ct-timeline { position: relative; margin: 28px 0 0; padding: 0; list-style: none; }
.ct-timeline::before { content: ""; position: absolute; left: 50%; top: 0; bottom: 0; width: 2px; margin-left: -1px; background: var(--ct-line); }
.ct-year-group { position: relative; margin: 0; padding: 0; list-style: none; }
.ct-year-label { position: sticky; top: 64px; z-index: 5; text-align: center; margin: 28px 0 18px; }
.ct-year-label span { display: inline-block; background: var(--ct-primary); color: #fff; padding: 5px 18px; border-radius: 999px; font-weight: 700; box-shadow: var(--ct-shadow); }
.ct-event { position: relative; width: 50%; padding: 0 36px 28px 0; }
.ct-event:nth-child(even) { margin-left: 50%; padding: 0 0 28px 36px; }
.ct-event::before { content: ""; position: absolute; top: 22px; right: -7px; width: 12px; height: 12px; border-radius: 50%; background: var(--ct-surface); border: 3px solid var(--ct-primary); z-index: 2; }
.ct-event:nth-child(even)::before { right: auto; left: -7px; }
.ct-card { background: var(--ct-surface); border: 1px solid var(--ct-border); border-radius: var(--ct-radius); box-shadow: var(--ct-shadow); padding: 18px 20px; }
.ct-card.is-important { border-left: 5px solid var(--ct-accent); }
.ct-card.is-major { border-left: 5px solid var(--ct-primary); box-shadow: 0 4px 18px rgba(140, 47, 27, 0.16); }
.ct-date { font-size: 0.85rem; color: var(--ct-primary); font-weight: 700; letter-spacing: 0.03em; }
.ct-card h3 { font-size: 1.25rem; margin: 4px 0 6px; }
.ct-card h3 a { color: var(--ct-text); }
.ct-card h3 a:hover { color: var(--ct-primary); }
.ct-meta { font-size: 0.85rem; color: var(--ct-muted); margin-bottom: 8px; }
.ct-type { display: inline-block; font-size: 0.78rem; padding: 2px 9px; border-radius: 999px; color: #fff; margin-right: 6px; }
.ct-type-politics { background: #8c2f1b; }
.ct-type-war { background: #5b2333; }
.ct-type-culture { background: #2f5d3a; }
.ct-type-tech { background: #1f4e79; }
.ct-type-economy { background: #b7791f; }
.ct-type-default { background: #6f675c; }
.ct-thumb { margin: 0 0 12px; }
.ct-thumb img { border-radius: 8px; display: block; width: 100%; }
.ct-excerpt { color: var(--ct-text); }
.ct-readmore { font-size: 0.9rem; font-weight: 700; }
.ct-badge { display: inline-block; font-size: 0.78rem; background: var(--ct-accent); color: #fff; border-radius: 4px; padding: 1px 7px; margin-left: 6px; vertical-align: middle; }
.ct-empty { text-align: center; color: var(--ct-muted); padding: 40px 0; }

/* 滚动淡入（可在自定义器关闭） */
.ct-animate .ct-event { opacity: 0; transform: translateY(18px); transition: opacity 0.6s ease, transform 0.6s ease; }
.ct-animate .ct-event.is-visible { opacity: 1; transform: none; }
@media (prefers-reduced-motion: reduce) {
    .ct-animate .ct-event { opacity: 1; transform: none; transition: none; }
    html { scroll-behavior: auto; }
}

/* ============ 详情页 ============ */
.ct-single-head { padding: 32px 0 8px; }
.ct-single-head h1 { font-size: 1.9rem; }
.ct-facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; margin: 20px 0; }
.ct-fact { background: var(--ct-surface); border: 1px solid var(--ct-border); border-radius: 8px; padding: 12px 14px; }
.ct-fact dt { font-size: 0.8rem; color: var(--ct-muted); margin: 0; }
.ct-fact dd { margin: 2px 0 0; font-weight: 700; }
.ct-section { margin: 28px 0; }
.ct-section h2 { font-size: 1.2rem; border-bottom: 2px solid var(--ct-border); padding-bottom: 8px; }
.ct-source { background: var(--ct-surface-2); border-radius: 8px; padding: 14px 16px; font-size: 0.92rem; color: var(--ct-muted); }
.ct-related { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px; margin-top: 12px; }
.ct-related .ct-card { padding: 14px 16px; }
.ct-nav { display: flex; justify-content: space-between; gap: 14px; margin: 36px 0 0; flex-wrap: wrap; }
.ct-nav a { background: var(--ct-surface); border: 1px solid var(--ct-border); border-radius: 8px; padding: 12px 16px; color: var(--ct-text); flex: 1; min-width: 200px; }
.ct-nav a:hover { border-color: var(--ct-primary); text-decoration: none; }
.ct-nav span { display: block; font-size: 0.8rem; color: var(--ct-muted); }
.ct-back { display: inline-block; margin: 18px 0 0; }

/* ============ 列表 / 搜索 / 分页 ============ */
.ct-list { list-style: none; margin: 20px 0; padding: 0; display: grid; gap: 14px; }
.ct-pagination { margin: 28px 0; text-align: center; }
.ct-pagination .page-numbers { display: inline-block; padding: 6px 12px; border: 1px solid var(--ct-border); border-radius: 6px; background: var(--ct-surface); color: var(--ct-text); margin: 0 2px; }
.ct-pagination .page-numbers.current { background: var(--ct-primary); border-color: var(--ct-primary); color: #fff; }
.ct-pagination a:hover { text-decoration: none; border-color: var(--ct-primary); }
.widget { margin-bottom: 28px; }
.widget h2 { font-size: 1.05rem; }
.widget ul { list-style: none; margin: 0; padding: 0; }
.widget li { margin-bottom: 6px; }

/* ============ 手机适配 ============ */
@media (max-width: 760px) {
    body { font-size: 15px; }
    .site-header { position: static; }
    .main-nav { margin-left: 0; width: 100%; }
    .ct-hero h1 { font-size: 1.6rem; }
    .ct-timeline::before { left: 8px; margin-left: 0; }
    .ct-year-label { text-align: left; top: 0; }
    .ct-event, .ct-event:nth-child(even) { width: 100%; margin-left: 0; padding: 0 0 22px 30px; }
    .ct-event::before, .ct-event:nth-child(even)::before { left: 2px; right: auto; top: 20px; }
    .ct-filters form { flex-direction: column; align-items: stretch; }
    .ct-field input, .ct-field select { width: 100%; }
    .ct-nav { flex-direction: column; }
}

/* ============ 调研修订：图例 / 三布局 / 加载更多 / 多媒体 ============ */
.ct-legend { display: flex; gap: 8px; flex-wrap: wrap; margin: 12px 0 0; }
.ct-legend a { display: inline-flex; align-items: center; gap: 6px; font-size: 0.85rem; padding: 4px 10px; border: 1px solid var(--ct-border); border-radius: 999px; background: var(--ct-surface); color: var(--ct-text); }
.ct-legend a.is-active { border-color: var(--ct-primary); background: var(--ct-surface-2); }
.ct-legend .ct-dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.ct-layout-switch { display: flex; gap: 8px; flex-wrap: wrap; margin: 12px 0 0; }
.ct-layout-switch a { font-size: 0.85rem; padding: 5px 12px; border: 1px solid var(--ct-border); border-radius: 6px; background: var(--ct-surface); color: var(--ct-text); }
.ct-layout-switch a.is-active { background: var(--ct-primary); border-color: var(--ct-primary); color: #fff; }
.ct-layout-switch a:hover { text-decoration: none; }

/* 竖向单列 */
.ct-layout-single .ct-timeline::before { left: 8px; margin-left: 0; }
.ct-layout-single .ct-year-label { text-align: left; top: 64px; }
.ct-layout-single .ct-event, .ct-layout-single .ct-event:nth-child(even) { width: 100%; margin-left: 0; padding: 0 0 22px 30px; }
.ct-layout-single .ct-event::before, .ct-layout-single .ct-event:nth-child(even)::before { left: 2px; right: auto; }

/* 横向滑杆：桌面横向滚动吸附，手机自动折叠为竖向单列 */
.ct-layout-horizontal .ct-timeline { display: flex; gap: 16px; overflow-x: auto; scroll-snap-type: x mandatory; padding: 10px 4px 20px; -webkit-overflow-scrolling: touch; }
.ct-layout-horizontal .ct-timeline::before { display: none; }
.ct-layout-horizontal .ct-year-group { display: contents; }
.ct-layout-horizontal .ct-year-label { position: static; text-align: left; margin: 0; }
.ct-layout-horizontal .ct-year-label span { white-space: nowrap; }
.ct-layout-horizontal .ct-event, .ct-layout-horizontal .ct-event:nth-child(even) { width: 320px; min-width: 320px; margin: 0; padding: 0; scroll-snap-align: start; }
.ct-layout-horizontal .ct-event::before, .ct-layout-horizontal .ct-event:nth-child(even)::before { display: none; }
.ct-hscroll-nav { display: flex; gap: 8px; align-items: center; margin: 8px 0 0; }
.ct-hscroll-nav button { background: var(--ct-surface); border: 1px solid var(--ct-border); border-radius: 6px; padding: 7px 14px; cursor: pointer; color: var(--ct-text); }
.ct-hscroll-nav button:hover { border-color: var(--ct-primary); }
.ct-hscroll-hint { font-size: 0.85rem; color: var(--ct-muted); }

.ct-loadmore-wrap { text-align: center; margin: 24px 0; }
.ct-loadmore { background: var(--ct-primary); color: #fff; border: 0; border-radius: 6px; padding: 11px 24px; cursor: pointer; font-size: 1rem; }
.ct-loadmore:hover { background: var(--ct-primary-dark); }
.ct-loadmore[disabled] { opacity: 0.6; cursor: default; }
.ct-video { margin: 0 0 14px; }
.ct-video iframe { width: 100%; aspect-ratio: 16/9; border: 0; border-radius: 8px; }
.ct-gallery { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 10px; margin: 0 0 14px; }
.ct-gallery figure { margin: 0; }
.ct-gallery img { border-radius: 8px; display: block; width: 100%; }
.ct-gallery figcaption, .ct-thumb figcaption { font-size: 0.82rem; color: var(--ct-muted); margin-top: 4px; }
.ct-sources { margin: 28px 0; }
.ct-sources ol { margin: 0; padding-left: 20px; }
.ct-sources li { margin-bottom: 6px; }
.ct-person-place { font-size: 0.9rem; }
.ct-person-place a { margin-right: 6px; }
.ct-cause-effect { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin: 20px 0; }
.ct-cause-effect h3 { font-size: 1rem; }
.ct-cause-effect ul { margin: 0; padding-left: 18px; }
.skip-link { position: absolute; left: -9999px; top: 0; background: var(--ct-primary); color: #fff; padding: 8px 14px; z-index: 100; }
.skip-link:focus { left: 8px; top: 8px; color: #fff; }

@media (max-width: 760px) {
    /* 横向在手机上明确折叠为竖向单列（调研：Bold Timeline 移动端故障点） */
    .ct-layout-horizontal .ct-timeline { display: block; overflow-x: visible; scroll-snap-type: none; padding: 0; }
    .ct-layout-horizontal .ct-timeline::before { display: block; left: 8px; margin-left: 0; }
    .ct-layout-horizontal .ct-year-group { display: block; }
    .ct-layout-horizontal .ct-event, .ct-layout-horizontal .ct-event:nth-child(even) { width: 100%; min-width: 0; padding: 0 0 22px 30px; }
    .ct-layout-horizontal .ct-event::before, .ct-layout-horizontal .ct-event:nth-child(even)::before { display: block; left: 2px; right: auto; top: 20px; }
    .ct-layout-horizontal .ct-year-label { text-align: left; }
    .ct-hscroll-nav, .ct-hscroll-hint { display: none; }
    .ct-cause-effect { grid-template-columns: 1fr; }
}
