/* ACBLS Engine — main.css
   单渲染器架构：预览为 pdf.js 渲染的 <canvas>，样式只管页面框架/控件/容器装饰，
   版面几何全部在 PdfRenderer（矢量 PDF 管线）内，不在此处。
   布局：左侧设置边栏（示例/版式/開本/書種/紙/字體/字號/效果/導入導出分組）+
         右側書籍預覽區（翻頁控件貼近書籍，canvas 由 JS 適配容器尺寸）。 */
@import url('https://fonts.googleapis.com/css2?family=Noto+Serif+TC:wght@400;500;600;700&display=swap');

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

html, body { height: 100%; }

body {
  background: #b8a88a;
  font-family: 'Noto Serif TC', 'KaiTi', 'STKaiti', 'SimKai', serif;
  overflow: hidden;
}

.app {
  display: flex;
  height: 100vh;
}

/* === 左侧设置边栏 === */
.sidebar {
  width: 216px;
  flex-shrink: 0;
  overflow-y: auto;
  overflow-x: hidden;
  background: #d3c49e;
  border-right: 1px solid #8b7a5a;
  box-shadow: 2px 0 10px rgba(0,0,0,0.12);
  padding: 12px 12px 20px;
  display: flex;
  flex-direction: column;
  gap: 13px;
  z-index: 10;
}
.sidebar::-webkit-scrollbar { width: 6px; }
.sidebar::-webkit-scrollbar-thumb { background: rgba(139,122,90,0.4); }

.side-title {
  font-size: 16px;
  letter-spacing: 5px;
  color: #5a4830;
  text-align: center;
  padding: 6px 0 10px;
  border-bottom: 1px solid rgba(139,122,90,0.45);
}

.side-group { display: flex; flex-direction: column; gap: 6px; }

.side-label {
  font-size: 11px;
  letter-spacing: 3px;
  color: #8b7a5a;
  border-left: 3px solid #8b7a5a;
  padding-left: 6px;
  user-select: none;
}

/* 下拉选择：細墨框簽條式（appearance 清除 + 墨色 ▾），替代原平鋪按鈕組 */
.sidebar select {
  width: 100%;
  padding: 6px 22px 6px 8px;
  font-family: inherit;
  font-size: 12px;
  color: #5a4830;
  background-color: transparent;
  border: 1px solid rgba(139,122,90,0.35);
  border-radius: 0;
  appearance: none;
  -webkit-appearance: none;
  background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="9" height="5" viewBox="0 0 9 5"><path d="M1 0.5l3.5 3.5L8 0.5" fill="none" stroke="%238b7a5a" stroke-width="1.2"/></svg>');
  background-repeat: no-repeat;
  background-position: right 8px center;
  cursor: pointer;
}
.sidebar select:hover { background-color: rgba(139,122,90,0.12); }
.sidebar select:focus-visible { outline: 1px solid #5a4830; outline-offset: 1px; }

.sel-hint {
  font-size: 10px;
  letter-spacing: 1px;
  color: #8b7a5a;
  user-select: none;
}

/* 自定義細節：低頻參數折疊區（summary 沿用 side-label 視覺） */
.custom-details summary { cursor: pointer; list-style: none; }
.custom-details summary::-webkit-details-marker { display: none; }
.custom-details summary::before { content: '▸ '; }
.custom-details[open] summary::before { content: '▾ '; }
.detail-rows {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 6px;
}
.detail-row {
  display: grid;
  grid-template-columns: 2.5em 1fr;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  letter-spacing: 2px;
  color: #8b7a5a;
}
.detail-row select { padding: 4px 20px 4px 6px; font-size: 11px; }

.sidebar button {
  padding: 6px 4px;
  font-family: inherit;
  font-size: 12px;
  background: transparent;
  border: 1px solid rgba(139,122,90,0.35);
  color: #6b5c42;
  cursor: pointer;
  letter-spacing: 1px;
  transition: background 0.15s ease;
}
.sidebar button:hover { background: rgba(139,122,90,0.12); }
.sidebar button:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}
.sidebar button:disabled:hover { background: transparent; }

