:root {
  --ink: #1d1b18;
  --ink-2: #57524b;
  --ink-3: #8b857c;
  --line: #e3ddd2;
  --line-2: #d3ccbe;
  --paper: #ffffff;
  --bg: #f7f4ef;
  --bg-2: #efeae1;
  --red: #b0352c;
  --red-dark: #94281f;
  --gold: #b08b45;
  --radius: 14px;
  --shadow-sm: 0 1px 2px rgba(29, 27, 24, .06), 0 1px 1px rgba(29, 27, 24, .04);
  --shadow-md: 0 8px 24px -12px rgba(29, 27, 24, .28), 0 2px 6px rgba(29, 27, 24, .05);
  --shadow-page: 0 1px 1px rgba(29, 27, 24, .05), 0 12px 32px -16px rgba(29, 27, 24, .35);
  --font: "Source Han Sans CN", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  color: var(--ink);
  background:
    radial-gradient(1200px 600px at 80% -10%, #fdfbf7 0%, transparent 60%),
    var(--bg);
  -webkit-font-smoothing: antialiased;
  font-size: 14px;
  overflow: hidden;
}

button { font-family: inherit; cursor: pointer; }

/* ---------- 顶栏 ---------- */
.topbar {
  height: 62px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 20px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, .82);
  backdrop-filter: blur(10px);
  position: relative;
  z-index: 20;
}

.brand { display: flex; align-items: center; gap: 11px; min-width: 0; }

.logo {
  width: 34px; height: 34px;
  display: grid; place-items: center;
  border-radius: 9px;
  background: var(--red);
  color: #fff;
  box-shadow: 0 2px 8px -2px rgba(176, 53, 44, .5);
  flex: none;
}
.logo svg { width: 26px; height: 26px; }

