/* ============================================================
   显影 DEVELOP — 简洁风格
   ============================================================ */
:root {
  --bg: #f7f7f8;
  --panel: #ffffff;
  --panel-2: #fafafa;

  --text: #1d1d1f;
  --text-2: #55555a;
  --muted: #9a9aa0;

  --border: #e6e6e9;
  --border-strong: #d4d4d8;

  --accent: #1d1d1f;
  --accent-soft: #f0f0f2;

  --danger: #c2503e;

  --paper: #ffffff;
  --paper-ink: #26262a;
  --paper-muted: #9a9aa0;

  --serif: 'Noto Serif SC', 'Songti SC', 'SimSun', 'STSong', serif;
  --sans: 'PingFang SC', 'Microsoft YaHei', 'Noto Sans SC', 'Hiragino Sans GB', system-ui, -apple-system, sans-serif;
  --mono: 'SF Mono', 'JetBrains Mono', 'Consolas', 'Menlo', monospace;

  --rail-w: 232px;
  --sheet-w: clamp(392px, 35vw, 468px);
  --r: 8px;
}

/* ============================================================
   reset
   ============================================================ */
*, *::before, *::after { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 13.5px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

h1, h2, h3, p, ol, ul, figure { margin: 0; }
ol, ul { padding: 0; list-style: none; }
img { display: block; max-width: 100%; }
[hidden] { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; padding: 0; }
a { color: inherit; }

:focus-visible {
  outline: 2px solid var(--border-strong);
  outline-offset: 2px;
}

::selection { background: rgba(29, 29, 31, 0.12); }

* { scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; }
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 8px; border: 2px solid transparent; background-clip: content-box; }
::-webkit-scrollbar-thumb:hover { background: var(--muted); background-clip: content-box; }
::-webkit-scrollbar-track { background: transparent; }

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

/* ============================================================
   shell
   ============================================================ */
.app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  min-height: 0;
}

.workspace {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: var(--rail-w) minmax(0, 1fr) var(--sheet-w);
}

/* ============================================================
   topbar
   ============================================================ */
.topbar {
  flex: 0 0 auto;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 20px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
  position: relative;
  z-index: 30;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.brand-mark { display: none; }

.brand-cn {
  font-size: 17px;
  font-weight: 600;
  letter-spacing: 0.06em;
  line-height: 1;
  color: var(--text);
}

.brand-rule {
  width: 1px;
  height: 13px;
  background: var(--border);
}

.brand-en {
  font-size: 11px;
  letter-spacing: 0.04em;
  color: var(--muted);
  white-space: nowrap;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.conn {
  display: flex;
  align-items: center;
  gap: 7px;
  height: 30px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 12px;
  color: var(--muted);
  max-width: 260px;
  transition: border-color 0.2s, color 0.2s;
}

.conn:hover { border-color: var(--border-strong); color: var(--text-2); }

.conn-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--border-strong);
  flex: 0 0 auto;
  transition: background 0.2s;
}

.conn.is-on { color: var(--text-2); border-color: var(--border-strong); }
.conn.is-on .conn-dot { background: #34a853; }

.conn-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.btn-ghost {
  height: 30px;
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: var(--r);
  background: transparent;
  color: var(--text-2);
  font-size: 12.5px;
  transition: border-color 0.2s, color 0.2s, background 0.2s;
}

.btn-ghost:hover { border-color: var(--border-strong); color: var(--text); background: var(--accent-soft); }

/* ============================================================
   column heads
   ============================================================ */
.col-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  padding: 18px 18px 12px;
}

.col-head h2 {
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.05em;
  color: var(--text);
}

.col-meta {
  font-size: 11px;
  letter-spacing: 0.02em;
  color: var(--muted);
  white-space: nowrap;
}

.col-meta b { color: var(--text-2); font-weight: 500; }

/* ============================================================
   rail — light table
   ============================================================ */
.rail {
  min-height: 0;
  overflow-y: auto;
  background: var(--panel);
  border-right: 1px solid var(--border);
  padding-bottom: 20px;
}

.rail-body { padding: 14px 14px 0; }

.frames {
  display: grid;
  gap: 12px;
}

.frame {
  position: relative;
  border: 1px solid var(--border);
  border-radius: var(--r);
  background: var(--panel-2);
  overflow: hidden;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.frame:hover { border-color: var(--border-strong); }

.frame.is-active {
  border-color: var(--text);
  box-shadow: 0 0 0 1px var(--text);
}

.frame.is-dragging { opacity: 0.35; }
.frame.is-drop { border-color: var(--text); box-shadow: 0 0 0 1px var(--text); }

.frame-thumb {
  width: 100%;
  aspect-ratio: 16 / 10;
  object-fit: cover;
  opacity: 0.65;
  transition: opacity 0.2s;
  cursor: grab;
}

.frame:hover .frame-thumb { opacity: 0.85; }
.frame.is-active .frame-thumb { opacity: 1; }

.frame-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  padding: 6px 9px;
  background: var(--panel);
  border-top: 1px solid var(--border);
}

