:root {
  color-scheme: light;
  --canvas: #f5f6f8;
  --surface: #ffffff;
  --surface-soft: #fafbfc;
  --surface-muted: #f0f3f7;
  --ink: #171b26;
  --muted: #677083;
  --quiet: #9aa3b2;
  --line: #dde3eb;
  --line-strong: #c9d2df;
  --blue: #2f6df6;
  --blue-soft: #eef4ff;
  --green: #0a8f57;
  --green-soft: #eaf7f0;
  --danger: #d83b3b;
  --shadow: 0 18px 42px rgba(23, 27, 38, .08);
  --radius: 8px;
  --mono: "SF Mono", "Cascadia Code", Menlo, Consolas, monospace;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --canvas: #0e1219;
  --surface: #151b25;
  --surface-soft: #111722;
  --surface-muted: #1d2634;
  --ink: #edf2f7;
  --muted: #a9b3c3;
  --quiet: #7f8a9d;
  --line: #273244;
  --line-strong: #39475d;
  --blue: #7ca8ff;
  --blue-soft: rgba(124, 168, 255, .14);
  --green: #36c98b;
  --green-soft: rgba(54, 201, 139, .13);
  --danger: #ff7777;
  --shadow: 0 18px 44px rgba(0, 0, 0, .28);
}

* { box-sizing: border-box; }
html, body { width: 100%; min-height: 100%; }
body {
  margin: 0;
  color: var(--ink);
  background: var(--canvas);
  font: 14px/1.5 Inter, "Avenir Next", "PingFang SC", "Noto Sans CJK SC", ui-sans-serif, system-ui, sans-serif;
  overflow: hidden;
}

button, input, select, textarea { font: inherit; }
button {
  min-height: 38px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  padding: 8px 13px;
  color: #fff;
  background: var(--blue);
  cursor: pointer;
  font-weight: 760;
  transition: background .16s ease, border-color .16s ease, transform .16s ease, opacity .16s ease;
}
button:hover { transform: translateY(-1px); }
button:disabled { cursor: not-allowed; opacity: .55; transform: none; }
button.secondary {
  color: var(--ink);
  background: var(--surface);
  border-color: var(--line);
}
button.secondary:hover {
  border-color: var(--line-strong);
  background: var(--surface-soft);
}
button.publish {
  background: var(--green);
  box-shadow: 0 10px 24px rgba(10, 143, 87, .18);
}
button.compact {
  min-height: 32px;
  padding: 6px 10px;
  font-size: 13px;
}

select, input, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  outline: none;
}
select, input {
  min-height: 38px;
  padding: 8px 10px;
}
textarea {
  resize: none;
}
select:focus,
input:focus,
textarea:focus {
  border-color: rgba(47, 109, 246, .58);
  box-shadow: 0 0 0 3px rgba(47, 109, 246, .11);
}
label {
  display: block;
  margin: 0 0 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 780;
}
h1, h2, h3, p { margin: 0; }

.login-screen {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 24px;
  background: var(--canvas);
}
.login-screen[hidden] {
  display: none;
}
.login-card {
  width: min(390px, 100%);
  display: grid;
  gap: 16px;
  padding: 30px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  box-shadow: var(--shadow);
}
.login-brand {
  display: grid;
  gap: 7px;
  margin-bottom: 4px;
}
.login-brand strong {
  color: #2b58b8;
  font-size: 30px;
  line-height: 1;
  font-weight: 900;
  letter-spacing: 0;
}
.login-brand span {
  color: var(--muted);
}
.login-submit {
  width: 100%;
  min-height: 42px;
  margin-top: 2px;
}
.login-error {
  min-height: 20px;
  color: var(--danger);
  font-size: 13px;
}

.app-shell {
  position: fixed;
  inset: 0;
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: 64px minmax(0, 1fr) 34px;
  background: var(--canvas);
}

.topbar {
  min-width: 0;
  display: grid;
  grid-template-columns: minmax(180px, 1fr) auto;
  align-items: center;
  gap: 18px;
  padding: 0 22px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}
