:root {
  --ink: #1d2a26;
  --muted: #6d7772;
  --line: #dfe5df;
  --paper: #fbfcf8;
  --panel: #ffffff;
  --field: #fff7f3;
  --accent: #fc5b1f;
  --accent-strong: #d94c24;
  --warm: #fa5c2e;
  --blue: #286a9b;
  --shadow: 0 20px 60px rgba(29, 42, 38, 0.12);
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  background:
    linear-gradient(90deg, rgba(252, 91, 31, 0.05) 1px, transparent 1px),
    linear-gradient(0deg, rgba(40, 106, 155, 0.05) 1px, transparent 1px),
    var(--paper);
  background-size: 32px 32px;
  color: var(--ink);
  font-family: "Avenir Next", "Helvetica Neue", "PingFang SC", sans-serif;
}

button,
input,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-rows: 64px minmax(0, 1fr);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 10px 18px;
  border-bottom: 1px solid var(--line);
  background: rgba(251, 252, 248, 0.92);
  backdrop-filter: blur(16px);
}

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

.brand-mark {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: var(--ink);
  color: #fff;
  font-weight: 800;
  box-shadow: inset 0 -4px 0 rgba(255, 255, 255, 0.08);
}

.brand-copy {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.brand-copy strong {
  font-size: 16px;
  line-height: 1.1;
  white-space: nowrap;
}

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

.actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

.primary-button,
.ghost-button,
.icon-button {
  border: 1px solid var(--line);
  border-radius: 8px;
  min-height: 36px;
  transition: transform 0.16s ease, border-color 0.16s ease, background 0.16s ease;
}

.primary-button {
  padding: 0 16px;
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
  font-weight: 700;
}

.ghost-button {
  padding: 0 12px;
  background: var(--panel);
  color: var(--ink);
}

.mini-button,
.upload-button {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  transition: transform 0.16s ease, border-color 0.16s ease, background 0.16s ease;
}

.mini-button {
  min-height: 28px;
  padding: 0 10px;
  font-size: 12px;
}

.upload-button {
  width: 100%;
  min-height: 34px;
  margin-top: 8px;
  background: var(--ink);
  color: #fff;
  font-weight: 700;
}

.icon-button {
  width: 36px;
  background: var(--field);
  color: var(--ink);
  font-size: 18px;
}

.primary-button:hover,
.ghost-button:hover,
.mini-button:hover,
.upload-button:hover,
.icon-button:hover {
  transform: translateY(-1px);
  border-color: var(--accent);
}

.workspace {
  min-height: 0;
  height: calc(100vh - 64px);
  display: grid;
  grid-template-columns: minmax(520px, 1fr) minmax(430px, 0.95fr);
  grid-template-areas: "editor preview";
  gap: 12px;
  padding: 12px;
}

body.drafts-open .workspace {
  grid-template-columns: 220px minmax(480px, 1fr) minmax(430px, 0.95fr);
  grid-template-areas: "drafts editor preview";
}

body.controls-open .workspace {
  grid-template-columns: minmax(420px, 1fr) minmax(390px, 0.9fr) 280px;
  grid-template-areas: "editor preview controls";
}

body.drafts-open.controls-open .workspace {
  grid-template-columns: 220px minmax(420px, 1fr) minmax(390px, 0.9fr) 280px;
  grid-template-areas: "drafts editor preview controls";
}

.draft-sidebar,
.editor-panel,
.control-rail,
.preview-panel {
  min-height: 0;
  background: rgba(255, 255, 255, 0.9);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 12px 36px rgba(29, 42, 38, 0.08);
}

.draft-sidebar {
  grid-area: drafts;
  display: none;
  grid-template-rows: 48px 1fr;
  min-height: 0;
  overflow: hidden;
}

body.drafts-open .draft-sidebar {
  display: grid;
}

.draft-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px 8px 12px;
  border-bottom: 1px solid var(--line);
  color: var(--ink);
  font-size: 13px;
  font-weight: 700;
}

.draft-head .icon-button {
  width: 32px;
  min-height: 32px;
  font-size: 20px;
  line-height: 1;
}

.draft-list {
  min-height: 0;
  overflow: auto;
  display: grid;
  align-content: start;
  gap: 6px;
  padding: 8px;
}

.draft-item {
  display: grid;
  gap: 5px;
  min-width: 0;
  min-height: 66px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--ink);
  padding: 10px;
  text-align: left;
}

.draft-item:hover {
  background: var(--field);
  border-color: rgba(252, 91, 31, 0.22);
}

.draft-item.is-active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.draft-item strong,
.draft-item span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.draft-item strong {
  font-size: 13px;
  line-height: 1.25;
}

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

.draft-item.is-active span {
  color: rgba(255, 255, 255, 0.78);
}

.editor-panel {
  grid-area: editor;
  display: grid;
  grid-template-rows: 54px 1fr;
  min-height: 0;
  overflow: hidden;
}

.panel-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px;
  border-bottom: 1px solid var(--line);
}

