/* =========================================================================
   catalog.css — 電子型錄檢視器
   ========================================================================= */

.cv {
  position: relative;
  display: grid;
  grid-template-columns: 1fr;
  height: calc(100vh - var(--nav-h));
  min-height: 560px;
  background: var(--c-bg-2);
  border-top: 1px solid var(--c-line);
}
@media (min-width: 860px) {
  .cv.with-side { grid-template-columns: 272px 1fr; }
}
.cv.embed { height: min(80vh, 860px); min-height: 480px; border: 1px solid var(--c-line); border-radius: var(--r); overflow: hidden; }
.cv.embed .cv-hint { display: none; }
.cv.fs { position: fixed; inset: 0; z-index: 120; height: 100vh; border-top: 0; }

/* ---------- 側欄 ---------- */
.cv-side {
  display: none; flex-direction: column; min-height: 0;
  background: var(--c-bg); border-right: 1px solid var(--c-line);
}
@media (min-width: 860px) { .cv.with-side .cv-side { display: flex; } }
/* 行動版：側欄變成覆蓋在舞台上的抽屜 */
@media (max-width: 859px) {
  .cv.with-side .cv-side {
    display: flex; position: absolute; z-index: 10;
    top: 0; bottom: 0; left: 0; width: min(312px, 86vw);
    box-shadow: var(--shadow-lg);
  }
}

.cv-tabs { display: flex; border-bottom: 1px solid var(--c-line); flex: none; }
.cv-tabs button {
  flex: 1; padding: 11px 6px; background: transparent; border: 0;
  border-bottom: 2px solid transparent;
  font-size: .82rem; color: var(--c-text-3); font-weight: 500;
}
.cv-tabs button:hover { color: var(--c-text); background: var(--c-surface-2); }
.cv-tabs button.on { color: var(--c-accent); border-bottom-color: var(--c-accent); }

.cv-panel { flex: 1; overflow-y: auto; padding: var(--sp-3); min-height: 0; }
.cv-panel[hidden] { display: none; }

/* 縮圖 */
.cv-thumbs { display: grid; grid-template-columns: 1fr 1fr; gap: var(--sp-3); }
.cv-thumb { border: 0; padding: 0; background: transparent; text-align: center; }
.cv-thumb .sheet {
  aspect-ratio: 210 / 297; background: #fff; border: 1px solid var(--c-line-2);
  border-radius: 2px; overflow: hidden; display: grid; place-items: center;
  transition: border-color .15s, box-shadow .15s, transform .15s;
}
/* 只縮放最外層的那一個 svg —— 型錄頁裡面還有嵌套的外形圖 svg，不能一起套 */
.cv-thumb .sheet > svg, .cv-thumb .sheet > img, .cv-thumb .sheet > canvas { width: 100%; height: 100%; object-fit: contain; }
.cv-thumb:hover .sheet { border-color: var(--c-accent-dim); transform: translateY(-2px); }
.cv-thumb.on .sheet { border-color: var(--c-accent); box-shadow: 0 0 0 2px var(--c-accent-wash); }
.cv-thumb .lbl { font-family: var(--f-mono); font-size: .7rem; color: var(--c-text-3); margin-top: 4px; display: block; }
.cv-thumb.on .lbl { color: var(--c-accent); }

/* 目錄 */
.cv-toc { list-style: none; margin: 0; padding: 0; }
.cv-toc li { margin-bottom: 1px; }
.cv-toc button {
  width: 100%; display: flex; justify-content: space-between; gap: var(--sp-3);
  align-items: baseline; padding: 8px 10px; border: 0; border-radius: var(--r);
  background: transparent; text-align: left; font-size: .87rem; color: var(--c-text-2);
}
.cv-toc button:hover { background: var(--c-accent-wash); color: var(--c-accent); }
.cv-toc button.on { background: var(--c-accent-wash); color: var(--c-accent); font-weight: 600; }
.cv-toc .pg { font-family: var(--f-mono); font-size: .74rem; color: var(--c-text-3); flex: none; }
.cv-toc li.lv2 button { padding-left: 24px; font-size: .82rem; color: var(--c-text-3); }

