:root {
  --font-stack: "思源宋体 CN", "Source Han Serif CN", "Source Han Serif SC", "Noto Serif SC", "Songti SC", SimSun, "Apple Color Emoji", "Segoe UI Emoji", serif;
  --ui-font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", sans-serif;
  --blue: #0071e3;
  --line: #e4e5e7;
  --muted: #77797e;
  --surface: #ffffff;
  --workspace: #f4f4f2;
  --shadow: 0 16px 40px rgba(28, 29, 31, 0.08);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  height: 100vh;
  overflow: hidden;
  color: #1d1d1f;
  background: #f5f5f7;
  font-family: var(--ui-font);
  -webkit-font-smoothing: antialiased;
}

button,
input,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  min-height: 72px;
  padding: 12px 24px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(20px);
}

.brand,
.topbar-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand > div {
  display: grid;
  gap: 3px;
}

.topbar strong {
  font-size: 17px;
}

.brand span {
  color: var(--muted);
  font-size: 12px;
}

.page-count {
  padding: 7px 10px;
  border-radius: 999px;
  color: #5f6268;
  background: #f1f2f3;
  font-size: 12px;
}

.button {
  min-height: 40px;
  padding: 9px 16px;
  border: 0;
  border-radius: 9px;
  font-size: 14px;
  font-weight: 500;
  transition: transform 160ms ease, background 160ms ease;
}

.button.primary {
  color: #fff;
  background: var(--blue);
}

.button.secondary {
  color: #1d1d1f;
  box-shadow: inset 0 0 0 1px var(--line);
  background: #fff;
}

.button:hover {
  transform: translateY(-1px);
}

.button:disabled {
  cursor: wait;
  opacity: 0.5;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(420px, 480px) 1fr;
  height: calc(100vh - 72px);
}

.editor-panel,
.preview-panel {
  min-height: 0;
  overflow-y: auto;
}

.editor-panel {
  display: grid;
  align-content: start;
  gap: 16px;
  padding: 22px;
  border-right: 1px solid var(--line);
  background: #f7f7f6;
}

.editor-card {
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  box-shadow: 0 2px 8px rgba(28, 29, 31, 0.025);
}

.article-card {
  padding: 20px;
}

.section-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.editor-title {
  margin-bottom: 5px;
  font-size: 19px;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.editor-help {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.65;
}

.auto-badge {
  flex: none;
  padding: 6px 9px;
  border-radius: 999px;
  color: #17643a;
  background: #edf8f1;
  font-size: 11px;
  font-weight: 600;
}

.field {
  display: grid;
  gap: 8px;
  margin-bottom: 18px;
}

.field > span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

.field-label-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.article-actions {
  display: inline-flex;
  align-items: center;
  gap: 7px;
}

.clear-article-button {
  position: relative;
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: #4f5359;
  background: #fafafa;
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
}

.clear-article-button:hover {
  color: var(--blue);
  border-color: rgba(0, 113, 227, 0.28);
}

.clear-article-button:hover {
  color: #d93025;
  border-color: rgba(217, 48, 37, 0.28);
}

.hidden-file-input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

input,
textarea {
  width: 100%;
  border: 1px solid rgba(0, 0, 0, 0.1);
  border-radius: 8px;
  color: #1d1d1f;
  background: #fff;
}

input {
  min-height: 42px;
  padding: 10px 12px;
}

input:focus,
textarea:focus {
  outline: none;
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(0, 113, 227, 0.1);
}

.article-field {
  margin-bottom: 12px;
}

.article-source {
  display: none;
}

.article-editor-shell {
  position: relative;
}

.article-editor {
  display: grid;
  gap: 14px;
  min-height: 430px;
  padding: 16px;
  border: 1px solid rgba(0, 0, 0, 0.1);
  border-radius: 8px;
  background: #fff;
}

.article-editor:focus-within {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(0, 113, 227, 0.1);
}

.inline-insert-image {
  position: absolute;
  left: -13px;
  z-index: 4;
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  padding: 0;
  border: 1px solid #dfe1e4;
  border-radius: 50%;
  color: #8a8d92;
  background: #fff;
  box-shadow: 0 3px 10px rgba(28, 29, 31, 0.08);
  font-size: 19px;
  font-weight: 300;
  line-height: 1;
}

.inline-insert-image:hover {
  color: var(--blue);
  border-color: rgba(0, 113, 227, 0.35);
}

.inline-insert-image.hidden {
  display: none;
}

.article-text-segment {
  display: block;
  min-height: 52px;
  padding: 4px 0;
  border: 0;
  border-radius: 4px;
  box-shadow: none;
  font-family: var(--font-stack);
  font-size: 15px;
  line-height: 1.72;
  white-space: pre-wrap;
  word-break: break-word;
}

.article-text-segment:focus {
  border: 0;
  box-shadow: none;
  outline: none;
}

.article-text-segment.select-all-active {
  background: rgba(0, 113, 227, 0.1);
}

.article-text-segment [data-formats~="bold"] {
  font-weight: 700;
}

.article-text-segment [data-size-level="1"] {
  font-size: 0.9em;
}

.article-text-segment [data-size-level="2"] {
  font-size: 0.8em;
}

.article-text-segment [data-size-level="3"] {
  font-size: 0.7em;
}

.article-text-segment [data-size-level="4"] {
  font-size: 0.6em;
}

.article-text-segment [data-formats~="color"] {
  color: #d93025;
}

.article-text-segment [data-formats~="background"] {
  padding: 0 2px;
  border-radius: 2px;
  background: #fff1a8;
}

.article-context-menu {
  position: fixed;
  z-index: 80;
  min-width: 130px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: rgba(255, 255, 255, 0.98);
  box-shadow: 0 12px 30px rgba(28, 29, 31, 0.16);
}

.article-context-menu.hidden {
  display: none;
}

.article-context-menu button {
  width: 100%;
  padding: 8px 12px;
  border: 0;
  border-radius: 6px;
  color: #1d1d1f;
  background: transparent;
  text-align: left;
  font-size: 12px;
}

.article-context-menu button:hover {
  color: var(--blue);
  background: #f1f6fc;
}

.text-format-toolbar {
  position: fixed;
  z-index: 90;
  display: flex;
  align-items: center;
  gap: 3px;
  padding: 5px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.98);
  box-shadow: 0 12px 30px rgba(28, 29, 31, 0.16);
}