.title-input {
  min-width: 0;
  width: 100%;
  height: 38px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: var(--field);
  padding: 0 12px;
  color: var(--ink);
  font-weight: 700;
}

.title-input:focus,
.markdown-input:focus {
  outline: 2px solid rgba(252, 91, 31, 0.18);
  border-color: rgba(252, 91, 31, 0.46);
}

.markdown-input {
  min-height: 0;
  width: 100%;
  resize: none;
  border: 0;
  background: transparent;
  padding: 22px;
  color: #24302c;
  font-family: "SFMono-Regular", "Cascadia Code", Consolas, monospace;
  font-size: 15px;
  line-height: 1.72;
}

.control-rail {
  grid-area: controls;
  padding: 14px;
  display: none;
  flex-direction: column;
  gap: 14px;
  overflow: auto;
  box-shadow: 0 10px 28px rgba(29, 42, 38, 0.07);
}

body.controls-open .control-rail {
  display: flex;
}

.control-block {
  border-bottom: 1px solid var(--line);
  padding-bottom: 14px;
}

.control-block:last-child {
  border-bottom: 0;
  padding-bottom: 0;
}

.control-label {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 9px;
}

.control-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}

.control-head .control-label {
  margin-bottom: 0;
}

.theme-list {
  display: grid;
  gap: 8px;
}

.theme-card {
  display: grid;
  grid-template-columns: 28px 1fr;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  text-align: left;
}

.theme-card.is-active {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(252, 91, 31, 0.12);
}

.theme-swatch {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  border: 1px solid rgba(29, 42, 38, 0.16);
}

.theme-meta {
  min-width: 0;
  display: grid;
  gap: 2px;
}

.theme-meta strong,
.theme-meta span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.theme-meta strong {
  font-size: 13px;
}

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

.toggle-row {
  min-height: 30px;
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--ink);
  font-size: 13px;
}

.toggle-row input {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
}

.image-control {
  display: grid;
  gap: 8px;
}

.dropzone {
  min-height: 88px;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 3px;
  border: 1px dashed rgba(252, 91, 31, 0.5);
  border-radius: 8px;
  background: linear-gradient(180deg, rgba(252, 91, 31, 0.08), rgba(40, 106, 155, 0.04));
  color: var(--ink);
  text-align: center;
  cursor: pointer;
}

.dropzone.is-active {
  border-style: solid;
  background: rgba(252, 91, 31, 0.12);
}

.dropzone input {
  display: none;
}

.dropzone strong {
  font-size: 14px;
  line-height: 1.2;
}

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

.upload-config {
  display: grid;
  gap: 6px;
}

.upload-config input {
  width: 100%;
  min-width: 0;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--field);
  color: var(--ink);
  padding: 0 10px;
  font-size: 12px;
}

.upload-config input:focus {
  outline: 2px solid rgba(252, 91, 31, 0.16);
  border-color: rgba(252, 91, 31, 0.46);
}

.upload-config-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.image-queue {
  display: grid;
  gap: 7px;
  max-height: min(230px, 24vh);
  overflow: auto;
}

.image-item {
  display: grid;
  grid-template-columns: 42px 1fr auto;
  align-items: center;
  gap: 8px;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  padding: 6px;
}

.image-item img {
  width: 42px;
  height: 42px;
  object-fit: cover;
  border-radius: 6px;
  background: var(--field);
}

.image-item-main {
  min-width: 0;
  display: grid;
  gap: 2px;
}

.image-item-main strong,
.image-item-main span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.image-item-main strong {
  font-size: 12px;
}

.image-item-main span {
  color: var(--muted);
  font-size: 11px;
}

.image-status {
  min-width: 46px;
  min-height: 24px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 6px;
  background: var(--field);
  color: var(--muted);
  font-size: 11px;
  text-decoration: none;
}

.image-status.done {
  background: rgba(252, 91, 31, 0.12);
  color: var(--accent);
}

.image-status.error {
  background: rgba(228, 92, 63, 0.12);
  color: var(--warm);
}

.image-status.warning {
  background: rgba(242, 193, 78, 0.18);
  color: #9b6a00;
}

.image-status.uploading {
  background: rgba(40, 106, 155, 0.12);
  color: var(--blue);
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.stats-grid div {
  min-height: 58px;
  display: grid;
  align-content: center;
  gap: 2px;
  border-radius: 8px;
  background: var(--field);
  padding: 8px;
}

.stats-grid strong {
  font-size: 20px;
  line-height: 1;
}

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

.preview-panel {
  grid-area: preview;
  display: grid;
  grid-template-rows: 44px 1fr;
  overflow: hidden;
}

.preview-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 14px;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
}

.preview-top-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.preview-mode-switch {
  display: inline-grid;
  grid-template-columns: 32px 32px;
  gap: 4px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--field);
}

.preview-mode-button {
  width: 32px;
  min-height: 30px;
  display: grid;
  place-items: center;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
}

