/* ===========================================================
   Novel — 沉浸式文字剧情引擎
   =========================================================== */

:root {
  --bg: #080b10;
  --bg-2: #0c1017;
  --panel: #111823;
  --panel-2: #161d2a;
  --panel-3: #1b2431;
  --line: rgba(255, 255, 255, .07);
  --line-strong: rgba(255, 255, 255, .13);
  --text: #e9e6e0;
  --text-2: #b9bfc9;
  --text-dim: #7d8794;
  --gold: #d8b478;
  --gold-soft: rgba(216, 180, 120, .14);
  --dialogue: #e4b273;
  --tag: #8fb0c9;
  --danger: #d9736a;
  --radius: 14px;
  --radius-sm: 10px;
  --serif: "Noto Serif SC", "Source Han Serif SC", "Songti SC", "SimSun", Georgia, "Times New Roman", serif;
  --sans: "PingFang SC", "HarmonyOS Sans SC", "Microsoft YaHei", "Segoe UI", system-ui, -apple-system, sans-serif;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  --reading: 18px;
}

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

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  overscroll-behavior: none;
}

body {
  background-image:
    radial-gradient(1100px 620px at 15% -10%, rgba(216, 180, 120, .06), transparent 60%),
    radial-gradient(900px 500px at 95% 0%, rgba(143, 176, 201, .05), transparent 55%);
}

button, input, textarea, select {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
}

button { cursor: pointer; border: none; background: none; }
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, .1); border-radius: 8px; }
::-webkit-scrollbar-track { background: transparent; }

/* ---------------- 布局骨架 ---------------- */
.app {
  display: flex;
  height: 100dvh;
  overflow: hidden;
}

.sidebar {
  width: 268px;
  flex: 0 0 268px;
  background: var(--bg-2);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  padding-top: var(--safe-t);
}

.sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 16px 12px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  font-family: var(--serif);
  font-size: 19px;
  letter-spacing: .12em;
  color: var(--gold);
}

.brand-mark {
  width: 9px;
  height: 20px;
  border-radius: 3px;
  background: linear-gradient(180deg, var(--gold), rgba(216, 180, 120, .25));
}

.sidebar-body { flex: 1; overflow-y: auto; padding: 6px 10px; }

