/* ===================================================
   古诗词 - 详情页 & 田字格样式
   =================================================== */

/* ===== 诗词详情页 ===== */
.poem-detail-wrap {
  display: grid;
  grid-template-columns: 1fr 280px;
  gap: 24px;
  align-items: start;
}

.poem-detail-main {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.poem-detail-header {
  background: linear-gradient(135deg, #6b0f0f, #8b1a1a);
  color: #fff;
  padding: 28px 32px;
  text-align: center;
  position: relative;
}

.poem-detail-header::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 20px;
  background: var(--bg-card);
  clip-path: ellipse(55% 100% at 50% 100%);
}

.poem-title {
  font-family: var(--font-body);
  font-size: 38px;
  margin-bottom: 8px;
  line-height:136%;
  letter-spacing:3px;
  text-shadow: 0 1px 3px rgba(0,0,0,0.3);
}

.poem-author {
  font-size: 16px;
  opacity: 0.9;
}

.poem-author a {
  color: var(--gold-light);
}

.poem-author a:hover {
  color: #fff;
  text-decoration: underline;
}

/* 工具栏 */
.poem-toolbar {
  display: flex;
  gap: 12px;
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
  background: #fff9f0;
  flex-wrap: wrap;
}

.tool-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 16px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: #fff;
  font-size: 13px;
  cursor: pointer;
  color: var(--text);
  transition: all .2s;
  user-select: none;
}

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

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

.tool-btn .icon { font-size: 15px; }

/* 朗读控制 */
.audio-player {
  display: none;
  align-items: center;
  gap: 10px;
  padding: 12px 24px;
  background: #fff9f0;
  border-bottom: 1px solid var(--border);
}

.audio-player.show { display: flex; }

.audio-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: var(--primary);
  color: #fff;
  font-size: 16px;
  cursor: pointer;
  transition: all .2s;
  display: flex;
  align-items: center;
  justify-content: center;
}

.audio-btn:hover { background: var(--primary-light); transform: scale(1.05); }

.audio-progress {
  flex: 1;
  position: relative;
  height: 6px;
  background: #e8d5b0;
  border-radius: 3px;
  cursor: pointer;
}

.audio-progress-fill {
  height: 100%;
  background: var(--primary);
  border-radius: 3px;
  transition: width .1s;
}

.audio-time {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
}

.audio-speed {
  padding: 4px 8px;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 12px;
  cursor: pointer;
  background: #fff;
  color: var(--text);
}

/* ===== 田字格显示区域 ===== */
.poem-content-area {
  padding: 28px 32px;
}

/* 普通模式（非田字格）*/
.poem-content-normal {
  font-family: "Microsoft YaHei", "PingFang SC", "Hiragino Sans GB", sans-serif;
  font-size: var(--poem-font-size, 24px);
  line-height: 1.8;
  color: var(--text);
  text-align: center;
}

.poem-content-normal .poem-line {
  padding: 2px 0;
}

/* 字号调节条 */
.font-size-bar {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  padding: 0 4px 10px;
  border-bottom: 1px dashed var(--border);
  margin-bottom: 16px;
}

.font-size-label {
  font-size: 12px;
  color: var(--text-muted);
}

.font-btn {
  width: 30px;
  height: 28px;
  border: 1px solid var(--border);
  background: #fff;
  border-radius: 4px;
  cursor: pointer;
  font-size: 13px;
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all .15s;
  user-select: none;
  line-height: 1;
}

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

.font-btn:active { transform: scale(0.92); }

.font-size-val {
  font-size: 12px;
  color: var(--text-muted);
  min-width: 36px;
  text-align: center;
}

/* 拼音模式 */
.poem-content-pinyin {
  text-align: center;
}

.pinyin-line {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 2px;
  margin-bottom: 12px;
  line-height: 1;
}

.pinyin-char {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  min-width: 28px;
  cursor: default;
}

.pinyin-char .py {
  font-size: 11px;
  color: #999;
  height: 16px;
  line-height: 1;
  letter-spacing: 0;
  white-space: nowrap;
  font-family: "Arial", sans-serif;
}

.pinyin-char .ch {
  font-family: "Microsoft YaHei", "PingFang SC", "Hiragino Sans GB", sans-serif;
  font-size: calc(var(--poem-font-size, 24px) * 0.92);
  color: var(--text);
  line-height: 1.3;
}

