:root {
  --bg: #0c0f1a;
  --bg-deep: #060810;
  --bg-glow: #182040;
  --panel: #141929;
  --panel-2: #1b2238;
  --border: #2d3656;
  --border-light: #3d4a72;
  --text: #e8ecf4;
  --muted: #a3acc4;
  --faint: #737c97;
  --accent: #a8c0ff;
  --accent-light: #c4d4ff;
  --accent-dark: #7a96d9;
  --accent-soft: rgba(168, 192, 255, .2);
  --accent-faint: rgba(168, 192, 255, .12);
  --on-accent: #08102a;
  --danger: #c2554a;
  --danger-light: #e08a80;
  --danger-border: #5a2b26;
  --danger-soft: rgba(194, 85, 74, .18);
  --header-bg: rgba(12, 15, 26, .92);
  --choice-bg: rgba(20, 25, 41, .85);
  --backdrop: rgba(3, 5, 12, .72);
  --toast-bg: rgba(27, 34, 56, .96);
  --preview-bg: rgba(24, 32, 64, .97);
  --radius: 8px;
}

/* ---------- 可选配色 ---------- */

html[data-theme="ember"] {
  --bg: #150c0a;
  --bg-deep: #0c0604;
  --bg-glow: #3a1a10;
  --panel: #241612;
  --panel-2: #2e1d17;
  --border: #4a2e24;
  --border-light: #5e3d31;
  --text: #f4e6dc;
  --muted: #b99a89;
  --faint: #886856;
  --accent: #ff7a3c;
  --accent-light: #ffa06e;
  --accent-dark: #c95418;
  --accent-soft: rgba(255, 122, 60, .2);
  --accent-faint: rgba(255, 122, 60, .12);
  --on-accent: #1a0a04;
  --danger: #c2554a;
  --danger-light: #e08a80;
  --danger-border: #5a2b26;
  --danger-soft: rgba(194, 85, 74, .18);
  --header-bg: rgba(21, 12, 10, .92);
  --choice-bg: rgba(36, 22, 18, .85);
  --backdrop: rgba(8, 3, 2, .72);
  --toast-bg: rgba(46, 29, 23, .96);
  --preview-bg: rgba(58, 26, 16, .97);
}

html[data-theme="mineral"] {
  --bg: #0a1a18;
  --bg-deep: #040e0d;
  --bg-glow: #16332f;
  --panel: #102623;
  --panel-2: #16302c;
  --border: #264a45;
  --border-light: #36635c;
  --text: #dff5f0;
  --muted: #93b8b1;
  --faint: #668780;
  --accent: #3dd1b8;
  --accent-light: #6be5cf;
  --accent-dark: #1fa48f;
  --accent-soft: rgba(61, 209, 184, .2);
  --accent-faint: rgba(61, 209, 184, .12);
  --on-accent: #021a15;
  --danger: #c2554a;
  --danger-light: #e08a80;
  --danger-border: #5a2b26;
  --danger-soft: rgba(194, 85, 74, .18);
  --header-bg: rgba(10, 26, 24, .92);
  --choice-bg: rgba(16, 38, 35, .85);
  --backdrop: rgba(2, 8, 7, .72);
  --toast-bg: rgba(22, 48, 44, .96);
  --preview-bg: rgba(22, 51, 47, .97);
}

html[data-theme="plasma"] {
  --bg: #120a1f;
  --bg-deep: #090511;
  --bg-glow: #2a1444;
  --panel: #1c1233;
  --panel-2: #241842;
  --border: #40295e;
  --border-light: #55387a;
  --text: #f3e7ff;
  --muted: #b9a3d4;
  --faint: #8670a3;
  --accent: #ff4fa8;
  --accent-light: #ff86c2;
  --accent-dark: #c9287e;
  --accent-soft: rgba(255, 79, 168, .2);
  --accent-faint: rgba(255, 79, 168, .12);
  --on-accent: #2a041a;
  --danger: #d1695e;
  --danger-light: #eb9a90;
  --danger-border: #6b3336;
  --danger-soft: rgba(209, 105, 94, .18);
  --header-bg: rgba(18, 10, 31, .92);
  --choice-bg: rgba(28, 18, 51, .85);
  --backdrop: rgba(7, 3, 14, .72);
  --toast-bg: rgba(36, 24, 66, .96);
  --preview-bg: rgba(64, 41, 94, .97);
}

