:root {
  --bg: #12110f; --panel: #1b1916; --panel2: #232019; --line: #3a3426; --ink: #ece3cf; --dim: #a39a86; --gold: #d8b76a; --gold2: #f3d68e; --red: #c8553a;
  --serif: 'Noto Serif TC', 'Songti TC', 'PMingLiU', serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink); font-family: var(--serif); }
body { display: flex; flex-direction: column; overflow: hidden; }
button { font-family: inherit; }

/* ---- header ---- */
#top { display: flex; align-items: center; gap: 18px; padding: 8px 16px 8px 70px; background: linear-gradient(#1f1c16, #16140f); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.brand { display: flex; align-items: baseline; gap: 10px; }
.brand h1 { margin: 0; font-size: 28px; font-weight: 900; letter-spacing: 6px; color: var(--gold2); text-shadow: 0 0 18px rgba(216, 183, 106, .35); }
.brand span { color: var(--dim); letter-spacing: 3px; font-size: 14px; }
#date { font-size: 24px; font-weight: 700; color: var(--ink); min-width: 140px; letter-spacing: 2px; }
#date small { display: block; font-size: 12px; color: var(--dim); letter-spacing: 1px; font-weight: 500; }
#ctl { display: flex; gap: 6px; align-items: center; margin-left: auto; flex-wrap: wrap; }
.btn { background: #2a2620; color: var(--ink); border: 1px solid #4a4130; border-radius: 6px; padding: 6px 12px; font-size: 14px; cursor: pointer; transition: background .15s, border-color .15s; }
.btn:hover { background: #352f25; border-color: var(--gold); }
.btn.on { background: #5a4520; border-color: var(--gold); color: var(--gold2); }
.btn.big { font-size: 16px; padding: 7px 16px; }
.btn.go { background: #6a4a1a; border-color: var(--gold); color: #fff3d0; }

/* ---- layout ---- */
main { flex: 1; display: grid; grid-template-columns: 1fr 420px; min-height: 0; }
#mapbox { position: relative; display: flex; flex-direction: column; min-height: 0; min-width: 0; }
#map { flex: 1; width: 100%; min-height: 0; display: block; cursor: crosshair; }
#chart { height: 96px; width: 100%; display: block; border-top: 1px solid var(--line); background: #15130f; }
#legend { position: absolute; left: 10px; bottom: 106px; display: flex; flex-direction: column; gap: 2px; pointer-events: none; }
#legend div { font-size: 12px; background: rgba(18, 16, 13, .72); padding: 2px 8px 2px 6px; border-radius: 4px; display: flex; align-items: center; gap: 6px; }
#legend i { width: 10px; height: 10px; border-radius: 2px; display: inline-block; }
#tip { position: absolute; pointer-events: none; background: rgba(20, 18, 14, .94); border: 1px solid var(--gold); border-radius: 6px; padding: 8px 10px; font-size: 13px; line-height: 1.5; max-width: 240px; z-index: 5; }
#tip b { color: var(--gold2); font-size: 15px; }

#side { border-left: 1px solid var(--line); background: var(--panel); display: flex; flex-direction: column; min-height: 0; }
#tabs { display: flex; border-bottom: 1px solid var(--line); }
#tabs button { flex: 1; background: none; border: 0; color: var(--dim); padding: 11px 4px; font-size: 16px; letter-spacing: 2px; cursor: pointer; border-bottom: 2px solid transparent; }
#tabs button.on { color: var(--gold2); border-bottom-color: var(--gold); }
#pane { flex: 1; overflow-y: auto; padding: 10px 12px 30px; }

/* ---- chronicle ---- */
.chips { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; position: sticky; top: -10px; background: var(--panel); padding: 6px 0; z-index: 2; }
.chip { background: #262219; border: 1px solid #3c3426; color: var(--dim); border-radius: 14px; padding: 3px 11px; font-size: 13px; cursor: pointer; }
.chip.on { color: var(--gold2); border-color: var(--gold); background: #3a2e18; }
.ev { display: flex; gap: 8px; padding: 6px 4px 6px 8px; border-left: 3px solid #444; margin-bottom: 4px; font-size: 14px; line-height: 1.55; border-radius: 0 4px 4px 0; cursor: default; }
.ev:hover { background: #221f19; }
.ev .d { color: var(--gold); font-size: 12px; min-width: 64px; padding-top: 2px; white-space: nowrap; }
.ev.lv2 { font-weight: 700; }
.ev.lv3 { font-weight: 900; background: #2a2214; color: var(--gold2); font-size: 15px; }
.ev.click { cursor: pointer; }

/* ---- tables and lists ---- */
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { text-align: left; color: var(--dim); font-weight: 500; padding: 4px 4px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--panel); cursor: pointer; white-space: nowrap; }
td { padding: 5px 4px; border-bottom: 1px solid #2a261e; white-space: nowrap; }
tr.row { cursor: pointer; } tr.row:hover td { background: #241f17; }
.sw { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 6px; vertical-align: -1px; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.dead td { color: #7a7266; }
.filters { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 8px; }
.filters input, .filters select { background: #26221b; color: var(--ink); border: 1px solid #443b2c; border-radius: 6px; padding: 6px 8px; font-family: inherit; font-size: 14px; }
.filters input { flex: 1; min-width: 120px; }
.count { color: var(--dim); font-size: 12px; margin: 4px 0 8px; }

/* ---- detail cards ---- */
.back { background: none; border: 0; color: var(--gold); cursor: pointer; font-size: 14px; padding: 2px 0 8px; }
.card h2 { margin: 2px 0 2px; font-size: 26px; letter-spacing: 3px; color: var(--gold2); }
.card .sub { color: var(--dim); font-size: 13px; margin-bottom: 10px; }
.stat { display: grid; grid-template-columns: 54px 1fr 34px; align-items: center; gap: 8px; margin: 5px 0; font-size: 14px; }
.bar { height: 9px; background: #2c271f; border-radius: 5px; overflow: hidden; }
.bar i { display: block; height: 100%; background: linear-gradient(90deg, #8a6a2a, var(--gold2)); }
.kv { display: grid; grid-template-columns: 90px 1fr; gap: 3px 10px; font-size: 14px; margin: 10px 0; }
.kv span:nth-child(odd) { color: var(--dim); }
.tag { display: inline-block; border: 1px solid #4a4030; border-radius: 4px; padding: 0 6px; margin: 2px 4px 2px 0; font-size: 12px; cursor: pointer; }
.tag:hover { border-color: var(--gold); }
h3 { font-size: 15px; color: var(--gold); margin: 16px 0 6px; letter-spacing: 2px; border-bottom: 1px solid var(--line); padding-bottom: 3px; }

/* ---- modal ---- */
#modal { position: fixed; inset: 0; background: rgba(6, 5, 4, .75); display: flex; align-items: center; justify-content: center; z-index: 20; }
#modal[hidden] { display: none; }
.box { background: linear-gradient(#26221a, #1a1712); border: 1px solid var(--gold); border-radius: 10px; padding: 24px 26px; width: min(520px, 92vw); box-shadow: 0 10px 50px rgba(0, 0, 0, .6); }
.box h2 { margin: 0 0 6px; font-size: 30px; letter-spacing: 6px; color: var(--gold2); text-align: center; }
.box p { line-height: 1.7; color: var(--ink); }
.box label { display: block; margin: 12px 0 4px; color: var(--dim); font-size: 14px; }
.box input, .box select { width: 100%; background: #26221b; color: var(--ink); border: 1px solid #443b2c; border-radius: 6px; padding: 8px; font-size: 15px; font-family: inherit; }
.box .row2 { display: flex; gap: 10px; justify-content: center; margin-top: 18px; flex-wrap: wrap; }
.box .big { font-size: 22px; text-align: center; color: var(--gold2); margin: 14px 0; }

/* ---- phones ---- */
@media (max-width: 860px) {
  body { overflow: auto; }
  #top { padding: 8px 10px 8px 64px; gap: 8px; }
  .brand h1 { font-size: 22px; letter-spacing: 3px; }
  .brand span { display: none; }
  #date { font-size: 18px; min-width: 0; }
  #ctl { margin-left: 0; width: 100%; }
  .btn { padding: 6px 9px; font-size: 13px; }
  main { grid-template-columns: 1fr; display: flex; flex-direction: column; }
  #mapbox { height: 62vh; flex: none; }
  #side { border-left: 0; border-top: 1px solid var(--line); min-height: 70vh; }
  #legend { bottom: 102px; }
}

/* treasures, spells, hidden generals */
.stat .plus { color: #7fd08a; font-size: 11px; margin-left: 2px; }
.item { font-size: 14px; margin: 3px 0; }
.item small, small.dim, .dim { color: var(--dim); }
.tag.item { border-color: #8a6a2a; color: var(--gold2); cursor: default; }
.tag.spell { border-color: #6a5aa8; color: #c8b8ff; cursor: default; }
.hiddenTag { color: #ff9ad8; font-weight: 700; }
#ndesc { color: var(--dim); font-size: 14px; min-height: 2.6em; }
