:root {
  --canvas: #e7ecea;
  --canvas-deep: #d4dedb;
  --paper: #fcfdfa;
  --ink: #1a2522;
  --ink-soft: #63706c;
  --line: #cbd6d2;
  --accent: #234f78;
  --accent-strong: #173b5c;
  --accent-wash: #e2edf3;
  --success: #1d614d;
  --danger: #a34332;
  --shadow: 0 26px 70px rgba(29, 50, 44, 0.13);
  --serif: "Iowan Old Style", "Palatino Linotype", "Noto Serif SC", "Songti SC", serif;
  --sans: "Avenir Next", "Segoe UI", "Microsoft YaHei", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--canvas);
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 14% 4%, rgba(255, 255, 255, 0.82), transparent 29rem),
    linear-gradient(118deg, var(--canvas), var(--canvas-deep));
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
}

button,
input {
  font: inherit;
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

a {
  color: var(--accent);
}

button:focus-visible,
a:focus-visible,
[contenteditable]:focus-visible,
input:focus-visible {
  outline: 3px solid rgba(35, 79, 120, 0.28);
  outline-offset: 3px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.site-header {
  position: relative;
  z-index: 3;
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: min(1120px, calc(100% - 36px));
  min-height: 78px;
  margin: 0 auto;
}

.wordmark {
  display: inline-flex;
  gap: 11px;
  align-items: center;
  color: var(--ink);
  font-size: 17px;
  font-weight: 700;
  letter-spacing: 0.01em;
  text-decoration: none;
}

.wordmark-mark {
  width: 16px;
  height: 22px;
  border: 2px solid var(--accent);
  border-radius: 2px 7px 2px 2px;
  background: linear-gradient(160deg, transparent 55%, var(--accent-wash) 56%);
  transform: rotate(-4deg);
}

.header-actions {
  display: flex;
  gap: 20px;
  align-items: center;
  color: var(--ink-soft);
  font-size: 14px;
}

.quiet-link {
  color: var(--ink-soft);
  text-decoration: none;
}

.quiet-link:hover {
  color: var(--accent);
}

.save-state {
  color: var(--ink-soft);
  font-size: 13px;
}

.paper {
  position: relative;
  background: var(--paper);
  border: 1px solid rgba(105, 126, 119, 0.2);
  box-shadow: var(--shadow);
}

.paper-tab {
  position: absolute;
  top: -1px;
  left: 42px;
  width: 72px;
  height: 4px;
  background: var(--accent);
}

.editor-shell {
  display: grid;
  grid-template-columns: minmax(0, 780px) 110px;
  justify-content: center;
  align-items: start;
  gap: 0;
  width: min(1120px, calc(100% - 36px));
  margin: 12px auto 40px;
}

.editor-paper {
  min-height: min(760px, calc(100vh - 155px));
  padding: clamp(34px, 6vw, 72px) clamp(24px, 7vw, 88px) 36px;
}

.title-input,
.author-input {
  display: block;
  width: 100%;
  padding: 0;
  color: var(--ink);
  background: transparent;
  border: 0;
}

.title-input {
  min-height: 1.18em;
  font-family: var(--serif);
  font-size: clamp(42px, 7vw, 68px);
  font-weight: 700;
  line-height: 1.08;
  letter-spacing: -0.032em;
}

.author-input {
  margin-top: 14px;
  color: var(--ink-soft);
  font-size: 16px;
}

.title-input::placeholder,
.author-input::placeholder {
  color: #a4afab;
}

.editor-toolbar {
  position: sticky;
  top: 8px;
  z-index: 2;
  display: flex;
  gap: 4px;
  align-items: center;
  margin: 30px -10px 18px;
  padding: 7px 10px;
  overflow-x: auto;
  background: color-mix(in srgb, var(--paper) 92%, transparent);
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(12px);
}

.editor-toolbar button {
  flex: 0 0 auto;
  min-height: 34px;
  padding: 5px 10px;
  color: var(--ink-soft);
  background: transparent;
  border: 0;
  border-radius: 5px;
  cursor: pointer;
}

.editor-toolbar button:hover {
  color: var(--ink);
  background: var(--accent-wash);
}

.editor-toolbar .publish-button {
  min-width: 74px;
  color: #fff;
  background: var(--accent);
  font-weight: 650;
}

.editor-toolbar .publish-button:hover {
  color: #fff;
  background: var(--accent-strong);
}

.toolbar-spacer {
  flex: 1;
}

.editor-status {
  min-height: 20px;
  margin: -8px 0 8px;
  color: var(--ink-soft);
  font-size: 13px;
}

.editor-content,
.article-content {
  font-family: var(--serif);
  font-size: clamp(19px, 2.1vw, 22px);
  line-height: 1.72;
  overflow-wrap: anywhere;
}

.editor-content {
  min-height: 350px;
  padding-bottom: 50px;
}

.editor-content:empty::before {
  color: #a4afab;
  content: attr(data-placeholder);
  pointer-events: none;
}

.editor-content h2,
.article-content h2 {
  margin: 1.55em 0 0.55em;
  font-size: 1.58em;
  line-height: 1.25;
}

.editor-content h3,
.article-content h3 {
  margin: 1.4em 0 0.45em;
  font-size: 1.24em;
}

.editor-content blockquote,
.article-content blockquote {
  margin: 1.35em 0;
  padding: 0.2em 0 0.2em 1.15em;
  color: var(--ink-soft);
  border-left: 3px solid var(--accent);
}

.editor-content figure,
.article-content figure {
  margin: 1.7em 0;
}

.editor-content img,
.editor-content video,
.article-content img,
.article-content video {
  display: block;
  width: auto;
  max-width: 100%;
  max-height: 78vh;
  border-radius: 3px;
}

.editor-content a,
.article-content a {
  text-decoration-thickness: 1px;
  text-underline-offset: 0.18em;
}

.editor-content pre,
.article-content pre {
  max-width: 100%;
  padding: 16px;
  overflow: auto;
  color: #e8efed;
  background: #26322f;
  border-radius: 5px;
  font-family: "Cascadia Code", "SFMono-Regular", Consolas, monospace;
  font-size: 14px;
  line-height: 1.55;
}

.editor-help {
  margin: 30px 0 0;
  color: var(--ink-soft);
  font-size: 13px;
}

.editor-margin {
  display: flex;
  flex-direction: column;
  gap: 11px;
  padding: 42px 0 0 24px;
  color: #82908b;
  font-family: var(--serif);
  font-size: 12px;
  font-style: italic;
}

.editor-margin span:nth-child(2) {
  padding-left: 18px;
}

.editor-margin span:nth-child(3) {
  padding-left: 7px;
}

.notice {
  width: min(760px, calc(100% - 36px));
  margin: 0 auto 16px;
  padding: 12px 16px;
  border: 1px solid;
  border-radius: 5px;
  font-size: 14px;
}

.editor-paper .notice {
  width: auto;
  margin: -16px 0 22px;
}

.notice-success {
  color: var(--success);
  background: #e7f3ed;
  border-color: #bcdacd;
}

.notice-error {
  color: var(--danger);
  background: #faeee9;
  border-color: #e8c6bb;
}

.article-shell {
  width: min(820px, calc(100% - 36px));
  margin: 18px auto 46px;
}

.article-paper {
  padding: clamp(38px, 7vw, 72px) clamp(24px, 8vw, 96px) 42px;
}

.article-header {
  padding-bottom: 30px;
  margin-bottom: 34px;
  border-bottom: 1px solid var(--line);
}

.article-header h1 {
  margin: 0;
  font-family: var(--serif);
  font-size: clamp(42px, 7vw, 64px);
  line-height: 1.08;
  letter-spacing: -0.03em;
  text-wrap: balance;
}

.article-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 18px;
  margin: 18px 0 0;
  color: var(--ink-soft);
  font-size: 14px;
}

.article-meta span + time::before {
  content: "/";
  margin-right: 18px;
  color: var(--line);
}

.article-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  padding-top: 28px;
  margin-top: 38px;
  border-top: 1px solid var(--line);
}