html[data-theme="pearl"] {
  --bg: #faf6ef;
  --bg-deep: #ede6d8;
  --bg-glow: #fffaf0;
  --panel: #fffcf4;
  --panel-2: #f4ece0;
  --border: #d4c7ae;
  --border-light: #c2b295;
  --text: #2a2e33;
  --muted: #6a7078;
  --faint: #8a9098;
  --accent: #4a5568;
  --accent-light: #2d3748;
  --accent-dark: #1a202c;
  --accent-soft: rgba(74, 85, 104, .14);
  --accent-faint: rgba(74, 85, 104, .08);
  --on-accent: #faf6ef;
  --danger: #b23b32;
  --danger-light: #9c3029;
  --danger-border: #d9a9a2;
  --danger-soft: rgba(178, 59, 50, .14);
  --header-bg: rgba(250, 246, 239, .92);
  --choice-bg: rgba(255, 252, 244, .9);
  --backdrop: rgba(42, 46, 51, .45);
  --toast-bg: rgba(42, 46, 51, .94);
  --preview-bg: rgba(244, 236, 224, .97);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background:
    radial-gradient(circle at 50% 0%, var(--bg-glow) 0%, var(--bg) 45%, var(--bg-deep) 100%);
  background-attachment: fixed;
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", "PingFang SC", sans-serif;
  font-size: 14.5px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
  touch-action: manipulation;
}

button:disabled {
  cursor: not-allowed;
}

input {
  font: inherit;
}

h1,
h2,
h3,
h4,
p {
  margin: 0;
}

/* ---------- 登录 ---------- */

.auth-screen {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.auth-card {
  width: min(380px, 100%);
  padding: 30px 26px 24px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 18px 50px rgba(0, 0, 0, .45);
}

.auth-brand {
  text-align: center;
  margin-bottom: 24px;
}

.auth-logo {
  width: 64px;
  height: 64px;
  margin: 0 auto 10px;
}

.auth-logo svg {
  width: 100%;
  height: 100%;
  display: block;
}

.auth-brand h1 {
  font-size: 28px;
  letter-spacing: 6px;
  color: var(--accent-light);
}

.auth-brand p {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 2px;
}

.field {
  display: block;
  margin-bottom: 14px;
}

.field span {
  display: block;
  margin-bottom: 5px;
  color: var(--muted);
  font-size: 12px;
}

.field input {
  width: 100%;
  height: 38px;
  padding: 0 11px;
  background: var(--bg-deep);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  outline: none;
}

.field input:focus {
  border-color: var(--accent-dark);
}

.field input::placeholder {
  color: var(--faint);
  font-size: 12px;
}

.form-error {
  min-height: 18px;
  margin: 2px 0 8px;
  color: var(--danger);
  font-size: 12px;
}

.btn-primary {
  width: 100%;
  height: 40px;
  background: var(--accent);
  border: 1px solid var(--accent-dark);
  border-radius: var(--radius);
  color: var(--on-accent);
  font-weight: 700;
}

.btn-primary:hover:not(:disabled) {
  background: var(--accent-light);
}

.btn-primary:disabled {
  opacity: .6;
}

.auth-hint {
  margin-top: 14px;
  color: var(--faint);
  font-size: 11px;
  text-align: center;
}

/* ---------- 配色选择 ---------- */

.theme-dots {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.theme-dot {
  width: 24px;
  height: 24px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--dot-bg);
  border: 1px solid var(--border-light);
  border-radius: 50%;
  transition: border-color .15s ease, box-shadow .15s ease;
}

.theme-dot span {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--dot-accent);
}

.theme-dot:hover {
  border-color: var(--accent);
}

.theme-dot.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-faint);
}

.theme-label {
  color: var(--muted);
  font-size: 12px;
}

.auth-note {
  margin-bottom: 16px;
  padding: 12px;
  background: var(--bg-deep);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--muted);
  font-size: 12px;
}

.btn-text {
  display: block;
  margin: 12px auto 0;
  padding: 4px 10px;
  background: none;
  border: 0;
  color: var(--faint);
  font-size: 12px;
}

.btn-text:hover {
  color: var(--accent-light);
}

.auth-foot {
  margin-top: 18px;
  color: var(--faint);
  font-size: 11px;
  letter-spacing: 1px;
}

/* ---------- 主界面 ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 22px;
  background: var(--header-bg);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(4px);
}

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

.brand-name {
  font-size: 19px;
  letter-spacing: 4px;
  color: var(--accent-light);
}

.user-tag {
  color: var(--faint);
  font-size: 11px;
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topbar-actions {
  display: flex;
  gap: 8px;
}

.btn-ghost {
  padding: 7px 15px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 13px;
}

.btn-ghost:hover {
  border-color: var(--accent-dark);
  color: var(--accent-light);
}

/* ---------- 阅读区 ---------- */

.game-main {
  width: min(720px, 100%);
  margin: 0 auto;
  padding: 22px 18px 70px;
}

.scene-frame {
  margin: 0;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  background: var(--bg-deep);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 12px 36px rgba(0, 0, 0, .42);
}

#sceneImg {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0;
  transition: opacity .9s ease;
}

#sceneImg.ready {
  opacity: 1;
}

/* ---------- 正文：颜色档位 ---------- */
.story-text .story-c-accent { color: var(--accent-light); }
.story-text .story-c-muted { color: var(--muted); }
.story-text .story-c-faint  { color: var(--faint); }
.story-text .story-c-danger { color: var(--danger-light); }