.frame-no {
  font-size: 11px;
  color: var(--muted);
}

.frame.is-active .frame-no { color: var(--text); font-weight: 600; }

.frame-dots {
  display: flex;
  gap: 2px;
  align-items: center;
  height: 4px;
  flex: 0 0 44px;
}

.frame-dots i {
  flex: 1;
  height: 3px;
  background: var(--border);
  border-radius: 2px;
}

.frame-dots i.m { background: var(--border-strong); }
.frame-dots i.e { background: var(--text); }

.frame-state {
  font-size: 10.5px;
  color: var(--danger);
}

.frame-state.is-busy { color: var(--muted); animation: pulse 1.1s ease-in-out infinite; }

.frame-actions {
  position: absolute;
  top: 6px;
  right: 6px;
  display: flex;
  gap: 3px;
  opacity: 0;
  transition: opacity 0.15s;
}

.frame:hover .frame-actions,
.frame:focus-within .frame-actions { opacity: 1; }

.frame-actions button {
  width: 20px;
  height: 20px;
  display: grid;
  place-items: center;
  font-size: 11px;
  color: var(--text-2);
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid var(--border);
  border-radius: 4px;
  transition: color 0.15s, border-color 0.15s;
}

.frame-actions button:hover { color: var(--text); border-color: var(--border-strong); }
.frame-actions button[data-act="remove"]:hover { color: var(--danger); }

.dropzone {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  margin-top: 14px;
  padding: 18px 10px;
  border: 1px dashed var(--border-strong);
  border-radius: var(--r);
  cursor: pointer;
  text-align: center;
  transition: border-color 0.2s, background 0.2s;
}

.dropzone:hover,
.dropzone.is-over {
  border-color: var(--muted);
  background: var(--panel-2);
}

.dz-plus { font-size: 15px; color: var(--muted); line-height: 1; }

.dz-text { font-size: 12px; color: var(--text-2); }

.dz-hint { font-size: 10.5px; color: var(--muted); }

.rail-foot {
  display: flex;
  gap: 14px;
  padding: 16px 16px 0;
}

.rail-note {
  padding: 10px 16px 0;
  font-size: 11px;
  line-height: 1.6;
  color: var(--muted);
}

.link-btn {
  font-size: 11.5px;
  color: var(--muted);
  text-decoration: none;
  border-bottom: 1px solid transparent;
  padding-bottom: 1px;
  transition: color 0.15s, border-color 0.15s;
  white-space: nowrap;
}

.link-btn:hover:not(:disabled) { color: var(--text); border-color: var(--border-strong); }
.link-btn:disabled { opacity: 0.35; cursor: default; }
.link-btn.is-danger:hover:not(:disabled) { color: var(--danger); }

/* ============================================================
   stage
   ============================================================ */
.stage {
  min-height: 0;
  overflow-y: auto;
  background: var(--bg);
}

.viewer-pin {
  position: sticky;
  top: 0;
  z-index: 5;
  padding: 16px 18px 10px;
  background: var(--bg);
}

.viewer { padding: 0 18px 12px; }

.viewer-empty {
  display: grid;
  place-items: center;
  gap: 12px;
  padding: 36px 10px 32px;
  border: 1px dashed var(--border);
  border-radius: var(--r);
  background: var(--panel);
  color: var(--muted);
  font-size: 12.5px;
}

.ve-frame { display: none; }

.viewer-frame {
  display: flex;
  justify-content: center;
  padding: 2px 0 6px;
}

