:root {
  color: #171716;
  background: #fff;
  font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", system-ui, sans-serif;
  font-synthesis: none;
  --sidebar-w: 156px;
  --template-w: 116px;
  --topbar-h: 48px;
  --panel-gap: 16px;
  --accent: #ff4a35;
  --line: #e8e4df;
  --muted: #77716a;
  --preview-width: 387px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
button, textarea { font: inherit; }
button { -webkit-tap-highlight-color: transparent; }

body {
  margin: 0;
  width: 100vw;
  height: 100vh;
  min-width: 980px;
  min-height: 620px;
  overflow: hidden;
  color: #171716;
  background: #fff;
}

.topbar {
  position: fixed;
  top: 0;
  right: 0;
  left: calc(var(--sidebar-w) + var(--template-w));
  z-index: 40;
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  padding: 0 20px;
  background: rgba(255,255,255,.96);
  border-bottom: 1px solid #ece8e3;
}
.topbar strong { color: #111; font-size: 14px; font-weight: 900; }
.account-state {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-left: auto;
  color: #827b74;
  font-size: 12px;
  font-weight: 700;
}
.account-state a,
.account-state button {
  min-height: 30px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 13px;
  color: #fff;
  background: #1f1e1c;
  border: 0;
  border-radius: 8px;
  text-decoration: none;
  cursor: pointer;
  font-size: 12px;
  font-weight: 850;
}
.account-state button { color: #5f5953; background: #f4f1ed; }

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 50;
  width: var(--sidebar-w);
  display: flex;
  flex-direction: column;
  padding: 24px 12px 22px;
  background: #fff;
  border-right: 1px solid #eee9e3;
}
.studio-brand {
  min-height: 34px;
  display: flex;
  align-items: center;
  margin: 0 4px 28px;
  color: #111;
  text-decoration: none;
  white-space: nowrap;
  font-size: 16px;
  font-weight: 900;
  letter-spacing: -.02em;
}
.studio-brand img { width: 124px; height: auto; max-height: 34px; object-fit: contain; flex: 0 0 auto; }
.workspace-nav { display: grid; gap: 9px; }
.nav-item {
  width: 100%;
  height: 44px;
  display: flex;
  align-items: center;
  padding: 0 13px;
  color: #282828;
  background: transparent;
  border: 0;
  border-radius: 12px;
  text-decoration: none;
  cursor: pointer;
  font-size: 13px;
  text-align: left;
}
.nav-item strong { font-weight: 780; white-space: nowrap; }
.nav-icon {
  width: 22px;
  height: 22px;
  flex: 0 0 22px;
  display: grid;
  place-items: center;
  margin-right: 10px;
  color: #5d6167;
  font-size: 15px;
  line-height: 1;
}
.nav-item:hover { background: rgba(255,241,234,.72); }
.nav-item.active { color: var(--accent); background: #fff1ea; }
.nav-item.active .nav-icon { color: var(--accent); }
.nav-favorite { margin-top: auto; }

.template-dock {
  position: fixed;
  inset: 0 auto 0 var(--sidebar-w);
  z-index: 46;
  width: var(--template-w);
  background: #fff;
  border-right: 1px solid #eee9e3;
  overflow: hidden;
}
.template-dock > header {
  position: absolute;
  top: 0;
  left: 12px;
  right: 12px;
  z-index: 2;
  height: 72px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 13px;
  background: #fff;
}
.template-dock > header strong { color: #171716; font-size: 15px; font-weight: 900; }
.template-dock > header button {
  width: 21px;
  height: 21px;
  padding: 0;
  color: #302f2d;
  background: transparent;
  border: 0;
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
}
.template-strip {
  position: absolute;
  inset: 72px 0 18px;
  display: grid;
  grid-auto-rows: max-content;
  grid-template-columns: 1fr;
  align-content: start;
  justify-items: center;
  gap: 13px;
  padding: 0 12px 4px;
  overflow-x: hidden;
  overflow-y: auto;
  scroll-snap-type: y proximity;
}
.template-card {
  position: relative;
  width: 86px;
  height: 112px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  padding: 0;
  isolation: isolate;
  background: transparent;
  border: 0;
  border-radius: 15px;
  cursor: pointer;
  scroll-snap-align: start;
  transition: transform .16s ease, background .16s ease, box-shadow .16s ease;
}
.template-card img {
  display: block;
  width: 78px;
  height: 100px;
  object-fit: cover;
  border: 1px solid #eee7df;
  border-radius: 9px;
  background: #fff;
  box-shadow: 0 8px 18px rgba(32,27,20,.055);
  transition: transform .16s ease, border-color .16s ease, box-shadow .16s ease;
}
.template-card:not(.active):hover { transform: translateY(-1px); background: rgba(255,248,244,.68); }
.template-card:not(.active):hover img { transform: scale(1.012); border-color: #f0cbbd; box-shadow: 0 14px 28px rgba(48,36,28,.095); }
.template-card.active { background: rgba(255,249,246,.54); box-shadow: inset 0 0 0 1px rgba(255,91,66,.06); }
.template-card.active::before {
  content: "";
  position: absolute;
  top: 6px;
  right: 4px;
  z-index: 4;
  width: 28px;
  height: 28px;
  border-radius: 0 8px 0 10px;
  background: linear-gradient(135deg,#ff765f 0%,#ff4f3a 58%,#ed3a2e 100%);
  clip-path: polygon(100% 0,100% 100%,0 0);
}
.template-card.active::after {
  content: "✓";
  position: absolute;
  top: 8px;
  right: 7px;
  z-index: 5;
  width: 12px;
  height: 12px;
  color: #fff;
  font-size: 9px;
  font-weight: 950;
  line-height: 12px;
  text-align: center;
}
.template-card.active img { border-color: #f0e4dc; box-shadow: inset -2px 0 0 rgba(255,77,56,.78),inset 0 2px 0 rgba(255,77,56,.7),0 10px 22px rgba(48,36,28,.09); }
.template-tier {
  position: absolute;
  top: 7px;
  left: 7px;
  z-index: 6;
  min-width: 28px;
  height: 17px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 5px;
  border-radius: 999px;
  box-shadow: 0 3px 9px rgba(28,25,22,.12);
  font-size: 8px;
  font-weight: 900;
  line-height: 17px;
  letter-spacing: .02em;
  pointer-events: none;
}
.template-tier.free {
  color: #236b4a;
  background: rgba(238,251,244,.96);
  border: 1px solid rgba(53,145,99,.28);
}
.template-tier.premium {
  color: #fff;
  background: rgba(35,33,30,.92);
  border: 1px solid rgba(255,255,255,.26);
}

.workspace-main {
  width: 100vw;
  height: 100vh;
  display: grid;
  grid-template-columns: minmax(390px,520px) minmax(560px,1fr);
  grid-template-rows: minmax(0,1fr);
  gap: var(--panel-gap);
  padding: calc(var(--topbar-h) + 14px) 20px 20px calc(var(--sidebar-w) + var(--template-w) + 16px);
  overflow: hidden;
  background: #fff;
}
.editor-panel, .preview-panel {
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 16px;
}
.editor-panel { display: grid; grid-template-rows: 50px minmax(0,1fr) auto auto auto; }
.editor-toolbar {
  min-width: 0;
  height: 50px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 20px;
  background: #fff;
  border-bottom: 1px solid #eee9e3;
  overflow: hidden;
}
.editor-toolbar > strong { flex: 0 0 auto; margin-right: 6px; color: #161616; font-size: 14px; font-weight: 900; white-space: nowrap; }
.formatbar {
  min-width: 0;
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  gap: 2px;
  overflow-x: auto;
  scrollbar-width: none;
}
.formatbar::-webkit-scrollbar { display: none; }
.formatbar button {
  width: 28px;
  height: 28px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  padding: 0;
  color: #6f6962;
  background: transparent;
  border: 0;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 850;
  line-height: 1;
}
.formatbar button:hover, .formatbar button:focus-visible { outline: 0; color: #1d1d1f; background: #f5f1ec; }
.formatbar .bold-tool { font-family: Georgia, serif; font-size: 15px; }
.formatbar .url-tool { width: 52px; font-size: 11px; }
.formatbar > i { width: 1px; height: 18px; flex: 0 0 1px; margin: 0 4px; background: #ece6df; }
.formatbar svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

#markdown {
  display: block;
  width: 100%;
  min-height: 0;
  padding: 22px 26px;
  resize: none;
  color: #171716;
  background: #fff;
  border: 0;
  outline: 0;
  font: 500 14px/25.48px "SFMono-Regular","SF Mono","Fira Code",Menlo,Consolas,"PingFang SC",monospace;
  caret-color: var(--accent);
}

.cover-settings {
  display: grid;
  gap: 10px;
  padding: 14px 20px 16px;
  background: #fff;
  border-top: 1px solid #eee9e3;
}
.cover-settings-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}
.cover-settings-head strong { color: #2a2927; font-size: 13px; font-weight: 900; }
.cover-settings-head span { color: #938d86; font-size: 10px; font-weight: 700; }
.cover-drop-zone {
  min-width: 0;
  min-height: 58px;
  display: grid;
  grid-template-columns: 46px minmax(0,1fr) auto;
  align-items: center;
  gap: 11px;
  padding: 8px 11px;
  background: #fafbfe;
  border: 1px solid #dedfe4;
  border-radius: 13px;
  cursor: pointer;
  transition: border-color .16s ease,background .16s ease,box-shadow .16s ease;
}
.cover-drop-zone:hover,
.cover-drop-zone:focus-visible,
.cover-drop-zone.is-over {
  outline: 0;
  background: #fff9f6;
  border-color: #f1a38f;
  box-shadow: 0 0 0 3px rgba(255,74,53,.08);
}
.cover-thumb {
  width: 46px;
  height: 34px;
  background-color: #ece9e5;
  background-image: url('/assets/default-cover.svg');
  background-position: center;
  background-size: cover;
  border: 1px solid rgba(40,36,31,.08);
  border-radius: 8px;
  box-shadow: 0 4px 10px rgba(32,27,20,.08);
}
.cover-thumb.is-empty { background-image: none !important; box-shadow: none; }
.cover-drop-copy { min-width: 0; display: grid; gap: 2px; }
.cover-drop-copy strong,
.cover-drop-copy span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cover-drop-copy strong { color: #55514d; font-size: 11px; font-weight: 850; }
.cover-drop-copy span { color: #918a83; font-size: 10px; font-weight: 650; }
.cover-remove {
  min-width: 66px;
  padding: 7px 8px;
  color: #a25445;
  background: transparent;
  border: 0;
  border-radius: 8px;
  cursor: pointer;
  font-size: 11px;
  font-weight: 850;
  white-space: nowrap;
}
.cover-remove:hover { background: #fff0eb; }
.cover-url-row { min-width: 0; display: grid; grid-template-columns: minmax(0,1fr) auto; gap: 9px; }
.cover-url-row input {
  width: 100%;
  min-width: 0;
  height: 34px;
  padding: 0 11px;
  color: #292725;
  background: #fff;
  border: 1px solid #e4dfda;
  border-radius: 10px;
  outline: 0;
  font-size: 11px;
}
.cover-url-row input:focus { border-color: #ef8a73; box-shadow: 0 0 0 3px rgba(255,74,53,.07); }
.cover-url-row button {
  height: 34px;
  padding: 0 12px;
  color: #34312e;
  background: #fff;
  border: 1px solid #dfdad4;
  border-radius: 10px;
  cursor: pointer;
  font-size: 11px;
  font-weight: 850;
  white-space: nowrap;
}
.cover-url-row button:disabled { opacity: .55; cursor: wait; }

.layout-settings {
  min-height: 62px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 11px 20px;
  background: #fff;
  border-top: 1px solid #eee9e3;
}
.layout-settings-copy { min-width: 0; display: grid; gap: 3px; }
.layout-settings-copy strong { color: #2a2927; font-size: 13px; font-weight: 900; }
.layout-settings-copy span {
  overflow: hidden;
  color: #918a83;
  font-size: 10px;
  font-weight: 650;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.layout-segment {
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: repeat(2,52px);
  gap: 3px;
  padding: 3px;
  background: #f3f1ee;
  border: 1px solid #ebe7e2;
  border-radius: 11px;
}
.layout-segment button {
  height: 31px;
  padding: 0 10px;
  color: #89837c;
  background: transparent;
  border: 0;
  border-radius: 8px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 900;
  transition: color .15s ease,background .15s ease,box-shadow .15s ease,transform .15s ease;
}
.layout-segment button:hover { color: #3b3834; }
.layout-segment button:focus-visible { outline: 2px solid rgba(255,74,53,.34); outline-offset: 1px; }
.layout-segment button.active {
  color: #fff;
  background: #262522;
  box-shadow: 0 5px 12px rgba(31,29,26,.18);
}
.layout-segment button.active:active { transform: translateY(1px); }

.identity-zone {
  position: relative;
  min-height: 81px;
  display: grid;
  grid-template-columns: 36px minmax(0,1fr) 108px 40px;
  align-items: center;
  gap: 12px;
  margin: 0;
  padding: 21px 32px;
  background: #fff;
  border-top: 1px solid #eee9e3;
}
.identity-zone::before {
  content: "";
  position: absolute;
  inset: 12px 20px;
  border: 1px solid #e8e4df;
  border-radius: 12px;
  pointer-events: none;
}
.identity-avatar {
  z-index: 1;
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border: 1px solid #ece6df;
  border-radius: 50%;
  background: #fffdf9;
  overflow: hidden;
}
.identity-avatar svg { width: 30px; height: 30px; fill: #fff; stroke: #242321; stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }
.identity-avatar svg circle { fill: #242321; stroke: none; }
.identity-copy { z-index: 1; display: grid; gap: 3px; min-width: 0; }
.identity-copy strong { overflow: hidden; color: #242321; font-size: 13px; font-weight: 900; text-overflow: ellipsis; white-space: nowrap; }
.identity-copy span { color: #8a8580; font-size: 11px; font-weight: 700; }
.identity-switch {
  z-index: 1;
  width: 108px;
  min-width: 108px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 13px;
  color: #272521;
  background: #fff;
  border: 1px solid #e7e1da;
  border-radius: 11px;
  cursor: pointer;
  box-shadow: 0 6px 15px rgba(30,26,20,.04);
  font-size: 13px;
  font-weight: 850;
}
.identity-switch svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.identity-switch span { white-space: nowrap; }
.identity-edit {
  z-index: 1;
  width: 40px;
  height: 36px;
  display: grid;
  place-items: center;
  padding: 0;
  color: #302e2a;
  background: #fff;
  border: 1px solid #e7e1da;
  border-radius: 11px;
  cursor: pointer;
}
.identity-edit svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.preview-panel { display: grid; grid-template-rows: 50px minmax(0,1fr) 48px; }
.preview-head {
  height: 50px;
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 0 18px 0 20px;
  background: #fff;
  border-bottom: 1px solid #eee9e3;
}
.preview-head > strong { overflow: hidden; font-size: 14px; font-weight: 900; text-overflow: ellipsis; white-space: nowrap; }
.preview-actions { display: flex; align-items: center; justify-content: flex-end; gap: 12px; margin-left: auto; }
.preview-enhance {
  min-width: 0;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}
.preview-enhance-meta {
  min-width: 58px;
  overflow: hidden;
  color: #8e877f;
  font-size: 9px;
  font-weight: 800;
  line-height: 1;
  text-align: right;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.preview-enhance.is-busy .preview-enhance-meta { color: #d56b4c; }
.preview-enhance.has-error .preview-enhance-meta { color: #aa5144; }
.preview-enhance-segment {
  display: grid;
  grid-template-columns: repeat(2,38px);
  gap: 2px;
  padding: 2px;
  background: #f3f1ee;
  border: 1px solid #ebe7e2;
  border-radius: 9px;
}
.preview-enhance-segment button {
  height: 24px;
  padding: 0;
  color: #8a847d;
  background: transparent;
  border: 0;
  border-radius: 7px;
  cursor: pointer;
  font-size: 10px;
  font-weight: 900;
  transition: color .15s ease,background .15s ease,box-shadow .15s ease;
}
.preview-enhance-segment button:hover { color: #35322f; }
.preview-enhance-segment button:focus-visible { outline: 2px solid rgba(255,74,53,.32); outline-offset: 1px; }
.preview-enhance-segment button.active {
  color: #fff;
  background: #302e2b;
  box-shadow: 0 3px 8px rgba(31,29,26,.16);
}
.preview-enhance-segment button:disabled { opacity: .52; cursor: wait; }
.premium-export-state {
  height: 24px;
  display: inline-flex;
  align-items: center;
  padding: 0 8px;
  border: 1px solid #ddd7cf;
  border-radius: 999px;
  color: #6e675f;
  background: #faf8f5;
  font-size: 9px;
  font-weight: 850;
  letter-spacing: .01em;
  white-space: nowrap;
}
.premium-export-state.is-pro {
  color: #276647;
  background: #eef9f2;
  border-color: #b9dec8;
}
.premium-export-state.is-stale {
  color: #9d4d34;
  background: #fff4ee;
  border-color: #efc6b7;
}
.saved-state { display: flex; align-items: center; gap: 5px; color: #5da575; font-size: 12px; font-weight: 900; white-space: nowrap; }
.saved-state i { width: 10px; height: 10px; border-radius: 50%; background: #62af7d; }
.saved-state.dirty { color: #99928b; }.saved-state.dirty i { background: #bab4ad; }
.saved-state.rendering { color: #e06a45; }.saved-state.rendering i { background: #f07a52; animation: status-pulse 1s ease-in-out infinite; }
@keyframes status-pulse { 50% { opacity: .35; } }
.export-button {
  min-width: 104px;
  height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 0 15px;
  color: #fff;
  background: linear-gradient(180deg,#ff513e 0%,#ff3f2e 100%);
  border: 0;
  border-radius: 999px;
  cursor: pointer;
  box-shadow: 0 10px 20px rgba(255,63,46,.18);
  font-size: 12px;
  font-weight: 900;
  white-space: nowrap;
}
.export-button span { font-size: 18px; line-height: 1; }
.export-button:disabled { opacity: .55; cursor: wait; }

.preview-viewport {
  position: relative;
  min-width: 0;
  min-height: 0;
  overflow: auto;
  padding: 20px;
  background: #fff;
  scroll-behavior: smooth;
}
.preview-pages {
  min-width: max-content;
  min-height: 100%;
  display: flex;
  align-items: flex-start;
  gap: 20px;
}
.preview-page {
  width: var(--preview-width);
  flex: 0 0 var(--preview-width);
  margin: 0;
  background: #fff;
  box-shadow: 0 18px 44px rgba(37,31,23,.11);
}
.preview-page img { display: block; width: 100%; height: auto; background: #fff; }
.preview-page figcaption { display: none; }
.placeholder-page { opacity: .24; filter: grayscale(.25); }
.render-status {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 12px;
  color: #67615a;
  background: rgba(250,249,247,.78);
  backdrop-filter: blur(3px);
  font-size: 12px;
}
.render-status span { width: 30px; height: 30px; border: 2px solid #d8d2cb; border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.preview-footer {
  position: relative;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-top: 1px solid #eee9e3;
  background: #fff;
  color: #8f8983;
}
.page-nav, .zoom-nav { display: flex; align-items: center; gap: 13px; }
.page-nav button, .zoom-nav button {
  width: 24px;
  height: 28px;
  display: grid;
  place-items: center;
  padding: 0;
  color: #948e87;
  background: transparent;
  border: 0;
  cursor: pointer;
  font-size: 18px;
}
.page-nav strong, .zoom-nav strong { min-width: 38px; text-align: center; font-size: 13px; font-weight: 800; }
.zoom-nav { position: absolute; right: 24px; gap: 9px; }
.zoom-nav button { font-size: 16px; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 34px;
  z-index: 90;
  transform: translateX(-50%);
  padding: 10px 15px;
  color: #fff;
  background: rgba(23,23,22,.92);
  border-radius: 10px;
  box-shadow: 0 12px 32px rgba(0,0,0,.16);
  font-size: 12px;
  font-weight: 750;
}

::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-thumb { background: rgba(128,128,128,.18); border-radius: 3px; }

@media (max-height: 860px) {
  :root { --sidebar-w: 144px; --template-w: 104px; --topbar-h: 44px; }
  .studio-brand { margin-bottom: 24px; font-size: 15px; }
  .template-dock > header { height: 60px; }
  .template-strip { inset: 60px 0 14px; gap: 10px; padding: 0 10px 4px; }
  .template-card { width: 76px; height: 98px; }
  .template-card img { width: 70px; height: 90px; }
  .workspace-main { grid-template-columns: minmax(360px,480px) minmax(560px,1fr); padding-top: calc(var(--topbar-h) + 12px); }
  .cover-settings { gap: 7px; padding: 10px 16px 11px; }
  .cover-drop-zone { min-height: 50px; padding-block: 6px; }
  .layout-settings { min-height: 56px; padding: 8px 16px; }
}

@media (max-width: 1180px) {
  :root { --sidebar-w: 132px; --template-w: 98px; }
  body { min-width: 760px; overflow: auto; }
  .workspace-main { height: auto; min-height: 100vh; grid-template-columns: 1fr; grid-template-rows: minmax(540px,55vh) minmax(600px,1fr); padding-left: calc(var(--sidebar-w) + var(--template-w) + 14px); overflow: auto; }
  .preview-panel { grid-column: 1; grid-row: 2; min-height: 600px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; scroll-behavior: auto !important; transition-duration: .01ms !important; }
}