/* ---------- 正文：5 种字体 ---------- */
:root {
  --font-stack-default: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
  --font-stack-serif:   "Source Han Serif SC", "Noto Serif CJK SC", "Songti SC", "SimSun", Georgia, serif;
  --font-stack-sans:    -apple-system, BlinkMacSystemFont, "Helvetica Neue", "PingFang SC", "Microsoft YaHei", sans-serif;
  --font-stack-mono:    "JetBrains Mono", "Fira Code", Consolas, "Liberation Mono", Menlo, monospace;
  --font-stack-hand:    "LXGW WenKai", "Long Cang", "KaiTi", "楷体", cursive;
}

.story-text {
  margin-top: 26px;
  font-size: 16px;
  line-height: 2.0;
  letter-spacing: .4px;
  font-family: var(--font-stack-default);
}

.story-text.story-f-serif { font-family: var(--font-stack-serif); }
.story-text.story-f-sans  { font-family: var(--font-stack-sans);  }
.story-text.story-f-mono  { font-family: var(--font-stack-mono);  }
.story-text.story-f-hand  { font-family: var(--font-stack-hand);  }

.story-text p {
  margin: 0 0 1.1em;
  animation: text-in .5s ease both;
}

.story-text p:nth-child(2) { animation-delay: .08s; }
.story-text p:nth-child(3) { animation-delay: .16s; }
.story-text p:nth-child(4) { animation-delay: .24s; }

@keyframes text-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ---------- 选项 ---------- */

.choices {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 32px;
}

.choice {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 14px 17px;
  background: var(--choice-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  text-align: left;
  font-size: 14.5px;
  transition: border-color .15s ease, background .15s ease, transform .15s ease;
}

.choice:hover:not(.locked) {
  border-color: var(--accent-dark);
  background: var(--panel-2);
  transform: translateX(4px);
}

.choice.locked {
  opacity: .55;
}

.choice-lock {
  color: var(--faint);
  font-size: 11.5px;
}

/* ---------- 结局面板 ---------- */

.ending-panel {
  margin-top: 36px;
  padding: 30px 24px;
  background:
    radial-gradient(circle at 50% 0%, var(--accent-faint) 0%, transparent 70%),
    var(--panel);
  border: 1px solid var(--accent-dark);
  border-radius: 10px;
  text-align: center;
  animation: text-in .6s ease both;
}

.ending-tone {
  display: inline-block;
  padding: 3px 14px;
  border: 1px solid var(--accent-dark);
  border-radius: 999px;
  color: var(--accent-light);
  font-size: 11px;
  letter-spacing: 2px;
}

.ending-title {
  margin-top: 12px;
  font-size: 26px;
  letter-spacing: 8px;
  color: var(--accent-light);
}

.ending-actions {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin-top: 20px;
}

.ending-actions .btn-primary {
  width: auto;
  min-width: 130px;
  padding: 0 22px;
}

/* ---------- 浮层窗口 ---------- */

.modal-layer {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  background: var(--backdrop);
  backdrop-filter: blur(2px);
}

.modal-window {
  display: flex;
  flex-direction: column;
  width: min(520px, 100%);
  max-height: min(82dvh, 720px);
  background: var(--panel);
  border: 1px solid var(--border-light);
  border-radius: 8px;
  box-shadow: 0 24px 70px rgba(0, 0, 0, .65);
}

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

.modal-head h2 {
  font-size: 16px;
  letter-spacing: 2px;
}

.modal-close {
  width: 30px;
  height: 30px;
  padding: 0;
  background: none;
  border: 1px solid transparent;
  border-radius: var(--radius);
  color: var(--muted);
  font-size: 22px;
  line-height: 1;
}

.modal-close:hover {
  color: var(--text);
  border-color: var(--border);
}

.modal-body {
  padding: 16px 18px 20px;
  overflow-y: auto;
}

.modal-section + .modal-section {
  margin-top: 22px;
  padding-top: 18px;
  border-top: 1px solid var(--border);
}

.modal-section h3 {
  margin-bottom: 10px;
  font-size: 14px;
  color: var(--accent-light);
}

/* ---------- 图鉴 ---------- */

.ending-list {
  margin: 10px 0 0;
  padding: 0;
  list-style: none;
}

.ending-item {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 14px;
  padding: 11px 2px;
  border-bottom: 1px solid var(--border);
}

.ending-item:last-child {
  border-bottom: 0;
}

.ending-name {
  font-size: 14.5px;
  color: var(--accent-light);
  letter-spacing: 2px;
}

.ending-item.locked .ending-name {
  color: var(--faint);
}

.ending-hint {
  color: var(--faint);
  font-size: 11.5px;
  text-align: right;
}

/* ---------- 设置 ---------- */

.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 9px 2px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}

.setting-row:last-child {
  border-bottom: 0;
}

.setting-row span:first-child {
  color: var(--muted);
}

.setting-hint {
  margin-top: 8px;
  color: var(--faint);
  font-size: 11px;
}

.btn-secondary {
  padding: 8px 14px;
  margin-top: 10px;
  margin-right: 8px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 12px;
}

.btn-secondary:hover {
  border-color: var(--accent-dark);
}