.preview-mode-button svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.preview-mode-button:hover {
  color: var(--ink);
  border-color: rgba(252, 91, 31, 0.28);
}

.preview-mode-button.is-active {
  background: #fff;
  color: var(--accent);
  border-color: rgba(252, 91, 31, 0.42);
  box-shadow: 0 5px 14px rgba(29, 42, 38, 0.08);
}

.phone-stage {
  min-height: 0;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  overflow: auto;
  padding: 18px;
}

.phone-stage.is-desktop {
  justify-content: center;
}

.wechat-paper {
  width: min(100%, 390px);
  height: auto;
  min-height: 100%;
  flex: 0 0 auto;
  background: #fff;
  box-shadow: var(--shadow);
  border: 1px solid #eef1ed;
}

.phone-stage.is-desktop .wechat-paper {
  width: min(100%, 720px);
}

.wechat-preview {
  padding: 18px;
  overflow-wrap: break-word;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 20px;
  z-index: 20;
  min-width: 180px;
  max-width: calc(100vw - 28px);
  transform: translate(-50%, 16px);
  opacity: 0;
  pointer-events: none;
  border: 1px solid rgba(29, 42, 38, 0.08);
  border-radius: 8px;
  background: #16231f;
  color: #fff;
  padding: 10px 14px;
  text-align: center;
  box-shadow: 0 16px 44px rgba(29, 42, 38, 0.24);
  transition: transform 0.2s ease, opacity 0.2s ease;
}

.toast.is-visible {
  transform: translate(-50%, 0);
  opacity: 1;
}

@media (max-width: 1380px) {
  .workspace {
    height: auto;
    min-height: calc(100vh - 64px);
    grid-template-columns: minmax(320px, 1fr) minmax(320px, 1fr);
    grid-template-areas:
      "editor preview";
  }

  body.drafts-open .workspace {
    grid-template-columns: minmax(320px, 1fr) minmax(320px, 1fr);
    grid-template-areas:
      "drafts drafts"
      "editor preview";
  }

  body.controls-open .workspace {
    grid-template-columns: minmax(320px, 1fr) minmax(320px, 1fr);
    grid-template-areas:
      "editor preview"
      "controls controls";
  }

  body.drafts-open.controls-open .workspace {
    grid-template-columns: minmax(320px, 1fr) minmax(320px, 1fr);
    grid-template-areas:
      "drafts drafts"
      "editor preview"
      "controls controls";
  }

  .draft-sidebar {
    min-height: 168px;
  }

  .draft-list {
    grid-auto-flow: column;
    grid-auto-columns: minmax(190px, 230px);
    overflow-x: auto;
    overflow-y: hidden;
  }

  .editor-panel {
    height: clamp(520px, calc(100vh - 260px), 680px);
    min-height: 520px;
  }

  .preview-panel {
    height: clamp(520px, calc(100vh - 260px), 680px);
    min-height: 520px;
  }

  body.controls-open .control-rail {
    display: grid;
    grid-template-columns: minmax(220px, 0.8fr) minmax(180px, 0.55fr) minmax(280px, 1fr) minmax(180px, 0.55fr);
    align-items: start;
    overflow: visible;
  }

  .control-block {
    height: 100%;
    border-bottom: 0;
    border-right: 1px solid var(--line);
    padding: 0 14px 0 0;
  }

  .control-block:last-child {
    border-right: 0;
    padding-right: 0;
  }
}

@media (max-width: 760px) {
  .app-shell {
    grid-template-rows: auto 1fr;
  }

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

  .actions {
    width: 100%;
    justify-content: stretch;
  }

  .actions button {
    flex: 1 1 auto;
  }

  .workspace {
    height: auto;
    grid-template-columns: 1fr;
    grid-template-areas:
      "editor"
      "preview";
    padding: 10px;
  }

  body.drafts-open .workspace {
    grid-template-columns: 1fr;
    grid-template-areas:
      "drafts"
      "editor"
      "preview";
  }

  body.controls-open .workspace {
    grid-template-columns: 1fr;
    grid-template-areas:
      "editor"
      "controls"
      "preview";
  }

  body.drafts-open.controls-open .workspace {
    grid-template-columns: 1fr;
    grid-template-areas:
      "drafts"
      "editor"
      "controls"
      "preview";
  }

  .draft-sidebar {
    min-height: 190px;
  }

  .draft-list {
    grid-auto-flow: row;
    grid-auto-columns: auto;
    overflow: auto;
  }

  .editor-panel {
    height: auto;
    min-height: 460px;
  }

  body.controls-open .control-rail {
    display: grid;
    grid-template-columns: 1fr;
    overflow: visible;
  }

  .control-block {
    border-right: 0;
    border-bottom: 1px solid var(--line);
    padding: 0 0 14px;
  }

  .control-block:last-child {
    border-bottom: 0;
    padding-bottom: 0;
  }

  .image-queue {
    max-height: none;
  }

  .preview-panel {
    height: auto;
    min-height: 560px;
  }

  .phone-stage {
    padding: 12px;
  }
}
