:root {
  --bg-app: #f4f4f1;
  --bg-surface: #ffffff;
  --bg-subtle: #ededeb;
  --bg-stage-dir: #f5f6f8;
  --border: #dfdfd9;
  --border-strong: #c8c8bf;
  --text-main: #1d2024;
  --text-secondary: #586069;
  --text-muted: #868e96;
  --accent-teal: #1c6b5a;
  --accent-teal-soft: #e6f2ef;
  --accent-crimson: #9e2a2b;
  --accent-crimson-soft: #fbeaea;
  --accent-gold: #8c6222;
  --accent-gold-soft: #fcf6e8;
  --accent-ink: #273444;
  --highlight-comment: #fff3bf;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg-app);
  color: var(--text-main);
  font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", system-ui, -apple-system, sans-serif;
  font-size: 14px;
  line-height: 1.6;
  letter-spacing: 0;
}

button, input, select, textarea {
  font-family: inherit;
  font-size: inherit;
  letter-spacing: 0;
}

.hidden {
  display: none !important;
}

/* Topbar */
.topbar {
  min-height: 48px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  padding: 6px 14px;
  gap: 8px 12px;
}

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

.brand-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent-teal);
  flex-shrink: 0;
}

.brand-title {
  font-weight: 600;
  color: var(--text-main);
  white-space: nowrap;
}

.brand-sep {
  color: var(--text-muted);
}

.current-doc-title {
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.mode-switch {
  display: inline-flex;
  background: var(--bg-subtle);
  padding: 3px;
  border-radius: 6px;
  border: 1px solid var(--border);
}

.mode-btn {
  border: none;
  background: transparent;
  color: var(--text-secondary);
  padding: 4px 12px;
  border-radius: 4px;
  cursor: pointer;
  font-weight: 500;
  white-space: nowrap;
}

.mode-btn.active {
  background: var(--bg-surface);
  color: var(--text-main);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
}

.mode-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.top-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 6px;
}

.search-box {
  display: flex;
  align-items: center;
  gap: 5px;
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 3px 8px;
  width: 148px;
  color: var(--text-muted);
}

.search-box input {
  border: none;
  background: transparent;
  outline: none;
  width: 100%;
  color: var(--text-main);
  font-size: 13px;
}

.action-btn, .small-btn, .primary-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  border-radius: 6px;
  padding: 4px 10px;
  cursor: pointer;
  font-size: 13px;
  white-space: nowrap;
}

.action-btn, .small-btn {
  background: var(--bg-surface);
  border: 1px solid var(--border-strong);
  color: var(--text-main);
}

.action-btn:hover, .small-btn:hover {
  background: var(--bg-subtle);
}

.primary-btn {
  background: var(--accent-teal);
  border: 1px solid var(--accent-teal);
  color: #fff;
}

.primary-btn:hover {
  opacity: 0.92;
}

.save-status {
  font-size: 12px;
  color: var(--text-muted);
  min-width: 110px;
  text-align: right;
  padding: 2px 8px;
  border-radius: 999px;
  transition: background-color 0.2s, color 0.2s;
}

.save-status.is-saving {
  color: var(--accent-gold);
  background: var(--accent-gold-soft);
}

.save-status.is-saved {
  color: var(--accent-teal);
  background: var(--accent-teal-soft);
  font-weight: 500;
}

.save-status.is-error {
  color: var(--accent-crimson);
  background: var(--accent-crimson-soft);
  font-weight: 600;
}

/* Workspace Grid */
.workspace {
  height: calc(100vh - 48px);
  display: grid;
  grid-template-columns: 248px minmax(0, 1fr) 408px;
}