.btn-secondary.danger {
  border-color: var(--danger-border);
  color: var(--danger-light);
}

.btn-secondary.danger:hover {
  border-color: var(--danger);
}

/* ---------- 提示 ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: 30px;
  z-index: 200;
  transform: translate(-50%, 12px);
  max-width: min(360px, calc(100vw - 32px));
  padding: 9px 18px;
  background: var(--toast-bg);
  border: 1px solid var(--border-light);
  border-radius: 999px;
  color: var(--text);
  font-size: 12px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .18s ease, transform .18s ease;
}

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

/* ---------- 草稿试玩提示条 ---------- */

.preview-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 8px 16px;
  background: var(--preview-bg);
  border-top: 1px solid var(--accent-dark);
  color: var(--accent-light);
  font-size: 12px;
}

.preview-bar .btn-secondary {
  margin: 0;
  padding: 4px 10px;
}

/* ---------- 剧情编辑器 ---------- */

body.editor-open {
  overflow: hidden;
}

.editor-layer {
  position: fixed;
  inset: 0;
  z-index: 120;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 14px;
  background: var(--backdrop);
  backdrop-filter: blur(3px);
}

.editor-shell {
  display: flex;
  flex-direction: column;
  width: min(1180px, 100%);
  height: min(92dvh, 980px);
  background: var(--panel);
  border: 1px solid var(--border-light);
  border-radius: 10px;
  box-shadow: 0 24px 70px rgba(0, 0, 0, .7);
  overflow: hidden;
}

.editor-head {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 16px;
  padding: 13px 18px;
  border-bottom: 1px solid var(--border);
}

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

.editor-font {
  display: flex;
  align-items: center;
  gap: 8px;
}

.editor-font select.ed-input {
  height: 28px;
  padding: 0 8px;
  font-size: 12px;
  width: 110px;
}

.editor-head-actions {
  margin-left: 12px;
}

.editor-title {
  display: flex;
  align-items: baseline;
  gap: 12px;
  min-width: 0;
}

.editor-title h2 {
  font-size: 16px;
  letter-spacing: 2px;
}

.editor-meta {
  color: var(--faint);
  font-size: 11px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.editor-head-actions {
  display: flex;
  align-items: center;
  gap: 7px;
}

.editor-head-actions .btn-secondary {
  margin: 0;
  padding: 6px 11px;
}

.btn-secondary.accent {
  border-color: var(--accent-dark);
  color: var(--accent-light);
}

.editor-tabs {
  display: flex;
  gap: 4px;
  padding: 0 14px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-deep);
  overflow-x: auto;
}

.editor-tabs button {
  padding: 10px 14px;
  background: none;
  border: 0;
  border-bottom: 2px solid transparent;
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}

.editor-tabs button.active {
  color: var(--accent-light);
  border-bottom-color: var(--accent);
}

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

.editor-side {
  width: 260px;
  flex: none;
  padding: 14px;
  background: var(--bg-deep);
  border-right: 1px solid var(--border);
  overflow-y: auto;
}

.editor-main {
  flex: 1;
  min-width: 0;
  padding: 18px 22px 40px;
  overflow-y: auto;
}

.editor-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 8px 16px;
  border-top: 1px solid var(--border);
  color: var(--faint);
  font-size: 11px;
}

#edDirty.dirty {
  color: var(--accent-light);
}

.ed-side-head {
  display: flex;
  gap: 7px;
  margin-bottom: 12px;
}

.ed-side-head .btn-secondary {
  margin: 0;
  white-space: nowrap;
}

.ed-side-head .ed-input {
  flex: 1;
  min-width: 0;
}

.ed-side-label {
  display: block;
  margin: 0 0 4px;
  color: var(--faint);
  font-size: 11px;
}

.ed-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-top: 10px;
}

.ed-list-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
  padding: 8px 9px;
  background: var(--panel);
  border: 1px solid transparent;
  border-radius: var(--radius);
  color: var(--text);
  text-align: left;
  font-size: 12px;
  cursor: pointer;
  user-select: none;
}

.ed-list-item:hover {
  border-color: var(--border);
}

.ed-list-item.active {
  border-color: var(--accent-dark);
  background: var(--panel-2);
}

.ed-list-item:has(.ed-tag.start) {
  border-left: 2px solid var(--accent);
}

.ed-list-action {
  flex: none;
  width: 22px;
  height: 22px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 50%;
  color: var(--faint);
  font-size: 11px;
  line-height: 1;
  cursor: pointer;
  opacity: 0;
  transition: opacity .12s ease, color .12s ease, border-color .12s ease, background .12s ease;
}

.ed-list-item:hover .ed-list-action {
  opacity: 1;
}

.ed-list-action:hover {
  color: var(--accent-light);
  border-color: var(--accent-dark);
  background: var(--accent-soft);
}

.ed-list-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ed-list-tag {
  flex: none;
  color: var(--faint);
  font-size: 10px;
}

.ed-list-tags {
  display: flex;
  flex: none;
  gap: 3px;
}

