:root {
  --bg: #0f1420; --panel: #171e2e; --panel2: #1e2740; --line: #2b3757;
  --text: #e8ecf5; --dim: #8a94ad; --accent: #d4a853; --accent2: #8b6fd8;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body { background: var(--bg); color: var(--text); font-family: "PingFang SC", "Microsoft YaHei", sans-serif; min-height: 100vh; }

/* ---------- 布局与侧栏 ---------- */
#layout { min-height: 100vh; }
.content { transition: margin-left .25s; min-width: 0; }
#layout.sidebar-open .content { margin-left: 270px; }

#sidebar { position: fixed; left: 0; top: 0; bottom: 0; width: 270px; z-index: 40;
           background: var(--panel); border-right: 1px solid var(--line);
           transform: translateX(-100%); transition: transform .25s;
           display: flex; flex-direction: column; }
#layout.sidebar-open #sidebar { transform: none; }
#sidebar .side-head { padding: 18px 16px 12px; border-bottom: 1px solid var(--line); }
#sidebar .side-head h2 { font-size: 15px; color: var(--accent); letter-spacing: 2px; }
#btnNewBook { width: 100%; margin-top: 12px; background: var(--accent); color: #1a1408; border: none;
              padding: 9px 0; border-radius: 8px; cursor: pointer; font-weight: 700; font-size: 13px; letter-spacing: 1px; }
#sessList { flex: 1; overflow-y: auto; padding: 10px; }
.sess { padding: 11px 12px; border-radius: 8px; cursor: pointer; border: 1px solid transparent; margin-bottom: 6px; position: relative; }
.sess:hover { background: var(--panel2); }
.sess.active { background: var(--panel2); border-color: var(--accent); }
.sess .del { position: absolute; top: 8px; right: 8px; width: 20px; height: 20px; line-height: 18px;
             text-align: center; border-radius: 5px; color: var(--dim); font-size: 13px; opacity: 0; }
