/* ==========================================================================
   《西遊記》兒童繪本閱讀器 - 統一視覺規範 (Unified Reader CSS)
   ========================================================================== */

:root {
  --reader-max-width: 860px;
  --font-body: -apple-system, BlinkMacSystemFont, "PingFang TC", "Microsoft JhengHei", "Noto Serif TC", sans-serif;
  --color-bg: #f8f6f0;
  --color-prose-bg: #ffffff;
  --color-text: #242924;
  --color-primary: #3b5f47;
  --color-accent: #c45c26;
  --color-border: #e6e2d8;
  --color-quote-border: #42664f;
  --color-quote-bg: #f3f6f1;
  
  /* Reading Font Sizes */
  --fs-reading: 30px;
  --lh-reading: 2.5;
}

*, *::before, *::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  padding: 0;
  background: var(--color-bg);
  font-family: var(--font-body);
  color: var(--color-text);
  -webkit-font-smoothing: antialiased;
}

/* ==========================================================================
   頂部導覽控制列 (Sticky Top Nav Bar)
   ========================================================================== */
.top-nav-bar {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 24px;
  background: rgba(250, 245, 233, 0.96);
  backdrop-filter: blur(12px);
  border-bottom: 2px solid #e2dbca;
  box-shadow: 0 4px 16px rgba(66, 102, 79, 0.08);
}

.portal-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  background: #42664f;
  color: #ffffff !important;
  text-decoration: none;
  font-weight: 700;
  font-size: 15px;
  border-radius: 20px;
  box-shadow: 0 2px 8px rgba(66, 102, 79, 0.25);
  transition: all 0.2s ease;
}
.portal-btn:hover {
  background: #32503d;
  transform: translateY(-1px);
}

.nav-center {
  display: flex;
  align-items: center;
  gap: 10px;
}
.nav-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 7px 14px;
  background: #fff;
  border: 1px solid #d4cbb8;
  border-radius: 16px;
  color: #3b4d3e;
  text-decoration: none;
  font-weight: 600;
  font-size: 14px;
  transition: all 0.2s ease;
}
.nav-btn:hover:not(.disabled) {
  background: #eef2e6;
  border-color: #42664f;
  color: #42664f;
}
.nav-btn.disabled {
  opacity: 0.35;
  cursor: not-allowed;
  pointer-events: none;
}
.ep-select {
  padding: 7px 16px;
  font-size: 15px;
  font-weight: 700;
  color: #334433;
  background: #ffffff;
  border: 1.5px solid #42664f;
  border-radius: 18px;
  outline: none;
  cursor: pointer;
}

.nav-right {
  display: flex;
  align-items: center;
  gap: 8px;
}
.control-group {
  display: flex;
  background: #e9e3d3;
  padding: 3px;
  border-radius: 14px;
  gap: 2px;
}
.control-group button {
  border: none;
  background: transparent;
  padding: 5px 12px;
  border-radius: 11px;
  font-size: 13px;
  font-weight: 700;
  color: #555;
  cursor: pointer;
  min-height: unset;
  transition: all 0.15s;
}
.control-group button.active {
  background: #42664f;
  color: #fff;
}
.toggle-btn {
  border: 1.5px solid #d4cbb8;
  background: #fff;
  padding: 6px 12px;
  border-radius: 14px;
  font-size: 13px;
  font-weight: 700;
  color: #42664f;
  cursor: pointer;
  min-height: unset;
  transition: all 0.2s ease;
}
.toggle-btn.active {
  background: #42664f;
  color: #ffffff;
  border-color: #42664f;
}
.toggle-btn.off {
  background: #ece8dc;
  color: #888888;
  border-color: #d0cabc;
}

@media (max-width: 860px) {
  .top-nav-bar {
    flex-wrap: wrap;
    padding: 8px 12px;
    gap: 8px;
  }
  .nav-left .text { display: none; }
  .ep-select { max-width: 160px; font-size: 13px; }
  .nav-right { flex-wrap: wrap; }
}

/* ==========================================================================
   正文閱讀卡片容器 (Reader Canvas & Typography)
   ========================================================================== */
.reader {
  padding: 30px 15px 80px;
  display: flex;
  justify-content: center;
}