.ed-tag {
  padding: 1px 5px;
  border-radius: 3px;
  font-size: 9px;
  line-height: 1.6;
}

.ed-tag.start {
  background: var(--accent-soft);
  color: var(--accent-light);
}

.ed-tag.ending {
  background: var(--danger-soft);
  color: var(--danger-light);
}

.ed-form-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.ed-form-head h3,
.ed-form-head h4 {
  font-size: 14px;
  color: var(--accent-light);
  letter-spacing: 1px;
}

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

.ed-form-actions .btn-secondary,
.ed-form-head .btn-secondary {
  margin: 0;
  padding: 5px 10px;
}

.ed-section {
  padding: 18px;
  margin-bottom: 14px;
  background: var(--bg-deep);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.ed-section h4 {
  margin-bottom: 12px;
  font-size: 13px;
  color: var(--muted);
}

.ed-field {
  display: block;
  margin-bottom: 14px;
  color: var(--muted);
  font-size: 11px;
}

.ed-field:last-child {
  margin-bottom: 0;
}

.ed-toolbar {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-top: 8px;
  margin-bottom: 2px;
}

.ed-tb-btn {
  min-width: 26px;
  height: 24px;
  padding: 0 6px;
  background: var(--bg-deep);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
  font-size: 12px;
  font-weight: 600;
  line-height: 1;
  cursor: pointer;
  transition: border-color .15s, color .15s;
}

.ed-tb-btn:hover {
  border-color: var(--accent-dark);
  color: var(--accent-light);
}

.ed-tb-btn.ed-tb-danger:hover {
  border-color: var(--danger-border);
  color: var(--danger-light);
}

.ed-tb-sep {
  width: 1px;
  height: 14px;
  background: var(--border);
  margin: 0 4px;
}

.ed-input {
  display: block;
  width: 100%;
  margin-top: 5px;
  padding: 8px 10px;
  background: var(--bg-deep);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 13px;
  line-height: 1.5;
  outline: none;
}

textarea.ed-input {
  resize: vertical;
  font-family: inherit;
}

.ed-input:focus {
  border-color: var(--accent-dark);
}

.ed-outline {
  min-height: 420px;
  line-height: 1.8;
  font-family: var(--font-hand, inherit);
}

/* ---------- 旗标选择器 ---------- */
.ed-flag-picker {
  margin-top: 5px;
  position: relative;
}

.ed-fp-tags {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  padding: 6px 8px;
  min-height: 34px;
  background: var(--bg-deep);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  transition: border-color .15s;
  cursor: text;
}

.ed-fp-tags:focus-within {
  border-color: var(--accent-dark);
}

.ed-fp-tags:empty::before {
  content: attr(data-placeholder);
  color: var(--faint);
  font-size: 12px;
}

.ed-fp-input {
  flex: 1;
  min-width: 80px;
  border: none;
  outline: none;
  background: transparent;
  color: var(--text);
  font-size: 13px;
  padding: 2px 0;
}

.ed-fp-tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 6px 2px 8px;
  background: var(--accent-soft);
  border: 1px solid var(--accent-dark);
  color: var(--accent-light);
  font-size: 11px;
  line-height: 1.6;
  border-radius: 10px;
  white-space: nowrap;
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ed-fp-tag.neg {
  background: var(--danger-soft);
  border-color: var(--danger-border);
  color: var(--danger-light);
}

.ed-fp-x {
  border: none;
  background: transparent;
  color: inherit;
  opacity: .7;
  font-size: 12px;
  line-height: 1;
  cursor: pointer;
  padding: 0 1px;
  margin-left: 2px;
}

.ed-fp-x:hover { opacity: 1; }

/* 下拉用 fixed 定位（坐标由 JS 计算），避免被编辑器滚动容器裁剪 */
.ed-fp-dropdown {
  position: fixed;
  z-index: 300;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 6px 18px rgba(0,0,0,.35);
  max-height: 260px;
  overflow-y: auto;
  padding: 6px;
}

.ed-fp-dropdown[hidden] {
  display: none;
}

.ed-fp-empty {
  padding: 10px 12px;
  color: var(--faint);
  font-size: 12px;
  line-height: 1.6;
}

.ed-fp-group { margin-bottom: 6px; }
.ed-fp-group:last-child { margin-bottom: 0; }

.ed-fp-group-title {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--faint);
  padding: 4px 6px 6px;
}

.ed-fp-item {
  display: inline-block;
  margin: 2px 3px;
  padding: 3px 8px;
  background: var(--bg-deep);
  border: 1px solid var(--border-light);
  border-radius: 10px;
  color: var(--text);
  font-size: 12px;
  cursor: pointer;
  transition: background .1s, border-color .1s, color .1s;
}

.ed-fp-item:hover {
  border-color: var(--accent-dark);
  color: var(--accent-light);
}

.ed-fp-item.neg:hover {
  border-color: var(--danger-border);
  color: var(--danger-light);
}

.ed-fp-item.var {
  border-style: dashed;
  color: var(--faint);
}

.ed-fp-item.var:hover {
  border-color: var(--accent-dark);
  color: var(--accent-light);
}

