:root {
  --red: #B8322A;
  --blue: #2450D6;
  --blue-soft: #E9EEFC;
  --blue-line: #C9D5F5;
  --ink: #15171C;
  --ink-2: #3B404B;
  --muted: #5B616E;
  --line: #E4E6EB;
  --input-line: #C9CDD5;
  --danger: #B42318;
  --danger-line: #F2B8B5;
  --surface: #F5F6F8;
  --sans: 'Noto Sans SC', system-ui, -apple-system, 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', sans-serif;
  --serif: 'Noto Serif SC', 'Songti SC', 'STSong', 'SimSun', serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  min-height: 100vh;
  background: #FFFFFF;
  color: var(--ink);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.6;
  -webkit-text-size-adjust: 100%;
}
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }

/* ---------- header ---------- */
.topbar {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between;
  gap: 8px 16px; padding: 10px 20px; border-bottom: 1px solid var(--line);
}
.brand {
  display: flex; align-items: center; gap: 10px; min-height: 44px; padding: 0;
  border: 0; background: none; color: var(--ink); text-decoration: none;
}
.brand img { width: 34px; height: 37px; object-fit: contain; display: block; }
.brand span { font-size: 17px; font-weight: 700; }
.nav { display: flex; flex-wrap: wrap; gap: 6px; }
.nav-tab {
  min-height: 40px; padding: 0 16px; border-radius: 20px; border: 1px solid var(--line);
  background: #FFFFFF; color: var(--ink-2); font-size: 14px; font-weight: 500;
}
.nav-tab[aria-current="page"] { background: var(--blue); border-color: var(--blue); color: #FFFFFF; }
.link-btn {
  min-height: 40px; padding: 0 10px; border: 0; background: none; color: var(--muted);
  font-size: 14px; text-decoration: underline;
}

/* ---------- buttons & fields ---------- */
.btn-primary {
  min-height: 48px; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border-radius: 10px; border: 0; background: var(--red); color: #FFFFFF; font-weight: 500;
}
.btn-primary:disabled { opacity: .6; cursor: default; }
.btn-outline {
  min-height: 48px; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border-radius: 10px; border: 1px solid var(--blue); background: #FFFFFF; color: var(--blue); font-weight: 500;
}
.btn-plain {
  min-height: 48px; border-radius: 10px; border: 1px solid var(--input-line); background: #FFFFFF;
  color: var(--ink); font-weight: 500;
}
.btn-danger { min-height: 48px; border-radius: 10px; border: 0; background: var(--danger); color: #FFFFFF; font-weight: 500; }
.text-btn {
  min-height: 44px; padding: 0 12px; border: 0; background: none; color: var(--ink-2);
  font-size: 14px; text-decoration: underline;
}
.btn-row { width: 100%; display: flex; gap: 10px; }
.btn-row > * { flex: 1 1 0; min-width: 0; }

.field-label { font-size: 13px; color: var(--muted); margin-bottom: -10px; }
.input {
  width: 100%; min-height: 44px; padding: 0 12px; border: 1px solid var(--input-line);
  border-radius: 8px; color: var(--ink); background: #FFFFFF;
}
textarea.input { padding: 10px 12px; resize: vertical; min-height: 0; }
.input.has-error { border-color: var(--danger); }
.check { display: flex; align-items: center; gap: 10px; min-height: 44px; cursor: pointer; }
.check input { width: 20px; height: 20px; margin: 0; accent-color: var(--blue); }
.hint { font-size: 12px; color: var(--muted); }

/* ---------- login ---------- */
.login-wrap {
  min-height: calc(100vh - 66px); padding: 56px 20px; display: flex; align-items: flex-start;
  justify-content: center; background: var(--surface);
}
.login-card {
  width: 100%; max-width: 380px; padding: 28px 24px; border-radius: 16px; background: #FFFFFF;
  box-shadow: 0 8px 24px rgba(21,23,28,0.06); display: flex; flex-direction: column; gap: 14px;
}
.login-head { display: flex; flex-direction: column; align-items: center; gap: 8px; text-align: center; }
.login-head img { width: 52px; height: 56px; object-fit: contain; display: block; }
.login-head h1 { margin: 0; font-size: 22px; }
.login-head span { font-size: 14px; color: var(--muted); }
.login-card .input { min-height: 48px; }
.login-card .check { min-height: 40px; font-size: 14px; color: var(--ink-2); }
.login-card .check input { width: 18px; height: 18px; }
.form-error { margin-top: -6px; font-size: 13px; color: var(--danger); }

/* ---------- page shells ---------- */
.page { margin: 0 auto; padding: 32px 20px 56px; display: flex; flex-direction: column; gap: 20px; }
.page-upload { max-width: 720px; padding-top: 40px; }
.page-edit { max-width: 1080px; gap: 24px; }
.page-docs { max-width: 880px; gap: 16px; }
.page h1 { margin: 0; font-size: 26px; line-height: 1.35; }
.page-upload h1 { font-family: var(--serif); font-size: 28px; }
.h1-sub { font-size: 15px; font-weight: 500; color: var(--muted); }

/* ---------- upload ---------- */
.drop {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px;
  padding: 48px 20px; border: 2px dashed var(--input-line); border-radius: 16px; background: #FAFBFC;
  text-align: center; cursor: pointer;
}
.drop.dragging { border-color: var(--blue); background: var(--blue-soft); }
.drop-icon { width: 56px; height: 56px; border-radius: 28px; background: var(--blue-soft); display: flex; align-items: center; justify-content: center; }
.drop-title { font-size: 18px; font-weight: 700; }
.drop-sub { font-size: 14px; color: var(--muted); }
.drop-btn {
  margin-top: 4px; display: inline-flex; align-items: center; min-height: 44px; padding: 0 24px;
  border-radius: 10px; background: var(--red); color: #FFFFFF; font-weight: 500;
}
.file-input { position: absolute; width: 1px; height: 1px; opacity: 0; overflow: hidden; }
.progress-card { padding: 24px; border: 1px solid var(--line); border-radius: 16px; display: flex; flex-direction: column; gap: 12px; }
.progress-name { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar { height: 8px; border-radius: 4px; background: var(--blue-soft); overflow: hidden; }
.bar > div { height: 100%; width: 0; background: var(--blue); border-radius: 4px; transition: width .25s; }
.progress-text { font-size: 14px; color: var(--muted); }

/* ---------- edit ---------- */
.edit-grid { display: flex; flex-wrap: wrap; gap: 32px; align-items: flex-start; }
.edit-col { flex: 1 1 340px; min-width: 0; display: flex; flex-direction: column; gap: 20px; }
.card { padding: 20px; border: 1px solid var(--line); border-radius: 12px; display: flex; flex-direction: column; gap: 14px; }
.card h2 { margin: 0; font-size: 16px; }
.tpl-list { display: flex; flex-wrap: wrap; gap: 12px; }
.tpl {
  display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 8px; border-radius: 12px;
  border: 2px solid transparent; background: #FFFFFF; font-size: 13px; color: var(--ink);
}
.tpl[aria-pressed="true"] { border-color: var(--blue); }
.tpl-swatch {
  position: relative; overflow: hidden; width: 64px; height: 96px; border: 1px solid var(--line);
  display: flex; flex-direction: column; justify-content: flex-end; gap: 5px; padding: 8px;
}
.tpl-swatch i { position: relative; display: block; }
.tpl-swatch .moon { position: absolute; top: 12px; right: -14px; width: 40px; height: 40px; border-radius: 50%; }

.preview-col {
  flex: 1 1 340px; min-width: 0; display: flex; flex-direction: column; align-items: center; gap: 14px;
  padding: 24px 16px; border-radius: 16px; background: var(--surface);
}
.poster-canvas {
  display: block; width: 300px; max-width: 100%; aspect-ratio: 9 / 16; height: auto; background: var(--line);
  box-shadow: 0 18px 40px rgba(21,23,28,0.18);
}
.preview-col .btn-primary, .preview-col .btn-row { width: 100%; max-width: 360px; }
.preview-col .btn-row { margin-top: -4px; }
.share-link { max-width: 360px; font-size: 12px; color: var(--muted); text-align: center; word-break: break-all; }

/* ---------- docs ---------- */
.empty { padding: 32px; border-radius: 12px; background: var(--surface); text-align: center; color: var(--muted); }
.doc { display: flex; flex-direction: column; gap: 12px; padding: 14px 16px; border: 1px solid var(--line); border-radius: 12px; }
.doc-row { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; }
.doc-info { flex: 1 1 240px; min-width: 0; display: flex; flex-direction: column; }
.doc-title { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.doc-seq { color: var(--muted); font-variant-numeric: tabular-nums; }
.doc-meta { font-size: 13px; color: var(--muted); }
.doc-meta .bad { color: var(--danger); }
.doc-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.doc-actions button {
  min-height: 40px; padding: 0 14px; border-radius: 8px; border: 1px solid var(--line);
  background: #FFFFFF; color: var(--ink); font-size: 14px;
}
.doc-actions .act-geo { border-color: var(--blue-line); color: var(--blue); font-weight: 500; }
.doc-actions .act-geo[aria-expanded="true"] { border-color: var(--blue); background: var(--blue-soft); }
.doc-actions .act-edit { border-color: var(--blue-line); color: var(--blue); }
.doc-actions .act-del { border-color: var(--danger-line); color: var(--danger); }

.geo { display: flex; flex-direction: column; gap: 6px; padding-top: 12px; border-top: 1px solid var(--line); }
.geo-head { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 4px 12px; font-size: 13px; color: var(--muted); }
.geo-empty { padding: 12px; border-radius: 8px; background: var(--surface); font-size: 13px; color: var(--muted); }
.map { position: relative; width: 100%; aspect-ratio: 1000 / 394; border-radius: 10px; overflow: hidden; background: #F7F9FC; }
.map svg { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.map .dot {
  position: absolute; transform: translate(-50%, -50%); border-radius: 50%;
  background: rgba(184, 50, 42, .8); border: 1.5px solid #FFFFFF;
}
.map .dot.dim { background: rgba(184, 50, 42, .25); }
.map-tip {
  position: absolute; z-index: 2; pointer-events: none; padding: 4px 8px; border-radius: 6px;
  background: var(--ink); color: #FFFFFF; font-size: 12px; white-space: nowrap; transform: translate(-50%, calc(-100% - 10px));
}
.legend { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 18px; font-size: 12px; color: var(--muted); }
.legend > span { display: inline-flex; align-items: center; gap: 6px; }
.legend .steps { display: inline-flex; }
.legend .steps i { width: 16px; height: 10px; display: block; }
.legend .city-dot { width: 10px; height: 10px; border-radius: 50%; background: rgba(184, 50, 42, .8); }

.geo-row {
  display: grid; grid-template-columns: minmax(96px, 150px) minmax(0, 1fr) 52px 8px 40px;
  align-items: center; column-gap: 8px; width: 100%; min-height: 36px; padding: 0 4px;
  font-size: 13px; color: var(--ink); text-align: left; border: 0; border-radius: 6px; background: transparent;
}
button.geo-row[aria-expanded="true"] { background: #F3F6FE; }
.geo-name { display: flex; align-items: center; gap: 4px; min-width: 0; }
.geo-name svg { flex-shrink: 0; transition: transform .15s; }
button.geo-row[aria-expanded="true"] .geo-name svg { transform: rotate(90deg); }
.geo-name .spacer { width: 14px; flex-shrink: 0; }
.geo-name b { font-weight: inherit; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lv0 .geo-name { font-weight: 700; }
.lv1 .geo-name { padding-left: 18px; font-weight: 500; }
.lv2 .geo-name { padding-left: 36px; font-weight: 400; }
.geo-bar { height: 10px; border-radius: 4px; background: #EEF0F3; overflow: hidden; }
.geo-bar i { display: block; height: 100%; border-radius: 0 4px 4px 0; }
.geo-count { text-align: right; font-variant-numeric: tabular-nums; }
.geo-dot { text-align: center; color: #A3A8B3; }
.geo-pct { font-variant-numeric: tabular-nums; color: var(--muted); }

/* ---------- modals & toast ---------- */
.overlay {
  position: fixed; inset: 0; background: rgba(21,23,28,0.55); display: flex; align-items: center;
  justify-content: center; padding: 16px; z-index: 20;
}
.dialog {
  width: 100%; max-width: 360px; max-height: 100%; overflow-y: auto; border-radius: 16px; background: #FFFFFF;
  padding: 20px; display: flex; flex-direction: column; gap: 12px;
}
.dialog h2 { margin: 0; font-size: 17px; }
.dialog-head { width: 100%; display: flex; align-items: center; justify-content: space-between; }
.close-btn {
  width: 44px; height: 44px; margin-right: -10px; display: flex; align-items: center; justify-content: center;
  border: 0; background: none; color: var(--ink-2);
}
.dialog-qr { max-width: 320px; padding: 16px 20px 20px; align-items: center; }
.qr-box { padding: 14px; border-radius: 12px; border: 1px solid var(--line); }
.qr-box img { width: 200px; height: 200px; display: block; image-rendering: pixelated; }
.dialog-poster { max-width: 340px; padding: 16px; background: var(--surface); align-items: center; }
.dialog-poster .poster-canvas, .dialog-poster .poster-img { width: 100%; max-width: 236px; box-shadow: 0 8px 24px rgba(21,23,28,0.15); }
.dialog-poster .btn-primary { width: 100%; }
.poster-img { display: block; width: 100%; height: auto; }
.dialog-save { max-width: 380px; align-items: center; text-align: center; }
.dialog-save img { width: 100%; max-width: 280px; display: block; box-shadow: 0 8px 24px rgba(21,23,28,0.15); -webkit-touch-callout: default; }

.toast {
  position: fixed; left: 50%; bottom: 32px; transform: translateX(-50%); z-index: 40;
  width: max-content; max-width: calc(100% - 32px); padding: 10px 18px; border-radius: 22px;
  background: var(--ink); color: #FFFFFF; font-size: 14px; text-align: center;
}

/* ---------- reader ---------- */
.reader-bar {
  display: flex; align-items: center; gap: 8px; padding: 8px 16px; border-bottom: 1px solid var(--line);
  font-size: 14px; font-weight: 700; color: var(--ink-2); background: #FFFFFF;
}
.reader-bar img { width: 26px; height: 28px; object-fit: contain; display: block; }
.reader-bg { background: #EEF0F3; min-height: 100vh; }
.article { max-width: 760px; margin: 0 auto; padding: 0 12px 48px; display: flex; flex-direction: column; gap: 16px; }
.article-head { padding: 4px 8px; display: flex; flex-direction: column; gap: 6px; }
.article-head h1 { margin: 0; font-family: var(--serif); font-size: 24px; line-height: 1.4; }
.article-meta { font-size: 14px; color: var(--muted); }
.article-summary { margin: 0; color: var(--ink-2); font-size: 14px; line-height: 1.7; white-space: pre-line; }
.pg { margin: 0; display: flex; flex-direction: column; gap: 6px; }
.pg-frame { background: #FFFFFF; box-shadow: 0 2px 10px rgba(21,23,28,0.08); }
.pg-frame img { display: block; width: 100%; height: auto; }
.pg figcaption { text-align: center; font-size: 12px; color: var(--muted); }
.dl-card { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; padding: 14px 16px; border-radius: 12px; background: #FFFFFF; }
.dl-card .info { flex: 1 1 160px; min-width: 0; display: flex; flex-direction: column; }
.dl-card .name { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dl-card .sub { font-size: 13px; color: var(--muted); }
.dl-card a {
  min-height: 44px; padding: 0 16px; display: inline-flex; align-items: center; border-radius: 8px;
  border: 1px solid var(--input-line); background: #FFFFFF; color: var(--ink); font-size: 14px; text-decoration: none;
}
.foot { text-align: center; font-size: 12px; color: var(--muted); }
.notfound { max-width: 420px; margin: 80px auto; padding: 0 20px; text-align: center; display: flex; flex-direction: column; gap: 10px; }
.notfound h1 { margin: 0; font-size: 22px; }
.notfound p { margin: 0; color: var(--muted); }

/* ---------- account ---------- */
.page-account { max-width: 560px; }
.page-account .card h2 { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.page-account .card .btn-primary, .page-account .card .btn-outline { align-self: flex-start; padding: 0 24px; }
.code-input { font-family: ui-monospace, Menlo, Consolas, monospace; letter-spacing: 1px; text-transform: uppercase; }
code { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 12px; }
.inline-row { display: flex; gap: 8px; }
.inline-row .input { flex: 1 1 auto; min-width: 0; }
.send-btn { min-height: 44px; flex: 0 0 auto; padding: 0 14px; font-size: 14px; white-space: nowrap; }
.send-btn:disabled { opacity: .55; cursor: default; }
#step2[hidden] { display: none !important; }
.char-count { margin-top: -8px; align-self: flex-end; font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.char-count.full { color: var(--danger); }
.publish-bar {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px;
  padding: 16px 20px; border: 1px solid var(--line); border-radius: 12px; background: #FFFFFF;
}
.publish-state { font-size: 14px; color: var(--muted); }
.publish-state.dirty { color: var(--danger); font-weight: 500; }
.publish-bar .btn-primary { padding: 0 36px; }
.publish-bar .btn-primary:disabled { background: #C9CDD5; opacity: 1; }
.open-in-browser { font-size: 15px; color: var(--ink-2); }
.open-in-browser p { margin: 0 0 6px; }
.open-in-browser ol { margin: 0; padding-left: 22px; line-height: 2; }
