:root {
  color-scheme: light;
  --navy: #087ff5;
  --navy-deep: #0758c7;
  --navy-soft: #e8f4ff;
  --orange: #ffaa24;
  --orange-strong: #f79311;
  --canvas: #f1f7fd;
  --surface: #ffffff;
  --surface-soft: #f8fafc;
  --ink: #14233c;
  --muted: #687a95;
  --line: #d7e6f5;
  --line-strong: #bdd3ea;
  --success: #1fa97a;
  --radius: 18px;
}

* { box-sizing: border-box; }

html {
  min-width: 320px;
  background: var(--canvas);
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background: var(--canvas);
  font-family: "Avenir Next", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}

button,
input,
textarea { font: inherit; }

button { color: inherit; }

button:focus-visible,
input:focus-visible,
textarea:focus-visible,
a:focus-visible {
  outline: 3px solid rgba(255, 170, 36, 0.42);
  outline-offset: 2px;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(14px);
}

.topbar-inner {
  width: min(1780px, 100%);
  min-height: 74px;
  margin: 0 auto;
  padding: 8px 16px;
  display: flex;
  align-items: center;
  gap: clamp(24px, 3vw, 52px);
}

.brand {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--ink);
  text-decoration: none;
}

.brand-logo {
  display: block;
  width: 112px;
  height: auto;
}

.brand-subtitle {
  padding: 6px 10px;
  border-radius: 999px;
  color: var(--navy-deep);
  background: var(--navy-soft);
  font-size: 12px;
  font-weight: 650;
  letter-spacing: 0.03em;
  white-space: nowrap;
}

.document-state {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
}

.live-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--success);
}

.privacy-note {
  margin-left: 2px;
  padding: 5px 9px;
  border-radius: 999px;
  color: #397c66;
  background: #e9f7f1;
  font-size: 10px;
  font-weight: 600;
}

.top-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
}

.button {
  min-height: 44px;
  border: 1px solid transparent;
  border-radius: 11px;
  padding: 0 14px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 650;
  transition: transform 150ms ease, background 150ms ease, border-color 150ms ease;
}

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

.button.ghost {
  border-color: var(--line);
  background: var(--surface-soft);
}

.button.ghost:hover {
  border-color: var(--navy);
  background: var(--surface);
}

.button.primary {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  background: var(--navy);
  color: white;
}

.button.primary:hover { background: var(--navy-deep); }

.button kbd {
  padding: 3px 6px;
  border: 0;
  border-radius: 6px;
  color: white;
  background: rgba(255, 255, 255, 0.18);
  font: 600 10px "DIN Alternate", "Avenir Next", sans-serif;
}

.workspace {
  width: min(1780px, 100%);
  min-height: calc(100vh - 132px);
  margin: 0 auto;
  padding: 16px;
  display: grid;
  grid-template-columns: minmax(360px, 1fr) minmax(230px, 0.5fr) minmax(430px, 1.16fr);
  gap: 14px;
}