.brand {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 14px;
}
.brand strong {
  color: #2b58b8;
  font-size: 25px;
  line-height: 1;
  font-weight: 900;
  letter-spacing: 0;
}
.brand span {
  min-width: 0;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.brand span::before {
  content: "";
  width: 8px;
  height: 8px;
  display: inline-block;
  margin-right: 8px;
  border-radius: 50%;
  background: var(--green);
  vertical-align: 1px;
}

.toolbar {
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 9px;
}
.toolbar-field {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 8px;
  min-width: 148px;
  height: 38px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}
.toolbar-field label {
  margin: 0;
  color: var(--quiet);
  font-size: 12px;
}
.toolbar-field select {
  min-height: 30px;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  font-weight: 720;
}
.theme-field { min-width: 198px; }
.workspace {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(520px, 56%) minmax(420px, 44%);
  overflow: hidden;
}
.editor-pane,
.preview-pane {
  min-width: 0;
  min-height: 0;
}
.editor-pane {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  border-right: 1px solid var(--line);
  background: var(--surface);
}
.meta-panel {
  display: grid;
  grid-template-columns: 1fr;
  gap: 14px;
  padding: 18px 22px 16px;
  border-bottom: 1px solid var(--line);
}
.field { min-width: 0; }
.title-field {
  max-width: 620px;
}
.quiet-fields {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}
.quiet-fields input {
  min-height: 34px;
  background: var(--surface-soft);
  font-size: 13px;
}

.editor-toolbar {
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 12px 22px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-soft);
}
.editor-toolbar strong {
  display: inline-block;
  margin-right: 10px;
  font-size: 14px;
  font-weight: 850;
}
.editor-toolbar span {
  color: var(--muted);
  font-size: 12px;
}
.draft-tools {
  min-width: 0;
  display: grid;
  grid-template-columns: minmax(170px, 260px) auto auto auto;
  align-items: center;
  gap: 8px;
}
.draft-tools select {
  min-height: 32px;
  font-size: 13px;
}

.editor-card {
  min-height: 0;
  min-width: 0;
  display: grid;
  grid-template-columns: 48px minmax(0, 1fr);
  background: var(--surface);
  overflow: hidden;
}
.line-numbers {
  min-height: 0;
  padding: 18px 0;
  border-right: 1px solid var(--line);
  color: var(--quiet);
  background: var(--surface-soft);
  font: 13px/1.72 var(--mono);
  text-align: right;
  overflow: hidden;
  user-select: none;
}
.line-numbers span {
  display: block;
  padding: 0 10px 0 4px;
}
#markdown {
  height: 100%;
  min-height: 0;
  padding: 18px 22px 36px;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  font: 14px/1.72 var(--mono);
  white-space: pre;
  overflow: auto;
}

.preview-pane {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  background: var(--surface-soft);
}
.preview-header {
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}
.preview-header strong {
  display: block;
  font-size: 16px;
}
.preview-header span,
.drawer-head span {
  color: var(--muted);
  font-size: 12px;
}
.preview-layout {
  position: relative;
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  overflow: hidden;
}
.wechat-preview {
  min-width: 0;
  min-height: 0;
  max-width: 760px;
  width: 100%;
  justify-self: center;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  padding: 28px 44px;
  background: var(--surface);
  overflow: hidden;
}
.article-head {
  padding-bottom: 18px;
  border-bottom: 1px solid var(--line);
}
.preview-title {
  color: var(--ink);
  font-size: 30px;
  line-height: 1.25;
  font-weight: 900;
  letter-spacing: 0;
}
.preview-byline {
  margin-top: 12px;
  color: var(--muted);
  font-size: 14px;
}
.preview-body {
  min-height: 0;
  padding: 22px 0 46px;
  color: var(--ink);
  overflow: auto;
  overflow-wrap: anywhere;
}
.preview-body img {
  max-width: 100%;
  height: auto;
  border-radius: var(--radius);
}
.preview-body p,
.preview-body li {
  font-size: 15px;
}
.preview-jump-target {
  position: relative;
  cursor: pointer;
  transition: background-color .16s ease, box-shadow .16s ease;
}
.preview-jump-target:hover {
  background: var(--blue-soft);
  box-shadow: 0 0 0 4px var(--blue-soft);
  border-radius: 6px;
}
.preview-empty {
  min-height: 420px;
  display: grid;
  place-items: center;
  color: var(--quiet);
  text-align: center;
}
.preview-empty strong {
  display: block;
  margin-bottom: 5px;
  color: var(--muted);
  font-size: 17px;
}

