/* PDF 對照閱讀：介面安靜，讓頁面當主角。黃色永遠代表原文、藍色永遠代表譯文。 */

:root {
  --desk: #e9ecef;
  --surface: #f4f6f8;
  --raise: #ffffff;
  --ink: #1d2430;
  --ink-2: #5b6573;
  --line: #d3d9e0;
  --accent: #2f66d0;
  --on-accent: #ffffff;
  --src: #d99a00;
  --src-fill: rgba(255, 193, 7, 0.34);
  --dst: #2f66d0;
  --dst-fill: rgba(47, 102, 208, 0.14);
  --danger: #b83232;
  --sans: system-ui, -apple-system, "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", sans-serif;
  --serif: "Noto Serif TC", "Songti TC", "PMingLiU", "MingLiU", Georgia, serif;
  --top: env(safe-area-inset-top, 0px);
  --bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --desk: #15191f;
    --surface: #1d232b;
    --raise: #252c35;
    --ink: #e6e9ed;
    --ink-2: #a3acb8;
    --line: #353d48;
    --accent: #6b9cff;
    --on-accent: #0d1420;
    --dst: #6b9cff;
    --danger: #e06666;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--desk);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}
[hidden] { display: none !important; }
button { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- 共用按鈕 ---------- */
.btn {
  min-height: 44px;
  padding: 0 18px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--raise);
  font-size: 15px;
  cursor: pointer;
  white-space: nowrap;
}
.btn:active { transform: scale(0.98); }
.btn-primary { background: var(--accent); border-color: transparent; color: var(--on-accent); font-weight: 600; }
.btn-danger { background: var(--danger); border-color: transparent; color: #fff; font-weight: 600; }
.icon-btn {
  width: 44px;
  height: 44px;
  flex: none;
  display: inline-grid;
  place-items: center;
  border: 0;
  border-radius: 10px;
  background: transparent;
  cursor: pointer;
}
.icon-btn:hover { background: var(--surface); }
.icon-btn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- 書架 ---------- */
.lib-head, .lib-main, .lib-foot { max-width: 760px; margin: 0 auto; }
.lib-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: calc(20px + var(--top)) 16px 12px;
}
.lib-brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.lib-brand h1 { margin: 0; font-size: 21px; font-weight: 600; letter-spacing: 0.02em; }
.brand-mark { position: relative; width: 31px; height: 24px; flex: none; }
.brand-mark i {
  position: absolute;
  top: 0;
  width: 18px;
  height: 24px;
  border-radius: 3px;
  background: #fff;
  box-shadow: 0 0 0 1px var(--line);
}
.brand-mark .m-src { left: 0; }
.brand-mark .m-dst { left: 13px; }
.brand-mark i::after { content: ""; position: absolute; left: 3px; right: 3px; top: 9px; height: 6px; border-radius: 1px; }
.brand-mark .m-src::after { background: var(--src-fill); box-shadow: inset 0 0 0 1px var(--src); }
.brand-mark .m-dst::after { background: var(--dst-fill); box-shadow: inset 0 0 0 1px var(--dst); }

.lib-main { padding: 4px 16px 24px; }
.install-hint {
  margin: 4px 0 12px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  color: var(--ink-2);
  font-size: 14px;
}
.lib-empty { padding: 40px 4px 24px; max-width: 34em; }
.lib-empty h2 { margin: 0 0 8px; font-family: var(--serif); font-weight: 600; font-size: 23px; line-height: 1.35; }
.lib-empty p { margin: 0 0 20px; color: var(--ink-2); }
.lib-list { list-style: none; margin: 0; padding: 0; }
.lib-item {
  display: flex;
  align-items: center;
  gap: 8px;
  border-bottom: 1px solid var(--line);
}
.lib-open {
  flex: 1;
  min-width: 0;
  padding: 14px 4px;
  border: 0;
  background: transparent;
  text-align: left;
  cursor: pointer;
}
.lib-open:hover .lib-title { text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 3px; }
.lib-title {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  font-family: var(--serif);
  font-size: 17px;
  line-height: 1.45;
}
.lib-meta { display: block; margin-top: 4px; font-size: 13px; color: var(--ink-2); }
.lib-meta .nomap { color: #a15c00; }
.lib-busy { color: var(--ink-2); font-size: 14px; }
.lib-foot {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 16px calc(16px + var(--bottom));
  font-size: 12px;
  color: var(--ink-2);
}

/* ---------- 閱讀 ---------- */
#reader { position: relative; display: flex; flex-direction: column; height: 100vh; height: 100dvh; }
/* 頂列是半透明的一層，頁面從它底下捲過去（不佔一條固定的實心橫帶） */
.bar {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: var(--top) max(8px, env(safe-area-inset-right)) 0 max(4px, env(safe-area-inset-left));
  min-height: calc(56px + var(--top));
  background: color-mix(in srgb, var(--desk) 78%, transparent);
  -webkit-backdrop-filter: blur(18px) saturate(160%);
  backdrop-filter: blur(18px) saturate(160%);
  border-bottom: 1px solid color-mix(in srgb, var(--line) 65%, transparent);
}
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .bar { background: var(--desk); }
}
@media (prefers-reduced-transparency: reduce) {
  .bar { background: var(--desk); -webkit-backdrop-filter: none; backdrop-filter: none; }
}
.r-title {
  flex: 1;
  min-width: 0;
  margin: 0;
  font-family: var(--serif);
  font-size: 15px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.seg {
  flex: none;
  display: inline-flex;
  padding: 2px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--surface);
}
.seg button {
  min-height: 40px;
  padding: 0 11px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--ink-2);
  font-size: 14px;
  cursor: pointer;
}
.seg button[aria-checked="true"] { background: var(--raise); color: var(--ink); font-weight: 600; box-shadow: 0 1px 2px rgba(0, 0, 0, 0.14); }
.dot { width: 9px; height: 9px; border-radius: 50%; flex: none; }
.dot + .dot { margin-left: -9px; }
.dot-src { background: var(--src-fill); box-shadow: inset 0 0 0 1.5px var(--src); }
.dot-dst { background: var(--dst-fill); box-shadow: inset 0 0 0 1.5px var(--dst); }
.zoom { flex: none; display: inline-flex; }