.img-wrap {
  position: relative;
  display: inline-block;
  line-height: 0;
  overflow: hidden;
  max-width: 100%;
  border-radius: var(--r);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

.img-wrap > img {
  max-width: 100%;
  max-height: 38vh;
  object-fit: contain;
}

.cm { display: none; }

.boxes { position: absolute; inset: 0; pointer-events: none; }

/* 全部框常显：非选中框弱化、不带白幕，选中的加粗并带标签 */
.boxes.is-show-all .box { opacity: 0.5; box-shadow: none; }
.boxes.is-show-all .box .box-label { display: none; }
.boxes.is-show-all .box.is-on { opacity: 1; border-width: 2.5px; }
.boxes.is-show-all .box.is-on .box-label { display: block; }

.box-toggle {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 3;
  padding: 3px 10px;
  border: 0;
  border-radius: 999px;
  background: rgba(29, 29, 31, 0.72);
  color: #fff;
  font-size: 11px;
  line-height: 1.5;
  letter-spacing: 0.02em;
  cursor: pointer;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

.box-toggle:active { background: rgba(29, 29, 31, 0.9); }

.box {
  position: absolute;
  opacity: 0;
  border: 1.5px solid var(--text);
  border-radius: 3px;
  box-shadow: 0 0 0 9999px rgba(255, 255, 255, 0.5);
  transition: opacity 0.18s ease;
}

.box.is-on { opacity: 1; }

.box-label {
  position: absolute;
  left: -1px;
  bottom: 100%;
  margin-bottom: 4px;
  padding: 2px 7px;
  background: var(--text);
  color: #fff;
  font-size: 10.5px;
  border-radius: 4px;
  white-space: nowrap;
  line-height: 1.4;
}

.box-label.is-below {
  bottom: auto;
  top: 100%;
  margin-bottom: 0;
  margin-top: 4px;
}

.viewer-note { margin-top: 10px; }

.note-input {
  display: block;
  width: 100%;
  min-height: 68px;
  padding: 8px 10px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 13px;
  line-height: 1.7;
  resize: vertical;
  transition: border-color 0.2s;
}

.note-input::placeholder { color: var(--muted); }
.note-input:focus { outline: none; border-color: var(--text-2); }

.viewer-summary {
  margin-top: 8px;
  min-height: 18px;
  font-size: 12px;
  line-height: 1.6;
  color: var(--text-2);
}

.viewer-summary.is-empty { color: var(--muted); }

/* ============================================================
   ledger
   ============================================================ */
.ledger-tools {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 14px;
  padding: 12px 18px 10px;
}

.ledger-actions { display: flex; gap: 6px; }

.btn-mini {
  height: 29px;
  padding: 0 13px;
  border: 1px solid var(--border);
  border-radius: var(--r);
  background: var(--panel);
  color: var(--text-2);
  font-size: 12px;
  transition: border-color 0.2s, color 0.2s, background 0.2s;
}

.btn-mini:hover:not(:disabled) { border-color: var(--border-strong); color: var(--text); background: var(--accent-soft); }
.btn-mini:disabled { opacity: 0.4; cursor: default; }

.filter-row {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-left: auto;
}

.chip {
  padding: 3px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 11px;
  color: var(--muted);
  background: var(--panel);
  transition: border-color 0.15s, color 0.15s, background 0.15s;
}

.chip:hover { color: var(--text-2); border-color: var(--border-strong); }

.chip.is-active {
  border-color: var(--text);
  color: var(--text);
  background: var(--accent-soft);
}

.chip i {
  font-style: normal;
  font-size: 10px;
  opacity: 0.8;
  margin-left: 4px;
}

.meter { padding: 2px 18px 12px; }

.meter-bar {
  display: flex;
  gap: 2px;
  height: 4px;
  margin-bottom: 7px;
}

.meter-bar i {
  flex: 1;
  min-width: 3px;
  border-radius: 2px;
  background: var(--border);
  transition: background 0.25s;
}

.meter-bar i.m { background: var(--border-strong); }
.meter-bar i.e { background: var(--text); }

.meter-legend {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 10px;
  font-size: 11px;
  color: var(--muted);
}

.meter-legend b { font-weight: 500; }
.meter-legend .lg-e { color: var(--text); }
.meter-legend .lg-m { color: var(--text-2); }
.meter-legend .lg-s { color: var(--muted); }
.meter-legend .lg-hint { margin-left: auto; font-size: 10.5px; }

.details { padding: 0 18px 4px; }

.detail {
  display: grid;
  grid-template-columns: 24px minmax(0, 1fr) auto;
  gap: 12px;
  padding: 13px 0;
  border-bottom: 1px solid var(--border);
  align-items: start;
}

.detail:last-child { border-bottom: 0; }

.detail.is-focus .type-chip { border-color: var(--text); color: var(--text); }

.type-chip {
  width: 24px;
  height: 24px;
  display: grid;
  place-items: center;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 11px;
  line-height: 1;
  color: var(--muted);
  cursor: pointer;
  transition: border-color 0.2s, color 0.2s, background 0.2s;
}

.type-chip:hover { border-color: var(--border-strong); color: var(--text); }

.detail.type-continuity .type-chip { border-color: var(--text-2); color: var(--text); }

.detail-main { min-width: 0; }

.detail-title {
  font-size: 13.5px;
  font-weight: 500;
  line-height: 1.45;
  color: var(--text);
  cursor: pointer;
  display: inline;
}

.detail-title:hover { color: var(--text-2); text-decoration: underline; text-underline-offset: 3px; }

.detail-note {
  margin-top: 3px;
  font-size: 12.5px;
  line-height: 1.65;
  color: var(--text-2);
  word-break: break-word;
}

.tag-inferred {
  display: inline-block;
  margin-right: 5px;
  padding: 0 5px;
  border: 1px solid var(--border-strong);
  border-radius: 4px;
  font-size: 10px;
  line-height: 1.5;
  color: var(--muted);
  vertical-align: 1px;
}

.detail-actions {
  display: flex;
  gap: 12px;
  margin-top: 6px;
  opacity: 0;
  transition: opacity 0.15s;
}

.detail:hover .detail-actions,
.detail:focus-within .detail-actions { opacity: 1; }

.detail-actions .link-btn { font-size: 10.5px; }

.seg {
  display: flex;
  border: 1px solid var(--border);
  border-radius: 999px;
  overflow: hidden;
  flex: 0 0 auto;
  height: 24px;
}

.seg button {
  width: 25px;
  height: 100%;
  font-size: 10.5px;
  color: var(--muted);
  transition: background 0.15s, color 0.15s;
}

.seg button + button { border-left: 1px solid var(--border); }
.seg button:hover { color: var(--text); background: var(--accent-soft); }
.seg button:active { color: var(--text); background: var(--accent-soft); }

.seg button[aria-pressed="true"] { color: var(--text); background: var(--accent-soft); }
.seg button[data-em="expand"][aria-pressed="true"] { color: #fff; background: var(--text); }
.seg button[data-em="mention"][aria-pressed="true"] { color: var(--text); background: #dedee2; }
.seg button[data-em="skip"][aria-pressed="true"] { color: var(--muted); background: transparent; }

.detail-edit {
  display: grid;
  gap: 6px;
  margin-top: 2px;
}

.detail-edit input,
.detail-edit select {
  width: 100%;
  height: 30px;
  padding: 0 8px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 12.5px;
}

.detail-edit input:focus,
.detail-edit select:focus { outline: none; border-color: var(--border-strong); }

.edit-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 2px;
}

.edit-row select { width: 92px; }

.btn-tiny {
  height: 25px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-2);
  font-size: 11px;
  transition: border-color 0.15s, color 0.15s;
}

.btn-tiny:hover { border-color: var(--border-strong); color: var(--text); }
.btn-tiny.is-primary { border-color: var(--text); color: var(--text); }

.add-detail { padding: 10px 18px 30px; }

.add-btn {
  width: 100%;
  height: 34px;
  border: 1px dashed var(--border-strong);
  border-radius: var(--r);
  color: var(--muted);
  font-size: 12px;
  transition: border-color 0.2s, color 0.2s, background 0.2s;
}

.add-btn:hover { border-color: var(--muted); color: var(--text-2); background: var(--panel); }

.ledger-empty {
  padding: 26px 4px;
  font-size: 12.5px;
  line-height: 1.8;
  color: var(--muted);
}

.ledger-empty b { color: var(--text-2); font-weight: 500; }

/* ============================================================
   sheet — story
   ============================================================ */
.sheet-col {
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  border-left: 1px solid var(--border);
}

.paper-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 14px 16px 22px;
}

.paper {
  position: relative;
  min-height: 100%;
  padding: 24px 24px 44px;
  background: var(--paper);
  color: var(--paper-ink);
  border-radius: var(--r);
  border: 1px solid var(--border);
  overflow: hidden;
}

.paper > * { position: relative; }

.paper-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 12px;
  margin-bottom: 20px;
  border-bottom: 1px solid var(--border);
}

