/* ============================================================
 * 七日轮回 · 设计系统
 * 暗色末世科幻风 · 后台仪表盘 + 沉浸式播放器
 * ============================================================ */
:root {
  --bg-0: #0a0e17;
  --bg-1: #0f1522;
  --bg-2: #151d2e;
  --bg-3: #1c2740;
  --panel: rgba(21, 29, 46, 0.82);
  --panel-solid: #131b2b;
  --line: rgba(140, 170, 220, 0.14);
  --line-strong: rgba(140, 170, 220, 0.28);
  --fg: #e8eef7;
  --fg-dim: #9fb0c8;
  --fg-mute: #6b7c96;
  --accent: #5fd0ff;
  --accent-2: #ffcf87;
  --good: #7ee2a8;
  --warn: #ffcf87;
  --bad: #ff8a8a;
  --purple: #c9a3ff;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.45);
  --glow: 0 0 0 1px rgba(95, 208, 255, 0.25), 0 8px 30px rgba(95, 208, 255, 0.12);
  --font: "Segoe UI", "PingFang SC", "Microsoft YaHei", system-ui, -apple-system, sans-serif;
  --mono: "Cascadia Code", "Consolas", monospace;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--font); color: var(--fg); background: var(--bg-0);
  font-size: 14px; line-height: 1.6; -webkit-font-smoothing: antialiased;
  background-image:
    radial-gradient(1200px 600px at 80% -10%, rgba(95, 208, 255, 0.08), transparent 60%),
    radial-gradient(900px 500px at -10% 110%, rgba(201, 163, 255, 0.07), transparent 60%);
  background-attachment: fixed;
}
button { font-family: inherit; }
::selection { background: rgba(95, 208, 255, 0.3); }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--bg-3); border-radius: 8px; border: 2px solid var(--bg-0); }
::-webkit-scrollbar-track { background: transparent; }

/* ---- 顶栏 ---- */
.topbar {
  position: sticky; top: 0; z-index: 50; display: flex; align-items: center; gap: 16px;
  padding: 12px 22px; background: rgba(10, 14, 23, 0.85); backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 11px; font-weight: 600; letter-spacing: 0.5px; }