:root[data-theme="dark"] .wechat-preview {
  color: #171b26;
  background: #ffffff;
}
:root[data-theme="dark"] .article-head {
  border-bottom-color: #dde3eb;
}
:root[data-theme="dark"] .preview-title {
  color: #171b26;
}
:root[data-theme="dark"] .preview-byline,
:root[data-theme="dark"] .preview-body {
  color: #677083;
}
:root[data-theme="dark"] .preview-empty {
  color: #9aa3b2;
}
:root[data-theme="dark"] .preview-empty strong {
  color: #677083;
}

.theme-drawer {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: 20;
  width: min(280px, 42%);
  min-width: 240px;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  border-left: 1px solid var(--line);
  background: var(--surface);
  box-shadow: -18px 0 34px rgba(23, 27, 38, .08);
  overflow: hidden;
  transition: transform .18s ease, opacity .18s ease;
}
.theme-drawer:not(.open) {
  transform: translateX(100%);
  opacity: 0;
  pointer-events: none;
}
.drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 14px 14px 12px;
  border-bottom: 1px solid var(--line);
}
.drawer-head strong {
  font-size: 14px;
}
.themes {
  min-height: 0;
  display: grid;
  align-content: start;
  overflow: auto;
}
.theme-card {
  position: relative;
  min-width: 0;
  display: grid;
  grid-template-columns: 20px minmax(0, 1fr);
  gap: 10px;
  align-items: start;
  padding: 10px 14px;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: transparent;
  color: var(--ink);
  text-align: left;
  cursor: pointer;
  transform: none !important;
}
.theme-card:hover {
  background: var(--surface-soft);
}
.theme-card.active {
  background: var(--blue-soft);
}
.theme-card.active::after {
  content: "";
  position: absolute;
  right: 14px;
  top: 16px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--blue);
}
.theme-swatch {
  width: 16px;
  height: 16px;
  margin-top: 2px;
  border: 1px solid var(--line-strong);
  border-radius: 50%;
  background: var(--card-color, var(--blue));
}
.theme-card strong {
  display: block;
  max-width: calc(100% - 18px);
  font-size: 13px;
  line-height: 1.25;
  font-weight: 850;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.theme-card p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
  display: -webkit-box;
  -webkit-line-clamp: 1;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.statusbar {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 22px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  background: var(--surface);
  font-size: 12px;
}
#status {
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.toast {
  position: fixed;
  right: 22px;
  top: 76px;
  z-index: 50;
  max-width: min(360px, calc(100vw - 44px));
  padding: 11px 13px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--ink);
  background: var(--surface);
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(-8px);
  pointer-events: none;
  transition: opacity .16s ease, transform .16s ease;
}
.toast.show {
  opacity: 1;
  transform: translateY(0);
}
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(10, 14, 22, .42);
}
.modal-backdrop[hidden] {
  display: none;
}
.settings-modal {
  width: min(640px, 100%);
  max-height: min(760px, calc(100vh - 48px));
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 18px;
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.modal-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}
.modal-head strong {
  display: block;
  font-size: 18px;
  line-height: 1.25;
}
.modal-head span {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
}
.settings-scroll {
  min-height: 0;
  display: grid;
  gap: 16px;
  padding-right: 2px;
  overflow: auto;
}
.settings-section {
  display: grid;
  gap: 14px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-soft);
}
.section-title {
  min-width: 0;
  display: grid;
  gap: 3px;
}
.section-title strong {
  font-size: 15px;
  line-height: 1.3;
}
.section-title span {
  color: var(--muted);
  font-size: 12px;
}
.settings-grid {
  display: grid;
  gap: 12px;
}
.settings-grid.two-columns {
  grid-template-columns: minmax(0, 1fr) minmax(150px, .48fr);
}
.settings-actions {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 10px;
}
.full-width {
  width: 100%;
}
.toggle-field {
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 0 2px;
  border-top: 1px solid var(--line);
}
.toggle-field strong {
  display: block;
  font-size: 14px;
}
.toggle-field span {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}
.switch {
  flex: 0 0 auto;
  display: inline-grid;
  place-items: center;
  margin: 0;
  cursor: pointer;
}
.switch input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}
.switch span {
  position: relative;
  width: 46px;
  height: 26px;
  margin: 0;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: var(--surface-muted);
  transition: background .16s ease, border-color .16s ease;
}
.switch span::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--surface);
  box-shadow: 0 2px 7px rgba(23, 27, 38, .2);
  transition: transform .16s ease;
}
.switch input:checked + span {
  border-color: var(--blue);
  background: var(--blue);
}
.switch input:checked + span::after {
  transform: translateX(20px);
}
.range-stack {
  display: grid;
  gap: 13px;
}
.range-stack.disabled {
  opacity: .58;
}
.range-field {
  display: grid;
  grid-template-columns: minmax(90px, 1fr) auto;
  align-items: center;
  gap: 8px 12px;
  margin: 0;
}
.range-field span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 780;
}
.range-field strong {
  color: var(--ink);
  font-size: 13px;
  font-weight: 820;
}
.range-field input {
  grid-column: 1 / -1;
  min-height: 26px;
  padding: 0;
  border: 0;
  accent-color: var(--blue);
  cursor: pointer;
}
.range-field input:disabled {
  cursor: not-allowed;
}
.password-form {
  display: grid;
  gap: 14px;
  padding-top: 2px;
}
.password-form .publish {
  width: 100%;
  min-height: 40px;
}
.settings-message {
  min-height: 20px;
  color: var(--muted);
  font-size: 13px;
}
.settings-message.error {
  color: var(--danger);
}
.settings-message.ok {
  color: var(--green);
}

