/* public/css/base.css —— 设计令牌 + reset + 共用控件原语
 *
 * 为什么单独一份 base:
 * 1. 颜色、圆角、阴影、层级、字体栈全部收在 :root 的 CSS 变量里,面板 / 时间轴 / 图例 / 详情
 *    这些由不同模块交付的样式表只消费变量,不各自硬编码颜色 —— 否则深色主题会在六个文件里
 *    漂移成六种灰。底图颜色是另一处唯一事实(map/style.js,§7.3),这里的 --bg 与它保持同值。
 * 2. index.html 只链接 base.css 与 layout.css;各 UI 模块(时间轴 / 面板 / 详情 / 移动端)自带
 *    的样式表由模块自己按 import.meta.url 注入,免得壳去引用尚不存在的文件而在控制台报 404。
 *    模块样式表可以直接用这里的变量与 .a-btn / .a-panel 原语。
 * 3. 无障碍(§11.4):焦点可见环、触控目标 ≥ 44 px、文字对比度 ≥ 4.5:1、prefers-reduced-motion
 *    关掉过渡,都在这里一次性定死,模块不必重复。
 * 4. 不引入 webfont(OFL 不在允许许可清单,§13),只用系统字体栈(§7.3 逐字)。
 */

:root {
  /* ── 底色与面板 ── */
  --bg: #0b1017;                              /* 与 map/style.js 的 background 同值(§7.3) */
  --bg-elev: #121a24;
  --panel: rgba(16, 23, 33, 0.90);            /* 浮层底:半透明让地图透出来一点 */
  --panel-solid: #121923;
  --panel-hover: rgba(230, 236, 245, 0.08);
  --panel-active: rgba(230, 236, 245, 0.14);
  --border: rgba(230, 236, 245, 0.14);
  --border-strong: rgba(230, 236, 245, 0.26);

  /* ── 文字 ── */
  --text: #e6ecf5;                            /* 对 --bg 对比度 ≈ 15:1 */
  --text-dim: rgba(230, 236, 245, 0.68);      /* ≈ 9:1 */
  --text-faint: rgba(230, 236, 245, 0.45);    /* 只用于非信息性装饰,不承载文本内容 */
  --text-invert: #0b1017;

  /* ── 强调与语义色(都在深底上过 4.5:1) ── */
  --accent: #58c8f5;
  --accent-strong: #8fdcff;
  --accent-soft: rgba(88, 200, 245, 0.16);
  --ok: #6ed49a;
  --warn: #f2c14e;
  --danger: #f2706b;

  /* ── 形状 ── */
  --radius: 10px;
  --radius-sm: 6px;
  --radius-lg: 16px;
  --shadow: 0 6px 24px rgba(0, 0, 0, 0.42);
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.35);
  --blur: saturate(1.1) blur(12px);

  /* ── 尺寸 ── */
  --gap: 12px;
  --gap-sm: 8px;
  --tap: 44px;                                /* 触控目标下限(§11.4) */
  --bar-w: 56px;                              /* 左侧图层栏宽 */
  --detail-w: 420px;                          /* 桌面右侧详情面板宽(§10.3) */
  --timeline-h: 84px;
  --timeline-h-compact: 56px;                 /* 手机紧凑时间轴(§11.4) */
  --sheet-peek: 96px;                         /* 手机抽屉 peek 档高(§11.4);ui/mobile.js 可覆盖 */

  /* ── 层级(自下而上:地图 → 标注 → 常规 UI → 面板 → 浮层 → 提示) ── */
  --z-map: 0;
  --z-labels: 10;
  --z-ui: 20;
  --z-panel: 30;
  --z-menu: 40;
  --z-toast: 50;

  /* ── 动效 ── */
  --dur: 160ms;
  --ease: cubic-bezier(0.2, 0, 0, 1);

  /* ── 字体(§7.3 逐字;不引入 webfont) ── */
  --font: system-ui, "PingFang SC", "Microsoft YaHei", "Noto Sans CJK SC", "Segoe UI", Roboto, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Consolas, "Liberation Mono", monospace;
  --fs: 14px;
  --fs-sm: 12px;
  --fs-xs: 11px;
  --fs-lg: 16px;

  color-scheme: dark;
}

/* ─────────────────────────── reset ─────────────────────────── */