.sync-bar {
  display: flex;
  align-items: center;
  gap: 7px;
  margin: 0 12px 8px;
  padding: 7px 10px;
  border-radius: 9px;
  font-size: 11.5px;
  line-height: 1.4;
  color: var(--text-dim);
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, .022);
  cursor: default;
}
.sync-bar .sync-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  flex: 0 0 auto;
  background: #6b7482;
}
.sync-bar.synced { color: #8fcbb6; border-color: rgba(95, 181, 154, .32); background: rgba(95, 181, 154, .07); }
.sync-bar.synced .sync-dot { background: #5fb59a; box-shadow: 0 0 8px rgba(95, 181, 154, .8); }
.sync-bar.syncing .sync-dot { background: var(--gold); animation: pulseDot .9s infinite; }
.sync-bar.error { color: #e9a99f; border-color: rgba(217, 115, 106, .35); background: rgba(217, 115, 106, .08); }
.sync-bar.error .sync-dot { background: #d9736a; }
@keyframes pulseDot { 50% { opacity: .25; } }
.sync-bar .sync-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-label {
  font-size: 11px;
  letter-spacing: .18em;
  color: var(--text-dim);
  padding: 8px 8px 6px;
  text-transform: uppercase;
}

.session-list { display: flex; flex-direction: column; gap: 6px; }

.session-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 11px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  color: var(--text-2);
  text-align: left;
  transition: background .16s, border-color .16s;
  width: 100%;
}
.session-item:hover { background: rgba(255, 255, 255, .04); }
.session-item.active {
  background: var(--gold-soft);
  border-color: rgba(216, 180, 120, .3);
  color: var(--text);
}
.session-emoji { font-size: 16px; }
.session-meta { min-width: 0; flex: 1; }
.session-title {
  display: block;
  font-size: 13.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.session-sub { display: block; font-size: 11px; color: var(--text-dim); margin-top: 2px; }
.session-del { color: var(--text-dim); font-size: 14px; padding: 4px 6px; border-radius: 6px; opacity: 0; }
.session-item:hover .session-del { opacity: 1; }
.session-del:hover { color: var(--danger); background: rgba(217, 115, 106, .12); }

.sidebar-foot {
  display: flex;
  gap: 8px;
  padding: 12px;
  border-top: 1px solid var(--line);
  padding-bottom: calc(12px + var(--safe-b));
}
.ghost-btn {
  flex: 1;
  padding: 9px;
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, .04);
  border: 1px solid var(--line);
  color: var(--text-2);
  font-size: 12.5px;
  transition: background .16s;
}
.ghost-btn:hover { background: rgba(255, 255, 255, .08); color: var(--text); }

.main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  position: relative;
  background: var(--bg);
}

/* ---------------- 顶栏 ---------------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  padding-top: calc(10px + var(--safe-t));
  border-bottom: 1px solid var(--line);
  background: rgba(8, 11, 16, .88);
  backdrop-filter: blur(14px);
  z-index: 20;
}

.title-wrap {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 9px;
}
.title-icon {
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  border-radius: 9px;
  font-size: 15px;
  background: linear-gradient(135deg, rgba(216, 180, 120, .22), rgba(143, 176, 201, .16));
  border: 1px solid var(--line);
}
.title-text {
  font-size: 14px;
  color: var(--text-2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-family: var(--serif);
  letter-spacing: .04em;
}

.topbar-actions { display: flex; gap: 6px; align-items: center; }

.icon-btn {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border-radius: 9px;
  color: var(--text-2);
  font-size: 15px;
  border: 1px solid transparent;
  transition: background .16s, color .16s;
}
.icon-btn:hover { background: rgba(255, 255, 255, .06); color: var(--text); }

.mini-btn {
  padding: 7px 11px;
  border-radius: 8px;
  font-size: 12.5px;
  color: var(--text-2);
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, .03);
  white-space: nowrap;
  transition: .16s;
}
.mini-btn:hover { color: var(--gold); border-color: rgba(216, 180, 120, .35); background: var(--gold-soft); }
.mini-btn.active { color: var(--gold); border-color: rgba(216, 180, 120, .4); background: var(--gold-soft); }

/* ---------------- HUD（情感条） ---------------- */
.hud {
  padding: 9px 14px 10px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(17, 24, 35, .92), rgba(12, 16, 23, .78));
  backdrop-filter: blur(10px);
  z-index: 15;
}
.hud-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 9px;
}
.act-name {
  font-family: var(--serif);
  font-size: 14.5px;
  letter-spacing: .06em;
  color: var(--text);
}
.act-meta { font-size: 12px; color: var(--text-dim); letter-spacing: .06em; white-space: nowrap; }

.emotion-strip {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  scrollbar-width: none;
  padding-bottom: 2px;
}
.emotion-strip::-webkit-scrollbar { display: none; }

.emo {
  flex: 1 0 auto;
  min-width: 84px;
  padding: 5px 9px 6px;
  border-radius: 8px;
  background: rgba(255, 255, 255, .025);
  border: 1px solid var(--line);
  position: relative;
  overflow: hidden;
}
.emo-top { display: flex; align-items: baseline; gap: 4px; position: relative; z-index: 1; }
.emo-label { font-size: 11px; color: var(--text-dim); letter-spacing: .04em; }
.emo-val {
  font-size: 14px;
  font-weight: 600;
  margin-left: auto;
  color: var(--c);
  font-variant-numeric: tabular-nums;
}
.emo-arrow { font-size: 10px; color: var(--c); }
.emo-bar {
  position: absolute;
  left: 0; bottom: 0; height: 2px;
  width: 100%;
  background: rgba(255, 255, 255, .035);
}
.emo-bar b {
  display: block;
  height: 100%;
  background: var(--c);
  box-shadow: 0 0 8px var(--c);
  transition: width .6s cubic-bezier(.2, .8, .2, 1);
}
.emo.flash { animation: emoFlash .5s ease; }
@keyframes emoFlash {
  0% { background: rgba(255, 255, 255, .12); }
  100% { background: rgba(255, 255, 255, .025); }
}

/* ---------------- 剧情区 ---------------- */
.stage {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 26px;
}