.paper-kicker {
  font-size: 10.5px;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.paper-meta {
  font-size: 10.5px;
  color: var(--muted);
  text-align: right;
}

.paper-empty { padding: 34px 4px 10px; }

.pe-line {
  font-family: var(--serif);
  font-size: 17px;
  line-height: 1.8;
  color: var(--text-2);
}

.pe-sub {
  margin-top: 10px;
  font-size: 12.5px;
  line-height: 1.8;
  color: var(--muted);
  max-width: 30em;
}

.story { font-family: var(--serif); color: var(--paper-ink); }

.story-title {
  margin-bottom: 26px;
  font-family: var(--serif);
  font-size: 24px;
  font-weight: 700;
  line-height: 1.5;
  letter-spacing: 0.02em;
  color: var(--text);
  outline: none;
  border-bottom: 1px solid transparent;
}

.story-title:focus { border-bottom-color: var(--border); }

.story-title:empty::before {
  content: '未命名故事';
  color: var(--muted);
}

.story-sec {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr);
  gap: 12px;
  margin-bottom: 22px;
}

.sec-margin { padding-top: 5px; }

.sec-label {
  font-size: 10.5px;
  letter-spacing: 0.08em;
  color: var(--muted);
  font-family: var(--mono);
}

.sec-rule {
  width: 20px;
  height: 1px;
  margin-top: 6px;
  background: var(--border-strong);
}

.sec-rewrite {
  margin-top: 8px;
  font-size: 10.5px;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 6px;
  opacity: 0;
  transition: opacity 0.15s, color 0.15s, border-color 0.15s;
}

.story-sec:hover .sec-rewrite,
.sec-margin:focus-within .sec-rewrite,
.sec-rewrite:focus-visible { opacity: 1; }
.sec-rewrite:disabled { cursor: default; }
@media (hover: none) { .sec-rewrite { opacity: 1; } }
.sec-rewrite:hover { color: var(--text-2); border-color: var(--border-strong); }

.sec-body { min-width: 0; }

.sec-body p {
  margin-bottom: 0.9em;
  font-size: 15.5px;
  line-height: 1.95;
  letter-spacing: 0.01em;
  color: #2f2f33;
}

.sec-body p:last-child { margin-bottom: 0; }

.sec-body strong,
.story-intro strong {
  font-weight: 700;
  color: #a63c26;
  background: linear-gradient(transparent 64%, rgba(166, 60, 38, 0.16) 64%);
}

