/* ═══════════════════════════════════════════════════════
   古典詩詞網 - 主樣式表
   中國風古典設計 · 響應式自適應
   ═══════════════════════════════════════════════════════ */

/* ── CSS Variables ── */
:root {
    --color-bg:       #f5f0e6;
    --color-text:     #333333;
    --color-accent:   #c0392b;
    --color-link:     #2c6e49;
    --color-link-hover: #1a4d33;
    --color-border:   #d4c5a9;
    --color-card-bg:  #faf6ed;
    --color-header:   #2c1810;
    --color-header-text: #f5f0e6;
    --color-muted:    #888;
    --color-tag-bg:   #e8dcc8;
    --color-ad-bg:    rgba(192, 57, 43, 0.05);
    --font-serif:     "Noto Serif TC", "Source Han Serif TC", "PingFang TC",
                      "Microsoft JhengHei", serif;
    --font-sans:      "PingFang TC", "Microsoft JhengHei", sans-serif;
    --radius:         6px;
    --max-width:      1200px;
    --transition:     all 0.3s ease;
}

/* ── Reset ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; scroll-behavior: smooth; }
body {
    font-family: var(--font-serif);
    background: var(--color-bg);
    color: var(--color-text);
    line-height: 1.8;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}
a { color: var(--color-link); text-decoration: none; transition: var(--transition); }
a:hover { color: var(--color-link-hover); text-decoration: underline; }
img { max-width: 100%; height: auto; display: block; }
ul, ol { list-style: none; }
h1, h2, h3, h4, h5 { font-weight: 600; line-height: 1.4; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.35rem; }
h3 { font-size: 1.1rem; }

/* ── Container ── */
.container { max-width: var(--max-width); margin: 0 auto; padding: 0 16px; width: 100%; }

/* ── Header ── */
.site-header {
    position: fixed; top: 0; left: 0; right: 0; z-index: 1000;
    background: var(--color-header);
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}
.header-inner {
    display: flex; align-items: center; gap: 16px; height: 56px;
}
.site-logo {
    color: var(--color-header-text); font-size: 1.3rem; font-weight: 700;
    white-space: nowrap; letter-spacing: 2px;
}
.site-logo:hover { text-decoration: none; color: var(--color-accent); }
.main-nav { display: none; gap: 20px; }
.main-nav a {
    color: var(--color-header-text); font-size: 1rem; padding: 4px 0;
    border-bottom: 2px solid transparent; transition: var(--transition);
}
.main-nav a:hover { text-decoration: none; border-bottom-color: var(--color-accent); }
.search-form { display: flex; margin-left: auto; }
.search-form input {
    border: 1px solid var(--color-border); background: rgba(255,255,255,0.95);
    padding: 6px 12px; border-radius: var(--radius) 0 0 var(--radius);
    width: 140px; font-size: 0.9rem; font-family: var(--font-sans);
}
.search-form input:focus { outline: none; border-color: var(--color-accent); width: 200px; }
.search-form button {
    background: var(--color-accent); color: #fff; border: none;
    padding: 6px 12px; border-radius: 0 var(--radius) var(--radius) 0;
    cursor: pointer; font-size: 0.9rem;
}
.nav-spacer { height: 56px; }

/* ── Hamburger Menu ── */
.menu-toggle {
    display: flex; flex-direction: column; justify-content: space-between;
    width: 24px; height: 18px; background: none; border: none; cursor: pointer;
    padding: 0;
}
.menu-toggle span {
    display: block; height: 2px; width: 100%; background: var(--color-header-text);
    border-radius: 1px; transition: var(--transition);
}
.menu-toggle.active span:nth-child(1) { transform: translateY(8px) rotate(45deg); }
.menu-toggle.active span:nth-child(2) { opacity: 0; }
.menu-toggle.active span:nth-child(3) { transform: translateY(-8px) rotate(-45deg); }