/* ---------------- 引擎状态横幅 ---------------- */
.engine-banner {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 10px 14px 0;
  padding: 10px 12px;
  border-radius: 11px;
  font-size: 12.5px;
  line-height: 1.6;
  border: 1px solid rgba(216, 180, 120, .28);
  background: rgba(216, 180, 120, .08);
  color: #ddc79b;
}
.engine-banner.error {
  border-color: rgba(217, 115, 106, .4);
  background: rgba(217, 115, 106, .09);
  color: #e9a99f;
}
.engine-banner .banner-text { flex: 1; white-space: pre-wrap; }
.engine-banner .banner-btn {
  flex: 0 0 auto;
  padding: 5px 11px;
  border-radius: 7px;
  font-size: 12px;
  border: 1px solid currentColor;
  color: inherit;
  opacity: .9;
}
.engine-banner .banner-btn:hover { opacity: 1; background: rgba(255, 255, 255, .07); }
.engine-banner .banner-close {
  flex: 0 0 auto;
  color: inherit;
  opacity: .5;
  font-size: 12px;
  padding: 3px 5px;
}
.engine-banner .banner-close:hover { opacity: 1; }

.round-badge {
  font-size: 10px;
  letter-spacing: .08em;
  padding: 1px 6px;
  border-radius: 5px;
  border: 1px dashed rgba(216, 180, 120, .45);
  color: var(--gold);
  opacity: .8;
}

.auto-btn {
  margin-left: auto;
  padding: 6px 12px;
  border-radius: 8px;
  font-size: 12px;
  letter-spacing: 0;
  color: var(--gold);
  border: 1px solid rgba(216, 180, 120, .35);
  background: var(--gold-soft);
  transition: .16s;
}
.auto-btn:hover { background: rgba(216, 180, 120, .22); }
.auto-btn:disabled { opacity: .55; cursor: progress; }

.builder-entry {
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: 100%;
  text-align: left;
  padding: 14px 16px;
  margin-bottom: 12px;
  border-radius: 12px;
  border: 1px solid rgba(216, 180, 120, .3);
  background: linear-gradient(135deg, rgba(216, 180, 120, .1), rgba(143, 176, 201, .06));
  transition: .16s;
}
.builder-entry:hover { border-color: rgba(216, 180, 120, .55); background: rgba(216, 180, 120, .14); }
.builder-entry .be-title { font-size: 14px; color: var(--gold); letter-spacing: .06em; }
.builder-entry .be-desc { font-size: 12px; line-height: 1.7; color: var(--text-dim); }

.sheet-group { margin-bottom: 24px; }
.sheet-group-title {
  display: block;
  font-size: 13px;
  letter-spacing: .1em;
  color: var(--gold);
  padding-bottom: 8px;
  margin-bottom: 12px;
  border-bottom: 1px solid var(--line);
}
.sheet-row { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.sheet-row span { font-size: 12.5px; color: var(--text-2); letter-spacing: .03em; }
.sheet-row textarea {
  width: 100%;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, .028);
  padding: 10px 12px;
  outline: none;
  font-size: 14px;
  line-height: 1.7;
  resize: vertical;
  color: var(--text);
}
.sheet-row textarea:focus { border-color: rgba(216, 180, 120, .42); }
.rounds {
  max-width: 900px;
  margin: 0 auto;
  padding: 18px 16px 0;
}

.round { animation: fadeUp .45s ease both; }
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: none; }
}

.round-divider {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 26px 0 16px;
  color: var(--text-dim);
  font-size: 11px;
  letter-spacing: .16em;
}
.round-divider::before, .round-divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--line-strong), transparent);
}
.round.first .round-divider { display: none; }

.block { margin: 0 0 20px; }
.block.tag {
  font-family: var(--serif);
  font-style: italic;
  color: var(--tag);
  font-size: 15px;
  opacity: .85;
  letter-spacing: .02em;
  margin-bottom: 16px;
}
.block.narration {
  font-family: var(--serif);
  font-size: var(--reading);
  line-height: 1.95;
  color: #ded9d1;
  letter-spacing: .015em;
}
.block.dialogue {
  font-family: var(--serif);
  font-size: var(--reading);
  line-height: 1.95;
  color: var(--dialogue);
  font-weight: 500;
  letter-spacing: .015em;
  text-shadow: 0 0 26px rgba(228, 178, 115, .12);
}
.block.dialogue .speaker { color: var(--gold); opacity: .75; margin-right: 2px; }

.player-action {
  display: inline-flex;
  align-items: flex-start;
  gap: 8px;
  margin: 4px 0 18px;
  padding: 10px 13px;
  border-radius: 12px;
  border: 1px solid rgba(216, 180, 120, .22);
  background: rgba(216, 180, 120, .07);
  color: #dcc79d;
  font-size: 14px;
  line-height: 1.6;
}
.player-action::before {
  content: "你";
  flex: 0 0 auto;
  font-size: 11px;
  padding: 1px 6px;
  border-radius: 5px;
  background: rgba(216, 180, 120, .2);
  color: var(--gold);
  margin-top: 3px;
}