@media (max-width: 1180px) {
  body { overflow: auto; }
  .app-shell {
    position: static;
    min-height: 100vh;
    grid-template-rows: auto auto auto;
  }
  .topbar {
    grid-template-columns: 1fr;
    gap: 12px;
    padding: 16px;
  }
  .toolbar {
    justify-content: flex-start;
    flex-wrap: wrap;
  }
  .workspace {
    grid-template-columns: 1fr;
    overflow: visible;
  }
  .editor-pane {
    min-height: 760px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }
  .preview-pane {
    min-height: 720px;
  }
  .preview-layout {
    min-height: 670px;
  }
}

@media (max-width: 760px) {
  .brand {
    align-items: flex-start;
    flex-direction: column;
    gap: 5px;
  }
  .toolbar {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    width: 100%;
  }
  .toolbar button {
    width: 100%;
    min-width: 0;
  }
  .meta-panel {
    grid-template-columns: 1fr;
    padding: 14px;
  }
  .quiet-fields {
    grid-template-columns: 1fr;
  }
  .editor-toolbar {
    align-items: stretch;
    flex-direction: column;
    padding: 12px 14px;
  }
  .draft-tools {
    grid-template-columns: 1fr auto auto auto;
  }
  .editor-card {
    grid-template-columns: 40px minmax(0, 1fr);
  }
  #markdown {
    padding: 16px 14px 32px;
    font-size: 13px;
  }
  .preview-layout {
    grid-template-columns: 1fr;
    overflow: visible;
  }
  .wechat-preview {
    max-width: none;
    min-height: 560px;
    padding: 22px 18px;
    overflow: visible;
  }
  .preview-body {
    overflow: visible;
  }
  .theme-drawer {
    position: static;
    width: auto;
    min-width: 0;
    min-height: 240px;
    border-left: 0;
    border-top: 1px solid var(--line);
    box-shadow: none;
  }
  .theme-drawer:not(.open) {
    display: none;
    transform: none;
  }
  .settings-modal {
    max-height: calc(100vh - 28px);
    padding: 16px;
  }
  .settings-grid.two-columns {
    grid-template-columns: 1fr;
  }
  .settings-section {
    padding: 14px;
  }
  .statusbar {
    min-height: 36px;
    padding: 0 14px;
  }
}