/* ── Main Layout ── */
.site-main { flex: 1; padding: 20px 0; }
.page-layout { display: flex; flex-direction: column; gap: 24px; }
.content-main { flex: 1; min-width: 0; }
.sidebar { width: 100%; }

/* ── Ad Slots ── */
.ad-slot {
    background: var(--color-ad-bg); border: 1px dashed var(--color-border);
    min-height: 90px; display: flex; align-items: center; justify-content: center;
    margin: 16px 0; border-radius: var(--radius);
}
.ad-label {
    font-size: 0.75rem; color: var(--color-muted);
    text-transform: uppercase; letter-spacing: 1px;
}

/* ── Breadcrumb ── */
.breadcrumb { margin-bottom: 16px; font-size: 0.85rem; color: var(--color-muted); }
.breadcrumb ol { display: flex; flex-wrap: wrap; gap: 0; }
.breadcrumb li { display: flex; align-items: center; }
.breadcrumb .sep { margin: 0 6px; color: var(--color-border); }
.breadcrumb .current { color: var(--color-text); font-weight: 500; }

/* ── Hero Section ── */
.hero-section {
    text-align: center; padding: 24px 0; margin-bottom: 24px;
    border-bottom: 2px solid var(--color-border);
}
.site-heading {
    font-size: 2rem; color: var(--color-header);
    letter-spacing: 4px; margin-bottom: 8px;
}
.site-subheading { font-size: 1rem; color: var(--color-muted); }

/* ── Dynasty Navigation ── */
.dynasty-nav { margin-bottom: 32px; }
.dynasty-nav h2 { margin-bottom: 16px; }
.dynasty-grid {
    display: grid; grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
    gap: 12px;
}
.dynasty-card {
    display: flex; flex-direction: column; align-items: center; gap: 4px;
    padding: 16px 8px; background: var(--color-card-bg);
    border: 1px solid var(--color-border); border-radius: var(--radius);
    transition: var(--transition); text-align: center;
}
.dynasty-card:hover {
    text-decoration: none; background: #fff;
    border-color: var(--color-accent); box-shadow: 0 2px 8px rgba(192,57,43,0.1);
    transform: translateY(-2px);
}
.dynasty-name { font-size: 1.1rem; font-weight: 600; color: var(--color-header); }
.dynasty-count { font-size: 0.75rem; color: var(--color-muted); }

/* ── Featured Section ── */
.featured-section, .mingju-section, .latest-section { margin-bottom: 32px; }
.featured-section h2, .mingju-section h2, .latest-section h2,
.author-poems h2, .list-page h1 { margin-bottom: 16px; }

/* ── Poem Grid (card layout) ── */
.poem-grid {
    display: grid; grid-template-columns: 1fr; gap: 16px;
}
.poem-grid-full { grid-column: 1 / -1; }
.poem-card, .poem-item, .book-card, .mingju-card {
    background: var(--color-card-bg); border: 1px solid var(--color-border);
    border-radius: var(--radius); padding: 16px; transition: var(--transition);
}
.poem-card:hover, .poem-item:hover, .book-card:hover {
    box-shadow: 0 4px 12px rgba(0,0,0,0.08); border-color: var(--color-accent);
}
.poem-card h3, .poem-item h2, .poem-item h3 { margin-bottom: 6px; }
.poem-author, .poem-item-meta, .book-meta, .book-meta-lg {
    font-size: 0.85rem; color: var(--color-muted); margin-bottom: 8px;
}
.poem-snippet, .poem-item-content, .book-desc {
    font-size: 0.9rem; color: #555; line-height: 1.6;
}
.poem-tags, .poem-tags-section { margin-top: 8px; display: flex; flex-wrap: wrap; gap: 4px; }
.tag {
    display: inline-block; padding: 2px 10px; background: var(--color-tag-bg);
    border-radius: 12px; font-size: 0.75rem; color: #666;
}