.text-format-toolbar.hidden {
  display: none;
}

.text-format-toolbar button {
  display: grid;
  place-items: center;
  width: 32px;
  min-width: 32px;
  height: 32px;
  padding: 0;
  border: 0;
  border-radius: 7px;
  color: #303236;
  background: transparent;
  font-size: 12px;
}

.text-format-toolbar button:hover {
  color: var(--blue);
  background: #f1f6fc;
}

.text-format-toolbar button.active {
  color: #fff;
  background: #1d1d1f;
}

.text-format-toolbar .size-format-button {
  position: relative;
  display: grid;
  min-width: 32px;
  font-family: Georgia, serif;
  font-size: 15px;
}

.text-format-toolbar .size-format-button sup {
  position: absolute;
  top: 4px;
  right: 3px;
  font-family: var(--ui-font);
  font-size: 8px;
  font-weight: 600;
}

.inserted-image-item {
  position: relative;
  display: block;
  padding: 0;
  overflow: hidden;
  border: 1px solid #e1e3e6;
  border-radius: 10px;
  background: #f7f7f7;
  cursor: pointer;
  outline: none;
}

.inserted-image-item:hover {
  border-color: rgba(0, 113, 227, 0.28);
}

.inserted-image-item.selected,
.inserted-image-item:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(0, 113, 227, 0.12);
}

.inserted-image-item.missing {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.inserted-image-item.uploading,
.inserted-image-item.upload-failed {
  display: flex;
  min-height: 120px;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: 13px;
}

.inserted-image-item.upload-failed {
  color: #b42318;
  background: #fff6f5;
}

.inserted-image-item.uploading::before {
  width: 16px;
  height: 16px;
  margin-right: 8px;
  border: 2px solid #d7dbe0;
  border-top-color: var(--blue);
  border-radius: 50%;
  content: "";
  animation: spin 800ms linear infinite;
}

.inserted-image-item.uploading .image-delete-button,
.inserted-image-item.upload-failed .image-delete-button {
  position: absolute;
  top: 10px;
  right: 10px;
}

.inserted-image-item img {
  display: block;
  width: 100%;
  height: auto;
  max-height: 520px;
  object-fit: contain;
  background: #ececec;
}

.inserted-image-info {
  display: none;
}

.inserted-image-info strong {
  overflow: hidden;
  font-size: 12px;
  font-weight: 500;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.inserted-image-info span {
  color: var(--muted);
  font-size: 10px;
}

.inserted-image-actions {
  position: absolute;
  top: 10px;
  right: 10px;
  display: flex;
  align-items: center;
  gap: 6px;
  opacity: 0;
  transition: opacity 140ms ease;
}

.inserted-image-item:hover .inserted-image-actions,
.inserted-image-item.selected .inserted-image-actions,
.inserted-image-item:focus .inserted-image-actions {
  opacity: 1;
}

.image-crop-button,
.image-delete-button {
  min-height: 32px;
  padding: 0 9px;
  border: 1px solid var(--line);
  border-radius: 7px;
  color: #4f5359;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: 0 3px 10px rgba(28, 29, 31, 0.12);
  font-size: 11px;
}

.image-crop-button:hover,
.image-delete-button:hover {
  color: var(--blue);
  border-color: rgba(0, 113, 227, 0.28);
}

.image-delete-button:hover {
  color: #d93025;
  border-color: rgba(217, 48, 37, 0.28);
}

.editor-footer {
  display: grid;
  gap: 9px;
}

.format-help {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 14px;
  color: var(--muted);
  font-size: 11px;
}

.format-help code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

.field.compact {
  margin-bottom: 0;
}

.meta-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 16px 18px;
}

.meta-label {
  margin-bottom: 10px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
}

.fixed-profile {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 48px;
  color: #1d1d1f;
}

.fixed-profile img {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  object-fit: cover;
}

.fixed-profile > div {
  display: grid;
  gap: 3px;
}

.fixed-profile strong {
  font-family: var(--font-stack);
  font-size: 14px;
}

.fixed-profile span {
  color: var(--muted);
  font-size: 11px;
}

.date-field {
  width: 132px;
}

.font-warning {
  display: none;
  margin-top: 20px;
  padding: 12px 14px;
  border: 1px solid #ef4444;
  border-radius: 8px;
  color: #b91c1c;
  background: #fef2f2;
  font-size: 12px;
  line-height: 1.5;
}

.font-warning.visible {
  display: block;
}

.status-text {
  color: var(--muted);
  font-size: 11px;
}

.preview-panel {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--workspace);
}

