:root {
  --bg: #f4f1ea;
  --paper: #fffdf8;
  --ink: #1d1b16;
  --muted: #6f6a5f;
  --line: #e2ddd0;
  --accent: #b4441f;
  --accent-ink: #fff;
  --accent-soft: #f6e2d8;
  --warn: #9a6400;
  --warn-soft: #fbeccb;
  --ok-soft: #e3eedc;
  --danger: #b3261e;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(40, 30, 10, .06), 0 4px 16px rgba(40, 30, 10, .06);
  --safe-b: env(safe-area-inset-bottom, 0px);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
  color: var(--ink);
  background: var(--bg);
  -webkit-text-size-adjust: 100%;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17150f; --paper: #221f18; --ink: #f1ece0; --muted: #a39d8f; --line: #36322a;
    --accent: #e0754d; --accent-ink: #1b120d; --accent-soft: #3a2519;
    --warn: #e9b44c; --warn-soft: #3a2f16; --ok-soft: #22301d; --danger: #f2867d;
    --shadow: 0 1px 2px rgba(0,0,0,.4);
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--bg); }
body { overscroll-behavior-y: none; }
[hidden] { display: none !important; }
button, input, a.btn { font: inherit; color: inherit; }
button { cursor: pointer; }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.view { min-height: 100dvh; }
#view-main, #view-preview { -webkit-user-select: none; user-select: none; }
#view-main input { -webkit-user-select: text; user-select: text; }

/* ---------- 通用组件 ---------- */
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; letter-spacing: .02em; font-size: 17px; }
.brand-mark { width: 30px; height: 30px; border-radius: 9px; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; font-size: 16px; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 46px; padding: 0 16px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--paper); text-decoration: none; font-size: 16px; white-space: nowrap;
  -webkit-tap-highlight-color: transparent; touch-action: manipulation;
}
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn.danger { color: var(--danger); }
.btn.ghost { background: transparent; }
.btn.block { width: 100%; }
.btn[disabled], .btn.disabled { opacity: .45; pointer-events: none; }
.icon-btn { width: 44px; height: 44px; border: 0; background: transparent; display: grid; place-items: center; border-radius: 12px; color: var(--ink); }
.icon-btn:active { background: var(--line); }
.icon-btn-spacer { width: 44px; }
.link { border: 0; background: none; padding: 0; color: var(--accent); font-weight: 600; text-decoration: underline; }

label { display: block; font-size: 14px; color: var(--muted); margin-bottom: 14px; }
label input { display: block; width: 100%; margin-top: 6px; height: 48px; border-radius: 12px; border: 1px solid var(--line); background: var(--bg); padding: 0 14px; font-size: 17px; color: var(--ink); }
label input:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: transparent; }
.form-error { min-height: 20px; color: var(--danger); font-size: 14px; margin: 0 0 10px; }

/* ---------- 登录 ---------- */
#view-login { display: grid; place-items: center; padding: 24px 16px; }
.login-card { width: 100%; max-width: 380px; background: var(--paper); border-radius: 20px; padding: 28px 22px; box-shadow: var(--shadow); }
.login-card .brand { margin-bottom: 26px; font-size: 20px; }

/* ---------- 主界面 ---------- */
.topbar {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; justify-content: space-between;
  padding: max(10px, env(safe-area-inset-top)) 12px 10px 16px; background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
}
.topbar-title { font-weight: 600; }
.banner { margin: 0 16px 8px; padding: 10px 14px; border-radius: 12px; background: var(--warn-soft); color: var(--warn); font-size: 14px; }
.banner.info { background: var(--ok-soft); color: var(--ink); }
#list-wrap { padding: 4px 12px calc(96px + var(--safe-b)); max-width: 760px; margin: 0 auto; }

.empty { display: grid; place-items: center; min-height: 60dvh; }
.upload-hero {
  width: min(320px, 90%); aspect-ratio: 1 / 1.1; border: 2px dashed var(--line); border-radius: 24px; background: var(--paper);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; font-size: 20px; font-weight: 600;
}
.upload-hero .plus { width: 72px; height: 72px; border-radius: 50%; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; font-size: 40px; font-weight: 400; }
.upload-hero small { font-size: 13px; font-weight: 400; color: var(--muted); padding: 0 24px; text-align: center; line-height: 1.5; }

.summary { font-size: 13px; color: var(--muted); padding: 4px 6px 10px; }
.list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.row {
  display: grid; grid-template-columns: 34px 64px 1fr auto; align-items: center; gap: 10px;
  background: var(--paper); border-radius: var(--radius); padding: 8px 6px 8px 0; box-shadow: var(--shadow);
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
}
.row.piece { margin-left: 18px; }
.handle { height: 64px; display: flex; flex-direction: column; align-items: center; justify-content: center; color: var(--muted); touch-action: none; cursor: grab; }
.handle .num { font-size: 12px; font-variant-numeric: tabular-nums; margin-top: 2px; }
.handle svg { width: 18px; height: 18px; }
.thumb { border: 0; padding: 0; width: 64px; height: 64px; border-radius: 8px; background: var(--bg); display: grid; place-items: center; overflow: hidden; position: relative; }
.thumb img { max-width: 100%; max-height: 100%; display: block; pointer-events: none; }
.thumb .ori { position: absolute; right: 3px; bottom: 3px; font-size: 10px; padding: 1px 4px; border-radius: 4px; background: rgba(0,0,0,.55); color: #fff; }
.info { min-width: 0; }
.info .name { font-size: 15px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.info .meta { font-size: 12px; color: var(--muted); margin-top: 3px; display: flex; flex-wrap: wrap; gap: 4px; align-items: center; }
.tag { font-size: 11px; padding: 1px 6px; border-radius: 6px; background: var(--bg); color: var(--muted); }
.tag.warn { background: var(--warn-soft); color: var(--warn); }
.tag.split { background: var(--accent-soft); color: var(--accent); }
.tag.piece { background: var(--ok-soft); }
.acts { display: flex; }
.acts .icon-btn { width: 40px; height: 44px; color: var(--muted); }
.acts .icon-btn.del { color: var(--danger); }

.row.dragging { position: fixed; z-index: 50; pointer-events: none; box-shadow: 0 12px 32px rgba(0,0,0,.22); transform: scale(1.02); opacity: .96; }
.placeholder { border: 2px dashed var(--accent); border-radius: var(--radius); background: var(--accent-soft); }

.bottombar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 8px;
  padding: 10px 12px calc(10px + var(--safe-b)); background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); border-top: 1px solid var(--line);
}
.bottombar .btn { min-height: 50px; }
.bottombar .btn.primary { grid-column: span 2; }
@media (min-width: 760px) { .bottombar { padding-left: calc(50vw - 370px); padding-right: calc(50vw - 370px); } }