.panel {
  min-width: 0;
  min-height: calc(100vh - 164px);
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.panel-heading {
  min-height: 90px;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  padding: 20px 22px 17px;
  border-bottom: 1px solid var(--line);
}

.panel-heading h1,
.panel-heading h2 {
  margin: 5px 0 0;
  font-size: 21px;
  font-weight: 750;
  letter-spacing: -0.02em;
}

.eyebrow {
  color: var(--orange-strong);
  font: 700 10px "DIN Alternate", "Avenir Next", sans-serif;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.text-button {
  min-height: 40px;
  border: 0;
  border-radius: 9px;
  padding: 0 10px;
  color: var(--navy);
  background: var(--navy-soft);
  cursor: pointer;
  font-size: 11px;
  font-weight: 650;
}

.text-button:hover { background: #d8ecff; }

.editor-panel {
  display: flex;
  flex-direction: column;
}

.editor-toolbar {
  min-height: 48px;
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 7px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-soft);
}

.editor-toolbar button {
  width: 44px;
  height: 44px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  cursor: pointer;
  font: 650 11px "Avenir Next", sans-serif;
}

.editor-toolbar button:hover {
  border-color: #b9d8f5;
  color: var(--navy);
  background: var(--navy-soft);
}

.toolbar-rule {
  width: 1px;
  height: 18px;
  margin: 0 7px;
  background: var(--line-strong);
}

.markdown-tip {
  margin-left: auto;
  color: var(--muted);
  font-size: 10px;
  font-weight: 550;
}

#markdownInput {
  width: 100%;
  flex: 1;
  min-height: 570px;
  resize: none;
  border: 0;
  outline: 0;
  padding: 28px clamp(24px, 2.5vw, 40px) 48px;
  color: #1e3351;
  background: var(--surface);
  font-family: "LXGW WenKai", "Kaiti SC", "STKaiti", "PingFang SC", sans-serif;
  font-size: 15px;
  line-height: 1.95;
  tab-size: 2;
}

.editor-stats {
  min-height: 42px;
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 0 20px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  background: var(--surface-soft);
  font-size: 10px;
}

.editor-stats b { color: var(--navy); }

.settings-panel { padding-bottom: 20px; }

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

.theme-card {
  position: relative;
  width: 100%;
  min-height: 66px;
  display: grid;
  grid-template-columns: 38px 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border: 1px solid transparent;
  border-radius: 12px;
  background: var(--surface-soft);
  text-align: left;
  cursor: pointer;
  transition: transform 150ms ease, border-color 150ms ease, background 150ms ease;
}

.theme-card:hover {
  transform: translateX(2px);
  border-color: var(--line-strong);
}

.theme-card[aria-checked="true"] {
  border-color: #69afff;
  background: var(--navy-soft);
}

.theme-swatch {
  width: 38px;
  height: 44px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 9px;
  color: var(--theme-color);
  background: var(--theme-bg);
  font: 700 10px "DIN Alternate", sans-serif;
}

.theme-card[aria-checked="true"] .theme-swatch {
  color: var(--theme-contrast, white);
  background: var(--theme-color);
}

.theme-copy b {
  display: block;
  margin-bottom: 3px;
  font-size: 12px;
}

.theme-copy small {
  display: block;
  color: var(--muted);
  font-size: 9px;
  line-height: 1.4;
}

.theme-check {
  width: 17px;
  height: 17px;
  border: 2px solid var(--line-strong);
  border-radius: 50%;
  background: var(--surface);
}

.theme-card[aria-checked="true"] .theme-check {
  border: 5px solid var(--navy);
}

.settings-rule {
  height: 1px;
  margin: 8px 18px 18px;
  background: var(--line);
}

.meta-fields {
  display: grid;
  gap: 14px;
  padding: 0 18px;
}

.meta-fields label > span {
  display: block;
  margin-bottom: 7px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 650;
}

.meta-fields input {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 10px;
  outline: 0;
  padding: 0 11px;
  color: var(--ink);
  background: var(--surface-soft);
  font-size: 12px;
}

.meta-fields input:focus {
  border-color: var(--navy);
  background: var(--surface);
}

.toggle-row {
  margin: 20px 18px 0;
  padding: 14px;
  border-radius: 12px;
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 12px;
  background: var(--surface-soft);
  cursor: pointer;
}

.toggle-row > span:first-child { grid-row: 1; }
.toggle-row b { display: block; font-size: 12px; }
.toggle-row small { display: block; margin-top: 3px; color: var(--muted); font-size: 9px; }
.toggle-row input { position: absolute; opacity: 0; pointer-events: none; }

.toggle {
  grid-column: 2;
  grid-row: 1;
  width: 40px;
  height: 22px;
  border-radius: 20px;
  background: #c5d7e8;
  padding: 3px;
  transition: background 160ms ease;
}

.toggle::after {
  content: "";
  display: block;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: white;
  transition: transform 160ms ease;
}

.toggle-row input:checked + .toggle { background: var(--navy); }
.toggle-row input:checked + .toggle::after { transform: translateX(18px); }

.privacy-card {
  margin: 14px 18px 0;
  padding: 13px;
  display: flex;
  gap: 10px;
  align-items: flex-start;
  border-radius: 12px;
  color: #397c66;
  background: #e9f7f1;
}

.privacy-card > span { color: var(--success); font-size: 14px; }
.privacy-card p { margin: 0; font-size: 9px; line-height: 1.6; }
.privacy-card b { color: #25644f; font-size: 11px; }

.preview-panel { background: var(--surface); }

.viewport-switch {
  display: flex;
  gap: 3px;
  padding: 3px;
  border-radius: 10px;
  background: var(--surface-soft);
}

.viewport-switch button {
  min-height: 36px;
  border: 0;
  border-radius: 8px;
  padding: 0 10px;
  background: transparent;
  cursor: pointer;
  font-size: 10px;
  font-weight: 650;
}

.viewport-switch button.active {
  color: white;
  background: var(--navy);
}

.proof-stage {
  min-height: calc(100vh - 254px);
  padding: 24px clamp(18px, 3vw, 44px) 44px;
  overflow: auto;
  background: #e6f2fc;
}

.proof-label {
  width: min(100%, 430px);
  margin: 0 auto 9px;
  display: flex;
  justify-content: space-between;
  color: var(--muted);
  font: 700 9px "DIN Alternate", "Avenir Next", sans-serif;
  letter-spacing: 0.08em;
  transition: width 220ms ease;
}

.preview-frame {
  width: min(100%, 430px);
  min-height: 720px;
  margin: 0 auto;
  padding: 18px 16px 36px;
  overflow: hidden;
  border: 1px solid var(--line-strong);
  border-radius: 14px;
  background: white;
  transition: width 220ms ease;
}

.proof-stage.wide .preview-frame,
.proof-stage.wide .proof-label { width: min(100%, 677px); }
.preview-frame img { max-width: 100%; }

.mobile-tabs { display: none; }

.site-footer {
  min-height: 48px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 10px clamp(18px, 2.4vw, 40px);
  color: var(--muted);
  font-size: 9px;
}

.site-footer > span:first-child {
  color: var(--navy);
  font-weight: 700;
}

.site-footer a { color: var(--navy); }

.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  z-index: 40;
  transform: translate(-50%, 16px);
  padding: 11px 17px;
  border-radius: 12px;
  background: var(--navy-deep);
  color: white;
  font-size: 12px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 180ms ease, transform 180ms ease;
}

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

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

.panel { animation: enter-panel 360ms ease both; }
.settings-panel { animation-delay: 55ms; }
.preview-panel { animation-delay: 110ms; }

@media (max-width: 1240px) {
  .document-state { display: none; }
  .workspace { grid-template-columns: minmax(330px, 0.9fr) 220px minmax(390px, 1.1fr); }
  .brand-subtitle { display: none; }
  .button kbd { display: none; }
  .button.primary { gap: 0; }
}

@media (max-width: 900px) {
  body { padding-bottom: 68px; }
  .topbar { position: relative; }
  .topbar-inner { min-height: 64px; padding: 6px 14px; }
  .brand-logo { width: 96px; }
  .top-actions .ghost { display: none; }
  .button.primary { min-height: 44px; padding: 0 12px; }
  .workspace { display: block; min-height: auto; padding: 10px; }
  .panel { display: none; min-height: calc(100vh - 156px); border-radius: 16px; }
  .panel.mobile-active { display: flex; }
  .settings-panel.mobile-active,
  .preview-panel.mobile-active { display: block; }
  .panel-heading { min-height: 78px; padding: 15px 17px 13px; }
  .panel-heading h1,
  .panel-heading h2 { font-size: 19px; }
  #markdownInput { min-height: calc(100vh - 316px); padding: 22px 22px 44px; }
  .theme-list { grid-template-columns: repeat(2, minmax(0, 1fr)); padding: 14px; }
  .theme-card { grid-template-columns: 34px 1fr; }
  .theme-check { display: none; }
  .proof-stage { min-height: 0; padding-bottom: 28px; }
  .mobile-tabs {
    position: fixed;
    left: 50%;
    bottom: 12px;
    z-index: 30;
    transform: translateX(-50%);
    width: min(350px, calc(100% - 28px));
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 4px;
    padding: 5px;
    border: 1px solid #328dff;
    border-radius: 15px;
    background: var(--navy-deep);
  }
  .mobile-tabs button {
    min-height: 44px;
    border: 0;
    border-radius: 10px;
    color: #d8e8ff;
    background: transparent;
    cursor: pointer;
    font-size: 12px;
    font-weight: 650;
  }
  .mobile-tabs button.active { color: var(--navy-deep); background: var(--orange); }
  .site-footer { display: none; }
}

@media (max-width: 520px) {
  .brand-logo { width: 92px; }
  .button.primary span { font-size: 11px; }
  .theme-list { grid-template-columns: 1fr; }
  .theme-card { grid-template-columns: 38px 1fr auto; }
  .theme-check { display: block; }
  .proof-stage { padding: 18px 9px 28px; }
  .preview-frame { padding: 12px 8px 28px; border-radius: 12px; }
  .privacy-note { display: none; }
  .markdown-tip,
  .toolbar-rule { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