.action-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  padding: 8px 15px;
  color: var(--ink);
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 5px;
  font-size: 14px;
  text-decoration: none;
  cursor: pointer;
}

.action-button:hover {
  border-color: var(--accent);
}

.action-button-primary {
  color: #fff;
  background: var(--accent);
  border-color: var(--accent);
}

.action-button-primary:hover {
  color: #fff;
  background: var(--accent-strong);
}

.error-shell {
  display: grid;
  place-items: center;
  width: min(760px, calc(100% - 36px));
  min-height: 68vh;
  margin: auto;
}

.error-paper {
  width: 100%;
  padding: clamp(38px, 8vw, 72px);
}

.error-code {
  margin: 0 0 10px;
  color: var(--accent);
  font-family: var(--serif);
  font-size: 18px;
}

.error-paper h1 {
  margin: 0 0 30px;
  font-family: var(--serif);
  font-size: clamp(32px, 6vw, 52px);
  line-height: 1.15;
}

.site-footer {
  display: flex;
  justify-content: space-between;
  width: min(1120px, calc(100% - 36px));
  padding: 18px 0 28px;
  margin: 0 auto;
  color: var(--ink-soft);
  font-size: 12px;
}

@media (max-width: 820px) {
  .site-header {
    min-height: 64px;
  }

  .editor-shell {
    display: block;
    width: min(760px, calc(100% - 20px));
    margin-top: 4px;
  }

  .editor-margin {
    display: none;
  }

  .editor-paper {
    min-height: calc(100vh - 105px);
    padding: 34px 22px 28px;
  }

  .title-input {
    font-size: clamp(38px, 13vw, 56px);
  }

  .editor-toolbar {
    margin-top: 24px;
  }

  .article-shell,
  .notice {
    width: min(760px, calc(100% - 20px));
  }

  .article-paper {
    padding: 36px 22px 30px;
  }

  .article-meta span + time::before {
    display: none;
  }

  .site-footer {
    width: calc(100% - 28px);
  }
}

@media (prefers-color-scheme: dark) {
  :root {
    --canvas: #18211f;
    --canvas-deep: #111917;
    --paper: #202a27;
    --ink: #edf3f0;
    --ink-soft: #9eada7;
    --line: #394640;
    --accent: #7aa9cf;
    --accent-strong: #a0c4e0;
    --accent-wash: #273b49;
    --success: #91d6bb;
    --danger: #efad9c;
    --shadow: 0 26px 70px rgba(0, 0, 0, 0.25);
  }

  body {
    background:
      radial-gradient(circle at 14% 4%, rgba(63, 83, 76, 0.52), transparent 29rem),
      linear-gradient(118deg, var(--canvas), var(--canvas-deep));
  }

  .notice-success {
    color: #b9ead8;
    background: #203b32;
    border-color: #356451;
  }

  .notice-error {
    color: #ffd4c8;
    background: #412a25;
    border-color: #754639;
  }

  .editor-toolbar .publish-button,
  .action-button-primary {
    color: #13201c;
  }
}

@media (prefers-reduced-motion: no-preference) {
  .paper {
    animation: settle 420ms cubic-bezier(0.22, 1, 0.36, 1) both;
  }

  @keyframes settle {
    from {
      opacity: 0;
      transform: translateY(8px);
    }
    to {
      opacity: 1;
      transform: translateY(0);
    }
  }
}
