:root {
  --bg: #f6f4f0; --panel: #ffffff; --ink: #1f2933; --muted: #6b7280; --line: #d9d4cc;
  --accent: #9a3412; --accent-soft: #fdeee4; --gold: #b7791f; --gold-soft: #fbf1d9;
  --red: #b42318; --ok: #1d7a46; --node: #ffffff; --edge: #8a8378; --warn: #fff7e0;
  --font: "Noto Sans TC", "Microsoft JhengHei", system-ui, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #16181c; --panel: #1f2329; --ink: #e8e6e1; --muted: #9aa0a6; --line: #343a42;
    --accent: #f0a070; --accent-soft: #3a2a20; --gold: #e6b84f; --gold-soft: #3a3220;
    --red: #ff8a7a; --ok: #6fd39b; --node: #262b32; --edge: #8c919a; --warn: #3a3420;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink); font: 15px/1.6 var(--font); }
button { font: inherit; cursor: pointer; border: 1px solid var(--line); background: var(--panel); color: var(--ink); padding: 5px 12px; border-radius: 6px; }
button:hover { border-color: var(--accent); }
button.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
button.danger { color: var(--red); }
button:disabled { opacity: .5; cursor: not-allowed; }
input, textarea, select { font: inherit; color: var(--ink); background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: 5px 8px; }
textarea { width: 100%; resize: vertical; }

.login { max-width: 340px; margin: 12vh auto; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 28px; }
.login h1 { margin: 0 0 16px; font-size: 20px; color: var(--accent); }
.login label { display: block; margin: 10px 0 4px; color: var(--muted); font-size: 13px; }
.login input { width: 100%; }
.login button { margin-top: 16px; width: 100%; }
.err { color: var(--red); margin-top: 10px; font-size: 14px; }

.shell { display: grid; grid-template-rows: 48px 1fr; height: 100vh; }
.top { display: flex; align-items: center; gap: 12px; padding: 0 16px; border-bottom: 1px solid var(--line); background: var(--panel); }
.top h1 { font-size: 16px; margin: 0; color: var(--accent); flex: 1; }
.top .who { color: var(--muted); font-size: 13px; }
.main { display: grid; grid-template-columns: 290px 1fr; min-height: 0; }
.side { border-right: 1px solid var(--line); background: var(--panel); overflow: auto; padding: 12px; }
.side select { width: 100%; margin-bottom: 10px; }
.side h3 { font-size: 12px; color: var(--muted); margin: 14px 0 4px; font-weight: 600; letter-spacing: .04em; }
.blk { display: flex; align-items: center; gap: 6px; padding: 5px 8px; border-radius: 6px; cursor: pointer; font-size: 14px; }
.blk:hover { background: var(--accent-soft); }
.blk.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.blk .t { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tag { font-size: 11px; border-radius: 10px; padding: 0 7px; border: 1px solid var(--line); color: var(--muted); white-space: nowrap; }
.tag.lock { color: var(--red); border-color: var(--red); }
.tag.pend { color: var(--gold); border-color: var(--gold); }
.kind { font-size: 11px; color: var(--muted); width: 2.4em; }

.content { overflow: auto; padding: 20px 28px 60px; }
.bhead { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 6px; }
.bhead h2 { margin: 0; font-size: 20px; }
.bhead .grow { flex: 1; }
.meta { color: var(--muted); font-size: 13px; margin-bottom: 10px; }
.banner { border: 1px solid var(--line); background: var(--warn); border-radius: 8px; padding: 8px 12px; margin: 8px 0; font-size: 14px; }
.banner.red { border-color: var(--red); color: var(--red); }
.banner.ok { border-color: var(--ok); }
.text p { margin: 4px 0; }
.text ul { margin: 4px 0 8px; padding-left: 22px; }
.text li { margin: 2px 0; }
b { font-weight: 700; }
.tablewrap { overflow-x: auto; margin: 10px 0; }
table.t { border-collapse: collapse; width: 100%; font-size: 14px; background: var(--panel); }
table.t th, table.t td { border: 1px solid var(--line); padding: 6px 9px; text-align: left; vertical-align: top; }
table.t th { background: var(--accent-soft); font-weight: 600; white-space: nowrap; }
table.t tr.hl td { background: var(--gold-soft); }

/* 國策樹 */
.tree { position: relative; overflow: auto; border: 1px solid var(--line); border-radius: 10px; background: var(--panel); padding: 20px; margin: 10px 0; }
.tree svg { position: absolute; left: 0; top: 0; pointer-events: none; }
.node { position: absolute; width: 170px; height: 84px; border: 1.5px solid var(--edge); border-radius: 8px; background: var(--node); padding: 6px 9px; cursor: pointer; overflow: hidden; }
.node:hover { border-color: var(--accent); }
.node.sel { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.node.auto { border-color: var(--gold); background: var(--gold-soft); }
.node.ghost { border-style: dashed; opacity: .75; }
.node .nm { font-size: 13px; font-weight: 600; line-height: 1.3; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.node .mt { position: absolute; left: 9px; bottom: 5px; font-size: 11px; color: var(--muted); }
.node .ex { position: absolute; right: 7px; bottom: 5px; font-size: 11px; color: var(--red); }
.detail { border: 1px solid var(--line); border-radius: 10px; background: var(--panel); padding: 10px 14px; margin: 8px 0; }
.detail dl { margin: 0; display: grid; grid-template-columns: 7em 1fr; gap: 4px 12px; font-size: 14px; }
.detail dt { color: var(--muted); }
.detail dd { margin: 0; }
.legend { font-size: 12px; color: var(--muted); margin: 2px 0 8px; }

/* 計量條 */
.bop { margin: 14px 0 6px; }
.bar { position: relative; height: 46px; border-radius: 8px; overflow: hidden; border: 1px solid var(--line); }
.seg { position: absolute; top: 0; bottom: 0; display: flex; align-items: center; justify-content: center; font-size: 12px; color: #fff; text-shadow: 0 1px 2px rgba(0,0,0,.5); overflow: hidden; white-space: nowrap; }
.mark { position: absolute; top: -4px; bottom: -4px; width: 0; border-left: 2px solid var(--ink); }
.mark.zero { border-left: 2px dashed #fff; opacity: .9; }
.mark.start { border-left: 3px solid #111; }
.ends { display: flex; justify-content: space-between; font-size: 13px; margin-top: 4px; }
.slider { width: 100%; margin: 10px 0 0; }
.now { border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px; background: var(--panel); margin-top: 6px; }

/* 事件選項 */
.opts { display: grid; gap: 8px; margin: 8px 0; }
.opt { border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px; background: var(--panel); }
.opt .on { font-weight: 700; color: var(--accent); margin-bottom: 2px; }
.opt .row { font-size: 14px; }
.opt .row span { color: var(--muted); margin-right: 6px; }

/* 編輯器 */
.editor { border: 1px solid var(--accent); border-radius: 10px; padding: 12px; margin: 14px 0; background: var(--panel); }
.editor h4 { margin: 0 0 8px; color: var(--accent); }
.grid { border-collapse: collapse; width: 100%; font-size: 13px; }
.grid th { background: var(--accent-soft); border: 1px solid var(--line); padding: 4px 6px; text-align: left; white-space: nowrap; }
.grid td { border: 1px solid var(--line); padding: 2px; vertical-align: top; }
.grid td textarea { border: none; border-radius: 0; padding: 3px 5px; min-width: 90px; height: auto; resize: none; overflow: hidden; background: transparent; }
.grid tr.sel td { background: var(--gold-soft); }
.grid td.ctl { white-space: nowrap; padding: 3px; }
.grid td.ctl button { padding: 0 6px; }

.modal { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: flex; align-items: center; justify-content: center; z-index: 50; }
.modal .box { background: var(--panel); border-radius: 12px; padding: 20px 24px; max-width: 760px; width: 92%; max-height: 86vh; overflow: auto; border: 1px solid var(--line); }
.modal h3 { margin: 0 0 10px; }
.modal pre { background: var(--bg); padding: 10px; border-radius: 6px; white-space: pre-wrap; font-size: 12px; max-height: 280px; overflow: auto; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.toast { position: fixed; right: 20px; bottom: 20px; background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 8px; z-index: 60; }
.plist .it { border-bottom: 1px solid var(--line); padding: 6px 0; cursor: pointer; }
.plist .it:hover { background: var(--accent-soft); }

@media (max-width: 760px) {
  .main { grid-template-columns: 1fr; }
  .side { max-height: 36vh; border-right: none; border-bottom: 1px solid var(--line); }
  .content { padding: 14px 16px 60px; }
}