.brand .logo {
  width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center;
  background: linear-gradient(135deg, var(--accent), var(--purple)); color: #06121f;
  font-size: 18px; font-weight: 700; box-shadow: var(--glow);
}
.brand .t { font-size: 15px; }
.brand .s { font-size: 11px; color: var(--fg-mute); font-weight: 400; }
.mode-switch { margin-left: auto; display: flex; gap: 6px; background: var(--bg-2); padding: 4px; border-radius: 11px; border: 1px solid var(--line); }
.mode-switch button {
  border: 0; background: transparent; color: var(--fg-dim); padding: 7px 18px; border-radius: 8px;
  cursor: pointer; font-size: 13px; font-weight: 500; transition: all 0.18s;
}
.mode-switch button.active { background: linear-gradient(135deg, var(--accent), #3aa0d8); color: #06121f; box-shadow: 0 4px 14px rgba(95, 208, 255, 0.3); }
.mode-switch button:not(.active):hover { color: var(--fg); background: var(--bg-3); }

/* ---- 通用组件 ---- */
.btn {
  border: 1px solid var(--line-strong); background: var(--bg-2); color: var(--fg);
  padding: 9px 16px; border-radius: var(--radius-sm); cursor: pointer; font-size: 13px; font-weight: 500;
  transition: all 0.16s; display: inline-flex; align-items: center; gap: 7px;
}
.btn:hover { border-color: var(--accent); background: var(--bg-3); transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn.primary { background: linear-gradient(135deg, var(--accent), #3aa0d8); color: #06121f; border-color: transparent; }
.btn.primary:hover { box-shadow: 0 6px 20px rgba(95, 208, 255, 0.35); }
.btn.ghost { background: transparent; }
.btn.danger { border-color: rgba(255, 138, 138, 0.4); color: var(--bad); }
.btn.danger:hover { background: rgba(255, 138, 138, 0.1); border-color: var(--bad); }
.btn.sm { padding: 6px 11px; font-size: 12px; }
.btn:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }
.badge { display: inline-flex; align-items: center; gap: 5px; font-size: 11px; padding: 2px 9px; border-radius: 999px; border: 1px solid var(--line-strong); color: var(--fg-dim); background: var(--bg-2); }
.badge.good { color: var(--good); border-color: rgba(126, 226, 168, 0.4); }
.badge.warn { color: var(--warn); border-color: rgba(255, 207, 135, 0.4); }
.badge.bad { color: var(--bad); border-color: rgba(255, 138, 138, 0.4); }
.badge.accent { color: var(--accent); border-color: rgba(95, 208, 255, 0.4); }
.badge.lock { color: var(--purple); border-color: rgba(201, 163, 255, 0.4); }
input, textarea, select {
  width: 100%; background: var(--bg-1); border: 1px solid var(--line-strong); color: var(--fg);
  border-radius: var(--radius-sm); padding: 9px 12px; font-size: 13px; font-family: inherit; transition: border 0.16s, box-shadow 0.16s;
}
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(95, 208, 255, 0.12); }
textarea { resize: vertical; min-height: 70px; line-height: 1.55; }
label.field { display: block; margin-bottom: 13px; }
label.field > span { display: block; font-size: 12px; color: var(--fg-dim); margin-bottom: 5px; font-weight: 500; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }

/* ---- 后台布局 ---- */
.admin { display: grid; grid-template-columns: 210px 1fr; min-height: calc(100vh - 60px); }
.side { border-right: 1px solid var(--line); padding: 18px 12px; background: rgba(15, 21, 34, 0.5); }
.side .nav { display: flex; flex-direction: column; gap: 4px; position: sticky; top: 78px; }
.side .nav button {
  text-align: left; border: 0; background: transparent; color: var(--fg-dim); padding: 11px 14px;
  border-radius: var(--radius-sm); cursor: pointer; font-size: 13.5px; font-weight: 500; transition: all 0.15s;
  display: flex; align-items: center; gap: 10px;
}
.side .nav button:hover { background: var(--bg-2); color: var(--fg); }
.side .nav button.active { background: linear-gradient(90deg, rgba(95, 208, 255, 0.16), transparent); color: var(--accent); box-shadow: inset 2px 0 0 var(--accent); }
.side .nav .ico { width: 18px; text-align: center; }
.side .side-note { margin-top: 20px; font-size: 11px; color: var(--fg-mute); padding: 12px; border-top: 1px solid var(--line); line-height: 1.6; }
.main { padding: 26px 30px; max-width: 1180px; }
.page-head { display: flex; align-items: center; gap: 14px; margin-bottom: 22px; flex-wrap: wrap; }
.page-head h1 { font-size: 21px; margin: 0; font-weight: 600; }
.page-head .desc { color: var(--fg-mute); font-size: 12.5px; width: 100%; }
.page-head .spacer { margin-left: auto; display: flex; gap: 8px; }
.section-title { font-size: 13px; color: var(--fg-dim); font-weight: 600; margin: 24px 0 12px; letter-spacing: 0.5px; text-transform: uppercase; }

/* 角色卡片 */
.char-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 16px; }
.char-card { padding: 0; overflow: hidden; transition: transform 0.18s, box-shadow 0.18s; }
.char-card:hover { transform: translateY(-3px); box-shadow: var(--glow); }
.char-top { display: flex; gap: 14px; padding: 16px; align-items: center; }
.char-avatar { width: 74px; height: 74px; border-radius: 12px; object-fit: cover; background: var(--bg-3); border: 1px solid var(--line-strong); flex: none; }
.char-avatar.placeholder { display: grid; place-items: center; font-size: 26px; font-weight: 700; color: #06121f; }
.char-id { min-width: 0; }
.char-slot { font-size: 11px; font-weight: 700; letter-spacing: 1px; padding: 2px 8px; border-radius: 6px; display: inline-block; margin-bottom: 5px; }
.char-name { font-size: 17px; font-weight: 600; }
.char-role { font-size: 12px; color: var(--fg-dim); margin-top: 2px; }
.char-body { padding: 0 16px 16px; }
.char-meta { font-size: 12px; color: var(--fg-mute); display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; }
.char-meta b { color: var(--fg-dim); font-weight: 500; }
.char-actions { display: flex; gap: 8px; }

/* 故事编辑器 */
.story-layout { display: grid; grid-template-columns: 290px 1fr; gap: 18px; align-items: start; }
.node-list { padding: 10px; max-height: 70vh; overflow: auto; position: sticky; top: 78px; }
.node-list .filter { margin-bottom: 8px; }
.node-item { padding: 9px 11px; border-radius: var(--radius-sm); cursor: pointer; border: 1px solid transparent; transition: all 0.14s; margin-bottom: 3px; }
.node-item:hover { background: var(--bg-2); }
.node-item.active { background: var(--bg-3); border-color: var(--line-strong); box-shadow: inset 2px 0 0 var(--accent); }
.node-item .nt { font-size: 13px; font-weight: 500; display: flex; align-items: center; gap: 7px; }
.node-item .ns { font-size: 11px; color: var(--fg-mute); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.node-item .day-tag { font-size: 10px; color: var(--fg-mute); font-family: var(--mono); }
.editor { padding: 22px; }
.editor .empty { color: var(--fg-mute); text-align: center; padding: 60px 20px; }
.choice-row { display: grid; grid-template-columns: 1fr 150px auto; gap: 8px; align-items: center; margin-bottom: 8px; }
.choice-row input { font-size: 12.5px; }
.type-pill { font-size: 10.5px; padding: 1px 7px; border-radius: 5px; font-weight: 600; }
.t-story { background: rgba(95, 208, 255, 0.16); color: var(--accent); }
.t-choice { background: rgba(255, 207, 135, 0.16); color: var(--warn); }
.t-video { background: rgba(201, 163, 255, 0.16); color: var(--purple); }
.t-gate { background: rgba(126, 226, 168, 0.16); color: var(--good); }
.t-ending { background: rgba(255, 138, 138, 0.16); color: var(--bad); }

/* 表格 */
.table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.table th, .table td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--line); }
.table th { color: var(--fg-mute); font-weight: 500; font-size: 11.5px; }
.table tr:hover td { background: rgba(95, 208, 255, 0.03); }

/* ---- 播放器 ---- */
.player-wrap { display: grid; place-items: center; padding: 24px; min-height: calc(100vh - 60px); }
.stage {
  position: relative; width: min(440px, 94vw); aspect-ratio: 9 / 16; max-height: calc(100vh - 110px);
  border-radius: 22px; overflow: hidden; background: #060a12; border: 1px solid var(--line-strong);
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.6), 0 0 0 1px rgba(95, 208, 255, 0.08);
  display: flex; flex-direction: column;
}
.stage-bg { position: absolute; inset: 0; background-size: cover; background-position: center; transition: opacity 0.6s; }
.stage-bg::after { content: ""; position: absolute; inset: 0; background: linear-gradient(180deg, rgba(6, 10, 18, 0.3) 0%, rgba(6, 10, 18, 0.1) 40%, rgba(6, 10, 18, 0.92) 100%); }
.stage-video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.stage-hud { position: relative; z-index: 3; display: flex; align-items: center; gap: 8px; padding: 14px 16px; }
.hud-chip { font-size: 11px; padding: 4px 10px; border-radius: 999px; background: rgba(6, 10, 18, 0.6); border: 1px solid var(--line); color: var(--fg-dim); backdrop-filter: blur(6px); }
.hud-chip b { color: var(--accent); font-weight: 600; }
.hud-factors { margin-left: auto; display: flex; gap: 5px; }
.factor-dot { width: 22px; height: 22px; border-radius: 7px; display: grid; place-items: center; font-size: 11px; background: rgba(6, 10, 18, 0.6); border: 1px solid var(--line); color: var(--fg-mute); }
.factor-dot.on { color: #06121f; border-color: transparent; }
.factor-dot.miracle.on { background: var(--accent-2); }
.factor-dot.ai.on { background: var(--good); }
.stage-portrait { position: absolute; right: -6%; bottom: 26%; width: 62%; z-index: 2; filter: drop-shadow(0 20px 40px rgba(0, 0, 0, 0.6)); opacity: 0.96; transition: opacity 0.4s; pointer-events: none; }
.stage-portrait img { width: 100%; display: block; }
.stage-bottom { position: relative; z-index: 4; margin-top: auto; padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.dialogue { background: rgba(10, 15, 26, 0.82); backdrop-filter: blur(12px); border: 1px solid var(--line-strong); border-radius: 16px; padding: 15px 17px; box-shadow: 0 12px 40px rgba(0, 0, 0, 0.4); }
.dialogue .speaker { font-size: 12.5px; font-weight: 700; margin-bottom: 6px; display: inline-flex; align-items: center; gap: 7px; }
.dialogue .speaker .dot { width: 8px; height: 8px; border-radius: 3px; }
.dialogue .title { font-size: 11px; color: var(--fg-mute); margin-bottom: 7px; letter-spacing: 0.5px; }
.dialogue .text { font-size: 14px; line-height: 1.7; color: var(--fg); }
.choices { display: flex; flex-direction: column; gap: 8px; }
.choice-btn {
  text-align: left; border: 1px solid var(--line-strong); background: rgba(21, 29, 46, 0.85); backdrop-filter: blur(8px);
  color: var(--fg); padding: 12px 15px; border-radius: 12px; cursor: pointer; font-size: 13.5px; font-weight: 500;
  transition: all 0.16s; display: flex; flex-direction: column; gap: 3px;
}
.choice-btn:hover:not(:disabled) { border-color: var(--accent); background: rgba(95, 208, 255, 0.12); transform: translateX(4px); box-shadow: 0 6px 20px rgba(95, 208, 255, 0.15); }
.choice-btn .hint { font-size: 11px; color: var(--fg-mute); font-weight: 400; }
.choice-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.choice-btn:disabled .hint { color: var(--bad); }
.choice-btn .lock-ico { font-size: 11px; color: var(--bad); }

/* 结局屏 */
.ending-screen { position: absolute; inset: 0; z-index: 6; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: 34px; background: radial-gradient(circle at 50% 30%, rgba(15, 21, 34, 0.86), rgba(6, 10, 18, 0.97)); backdrop-filter: blur(4px); }
.ending-screen .e-kind { font-size: 12px; letter-spacing: 3px; color: var(--fg-mute); margin-bottom: 10px; }
.ending-screen h2 { font-size: 27px; margin: 0 0 16px; font-weight: 700; line-height: 1.3; }
.ending-screen.tone-ok h2 { color: var(--good); }
.ending-screen.tone-warn h2 { color: var(--warn); }
.ending-screen.tone-no h2 { color: var(--bad); }
.ending-screen .e-text { font-size: 13.5px; color: var(--fg-dim); line-height: 1.8; max-width: 340px; margin-bottom: 22px; }
.ending-screen .e-loop { font-size: 12px; color: var(--purple); margin-bottom: 20px; display: flex; align-items: center; gap: 7px; }
.ending-screen .e-actions { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }
.ending-video { width: 100%; max-width: 300px; border-radius: 14px; margin-bottom: 20px; border: 1px solid var(--line-strong); }

/* 状态抽屉 */
.state-toggle { position: absolute; z-index: 5; top: 14px; right: 14px; }
.state-panel { position: absolute; z-index: 7; top: 52px; right: 14px; width: 230px; padding: 14px; font-size: 12px; background: rgba(10, 15, 26, 0.95); border: 1px solid var(--line-strong); border-radius: 12px; box-shadow: var(--shadow); }
.state-panel h4 { margin: 0 0 8px; font-size: 12px; color: var(--accent); }
.state-panel .row { display: flex; justify-content: space-between; padding: 3px 0; color: var(--fg-dim); }
.state-panel .row b { color: var(--fg); font-weight: 500; }
.state-panel .tags { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }

/* toast */
.toast-wrap { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); z-index: 200; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.toast { background: var(--panel-solid); border: 1px solid var(--line-strong); color: var(--fg); padding: 11px 20px; border-radius: 11px; font-size: 13px; box-shadow: var(--shadow); animation: toast-in 0.25s ease; }
.toast.good { border-color: rgba(126, 226, 168, 0.5); }
.toast.bad { border-color: rgba(255, 138, 138, 0.5); }
@keyframes toast-in { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: translateY(0); } }

/* modal */
.modal-mask { position: fixed; inset: 0; z-index: 150; background: rgba(6, 10, 18, 0.7); backdrop-filter: blur(4px); display: grid; place-items: center; padding: 20px; }
.modal { width: min(560px, 94vw); max-height: 86vh; overflow: auto; padding: 24px; }
.modal h3 { margin: 0 0 16px; font-size: 17px; }
.modal .modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 20px; }
.three-view { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 8px; }
.three-view img { width: 100%; border-radius: 8px; border: 1px solid var(--line); background: var(--bg-3); aspect-ratio: 3/4; object-fit: cover; }

.hidden { display: none !important; }
.text-mute { color: var(--fg-mute); }
.mt { margin-top: 14px; }
.row-flex { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

@media (max-width: 860px) {
  .admin { grid-template-columns: 1fr; }
  .side { border-right: 0; border-bottom: 1px solid var(--line); }
  .side .nav { flex-direction: row; flex-wrap: wrap; position: static; }
  .side .side-note { display: none; }
  .story-layout { grid-template-columns: 1fr; }
  .node-list { position: static; max-height: 260px; }
  .main { padding: 18px; }
  .choice-row { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}