.prose {
  max-width: var(--reader-max-width);
  width: 100%;
  background: var(--color-prose-bg);
  border-radius: 20px;
  padding: 40px 48px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.04);
  border: 1px solid var(--color-border);
  font-size: var(--fs-reading);
  line-height: var(--lh-reading);
  box-sizing: border-box;
}

@media (max-width: 600px) {
  .prose {
    padding: 24px 18px;
    border-radius: 0;
    border: none;
  }
  .reader {
    padding: 0 0 40px 0;
  }
}

/* 字級調整控制 */
body[data-font-size="sm"] .prose, body[data-font-size="small"] .prose {
  --fs-reading: 26px;
  --lh-reading: 2.3;
}
body[data-font-size="md"] .prose, body[data-font-size="medium"] .prose {
  --fs-reading: 30px;
  --lh-reading: 2.5;
}
body[data-font-size="lg"] .prose, body[data-font-size="large"] .prose {
  --fs-reading: 36px;
  --lh-reading: 2.7;
}

/* 章節大標題 */
.chapter-heading {
  text-align: center;
  margin-bottom: 30px;
  border-bottom: 2px dashed #dedbce;
  padding-bottom: 20px;
}
.chapter-heading h1 {
  font-size: 1.4em;
  color: var(--color-primary);
  margin: 0;
  line-height: 1.8;
  font-weight: 800;
}

/* 分段小標題 */
.section-heading {
  margin: 1.8em 0 0.8em 0;
  color: #7a3e1d;
  font-size: 1.15em;
  font-weight: 700;
  border-left: 6px solid #c45c26;
  padding-left: 12px;
  line-height: 1.8;
}

/* 段落與對話 */
.source-block {
  margin: 0 0 1.2em 0;
  text-indent: 2em;
}
.dialogue-block {
  margin: 0 0 1.2em 0;
  text-indent: 0;
  padding-left: 1.2em;
  color: #1f3624;
  font-weight: 500;
}

/* 古詩 / 妙訣引用區塊 */
.verse-block {
  margin: 1.5em 0;
  padding: 16px 20px;
  background: var(--color-quote-bg);
  border-left: 4px solid var(--color-quote-border);
  border-radius: 0 12px 12px 0;
  font-size: 0.95em;
}

/* 插圖樣式 */
.story-picture {
  margin: 28px auto 35px;
  text-align: center;
}
.story-picture img {
  max-width: 100%;
  height: auto;
  border-radius: 16px;
  box-shadow: 0 6px 18px rgba(0,0,0,0.08);
}
.story-picture figcaption {
  margin-top: 10px;
  font-size: 0.8em;
  color: #667568;
}

/* ==========================================================================
   可點擊生詞卡按鈕 (Word Help Badges)
   ========================================================================== */
.word-help {
  display: inline;
  background: rgba(233, 184, 91, 0.22);
  border-bottom: 2px solid #d4952d;
  border-radius: 4px;
  cursor: pointer;
  padding: 1px 3px;
  transition: all 0.15s ease;
}
.word-help:hover {
  background: rgba(233, 184, 91, 0.45);
  box-shadow: 0 2px 6px rgba(212, 149, 45, 0.25);
}

/* ==========================================================================
   兒童動動腦思考互動卡片 (Interaction Cards)
   ========================================================================== */