*,
*::before,
*::after { box-sizing: border-box; }

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;                 /* 整页不滚动:面板内部各自滚 */
  overscroll-behavior: none;        /* 移动端下拉不触发浏览器刷新 */
}

body {
  background: var(--bg);
  color: var(--text);
  font: var(--fs) / 1.45 var(--font);
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  text-rendering: optimizeLegibility;
}

h1, h2, h3, h4, p, figure, blockquote, dl, dd { margin: 0; }
ul, ol { margin: 0; padding: 0; list-style: none; }

img, svg, canvas { display: block; max-width: 100%; }

button, input, select, textarea {
  font: inherit;
  color: inherit;
  margin: 0;
}

button {
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
  color: inherit;
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-strong); text-decoration: underline; }

/* ─────────────────────────── 焦点与无障碍 ─────────────────────────── */

:focus { outline: none; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

/* ─────────────────────────── 滚动条 ─────────────────────────── */

* {
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) transparent;
}

*::-webkit-scrollbar { width: 8px; height: 8px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: 4px;
}
*::-webkit-scrollbar-thumb:hover { background: rgba(230, 236, 245, 0.4); }

/* ─────────────────────────── 共用原语 ─────────────────────────── */

/* 浮层容器:图层菜单、模式条、图例、设置、关于都用它当底 */
.a-panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  backdrop-filter: var(--blur);
  -webkit-backdrop-filter: var(--blur);
  color: var(--text);
}

/* 通用按钮:图标按钮与文字按钮共用 */
.a-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--gap-sm);
  min-height: 32px;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  color: var(--text-dim);
  background: transparent;
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}

.a-btn:hover { background: var(--panel-hover); color: var(--text); }
.a-btn:active { background: var(--panel-active); }
.a-btn[aria-pressed="true"],
.a-btn[aria-checked="true"],
.a-btn.is-active {
  background: var(--accent-soft);
  color: var(--accent-strong);
}
.a-btn[disabled],
.a-btn[aria-disabled="true"] {
  color: var(--text-faint);
  cursor: default;
  pointer-events: none;
}

/* 触控档:手机上所有可点控件放大到 44 px(§11.4) */
.a-btn-tap {
  min-width: var(--tap);
  min-height: var(--tap);
}

.a-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 8px;
  border-radius: 999px;
  border: 1px solid var(--border);
  font-size: var(--fs-sm);
  color: var(--text-dim);
  white-space: nowrap;
}

.a-icon {
  width: 20px;
  height: 20px;
  flex: none;
  stroke: currentColor;
  fill: none;
}

/* 图例/标注这类叠在地图上的文字:描边保证对比度(§11.4) */
.a-on-map {
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.85), 0 0 3px rgba(0, 0, 0, 0.7);
}

.a-num { font-variant-numeric: tabular-nums; }

/* ─────────────────────────── 署名行(§13) ─────────────────────────── */

#attribution-link {
  display: inline-block;
  padding: 3px 8px;
  border-radius: var(--radius-sm);
  background: rgba(11, 16, 23, 0.55);
  color: var(--text-dim);
  font-size: var(--fs-xs);
  line-height: 1.4;
  white-space: nowrap;
  transition: color var(--dur) var(--ease), background var(--dur) var(--ease);
}

#attribution-link:hover {
  color: var(--text);
  background: rgba(11, 16, 23, 0.8);
}

/* ─────────────────────────── MapLibre 默认件的收敛 ─────────────────────────── */

.maplibregl-map { font: inherit; }

/* 自带的 attribution / logo 不用:署名由 #attribution 与"关于"页承担(§13) */
.maplibregl-ctrl-attrib,
.maplibregl-ctrl-logo { display: none !important; }

.maplibregl-canvas:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }

/* ─────────────────────────── noscript ─────────────────────────── */

.noscript-note {
  position: fixed;
  inset: auto 0 0 0;
  z-index: var(--z-toast);
  padding: 14px;
  text-align: center;
  background: var(--panel-solid);
  border-top: 1px solid var(--border);
}

/* 中英两行(noscript 里 i18n 跑不起来):去掉 <p> 的默认外边距,行距自己给 */
.noscript-note p {
  margin: 0;
}

.noscript-note p + p {
  margin-top: 6px;
  color: var(--text-dim);
}

/* ─────────────────────────── 减少动效(§11.4) ─────────────────────────── */

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}