.branch-note {
  margin: 0 0 12px;
  padding: 10px 13px;
  border-radius: 11px;
  font-size: 12.5px;
  line-height: 1.7;
  color: #a9c2d6;
  border: 1px dashed rgba(143, 176, 201, .35);
  background: rgba(143, 176, 201, .06);
}

/* 正在生成 */
.typing { display: inline-flex; gap: 5px; align-items: center; padding: 6px 0; }
.typing i {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--gold);
  opacity: .35;
  animation: blink 1.25s infinite;
}
.typing i:nth-child(2) { animation-delay: .18s; }
.typing i:nth-child(3) { animation-delay: .36s; }
@keyframes blink { 0%, 60%, 100% { opacity: .25; transform: translateY(0); } 30% { opacity: 1; transform: translateY(-3px); } }

.cursor::after {
  content: "";
  display: inline-block;
  width: 7px; height: 17px;
  margin-left: 3px;
  vertical-align: -3px;
  background: var(--gold);
  animation: caret 1s steps(2) infinite;
}
@keyframes caret { 50% { opacity: 0; } }

/* ---------------- 选项 & 输入 ---------------- */
.composer { margin: 26px 0 8px; }
.composer.locked { opacity: .55; }
.options { display: flex; flex-direction: column; gap: 9px; margin-bottom: 12px; }

.option-card {
  display: flex;
  align-items: flex-start;
  gap: 11px;
  width: 100%;
  text-align: left;
  padding: 13px 14px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(255, 255, 255, .035), rgba(255, 255, 255, .012));
  color: var(--text-2);
  font-size: 14.5px;
  line-height: 1.55;
  transition: .18s;
}
.option-card:hover, .option-card:focus-visible {
  border-color: rgba(216, 180, 120, .42);
  background: var(--gold-soft);
  color: var(--text);
  transform: translateY(-1px);
  outline: none;
}
.option-card .opt-idx {
  flex: 0 0 auto;
  width: 21px; height: 21px;
  display: grid; place-items: center;
  border-radius: 6px;
  font-size: 11px;
  background: rgba(216, 180, 120, .16);
  color: var(--gold);
  margin-top: 1px;
}