.story-say { color: #2f5d63; }

.sec-body em { font-style: normal; border-bottom: 1px solid var(--border-strong); }
.sec-body code {
  font-family: var(--mono);
  font-size: 0.86em;
  background: var(--accent-soft);
  padding: 1px 5px;
  border-radius: 4px;
}

.sec-body blockquote {
  margin: 0 0 0.9em;
  padding: 2px 0 2px 12px;
  border-left: 2px solid var(--border-strong);
  color: var(--text-2);
}

.story-intro p {
  font-size: 15.5px;
  line-height: 1.95;
  color: #2f2f33;
  margin-bottom: 0.9em;
}

/* Markdown 元素：标题、列表、分隔线（正文里偶发时也有样式） */
.story-h {
  margin: 0.4em 0 0.5em;
  font-family: var(--serif);
  font-size: 16.5px;
  font-weight: 700;
  line-height: 1.6;
  color: var(--text);
}

.story-list {
  margin: 0 0 0.9em;
  padding-left: 1.5em;
  font-size: 15.5px;
  line-height: 1.95;
  color: #2f2f33;
}

ul.story-list { list-style: disc; }
ol.story-list { list-style: decimal; }
.story-list li { margin-bottom: 0.25em; }
.story-list li:last-child { margin-bottom: 0; }

.story-hr {
  border: 0;
  border-top: 1px solid var(--border-strong);
  margin: 1.5em 0;
}

.caret {
  display: inline-block;
  width: 2px;
  height: 1.02em;
  margin-left: 2px;
  background: var(--text);
  vertical-align: -0.14em;
  animation: blink 1s steps(1) infinite;
}

.story-error {
  margin-top: 18px;
  padding: 10px 12px;
  border-left: 2px solid var(--danger);
  background: rgba(194, 80, 62, 0.06);
  font-family: var(--sans);
  font-size: 12px;
  line-height: 1.7;
  color: var(--danger);
  border-radius: 0 6px 6px 0;
}

/* composer */
.composer {
  flex: 0 1 auto;
  min-height: 0;
  max-height: 60%;
  overflow-y: auto;
  padding: 12px 16px 14px;
  background: var(--panel);
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 9px;
}

.mode-row {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-wrap: wrap;
}

.mode {
  height: 26px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 11.5px;
  color: var(--muted);
  background: var(--panel);
  transition: border-color 0.15s, color 0.15s, background 0.15s;
}

.mode:hover { color: var(--text-2); border-color: var(--border-strong); }

.mode.is-active {
  border-color: var(--text);
  color: var(--text);
  background: var(--accent-soft);
}

.mode-hint {
  margin-left: auto;
  font-size: 10.5px;
  color: var(--muted);
  text-align: right;
  max-width: 52%;
  line-height: 1.4;
}

.select-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.field {
  display: flex;
  align-items: center;
  gap: 7px;
  height: 32px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: var(--r);
  background: var(--panel);
}

.field > span {
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
}

.field select {
  flex: 1;
  min-width: 0;
  height: 100%;
  border: 0;
  background: transparent;
  color: var(--text);
  font-size: 12px;
  appearance: none;
  padding-right: 14px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M1 1l4 4 4-4' fill='none' stroke='%239a9aa0' stroke-width='1.2'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0 center;
  cursor: pointer;
}

.field select:focus { outline: none; }
.field:focus-within { border-color: var(--border-strong); }
.field option { background: var(--panel); color: var(--text); }

.writing-selects { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.writing-selects .field { gap: 5px; padding: 0 7px; }

.prompt-more {
  border: 1px solid var(--border);
  border-radius: var(--r);
}
.prompt-more summary {
  padding: 7px 10px;
  font-size: 12px;
  cursor: pointer;
}
.prompt-more summary span {
  float: right;
  color: var(--muted);
  font-size: 10.5px;
}
.prompt-fields {
  display: flex;
  flex-direction: column;
  gap: 7px;
  padding: 0 10px 10px;
}
.prompt-label { color: var(--text-2); font-size: 11px; }
.prompt-fields textarea {
  width: 100%;
  min-height: 90px;
  max-height: 240px;
  resize: vertical;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--r);
  background: var(--panel-2);
  font-family: var(--sans);
  font-size: 12px;
  line-height: 1.7;
}
.prompt-fields textarea::placeholder { color: var(--muted); }
.prompt-hint { color: var(--text-2); font-size: 10.5px; line-height: 1.6; }
.composer :disabled { cursor: default; opacity: 0.55; }
.story-stale {
  margin-bottom: 18px;
  padding: 10px 12px;
  border-left: 2px solid var(--border-strong);
  background: var(--panel-2);
  color: var(--text-2);
  font-family: var(--sans);
  font-size: 12px;
  line-height: 1.7;
}

.cta {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  height: 40px;
  border-radius: var(--r);
  background: var(--accent);
  color: #fff;
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0.04em;
  transition: opacity 0.15s, transform 0.08s;
}

.cta:hover:not(:disabled) { opacity: 0.85; }
.cta:active:not(:disabled) { transform: translateY(1px); }
.cta:disabled { opacity: 0.35; cursor: default; }

.cta-key {
  font-family: var(--mono);
  font-size: 9.5px;
  font-weight: 400;
  letter-spacing: 0.08em;
  opacity: 0.55;
}

.cta.is-stop {
  background: transparent;
  border: 1px solid var(--border-strong);
  color: var(--danger);
}

.cta.is-stop:hover { background: rgba(194, 80, 62, 0.05); opacity: 1; }

.cta-sm {
  width: auto;
  height: 32px;
  padding: 0 18px;
  font-size: 12.5px;
}

.composer-foot {
  display: flex;
  gap: 14px;
  padding-top: 1px;
}

@media (prefers-reduced-motion: reduce) {
  .caret { animation: none; }
  .composer button, .sec-rewrite { transition: none; }
}

@media (max-width: 380px) {
  .writing-selects { grid-template-columns: 1fr; }
}

/* ============================================================
   settings
   ============================================================ */
.settings {
  width: min(560px, calc(100vw - 28px));
  max-height: calc(100dvh - 48px);
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--panel);
  color: var(--text);
  box-shadow: 0 24px 60px -24px rgba(0, 0, 0, 0.18);
}