.preview-toolbar {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  min-height: 58px;
  padding: 12px 24px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.7);
}

.preview-toolbar > div {
  display: grid;
  gap: 2px;
}

.preview-toolbar strong {
  font-size: 14px;
}

.preview-toolbar span {
  color: var(--muted);
  font-size: 11px;
}

.preview-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
}

.pages {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 300px));
  justify-content: center;
  align-items: start;
  gap: 26px 20px;
  padding: 24px 26px 42px;
}

.page-shell {
  min-width: 0;
  counter-increment: preview-page;
  content-visibility: auto;
  contain-intrinsic-size: 300px 430px;
}

.page-frame {
  overflow: hidden;
  background: #f9faf5;
  box-shadow: var(--shadow);
}

.page-frame canvas {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 3 / 4;
}

.page-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 2px 0;
  color: #6e6e73;
  font-size: 12px;
}

.page-label {
  display: inline-flex;
  align-items: center;
  gap: 7px;
}

.page-label::before {
  content: attr(data-number);
  display: inline-grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  color: #5f6268;
  background: #e7e8e9;
  font-size: 10px;
  font-variant-numeric: tabular-nums;
}

.page-download {
  padding: 7px 10px;
  border: 0;
  border-radius: 7px;
  color: #1d1d1f;
  box-shadow: inset 0 0 0 1px var(--line);
  background: #fff;
}

.page-download:hover {
  color: var(--blue);
  border-color: rgba(0, 113, 227, 0.3);
}

.auth-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: #666;
  background: #fff;
  font-size: 13px;
}

.auth-overlay.hidden {
  display: none;
}

.spinner {
  width: 32px;
  height: 32px;
  margin-bottom: 12px;
  border: 3px solid #e0e0e0;
  border-top-color: #333;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 50;
  padding: 11px 15px;
  border-radius: 8px;
  color: #fff;
  background: #1d1d1f;
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
  transition: opacity 180ms ease, transform 180ms ease;
}

.toast.visible {
  opacity: 1;
  transform: translateY(0);
}

.hidden {
  display: none !important;
}

.crop-modal {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(22, 24, 28, 0.58);
  backdrop-filter: blur(6px);
}

.crop-card {
  width: min(920px, 100%);
  overflow: hidden;
  border-radius: 16px;
  background: #fff;
  box-shadow: 0 30px 90px rgba(0, 0, 0, 0.28);
}

.crop-head,
.crop-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 16px 18px;
}

.crop-head {
  border-bottom: 1px solid var(--line);
}

.crop-head > div {
  display: grid;
  gap: 3px;
}

.crop-head strong {
  font-size: 16px;
}

.crop-head span {
  color: var(--muted);
  font-size: 11px;
}

.crop-close {
  min-height: 34px;
  padding: 0 10px;
  border: 0;
  border-radius: 8px;
  color: var(--muted);
  background: #f4f4f4;
}

.crop-stage {
  display: grid;
  place-items: center;
  padding: 18px;
  background: #17191d;
}

.crop-stage canvas {
  display: block;
  width: min(760px, 100%);
  height: auto;
  cursor: crosshair;
  touch-action: none;
  user-select: none;
}

.crop-footer {
  border-top: 1px solid var(--line);
}

.ratio-buttons,
.crop-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.ratio-buttons button {
  min-height: 34px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: #5f6268;
  background: #fff;
}

.ratio-buttons button.active {
  color: #fff;
  border-color: var(--blue);
  background: var(--blue);
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@media (max-width: 980px) {
  body {
    height: auto;
    overflow: auto;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .topbar-actions {
    width: 100%;
    flex-wrap: wrap;
  }

  .workspace {
    grid-template-columns: 1fr;
    height: auto;
  }

  .editor-panel,
  .preview-panel,
  .preview-scroll {
    overflow: visible;
  }
}

@media (max-width: 560px) {
  .topbar,
  .editor-panel,
  .pages {
    padding: 18px;
  }

  .brand {
    flex-wrap: wrap;
  }

  .meta-card,
  .preview-toolbar,
  .crop-footer {
    align-items: flex-start;
    flex-direction: column;
  }

  .date-field {
    width: 100%;
  }

  .pages {
    grid-template-columns: 1fr;
  }
}