.input-wrap {
  border: 1px solid var(--line);
  border-radius: 13px;
  background: rgba(255, 255, 255, .028);
  padding: 10px 10px 8px;
  transition: border-color .18s;
}
.input-wrap:focus-within { border-color: rgba(216, 180, 120, .38); }
.input-wrap textarea {
  width: 100%;
  border: none;
  outline: none;
  background: transparent;
  resize: none;
  font-size: 14.5px;
  line-height: 1.6;
  max-height: 180px;
  color: var(--text);
}
.input-wrap textarea::placeholder { color: #5f6874; }
.input-foot {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 6px;
}
.input-tip { font-size: 11px; color: var(--text-dim); flex: 1; }

.send-btn {
  padding: 8px 16px;
  border-radius: 9px;
  font-size: 13px;
  background: linear-gradient(180deg, #e0bd83, #c49d5c);
  color: #201607;
  font-weight: 600;
  transition: .16s;
}
.send-btn:hover { filter: brightness(1.08); }
.send-btn:disabled { opacity: .45; cursor: not-allowed; }

.tool-row {
  display: flex;
  gap: 7px;
  flex-wrap: wrap;
  margin-top: 12px;
}
.tool-btn {
  padding: 7px 11px;
  border-radius: 8px;
  font-size: 12px;
  color: var(--text-dim);
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, .02);
  transition: .16s;
}
.tool-btn:hover { color: var(--gold); border-color: rgba(216, 180, 120, .3); background: var(--gold-soft); }

/* ---------------- 回合导航 ---------------- */
.round-nav {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(62px + var(--safe-b));
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 4px;
  border-radius: 999px;
  background: #171e2a;
  border: 1px solid var(--line-strong);
  backdrop-filter: blur(12px);
  box-shadow: 0 14px 34px rgba(0, 0, 0, .72), 0 0 0 6px rgba(8, 11, 16, .45);
  z-index: 25;
}

.jump-bottom {
  position: absolute;
  right: 18px;
  bottom: calc(118px + var(--safe-b));
  z-index: 26;
  padding: 8px 14px;
  border-radius: 999px;
  font-size: 12.5px;
  color: #201607;
  font-weight: 600;
  background: linear-gradient(180deg, #e0bd83, #c49d5c);
  box-shadow: 0 10px 26px rgba(0, 0, 0, .5);
  animation: fadeUp .22s ease both;
}
.jump-bottom:hover { filter: brightness(1.08); }
.nav-btn {
  width: 34px; height: 34px;
  border-radius: 50%;
  color: var(--text-2);
  font-size: 17px;
  display: grid; place-items: center;
  transition: .16s;
}
.nav-btn:hover:not(:disabled) { background: rgba(255, 255, 255, .08); color: var(--gold); }
.nav-btn:disabled { opacity: .28; cursor: default; }
.nav-count {
  min-width: 76px;
  padding: 0 8px;
  font-size: 12.5px;
  color: var(--text);
  letter-spacing: .06em;
  font-variant-numeric: tabular-nums;
}

/* ---------------- 底部按钮 ---------------- */
.bottombar {
  display: flex;
  align-items: stretch;
  gap: 0;
  border-top: 1px solid var(--line);
  background: rgba(10, 13, 19, .96);
  backdrop-filter: blur(14px);
  overflow-x: auto;
  scrollbar-width: none;
  padding-bottom: var(--safe-b);
  z-index: 22;
}
.bottombar::-webkit-scrollbar { display: none; }
.bottom-btn {
  flex: 1 0 auto;
  min-width: 84px;
  padding: 13px 12px 12px;
  font-size: 12.5px;
  color: var(--text-dim);
  border-right: 1px solid var(--line);
  white-space: nowrap;
  transition: .16s;
  position: relative;
}
.bottom-btn:last-child { border-right: none; }
.bottom-btn:hover { color: var(--text); background: rgba(255, 255, 255, .03); }
.bottom-btn.active { color: var(--gold); background: var(--gold-soft); }
.bottom-btn.active::after {
  content: "";
  position: absolute;
  left: 14%; right: 14%; bottom: 0;
  height: 2px;
  background: var(--gold);
  border-radius: 2px;
}
.bottombar.empty { display: none; }

/* ---------------- 抽屉面板 ---------------- */
.drawer {
  position: absolute;
  left: 0; right: 0;
  bottom: calc(52px + var(--safe-b));
  max-height: 62%;
  display: flex;
  flex-direction: column;
  background: linear-gradient(180deg, rgba(22, 29, 42, .98), rgba(13, 17, 24, .99));
  border-top: 1px solid var(--line-strong);
  box-shadow: 0 -20px 50px rgba(0, 0, 0, .55);
  z-index: 30;
  animation: drawerUp .26s cubic-bezier(.2, .8, .2, 1);
}
@keyframes drawerUp { from { transform: translateY(24px); opacity: 0; } to { transform: none; opacity: 1; } }
.drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px 10px;
}
.drawer-title {
  font-family: var(--serif);
  font-size: 16px;
  color: var(--gold);
  letter-spacing: .08em;
}
.drawer-body {
  overflow-y: auto;
  padding: 4px 18px 22px;
  font-size: 15px;
  line-height: 1.85;
  color: #d6d2cb;
  font-family: var(--serif);
}
.drawer-body ul { margin: 0; padding-left: 2px; list-style: none; }
.drawer-body li {
  position: relative;
  padding-left: 15px;
  margin-bottom: 9px;
}
.drawer-body li::before {
  content: "";
  position: absolute;
  left: 0; top: .72em;
  width: 4px; height: 4px;
  border-radius: 50%;
  background: var(--gold);
  opacity: .6;
}
.drawer-body .kv-grid { display: flex; flex-direction: column; gap: 10px; }
.drawer-body .kv {
  display: flex;
  gap: 12px;
  padding: 11px 13px;
  border-radius: 10px;
  background: rgba(255, 255, 255, .03);
  border: 1px solid var(--line);
}
.drawer-body .kv .k {
  flex: 0 0 84px;
  font-size: 12.5px;
  color: var(--gold);
  opacity: .85;
  letter-spacing: .04em;
  padding-top: 2px;
}
.drawer-body .kv .v { flex: 1; font-size: 14.5px; color: #d6d2cb; }
.drawer-body p { margin: 0 0 12px; }
.drawer-body .hl { color: var(--dialogue); }
.drawer-foot {
  display: flex;
  gap: 8px;
  padding: 10px 16px calc(14px + var(--safe-b));
  border-top: 1px solid var(--line);
}
.drawer-foot input {
  flex: 1;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, .03);
  padding: 10px 12px;
  outline: none;
  font-size: 14px;
}
.drawer-foot input:focus { border-color: rgba(216, 180, 120, .38); }
.drawer-foot button {
  padding: 10px 14px;
  border-radius: 10px;
  font-size: 13px;
  background: var(--gold-soft);
  color: var(--gold);
  border: 1px solid rgba(216, 180, 120, .3);
}

.drawer-empty { color: var(--text-dim); font-size: 14px; }

/* ---------------- 空状态 ---------------- */
.empty-state {
  max-width: 460px;
  margin: 12vh auto 0;
  text-align: center;
  padding: 0 24px;
}
.empty-state h2 {
  font-family: var(--serif);
  font-size: 22px;
  letter-spacing: .1em;
  color: var(--gold);
  font-weight: 500;
  margin: 0 0 14px;
}
.empty-state p { color: var(--text-dim); line-height: 1.9; font-size: 14px; margin: 0 0 24px; }

/* ---------------- 开场设定页 ---------------- */
.screen {
  position: fixed;
  inset: 0;
  z-index: 60;
  background:
    radial-gradient(900px 500px at 20% -10%, rgba(216, 180, 120, .07), transparent 60%),
    var(--bg);
  display: none;
  flex-direction: column;
}
.screen.open { display: flex; }

.setup-wrap {
  width: min(940px, 100%);
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  height: 100dvh;
  padding-top: var(--safe-t);
}
.setup-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px 12px;
}
.setup-brand {
  font-family: var(--serif);
  font-size: 20px;
  letter-spacing: .14em;
  color: var(--gold);
  display: flex;
  align-items: baseline;
  gap: 7px;
}
.setup-brand span { opacity: .4; }
.setup-brand em {
  font-style: normal;
  font-size: 12px;
  letter-spacing: .18em;
  color: var(--text-dim);
}
.setup-scroll { flex: 1; overflow-y: auto; padding: 8px 20px 20px; }
.setup-foot {
  padding: 12px 20px calc(16px + var(--safe-b));
  border-top: 1px solid var(--line);
  background: rgba(8, 11, 16, .9);
  backdrop-filter: blur(12px);
}
.primary-btn {
  width: 100%;
  padding: 15px;
  border-radius: 12px;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: .1em;
  background: linear-gradient(180deg, #e0bd83, #c49d5c);
  color: #201607;
  transition: .16s;
}
.primary-btn:hover { filter: brightness(1.08); }
.primary-btn:disabled { opacity: .5; cursor: progress; }

.field { margin-bottom: 20px; }
.field-label {
  display: flex;
  align-items: baseline;
  gap: 9px;
  font-size: 12.5px;
  letter-spacing: .1em;
  color: var(--gold);
  margin-bottom: 9px;
  opacity: .92;
}
.field-hint { font-size: 11px; color: var(--text-dim); letter-spacing: 0; }
.field-tip {
  margin-top: 8px;
  font-size: 11.5px;
  line-height: 1.75;
  color: var(--text-dim);
}
.field-tip b { color: #ddc79b; font-weight: 500; }

.field textarea, .field input[type="text"], .field select {
  width: 100%;
  border-radius: 11px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, .028);
  padding: 12px 13px;
  outline: none;
  font-size: 14.5px;
  line-height: 1.7;
  resize: vertical;
  transition: border-color .16s;
}
.field textarea:focus, .field input[type="text"]:focus, .field select:focus {
  border-color: rgba(216, 180, 120, .42);
}
.field select { appearance: none; background-image: linear-gradient(45deg, transparent 50%, #7d8794 50%), linear-gradient(135deg, #7d8794 50%, transparent 50%); background-position: calc(100% - 18px) 20px, calc(100% - 13px) 20px; background-size: 5px 5px; background-repeat: no-repeat; }
.field-2col, .field-3col { display: grid; gap: 14px; }
.field-2col { grid-template-columns: 1fr; }
.field-3col { grid-template-columns: 1fr; }

.template-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 9px;
}
.template-card {
  text-align: left;
  padding: 12px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, .025);
  transition: .18s;
}
.template-card:hover { border-color: rgba(216, 180, 120, .3); background: rgba(216, 180, 120, .06); }
.template-card.active { border-color: rgba(216, 180, 120, .5); background: var(--gold-soft); }
.template-card .t-emoji { font-size: 18px; }
.template-card .t-name { font-size: 13.5px; margin: 7px 0 5px; color: var(--text); }
.template-card .t-desc { font-size: 11.5px; line-height: 1.6; color: var(--text-dim); }

.chip-row { display: flex; flex-wrap: wrap; gap: 7px; margin: 9px 0; }
.chip {
  padding: 6px 11px;
  border-radius: 999px;
  font-size: 12px;
  border: 1px solid var(--line);
  color: var(--text-dim);
  background: rgba(255, 255, 255, .025);
  transition: .16s;
}
.chip:hover { color: var(--text); border-color: var(--line-strong); }
.chip.active { color: var(--gold); border-color: rgba(216, 180, 120, .4); background: var(--gold-soft); }

.panel-editor { display: flex; flex-direction: column; gap: 8px; }
.panel-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, .022);
}
.field .panel-row input,
.field .panel-row input[type="text"] {
  flex: 1 1 110px;
  min-width: 0;
  width: auto;
  background: transparent;
  border: none;
  border-bottom: 1px dashed transparent;
  border-radius: 0;
  outline: none;
  font-size: 13.5px;
  line-height: 1.5;
  padding: 5px 4px;
  resize: none;
}
.field .panel-row input:focus { border-bottom-color: rgba(216, 180, 120, .45); }
.field .panel-row input.hint {
  flex: 1 1 100%;
  order: 3;
  color: var(--text-dim);
  font-size: 12.5px;
}
.field .panel-row select {
  flex: 0 0 auto;
  width: auto;
  background: rgba(255, 255, 255, .04);
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 5px 6px;
  font-size: 12px;
  color: var(--text-2);
}
.panel-row .del { color: var(--text-dim); font-size: 14px; padding: 4px 6px; border-radius: 6px; }
.panel-row .del:hover { color: var(--danger); background: rgba(217, 115, 106, .12); }
.add-btn {
  align-self: flex-start;
  margin-top: 8px;
  padding: 8px 13px;
  border-radius: 9px;
  font-size: 12.5px;
  color: var(--text-dim);
  border: 1px dashed var(--line-strong);
}
.add-btn:hover { color: var(--gold); border-color: rgba(216, 180, 120, .4); }

