:root {
  --bg: #f7f5f0;
  --panel: #ffffffee;
  --fg: #1f1d1a;
  --muted: #6b665e;
  --line: #e2ddd3;
  --accent: #8a1c1c;
  --glorifying: #b03a2e; --honoring: #d4813a; --reflection: #2a9d8f; --mourning: #4a78c2; --peace: #6f9e4f; --unknown: #8c8c8c; --none: #b9b4aa;
  --modern-war-dead: #6d2f9c; --modern-imperial: #b0527e; --ancient-promoted: #c98a12; --ancient-ranked: #d6bf74; --general: #9a978f;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #15140f; --panel: #1e1c18ee; --fg: #ece8e0; --muted: #a39d92; --line: #36332c; --accent: #e06b6b;
    --glorifying: #ee6a5a; --honoring: #f0a35e; --reflection: #4fc3b4; --mourning: #6aa4f0; --peace: #8cc46a; --unknown: #8a8780; --none: #5c5952;
    --modern-war-dead: #a874d4; --modern-imperial: #dc7fa8; --ancient-promoted: #e7b041; --ancient-ranked: #bba65e; --general: #6f6c66;
  }
}
:root[data-theme="dark"] {
  --bg: #15140f; --panel: #1e1c18ee; --fg: #ece8e0; --muted: #a39d92; --line: #36332c; --accent: #e06b6b;
  --glorifying: #ee6a5a; --honoring: #f0a35e; --reflection: #4fc3b4; --mourning: #6aa4f0; --peace: #8cc46a; --unknown: #8a8780; --none: #5c5952;
    --modern-war-dead: #a874d4; --modern-imperial: #dc7fa8; --ancient-promoted: #e7b041; --ancient-ranked: #bba65e; --general: #6f6c66;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; overscroll-behavior: none; background: var(--bg); color: var(--fg);
  font: 14px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Hiragino Sans", "Noto Sans JP", sans-serif; }
/* 按界面语言选字形；日文专有名词（lang="ja"）始终用日文字形 */
:lang(zh-Hans) body, body:lang(zh-Hans) { font-family: -apple-system, "PingFang SC", "Noto Sans SC", "Microsoft YaHei", sans-serif; }
:lang(zh-Hant) body, body:lang(zh-Hant) { font-family: -apple-system, "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", sans-serif; }
:lang(ko) body, body:lang(ko) { font-family: -apple-system, "Apple SD Gothic Neo", "Noto Sans KR", "Malgun Gothic", sans-serif; }
[lang="ja"] { font-family: -apple-system, "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", "Yu Gothic", "Meiryo", sans-serif; }
.ins[lang="ja"] { font-family: "Hiragino Mincho ProN", "Noto Serif JP", "Yu Mincho", serif; }
#map { position: fixed; inset: 0; }
#results, #detail { overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }
.grip { display: none; }
a { color: var(--accent); }
button, input, select { font: inherit; color: inherit; }

#panel {
  position: fixed; top: 12px; left: 12px; bottom: 12px; width: 380px; max-width: calc(100vw - 24px);
  background: var(--panel); backdrop-filter: blur(8px); border: 1px solid var(--line); border-radius: 12px;
  display: flex; flex-direction: column; overflow: hidden; box-shadow: 0 6px 24px #0002;
}
#panel header { display: flex; align-items: center; justify-content: space-between; padding: 12px 14px 6px; }
#panel h1 { font-size: 17px; margin: 0; letter-spacing: .02em; }
.ghost { background: none; border: 1px solid var(--line); border-radius: 6px; padding: 2px 10px; cursor: pointer; }
.hdr-actions { display: flex; gap: 6px; flex: none; }
#lang { padding: 2px 4px; max-width: 120px; }
#lang option { background: var(--bg); }
#panel h1 { min-width: 0; }
.controls { display: flex; gap: 6px; padding: 6px 14px; }
.controls input, .controls select { flex: 1; min-width: 0; padding: 6px 8px; border: 1px solid var(--line); border-radius: 6px; background: transparent; }
.controls select { flex: 0 0 130px; }
.controls select option { background: var(--bg); }

