:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --panel: #ffffff;
  --text: #17202a;
  --muted: #687386;
  --line: #dfe4ea;
  --line-soft: #edf1f4;
  --soft: #f8fafc;
  --primary: #16735f;
  --primary-dark: #115c4c;
  --ink: #263445;
  --warning: #9a5b19;
  --shadow: 0 10px 28px rgba(22, 32, 45, 0.055);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(180deg, #eef3f5 0, #f7f8fa 180px, var(--bg) 100%);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

body.is-locked {
  overflow: hidden;
}

button,
input,
textarea {
  font: inherit;
}

.hidden {
  display: none !important;
}

.login-view {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(244, 246, 248, 0.92);
  backdrop-filter: blur(8px);
}

.login-card {
  width: min(420px, 100%);
  display: grid;
  gap: 18px;
  padding: 24px;
  text-align: center;
}

.login-card p {
  margin-top: 8px;
  color: var(--muted);
  line-height: 1.7;
}

.qr-box {
  width: 268px;
  height: 268px;
  display: grid;
  place-items: center;
  margin: 0 auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.qr-box img {
  width: 240px;
  height: 240px;
}

.login-note {
  min-height: 22px;
  font-size: 13px;
}

.shell {
  min-height: 100vh;
  padding: 12px;
}

.workspace {
  max-width: 1680px;
  margin: 0 auto;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 10px;
  padding: 10px 12px;
}

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

.user-badge {
  min-height: 22px;
  display: inline-flex;
  align-items: center;
  color: var(--muted);
  font-size: 12px;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 18px;
  line-height: 1.25;
  font-weight: 750;
}

h2 {
  font-size: 14px;
  line-height: 1.3;
}

.topbar p,
#resultText {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

button {
  height: 34px;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 0 12px;
  cursor: pointer;
  white-space: nowrap;
  transition: transform 0.15s ease, background 0.15s ease, box-shadow 0.15s ease;
  font-size: 13px;
}

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

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.primary {
  background: var(--primary);
  color: #fff;
  box-shadow: 0 8px 18px rgba(22, 115, 95, 0.18);
}

.primary:hover:not(:disabled) {
  background: var(--primary-dark);
}

.secondary {
  background: var(--ink);
  color: #fff;
}

.ghost {
  background: #f2f5f7;
  border-color: #e3e8ed;
  color: var(--ink);
}

.danger {
  color: #9f2f2f;
}

.actions {
  display: flex;
  gap: 6px;
  align-items: center;
}

.editor-grid {
  display: grid;
  grid-template-columns: minmax(360px, 0.95fr) minmax(310px, 0.62fr) minmax(400px, 1fr);
  gap: 10px;
  align-items: start;
}

.surface {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.panel {
  min-height: calc(100vh - 92px);
  max-height: calc(100vh - 92px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.panel-head {
  min-height: 46px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--line-soft);
  background: var(--soft);
  border-radius: 8px 8px 0 0;
}

.panel-head input {
  max-width: 260px;
}

input,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  outline: none;
  background: #fff;
  color: var(--text);
}

input {
  height: 34px;
  padding: 0 10px;
  font-size: 13px;
}

textarea {
  padding: 10px;
  resize: vertical;
  line-height: 1.6;
  font-size: 13px;
}

input:focus,
textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(18, 113, 91, 0.12);
}

#rawText {
  flex: 1;
  min-height: 0;
  border: 0;
  border-radius: 0 0 8px 8px;
  font-size: 14px;
  background: #fff;
  line-height: 1.7;
  resize: none;
}

.fields {
  display: grid;
  gap: 9px;
  padding: 10px;
  overflow: auto;
}

label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 12px;
}

#digest {
  min-height: 72px;
}

.file-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 6px;
  align-items: center;
}

.file-row input {
  min-width: 0;
  padding: 6px 8px;
}

.field-note {
  min-height: 16px;
  color: var(--warning);
  font-size: 12px;
  line-height: 1.35;
}

.cover-cropper {
  display: grid;
  gap: 7px;
  padding: 8px;
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  background: #fbfcfd;
}

.cover-cropper canvas {
  width: 100%;
  aspect-ratio: 900 / 383;
  display: block;
  border-radius: 6px;
  background: #eef2f5;
  cursor: grab;
  touch-action: none;
}

.cover-cropper canvas:active {
  cursor: grabbing;
}

.crop-actions {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  color: var(--muted);
  font-size: 12px;
}

.crop-actions input {
  height: 22px;
  padding: 0;
}

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

.author-row {
  position: relative;
}

.preview-head-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
  min-width: 0;
}

.image-tools {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.image-tools button {
  height: 30px;
  padding: 0 10px;
  font-size: 12px;
}

.preview {
  flex: 1;
  min-height: 0;
  width: 100%;
  max-width: none;
  margin: 0;
  padding: 26px 22px 42px;
  background: #fff;
  overflow: auto;
  overflow-wrap: anywhere;
  color: #2a2f36;
  box-shadow: inset 0 1px 0 #f0f2f5;
}

.preview:empty::before {
  content: "排版结果会显示在这里";
  color: var(--muted);
}

.preview img {
  cursor: pointer;
}

.preview .selected-image {
  outline: 3px solid rgba(22, 115, 95, 0.28);
  outline-offset: 4px;
}

@media (max-width: 1280px) {
  .editor-grid {
    grid-template-columns: minmax(0, 1fr) minmax(310px, 0.55fr);
  }

  .preview-panel {
    grid-column: 1 / -1;
    min-height: 520px;
    max-height: none;
  }
}

@media (max-width: 900px) {
  .shell {
    padding: 10px;
  }

  .topbar,
  .editor-grid {
    grid-template-columns: 1fr;
  }

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

  .editor-grid {
    display: grid;
  }

  .panel {
    min-height: auto;
    max-height: none;
  }

  #rawText {
    min-height: 320px;
    resize: vertical;
  }

  .panel-head {
    align-items: stretch;
    flex-direction: column;
  }

  .actions {
    width: 100%;
  }

  .actions button,
  .top-actions button,
  .file-row button {
    width: 100%;
  }

  .preview-head-actions {
    width: 100%;
    justify-content: flex-start;
  }

  .file-row {
    grid-template-columns: 1fr;
  }

  .crop-actions {
    grid-template-columns: 1fr;
  }

  .panel-head input {
    max-width: none;
  }
}