/* 搜尋 */
.cv-search-box { position: relative; margin-bottom: var(--sp-3); }
.cv-search-box input { width: 100%; padding: 9px 12px 9px 32px; background: var(--c-bg-3); color: var(--c-text); border: 1px solid var(--c-line-2); border-radius: var(--r); font-size: .88rem; }
.cv-search-box input:focus { outline: 0; border-color: var(--c-accent); }
.cv-search-box svg { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--c-text-3); }
.cv-hits { list-style: none; margin: 0; padding: 0; }
.cv-hits li { border-bottom: 1px solid var(--c-line); }
.cv-hits button { width: 100%; text-align: left; padding: 10px; border: 0; background: transparent; font-size: .82rem; color: var(--c-text-2); line-height: 1.55; }
.cv-hits button:hover { background: var(--c-surface-2); }
.cv-hits .pg { font-family: var(--f-mono); font-size: .72rem; color: var(--c-accent); display: block; margin-bottom: 2px; }
.cv-hits mark { background: var(--c-accent); color: var(--c-on-accent); padding: 0 2px; border-radius: 2px; }
.cv-empty { padding: var(--sp-5) var(--sp-3); text-align: center; color: var(--c-text-3); font-size: .85rem; }

/* ---------- 主區 ---------- */
.cv-main { display: flex; flex-direction: column; min-width: 0; min-height: 0; position: relative; }

.cv-bar {
  flex: none; display: flex; align-items: center; gap: var(--sp-2);
  padding: var(--sp-2) var(--sp-3); background: var(--c-bg);
  border-bottom: 1px solid var(--c-line); overflow-x: auto; scrollbar-width: none;
}
.cv-bar::-webkit-scrollbar { display: none; }
.cv-bar .sep { width: 1px; height: 22px; background: var(--c-line); flex: none; }
.cv-bar .grow { flex: 1; min-width: 4px; }
.cv-btn {
  display: inline-flex; align-items: center; gap: 6px; flex: none;
  height: 32px; padding: 0 10px; border: 1px solid transparent; border-radius: var(--r);
  background: transparent; color: var(--c-text-2); font-size: .83rem; white-space: nowrap;
}
.cv-btn:hover { background: var(--c-surface-2); color: var(--c-text); }
.cv-btn.on { background: var(--c-accent-wash); color: var(--c-accent); border-color: var(--c-accent-dim); }
.cv-btn:disabled { opacity: .35; pointer-events: none; }
.cv-btn.sq { width: 32px; padding: 0; justify-content: center; }

.cv-zoomval { font-family: var(--f-mono); font-size: .8rem; color: var(--c-text-2); min-width: 50px; text-align: center; flex: none; }
.cv-pagebox { display: flex; align-items: center; gap: 5px; flex: none; font-size: .82rem; color: var(--c-text-3); }
.cv-pagebox input {
  width: 48px; height: 30px; padding: 0 6px; text-align: center;
  background: var(--c-bg-3); border: 1px solid var(--c-line-2); border-radius: var(--r);
  font-family: var(--f-mono); font-size: .84rem; color: var(--c-text);
}
.cv-pagebox input:focus { outline: 0; border-color: var(--c-accent); }

/* 舞台 */
.cv-stage {
  flex: 1; position: relative; overflow: hidden; min-height: 0;
  background:
    radial-gradient(circle at 50% 0%, var(--c-bg-3), var(--c-bg-2) 60%);
  cursor: grab; touch-action: none; user-select: none;
}
.cv-stage.dragging { cursor: grabbing; }
.cv-stage.zoomable { cursor: zoom-in; }

.cv-canvas {
  position: absolute; top: 0; left: 0;
  transform-origin: 0 0;
  display: flex; gap: 2px;
  will-change: transform;
}
.cv-sheet {
  background: #fff; flex: none; position: relative;
  box-shadow: 0 6px 28px rgba(0,0,0,.45);
  display: grid; place-items: center; overflow: hidden;
}
:root[data-theme="light"] .cv-sheet { box-shadow: 0 4px 22px rgba(16,21,27,.22); }
.cv-sheet > svg, .cv-sheet > img, .cv-sheet > canvas { width: 100%; height: 100%; display: block; }
.cv-sheet.blank { background: transparent; box-shadow: none; }
/* 跨頁中央的書溝 */
.cv-canvas.spread .cv-sheet:first-child::after,
.cv-canvas.spread .cv-sheet:last-child::before {
  content: ""; position: absolute; top: 0; bottom: 0; width: 26px; pointer-events: none;
}
.cv-canvas.spread .cv-sheet:first-child::after { right: 0; background: linear-gradient(90deg, transparent, rgba(0,0,0,.14)); }
.cv-canvas.spread .cv-sheet:last-child::before { left: 0; background: linear-gradient(270deg, transparent, rgba(0,0,0,.14)); }