#legend { list-style: none; margin: 4px 0; padding: 0 14px; }
#legend li { display: flex; align-items: center; gap: 8px; padding: 3px 0; cursor: pointer; user-select: none; }
#legend li.off { opacity: .4; }
.dot { display: inline-block; width: 11px; height: 11px; border-radius: 50%; flex: none; border: 1.5px solid #fff8; vertical-align: -1px; margin-right: 6px; }
#legend .dot { margin-right: 0; }
#legend .n { margin-left: auto; color: var(--muted); font-variant-numeric: tabular-nums; }
.toggle { display: block; padding: 2px 14px; color: var(--muted); font-size: 12.5px; }
.toggle.last { padding-bottom: 8px; border-bottom: 1px solid var(--line); }
.toggle .n { font-variant-numeric: tabular-nums; }
.seg { display: flex; flex: 1; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.seg button { flex: 1; background: none; border: 0; padding: 5px 4px; cursor: pointer; font-size: 13px; }
.seg button[aria-pressed="true"] { background: var(--fg); color: var(--bg); }

#results { overflow: auto; flex: 1; }
#results .item { padding: 7px 14px; border-bottom: 1px solid var(--line); cursor: pointer; display: flex; gap: 8px; align-items: baseline; }
#results .item:hover { background: #8881; }
#results .item .sub { color: var(--muted); font-size: 12px; }
#results .more { padding: 8px 14px; color: var(--muted); font-size: 12px; }

#detail { overflow: auto; flex: 1; padding: 10px 14px 16px; border-top: 1px solid var(--line); }
#detail h2 { margin: 4px 0 2px; font-size: 18px; }
#detail .back { margin-bottom: 6px; }
.pill { display: inline-block; padding: 1px 8px; border-radius: 999px; color: #fff; font-size: 12px; font-weight: 600; margin-right: 6px; white-space: nowrap; }
#results .item .dot { margin-top: 4px; }
.kv { display: grid; grid-template-columns: 76px 1fr; gap: 2px 8px; margin: 8px 0; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; word-break: break-word; }
.mem { border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; margin: 8px 0; }
.mem h4 { margin: 0 0 4px; font-size: 14px; line-height: 1.6; }
.mem .kv { margin: 4px 0; }
.mem p { margin: 3px 0; font-size: 13px; }
.mem .ins { font-family: "Hiragino Mincho ProN", "Noto Serif JP", serif; background: #8881; padding: 4px 6px; border-radius: 4px; }
.muted { color: var(--muted); font-size: 12px; }
.links a { margin-right: 10px; font-size: 12.5px; }

dialog { max-width: min(640px, calc(100vw - 32px)); border: 1px solid var(--line); border-radius: 12px; background: var(--bg); color: var(--fg); }
dialog::backdrop { background: #0006; }
dialog .cats dt { font-weight: 700; margin-top: 6px; display: flex; align-items: center; }
dialog .cats dd { margin: 0 0 0 1.2em; color: var(--muted); }

.maplibregl-popup-content { background: var(--panel); color: var(--fg); padding: 6px 10px; border-radius: 6px; font-size: 13px; }
.maplibregl-popup-tip { display: none; }

/* 手机：可拖动的底部抽屉，三档（收起 / 半屏 / 全屏） */
@media (max-width: 640px) {
  #panel {
    --sheet-h: 88vh; --peek: 128px;
    top: auto; left: 0; right: 0; bottom: 0; width: 100%; max-width: 100%;
    height: var(--sheet-h); border-radius: 14px 14px 0 0; border-bottom: 0;
    transition: transform .25s ease; will-change: transform;
    transform: translateY(calc(var(--sheet-h) - 46vh));
  }
  @supports (height: 100dvh) { #panel { --sheet-h: 88dvh; transform: translateY(calc(var(--sheet-h) - 46dvh)); } }
  #panel[data-sheet="collapsed"] { transform: translateY(calc(var(--sheet-h) - var(--peek))); }
  #panel[data-sheet="full"] { transform: translateY(0); }
  #panel.dragging { transition: none; }
  .grip { display: block; flex: none; height: 20px; touch-action: none; cursor: grab; }
  .grip::before { content: ""; display: block; width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 8px auto 0; }
  #panel header { padding-top: 0; touch-action: none; }
  .controls select { flex-basis: 110px; }
  /* iOS 聚焦输入框时字号小于 16px 会自动放大页面 */
  .controls input, .controls select { font-size: 16px; }
  .maplibregl-ctrl-bottom-right { bottom: var(--peek, 128px); }
  /* 打开详情时只保留标题栏，详情占满抽屉 */
  #panel.has-detail .controls, #panel.has-detail #legend, #panel.has-detail .toggle { display: none; }
}