.sess:hover .del { opacity: 1; }
.sess .del:hover { color: #f08080; background: #3a2222; }
.sess .t { font-size: 14px; color: var(--text); margin-bottom: 5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sess .m { display: flex; gap: 6px; align-items: center; font-size: 12px; color: var(--dim); }
.sess .time { font-size: 11px; color: var(--dim); margin-top: 4px; opacity: .7; }
.stage-badge { padding: 1px 7px; border-radius: 6px; font-size: 11px; white-space: nowrap; }
.st-synopses { background: #3a3a22; color: #e0cf8a; }
.st-chapters { background: #22303f; color: #8ab8e0; }
.st-arc      { background: #2a223a; color: #c8b0f0; }
.st-done     { background: #233a2a; color: #8fd8a0; }
.sess-empty { color: var(--dim); font-size: 13px; text-align: center; padding: 30px 10px; line-height: 1.8; }

#sideToggle { position: fixed; top: 14px; left: 14px; z-index: 50; width: 34px; height: 34px;
              background: var(--panel2); color: var(--text); border: 1px solid var(--line);
              border-radius: 8px; cursor: pointer; font-size: 16px; transition: left .25s; }
#sideToggle:hover { border-color: var(--accent); color: var(--accent); }
#layout.sidebar-open #sideToggle { left: 284px; }

header { padding: 28px 5vw 12px; border-bottom: 1px solid var(--line); }
header h1 { font-size: 26px; letter-spacing: 4px; color: var(--accent); }
header p { color: var(--dim); margin-top: 6px; font-size: 13px; }
.badge { display:inline-block; padding:2px 10px; border-radius:10px; font-size:12px; margin-left:10px; vertical-align: middle;}
.badge.mock { background:#4a2c2c; color:#f0a0a0; }
.badge.live { background:#233a2a; color:#8fd8a0; }
main { max-width: 1100px; margin: 0 auto; padding: 24px 20px 80px; }

/* 步骤条 */
.steps { display: flex; gap: 6px; flex-wrap: wrap; margin: 20px 0 28px; }
.step { flex: 1; min-width: 100px; text-align: center; padding: 10px 4px; border-radius: 8px;
        background: var(--panel); color: var(--dim); font-size: 13px; border: 1px solid var(--line); }
.step.active { background: var(--panel2); color: var(--accent); border-color: var(--accent); font-weight: 600; }
.step.done { color: #7fb98a; }
.step.clickable { cursor: pointer; }
.step.clickable:hover { border-color: var(--accent); color: var(--text); }

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 26px; }
.panel h2 { font-size: 19px; margin-bottom: 6px; color: var(--accent); }
.panel .hint { color: var(--dim); font-size: 13px; margin-bottom: 18px; }

.group { margin-bottom: 22px; }
.group h3 { font-size: 15px; margin-bottom: 10px; color: var(--accent2); }
.opts { display: flex; flex-wrap: wrap; gap: 10px; }
.opt { padding: 9px 16px; border-radius: 8px; background: var(--panel2); border: 1px solid var(--line);
       cursor: pointer; font-size: 14px; transition: all .15s; }
.opt:hover { border-color: var(--accent); }
.opt.sel { background: var(--accent); color: #1a1408; font-weight: 600; border-color: var(--accent); }

button.primary { background: var(--accent); color: #1a1408; border: none; padding: 13px 34px; font-size: 15px;
                 border-radius: 8px; cursor: pointer; font-weight: 700; letter-spacing: 2px; }
button.primary:disabled { opacity: .4; cursor: not-allowed; }
button.ghost { background: transparent; color: var(--dim); border: 1px solid var(--line); padding: 11px 22px;
               font-size: 14px; border-radius: 8px; cursor: pointer; }
button.ghost:hover { color: var(--text); border-color: var(--dim); }

.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 14px; }
.card { background: var(--panel2); border: 1px solid var(--line); border-radius: 10px; padding: 16px; cursor: pointer; transition: all .15s; }
.card:hover { border-color: var(--accent); transform: translateY(-2px); }
.card.sel { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.card h4 { color: var(--accent); font-size: 15px; margin-bottom: 8px; }
.card p { color: var(--dim); font-size: 13px; line-height: 1.7; }
.card-custom { border-style: dashed; }
#customSynForm { margin-top: 14px; }

.chapter { margin-bottom: 26px; }
.chapter h4 { color: var(--accent); font-size: 17px; margin-bottom: 10px; padding-bottom: 8px; border-bottom: 1px solid var(--line); }
.chapter p { white-space: pre-wrap; line-height: 2.0; font-size: 15px; color: #cdd5e5; }

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--accent2); font-weight: 600; white-space: nowrap; }
td { color: #cdd5e5; line-height: 1.6; }

.tabs { display: flex; gap: 8px; margin-bottom: 16px; }
.tab { padding: 8px 20px; border-radius: 8px 8px 0 0; background: var(--panel2); border: 1px solid var(--line);
       border-bottom: none; cursor: pointer; color: var(--dim); font-size: 14px; }
.tab.sel { color: var(--accent); font-weight: 600; background: var(--panel); }

.row { display: flex; gap: 12px; align-items: center; margin-top: 22px; flex-wrap: wrap; }
textarea { width: 100%; background: var(--panel2); color: var(--text); border: 1px solid var(--line);
           border-radius: 8px; padding: 12px; font-size: 14px; font-family: inherit; resize: vertical; min-height: 70px; margin-top: 14px; }
.err { background: #3a2222; color: #f0b0b0; padding: 12px 16px; border-radius: 8px; margin: 14px 0; font-size: 14px; }
.ok  { background: #233a2a; color: #8fd8a0; padding: 12px 16px; border-radius: 8px; margin: 14px 0; font-size: 14px; }
.hidden { display: none !important; }
.tag { display:inline-block; background:var(--panel); border:1px solid var(--accent2); color:var(--accent2);
       padding:1px 8px; border-radius:6px; font-size:12px; margin-right:6px; }

/* 大纲与连载 */
.memo { background: var(--panel2); border: 1px solid var(--line); border-radius: 8px; padding: 10px 14px; margin-bottom: 12px; }
.memo summary { cursor: pointer; color: var(--accent2); font-size: 14px; }
.memo p, .memo div { margin-top: 10px; font-size: 13px; color: #cdd5e5; line-height: 1.8; }
.chapter.draft { border: 1px dashed var(--accent); border-radius: 10px; padding: 14px; }
.draft-badge { display: inline-block; background: #4a3a1c; color: var(--accent); padding: 1px 10px;
               border-radius: 6px; font-size: 12px; margin-left: 8px; vertical-align: middle; }
.hook { font-size: 13px; line-height: 1.8; color: #cdd5e5; }
.hook.resolved { color: var(--dim); text-decoration: line-through; }

/* 章节列表与编辑 */
input[type=text] { width: 100%; background: var(--panel2); color: var(--text); border: 1px solid var(--line);
                   border-radius: 8px; padding: 12px; font-size: 14px; font-family: inherit; margin-top: 14px; }
.chap-item { display: flex; justify-content: space-between; align-items: center; gap: 10px;
             padding: 12px 14px; border: 1px solid var(--line); border-radius: 8px;
             background: var(--panel2); margin-bottom: 8px; cursor: pointer; transition: all .15s; }
.chap-item:hover { border-color: var(--accent); }
.chap-item .ct { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* 浮动进度窗：大模型调用期间居中悬浮于页面，半透遮罩防止误操作 */
#loadingMask { position: fixed; inset: 0; z-index: 100; background: rgba(8, 11, 18, .55);
               backdrop-filter: blur(2px); display: flex; align-items: center; justify-content: center; }
#loadingFloat { background: var(--panel); border: 1px solid var(--accent); border-radius: 14px;
                padding: 32px 48px; text-align: center; max-width: 420px;
                box-shadow: 0 16px 48px rgba(0, 0, 0, .55); animation: pop .18s ease-out; }
#loadingFloat .spin { width: 30px; height: 30px; border: 3px solid var(--line); border-top-color: var(--accent);
                      border-radius: 50%; animation: sp 0.8s linear infinite; margin: 0 auto 16px; }
#loadingText { color: var(--text); font-size: 15px; line-height: 1.6; }
#pipeSteps { margin-top: 14px; font-size: 13px; color: var(--dim); }
#pipeSteps span { padding: 3px 10px; border: 1px solid var(--line); border-radius: 999px; opacity: .55; }
#pipeSteps span.on { color: var(--accent); border-color: var(--accent); font-weight: 600; opacity: 1; }
#pipeSteps i { font-style: normal; margin: 0 6px; opacity: .5; }
.loading-sub { margin-top: 10px; font-size: 12px; color: var(--dim); opacity: .8; }
@keyframes pop { from { transform: scale(.92); opacity: 0; } to { transform: scale(1); opacity: 1; } }
@keyframes sp { to { transform: rotate(360deg); } }

/* ---------- 章节棋盘 ---------- */
#boardWrap { display: flex; gap: 16px; align-items: flex-start; margin-top: 18px; }
#novelPreview { margin-top: 18px; }
.preview-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; border-bottom: 1px solid var(--line); padding-bottom: 12px; }
#previewContent { max-width: 900px; margin: 24px auto; color: var(--text); font-size: 20px; line-height: 2; }
.preview-chapter { margin-bottom: 42px; }
.preview-chapter h3 { color: var(--accent); font-size: 24px; margin-bottom: 16px; }
.preview-chapter p { margin: 0 0 18px; white-space: pre-wrap; text-indent: 2em; }
#boardGrid { flex: 1; display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 10px; }
.vol-head { grid-column: 1 / -1; margin-top: 8px; padding: 8px 12px; color: var(--accent);
            font-size: 15px; border-left: 3px solid var(--accent); background: var(--panel2); border-radius: 6px; }
.vol-head .vol-meta { margin-left: 8px; font-size: 12px; color: var(--dim); }
.vol-head .vol-sum { margin-top: 4px; font-size: 12px; color: var(--dim); line-height: 1.7; font-weight: normal; }
.vol-head-list { margin: 10px 0 4px; }
.preview-vol { color: var(--accent2); font-size: 22px; margin: 36px 0 8px; border-bottom: 1px dashed var(--line); padding-bottom: 8px; }
.cell { background: var(--panel2); border: 1px solid var(--line); border-radius: 10px;
        padding: 10px; min-height: 110px; transition: border-color .15s, box-shadow .15s; }
.cell.draft { border-style: dashed; border-color: var(--accent); }
.cell.drop-hint { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.cell .ch-head { display: flex; justify-content: space-between; align-items: center; }
.cell .ch-no { font-size: 12px; color: var(--dim); }
.cell .ch-ops { display: inline-flex; align-items: center; gap: 6px; }
.cell .gen { display: inline-flex; font-style: normal; cursor: pointer; color: var(--dim);
             opacity: .7; transition: all .15s; }
.cell .gen:hover { opacity: 1; color: var(--accent); }
/* 章节剧情点（beat）悬停浮窗 */
.cell { position: relative; }
.cell-tip { display: none; position: absolute; left: 0; bottom: calc(100% + 8px); z-index: 60;
            width: 280px; white-space: normal; line-height: 1.8; font-size: 12px; color: var(--text);
            background: var(--panel); border: 1px solid var(--accent); border-radius: 10px;
            padding: 12px 14px; box-shadow: 0 12px 36px rgba(0, 0, 0, .55); }
.cell-tip::before { content: '本章剧情点'; display: block; color: var(--accent2);
                    font-size: 11px; margin-bottom: 5px; letter-spacing: 1px; }
.ch-title:hover ~ .cell-tip { display: block; animation: pop .15s ease-out; }
.cell .ch-title { font-size: 14px; color: var(--accent); margin: 6px 0 8px; cursor: pointer;
                  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cell .ch-title:hover { text-decoration: underline; }
.cell .chips { display: flex; flex-wrap: wrap; gap: 4px; }
.chip { display: inline-flex; align-items: center; gap: 4px; font-size: 11px; padding: 1px 6px;
        border-radius: 6px; border: 1px solid; max-width: 100%; }
.chip > span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 110px; }
.chip .x { font-style: normal; cursor: pointer; opacity: .6; }
.chip .x:hover { opacity: 1; }
.chip-hook      { border-color: var(--accent);  color: var(--accent); }
.chip-character { border-color: var(--accent2); color: var(--accent2); }
.chip-item      { border-color: #6fb8d8;        color: #6fb8d8; }
.chip-skill     { border-color: #8fd8a0;        color: #8fd8a0; }
.chip-extracted { border-style: dashed; opacity: .75; }
.chip-hook.resolved { opacity: .5; text-decoration: line-through; }

/* 元素栏（右侧） */
#elemPanel { width: 300px; flex-shrink: 0; background: var(--panel2); border: 1px solid var(--line);
             border-radius: 10px; padding: 12px; max-height: 70vh; overflow-y: auto; }
.elem-item { position: relative; padding: 9px 10px; border: 1px solid var(--line); border-radius: 8px;
             margin-bottom: 8px; cursor: grab; background: var(--panel); }
.elem-item:hover { border-color: var(--accent); }
.elem-item:active { cursor: grabbing; }
.elem-item .del { position: absolute; top: 4px; right: 6px; font-style: normal; font-size: 12px;
                  color: var(--dim); cursor: pointer; opacity: .5; padding: 2px 4px; }
.elem-item .del:hover { opacity: 1; color: #e07a7a; }
.elem-item .et { font-size: 13px; color: var(--text); overflow: hidden; text-overflow: ellipsis;
                 display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.elem-item .em { font-size: 11px; color: var(--dim); margin-top: 3px; }
.elem-empty { color: var(--dim); font-size: 12px; text-align: center; padding: 16px 0; }
#btnAddElem { width: 100%; }
#elemPanel .tabs { margin-bottom: 10px; }
#elemPanel .tab { flex: 1; text-align: center; padding: 6px 4px; font-size: 13px; }

/* 元素添加弹窗 */
.modal-mask { position: fixed; inset: 0; z-index: 110; background: rgba(8, 11, 18, .55);
              backdrop-filter: blur(2px); display: flex; align-items: center; justify-content: center; }
#elemModal { background: var(--panel); border: 1px solid var(--accent); border-radius: 14px;
             padding: 24px 28px; width: 460px; max-width: 92vw; max-height: 85vh; overflow-y: auto;
             box-shadow: 0 16px 48px rgba(0, 0, 0, .55); animation: pop .18s ease-out; }
#elemModal h3 { color: var(--accent); font-size: 17px; margin-bottom: 14px; }
#elemForm label { display: block; font-size: 13px; color: var(--dim); margin-bottom: 4px; }
#elemForm input, #elemForm select, #elemForm textarea { margin-top: 5px; }
select { width: 100%; background: var(--panel2); color: var(--text); border: 1px solid var(--line);
         border-radius: 8px; padding: 10px; font-size: 14px; font-family: inherit; }

/* ---------- 故事图谱 ---------- */
#panelGraph { padding: 20px; }
.graph-toolbar { display: flex; align-items: center; gap: 16px; margin-bottom: 12px; flex-wrap: wrap; }
.graph-legend { display: flex; gap: 14px; font-size: 12px; color: var(--dim); flex-wrap: wrap; }
.lg-item { display: inline-flex; align-items: center; gap: 5px; }
.lg-dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; }
.lg-active { background: #8b6fd8; }
.lg-exit { background: #4a4a4a; }
.lg-turning { background: var(--accent); }
.lg-ally { background: #4a8fd8; }
.lg-enemy { background: #d84a4a; }
.lg-lover { background: #d84a9a; }
.lg-line { display: inline-block; width: 20px; height: 3px; border-radius: 2px; }
.lg-line-turning { background: var(--accent); height: 5px; }
#graphCanvas { width: 100%; height: 600px; background: var(--bg); border: 1px solid var(--line); border-radius: 10px; }
.graph-detail { margin-top: 16px; background: var(--panel2); border: 1px solid var(--accent); border-radius: 10px; padding: 16px 20px; }
.graph-detail-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 10px; }
.graph-detail-head h3 { color: var(--accent); font-size: 16px; }
.graph-detail-head .ghost { margin-left: auto; padding: 4px 12px; font-size: 12px; }
.graph-detail p { color: #cdd5e5; font-size: 14px; line-height: 1.8; margin-bottom: 10px; }
.graph-detail h4 { color: var(--accent2); font-size: 13px; margin: 16px 0 8px; }
.graph-bg { color: var(--dim); font-size: 13px; }
.graph-identity { color: var(--accent2); font-size: 13px; }
.graph-impact { padding: 2px 10px; border-radius: 6px; font-size: 12px; }
.impact-minor { background: #2a2a3a; color: #8a94ad; }
.impact-major { background: #2b3757; color: #8ab8e0; }
.impact-turning { background: #4a3a1c; color: var(--accent); font-weight: 600; }
.graph-chapter { color: var(--dim); font-size: 13px; }
.graph-chars { margin-top: 10px; }
.graph-state-timeline { margin-top: 8px; }
.graph-state-item { display: grid; grid-template-columns: 14px 70px 1fr 120px 1fr auto; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 13px; align-items: start; }
.graph-state-dot { width: 12px; height: 12px; border-radius: 50%; margin-top: 3px; }
.graph-state-ch { color: var(--accent); font-weight: 600; white-space: nowrap; }
.graph-state-text { color: #cdd5e5; }
.graph-state-rel { color: var(--accent2); }
.graph-state-evt { color: var(--dim); }
.graph-state-exit { color: #e07a7a; font-size: 12px; white-space: nowrap; }

/* ---------- 故事地铁图编排画布 ---------- */
#panelArc { padding: 20px; }
#arcMainTabs { margin-bottom: 16px; }
#arcWrap { display: flex; gap: 16px; align-items: flex-start; margin-top: 4px; }
#arcCanvasWrap { flex: 1; overflow: auto; max-height: 90vh; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); }
.arc-toolbar { padding: 8px 12px; border-bottom: 1px solid var(--line); background: var(--panel2); position: sticky; top: 0; z-index: 5; }
.arc-hint { font-size: 12px; color: var(--dim); }
#arcCanvas { overflow: auto; }
#arcElemPanel { width: 280px; flex-shrink: 0; background: var(--panel2); border: 1px solid var(--line);
                border-radius: 10px; padding: 12px; max-height: 90vh; overflow-y: auto; }
.arc-elem-item { padding: 9px 10px; border: 1px solid var(--line); border-radius: 8px;
                 margin-bottom: 8px; cursor: grab; background: var(--panel); transition: border-color .15s; }
.arc-elem-item:hover { border-color: var(--accent); }
.arc-elem-item:active { cursor: grabbing; }
.arc-elem-item.has-arc { border-color: var(--accent2); background: rgba(139, 111, 216, 0.1); }
.arc-elem-label { font-size: 13px; color: var(--text); font-weight: 600; }
.arc-elem-meta { font-size: 11px; color: var(--dim); margin-top: 3px; line-height: 1.5; }
#btnArcAddElem { width: 100%; margin-top: 8px; }
#arcEditBox { margin-top: 18px; background: var(--panel2); border: 1px solid var(--accent); border-radius: 10px; padding: 18px; }
#arcEditBox h3 { color: var(--accent); font-size: 16px; margin-bottom: 14px; }
#arcEditBox label { display: block; font-size: 13px; color: var(--dim); margin-bottom: 4px; margin-top: 10px; }
#arcEditBox input, #arcEditBox textarea { margin-top: 5px; }
#arcEditBox input[type=number] { width: 120px; }