.setup-note {
  margin: 4px 0 12px;
  padding: 12px 14px;
  border-radius: 11px;
  font-size: 12.5px;
  line-height: 1.8;
  color: var(--text-dim);
  background: rgba(255, 255, 255, .022);
  border: 1px solid var(--line);
}
.setup-note b { color: var(--gold); font-weight: 500; }

/* ---------------- 弹层 ---------------- */
.modal-root {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.modal-root[hidden] { display: none; }
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, .62);
  backdrop-filter: blur(4px);
}
.modal {
  position: relative;
  width: min(520px, 100%);
  max-height: 84dvh;
  overflow-y: auto;
  border-radius: 16px;
  border: 1px solid var(--line-strong);
  background: var(--panel);
  padding: 20px;
  box-shadow: 0 30px 70px rgba(0, 0, 0, .6);
  animation: fadeUp .22s ease both;
}
.modal h3 {
  margin: 0 0 16px;
  font-family: var(--serif);
  font-size: 17px;
  letter-spacing: .08em;
  color: var(--gold);
  font-weight: 500;
}
.modal .field { margin-bottom: 14px; }
.modal .row { display: flex; gap: 9px; margin-top: 16px; }
.modal .row button { flex: 1; padding: 12px; border-radius: 10px; font-size: 13.5px; }
.modal .row .ok { background: linear-gradient(180deg, #e0bd83, #c49d5c); color: #201607; font-weight: 600; }
.modal .row .cancel { background: rgba(255, 255, 255, .05); color: var(--text-2); border: 1px solid var(--line); }
.modal .row .danger { background: rgba(217, 115, 106, .14); color: var(--danger); border: 1px solid rgba(217, 115, 106, .3); }
.modal .kvline { display: flex; justify-content: space-between; gap: 12px; padding: 9px 0; border-bottom: 1px solid var(--line); font-size: 13.5px; }
.modal .kvline span:first-child { color: var(--text-dim); }
.modal .tip { font-size: 12px; color: var(--text-dim); line-height: 1.8; margin-top: 10px; }

.diag {
  margin-top: 12px;
  padding: 11px 13px;
  border-radius: 10px;
  font-size: 12.5px;
  line-height: 1.75;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, .03);
  color: var(--text-2);
  word-break: break-word;
}
.diag.ok { border-color: rgba(95, 181, 154, .4); background: rgba(95, 181, 154, .08); color: #9ed6c5; }
.diag.bad { border-color: rgba(217, 115, 106, .4); background: rgba(217, 115, 106, .08); color: #e9a99f; }
.diag b { display: block; margin-bottom: 4px; }
.diag .raw { margin-top: 6px; font-size: 11.5px; opacity: .7; max-height: 90px; overflow: auto; white-space: pre-wrap; }

.timeline-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  text-align: left;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, .02);
  margin-bottom: 7px;
  color: var(--text-2);
  font-size: 13px;
}
.timeline-item:hover { border-color: rgba(216, 180, 120, .35); background: var(--gold-soft); color: var(--text); }
.timeline-item.current { border-color: rgba(216, 180, 120, .5); background: var(--gold-soft); color: var(--text); }
.timeline-item .idx { color: var(--gold); font-variant-numeric: tabular-nums; }
.timeline-item .txt { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(148px + var(--safe-b));
  transform: translateX(-50%);
  z-index: 90;
  max-width: min(420px, 88vw);
  padding: 11px 16px;
  border-radius: 11px;
  font-size: 13px;
  line-height: 1.6;
  color: var(--text);
  background: rgba(26, 33, 46, .97);
  border: 1px solid var(--line-strong);
  box-shadow: 0 14px 40px rgba(0, 0, 0, .5);
  animation: fadeUp .2s ease both;
}
.toast[hidden] { display: none; }
.toast.warn { border-color: rgba(217, 115, 106, .45); }

.scrim {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .55);
  z-index: 44;
  backdrop-filter: blur(2px);
}
.scrim[hidden] { display: none; }

