:root {
  --paper: #f6eedb;
  --paper2: #efe3c6;
  --ink: #2b1d10;
  --ink2: #5c4630;
  --line: #b89a6a;
  --accent: #9c2b1f;
  --good: #2f7a33;
  --bad: #b3261e;
  --bar: #2a1f16;
  --bar-ink: #f3e6c8;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #22384f; color: var(--ink);
  font-family: "Noto Serif SC", "Songti SC", "STSong", "SimSun", serif; font-size: 13px; }
button { font-family: inherit; }
#app { position: fixed; inset: 0; }
#map { position: absolute; inset: 0; width: 100%; height: 100%; display: block; cursor: grab; touch-action: none; }
#map.dragging { cursor: grabbing; }
#map.targeting { cursor: crosshair; }
.hidden { display: none !important; }

/* 左上：国家栏 + 缩略图 */
#tl { position: absolute; left: 10px; top: 10px; width: 260px; z-index: 5; display: flex; flex-direction: column; gap: 6px; }
#country-bar { background: var(--paper); border: 1px solid var(--line); border-radius: 6px; box-shadow: 0 2px 8px rgba(0,0,0,.35); }
.cb-current { display: flex; align-items: center; gap: 8px; padding: 7px 9px; cursor: pointer; user-select: none; }
.cb-current .name { font-weight: 700; font-size: 15px; flex: 1; }
.chip { display: inline-block; width: 14px; height: 14px; border-radius: 3px; border: 1px solid rgba(0,0,0,.45); flex: none; }
.cb-list { max-height: 50vh; overflow-y: auto; border-top: 1px solid var(--line); }
.cb-item { display: flex; align-items: center; gap: 8px; padding: 5px 9px; cursor: pointer; }
.cb-item:hover { background: var(--paper2); }
.cb-item.sel { background: #e7d6ae; font-weight: 700; }
.cb-item .meta { margin-left: auto; color: var(--ink2); font-size: 12px; }
#mini-wrap { background: #111; border: 2px solid var(--paper); border-radius: 4px; box-shadow: 0 2px 8px rgba(0,0,0,.4); line-height: 0; }
#minimap { width: 256px; height: 176px; image-rendering: pixelated; cursor: pointer; }

/* 顶栏 */
#topbar { position: absolute; left: 280px; right: 10px; top: 10px; z-index: 4; display: flex; flex-wrap: wrap; align-items: center; gap: 6px;
  background: rgba(42,31,22,.92); color: var(--bar-ink); border-radius: 6px; padding: 5px 8px; box-shadow: 0 2px 8px rgba(0,0,0,.35); }