.pinyin-char.punct {
  min-width: 14px;
}

.pinyin-char.punct .py {
  visibility: hidden;
}

.pinyin-char.punct .ch {
  color: var(--text-light);
  font-size: 18px;
}

/* ===== 田字格模式 ===== */
.poem-content-tian {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.tian-line {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: center;
}

/* 田字格单字容器 */
.tian-char-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.tian-char-wrap .py {
  font-size: 11px;
  color: #999;
  height: 16px;
  line-height: 16px;
  font-family: "Arial", sans-serif;
  letter-spacing: 0;
  white-space: nowrap;
}

/* 田字格本体 */
.tian-cell {
  width: 50px;
  height: 50px;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1.5px solid #c8a44b;
  background: #fffdf5;
  border-radius: 2px;
}

/* 田字格中间的十字辅助线 */
.tian-cell::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 0;
  right: 0;
  height: 0;
  border-top: 1px dashed rgba(200,164,75,0.45);
}

.tian-cell::after {
  content: '';
  position: absolute;
  left: 50%;
  top: 0;
  bottom: 0;
  width: 0;
  border-left: 1px dashed rgba(200,164,75,0.45);
}

.tian-cell .zh {
  position: relative;
  z-index: 1;
  font-family: "Microsoft YaHei", "PingFang SC", "Hiragino Sans GB", sans-serif;
  font-size: calc(var(--poem-font-size, 24px) * 1.08);
  color: #8b1a1a;
  line-height: 1;
  user-select: text;
}

/* 标点符号的田字格 */
.tian-cell.punct {
  width: 30px;
  border-color: transparent;
  background: transparent;
}

.tian-cell.punct::before, .tian-cell.punct::after { display: none; }

.tian-cell.punct .zh {
  font-size: 20px;
  color: var(--text-light);
}

/* 空格/换行标记 */
.tian-break {
  width: 100%;
  height: 0;
}

/* ===== 赏析区 ===== */
.poem-appreciation {
  padding: 20px 32px;
  border-top: 1px solid var(--border);
  background: #fffdf8;
}

.appreciation-tabs {
  display: flex;
  gap: 0;
  border-bottom: 2px solid var(--border);
  margin-bottom: 16px;
}

.appreciation-tab {
  padding: 8px 20px;
  cursor: pointer;
  font-size: 14px;
  color: var(--text-muted);
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: all .2s;
}

.appreciation-tab:hover { color: var(--primary); }

.appreciation-tab.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
  font-weight: bold;
}

.appreciation-pane {
  display: none;
  font-size: 15px;
  line-height: 2;
  color: var(--text);
}

.appreciation-pane.active { display: block; }

.appreciation-pane.empty {
  color: var(--text-muted);
  font-style: italic;
}

/* ===== 前后导航 ===== */
.poem-nav {
  display: flex;
  gap: 16px;
  padding: 16px 24px;
  border-top: 1px solid var(--border);
}

.poem-nav-item {
  flex: 1;
  padding: 12px;
  background: var(--bg-warm);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
  color: var(--text);
  transition: all .2s;
  text-decoration: none;
  display: block;
}

.poem-nav-item:hover {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.poem-nav-item.next { text-align: right; }

.poem-nav-item .nav-label {
  font-size: 12px;
  color: inherit;
  opacity: 0.7;
  display: block;
  margin-bottom: 4px;
}

.poem-nav-item .nav-title {
  font-family: var(--font-body);
  font-size: 16px;
}

/* ===== 诗人简介（侧边栏）===== */
.poet-info-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  margin-bottom: 20px;
}