/* ---------- 预览 ---------- */
.pages { padding: 8px 16px calc(96px + var(--safe-b)); display: flex; flex-direction: column; align-items: center; gap: 18px; }
.page-wrap { width: 100%; max-width: 520px; display: flex; flex-direction: column; align-items: center; gap: 6px; }
.page { position: relative; background: #fff; box-shadow: 0 2px 10px rgba(0,0,0,.15); width: 100%; }
.page.L { width: 100%; }
.page.P { width: 72%; }
.page img { position: absolute; display: block; }
.page .margin-guide { position: absolute; border: 1px dashed rgba(180, 68, 31, .25); pointer-events: none; }
.page-cap { font-size: 12px; color: var(--muted); }
@media (min-width: 900px) {
  .pages { flex-direction: row; flex-wrap: wrap; justify-content: center; align-items: flex-start; }
  .page-wrap { width: 260px; }
}

/* ---------- 底部弹层 ---------- */
.sheet { position: fixed; inset: 0; z-index: 30; background: rgba(20, 15, 5, .38); display: flex; align-items: flex-end; justify-content: center; }
.sheet-panel {
  width: 100%; max-width: 560px; max-height: 92dvh; overflow: auto; background: var(--paper); border-radius: 22px 22px 0 0;
  padding: 8px 18px calc(20px + var(--safe-b)); animation: up .18s ease-out;
}
@keyframes up { from { transform: translateY(30px); opacity: .6; } }
@media (min-width: 760px) { .sheet { align-items: center; } .sheet-panel { border-radius: 22px; } }
.sheet-handle { width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 4px auto 10px; }
.detail-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; margin-bottom: 12px; }
.detail-title { font-size: 17px; font-weight: 600; word-break: break-all; }
.detail-meta { font-size: 13px; color: var(--muted); margin-top: 4px; }
.detail-img { background: var(--bg); border-radius: 12px; display: grid; place-items: center; height: 38dvh; overflow: hidden; margin-bottom: 12px; }
.detail-img img { max-width: 100%; max-height: 100%; }
.detail-row { display: flex; gap: 8px; margin-bottom: 10px; flex-wrap: wrap; }
.detail-row .btn { flex: 1; }
.split-box { border-top: 1px solid var(--line); padding-top: 12px; margin-top: 4px; }
.split-title { font-size: 14px; font-weight: 600; margin-bottom: 8px; }
.stepper { display: flex; align-items: center; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; flex: 0 0 auto !important; }
.stepper .btn { border: 0; border-radius: 0; min-width: 44px; padding: 0; }
.stepper span { min-width: 26px; text-align: center; font-variant-numeric: tabular-nums; font-weight: 600; }
.hint { font-size: 13px; color: var(--muted); margin: 6px 0 0; line-height: 1.5; }

.setting { padding: 12px 0; border-bottom: 1px solid var(--line); }
.setting-label { font-size: 14px; color: var(--muted); margin-bottom: 8px; }
.setting-value { font-size: 15px; }
.seg { display: flex; background: var(--bg); border-radius: 12px; padding: 3px; gap: 3px; }
.seg button { flex: 1; min-height: 40px; border: 0; border-radius: 9px; background: transparent; font-size: 15px; }
.seg button.on { background: var(--paper); box-shadow: var(--shadow); font-weight: 600; }
.settings-actions { display: flex; flex-direction: column; gap: 8px; margin-top: 16px; }

/* ---------- 等待与提示 ---------- */
.busy { position: fixed; inset: 0; z-index: 60; background: rgba(20, 15, 5, .3); display: grid; place-items: center; }
.busy-card { background: var(--paper); border-radius: 16px; padding: 22px 26px; min-width: 220px; text-align: center; box-shadow: var(--shadow); }
.spinner { width: 34px; height: 34px; margin: 0 auto 12px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--accent); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.progress { height: 6px; border-radius: 3px; background: var(--line); margin-top: 12px; overflow: hidden; }
.progress i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .2s; }
.toast {
  position: fixed; left: 50%; bottom: calc(86px + var(--safe-b)); transform: translateX(-50%); z-index: 70;
  max-width: calc(100% - 32px); background: var(--ink); color: var(--bg); padding: 11px 16px; border-radius: 12px; font-size: 14px; line-height: 1.5;
  white-space: pre-line;
}