.toggle-col { display: flex; flex-direction: column; gap: 6px; }
.toggle-btn {
  font-size: 12px;
  color: #6b5c42;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  letter-spacing: 1px;
  user-select: none;
}
.toggle-btn input { cursor: pointer; accent-color: #5a4830; }

.font-slider {
  width: 100%;
  cursor: pointer;
  accent-color: #5a4830;
}
.font-scale-label { font-size: 11px; color: #8b7a5a; letter-spacing: 0; }

.side-actions { margin-top: auto; gap: 6px; }
.side-actions button {
  padding: 8px 4px;
  background: #e5d6b0;
  border-color: #8b7a5a;
  color: #3a3530;
}
.side-actions button:hover { background: #d4c8a0; }

/* 移动端抽屉控件：桌面端隐藏（媒体查询内启用） */
.btn-menu { display: none; }
.drawer-backdrop { display: none; }

/* === 右侧书籍预览 === */
.stage {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.stage-nav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 18px;
  padding: 10px 0 6px;
  flex-shrink: 0;
}
.stage-nav .btn-icon {
  font-size: 15px;
  padding: 6px 14px;
  font-family: inherit;
  background: #e5d6b0;
  border: 1px solid #8b7a5a;
  color: #3a3530;
  cursor: pointer;
}
.stage-nav .btn-icon:hover { background: #d4c8a0; }
.stage-nav .page-indicator {
  font-size: 14px;
  color: #3a3530;
  min-width: 110px;
  text-align: center;
  letter-spacing: 2px;
  user-select: none;
}

.stage-body {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* === Spread 容器（canvas 挂载点，纸张色纯装饰，PDF 页内含纸色） === */
#spreadRoot {
  position: relative;
  overflow: hidden;
  user-select: none;
  box-shadow: 0 2px 20px rgba(0,0,0,0.15), 0 1px 4px rgba(0,0,0,0.1);
  background-color: #efe3c4;
}
#spreadRoot:empty {
  box-shadow: none;
  background: transparent;
}

.spread-canvas {
  display: block;
  transition: opacity 0.3s ease, transform 0.3s ease;
}
.spread-canvas.transitioning {
  opacity: 0.5;
  transform: scale(0.98);
}

/* === 导入面板（浮层） === */
.input-panel {
  display: none;
  position: fixed;
  top: 48px;
  left: 50%;
  transform: translateX(-50%);
  width: 862px;
  max-width: 92vw;
  background: #ede3c8;
  border: 1px solid #8b7a5a;
  box-shadow: 0 6px 30px rgba(0,0,0,0.25);
  padding: 16px;
  flex-direction: column;
  gap: 10px;
  z-index: 60;
}
.input-panel.open { display: flex; }
.input-panel .input-row {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}
.input-panel .input-row label {
  font-size: 12px;
  color: #4a4638;
  letter-spacing: 1px;
}
.input-panel .input-row input {
  width: 160px;
  padding: 5px 8px;
  font-family: inherit;
  font-size: 13px;
  background: #f5f0dd;
  border: 1px solid #8b7a5a;
  color: #2c291e;
}
.input-panel textarea {
  width: 100%;
  height: 110px;
  font-family: inherit;
  font-size: 14px;
  background: #f5f0dd;
  border: 1px solid #8b7a5a;
  padding: 10px;
  color: #2c291e;
  resize: vertical;
}
.input-panel .input-row button {
  padding: 7px 16px;
  font-family: inherit;
  font-size: 13px;
  background: #5a4830;
  border: 1px solid #3a3530;
  color: #f4ecda;
  cursor: pointer;
  letter-spacing: 1px;
}
.input-panel .input-row button:hover { background: #4a3820; }
.input-panel .input-row button.btn-cancel {
  background: transparent;
  border-color: #8b7a5a;
  color: #5a4830;
}
.input-panel .input-row button.btn-cancel:hover { background: rgba(139,122,90,0.12); }
.input-panel .input-hint {
  font-size: 10px;
  color: #8b7a5a;
  letter-spacing: 1px;
}

/* === 错误提示（浮层） === */
.error-box {
  position: fixed;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  max-width: 80vw;
  padding: 16px 24px;
  background: #f4ecda;
  border: 1px solid #8b2020;
  color: #8b2020;
  font-family: serif;
  font-size: 14px;
  text-align: center;
  z-index: 90;
  box-shadow: 0 4px 16px rgba(0,0,0,0.2);
}

/* === 生成中遮罩 === */
.loading-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(184,168,138,0.55);
  color: #3a3530;
  font-size: 18px;
  letter-spacing: 4px;
  z-index: 100;
  pointer-events: none;
}

/* === 窄屏：侧栏变左侧抽屉，书页占满全屏 === */
@media (max-width: 760px) {
  body { overflow: hidden; }
  .app { height: 100vh; height: 100dvh; }

  /* 抽屉开关：悬浮左上，层级高于抽屉保证始终可点（再点收起） */
  .btn-menu {
    display: block;
    position: fixed;
    top: 8px;
    left: 8px;
    z-index: 90;
    width: 34px;
    height: 34px;
    padding: 0;
    font-family: inherit;
    font-size: 15px;
    background: #e5d6b0;
    border: 1px solid #8b7a5a;
    color: #5a4830;
    cursor: pointer;
    box-shadow: 0 1px 4px rgba(0,0,0,0.2);
  }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: min(78vw, 320px);
    padding-top: 48px;          /* 顶部给 btn-menu 让位 */
    transform: translateX(-105%);
    transition: transform 0.25s ease;
    z-index: 80;
  }
  .sidebar.open { transform: translateX(0); }

  .drawer-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(42,36,26,0.4);
    z-index: 75;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease;
  }
  .drawer-backdrop.open { opacity: 1; pointer-events: auto; }

  .stage { height: 100%; min-height: 0; }
  .stage-nav { padding-left: 44px; }  /* 避开 btn-menu */
}