.brand-text h1 {
  font-size: 16px;
  font-weight: 600;
  letter-spacing: .3px;
  margin: 0;
  line-height: 1.25;
}
.brand-text p {
  margin: 1px 0 0;
  font-size: 11.5px;
  color: var(--ink-3);
  letter-spacing: .2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-actions { display: flex; gap: 8px; flex: none; }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 34px;
  padding: 0 14px;
  border-radius: 9px;
  border: 1px solid var(--line-2);
  background: #fff;
  color: var(--ink);
  font-size: 13px;
  font-weight: 500;
  transition: .16s ease;
  box-shadow: var(--shadow-sm);
}
.btn:hover { border-color: #bdb5a6; transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn .ico { width: 16px; height: 16px; }

.btn.primary {
  background: var(--red);
  border-color: var(--red);
  color: #fff;
  box-shadow: 0 4px 14px -6px rgba(176, 53, 44, .75);
}
.btn.primary:hover { background: var(--red-dark); border-color: var(--red-dark); }

.btn.ghost { background: #fff; }
.btn.small { height: 30px; padding: 0 11px; font-size: 12.5px; border-radius: 8px; }
.btn:disabled { opacity: .45; cursor: not-allowed; transform: none !important; }

/* ---------- 三栏布局 ---------- */
.layout {
  display: grid;
  grid-template-columns: 316px minmax(0, 1fr);
  height: calc(100vh - 62px);
}
.layout.with-thumbs { grid-template-columns: 316px minmax(0, 1fr) 232px; }

/* ---------- 左侧设置 ---------- */
.panel {
  border-right: 1px solid var(--line);
  background: linear-gradient(180deg, #fffdfa 0%, #fbf8f3 100%);
  overflow-y: auto;
  padding: 16px 16px 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.drop {
  border: 1.5px dashed #cfc6b6;
  border-radius: var(--radius);
  background: #fff;
  padding: 18px 14px 14px;
  text-align: center;
  transition: .18s ease;
}
.drop.dragging {
  border-color: var(--red);
  background: #fdf5f4;
  box-shadow: inset 0 0 0 3px rgba(176, 53, 44, .07);
}
.drop-ico {
  color: #b9ae9c;
  margin-bottom: 4px;
}
.drop-ico svg { width: 42px; height: 42px; }
.drop.dragging .drop-ico { color: var(--red); }
.drop strong { display: block; font-size: 13.5px; font-weight: 600; }
.drop span {
  display: block;
  font-size: 11.5px;
  color: var(--ink-3);
  margin-top: 3px;
  line-height: 1.5;
}
.drop-actions { display: flex; gap: 7px; justify-content: center; margin-top: 11px; }

.group {
  padding: 15px 2px 5px;
  border-top: 1px solid var(--line);
  margin-top: 12px;
}
.group h2 {
  font-size: 11px;
  font-weight: 600;
  color: var(--ink-3);
  letter-spacing: 1.4px;
  text-transform: uppercase;
  margin: 0 0 10px;
}

.field { margin-bottom: 12px; }
.field > label {
  display: block;
  font-size: 12.5px;
  color: var(--ink-2);
  margin-bottom: 6px;
}

.seg {
  display: flex;
  gap: 2px;
  padding: 3px;
  background: #f1ece3;
  border-radius: 9px;
}
.seg button {
  flex: 1;
  min-width: 0;
  height: 27px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--ink-2);
  font-size: 12.5px;
  font-weight: 500;
  transition: .14s ease;
  white-space: nowrap;
  padding: 0 4px;
}
.seg button:hover { color: var(--ink); background: rgba(255, 255, 255, .6); }
.seg button.active {
  background: #fff;
  color: var(--ink);
  box-shadow: var(--shadow-sm);
  font-weight: 600;
}
.seg.wide { flex-wrap: wrap; }
.seg.wide button { flex: 1 0 30%; }

.switch {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 5px 0;
  cursor: pointer;
  user-select: none;
}
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch .track {
  width: 34px; height: 20px;
  border-radius: 999px;
  background: #ddd5c7;
  position: relative;
  flex: none;
  transition: .18s ease;
}
.switch .knob {
  position: absolute;
  top: 2px; left: 2px;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .22);
  transition: .18s cubic-bezier(.4, 1.4, .6, 1);
}
.switch input:checked + .track { background: var(--red); }
.switch input:checked + .track .knob { transform: translateX(14px); }
.switch-label { font-size: 12.5px; color: var(--ink-2); line-height: 1.35; }

.panel-foot {
  margin: auto -16px 0;
  padding: 12px 16px 16px;
  font-size: 11px;
  color: var(--ink-3);
  line-height: 1.6;
  border-top: 1px solid var(--line);
  background: #fbf8f3;
}

/* ---------- 中间预览 ---------- */
.stage {
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
  background:
    radial-gradient(700px 400px at 50% 0%, #fffdf9 0%, transparent 70%);
}

.stage-head {
  height: 44px;
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 22px;
  font-size: 12px;
  color: var(--ink-3);
  border-bottom: 1px solid var(--line);
}
.stat { display: flex; align-items: center; gap: 7px; }
.stat i { font-style: normal; color: #ccc4b6; }
.stat #statPhotos { color: var(--ink); font-weight: 600; }
.stage-tools { display: flex; gap: 14px; }

.link {
  background: none;
  border: 0;
  padding: 0;
  font-size: 12px;
  color: var(--ink-3);
  transition: .15s;
}
.link:hover { color: var(--red); }

.pages-wrap {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 24px 22px 60px;
}

.pages {
  --pw: 210mm;
  --ph: 297mm;
  --cols: 2;
  --rows: 2;
  --gap: 8mm;
  --pad: 15mm;
  --scale: .6;
  --capfs: 9pt;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 22px;
}

.page-slot {
  width: calc(var(--pw) * var(--scale));
  height: calc(var(--ph) * var(--scale));
  position: relative;
  flex: none;
}

.page {
  width: var(--pw);
  height: var(--ph);
  padding: var(--pad);
  background: var(--paper);
  transform: scale(var(--scale));
  transform-origin: top left;
  box-shadow: var(--shadow-page);
  border-radius: 2px;
  display: grid;
  grid-template-columns: repeat(var(--cols), minmax(0, 1fr));
  grid-template-rows: repeat(var(--rows), minmax(0, 1fr));
  gap: var(--gap);
  overflow: hidden;
}

.cell {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}
.ph {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.ph img {
  max-width: 100%;
  max-height: 100%;
  display: block;
  object-fit: contain;
  -webkit-user-drag: none;
}
.cell.cover .ph { display: block; }
.cell.cover .ph img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.cap {
  flex: none;
  height: calc(var(--capfs) * 1.7);
  line-height: calc(var(--capfs) * 1.7);
  font-size: var(--capfs);
  color: #444;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-family: "Source Han Sans CN", "Microsoft YaHei", sans-serif;
}
.cap .num { color: var(--red); font-weight: 600; margin-right: .3em; }
.cell.nocap .ph { flex: 1; }

.page-tag {
  position: absolute;
  right: 0;
  top: -19px;
  font-size: 11px;
  color: var(--ink-3);
  letter-spacing: .4px;
}

/* ---------- 空状态 ---------- */
.empty {
  max-width: 340px;
  margin: 8vh auto 0;
  text-align: center;
  color: var(--ink-3);
}
.empty[hidden] { display: none; }
.empty-art { display: grid; place-items: center; margin-bottom: 22px; }
.sheet {
  width: 118px;
  height: 165px;
  background: #fff;
  border: 1px solid var(--line-2);
  border-radius: 4px;
  box-shadow: 0 10px 24px -14px rgba(29, 27, 24, .45);
  padding: 11px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr 1fr;
  gap: 7px;
  transform: rotate(-3deg);
}
.sheet .cell {
  background: linear-gradient(135deg, #f3ede2, #e8e0d1);
  border-radius: 2px;
}
.sheet .cell:nth-child(2) { background: linear-gradient(135deg, #f7e9e6, #eed8d3); }
.empty h3 {
  font-size: 15px;
  color: var(--ink);
  margin: 0 0 7px;
  font-weight: 600;
}
.empty p {
  font-size: 12.5px;
  line-height: 1.75;
  margin: 0 0 16px;
}

/* ---------- 右侧缩略图 ---------- */
.thumbs-panel {
  border-left: 1px solid var(--line);
  background: #fbf8f3;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.thumbs-panel[hidden] { display: none; }
.thumbs-head {
  height: 44px;
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 14px;
  border-bottom: 1px solid var(--line);
}
.thumbs-head h2 {
  margin: 0;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--ink-2);
}
.thumbs {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 9px;
  align-content: start;
}
.thumb {
  position: relative;
  border-radius: 8px;
  overflow: hidden;
  background: #fff;
  border: 1px solid var(--line);
  cursor: grab;
  transition: .15s;
}
.thumb:hover { border-color: #c8bfae; box-shadow: var(--shadow-sm); }
.thumb.dragging { opacity: .35; }
.thumb.drop-target { border-color: var(--red); box-shadow: 0 0 0 2px rgba(176, 53, 44, .18); }
.thumb .im {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  display: block;
  background: #f4efe6;
}
.thumb .nm {
  font-size: 10.5px;
  color: var(--ink-2);
  padding: 4px 5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.thumb .del {
  position: absolute;
  top: 4px; right: 4px;
  width: 19px; height: 19px;
  border-radius: 50%;
  border: 0;
  background: rgba(29, 27, 24, .62);
  color: #fff;
  font-size: 12px;
  line-height: 1;
  display: grid;
  place-items: center;
  opacity: 0;
  transition: .15s;
}
.thumb:hover .del { opacity: 1; }
.thumbs-tip {
  flex: none;
  margin: 0;
  padding: 9px 14px;
  font-size: 11px;
  color: var(--ink-3);
  border-top: 1px solid var(--line);
}

/* ---------- 提示 / 遮罩 ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 26px;
  transform: translate(-50%, 14px);
  background: rgba(29, 27, 24, .93);
  color: #fff;
  font-size: 13px;
  padding: 9px 16px;
  border-radius: 999px;
  opacity: 0;
  pointer-events: none;
  transition: .22s ease;
  z-index: 60;
  max-width: 80vw;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.busy {
  position: fixed;
  inset: 0;
  background: rgba(247, 244, 239, .78);
  backdrop-filter: blur(3px);
  display: grid;
  place-items: center;
  z-index: 70;
}
.busy[hidden] { display: none; }
.busy-card {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 22px 26px 20px;
  min-width: 260px;
  text-align: center;
  box-shadow: var(--shadow-md);
}
.spinner {
  width: 26px; height: 26px;
  margin: 0 auto 12px;
  border: 2.5px solid #ece5d9;
  border-top-color: var(--red);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.busy-card p { margin: 0 0 12px; font-size: 13px; color: var(--ink-2); }
.bar {
  height: 4px;
  border-radius: 999px;
  background: #f0ebe1;
  overflow: hidden;
}
.bar span {
  display: block;
  height: 100%;
  width: 0%;
  background: var(--red);
  border-radius: 999px;
  transition: width .2s ease;
}

/* ---------- 响应式 ---------- */
@media (max-width: 1120px) {
  .layout.with-thumbs { grid-template-columns: 300px minmax(0, 1fr); }
  .thumbs-panel {
    position: fixed;
    right: 0; top: 62px; bottom: 0;
    width: 232px;
    z-index: 30;
    box-shadow: -12px 0 30px -20px rgba(0, 0, 0, .4);
  }
}
@media (max-width: 860px) {
  body { overflow: auto; }
  .layout, .layout.with-thumbs {
    grid-template-columns: 1fr;
    height: auto;
  }
  .panel { border-right: 0; border-bottom: 1px solid var(--line); }
  .stage { min-height: 70vh; }
  .topbar { padding: 0 12px; }
  .brand-text p { display: none; }
}

/* ---------- 打印 / 存 PDF ---------- */
@media print {
  @page { size: A4 portrait; margin: 0; }

  html, body {
    overflow: visible !important;
    height: auto !important;
    background: #fff !important;
  }
  .topbar, .panel, .stage-head, .empty, .thumbs-panel, .toast, .busy, .page-tag { display: none !important; }
  .layout, .layout.with-thumbs { display: block !important; height: auto !important; }
  .stage { overflow: visible !important; background: #fff !important; }
  .pages-wrap { overflow: visible !important; padding: 0 !important; }
  .pages {
    --scale: 1 !important;
    gap: 0 !important;
    display: block !important;
  }
  .page-slot {
    width: auto !important;
    height: auto !important;
    break-after: page;
    page-break-after: always;
  }
  .page-slot:last-child { break-after: auto; page-break-after: auto; }
  .page {
    transform: none !important;
    box-shadow: none !important;
    border-radius: 0 !important;
    width: calc(var(--pw) - .6mm);
    height: calc(var(--ph) - .6mm);
    margin: 0 auto;
  }
}