/* 搜尋命中標記 */
.cv-mark {
  position: absolute; background: color-mix(in srgb, var(--c-accent) 40%, transparent);
  outline: 1.5px solid var(--c-accent); border-radius: 2px; pointer-events: none;
  animation: cvPulse 1.4s ease-out 2;
}
@keyframes cvPulse { 0%,100% { opacity: .35; } 50% { opacity: .95; } }

/* 載入 / 錯誤 */
.cv-load {
  position: absolute; inset: 0; display: grid; place-items: center; z-index: 5;
  background: color-mix(in srgb, var(--c-bg-2) 82%, transparent); backdrop-filter: blur(3px);
  color: var(--c-text-2); font-size: .9rem; text-align: center; padding: var(--sp-5);
}
.cv-spin {
  width: 30px; height: 30px; margin: 0 auto var(--sp-3);
  border: 2.5px solid var(--c-line-2); border-top-color: var(--c-accent);
  border-radius: 50%; animation: cvSpin .85s linear infinite;
}
@keyframes cvSpin { to { transform: rotate(360deg); } }

/* 浮動提示 */
.cv-hint {
  position: absolute; bottom: var(--sp-4); left: 50%; transform: translateX(-50%);
  z-index: 6; padding: 7px 14px; border-radius: 100px;
  background: color-mix(in srgb, var(--c-bg) 80%, transparent);
  backdrop-filter: blur(10px); border: 1px solid var(--c-line);
  font-size: .76rem; color: var(--c-text-3); white-space: nowrap;
  max-width: calc(100% - 32px); overflow: hidden; text-overflow: ellipsis;
  transition: opacity .4s, transform .4s;
}
.cv-hint.gone { opacity: 0; transform: translateX(-50%) translateY(8px); pointer-events: none; }

/* 書籍選擇 */
.book-row { display: grid; gap: var(--sp-4); }
@media (min-width: 620px)  { .book-row { grid-template-columns: repeat(2, 1fr); } }
@media (min-width: 1040px) { .book-row { grid-template-columns: repeat(4, 1fr); } }
.book {
  display: flex; flex-direction: column; gap: var(--sp-3);
  border: 1px solid var(--c-line); border-radius: var(--r-lg); padding: var(--sp-3);
  background: var(--c-surface); transition: border-color .18s, transform .18s;
}
.book:hover { border-color: var(--c-accent-dim); transform: translateY(-3px); }
.book.on { border-color: var(--c-accent); box-shadow: 0 0 0 1px var(--c-accent); }
.book .cover {
  aspect-ratio: 210 / 297; background: #fff; border-radius: var(--r-sm);
  overflow: hidden; display: grid; place-items: center;
}
.book .cover > svg, .book .cover > img { width: 100%; height: 100%; object-fit: contain; }
.book .meta b { display: block; font-size: .92rem; color: var(--c-text); line-height: 1.4; }
.book .meta span { font-size: .78rem; color: var(--c-text-3); font-family: var(--f-mono); }

/* 鍵盤說明 */
.kb { display: flex; flex-wrap: wrap; gap: var(--sp-2) var(--sp-5); list-style: none; padding: 0; margin: 0; }
.kb li { display: flex; align-items: center; gap: 7px; font-size: .82rem; color: var(--c-text-3); }
kbd {
  display: inline-block; min-width: 22px; padding: 2px 6px; text-align: center;
  background: var(--c-bg-3); border: 1px solid var(--c-line-2);
  border-bottom-width: 2px; border-radius: 4px;
  font-size: .76rem; color: var(--c-text-2);
}