/* ---------------- 响应式 ---------------- */
@media (max-width: 1023px) {
  .sidebar {
    position: fixed;
    top: 0; bottom: 0; left: 0;
    z-index: 46;
    transform: translateX(-100%);
    transition: transform .26s cubic-bezier(.2, .8, .2, 1);
    box-shadow: 20px 0 60px rgba(0, 0, 0, .5);
  }
  .sidebar.open { transform: none; }
  .drawer { max-height: 68%; }
}

@media (max-width: 639px) {
  .topbar { flex-wrap: wrap; row-gap: 8px; }
  .title-wrap { flex: 1 1 auto; min-width: 0; }
  .topbar-actions {
    order: 3;
    flex: 1 0 100%;
    overflow-x: auto;
    scrollbar-width: none;
    padding-bottom: 1px;
  }
  .topbar-actions::-webkit-scrollbar { display: none; }
  .mini-btn { padding: 6px 10px; font-size: 12px; }
  .emo { min-width: 68px; padding: 4px 7px 5px; }
  .emo-label { font-size: 10.5px; }
  .emo-val { font-size: 13px; }
  .bottom-btn { min-width: 72px; padding: 12px 6px 11px; font-size: 12px; }
  .rounds { padding-bottom: 92px; }
  .round-nav { bottom: calc(58px + var(--safe-b)); }
  .drawer { bottom: calc(48px + var(--safe-b)); }
}

@media (min-width: 640px) {
  :root { --reading: 19px; }
  .field-2col { grid-template-columns: 1fr 1fr; }
  .field-3col { grid-template-columns: 1fr 1fr 1fr; }
  .rounds { padding: 24px 28px 92px; }
  .hud { padding: 11px 28px 12px; }
  .emo { min-width: 96px; }
}

@media (min-width: 1024px) {
  :root { --reading: 19.5px; }
  #btn-sidebar { display: none; }
  .rounds { padding: 30px 40px 92px; }
  .hud { padding: 12px 40px 13px; }
  .topbar { padding: 12px 20px; padding-top: 12px; }
  .drawer { left: 0; right: 0; bottom: calc(52px + var(--safe-b)); max-height: 56%; }
  .drawer-body { padding: 4px 40px 24px; }
  .drawer-head { padding: 16px 40px 10px; }
  .drawer-foot { padding: 12px 40px 16px; }
  .bottom-btn { min-width: 110px; }
  .round-nav { bottom: calc(66px + var(--safe-b)); }
}

@media (min-width: 1440px) {
  .rounds { max-width: 860px; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