.ed-fp-tip {
  display: block;
  margin-top: 4px;
  font-size: 10px;
  color: var(--faint);
  line-height: 1.4;
}

.ed-inline {
  display: flex;
  gap: 6px;
  align-items: center;
}

.ed-inline .ed-input {
  margin-top: 0;
}

.ed-inline .btn-secondary {
  margin: 0;
  white-space: nowrap;
}

.ed-hint {
  display: block;
  margin-top: 5px;
  color: var(--faint);
  font-size: 10.5px;
  line-height: 1.6;
}

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

.ed-check {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 4px;
  padding: 9px 10px;
  background: var(--bg-deep);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--muted);
  font-size: 12px;
}

.ed-scene-preview {
  margin: -4px 0 14px;
  aspect-ratio: 16 / 9;
  max-height: 180px;
  overflow: hidden;
  background: var(--bg-deep);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.ed-scene-preview.large {
  max-height: 320px;
}

.ed-scene-preview img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.ed-choices,
.ed-branches {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.ed-choice {
  padding: 15px 15px 13px;
  background: var(--panel-2);
  border: 1.5px solid var(--border-light);
  border-radius: var(--radius);
  position: relative;
}

.ed-choice + .ed-choice {
  border-top-style: solid;
  border-top-width: 1.5px;
  border-top-color: var(--border-light);
}

.ed-choice-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
  color: var(--muted);
  font-size: 12px;
}

.ed-choice-head > strong {
  color: var(--accent-light);
  font-weight: 700;
  letter-spacing: 0.5px;
  font-size: 13px;
  padding: 3px 10px;
  background: var(--accent-soft);
  border: 1px solid var(--accent-dark);
  border-radius: 12px;
  line-height: 1.2;
}

.ed-choice-body {
  display: block;
  margin-top: 4px;
}

.ed-choice.collapsed .ed-choice-body {
  display: none;
}

.ed-choice-toggle {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  margin-left: 4px;
  background: var(--bg-deep);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.2;
  cursor: pointer;
  user-select: none;
}

.ed-choice-toggle:hover {
  color: var(--text);
  border-color: var(--accent-dark);
}

.ed-choice-toggle .caret {
  transition: transform .18s ease;
  display: inline-block;
  font-size: 10px;
}

.ed-choice.collapsed .ed-choice-toggle .caret {
  transform: rotate(-90deg);
}

.ed-choice-toggle .summary {
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--faint);
}

.ed-choice.collapsed .ed-choice-toggle .summary {
  color: var(--muted);
}

.ed-choice-head .btn-secondary,
.ed-branches .btn-secondary {
  margin: 0;
  padding: 4px 9px;
}

.ed-branch {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 8px;
  align-items: end;
  padding: 10px;
  background: var(--bg-deep);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}

.ed-branch .ed-field {
  margin-bottom: 0;
}

.ed-branch .btn-secondary {
  align-self: end;
}

.ed-upload {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
}

.ed-upload .ed-hint {
  margin: 0;
}

.upload-label {
  display: inline-block;
  margin: 0 !important;
  cursor: pointer;
}

.ed-side-info {
  padding: 10px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--muted);
  font-size: 12px;
}

.ed-side-info p {
  margin-top: 8px;
  color: var(--faint);
  font-size: 10px;
}

.ed-side-info p:first-child {
  margin-top: 0;
}

.ed-side-info strong {
  color: var(--accent-light);
  font-size: 16px;
}

.ed-side-info span {
  color: var(--text);
  font-size: 11px;
}

.ed-check-summary {
  display: flex;
  gap: 8px;
}

.ed-check-num {
  flex: 1;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 22px;
  text-align: center;
}

.ed-check-num span {
  display: block;
  margin-top: 2px;
  color: var(--faint);
  font-size: 10px;
}

.ed-check-num.error {
  border-color: var(--danger-border);
  color: var(--danger-light);
}

.ed-check-num.warn {
  border-color: var(--accent-dark);
  color: var(--accent-light);
}

.ed-check-item {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  width: 100%;
  padding: 9px 10px;
  margin-bottom: 6px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 12px;
  text-align: left;
}

.ed-check-item:hover {
  border-color: var(--accent-dark);
}

.ed-check-dot {
  flex: none;
  width: 6px;
  height: 6px;
  margin-top: 5px;
  border-radius: 50%;
  background: var(--muted);
}

.ed-check-item.error .ed-check-dot {
  background: var(--danger);
}

.ed-check-item.warn .ed-check-dot {
  background: var(--accent);
}