.poet-info-header {
  background: linear-gradient(135deg, var(--primary), #a82828);
  color: #fff;
  padding: 16px 20px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.poet-avatar-large {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: rgba(255,255,255,0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-serif);
  font-size: 24px;
  border: 2px solid rgba(255,255,255,0.4);
}

.poet-info-name {
  font-family: var(--font-body);
  font-size: 30px;
  margin: 0;
  font-weight: bold;
  letter-spacing:5px;
}

.poet-info-dynasty {
  font-size: 13px;
  opacity: 0.8;
}

.poet-info-body {
  padding: 16px 20px;
}

.poet-info-brief {
  font-size: 13px;
  color: var(--text-light);
  line-height: 1.8;
  margin-bottom: 12px;
  display: -webkit-box;
  -webkit-line-clamp: 5;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.poet-info-meta {
  font-size: 12px;
  color: var(--text-muted);
  display: flex;
  justify-content: space-between;
}

/* ===== 侧边栏其他诗词 ===== */
.other-poems-list {
  list-style: none;
}

.other-poems-list li {
  padding: 8px 0;
  border-bottom: 1px dashed var(--border);
}

.other-poems-list li:last-child { border-bottom: none; }

.other-poems-list a {
  font-size: 13px;
  color: var(--text);
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.other-poems-list a:hover { color: var(--primary); }

/* ===== 响应式 ===== */
@media (max-width: 900px) {
  .poem-detail-wrap {
    grid-template-columns: 1fr;
  }
  
  .poem-detail-sidebar { order: 2; }
}

@media (max-width: 600px) {
  .poem-detail-header { padding: 20px 16px; }
  .poem-title { font-size: 28px; }
  .poem-content-area { padding: 20px 16px; }

  .poem-content-normal {
    --poem-font-size: 18px;
  }

  .poet-info-header { padding: 12px 14px; gap: 10px; }
  .poet-info-name { font-size: 17px; }
  .poet-info-body { padding: 12px 14px; }

  /* 作品列表移动端竖排，隐藏预览文本 */
  .poem-work-item {
    flex-direction: column !important;
    align-items: flex-start !important;
  }
  .poem-work-preview { display: none; }

  .poem-works-header { padding: 12px 16px !important; }
  .poem-works-header h2 { font-size: 18px !important; }

  .tian-cell {
    width: 42px;
    height: 42px;
  }

  .tian-cell .zh { font-size: calc(var(--poem-font-size, 24px) * 0.85); }

  .pinyin-char .ch { font-size: calc(var(--poem-font-size, 24px) * 0.75); }

  .poem-toolbar { padding: 12px 16px; }
  .poem-appreciation { padding: 16px; }
  .poem-nav { padding: 12px 16px; flex-direction: column; }
}

/* ===== 动画 ===== */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

.poem-content-tian, .poem-content-pinyin {
  animation: fadeIn .3s ease;
}

/* ===== 标签云 ===== */
.tag-cloud {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.tag-cloud .tag {
  font-size: 13px;
  padding: 4px 12px;
}

/* ===== 打印样式 ===== */
@media print {
  /* 隐藏不需要打印的部分 */
  .site-header,
  .site-footer,
  .poem-toolbar,
  .font-size-bar,
  .audio-player,
  .poem-detail-sidebar,
  .appreciation-tabs,
  .poem-nav,
  #btn-print,
  #btn-pdf { display: none !important; }

  /* 正文区域占满宽度 */
  body {
    background: #fff;
    color: #000;
    font-size: 16pt;
  }

  .poem-detail-wrap {
    grid-template-columns: 1fr;
    display: block;
    box-shadow: none;
    border: none;
  }

  .poem-detail-main {
    box-shadow: none;
    border: none;
    border-bottom: 2px solid #ccc;
  }

  .poem-detail-header {
    background: #333 !important;
    color: #fff;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
    padding: 12pt 0 !important;
  }

  .poem-detail-header::after {
    display: none !important;
  }

  .poem-content-area {
    padding: 20px 0;
  }

  .font-size-bar {
    display: none !important;
    height: 0;
    margin: 0;
    padding: 0;
    border: none;
    overflow: hidden;
  }

  .poem-content-normal {
    font-size: var(--poem-font-size, 22pt);
    line-height: 1.8;
  }

  /* 默认(normal)模式打印：隐藏拼音和田字格 */
  .poem-content-pinyin { display: none !important; }
  .poem-content-tian   { display: none !important; }

  /* 拼音模式打印 */
  html[data-print-mode="pinyin"] .poem-content-normal { display: none !important; }
  html[data-print-mode="pinyin"] .poem-content-pinyin { display: block !important; }
  html[data-print-mode="pinyin"] .poem-content-pinyin .pinyin-line {
    font-size: var(--poem-font-size, 18pt);
    line-height: 2.2;
    margin-bottom: 4pt;
  }

  /* 田字格模式打印 */
  html[data-print-mode="tian"] .poem-content-normal { display: none !important; height: 0 !important; min-height: 0 !important; margin: 0 !important; padding: 0 !important; overflow: hidden !important; }
  html[data-print-mode="tian"] .poem-content-pinyin { display: none !important; height: 0 !important; min-height: 0 !important; margin: 0 !important; padding: 0 !important; overflow: hidden !important; }
  html[data-print-mode="tian"] .poem-content-tian   { display: flex !important; flex-direction: column; align-items: center; gap: 10pt; }
  html[data-print-mode="tian"] .tian-line { display: flex; flex-wrap: wrap; justify-content: center; margin-bottom: 0; }
  html[data-print-mode="tian"] .tian-char-wrap { display: flex; flex-direction: column; align-items: center; gap: 1pt; }
  html[data-print-mode="tian"] .tian-cell {
    border: 1pt solid #999;
    width: 44pt;
    height: 44pt;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 2pt;
    font-size: 24pt;
    background: #fff;
    border-radius: 0;
  }
  html[data-print-mode="tian"] .tian-cell::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 0;
    right: 0;
    height: 0;
    border-top: 0.5pt dashed #ccc;
  }
  html[data-print-mode="tian"] .tian-cell::after {
    content: '';
    position: absolute;
    left: 50%;
    top: 0;
    bottom: 0;
    width: 0;
    border-left: 0.5pt dashed #ccc;
  }
  html[data-print-mode="tian"] .tian-cell .zh { position: relative; z-index: 1; color: #000; }
  html[data-print-mode="tian"] .tian-cell.punct { width: auto; border: none; background: none; }
  html[data-print-mode="tian"] .tian-cell.punct::before,
  html[data-print-mode="tian"] .tian-cell.punct::after { display: none; }
  html[data-print-mode="tian"] .tian-char-wrap .py { font-size: 9pt; color: #666; display: block; height: 12pt; line-height: 12pt; }
  html[data-print-mode="tian"] #poem-raw-text { display: none !important; position: absolute; visibility: hidden; }
  html[data-print-mode="tian"] .poem-content-area { padding: 10pt 0; }

  .poem-appreciation {
    border-top: 1px solid #ccc;
    padding: 12px 0;
  }

  .appreciation-pane {
    display: block !important;
    font-size: 11pt;
    color: #333;
  }

  /* 隐藏内容为空的赏析pane */
  .appreciation-pane.has-empty {
    display: none !important;
  }

  /* 整个赏析区无有效内容时隐藏 */
  .poem-appreciation.all-empty {
    display: none !important;
  }

  .site-main { padding: 0; }
}

/* ===== PDF下载弹窗 ===== */
.pdf-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fadeIn .2s ease;
}

.pdf-modal {
  background: #fff;
  border-radius: 12px;
  width: 400px;
  max-width: 90vw;
  box-shadow: 0 8px 40px rgba(0,0,0,0.25);
  overflow: hidden;
}

.pdf-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  background: linear-gradient(135deg, var(--primary), #a82828);
  color: #fff;
}

.pdf-modal-header h3 {
  font-size: 16px;
  margin: 0;
}

.pdf-modal-close {
  background: none;
  border: none;
  color: rgba(255,255,255,0.7);
  font-size: 24px;
  cursor: pointer;
  line-height: 1;
  padding: 4px 8px;
}

.pdf-modal-close:hover { color: #fff; }

.pdf-modal-body {
  padding: 20px;
}

.pdf-modal-tip {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 14px;
}

.pdf-options {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.pdf-option {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  font-size: 14px;
  padding: 8px 12px;
  border-radius: 6px;
  transition: background .15s;
  user-select: none;
}

.pdf-option:hover { background: var(--bg-warm); }
.pdf-option input[type="checkbox"] {
  width: 16px; height: 16px;
  accent-color: var(--primary);
  cursor: pointer;
}
.pdf-option input[type="checkbox"]:disabled { opacity: 0.35; cursor: not-allowed; }
.pdf-option span { color: var(--text); }
.pdf-option span:last-of-type { flex: 1; }

.pdf-modal-footer {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  background: #fafafa;
}

.pdf-btn {
  padding: 8px 20px;
  border-radius: 6px;
  border: 1px solid var(--border);
  font-size: 13px;
  cursor: pointer;
  transition: all .15s;
}

.pdf-btn-cancel {
  background: #fff;
  color: var(--text-muted);
}

.pdf-btn-cancel:hover { background: #f5f5f5; }

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

.pdf-btn-generate:hover { background: var(--primary-light); }