.settings::backdrop {
  background: rgba(0, 0, 0, 0.3);
}

.settings-form { padding: 24px 24px 20px; }

.settings-head h2 {
  font-size: 17px;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.settings-head p {
  margin-top: 6px;
  font-size: 12px;
  line-height: 1.7;
  color: var(--text-2);
}

.settings code {
  font-family: var(--mono);
  font-size: 0.92em;
  color: var(--text-2);
  background: var(--accent-soft);
  padding: 1px 5px;
  border-radius: 4px;
}

.sfield {
  display: flex;
  flex-direction: column;
  gap: 5px;
  margin-top: 15px;
}

.sfield > span {
  font-size: 11.5px;
  color: var(--text-2);
}

.sfield input {
  height: 36px;
  padding: 0 11px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--r);
  color: var(--text);
  font-size: 12.5px;
  transition: border-color 0.15s;
}

.sfield input:focus { outline: none; border-color: var(--border-strong); }
.sfield input::placeholder { color: var(--muted); }

.sfield em {
  font-style: normal;
  font-size: 10.5px;
  line-height: 1.6;
  color: var(--muted);
}

.sgrid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.shint {
  margin-top: 14px;
  font-size: 11px;
  line-height: 1.7;
  color: var(--muted);
}

.sstatus {
  min-height: 16px;
  margin-top: 8px;
  font-size: 11.5px;
  color: var(--text-2);
}

.sstatus.is-ok { color: #2e8b57; }
.sstatus.is-err { color: var(--danger); }

.settings-foot {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.spacer { flex: 1; }

/* ============================================================
   toast / tabs
   ============================================================ */
.toast {
  position: fixed;
  left: 50%;
  bottom: 26px;
  transform: translate(-50%, 10px);
  z-index: 80;
  max-width: min(90vw, 520px);
  padding: 10px 16px;
  background: var(--text);
  border-radius: 10px;
  box-shadow: 0 16px 40px -16px rgba(0, 0, 0, 0.3);
  font-size: 12.5px;
  line-height: 1.6;
  color: #fff;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.22s, transform 0.22s;
}

.toast.is-on { opacity: 1; transform: translate(-50%, 0); }
.toast.is-err { background: var(--danger); }

.tabs { display: none; }

/* ============================================================
   motion
   ============================================================ */
@keyframes blink { 0%, 50% { opacity: 1; } 50.01%, 100% { opacity: 0; } }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.35; } }

/* ============================================================
   responsive
   ============================================================ */
@media (max-width: 1240px) {
  :root { --rail-w: 208px; --sheet-w: clamp(360px, 34vw, 420px); }
  .sec-body p, .story-intro p { font-size: 15px; }
}