@media (max-width: 600px) {
  .r-title { display: none; }
  .bar { justify-content: space-between; }
  .zoom [data-zoom="fit"] { display: none; }
  .seg button { padding: 0 9px; }
}

.pages {
  position: relative;
  flex: 1;
  overflow: auto;
  overscroll-behavior: contain;
  padding: calc(68px + var(--top)) 0 calc(32px + var(--bottom));
  outline: none;
}
.page {
  position: relative;
  margin: 0 auto 12px;
  background: #fff;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.07), 0 1px 3px rgba(0, 0, 0, 0.1);
  cursor: default;
  -webkit-tap-highlight-color: transparent;
}
.page canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.page.hot { cursor: pointer; }
.hl { position: absolute; inset: 0; pointer-events: none; }
.mark { position: absolute; border-radius: 3px; mix-blend-mode: multiply; }
.mark-src { background: var(--src-fill); box-shadow: inset 0 0 0 1.5px var(--src); }
.mark-dst { background: var(--dst-fill); box-shadow: inset 0 0 0 1.5px #2f66d0; }
.mark.soft { opacity: 0.6; }
.r-status {
  position: fixed;
  left: 0;
  right: 0;
  top: 45%;
  margin: 0;
  text-align: center;
  color: var(--ink-2);
  font-size: 15px;
}

/* ---------- 面板（窄螢幕：底部；寬螢幕：右側） ---------- */
.panel {
  position: fixed;
  z-index: 20;
  display: flex;
  flex-direction: column;
  background: var(--raise);
  color: var(--ink);
}
.panel-grip { width: 38px; height: 5px; margin: 8px auto 0; border-radius: 3px; background: var(--line); flex: none; }
.panel-head { display: flex; align-items: center; gap: 8px; padding: 6px 6px 4px 16px; flex: none; }
.panel-title { flex: 1; margin: 0; font-size: 15px; font-weight: 600; display: flex; align-items: center; gap: 8px; }
.panel-body { overflow: auto; padding: 4px 16px calc(16px + var(--bottom)); overscroll-behavior: contain; }
.crop { display: block; max-width: 100%; height: auto; margin: 0 auto; background: #fff; border-radius: 6px; box-shadow: 0 0 0 1px var(--line); }
.crop-text { margin: 12px 0 0; font-size: 14px; line-height: 1.65; color: var(--ink-2); -webkit-user-select: text; user-select: text; }
.panel-actions { display: flex; gap: 8px; margin-top: 14px; }

@media (max-width: 899px) {
  .panel {
    left: 0;
    right: 0;
    bottom: 0;
    max-height: 60vh;
    max-height: 60dvh;
    border-radius: 14px 14px 0 0;
    box-shadow: 0 -6px 24px rgba(0, 0, 0, 0.2);
    transform: translateY(110%);
    touch-action: none;
  }
  .panel-body { touch-action: pan-y; }
}
@media (min-width: 900px) {
  .panel {
    top: 0;
    right: 0;
    bottom: 0;
    width: min(420px, 38vw);
    padding-top: var(--top);
    border-left: 1px solid var(--line);
    box-shadow: -6px 0 24px rgba(0, 0, 0, 0.08);
    transform: translateX(105%);
    transition: transform 0.24s cubic-bezier(0.2, 0.8, 0.2, 1);
  }
  .panel.open { transform: none; }
  .panel-grip { display: none; }
}

/* ---------- 提示與對話框 ---------- */
.toast {
  position: fixed;
  z-index: 40;
  left: 50%;
  bottom: calc(20px + var(--bottom));
  transform: translate(-50%, 8px);
  max-width: min(92vw, 480px);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px 10px 16px;
  border-radius: 12px;
  background: var(--ink);
  color: var(--desk);
  font-size: 14px;
  opacity: 0;
  transition: opacity 0.2s, transform 0.2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast[data-kind="error"] { background: #8f2d2d; color: #fff; }
.toast-msg { margin: 0; flex: 1; }
.toast-btn, .toast-close { min-height: 36px; border: 0; border-radius: 8px; background: rgba(255, 255, 255, 0.16); color: inherit; padding: 0 12px; cursor: pointer; }
.dialog {
  border: 0;
  border-radius: 14px;
  padding: 20px;
  width: min(92vw, 420px);
  background: var(--raise);
  color: var(--ink);
}
.dialog::backdrop { background: rgba(0, 0, 0, 0.38); }
.dialog-title { margin: 0 0 8px; font-size: 18px; }
.dialog-msg { margin: 0; color: var(--ink-2); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }
.noscript { padding: 24px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
  /* 減少動態效果：面板不滑動，改成淡入淡出 */
  .panel { transform: none !important; opacity: 0; transition: opacity 0.2s ease !important; }
  .panel.open { opacity: 1; }
}