.sidebar-left {
  background: var(--bg-surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.panel-section {
  padding: 12px;
  border-bottom: 1px solid var(--border);
}

.outline-section {
  flex: 1;
  overflow-y: auto;
  border-bottom: none;
}

.panel-heading {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.doc-group-title {
  font-size: 11px;
  color: var(--text-muted);
  margin: 8px 0 4px;
  padding-left: 4px;
}

.doc-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 8px;
  border-radius: 6px;
  cursor: pointer;
  color: var(--text-main);
  font-size: 13px;
  margin-bottom: 2px;
}

.doc-item:hover {
  background: var(--bg-subtle);
}

.doc-item.active {
  background: var(--accent-teal-soft);
  color: var(--accent-teal);
  font-weight: 600;
}

.doc-badge {
  background: var(--accent-gold-soft);
  color: var(--accent-gold);
  border: 1px solid #e6d3a7;
  font-size: 11px;
  padding: 0 6px;
  border-radius: 10px;
}

.outline-item {
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 12.5px;
  color: var(--text-secondary);
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.outline-item:hover {
  background: var(--bg-subtle);
  color: var(--text-main);
}

.outline-item.is-choice {
  color: var(--accent-teal);
  font-weight: 500;
}

.outline-item.is-be {
  color: var(--accent-crimson);
}

/* Main Stage */
.stage {
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.play-toolbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: #fafaf7;
  border-bottom: 1px solid var(--border);
  padding: 8px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.play-presets {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  font-size: 13px;
}

.preset-label {
  font-weight: 600;
  color: var(--text-secondary);
}

.inline-select, .inline-input, .inline-check {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--text-secondary);
  font-size: 13px;
}

.inline-select select, .inline-input input {
  border: 1px solid var(--border-strong);
  border-radius: 4px;
  padding: 2px 6px;
  background: var(--bg-surface);
}

.inline-input input {
  width: 88px;
}

.verify-banner {
  margin: 12px 32px 0;
  padding: 10px 14px;
  border-radius: 6px;
  font-size: 13px;
  white-space: pre-wrap;
}

.verify-banner.ok {
  background: var(--accent-teal-soft);
  border: 1px solid #b8dcd4;
  color: var(--accent-teal);
}

.verify-banner.err {
  background: var(--accent-crimson-soft);
  border: 1px solid #e6b8b8;
  color: var(--accent-crimson);
}

.reader-container {
  max-width: 820px;
  width: 100%;
  margin: 20px auto 64px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 32px 44px;
}

/* Script Line Styles */
.script-row {
  position: relative;
  padding: 3px 8px;
  margin: 1px -8px;
  border-radius: 4px;
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr) 28px;
  align-items: baseline;
  gap: 8px;
}

.script-row:hover {
  background: #f9f9f6;
}

.script-row.has-comment {
  background: var(--highlight-comment);
}

.script-row.flash-focus {
  outline: 2px solid var(--accent-teal);
}

.line-num {
  font-size: 11px;
  color: #b5bac0;
  text-align: right;
  user-select: none;
  font-variant-numeric: tabular-nums;
}

.row-actions {
  opacity: 0;
  display: flex;
  justify-content: flex-end;
}

.script-row:hover .row-actions,
.script-row.has-comment .row-actions {
  opacity: 1;
}

.comment-pin-btn {
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  padding: 2px 4px;
  border-radius: 4px;
  font-size: 12px;
}

.comment-pin-btn:hover {
  background: var(--bg-subtle);
  color: var(--accent-teal);
}

.line-body {
  min-width: 0;
  word-break: break-word;
}

/* Specific Script Semantics */
.ln-h1 {
  font-size: 20px;
  font-weight: 700;
  margin: 4px 0 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

.ln-h2 {
  font-size: 16px;
  font-weight: 700;
  color: var(--accent-ink);
  margin: 20px 0 8px;
  padding-top: 8px;
  border-top: 1px dashed var(--border);
}

.ln-meta {
  font-size: 12.5px;
  color: var(--text-secondary);
}

.ln-narration {
  font-family: "Songti SC", "STSong", "Noto Serif SC", "SimSun", Georgia, serif;
  font-size: 16px;
  line-height: 1.85;
  color: #22252a;
  padding: 2px 0;
}

.ln-dialogue {
  font-size: 15px;
  line-height: 1.75;
  padding: 3px 0;
}

.speaker-tag {
  display: inline-block;
  font-weight: 700;
  margin-right: 6px;
  padding: 0 6px;
  border-radius: 4px;
  font-size: 13.5px;
}

.spk-mizhen { background: #fdf3dc; color: #7a5211; }
.spk-leon { background: #f8e6e7; color: #8c2327; }
.spk-me { background: #e6f2ef; color: #185c4d; }
.spk-lianyu { background: #e7f0f8; color: #1f4f78; }
.spk-qing { background: #eef2f5; color: #364958; }
.spk-peiyan { background: #eaebed; color: #222930; }
.spk-other { background: #f1f1ee; color: #52575c; }

.ln-stage {
  font-size: 12.5px;
  color: var(--text-secondary);
  background: var(--bg-stage-dir);
  border-left: 2px solid #cbd2d9;
  padding: 3px 10px;
  border-radius: 0 4px 4px 0;
  margin: 2px 0;
}

.ln-ui {
  font-family: "Consolas", "Microsoft YaHei", monospace;
  font-size: 13px;
  color: var(--accent-gold);
  background: var(--accent-gold-soft);
  border: 1px solid #ead8b1;
  display: inline-block;
  padding: 2px 10px;
  border-radius: 4px;
  margin: 1px 0;
}

.ln-directive {
  font-family: "Consolas", "Microsoft YaHei", monospace;
  font-size: 12.5px;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 4px;
  margin: 4px 0;
}

.dir-q {
  background: var(--accent-teal-soft);
  color: var(--accent-teal);
  border-left: 3px solid var(--accent-teal);
  font-size: 14px;
}

.dir-opt {
  background: #eef6f4;
  color: #16594a;
  border: 1px dashed #8fc4b8;
}

.dir-cond {
  background: #f2f4f7;
  color: #475467;
}

.dir-be {
  background: var(--accent-crimson-soft);
  color: var(--accent-crimson);
  border-left: 3px solid var(--accent-crimson);
}

/* Seamless Single-Click Live Line Editor */
.script-row.is-editable {
  cursor: text;
}

.script-row.is-editing {
  background: #f5fbf9;
  box-shadow: inset 3px 0 0 var(--accent-teal);
}

.inline-live-wrap {
  width: 100%;
  display: flex;
  flex-direction: column;
}

.inline-live-input {
  width: 100%;
  border: none;
  outline: none;
  background: transparent;
  padding: 2px 0;
  margin: 0;
  color: var(--text-main);
  font-size: 15px;
  line-height: 1.75;
  resize: none;
  overflow: hidden;
  display: block;
}

.inline-live-input.is-narration {
  font-family: "Songti SC", "STSong", "Noto Serif SC", "SimSun", Georgia, serif;
  font-size: 16px;
  line-height: 1.85;
  color: #22252a;
}

.inline-live-input.is-mono {
  font-family: "Consolas", "Microsoft YaHei", monospace;
  font-size: 13.5px;
  line-height: 1.65;
}

.inline-live-hint {
  font-size: 11px;
  color: #9aa3ab;
  user-select: none;
  margin-top: 1px;
}

/* Play Mode Interactive Choice Card */
.play-choice-card {
  margin: 20px 0;
  padding: 16px 20px;
  background: #fafaf7;
  border: 1px solid var(--border-strong);
  border-left: 4px solid var(--accent-teal);
  border-radius: 6px;
}

.play-choice-prompt {
  font-weight: 700;
  color: var(--text-main);
  margin-bottom: 12px;
  font-size: 15px;
}

.play-choice-options {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.play-opt-btn {
  text-align: left;
  padding: 9px 14px;
  border-radius: 6px;
  border: 1px solid var(--border-strong);
  background: var(--bg-surface);
  cursor: pointer;
  font-size: 14px;
  color: var(--text-main);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.play-opt-btn:hover {
  border-color: var(--accent-teal);
  background: var(--accent-teal-soft);
}

.play-opt-btn.chosen {
  border-color: var(--accent-teal);
  background: var(--accent-teal);
  color: #fff;
  font-weight: 600;
}

.play-end-card {
  margin: 24px 0 8px;
  padding: 16px 20px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.play-end-card.be {
  background: var(--accent-crimson-soft);
  border: 1px solid #e3b2b3;
  color: var(--accent-crimson);
}

.play-end-card.clear {
  background: var(--accent-teal-soft);
  border: 1px solid #b4dcd3;
  color: var(--accent-teal);
}

/* Markdown Table for non-script docs */
.md-table {
  width: 100%;
  border-collapse: collapse;
  margin: 12px 0;
  font-size: 13px;
}

.md-table th, .md-table td {
  border: 1px solid var(--border);
  padding: 8px 10px;
  text-align: left;
  vertical-align: top;
}

.md-table th {
  background: var(--bg-subtle);
  font-weight: 600;
}

/* Raw Editor */
.raw-editor-wrap {
  max-width: 920px;
  width: 100%;
  margin: 16px auto;
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}

.raw-toolbar {
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--bg-subtle);
}

.raw-hint {
  font-size: 12.5px;
  color: var(--text-secondary);
}

#rawTextarea {
  flex: 1;
  width: 100%;
  border: none;
  outline: none;
  padding: 20px 24px;
  font-family: "Consolas", "PingFang SC", "Microsoft YaHei", monospace;
  font-size: 14px;
  line-height: 1.75;
  resize: none;
}

/* Right Sidebar */
.sidebar-right {
  background: var(--bg-surface);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.right-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  border-bottom: 1px solid var(--border);
}

.rtab {
  padding: 10px 4px;
  border: none;
  background: var(--bg-subtle);
  color: var(--text-secondary);
  cursor: pointer;
  font-weight: 600;
  font-size: 12.5px;
  border-bottom: 2px solid transparent;
  white-space: nowrap;
}

.rtab.active {
  background: var(--bg-surface);
  color: var(--accent-teal);
  border-bottom-color: var(--accent-teal);
}

.badge {
  display: inline-block;
  background: var(--accent-teal-soft);
  color: var(--accent-teal);
  padding: 0 6px;
  border-radius: 10px;
  font-size: 11px;
  margin-left: 3px;
}

.right-pane {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
}

.filter-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.comment-composer {
  background: #fafaf7;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  padding: 10px;
  margin-bottom: 12px;
}

.composer-meta {
  font-size: 12px;
  font-weight: 600;
  color: var(--accent-teal);
  margin-bottom: 6px;
}

.composer-quote {
  margin: 0 0 8px;
  padding: 4px 8px;
  background: var(--highlight-comment);
  border-left: 3px solid #e0b422;
  font-size: 12px;
  color: var(--text-secondary);
}

.comment-composer textarea {
  width: 100%;
  border: 1px solid var(--border-strong);
  border-radius: 4px;
  padding: 6px 8px;
  resize: vertical;
}

.composer-actions {
  display: flex;
  justify-content: flex-end;
  gap: 6px;
  margin-top: 8px;
}

.comment-card {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px;
  margin-bottom: 8px;
  background: var(--bg-surface);
}

.comment-card.resolved {
  opacity: 0.6;
  background: var(--bg-subtle);
}

.comment-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.comment-loc {
  color: var(--accent-teal);
  font-weight: 600;
  cursor: pointer;
}

.comment-loc:hover {
  text-decoration: underline;
}

.comment-quote {
  font-size: 12px;
  color: var(--text-secondary);
  background: #f8f8f5;
  border-left: 2px solid #d0d0c8;
  padding: 3px 8px;
  margin: 4px 0 6px;
}

.comment-note {
  font-size: 13.5px;
  color: var(--text-main);
  white-space: pre-wrap;
}

.comment-foot {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 6px;
}

.link-btn {
  border: none;
  background: none;
  color: var(--text-muted);
  font-size: 12px;
  cursor: pointer;
  padding: 0;
}

.link-btn:hover {
  color: var(--text-main);
  text-decoration: underline;
}

/* State Box */
.state-box {
  margin-bottom: 16px;
}

.state-title {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.kv-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 5px 8px;
  border-bottom: 1px solid var(--border);
  font-size: 12.5px;
}

.kv-key {
  font-family: "Consolas", monospace;
  color: var(--text-secondary);
}

.kv-val {
  font-weight: 600;
  color: var(--accent-teal);
}

.tendency-pill {
  display: inline-block;
  background: var(--accent-gold-soft);
  color: var(--accent-gold);
  border: 1px solid #e6d3a7;
  padding: 3px 8px;
  border-radius: 4px;
  font-size: 12.5px;
  font-weight: 600;
  margin-top: 4px;
}

/* Floating Selection Popover */
.selection-popover {
  position: fixed;
  z-index: 999;
  background: var(--accent-ink);
  color: #fff;
  padding: 4px 6px;
  border-radius: 6px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.18);
}

.selection-popover button {
  border: none;
  background: transparent;
  color: #fff;
  font-size: 12.5px;
  padding: 2px 8px;
  cursor: pointer;
  font-weight: 500;
}


/* Center Controls & Mount Strip */
.center-controls {
  display: flex;
  align-items: center;
  gap: 12px;
}

.mount-toggle {
  font-size: 12.5px;
  user-select: none;
  cursor: pointer;
}

.mount-strip {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 5px;
  margin: 3px 0 6px;
  padding: 5px 8px;
  background: #f8faf9;
  border: 1px solid #dce8e4;
  border-radius: 6px;
}

.mount-strip.unmounted {
  background: #fff8eb;
  border-color: #f0d090;
}

.mount-strip.obs-strip {
  background: #f7f6fc;
  border-color: #ded9f2;
}

.play-mount-toast {
  margin: 4px 0 8px 46px;
}

.mchip {
  display: inline-flex;
  align-items: center;
  font-size: 11.5px;
  padding: 1px 7px;
  border-radius: 4px;
  font-weight: 500;
  line-height: 1.5;
}

.mchip-lens {
  background: #ede9fe;
  color: #5b21b6;
  border: 1px solid #ddd6fe;
}

.mchip-boundary {
  background: #fbeaea;
  color: #9e2a2b;
  border: 1px solid #f0c2c3;
  font-weight: 600;
}

.mchip-residue {
  background: #fcf6e8;
  color: #8c6222;
  border: 1px solid #ead8b1;
}

.mchip-behavior {
  background: #e6f2ef;
  color: #185c4d;
  border: 1px solid #bfe0d8;
}

.mchip-trait {
  background: #eef2f6;
  color: #344054;
}

.mchip-obs {
  background: #f2f4f7;
  color: #475467;
}

.mchip-hook {
  background: #fffbeb;
  color: #92400e;
  border: 1px dashed #f59e0b;
}

.mchip-warn {
  background: #fef3c7;
  color: #b45309;
  font-weight: 600;
}

.mchip-note {
  color: var(--text-secondary);
}

.mount-edit-btn {
  margin-left: auto;
  border: 1px solid var(--border-strong);
  background: #fff;
  color: var(--accent-teal);
  border-radius: 4px;
  font-size: 11.5px;
  padding: 1px 8px;
  cursor: pointer;
  font-weight: 600;
}

.mount-edit-btn:hover {
  background: var(--accent-teal);
  color: #fff;
  border-color: var(--accent-teal);
}

/* Right Sidebar Lexicon Monitor & Quick Mount Drawer */
.mount-editor-box {
  background: #f9fbfa;
  border: 1.5px solid var(--accent-teal);
  border-radius: 8px;
  padding: 12px;
  margin-bottom: 14px;
}

.me-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 10px;
}

.me-title {
  font-weight: 700;
  color: var(--accent-teal);
  font-size: 13.5px;
}

.me-trigger {
  font-size: 11.5px;
  background: #e6f2ef;
  padding: 1px 6px;
  border-radius: 4px;
  color: #16594a;
}

.me-field {
  margin-bottom: 8px;
}

.me-field label {
  display: block;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 3px;
}

.me-field input,
.me-field select {
  width: 100%;
  border: 1px solid var(--border-strong);
  border-radius: 4px;
  padding: 5px 7px;
  font-size: 12.5px;
  background: #fff;
}

.me-grid2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.npc-check-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 4px 0;
}

.npc-check {
  display: inline-flex !important;
  align-items: center;
  gap: 4px;
  font-size: 12px !important;
  font-weight: 500 !important;
  background: #fff;
  border: 1px solid var(--border);
  padding: 2px 7px;
  border-radius: 4px;
  cursor: pointer;
}

.npc-check input {
  width: auto;
  margin: 0;
}

.me-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 8px;
}

.state-card {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  margin-bottom: 10px;
  background: #fff;
}

.empty-hint {
  font-size: 12px;
  color: var(--text-muted);
}

.lens-banner {
  background: #f5f3ff;
  border: 1px solid #ddd6fe;
  border-radius: 6px;
  padding: 7px 10px;
  margin-bottom: 6px;
}

.lens-name {
  font-weight: 700;
  color: #5b21b6;
  font-size: 13px;
}

.lens-desc {
  font-size: 12px;
  color: #4c1d95;
  margin-top: 2px;
}

.boundary-banner {
  background: #fbeaea;
  border: 1px solid #f0c2c3;
  color: #8c2327;
  border-radius: 6px;
  padding: 7px 10px;
  font-size: 12px;
  margin-top: 6px;
}

.trait-row {
  margin-bottom: 8px;
}

.trait-top {
  display: flex;
  justify-content: space-between;
  font-size: 12.5px;
  margin-bottom: 3px;
}

.trait-cnt {
  font-weight: 700;
  color: var(--accent-teal);
}

.trait-bar {
  height: 6px;
  background: var(--bg-subtle);
  border-radius: 4px;
  overflow: hidden;
}

.trait-fill {
  height: 100%;
  background: var(--accent-teal);
  border-radius: 4px;
}

.npc-monitor-note {
  font-size: 11.5px;
  color: var(--text-muted);
  margin-bottom: 8px;
  padding-bottom: 6px;
  border-bottom: 1px dashed var(--border);
}

.npc-mem-item {
  display: grid;
  grid-template-columns: 54px minmax(0, 1fr);
  gap: 6px;
  padding: 5px 0;
  border-bottom: 1px solid #f2f2ef;
  font-size: 12px;
}

.npc-mem-item:last-child {
  border-bottom: none;
}

.npc-mem-name {
  font-weight: 700;
  color: var(--accent-ink);
}

.npc-mem-list {
  color: var(--text-secondary);
}

.hook-item {
  font-size: 12px;
  color: var(--text-secondary);
  padding: 4px 0;
  border-bottom: 1px dashed #eee;
}

.hook-item:last-child {
  border-bottom: none;
}

.hook-target {
  display: inline-block;
  background: #fffbeb;
  color: #92400e;
  border: 1px solid #fcd34d;
  border-radius: 4px;
  padding: 0 5px;
  font-size: 11px;
  font-weight: 600;
  margin-right: 4px;
}

.mount-list-item {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 8px;
  margin-bottom: 6px;
  cursor: pointer;
  background: #fcfcfa;
}

.mount-list-item:hover {
  border-color: var(--accent-teal);
}

.mount-list-item.active {
  background: var(--accent-teal-soft);
  border-color: #9fd3c7;
}

.mli-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 11.5px;
  margin-bottom: 2px;
}

.mli-top code {
  font-weight: 700;
  color: var(--text-main);
}

.mli-obs {
  color: var(--text-muted);
  font-size: 11px;
}

.mli-desc {
  font-size: 12px;
  color: var(--text-secondary);
}


/* Canonical Trait Quick-Pick Pills */
.trait-pick-row {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-bottom: 5px;
}

.trait-pick-btn {
  border: 1px solid var(--border-strong);
  background: #fff;
  color: var(--text-secondary);
  border-radius: 4px;
  font-size: 11px;
  padding: 1px 6px;
  cursor: pointer;
}

.trait-pick-btn.picked {
  background: var(--accent-teal);
  color: #fff;
  border-color: var(--accent-teal);
  font-weight: 600;
}

/* Hand-Edit Protection Tag & Version History Modal */
.script-row.is-human-edited {
  background: rgba(255, 248, 230, 0.45);
}

.human-tag {
  display: inline-block;
  font-size: 10px;
  line-height: 1.3;
  padding: 0 4px;
  margin-left: 4px;
  border-radius: 3px;
  background: #fef3c7;
  color: #92400e;
  border: 1px solid #f59e0b;
  vertical-align: middle;
  user-select: none;
}

.history-modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
}

.history-modal {
  width: min(980px, 92vw);
  height: min(680px, 86vh);
  background: #fff;
  border-radius: 10px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.22);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.history-head {
  padding: 12px 18px;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.history-body {
  flex: 1;
  display: grid;
  grid-template-columns: 280px 1fr;
  min-height: 0;
}

.history-list {
  border-right: 1px solid var(--border-subtle);
  overflow-y: auto;
  padding: 8px;
}

.history-item {
  padding: 8px 10px;
  border-radius: 6px;
  cursor: pointer;
  margin-bottom: 4px;
  border: 1px solid transparent;
}

.history-item:hover {
  background: #f8f9fa;
}

.history-item.active {
  background: #eef6f4;
  border-color: #8fc4b8;
}

.history-item-top {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-main);
}

.history-item-sub {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
}

.history-preview-wrap {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.history-preview-bar {
  padding: 8px 14px;
  border-bottom: 1px solid var(--border-subtle);
  background: #fafaf8;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12px;
  color: var(--text-secondary);
}

.history-preview-text {
  flex: 1;
  margin: 0;
  padding: 14px 18px;
  overflow: auto;
  font-family: "Consolas", "Microsoft YaHei", monospace;
  font-size: 13px;
  line-height: 1.7;
  white-space: pre-wrap;
  color: #1f2937;
}

/* Strikethrough Draft Comparison Rows */
.script-row.is-strike-row {
  background: #faf3f3;
  border-left: 3px solid #d89b9b;
}

.script-row.is-strike-row:hover {
  background: #f5e9e9;
}

.ln-strike {
  display: flex;
  align-items: baseline;
  gap: 8px;
  color: #8c6d6d;
  font-size: 13.5px;
}

.ln-strike del {
  text-decoration: line-through;
  text-decoration-color: #c25959;
  text-decoration-thickness: 1.5px;
  color: #867373;
}

.strike-badge {
  flex-shrink: 0;
  font-size: 11px;
  font-weight: 600;
  color: #9e2a2b;
  background: #fbeaea;
  border: 1px solid #ecc2c2;
  padding: 0 5px;
  border-radius: 4px;
  line-height: 1.5;
}

.strike-restore-btn,
.strike-del-btn {
  border: 1px solid #d8c4c4;
  background: #fff;
  color: #6c5858;
  border-radius: 4px;
  font-size: 11px;
  padding: 1px 6px;
  cursor: pointer;
  line-height: 1.4;
}

.strike-restore-btn:hover {
  background: var(--accent-teal-soft);
  border-color: var(--accent-teal);
  color: var(--accent-teal);
}

.strike-del-btn:hover {
  background: var(--accent-crimson-soft);
  border-color: var(--accent-crimson);
  color: var(--accent-crimson);
}


/* Multi-User Collaboration, Locks, AI Rules & Diff View */
.doc-panel-section {
  max-height: 48vh;
  overflow-y: auto;
}

.author-select {
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  padding: 4px 8px;
  background: #f8faf9;
  color: var(--accent-teal);
  font-weight: 600;
  font-size: 12.5px;
  cursor: pointer;
}

.ai-pack-btn {
  border-color: #9ec5bb;
  color: #155c4d;
  background: #f3faf8;
}

.ai-import-btn {
  border-color: #c2b5e8;
  color: #4c2d91;
  background: #f7f5fc;
}

.health-pill {
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 2px 9px;
  font-size: 11.5px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
}

.health-pill.ok {
  background: var(--accent-teal-soft);
  border-color: #b4dcd3;
  color: var(--accent-teal);
}

.health-pill.warn {
  background: var(--accent-gold-soft);
  border-color: #e6d3a7;
  color: var(--accent-gold);
}

.health-pill.err {
  background: var(--accent-crimson-soft);
  border-color: #e6b8b8;
  color: var(--accent-crimson);
}

.doc-item-badges {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

.doc-lock-tag {
  font-size: 10.5px;
  padding: 0 5px;
  border-radius: 4px;
  font-weight: 600;
  line-height: 1.5;
}

.doc-lock-tag.mine {
  background: var(--accent-teal-soft);
  color: var(--accent-teal);
}

.doc-lock-tag.others {
  background: var(--accent-gold-soft);
  color: var(--accent-gold);
}

.doc-lock-tag.review {
  background: #e7f0f8;
  color: #1f4f78;
}

.doc-lock-tag.locked {
  background: #ececef;
  color: #4b5563;
}

.collab-bar {
  position: sticky;
  top: 0;
  z-index: 12;
  background: #f7f9f8;
  border-bottom: 1px solid var(--border);
  padding: 7px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  font-size: 12.5px;
}

.collab-bar.is-readonly {
  background: #fff8eb;
  border-bottom-color: #ead39c;
}

.collab-bar.is-approved {
  background: #f2f4f7;
  border-bottom-color: #d0d5dd;
}

.collab-bar-info {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-secondary);
}

.collab-bar-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.health-drawer {
  margin: 10px 32px 0;
  padding: 12px 16px;
  background: #fff;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  font-size: 12.5px;
}

.health-drawer-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.health-item {
  padding: 4px 6px;
  border-radius: 4px;
  margin-bottom: 4px;
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.health-item.err {
  background: var(--accent-crimson-soft);
  color: var(--accent-crimson);
}

.health-item.warn {
  background: var(--accent-gold-soft);
  color: #7c5418;
}

.health-jump {
  border: none;
  background: rgba(255, 255, 255, 0.75);
  color: inherit;
  font-weight: 700;
  font-size: 11px;
  padding: 1px 6px;
  border-radius: 4px;
  cursor: pointer;
}

.author-tag {
  display: inline-block;
  font-size: 10px;
  line-height: 1.3;
  padding: 0 4px;
  margin-left: 4px;
  border-radius: 3px;
  background: #eef4f2;
  color: #1c6b5a;
  border: 1px solid #b8dcd4;
  vertical-align: middle;
  user-select: none;
}

.pop-sep {
  display: inline-block;
  width: 1px;
  height: 12px;
  background: rgba(255, 255, 255, 0.28);
  vertical-align: middle;
  margin: 0 2px;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  z-index: 210;
  display: flex;
  align-items: center;
  justify-content: center;
}

.studio-modal {
  width: min(760px, 94vw);
  max-height: 88vh;
  background: #fff;
  border-radius: 10px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.22);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.studio-modal.modal-wide {
  width: min(940px, 95vw);
}

.modal-body-pad {
  padding: 14px 18px 18px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.modal-form-grid {
  display: grid;
  grid-template-columns: 1.2fr 1fr;
  gap: 12px;
}

.modal-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12.5px;
  color: var(--text-secondary);
}

.modal-field > span {
  font-weight: 600;
}

.modal-field input,
.modal-field select {
  border: 1px solid var(--border-strong);
  border-radius: 5px;
  padding: 5px 8px;
  background: #fff;
  color: var(--text-main);
}

.range-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

.range-row input[type="number"] {
  width: 82px;
}

.pp-meta-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  margin: 4px 0;
}

.pp-meta-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.pp-btns {
  display: flex;
  align-items: center;
  gap: 8px;
}

.modal-code-area {
  width: 100%;
  min-height: 310px;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  padding: 10px 12px;
  font-family: "Consolas", "PingFang SC", "Microsoft YaHei", monospace;
  font-size: 12.5px;
  line-height: 1.6;
  resize: vertical;
  background: #fafaf8;
  color: var(--text-main);
}

.modal-code-area.short {
  min-height: 170px;
}

.ai-check-summary {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-secondary);
}

.ai-check-result {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px 12px;
  background: #fafaf9;
  max-height: 290px;
  overflow-y: auto;
  font-size: 12.5px;
}

.history-head-actions,
.history-preview-btns {
  display: flex;
  align-items: center;
  gap: 8px;
}

.mini-switch .mode-btn {
  padding: 2px 8px;
  font-size: 12px;
}

.history-diff-view {
  flex: 1;
  overflow: auto;
  padding: 12px 16px;
  font-family: "Consolas", "PingFang SC", "Microsoft YaHei", monospace;
  font-size: 12.5px;
  line-height: 1.65;
}

.diff-hunk {
  border: 1px solid var(--border);
  border-radius: 6px;
  margin-bottom: 10px;
  overflow: hidden;
}

.diff-hunk-head {
  background: var(--bg-subtle);
  padding: 3px 10px;
  font-size: 11.5px;
  color: var(--text-secondary);
  font-weight: 600;
}

.diff-row {
  display: grid;
  grid-template-columns: 44px 44px 20px minmax(0, 1fr);
  padding: 1px 8px;
  white-space: pre-wrap;
  word-break: break-word;
}

.diff-row.add {
  background: #ecfdf3;
  color: #0f5132;
}

.diff-row.del {
  background: #fef2f2;
  color: #991b1b;
}

.diff-row.ctx {
  background: #fff;
  color: var(--text-secondary);
}

.diff-ln {
  color: #9ca3af;
  font-size: 11px;
  user-select: none;
}

.collab-section-box {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 14px;
  background: #fafaf8;
}

.collab-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12.5px;
  margin-top: 8px;
}

.collab-table th,
.collab-table td {
  border-bottom: 1px solid var(--border);
  padding: 6px 8px;
  text-align: left;
}

.extra-upstream-presets {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.login-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(244, 244, 241, 0.96);
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: center;
}

.login-card {
  width: min(400px, 90vw);
  background: #fff;
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  padding: 24px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.08);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.login-title {
  font-size: 17px;
  font-weight: 700;
  color: var(--text-main);
}

.login-sub {
  font-size: 13px;
  color: var(--text-secondary);
}

.login-input {
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 14px;
}

.login-error {
  color: var(--accent-crimson);
  font-size: 12.5px;
  background: var(--accent-crimson-soft);
  padding: 6px 10px;
  border-radius: 5px;
}

.login-submit-btn {
  justify-content: center;
  padding: 8px 14px;
}

.identity-choice-list {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.identity-choice-btn {
  border: 1px solid var(--border-strong);
  background: #fff;
  border-radius: 6px;
  padding: 10px;
  cursor: pointer;
  font-weight: 600;
  text-align: center;
}

.identity-choice-btn:hover {
  border-color: var(--accent-teal);
  background: var(--accent-teal-soft);
  color: var(--accent-teal);
}


/* Word Count Pill, Chapter Balance Bars & Outline Expansion Pane */
.word-pill {
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 2px 9px;
  font-size: 11.5px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
  background: #f5f7f9;
  color: var(--accent-ink);
}

.word-pill.short {
  background: #fff8eb;
  border-color: #f0d090;
  color: #92400e;
}

.word-pill.ok {
  background: #eef6f4;
  border-color: #b4dcd3;
  color: #16594a;
}

.doc-wc-tag {
  font-size: 10.5px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.doc-wc-tag.is-short {
  color: #b45309;
  font-weight: 600;
}

.wb-row {
  margin-bottom: 8px;
  padding: 5px 6px;
  border-radius: 5px;
  cursor: pointer;
}

.wb-row:hover {
  background: #f8f9f8;
}

.wb-row.is-current {
  background: #f2f8f6;
  outline: 1px solid #bfe0d8;
}

.wb-top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 12px;
  margin-bottom: 3px;
}

.wb-bar-bg {
  height: 7px;
  background: var(--bg-subtle);
  border-radius: 4px;
  overflow: hidden;
  position: relative;
}

.wb-bar-fill {
  height: 100%;
  background: var(--accent-teal);
  border-radius: 4px;
}

.wb-bar-fill.short {
  background: #d97706;
}

.wb-bar-fill.intro {
  background: #94a3b8;
}

.wb-alert {
  background: #fff8eb;
  border: 1px solid #f0d090;
  color: #7c5418;
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 12px;
  line-height: 1.55;
  margin-bottom: 10px;
}

.outline-beat-card {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
  margin-bottom: 7px;
  background: #fcfcfa;
  font-size: 12.5px;
  line-height: 1.6;
  white-space: pre-wrap;
}

.supp-beat-card {
  border: 1px solid #bfe0d8;
  border-radius: 6px;
  padding: 8px 10px;
  margin-bottom: 7px;
  background: #f4faf8;
  font-size: 12.5px;
}

.supp-beat-card.done {
  opacity: 0.6;
  background: var(--bg-subtle);
  border-color: var(--border);
}

.supp-composer {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 8px;
  padding: 9px;
  background: #fafaf7;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
}

.supp-composer input,
.supp-composer textarea {
  width: 100%;
  border: 1px solid var(--border-strong);
  border-radius: 4px;
  padding: 5px 8px;
  font-size: 12.5px;
  background: #fff;
}