@media (max-width: 1080px) {
  body { overflow-y: auto; }

  .app { height: auto; min-height: 100dvh; }

  .workspace { display: block; }

  .tabs {
    display: flex;
    gap: 2px;
    padding: 0 14px;
    border-bottom: 1px solid var(--border);
    background: var(--panel);
    position: sticky;
    top: 0;
    z-index: 25;
  }

  .tab {
    padding: 11px 14px 10px;
    font-size: 12.5px;
    color: var(--muted);
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
  }

  .tab.is-active { color: var(--text); border-bottom-color: var(--text); }

  .rail {
    border-right: 0;
    border-bottom: 1px solid var(--border);
    padding-bottom: 12px;
    overflow: visible;
  }

  .workspace[data-panel="sheet"] .rail { display: none; }

  .rail .col-head { padding: 12px 14px 10px; }

  .rail-body {
    display: flex;
    gap: 10px;
    overflow-x: auto;
    padding: 0 14px;
    align-items: stretch;
  }

  .frames {
    display: flex;
    gap: 10px;
    flex: 0 0 auto;
  }

  .frame { flex: 0 0 132px; width: 132px; }

  .frame-actions { opacity: 0; }
  .frame.is-active .frame-actions,
  .frame:focus-within .frame-actions { opacity: 1; }

  .dropzone {
    flex: 0 0 132px;
    order: -1;
    margin-top: 0;
    min-height: 108px;
    padding: 12px 8px;
  }

  .rail-foot { padding: 12px 14px 0; }
  .rail-note { display: none; }

  .stage, .sheet-col { display: none; }

  .workspace[data-panel="stage"] .stage { display: block; }
  .workspace[data-panel="sheet"] .sheet-col { display: flex; }

  .stage { overflow: visible; }

  /* 图片钉在标签栏下面，细节列表从它底下滚过 */
  .viewer-pin {
    top: 36px;
    padding: 10px 14px 8px;
    border-bottom: 1px solid var(--border);
  }

  .viewer { padding: 0 14px 10px; }

  .img-wrap > img { max-height: 28vh; }

  .sheet-col {
    min-height: calc(100dvh - 60px);
    border-left: 0;
  }

  .paper-scroll { flex: 1 1 auto; }

  .composer { position: sticky; bottom: 0; z-index: 12; }

  .settings-form { padding: 20px 18px 16px; }
}

@media (max-width: 720px) {
  .topbar { height: 52px; padding: 0 14px; }
  .brand-en, .brand-rule { display: none; }
  .conn-text { max-width: 96px; }
  .col-head { padding: 14px 14px 10px; }
  .viewer-pin { padding: 10px 14px 8px; }
  .viewer { padding: 0 14px 8px; }
  .ledger-tools { padding: 10px 14px 8px; }
  .filter-row { margin-left: 0; }
  .meter { padding: 2px 14px 10px; }
  .details { padding: 0 14px 4px; }
  .add-detail { padding: 10px 14px 24px; }
  .paper-scroll { padding: 10px 10px 16px; }
  .paper { padding: 18px 16px 34px; }
  .story-title { font-size: 21px; }
  .sec-body p, .story-intro p { font-size: 15px; line-height: 1.9; }
  .story-sec { grid-template-columns: 34px minmax(0, 1fr); gap: 8px; }
  .sec-rewrite { opacity: 1; }
  .composer { padding: 10px 12px 12px; }
  .mode-hint { display: none; }
  .sgrid { grid-template-columns: 1fr; gap: 0; }
  /* 略/提/展 挪到文字下面，加大到好按的尺寸 */
  .detail { grid-template-columns: 24px minmax(0, 1fr); row-gap: 8px; }
  .detail-actions { opacity: 1; }
  .seg {
    grid-column: 2;
    justify-self: start;
    height: 32px;
  }
  .seg button { width: 44px; font-size: 12px; touch-action: manipulation; }
  .frame-actions { opacity: 1; }
}

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

/* ============================================================
   projects
   ============================================================ */
.proj-chip {
  display: flex;
  align-items: center;
  gap: 6px;
  height: 30px;
  max-width: 240px;
  padding: 0 11px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: transparent;
  color: var(--text-2);
  font-size: 12px;
  transition: border-color 0.2s, color 0.2s, background 0.2s;
}

.proj-chip:hover { border-color: var(--border-strong); color: var(--text); background: var(--accent-soft); }

.proj-chip-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.proj-chip-caret { flex: 0 0 auto; font-size: 9px; color: var(--muted); }

.project-actions { display: flex; gap: 8px; margin-top: 14px; }

.project-list {
  list-style: none;
  margin: 12px 0 0;
  padding: 0 2px 4px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  overflow-y: auto;
  max-height: min(46vh, 380px);
}

.project-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--r);
  transition: border-color 0.2s, background 0.2s;
}

.project-row:hover { border-color: var(--border-strong); }

.project-row.is-current { border-color: var(--text); background: var(--accent-soft); }

.pr-main { min-width: 0; display: flex; flex-direction: column; gap: 3px; }

.pr-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pr-meta { font-size: 11px; color: var(--muted); white-space: nowrap; }

.pr-acts { display: flex; gap: 10px; flex: 0 0 auto; }

.project-empty {
  padding: 22px 12px;
  border: 1px dashed var(--border);
  border-radius: var(--r);
  text-align: center;
  font-size: 12px;
  line-height: 1.7;
  color: var(--muted);
}

.settings-foot .shint { margin: 0; }

@media (max-width: 720px) {
  .proj-chip { max-width: 118px; padding: 0 9px; }
  .btn-ghost { padding: 0 10px; }
  .conn-text { max-width: 70px; }
  .pr-acts { flex-direction: column; align-items: flex-end; gap: 2px; }
}

/* ============================================================
   gallery — 画册页
   ============================================================ */

.btn-link { text-decoration: none; display: inline-flex; align-items: center; }

.gallery-body {
  flex: 1;
  min-height: 0;
  display: flex;
}