.ed-version {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 12px;
  margin-bottom: 8px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.ed-version-main {
  font-size: 12px;
}

.ed-version-main strong {
  color: var(--accent-light);
  font-size: 15px;
  margin-right: 10px;
}

.ed-version-main span {
  color: var(--faint);
  font-size: 11px;
}

.ed-version-main p {
  margin-top: 4px;
  color: var(--muted);
}

.ed-version .btn-secondary {
  margin: 0;
  white-space: nowrap;
}

@media (max-width: 860px) {
  .editor-layer {
    padding: 0;
  }

  .editor-shell {
    width: 100%;
    height: 100dvh;
    border-radius: 0;
  }

  .editor-body {
    flex-direction: column;
  }

  .editor-side {
    width: 100%;
    max-height: 190px;
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }

  .editor-main {
    padding: 14px 12px 30px;
  }

  .editor-head {
    padding: 10px 12px;
    gap: 10px;
  }

  .editor-theme .theme-label {
    display: none;
  }

  .editor-theme .theme-dot {
    width: 18px;
    height: 18px;
  }

  .editor-theme .theme-dot span {
    width: 8px;
    height: 8px;
  }

  .editor-head-actions {
    margin-left: 0;
  }

  .editor-meta {
    display: none;
  }

  .editor-head-actions .btn-secondary {
    padding: 5px 8px;
    font-size: 11px;
  }

  .ed-grid2,
  .ed-branch {
    grid-template-columns: 1fr;
  }
}

/* ---------- 响应式 ---------- */

@media (max-width: 860px) {
  .topbar {
    padding: 10px 14px;
  }

  .brand-name {
    font-size: 17px;
  }

  .btn-ghost {
    padding: 6px 11px;
    font-size: 12px;
  }

  .game-main {
    padding: 14px 14px 60px;
  }

  .story-text {
    margin-top: 18px;
    font-size: 15px;
  }

  .ending-title {
    font-size: 22px;
    letter-spacing: 5px;
  }

  .modal-layer {
    padding: 12px;
  }

  .modal-window {
    max-height: 88dvh;
  }
}

/* ---------------- 管理控制台 ---------------- */

.console-screen {
  max-width: 980px;
  margin: 0 auto;
  padding: 40px 20px 64px;
}

.console-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--border);
}

.console-title h1 {
  margin: 0;
  font-size: 22px;
  letter-spacing: 2px;
  color: var(--accent-light);
}

.console-sub {
  display: block;
  margin-top: 4px;
  font-size: 12px;
  color: var(--faint);
}

.console-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 0 0 auto;
}

.console-actions .btn-primary,
.console-actions .btn-secondary {
  width: auto;
  height: 36px;
  margin: 0;
  padding: 0 16px;
  font-size: 13px;
  white-space: nowrap;
}

.game-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 20px;
}

.game-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  padding: 18px 20px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.game-card-main {
  min-width: 0;
}

.game-card-main h2 {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  font-size: 16px;
  font-weight: 600;
}

.game-meta {
  margin: 6px 0 0;
  font-size: 12px;
  color: var(--faint);
  word-break: break-all;
}

.badge {
  padding: 2px 8px;
  font-size: 11px;
  font-weight: 500;
  border-radius: 999px;
  border: 1px solid var(--border-light);
  color: var(--muted);
}

.badge.published {
  color: var(--accent-light);
  border-color: var(--accent-dark);
  background: var(--accent-faint);
}

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

.game-card-actions .btn-secondary,
.game-card-actions .btn-ghost {
  height: 32px;
  margin: 0;
  padding: 0 12px;
  font-size: 12px;
  line-height: 1;
  white-space: nowrap;
}

.game-card-actions .danger {
  color: var(--danger);
}

.console-empty {
  margin-top: 28px;
  text-align: center;
  color: var(--faint);
  font-size: 13px;
}

@media (max-width: 640px) {
  .console-screen {
    padding: 24px 14px 48px;
  }

  .game-card {
    align-items: flex-start;
    flex-direction: column;
  }
}

/* ---------- 试玩调试面板 ---------- */

.debug-panel {
  position: fixed;
  right: 14px;
  bottom: 14px;
  z-index: 60;
  width: 300px;
  max-height: 46vh;
  overflow-y: auto;
  padding: 10px 12px;
  background: rgba(13, 11, 9, .94);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  box-shadow: 0 10px 30px rgba(0, 0, 0, .45);
  color: var(--text);
  font-size: 11px;
}

.debug-panel[hidden] { display: none; }

.debug-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
  color: var(--accent-light);
  font-size: 12px;
}

.debug-select {
  max-width: 160px;
  height: 24px;
  padding: 0 6px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
  font-size: 11px;
}

.debug-row {
  display: flex;
  gap: 8px;
  padding: 3px 0;
  line-height: 1.6;
}

.debug-label {
  flex: none;
  width: 48px;
  color: var(--faint);
}

.debug-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  min-width: 0;
}

.debug-chip {
  padding: 1px 6px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 3px;
  color: var(--muted);
  font-size: 11px;
}