#topbar .date { font-weight: 700; font-size: 14px; min-width: 118px; }
#topbar .grp { display: flex; gap: 3px; align-items: center; }
#topbar .sep { width: 1px; height: 20px; background: rgba(255,255,255,.2); margin: 0 3px; }
.tb { background: #4a3826; color: var(--bar-ink); border: 1px solid #6e5638; border-radius: 4px; padding: 2px 6px; cursor: pointer; font-size: 12.5px; }
.tb:hover { background: #5d4630; }
.tb { white-space: nowrap; }
.menu-btn, .side-toggle { display: none; }
#topbar .more { display: contents; }
.tb.on { background: #b88a3e; color: #1d1209; border-color: #e0b866; font-weight: 700; }
#topbar .res { font-size: 12px; opacity: .95; }
#topbar .res b { color: #ffd98a; }
#toolopts { position: absolute; left: 280px; top: 56px; z-index: 4; background: var(--paper); border: 1px solid var(--line); border-radius: 6px; padding: 6px 10px; box-shadow: 0 2px 8px rgba(0,0,0,.3); }

/* 右侧面板 */
#side { position: absolute; right: 10px; top: 58px; bottom: 10px; width: 330px; z-index: 4; overflow-y: auto;
  background: rgba(246,238,219,.97); border: 1px solid var(--line); border-radius: 6px; box-shadow: 0 2px 10px rgba(0,0,0,.35); padding: 10px 12px; }
#side h2 { margin: 0 0 4px; font-size: 18px; display: flex; align-items: center; gap: 8px; }
#side h3 { margin: 12px 0 5px; font-size: 14px; border-bottom: 1px solid var(--line); padding-bottom: 2px; color: var(--ink2); }
.sub { color: var(--ink2); font-size: 12px; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 2px 10px; }
.kv .k { color: var(--ink2); }
table.units { width: 100%; border-collapse: collapse; font-size: 12px; }
table.units td, table.units th { padding: 2px 3px; text-align: right; border-bottom: 1px dotted #d4c19a; }
table.units th { color: var(--ink2); font-weight: 600; }
table.units td:first-child, table.units th:first-child { text-align: left; }
table.units input { width: 64px; padding: 1px 3px; font-size: 12px; text-align: right; border: 1px solid var(--line); background: #fffaf0; }
.btn { background: #7a2a1c; color: #fff4e0; border: 1px solid #4b170e; border-radius: 4px; padding: 4px 10px; cursor: pointer; font-size: 13px; margin: 3px 4px 3px 0; }
.btn:hover { background: #962f1f; }
.btn.sec { background: #e9dcc0; color: var(--ink); border-color: var(--line); }
.btn.sec:hover { background: #dfcca4; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.mini-btn { background: none; border: 1px solid var(--line); border-radius: 3px; cursor: pointer; font-size: 11px; padding: 0 5px; color: var(--ink2); }
select, input[type=number], input[type=text] { font-family: inherit; font-size: 13px; padding: 2px 4px; border: 1px solid var(--line); background: #fffaf0; border-radius: 3px; }
.row { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; margin: 4px 0; }
.good { color: var(--good); } .bad { color: var(--bad); }
.gen { padding: 4px 0; border-bottom: 1px dotted #d4c19a; }
.gen .stats { color: var(--ink2); font-size: 12px; }
.risk { display: inline-block; padding: 0 5px; border-radius: 3px; font-size: 11px; margin-left: 4px; }
.risk.l { background: #d9ecd2; color: #23571f; } .risk.m { background: #f6e3b4; color: #7a5200; } .risk.h { background: #f5c7c0; color: #8a1c10; }
.note { background: #efe2c2; border-left: 3px solid #b88a3e; padding: 5px 8px; margin: 6px 0; font-size: 12px; color: var(--ink2); }
.bar { height: 6px; background: #e3d3ad; border-radius: 3px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: #9c2b1f; }

/* 日志 */
#logbox { position: absolute; left: 10px; bottom: 10px; width: min(560px, calc(100vw - 370px)); max-height: 30vh; z-index: 4;
  background: rgba(246,238,219,.95); border: 1px solid var(--line); border-radius: 6px; box-shadow: 0 2px 8px rgba(0,0,0,.3); display: flex; flex-direction: column; }
#logbox.collapsed #log { display: none; }
.log-head { display: flex; align-items: center; padding: 4px 8px; border-bottom: 1px solid var(--line); gap: 6px; }
.log-head .tabs { display: flex; gap: 4px; flex: 1; }
.log-head .tab { cursor: pointer; padding: 0 6px; border-radius: 3px; color: var(--ink2); }
.log-head .tab.on { background: #e1cfa6; color: var(--ink); font-weight: 700; }
#log { overflow-y: auto; padding: 4px 8px; font-size: 12px; line-height: 1.55; }
#log .e { cursor: pointer; padding: 1px 0; }
#log .e:hover { background: #ecdfc0; }
#log .e .d { color: #8a7253; margin-right: 6px; font-size: 11px; }
#log .e.major { color: #7a1a10; font-weight: 700; }
#log .e.battle { color: #3a2a18; }
#log .e.mine { border-left: 3px solid #b88a3e; padding-left: 4px; }

#hoverinfo { position: absolute; left: 10px; bottom: calc(30vh + 18px); z-index: 3; background: rgba(42,31,22,.85); color: var(--bar-ink); padding: 3px 8px; border-radius: 4px; font-size: 12px; pointer-events: none; }
#hoverinfo:empty { display: none; }
#toast { position: absolute; left: 50%; top: 104px; transform: translateX(-50%); z-index: 20; display: flex; flex-direction: column; gap: 6px; align-items: center; pointer-events: none; }
#toast .t { background: rgba(42,31,22,.95); color: var(--bar-ink); padding: 7px 14px; border-radius: 5px; box-shadow: 0 2px 8px rgba(0,0,0,.4); max-width: 520px; font-size: 13px; animation: fade 5s forwards; }
#toast .t.bad { border-left: 4px solid #e0503f; } #toast .t.good { border-left: 4px solid #6cbf5a; }
@keyframes fade { 0%,85% { opacity: 1; } 100% { opacity: 0; } }

#modal { position: absolute; inset: 0; z-index: 30; background: rgba(0,0,0,.45); display: flex; align-items: center; justify-content: center; }
.modal-card { background: var(--paper); border: 1px solid var(--line); border-radius: 8px; width: min(760px, 94vw); max-height: 88vh; display: flex; flex-direction: column; box-shadow: 0 6px 30px rgba(0,0,0,.5); }
.modal-title { display: flex; justify-content: space-between; align-items: center; padding: 10px 14px; border-bottom: 1px solid var(--line); font-size: 17px; font-weight: 700; }
.modal-title button { background: none; border: none; font-size: 18px; cursor: pointer; }
.modal-body { padding: 12px 16px; overflow-y: auto; line-height: 1.6; }
.modal-body table { border-collapse: collapse; width: 100%; font-size: 12px; }
.modal-body td, .modal-body th { border-bottom: 1px dotted #d4c19a; padding: 3px 5px; text-align: left; }
#loading { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; background: #22384f; color: #f3e6c8; font-size: 22px; z-index: 50; letter-spacing: 4px; }

@media (max-width: 760px) {
  #tl { width: 170px; }
  #minimap { width: 166px; height: 114px; }
  #topbar { left: 186px; font-size: 12px; }
  #topbar .more { display: none; }
  #topbar.open .more { display: flex; flex-wrap: wrap; gap: 4px; width: 100%; }
  #topbar .sep { display: none; }
  .menu-btn { display: inline-block; }
  .side-toggle { display: block; float: right; }
  #topbar .date { min-width: 0; }
  #side { left: 10px; right: 10px; top: auto; width: auto; height: 42vh; bottom: 10px; }
  #side.collapsed { height: 40px; overflow: hidden; }
  #logbox { display: none; }
  #toolopts { left: 186px; top: 96px; }
}
