* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --bg: #fafaf9;
  --card: #fff;
  --border: #e7e5e4;
  --text: #1c1917;
  --muted: #78716c;
  --accent: #b45309;
  --accent-hover: #92400e;
  --accent-light: #fef3c7;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Segoe UI", Roboto, "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); }

/* <main class="app-shell"> 刻意不做 flex 容器：flex item 上的 margin:0 auto 会抑制
   stretch，让只写 max-width 的子元素（.hero）塌缩成 fit-content 而非 1200px。 */

.topnav {
  background: #1c1917; padding: 0.6rem 1.5rem; display: flex;
  align-items: center; justify-content: space-between;
}
.topnav-brand {
  color: #fff; text-decoration: none; font-size: 0.85rem; font-weight: 600;
  display: flex; align-items: center; gap: 0.4rem;
}
.topnav-brand span { color: var(--accent); }
.topnav-back {
  color: rgba(255, 255, 255, 0.6); text-decoration: none; font-size: 0.78rem;
  display: flex; align-items: center; gap: 0.3rem; transition: color 0.15s;
}
.topnav-back:hover { color: #fff; }
.topnav-back svg { width: 14px; height: 14px; }

.hero { max-width: 1480px; margin: 0 auto; padding: 1.75rem 1.5rem 0.5rem; }
.hero h1 { font-size: 1.55rem; font-weight: 800; letter-spacing: -0.03em; margin-bottom: 0.3rem; }
.hero p { color: var(--muted); font-size: 0.95rem; /*max-width: 720px;*/ }
.hero-agent { margin-top: 0.5rem; font-size: 0.85rem; }

/* 三栏：左控制 / 中预览 / 右样式。max-width 1480 是算出来的——840(两侧栏+gap) + 592(中列)
   刚好让 540px 的 stage 不被 fitStageScale() 缩放，两侧还留 26px 呼吸。 */
.workspace {
  max-width: 1480px; margin: 0 auto; padding: 1rem 1.5rem 2rem;
  display: grid; grid-template-columns: 400px minmax(0, 1fr) 400px; gap: 1.25rem;
  grid-template-areas: "left preview right"; align-items: start;
}

/* ---------- 控制面板（左右两栏共用同一套样式） ---------- */
.control-panel { display: flex; flex-direction: column; gap: 1rem; grid-area: left; }
.control-panel-right { grid-area: right; }
.control-section {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1rem 1.1rem; display: flex; flex-direction: column; gap: 0.75rem;
  box-shadow: var(--shadow);
}
.section-heading { display: flex; gap: 0.6rem; align-items: baseline; }
.section-heading span { font-size: 0.72rem; font-weight: 700; color: #d6d3d1; }
.section-heading h2 { font-size: 0.95rem; font-weight: 700; }
.section-heading h2 em { font-style: normal; color: var(--muted); font-weight: 500; font-size: 0.75rem; }
.section-heading p { font-size: 0.75rem; color: var(--muted); margin-top: 0.1rem; }
/* 标题行右侧的小动作按钮（如设置齿轮）：margin-left:auto 推到最右，不动原有 flex 规则 */
.heading-action { margin-left: auto; width: 30px; height: 30px; line-height: 1; font-size: 0.9rem; flex-shrink: 0; align-self: center; }
.importer-settings { display: flex; flex-direction: column; gap: 0.6rem; padding: 0.75rem; border: 1px dashed var(--border); border-radius: 10px; background: var(--bg); }
.importer-settings code { font-size: 0.72rem; background: var(--card); padding: 0.1rem 0.3rem; border-radius: 4px; }
.hidden { display: none !important; }

.segmented { display: flex; background: var(--bg); border-radius: 10px; padding: 3px; gap: 3px; }
.segmented button {
  flex: 1; border: 0; background: transparent; padding: 0.5rem 0.6rem; border-radius: 8px;
  font-size: 0.82rem; color: var(--muted); cursor: pointer; font-family: inherit;
}
.segmented button.active { background: var(--accent); color: #fff; font-weight: 600; }
.segmented.small button { padding: 0.38rem 0.5rem; font-size: 0.76rem; }

.search-row { display: flex; gap: 0.5rem; }
#search {
  flex: 1; border: 1px solid var(--border); border-radius: 10px; padding: 0.55rem 0.75rem;
  font-size: 0.82rem; font-family: inherit; outline: none; background: var(--bg);
}
#search:focus { border-color: var(--accent); background: #fff; }
.icon-button {
  border: 1px solid var(--border); background: var(--card); border-radius: 10px;
  width: 38px; cursor: pointer; font-size: 0.95rem;
}
.icon-button:hover { background: var(--bg); }

.chip-row { display: flex; flex-wrap: wrap; gap: 0.35rem; align-items: center; }
.mini-label { font-size: 0.75rem; color: var(--muted); }
.chip {
  border: 1px solid var(--border); background: var(--card); color: var(--text);
  border-radius: 20px; padding: 0.3rem 0.7rem; font-size: 0.76rem; cursor: pointer; font-family: inherit;
}
.chip:hover { border-color: var(--accent); color: var(--accent); }
.chip em { font-style: normal; color: var(--muted); margin-left: 0.25rem; font-size: 0.7rem; }
.chip.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.chip.active em { color: #fde68a; }

.post-list { list-style: none; display: flex; flex-direction: column; gap: 0.5rem; max-height: 400px; overflow-y: auto; padding-right: 2px; }
.post-item { border: 1px solid var(--border); border-radius: 10px; padding: 0.6rem 0.75rem; cursor: pointer; background: var(--card); }
.post-item:hover { border-color: #d6bb96; }
.post-item.active { border-color: var(--accent); background: #fffbf5; }
.post-item .pi-meta { display: flex; justify-content: space-between; font-size: 0.7rem; color: var(--muted); margin-bottom: 0.25rem; }
.post-item .pi-text { font-size: 0.8rem; line-height: 1.5; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.list-more { font-size: 0.75rem; color: var(--muted); text-align: center; padding: 0.4rem; }

#custom-text {
  border: 1px solid var(--border); border-radius: 10px; padding: 0.75rem; font-size: 0.88rem;
  line-height: 1.6; font-family: inherit; resize: vertical; outline: none; background: var(--bg); width: 100%;
}
#custom-text:focus { border-color: var(--accent); background: #fff; }

.option-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem; }
.option { display: flex; flex-direction: column; gap: 0.35rem; }
.option.full { grid-column: 1 / -1; }
input[type="range"] { width: 100%; accent-color: var(--accent); }

.bg-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 0.5rem; }
.bg-thumb { aspect-ratio: 3 / 4; border-radius: 8px; overflow: hidden; cursor: pointer; border: 2px solid transparent; padding: 0; background: var(--bg); }
.bg-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.bg-thumb.active { border-color: var(--accent); }
.bg-import { display: flex; gap: 0.5rem; }
.file-chip { display: inline-flex; align-items: center; }
#bg-url { flex: 1; border: 1px solid var(--border); border-radius: 20px; padding: 0.3rem 0.75rem; font-size: 0.76rem; font-family: inherit; outline: none; }
.profile-row { display: flex; align-items: center; gap: 0.6rem; }
.profile-avatar { width: 42px; height: 42px; border-radius: 50%; border: 1px solid var(--border); }
.text-input { border: 1px solid var(--border); border-radius: 10px; padding: 0.5rem 0.7rem; font-size: 0.82rem; font-family: inherit; outline: none; background: var(--bg); width: 100%; }
.text-input:focus { border-color: var(--accent); background: #fff; }
.text-input:disabled { opacity: 0.55; cursor: not-allowed; }
.chip:disabled { opacity: 0.55; cursor: not-allowed; }
.agent-prompt { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.7rem; line-height: 1.55; resize: vertical; }

/* ---------- 中间预览 ---------- */
/* min-width:0 —— grid 的 1fr 默认 min-width:auto，超长不换行内容会把列撑破 */
.preview-panel {
  position: sticky; top: 1rem; display: flex; flex-direction: column; grid-area: preview;
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  overflow: hidden; box-shadow: var(--shadow); min-width: 0;
}
.preview-topbar { display: flex; align-items: center; gap: 0.6rem; padding: 0.7rem 1rem; border-bottom: 1px solid var(--border); font-size: 0.8rem; flex-wrap: wrap; }
.preview-topbar .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); }
.drag-hint { font-size: 0.72rem; color: var(--muted); white-space: nowrap; }
.preview-actions { margin-left: auto; display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }
.preview-actions a { color: var(--muted); font-size: 0.74rem; }
.ghost-btn { border: 1px solid var(--border); background: var(--card); border-radius: 8px; padding: 0.42rem 0.7rem; font-size: 0.74rem; cursor: pointer; font-family: inherit; white-space: nowrap; }
.ghost-btn:hover { background: var(--bg); }
.ghost-btn.active { border-color: #fe2c55; color: #fe2c55; }
.primary-btn { border: 0; background: var(--accent); color: #fff; border-radius: 8px; padding: 0.48rem 1rem; font-size: 0.8rem; font-weight: 600; cursor: pointer; font-family: inherit; white-space: nowrap; }
.primary-btn:hover { background: var(--accent-hover); }
.primary-btn:disabled { opacity: 0.5; cursor: wait; }

.stage-wrap { flex: 1; overflow: auto; display: flex; align-items: center; justify-content: center; padding: 1.5rem; background: repeating-conic-gradient(#efedeb 0% 25%, #f8f7f6 0% 50%) 0 0 / 24px 24px; }
.stage { position: relative; width: 540px; height: 720px; flex-shrink: 0; display: flex; align-items: center; justify-content: center; overflow: hidden; box-shadow: 0 18px 50px rgba(28, 25, 23, 0.28); }
.stage.tall { height: 960px; }
.stage.tall .sg-top { top: 88px; }
.stage.tall .sg-label-top { top: 92px; }
.stage-bg { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
/* 背景压暗：盖一层黑，opacity 由 renderCard() 写入。用叠层而非 filter:brightness——
   前者与导出侧 ctx.fillRect(rgba(0,0,0,a)) 是同一套 source-over 混合，预览才能和成品逐像素对齐。
   pointer-events:none 是必须的，否则会吃掉卡片拖拽的指针事件。 */
.stage-dim { position: absolute; inset: 0; background: #000; opacity: 0; pointer-events: none; }

/* 抖音安全区参考线（画布 1080×1440，预览为 1/2 缩放）：顶部 150px、右侧 140px、底部 300px、左侧 60px */
.safe-guides { position: absolute; inset: 0; pointer-events: none; z-index: 5; }
.safe-guides.hidden { display: none; }
.sg-line { position: absolute; }
.sg-top { left: 0; right: 0; top: 75px; border-top: 1.5px dashed rgba(254, 44, 85, 0.85); }
.sg-right { top: 0; bottom: 0; right: 78px; border-right: 1.5px dashed rgba(254, 44, 85, 0.85); }
.sg-bottom { left: 0; right: 0; bottom: 150px; border-bottom: 1.5px dashed rgba(254, 44, 85, 0.85); }
.sg-left { top: 0; bottom: 0; left: 30px; border-left: 1.5px dashed rgba(254, 44, 85, 0.6); }
.sg-label { position: absolute; font-size: 10px; line-height: 1; padding: 3px 6px; border-radius: 4px; background: rgba(254, 44, 85, 0.85); color: #fff; white-space: nowrap; }
.sg-label-top { top: 79px; left: 34px; }
.sg-label-right { right: 74px; top: 50%; transform: translateY(-50%) rotate(90deg); transform-origin: right center; }
.sg-label-bottom { bottom: 154px; left: 34px; }

.stage.card-only { height: auto; min-height: 0; box-shadow: none; overflow: visible; }
.stage.card-only .stage-bg { display: none; }
.stage.card-only .stage-dim { display: none; }   /* 没背景可压，留着会变成一块凭空的黑幕 */
.stage.card-only .tweet-card { box-shadow: 0 18px 50px rgba(28, 25, 23, 0.28); }
.stage .tweet-card.floating { position: absolute; left: 50%; top: 50%; cursor: grab; touch-action: none; margin-left: -4px; }
.stage .tweet-card.floating:active { cursor: grabbing; }
.stage .tweet-card.floating.dragging { user-select: none; }

/* ---------- 推文卡片（保持 X 原生风格，不随站点配色） ---------- */
.tweet-card { position: relative; width: 84%; background: #fff; color: #0f1419; border-radius: 0; padding: 22px 24px; box-shadow: 0 10px 40px rgba(0, 0, 0, 0.35); line-height: 1.3; }
.tc-head { display: flex; align-items: center; gap: 11px; }
.tc-avatar { width: 44px; height: 44px; border-radius: 50%; object-fit: cover; }
.tc-id { flex: 1; min-width: 0; }
.tc-name { font-weight: 700; font-size: 15.5px; display: flex; align-items: center; gap: 4px; }
.tc-badge { width: 17px; height: 17px; }
.tc-handle { color: #536471; font-size: 13.5px; margin-top: 1px; }
.tc-x-brand { display: flex; align-items: center; align-self: flex-start; color: #0f1419; }
.tc-x-logo { width: 20px; height: 20px; }
/* 正文字号：--tc-body-size 是用户滑块定的基准（默认 17px），renderCard() 写进 inline style。
   四档是按文本长度自动降级的相对倍率（原绝对值 17/15/13/11.5 换算而来），
   这样"手动定基准"和"长文自动缩"能叠加，长文不会溢出画框。
   line-height 无单位，自动跟随字号，四档现值原样保留。 */
.tc-body { margin-top: 14px; font-size: var(--tc-body-size, 17px); line-height: 1.62; white-space: pre-wrap; word-break: break-word; }
.tc-body.size-m { font-size: calc(var(--tc-body-size, 17px) * 0.88); line-height: 1.58; }
.tc-body.size-s { font-size: calc(var(--tc-body-size, 17px) * 0.76); line-height: 1.55; }
.tc-body.size-xs { font-size: calc(var(--tc-body-size, 17px) * 0.68); line-height: 1.5; }
.tc-body .tc-link { color: #1d9bf0; }
.tc-metrics { margin-top: 16px; padding-top: 12px; border-top: 1px solid #eff3f4; display: flex; gap: 18px; color: #536471; font-size: 12.5px; }
.tc-metrics span { display: inline-flex; align-items: center; gap: 5px; }
.tc-metrics svg { width: 15px; height: 15px; fill: currentColor; }
.tc-metrics b { color: #0f1419; font-weight: 600; }
.tc-metrics.hidden { display: none; }
.tweet-card.dark { background: #000; color: #e7e9ea; }
.tweet-card.dark .tc-handle { color: #71767b; }
.tweet-card.dark .tc-x-brand { color: #e7e9ea; }
.tweet-card.dark .tc-metrics { border-top-color: #2f3336; color: #71767b; }
.tweet-card.dark .tc-metrics b { color: #e7e9ea; }

.footer { text-align: center; padding: 2rem 1rem; color: var(--muted); font-size: 0.8rem; border-top: 1px solid var(--border); }
.footer a { color: var(--accent); }
.footer p + p { margin-top: 0.5rem; }

/* 三栏放不下时先退两栏：右栏并到左栏下方，预览跨两行保持完整高度 */
@media (max-width: 1279px) {
  .workspace {
    grid-template-columns: 400px minmax(0, 1fr);
    grid-template-areas: "left preview" "right preview";
  }
}

/* 单列顺序刻意是 左栏→预览→右栏：先选内容、再看效果、最后调样式，
   样式控件贴着预览下方，拉滑块时向上一眼就能看到结果 */
@media (max-width: 980px) {
  .workspace { grid-template-columns: 1fr; grid-template-areas: "left" "preview" "right"; }
  .preview-panel { position: static; }
  .stage-wrap { padding: 1rem 0.5rem; }
}

/* embed=1：无界面渲染模式，供 Agent / 自动化截图或读取 window.__cardDataUrl */
body.embed { background: transparent; }
body.embed > *:not(#embed-view) { display: none !important; }
#embed-view { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; }
#embed-view img { max-width: 100%; max-height: 100%; display: block; }

/* 导出交付面板（移动端）：iOS 对程序化下载常静默拦截，改走分享/长按保存 */
.export-sheet { position: fixed; inset: 0; background: rgba(28, 25, 23, 0.6); display: flex; align-items: center; justify-content: center; z-index: 50; padding: 1rem; }
.es-panel { background: var(--card); border-radius: var(--radius); padding: 1rem; max-width: 420px; width: 100%; display: flex; flex-direction: column; gap: 0.75rem; }
.es-preview { background: repeating-conic-gradient(#efedeb 0% 25%, #f8f7f6 0% 50%) 0 0 / 20px 20px; border-radius: 8px; overflow: hidden; display: flex; justify-content: center; }
.es-preview img, .es-preview video { max-width: 100%; max-height: 55vh; display: block; }
.es-hint { font-size: 0.8rem; color: var(--muted); text-align: center; }
.es-actions { display: flex; gap: 0.5rem; justify-content: center; }