/* 左侧项目列表 */
.gal-side {
  flex: 0 0 228px;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--panel-2);
  border-right: 1px solid var(--border);
}

.gal-side-head {
  padding: 12px 14px 8px;
  font-size: 10.5px;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.gal-nav {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 0 8px 16px;
}

.gal-item {
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 7px 8px;
  margin-bottom: 2px;
  border-radius: 6px;
  border-left: 2px solid transparent;
  cursor: pointer;
  transition: background 0.12s;
}

.gal-item:hover { background: var(--accent-soft); }

.gal-item.is-active {
  background: var(--panel);
  border-left-color: var(--text);
}

.gal-item-thumb {
  flex: 0 0 auto;
  width: 46px;
  height: 34px;
  object-fit: cover;
  border-radius: 4px;
  border: 1px solid var(--border);
}

.gal-item-main { min-width: 0; }

.gal-item-name {
  display: block;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.gal-item-meta {
  display: block;
  font-size: 10.5px;
  color: var(--muted);
}

/* 右侧内容 */
.gallery-main {
  flex: 1;
  min-width: 0;
  min-height: 0;
  overflow-y: auto;
  padding: 18px 26px 64px;
}

.gal-pager {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  margin-bottom: 16px;
}

.gal-pos {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.gal-project {
  max-width: 860px;
  margin: 0 auto;
}

.gallery-head { margin-bottom: 22px; }

.gallery-head h1 {
  font-family: var(--serif);
  font-size: 22px;
  font-weight: 700;
  color: var(--text);
}

.gallery-head p {
  margin-top: 6px;
  font-size: 12.5px;
  color: var(--muted);
}

.gal-project {
  background: var(--paper);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 26px 28px 30px;
  margin-bottom: 24px;
}

.gal-name {
  font-family: var(--serif);
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
}

.gal-meta {
  margin-top: 4px;
  font-size: 11px;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.gal-title {
  margin: 18px 0 4px;
  font-family: var(--serif);
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
}

.gal-row {
  display: grid;
  grid-template-columns: minmax(0, 42%) minmax(0, 1fr);
  gap: 18px;
  align-items: start;
  margin-top: 20px;
  padding-top: 18px;
  border-top: 1px dashed var(--border);
}

.gal-fig {
  position: relative;
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
  background: var(--panel-2);
}

.gal-fig img { width: 100%; height: auto; }

.gal-no {
  position: absolute;
  left: 8px;
  top: 8px;
  padding: 1px 7px;
  border-radius: 999px;
  background: rgba(29, 29, 31, 0.72);
  color: #fff;
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.06em;
}

.gal-story { min-width: 0; }

.gal-story p {
  font-size: 15px;
  line-height: 1.9;
  color: #2f2f33;
  margin-bottom: 0.85em;
}

.gal-story p:last-child { margin-bottom: 0; }

.gal-story strong,
.gal-intro strong {
  font-weight: 700;
  color: #a63c26;
  background: linear-gradient(transparent 64%, rgba(166, 60, 38, 0.16) 64%);
}

.gal-story .story-say { color: #2f5d63; }

.gal-story blockquote {
  margin: 0 0 0.85em;
  padding: 2px 0 2px 12px;
  border-left: 2px solid var(--border-strong);
  color: var(--text-2);
}

.gal-story .story-h {
  margin: 0.4em 0 0.5em;
  font-family: var(--serif);
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
}

.gal-story .story-list {
  margin: 0 0 0.85em;
  padding-left: 1.5em;
  font-size: 15px;
  line-height: 1.9;
  color: #2f2f33;
}

ul.gal-story .story-list, .gal-story ul.story-list { list-style: disc; }
.gal-story ol.story-list { list-style: decimal; }

.gal-story .story-hr {
  border: 0;
  border-top: 1px solid var(--border-strong);
  margin: 1.4em 0;
}

.gal-missing { color: var(--muted) !important; font-size: 13px !important; }

.gal-solo {
  margin-top: 18px;
  padding-top: 18px;
  border-top: 1px dashed var(--border);
}

.gal-wall {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 12px;
  margin-top: 18px;
}

.gallery-empty {
  text-align: center;
  padding: 60px 0;
  color: var(--muted);
  font-size: 13px;
}

@media (max-width: 720px) {
  .gallery-body { flex-direction: column; }
  .gal-side { flex: 0 0 auto; border-right: 0; border-bottom: 1px solid var(--border); }
  .gal-side-head { display: none; }
  .gal-nav { display: flex; overflow-x: auto; overflow-y: hidden; padding: 8px 10px; }
  .gal-item { flex: 0 0 auto; max-width: 180px; margin-bottom: 0; border-left: 0; border-bottom: 2px solid transparent; border-radius: 6px 6px 0 0; }
  .gal-item.is-active { border-bottom-color: var(--text); }
  .gallery-main { padding: 14px 14px 48px; }
  .gal-row { grid-template-columns: 1fr; }
  .gal-project { padding: 18px 16px 24px; }
}
