/* ══════════════════ 全域 ══════════════════ */
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body {
  width: 100%; height: 100%;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
}
body {
  font-family: "DFKai-SB", "BiauKai", "標楷體", "PMingLiU", "新細明體", "Microsoft JhengHei", "微軟正黑", serif;
  background: #f6f1e6;   /* 米黃色底,誦經傳統色調 */
  color: #1a1a1a;
}

/* 主題色 */
body.theme-white-on-black { background: #000; color: #fff; }
body.theme-white-on-black .home-title { color: #fff; }
body.theme-white-on-black .home-sub { color: #ccc; }
body.theme-white-on-black .home-btn { background: #222; color: #fff; border-color: #fff; }
body.theme-white-on-black .home-btn:hover { background: #333; }
body.theme-white-on-black .corner-dot { color: #fff; }
body.theme-white-on-black .nav-hint { color: rgba(255,255,255,0.35); }
body.theme-white-on-black .page-info { color: rgba(255,255,255,0.5); }
body.theme-white-on-black .settings-panel { background: #111; color: #eee; border-color: #444; }
body.theme-white-on-black .settings-panel select,
body.theme-white-on-black .settings-panel input[type="number"] { background:#222; color:#eee; border-color:#555; }

/* 字型 */
body.font-kaiti .reader-content, body.font-kaiti .home-title { font-family: "DFKai-SB", "BiauKai", "標楷體", "楷體", KaiTi, serif; }
body.font-mingliu .reader-content, body.font-mingliu .home-title { font-family: "PMingLiU", "新細明體", "細明體", "SimSun", "宋體", serif; }
body.font-yahei .reader-content, body.font-yahei .home-title { font-family: "Microsoft JhengHei", "微軟正黑體", "Microsoft YaHei", sans-serif; }

.screen { position: fixed; inset: 0; }
.hidden { display: none !important; }

/* ══════════════════ 首頁 ══════════════════ */
#home { display: flex; align-items: center; justify-content: center; text-align: center; }
.home-inner { padding: 24px; }
.home-title {
  font-size: clamp(28px, 6vw, 56px);
  letter-spacing: 0.15em;
  margin-bottom: 12px;
  color: #4a2c1a;
}
.home-sub { font-size: 14px; color: #7a6a55; margin-bottom: 40px; letter-spacing: 0.05em; }
.home-btn {
  display: block; margin: 12px auto;
  font-size: 20px; padding: 12px 32px;
  min-width: 220px;
  border: 2px solid #4a2c1a;
  border-radius: 4px;
  background: #f6f1e6; color: #4a2c1a;
  cursor: pointer;
  font-family: inherit;
  letter-spacing: 0.1em;
}
.home-btn:hover { background: #eee1c6; }
.home-btn.secondary { background: transparent; }
.home-hint { margin-top: 28px; font-size: 12px; color: #999; }

/* ══════════════════ 閱讀器 ══════════════════ */
#reader { display: flex; align-items: stretch; }
.reader-container {
  flex: 1;
  padding: min(6vw, 40px) min(6vw, 40px);
  padding-bottom: 60px;
  position: relative;
  overflow: hidden;
}
.reader-content {
  width: 100%;
  height: 100%;
  line-height: 1.9;
  font-size: 30px;
}

/* 直式 (右→左) */
.reader-content.vertical {
  writing-mode: vertical-rl;
  -webkit-writing-mode: vertical-rl;
  text-orientation: upright;
  -webkit-text-orientation: upright;
  overflow-wrap: normal;
}
/* 橫式 (上→下 = 一般由左到右閱讀,自然由上換行至下) */
.reader-content.horizontal { writing-mode: horizontal-tb; }

/* ruby 注音 */
ruby { ruby-align: center; }
ruby rt {
  font-size: 0.4em;
  line-height: 1;
  color: inherit;
  opacity: 0.75;
  font-family: "PMingLiU", "SimSun", serif;
  letter-spacing: 0;
}
/* 直式時注音在右邊 */
.reader-content.vertical ruby { ruby-position: over; -webkit-ruby-position: after; }
.reader-content.vertical ruby rt { text-orientation: upright; }

.reader-content.no-zhuyin rt { display: none; }

/* 段落點:讓每個句號後有小間隔 */
.reader-content .punc { opacity: 0.5; }

/* 頁面資訊 */
.page-info {
  position: absolute; bottom: 12px; left: 50%; transform: translateX(-50%);
  font-size: 13px; color: rgba(0,0,0,0.4);
  letter-spacing: 0.05em;
  pointer-events: none;
}

.nav-hint {
  position: absolute; top: 50%; transform: translateY(-50%);
  font-size: 60px; color: rgba(0,0,0,0.15);
  cursor: pointer; padding: 8px 16px;
  user-select: none;
}
.nav-hint:hover { color: rgba(0,0,0,0.4); }
.nav-hint.left { left: 4px; }
.nav-hint.right { right: 4px; }

/* ══════════════════ 左下角小點 ══════════════════ */
.corner-dot {
  position: fixed; left: 12px; bottom: 12px;
  width: 28px; height: 28px; line-height: 24px; text-align: center;
  font-size: 32px; font-weight: bold;
  cursor: pointer; z-index: 100;
  color: rgba(0,0,0,0.35);
  transition: color 0.2s;
}
.corner-dot:hover { color: rgba(0,0,0,0.9); }

/* ══════════════════ 設定面板 ══════════════════ */
.settings-panel {
  position: fixed;
  left: 16px; bottom: 48px;
  width: min(340px, calc(100vw - 32px));
  max-height: calc(100vh - 80px);
  background: #fff; color: #222;
  border: 1px solid #ccc; border-radius: 6px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.2);
  z-index: 200;
  overflow-y: auto;
  font-family: "Microsoft JhengHei", "微軟正黑體", sans-serif;
}
.settings-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 14px;
  border-bottom: 1px solid #ddd;
  font-weight: bold;
  position: sticky; top: 0; background: inherit;
}
.settings-header button { background: none; border: none; font-size: 18px; cursor: pointer; color: inherit; }
.settings-body { padding: 12px 14px; }
.row {
  margin-bottom: 12px; display: flex; align-items: center; flex-wrap: wrap; gap: 8px;
  font-size: 14px;
}
.row > label:first-child {
  min-width: 72px; font-weight: 500; color: #666; flex-shrink: 0;
}
.row .sw { display: inline-flex; align-items: center; gap: 4px; font-weight: normal; color: inherit; min-width: auto; }
.row select, .row input[type="number"] {
  padding: 4px 8px; border: 1px solid #bbb; border-radius: 3px; font: inherit;
  background: #fff; color: inherit;
}
.row input[type="range"] { flex: 1; min-width: 100px; }
.row.actions button {
  padding: 6px 14px; margin-right: 8px;
  border: 1px solid #bbb; background: #f4f4f4; color: #333;
  border-radius: 3px; cursor: pointer; font: inherit;
}
body.theme-white-on-black .row.actions button { background:#222; color:#eee; border-color:#555; }
.row.info { font-size: 11px; color: #888; }

/* toast */
.toast {
  position: fixed; top: 20px; left: 50%; transform: translateX(-50%);
  background: rgba(0,0,0,0.75); color: #fff;
  padding: 8px 16px; border-radius: 4px; z-index: 300;
  font-size: 14px;
}

/* Very small screens */
@media (max-width: 480px) {
  .home-title { letter-spacing: 0.1em; }
  .nav-hint { font-size: 40px; }
  .reader-container { padding: 12px; padding-bottom: 40px; }
}