/* ── Mingju Grid ── */
.mingju-grid {
    display: grid; grid-template-columns: 1fr; gap: 16px;
}
.mingju-card {
    border-left: 4px solid var(--color-accent); padding: 16px 20px;
}
.mingju-text { font-size: 1.05rem; color: var(--color-header); margin-bottom: 8px; }
.mingju-text-lg {
    font-size: 1.1rem; color: var(--color-header); margin-bottom: 8px;
    border-left: 4px solid var(--color-accent); padding-left: 12px;
}
.mingju-source { font-size: 0.85rem; color: var(--color-muted); }
.mingju-translation { font-size: 0.85rem; color: #555; margin-top: 6px; }

/* ── Latest List ── */
.latest-list li {
    display: flex; justify-content: space-between; align-items: center;
    padding: 10px 0; border-bottom: 1px solid var(--color-border);
    font-size: 0.9rem;
}
.latest-list li:last-child { border-bottom: none; }
.latest-list .meta { color: var(--color-muted); font-size: 0.8rem; }

/* ── More Link ── */
.more-link { text-align: right; margin-top: 12px; font-size: 0.9rem; }

/* ── Section Title ── */
.section-title {
    display: flex; align-items: center; gap: 12px;
    padding-bottom: 12px; border-bottom: 2px solid var(--color-border);
    margin-bottom: 20px;
}
.count-badge {
    display: inline-block; padding: 2px 10px; background: var(--color-tag-bg);
    border-radius: 12px; font-size: 0.75rem; color: #666; font-weight: normal;
}

/* ── Filter Bar ── */
.filter-bar {
    display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 20px;
    padding: 12px; background: var(--color-card-bg);
    border-radius: var(--radius); border: 1px solid var(--color-border);
}
.filter-bar a {
    padding: 4px 14px; border-radius: 20px; font-size: 0.85rem;
    color: var(--color-text); transition: var(--transition);
}
.filter-bar a:hover { text-decoration: none; background: var(--color-tag-bg); }
.filter-bar a.active { background: var(--color-accent); color: #fff; }

/* ── Poem List (full list view) ── */
.poem-list { display: flex; flex-direction: column; gap: 12px; }
.mingju-list { display: flex; flex-direction: column; gap: 16px; }
.mingju-item {
    background: var(--color-card-bg); border: 1px solid var(--color-border);
    border-radius: var(--radius); padding: 16px 20px;
}

/* ── Author Grid ── */
.author-grid {
    display: grid; grid-template-columns: 1fr; gap: 12px;
}
.author-card {
    background: var(--color-card-bg); border: 1px solid var(--color-border);
    border-radius: var(--radius); padding: 16px; transition: var(--transition);
}
.author-card:hover { border-color: var(--color-accent); box-shadow: 0 2px 8px rgba(0,0,0,0.06); }
.author-card-link { display: flex; gap: 12px; align-items: center; }
.author-card-info h3 { font-size: 1rem; margin-bottom: 2px; }
.author-card-dynasty { font-size: 0.8rem; color: var(--color-muted); }
.author-card-bio { font-size: 0.8rem; color: #666; margin-top: 4px; line-height: 1.5; }

/* ── Book Grid ── */
.book-grid {
    display: grid; grid-template-columns: 1fr; gap: 16px;
}
.book-stats { margin-top: 8px; font-size: 0.8rem; color: var(--color-muted); }
.book-stats span { margin-right: 12px; }

/* ── Author Detail Header ── */
.author-header {
    display: flex; gap: 20px; align-items: center; margin-bottom: 24px;
    padding: 24px; background: var(--color-card-bg);
    border-radius: var(--radius); border: 1px solid var(--color-border);
}
.author-avatar-lg { flex-shrink: 0; }
.author-info h1 { margin-bottom: 8px; }
.author-meta { font-size: 0.9rem; color: var(--color-muted); display: flex; gap: 12px; align-items: center; }
.author-bio-full { margin-bottom: 32px; }
.author-bio-full h2 { margin-bottom: 12px; }
.bio-content { line-height: 2; }
.author-bio {
    padding: 16px; background: var(--color-card-bg);
    border-radius: var(--radius); border: 1px solid var(--color-border);
}
.author-bio-header { display: flex; gap: 12px; align-items: center; margin-bottom: 12px; }
.author-bio-header h3 { margin: 0; }
.author-meta { font-size: 0.85rem; color: var(--color-muted); }

/* ── Poem Detail ── */
.poem-detail {
    background: var(--color-card-bg); border: 1px solid var(--color-border);
    border-radius: var(--radius); padding: 32px 24px;
}
.poem-header { text-align: center; margin-bottom: 24px; }
.poem-title { font-size: 1.8rem; margin-bottom: 12px; letter-spacing: 2px; }
.poem-meta { display: flex; justify-content: center; gap: 16px; align-items: center; flex-wrap: wrap; font-size: 0.9rem; color: var(--color-muted); }
.poem-author-link { display: flex; align-items: center; gap: 8px; }
.poem-author-link img { border-radius: 50%; }
.poem-dynasty a { color: var(--color-accent); }

.poem-content {
    text-align: center; margin: 32px 0; font-size: 1.15rem; line-height: 2.4;
}
.poem-content p { margin-bottom: 4px; }

.poem-section {
    margin-top: 24px; padding-top: 20px; border-top: 1px dashed var(--color-border);
}
.poem-section h2 {
    font-size: 1.1rem; color: var(--color-accent);
    margin-bottom: 12px; padding-left: 12px; border-left: 4px solid var(--color-accent);
}
.poem-translation, .poem-notes, .poem-appreciation, .poem-background {
    line-height: 2; color: #444; font-size: 0.95rem;
}

.poem-related { margin-top: 32px; }
.related-list {
    display: grid; grid-template-columns: 1fr; gap: 8px;
}
.related-list li {
    padding: 8px 12px; background: var(--color-card-bg);
    border: 1px solid var(--color-border); border-radius: 4px;
}
.related-list a { font-size: 0.9rem; }

/* ── Book Detail ── */
.book-detail {
    background: var(--color-card-bg); border: 1px solid var(--color-border);
    border-radius: var(--radius); padding: 24px;
}
.book-header { margin-bottom: 24px; }
.book-title { font-size: 1.6rem; margin-bottom: 8px; }
.book-meta-lg { font-size: 0.9rem; color: var(--color-muted); }
.book-description { margin-bottom: 24px; }
.book-chapters h2 { margin-bottom: 16px; }
.chapter-list {
    display: grid; grid-template-columns: 1fr; gap: 4px;
    counter-reset: chapter;
}
.chapter-list li { counter-increment: chapter; }
.chapter-list li a {
    display: block; padding: 10px 16px; background: #fff;
    border: 1px solid var(--color-border); border-radius: 4px;
    font-size: 0.9rem; transition: var(--transition);
}
.chapter-list li a:hover {
    text-decoration: none; border-color: var(--color-accent);
    background: var(--color-card-bg);
}
.chapter-list li a::before {
    content: counter(chapter) ". "; color: var(--color-muted); font-weight: 600;
}

/* ── Chapter Detail ── */
.chapter-detail {
    background: var(--color-card-bg); border: 1px solid var(--color-border);
    border-radius: var(--radius); padding: 32px 24px;
}
.chapter-header { text-align: center; margin-bottom: 24px; }
.chapter-book { font-size: 0.85rem; color: var(--color-muted); margin-bottom: 8px; }
.chapter-title { font-size: 1.5rem; margin-bottom: 8px; }
.chapter-author { font-size: 0.85rem; color: var(--color-muted); }
.chapter-content {
    font-size: 1.05rem; line-height: 2.2; color: #333;
    max-width: 720px; margin: 0 auto;
}
.chapter-content p { margin-bottom: 12px; text-indent: 2em; }

.chapter-nav {
    display: flex; justify-content: space-between; gap: 16px;
    margin-top: 32px; padding-top: 24px; border-top: 2px solid var(--color-border);
}
.prev-chapter, .next-chapter {
    flex: 1; display: flex; flex-direction: column; gap: 4px;
    padding: 12px 16px; background: #fff;
    border: 1px solid var(--color-border); border-radius: var(--radius);
    transition: var(--transition);
}
.prev-chapter:hover, .next-chapter:hover {
    text-decoration: none; border-color: var(--color-accent); background: var(--color-card-bg);
}
.prev-chapter.disabled, .next-chapter.disabled {
    opacity: 0.5; cursor: default; color: var(--color-muted);
}
.next-chapter { text-align: right; }
.nav-label { font-size: 0.75rem; color: var(--color-muted); }
.nav-title { font-size: 0.9rem; color: var(--color-link); }

/* ── Search Page ── */
.search-large { display: flex; gap: 8px; margin-bottom: 24px; }
.search-large input {
    flex: 1; padding: 10px 16px; font-size: 1rem;
    border: 1px solid var(--color-border); border-radius: var(--radius);
    font-family: var(--font-sans);
}
.search-large input:focus { outline: none; border-color: var(--color-accent); }
.search-large button {
    padding: 10px 24px; background: var(--color-accent); color: #fff;
    border: none; border-radius: var(--radius); cursor: pointer;
    font-size: 0.95rem;
}
.search-section { margin-bottom: 32px; }
.search-tips { padding: 20px; background: var(--color-card-bg); border-radius: var(--radius); }
.search-tips ul { list-style: disc; padding-left: 20px; }
.search-tips li { margin-bottom: 8px; }

/* ── Sidebar ── */
.sidebar-section {
    background: var(--color-card-bg); border: 1px solid var(--color-border);
    border-radius: var(--radius); padding: 16px; margin-bottom: 16px;
}
.sidebar-title {
    font-size: 1rem; margin-bottom: 12px; padding-bottom: 8px;
    border-bottom: 2px solid var(--color-border); color: var(--color-header);
}
.sidebar-list li { margin-bottom: 8px; }
.sidebar-list a { display: flex; flex-direction: column; gap: 2px; }
.list-title { font-size: 0.9rem; color: var(--color-text); }
.list-meta { font-size: 0.75rem; color: var(--color-muted); }

.author-chips { display: flex; flex-direction: column; gap: 10px; }
.author-chips a { display: flex; align-items: center; gap: 10px; }
.author-chips img { border-radius: 50%; }
.author-chips .author-name { font-size: 0.9rem; }
.author-chips .author-dynasty { font-size: 0.75rem; color: var(--color-muted); }

.dynasty-tags { display: flex; flex-wrap: wrap; gap: 6px; }
.dynasty-tag {
    padding: 3px 12px; background: #fff; border: 1px solid var(--color-border);
    border-radius: 16px; font-size: 0.8rem; color: var(--color-text);
    transition: var(--transition);
}
.dynasty-tag:hover { text-decoration: none; background: var(--color-accent); color: #fff; }

/* ── Pagination ── */
.pagination { margin: 24px 0; }
.pagination ul { display: flex; justify-content: center; flex-wrap: wrap; gap: 4px; }
.pagination li a, .pagination li span {
    display: block; padding: 6px 12px; background: #fff;
    border: 1px solid var(--color-border); border-radius: 4px;
    font-size: 0.85rem; color: var(--color-text); transition: var(--transition);
}
.pagination li a:hover { text-decoration: none; background: var(--color-accent); color: #fff; }
.pagination li.current span { background: var(--color-accent); color: #fff; border-color: var(--color-accent); }
.pagination li.disabled span { opacity: 0.5; }
.pagination li.ellipsis span { border: none; background: transparent; }

/* ── Avatar ── */
.avatar { border-radius: 50%; object-fit: cover; }
.avatar-fallback {
    width: 40px !important; height: 40px !important;
    background: var(--color-tag-bg); border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
}
.avatar-fallback::after { content: '人'; font-size: 0.8rem; color: var(--color-muted); }

/* ── Empty State ── */
.empty-state {
    text-align: center; padding: 40px 20px; color: var(--color-muted);
    font-size: 1rem;
}

/* ── Footer ── */
.site-footer {
    background: var(--color-header); color: var(--color-header-text);
    padding: 32px 0 16px; margin-top: 40px;
}
.footer-grid {
    display: grid; grid-template-columns: 1fr; gap: 24px; margin-bottom: 24px;
}
.footer-col h4 {
    font-size: 1rem; margin-bottom: 12px; color: var(--color-accent);
}
.footer-col p { font-size: 0.85rem; line-height: 1.6; color: rgba(245,240,230,0.7); }
.footer-col ul li { margin-bottom: 6px; }
.footer-col a { color: rgba(245,240,230,0.8); font-size: 0.85rem; }
.footer-col a:hover { color: #fff; }
.footer-dynasties { display: flex; flex-wrap: wrap; gap: 6px; }
.footer-bottom {
    border-top: 1px solid rgba(245,240,230,0.2); padding-top: 16px;
    text-align: center; font-size: 0.8rem; color: rgba(245,240,230,0.6);
}
.footer-bottom a { color: rgba(245,240,230,0.7); }

/* ── Error Page ── */
.error-page { text-align: center; padding: 60px 20px; }
.error-page h1 { font-size: 3rem; color: var(--color-accent); margin-bottom: 16px; }

/* ═══════════════════════════════════════════════════════
   響應式 - 平板 (≥768px)
   ═══════════════════════════════════════════════════════ */
@media (min-width: 768px) {
    h1 { font-size: 1.8rem; }
    h2 { font-size: 1.5rem; }
    .menu-toggle { display: none; }
    .main-nav { display: flex; }
    .search-form input { width: 180px; }
    .search-form input:focus { width: 240px; }

    .page-layout { flex-direction: row; }
    .content-main { flex: 1; }
    .sidebar { width: 300px; flex-shrink: 0; }

    .poem-grid { grid-template-columns: repeat(2, 1fr); }
    .mingju-grid { grid-template-columns: repeat(2, 1fr); }
    .author-grid { grid-template-columns: repeat(2, 1fr); }
    .book-grid { grid-template-columns: repeat(2, 1fr); }
    .related-list { grid-template-columns: repeat(2, 1fr); }
    .chapter-list { grid-template-columns: repeat(2, 1fr); }

    .footer-grid { grid-template-columns: repeat(4, 1fr); }

    .container { padding: 0 24px; }
}

/* ═══════════════════════════════════════════════════════
   響應式 - 桌面 (≥1024px)
   ═══════════════════════════════════════════════════════ */
@media (min-width: 1024px) {
    .poem-grid { grid-template-columns: repeat(3, 1fr); }
    .chapter-list { grid-template-columns: repeat(3, 1fr); }
    .site-heading { font-size: 2.5rem; }
}

/* ═══════════════════════════════════════════════════════
   響應式 - 手機 (<480px) 精簡
   ═══════════════════════════════════════════════════════ */
@media (max-width: 479px) {
    .site-logo { font-size: 1.1rem; letter-spacing: 1px; }
    .search-form { width: 100%; margin-left: 0; }
    .search-form input { width: 100%; }
    .hero-section { padding: 16px 0; }
    .site-heading { font-size: 1.5rem; }
    .poem-detail { padding: 20px 16px; }
    .chapter-detail { padding: 20px 16px; }
    .poem-content { font-size: 1.05rem; }
    .chapter-content { font-size: 0.95rem; }
    .chapter-nav { flex-direction: column; }
    .prev-chapter, .next-chapter { text-align: left; }
    .filter-bar { padding: 8px; }
    .filter-bar a { font-size: 0.8rem; padding: 3px 10px; }
}

/* ── Print Styles ── */
@media print {
    .site-header, .sidebar, .ad-slot, .search-form, .main-nav,
    .menu-toggle, .site-footer, .pagination { display: none !important; }
    body { background: #fff; color: #000; }
    .poem-detail, .chapter-detail { border: none; }
}