.interaction-card {
  margin: 36px 0;
  padding: 24px 28px;
  background: linear-gradient(135deg, #fffdf5 0%, #fff8e8 100%);
  border: 2px dashed #e5a823;
  border-radius: 20px;
  box-shadow: 0 6px 16px rgba(229, 168, 35, 0.1);
  transition: all 0.3s ease;
}
.interaction-header {
  margin-bottom: 14px;
}
.interaction-badge {
  display: inline-block;
  background: #d97706;
  color: white;
  font-size: 15px;
  font-weight: 800;
  padding: 4px 14px;
  border-radius: 16px;
  margin-bottom: 6px;
  letter-spacing: 0.05em;
}
.interaction-title {
  font-size: 24px;
  font-weight: 800;
  color: #92400e;
  line-height: 1.6;
}
.interaction-body {
  font-size: 20px;
  line-height: 2.1;
  color: #4b3820;
}
.interaction-prompt {
  margin-top: 12px;
  padding: 12px 18px;
  background: rgba(217, 119, 6, 0.08);
  border-radius: 12px;
  font-weight: 700;
  color: #b45309;
}

/* ==========================================================================
   三大無障礙閱讀控制 (Toggle States)
   ========================================================================== */

/* 1. 關閉注音狀態 */
body.hide-zhuyin rt, body.hide-bopomofo rt, body.no-bopo rt {
  display: none !important;
}
body.hide-zhuyin ruby, body.hide-bopomofo ruby, body.no-bopo ruby {
  display: inline !important;
  vertical-align: baseline !important;
  line-height: inherit !important;
  margin: 0 !important;
}
body.hide-zhuyin .prose, body.hide-bopomofo .prose, body.no-bopo .prose {
  line-height: 2.1 !important;
}

/* 2. 關閉生詞註解狀態 (取消背景與底線，滑鼠游標恢復正常，無法點擊彈窗) */
body.hide-glossary .word-help {
  background: transparent !important;
  border-bottom: none !important;
  cursor: text !important;
  padding: 0 !important;
  color: inherit !important;
  outline: none !important;
  box-shadow: none !important;
}

/* 3. 關閉思考互動狀態 */
body.hide-interactions .interaction-card {
  display: none !important;
}

/* ==========================================================================
   生詞彈窗 (Modal Dialog - Qiao Hu Style)
   ========================================================================== */
.vocab-modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(20, 28, 22, 0.55);
  backdrop-filter: blur(4px);
  z-index: 1000;
  justify-content: center;
  align-items: center;
  padding: 20px;
}
.vocab-modal.show {
  display: flex;
}
.modal-content {
  background: #ffffff;
  border: 4px solid #42664f;
  border-radius: 28px;
  padding: 32px 36px;
  width: 90%;
  max-width: 680px;
  max-height: 85vh;
  box-sizing: border-box;
  overflow-x: hidden;
  overflow-y: auto;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.25);
  position: relative;
  animation: modalPop 0.25s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}
@keyframes modalPop {
  0% { transform: scale(0.9); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}
.modal-close {
  position: absolute;
  top: 14px;
  right: 18px;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 2px solid #d1d9cb;
  background: #f4f6f0;
  font-size: 24px;
  font-weight: 800;
  color: #42664f;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s;
}
.modal-close:hover {
  background: #42664f;
  color: #fff;
}
.modal-word-title {
  font-size: 36px;
  color: #3b5f47;
  border-bottom: 3px solid #e2ebd8;
  padding-bottom: 12px;
  margin-top: 0;
  margin-bottom: 18px;
  line-height: 2.1;
}
.modal-word-def {
  font-size: 26px;
  line-height: 2.3;
  color: #2c362e;
}
.modal-footer {
  margin-top: 24px;
  text-align: right;
}
.modal-btn-confirm {
  background: #42664f;
  color: #ffffff;
  border: none;
  border-radius: 16px;
  padding: 10px 24px;
  font-size: 18px;
  font-weight: 700;
  cursor: pointer;
}
.modal-btn-confirm:hover {
  background: #32503d;
}

/* ==========================================================================
   章節底部翻頁列 (Chapter Nav Footer)
   ========================================================================== */
.chapter-nav-footer {
  margin-top: 48px;
  padding-top: 28px;
  border-top: 2px dashed #dedbce;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
}
.chapter-nav-footer a {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 12px 20px;
  border-radius: 16px;
  text-decoration: none;
  font-weight: 700;
  font-size: 16px;
  background: #f1ede3;
  color: #3b4d3e;
  border: 1px solid #d4cbb8;
  transition: all 0.2s;
}
.chapter-nav-footer a:hover:not(.disabled) {
  background: #42664f;
  color: #ffffff;
  border-color: #42664f;
}
.chapter-nav-footer a.disabled {
  opacity: 0.35;
  cursor: not-allowed;
  pointer-events: none;
}
@media (max-width: 600px) {
  .chapter-nav-footer {
    flex-direction: column;
    width: 100%;
  }
  .chapter-nav-footer a {
    width: 100%;
    justify-content: center;
    box-sizing: border-box;
  }
}