button.debug-chip:hover { border-color: var(--accent-dark); color: var(--text); }
.debug-chip.on { color: var(--accent-light); border-color: var(--accent-dark); }
.debug-chip.var { color: #9fc7d9; }
.debug-chip.active { color: var(--on-accent); background: var(--accent); border-color: var(--accent); }

/* ---------- 编辑器：旗标 / 关联 / 搜索 / 对比 / 属性 ---------- */

.ed-badge {
  flex: none;
  padding: 1px 6px;
  border-radius: 3px;
  font-size: 10px;
  line-height: 16px;
  border: 1px solid var(--border);
  color: var(--muted);
}

.ed-badge.warn { color: var(--accent-light); border-color: var(--accent-dark); background: var(--accent-faint); }
.ed-badge.danger { color: var(--danger-light); border-color: var(--danger-border); background: var(--danger-soft); }
.ed-badge.ok { color: var(--muted); }

.ed-usage {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-top: 6px;
}

.ed-usage-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 6px 8px;
  background: var(--panel);
  border: 1px solid transparent;
  border-radius: 4px;
  color: var(--text);
  text-align: left;
  font-size: 12px;
}

.ed-usage-item:hover { border-color: var(--border); }
.ed-usage-item .ed-usage-where { flex: none; color: var(--faint); font-size: 11px; }
.ed-usage-item .ed-usage-cond { color: var(--accent-light); font-size: 11px; }

.ed-path {
  padding: 6px 8px;
  margin-top: 4px;
  background: var(--panel);
  border-radius: 4px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.7;
  word-break: break-all;
}

.ed-search-box {
  display: flex;
  gap: 7px;
  margin-bottom: 12px;
}

.ed-search-box .ed-input { flex: 1; }

.ed-result {
  display: block;
  width: 100%;
  padding: 9px 10px;
  margin-bottom: 6px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  text-align: left;
  font-size: 12px;
  line-height: 1.6;
}

.ed-result:hover { border-color: var(--accent-dark); }
.ed-result-head { display: flex; justify-content: space-between; gap: 8px; color: var(--accent-light); font-size: 11px; margin-bottom: 3px; }
.ed-result-snippet { color: var(--muted); word-break: break-all; }
.ed-result-snippet mark { background: var(--accent-soft); color: var(--accent-light); }

.ed-batch-bar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  padding: 8px 10px;
  margin-bottom: 12px;
  background: var(--accent-faint);
  border: 1px solid var(--accent-dark);
  border-radius: var(--radius);
  font-size: 12px;
}

.ed-batch-bar .ed-input { width: auto; min-width: 140px; height: 30px; }
.ed-batch-bar .btn-secondary { margin: 0; }

.ed-list-check {
  flex: none;
  width: 14px;
  height: 14px;
  margin: 0;
  accent-color: var(--accent);
}

.ed-scene-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  gap: 8px;
  margin-top: 8px;
}

.ed-scene-card {
  display: block;
  padding: 0;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  color: var(--text);
  font-size: 11px;
  text-align: left;
}

.ed-scene-card:hover { border-color: var(--accent-dark); }
.ed-scene-card img { display: block; width: 100%; aspect-ratio: 16 / 9; object-fit: cover; background: var(--bg-deep); }
.ed-scene-card span { display: block; padding: 4px 6px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.ed-relate-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 8px;
  font-size: 12px;
}

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

.ed-relate-table th { color: var(--faint); font-weight: normal; font-size: 11px; }
.ed-relate-table td.cond { color: var(--accent-light); font-size: 11px; }
.ed-relate-link {
  background: none;
  border: 0;
  padding: 0;
  color: var(--accent-light);
  font-size: 12px;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.ed-diff-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 18px;
  padding: 8px 10px;
  margin-bottom: 12px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 12px;
  color: var(--muted);
}

.ed-diff-summary strong { color: var(--accent-light); font-weight: normal; }

.ed-diff-group { margin-bottom: 14px; }

.ed-diff-group h4 {
  margin: 0 0 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: normal;
}

.ed-diff-row {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 6px 8px;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
}

.ed-diff-row .ed-diff-id { flex: none; width: 150px; color: var(--text); word-break: break-all; }
.ed-diff-row .ed-diff-kind { flex: none; color: var(--faint); font-size: 11px; }
.ed-diff-row .ed-diff-fields { color: var(--accent-light); font-size: 11px; }

.ed-var-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  background: var(--panel);
  border: 1px solid transparent;
  border-radius: 4px;
  font-size: 12px;
}

.ed-var-row:hover { border-color: var(--border); }
.ed-var-row.active { border-color: var(--accent-dark); background: var(--panel-2); }

/* ---------- 跳转到 + 跳转按钮 ---------- */
.ed-with-btn {
  display: flex;
  align-items: center;
  gap: 6px;
}
.ed-with-btn .ed-input {
  flex: 1;
  min-width: 0;
}
.btn-secondary.small {
  padding: 4px 8px;
  font-size: 12px;
  line-height: 1;
  white-space: nowrap;
}
.btn-secondary.small:hover {
  border-color: var(--accent-dark);
  color: var(--accent-light);
}

/* flag picker: setter 类型里混进了数值属性 tag — 标红警示 */
.ed-fp-tag.var-warn {
  background: var(--danger-soft) !important;
  border-color: var(--danger) !important;
  color: var(--danger-light) !important;
}
.ed-fp-tag.var-warn:hover {
  background: var(--danger-border) !important;
}
