/* ============================================================
   第五人格 · 密码机刷点推导工具 —— Material Design 3 主题
   依赖：src/styles/md3-tokens.css（Dynamic Color Token）
   ============================================================ */

:root {
  /* MD3 语义别名（桥接旧变量名，保持现有规则可用） */
  --bg: var(--md-sys-color-background);
  --bg2: var(--md-sys-color-surface-container-low);
  --panel: var(--md-sys-color-surface-container);
  --panel-border: var(--md-sys-color-outline-variant);
  --gold: var(--md-sys-color-primary);
  --gold-bright: var(--md-sys-color-on-primary-container);
  --text: var(--md-sys-color-on-surface);
  --muted: var(--md-sys-color-on-surface-variant);
  --blood: var(--md-sys-color-error);
  /* 品牌字体（区别于正文，用衬线体） */
  --md-ref-typeface-brand: "Noto Serif SC", "STSong", "SimSun", Georgia, serif;
  /* 动效令牌 */
  --ease-out: cubic-bezier(0.23, 1, 0.32, 1);
  --ease-in-out: cubic-bezier(0.77, 0, 0.175, 1);
  --ease-drawer: cubic-bezier(0.32, 0.72, 0, 1);
  /* 状态层（MD3 State Layer，hover/press 叠加在 on-surface 之上） */
  --state-hover: color-mix(in srgb, var(--md-sys-color-on-surface) 8%, transparent);
  --state-pressed: color-mix(in srgb, var(--md-sys-color-on-surface) 12%, transparent);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }

body {
  background: var(--md-sys-color-background);
  color: var(--md-sys-color-on-surface);
  min-height: 100vh;
  font-family: var(--md-ref-typeface-plain);
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }

/* 全局可见焦点（无障碍） */
:focus-visible {
  outline: 2px solid var(--md-sys-color-primary);
  outline-offset: 2px;
}

/* ============ 整体布局 ============ */
.app {
  position: relative;
  display: flex;
  align-items: stretch;
  height: 100vh;
  min-height: 100vh;
  overflow: hidden;
}

/* ============ 侧边栏（Navigation Drawer，悬浮 Overlay） ============ */
.sidebar {
  position: fixed;
  left: 0;
  top: 0;
  height: 100vh;
  width: min(300px, 85vw);
  z-index: 100;
  background: var(--md-sys-color-surface-container);
  border-radius: 0 var(--md-sys-shape-corner-lg) var(--md-sys-shape-corner-lg) 0;
  box-shadow: var(--md-sys-elevation-level-3);
  transform: translateX(0);
  transition: transform .3s var(--ease-drawer);
}
.sidebar-scroll {
  height: 100%;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  padding: 24px 12px 16px;
}
.sidebar.is-collapsed { transform: translateX(-100%); }

.brand { text-align: center; margin-bottom: 22px; }
.brand-title {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  margin: 0;
  font-family: var(--md-ref-typeface-brand);
  font-size: 20px;
  letter-spacing: 0.06em;
  color: var(--md-sys-color-primary);
}
.brand-icon {
  flex: 0 0 auto;
  width: 32px;
  height: 32px;
  object-fit: contain;
}
.menu-title {
  font-size: 11px; letter-spacing: 0.12em;
  color: var(--md-sys-color-on-surface-variant); margin: 0 16px 8px;
}
.map-menu-list { display: flex; flex-direction: column; gap: 4px; }
.map-item {
  cursor: pointer;
  display: flex;
  align-items: center;
  width: 100%;
  height: 56px;
  padding: 0 16px;
  text-align: left;
  font-size: 14px;
  font-weight: 500;
  color: var(--md-sys-color-on-surface-variant);
  background: transparent;
  border: none;
  border-radius: var(--md-sys-shape-corner-full);
  letter-spacing: 0.04em;
  transition: background .15s ease, color .15s ease;
}
.map-item:hover { background: var(--state-hover); color: var(--md-sys-color-on-surface); }
.map-item:active { background: var(--state-pressed); }
.map-item.active {
  background: var(--md-sys-color-secondary-container);
  color: var(--md-sys-color-on-secondary-container);
  font-weight: 600;
}

.sidebar-foot {
  margin-top: auto;
  font-size: 11px;
  color: var(--md-sys-color-on-surface-variant);
  text-align: center;
  letter-spacing: 0.04em;
  line-height: 1.7;
  padding: 0 12px;
}

/* ============ 主区 ============ */
.main {
  flex: 1 1 auto;
  min-width: 0;
  height: 100vh;
  padding: 16px 16px 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow: hidden;
}

/* 工作区：Canvas（自适应）+ 右侧控制面板（固定宽） */
.workspace {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  gap: 12px;
  align-items: stretch;
}

/* ============ 顶部状态栏（Top App Bar） ============ */
.status-panel {
  display: flex; align-items: center; justify-content: space-between;
  flex-wrap: wrap; gap: 12px;
  margin: -16px -16px 0;
  padding: 12px 20px;
  background: var(--md-sys-color-surface-container);
}
.status-left { display: flex; align-items: center; gap: 8px; }
.status-label { font-size: 14px; color: var(--md-sys-color-on-surface-variant); letter-spacing: 0.04em; }
.status-number {
  font-size: 30px; line-height: 1; font-weight: 700;
  color: var(--md-sys-color-primary);
  min-width: 1.2em; text-align: center;
  transition: color .2s ease;
}
.status-number.locked { color: var(--md-sys-color-tertiary); }
.status-number.conflict { color: var(--md-sys-color-error); }
.status-unit { font-size: 15px; color: var(--md-sys-color-on-surface-variant); }

/* 抽屉拉手：吸附侧边栏右缘，随抽屉 translateX 同步联动 */
.sidebar-toggle {
  cursor: pointer;
  position: absolute;
  right: -28px;
  top: 50%;
  transform: translateY(-50%);
  z-index: 2;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  /* 向左重叠 1px：封死抽屉动画时拉手与侧边栏之间的亚像素缝隙（异常竖线） */
  width: 29px;
  height: 64px;
  padding: 0;
  color: var(--md-sys-color-primary);
  background: var(--md-sys-color-surface-container);
  border: 1px solid var(--md-sys-color-outline-variant);
  border-left: none;
  border-radius: 0 var(--md-sys-shape-corner-full) var(--md-sys-shape-corner-full) 0;
  transition: background .18s ease, color .18s ease, border-color .18s ease, transform .16s var(--ease-out);
}
.sidebar-toggle:hover {
  color: var(--md-sys-color-on-surface);
  background: var(--md-sys-color-surface-container-high);
}
.sidebar-toggle:active { transform: translateY(-50%) scale(0.96); }
.sidebar-toggle:focus-visible {
  outline: 2px solid var(--md-sys-color-primary);
  outline-offset: 2px;
}
.sidebar-toggle svg { display: block; }

/* 抽屉遮罩层 */
.drawer-backdrop {
  position: fixed;
  inset: 0;
  z-index: 90;
  background: var(--md-sys-color-scrim);
  opacity: 0;
  visibility: hidden;
  transition: opacity .3s var(--ease-out), visibility .3s;
}
.drawer-backdrop.show { opacity: 0.5; visibility: visible; }

.status-right {
  display: flex; flex-wrap: wrap;
  gap: 8px; align-items: center;
  margin-left: 0;
  max-width: 100%;
}

/* ---- 按钮：Icon Button ---- */
.icon-btn {
  cursor: pointer;
  width: 40px; height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 18px; line-height: 1;
  color: var(--md-sys-color-on-surface-variant);
  background: transparent;
  border: none;
  border-radius: var(--md-sys-shape-corner-full);
  transition: background .15s ease, color .15s ease;
}
.icon-btn:hover { background: var(--state-hover); color: var(--md-sys-color-on-surface); }
.icon-btn:active { background: var(--state-pressed); }
.icon-btn svg { width: 20px; height: 20px; display: block; }
/* ---- 顶部工具行（快速确认 + 名称标注 + 主题切换） ---- */
.panel-tools {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;      /* 空间不足时控件整体换行（避免标签被压缩换行） */
  gap: 6px;
}

/* ---- 开关（MD3 Switch + 标签） ---- */
.name-toggle {
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  white-space: nowrap;   /* 避免标签文字换行 */
  gap: 8px;
  height: 40px;
  padding: 0 10px 0 12px;
  color: var(--md-sys-color-on-surface-variant);
  background: transparent;
  border: none;
  border-radius: var(--md-sys-shape-corner-full);
  transition: background .15s ease, color .15s ease;
}
.name-toggle:hover { background: var(--state-hover); color: var(--md-sys-color-on-surface); }
.name-toggle:active { background: var(--state-pressed); }
.name-toggle-label { font-size: 13px; font-weight: 500; letter-spacing: .02em; white-space: nowrap; flex: 0 0 auto; }

/* MD3 Switch：轨道 + 手柄 */
.md3-switch {
  position: relative;
  flex: 0 0 auto;
  width: 52px;
  height: 32px;
  border-radius: 16px;
  box-sizing: border-box;
  background: var(--md-sys-color-surface-container-highest);
  border: 2px solid var(--md-sys-color-outline);
  transition: background .2s var(--ease-out), border-color .2s var(--ease-out);
}
.md3-switch-thumb {
  position: absolute;
  top: 50%;
  left: 6px;
  width: 16px;
  height: 16px;
  margin-top: -8px;
  border-radius: 50%;
  background: var(--md-sys-color-outline);
  transition: left .2s var(--ease-out), background .2s var(--ease-out);
}
.name-toggle[aria-checked="true"] .md3-switch {
  background: var(--md-sys-color-primary);
  border-color: var(--md-sys-color-primary);
}
.name-toggle[aria-checked="true"] .md3-switch-thumb {
  left: 26px;
  background: var(--md-sys-color-on-primary);
}

/* ---- 按钮：Outlined Button（重置） ---- */
.reset-btn {
  cursor: pointer;
  height: 40px; padding: 0 24px;
  font-size: 14px; font-weight: 600; letter-spacing: 0.02em;
  color: var(--md-sys-color-primary);
  background: transparent;
  border: 1px solid var(--md-sys-color-outline);
  border-radius: var(--md-sys-shape-corner-full);
  transition: background .15s ease, border-color .15s ease, box-shadow .15s ease;
}
.reset-btn:hover {
  background: color-mix(in srgb, var(--md-sys-color-primary) 8%, transparent);
  border-color: var(--md-sys-color-primary);
}
.reset-btn:active { background: color-mix(in srgb, var(--md-sys-color-primary) 12%, transparent); }
.reset-btn.attention {
  color: var(--md-sys-color-on-error);
  background: var(--md-sys-color-error);
  border-color: var(--md-sys-color-error);
  animation: reset-pulse 1.2s var(--ease-out) infinite;
}
@keyframes reset-pulse {
  0%, 100% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--md-sys-color-error) 45%, transparent); }
  50%      { box-shadow: 0 0 0 10px color-mix(in srgb, var(--md-sys-color-error) 0%, transparent); }
}

/* ---- 按钮：Filled Button（确认布局） ---- */
.confirm-layout-btn {
  cursor: pointer;
  height: 40px; padding: 0 24px;
  font-size: 14px; font-weight: 600; letter-spacing: 0.02em;
  color: var(--md-sys-color-on-surface);
  background: color-mix(in srgb, var(--md-sys-color-on-surface) 12%, transparent);
  border: none;
  border-radius: var(--md-sys-shape-corner-full);
  transition: background .15s ease, color .15s ease, box-shadow .15s ease, opacity .15s ease;
}
.confirm-layout-btn:disabled {
  cursor: not-allowed;
  color: color-mix(in srgb, var(--md-sys-color-on-surface) 38%, transparent);
  background: color-mix(in srgb, var(--md-sys-color-on-surface) 12%, transparent);
  box-shadow: none;
}
.confirm-layout-btn.is-ready {
  color: var(--md-sys-color-on-primary);
  background: var(--md-sys-color-primary);
  box-shadow: var(--md-sys-elevation-level-1);
  opacity: 1;
}
.confirm-layout-btn.is-ready:hover {
  background: color-mix(in srgb, var(--md-sys-color-on-primary) 8%, var(--md-sys-color-primary));
  box-shadow: var(--md-sys-elevation-level-2);
}
.confirm-layout-btn.is-ready:active {
  background: color-mix(in srgb, var(--md-sys-color-on-primary) 12%, var(--md-sys-color-primary));
}
.confirm-layout-btn.is-locked {
  color: var(--md-sys-color-on-tertiary-container);
  background: var(--md-sys-color-tertiary-container);
  opacity: 1;
}

/* ============ 地图画布（Card） ============ */
.map-frame {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  padding: 0;
  border-radius: var(--md-sys-shape-corner-md);
}
.map-wrap {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  overflow: hidden;
  border-radius: var(--md-sys-shape-corner-md);
  background: #0a0907;
}
#mapCanvas {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  display: block;
  cursor: grab;
  touch-action: none;
}
#mapCanvas.dragging { cursor: grabbing; }

.map-title {
  position: absolute; top: 10px; left: 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 28px;
  padding: 0 12px;
  font-size: 12.5px; letter-spacing: 0.06em; line-height: 1;
  color: var(--md-sys-color-on-surface);
  background: var(--md-sys-color-surface-container);
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: var(--md-sys-shape-corner-full);
  pointer-events: none;
  white-space: nowrap;
}
.map-title-icon {
  flex: 0 0 auto;
  width: 16px;
  height: 16px;
  color: var(--md-sys-color-primary);
}

.map-tooltip {
  position: absolute; z-index: 10;
  padding: 8px 12px;
  font-size: 11.5px;
  line-height: 1.65;
  color: var(--md-sys-color-on-surface);
  background: var(--md-sys-color-surface-container-high);
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: var(--md-sys-shape-corner-sm);
  pointer-events: none;
  white-space: normal;
  box-shadow: var(--md-sys-elevation-level-2);
}
.map-tooltip b { color: var(--md-sys-color-primary); }
.map-tooltip .tt-star { color: #4aa8ff; }
.map-tooltip .tt-com { color: #4fb3ff; }
.map-tooltip .tt-exc { color: var(--md-sys-color-error); }
.map-tooltip .tt-grp { color: var(--md-sys-color-on-surface-variant); }

.map-loading {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 15px; letter-spacing: 0.12em;
  color: var(--md-sys-color-on-surface-variant);
  background: var(--md-sys-color-surface-container-low);
  z-index: 20;
  animation: fadePulse 1.2s ease-in-out infinite;
}
@keyframes fadePulse {
  0%, 100% { opacity: 0.55; }
  50% { opacity: 1; }
}

.brush-hint {
  text-align: center;
  font-size: 12.5px; color: var(--md-sys-color-on-surface-variant); letter-spacing: 0.04em;
  transition: color .2s;
  min-height: 20px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.brush-hint.on { color: var(--md-sys-color-primary); }

/* 错误反馈：红色胶囊圈住提示词（最多点亮 5 台上限拦截） */
.brush-hint.warn {
  color: var(--md-sys-color-error);
  border: 1px solid var(--md-sys-color-error);
  border-radius: var(--md-sys-shape-corner-full);
  background: color-mix(in srgb, var(--md-sys-color-error) 8%, transparent);
  width: fit-content;
  margin: 0 auto;
  padding: 4px 16px;
}

/* ============ 右侧控制面板（图例 + 方案） ============ */
.right-panel {
  flex: 0 0 360px;
  min-width: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 16px 12px;
  overflow-y: auto;
  background: var(--md-sys-color-surface-container-low);
}

/* ---- 卡片（Card） ---- */
.panel {
  margin: 0;
  background: var(--md-sys-color-surface-container-highest);
  border-radius: var(--md-sys-shape-corner-md);
  padding: 16px;
}
.panel h2 {
  margin: 0 0 12px;
  font-size: 13px; font-weight: 600; letter-spacing: 0.08em;
  color: var(--md-sys-color-on-surface);
  display: flex; align-items: baseline; justify-content: space-between;
}
.panel-sub { font-size: 10.5px; font-weight: 400; color: var(--md-sys-color-on-surface-variant); letter-spacing: 0.02em; }

/* ---- 图例（Filter Chip） ---- */
.legend { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.legend-item {
  display: flex; align-items: center; gap: 10px;
  height: 56px;   /* ≥48dp 触控目标，并放大密码机图标 */
  width: 100%;
  padding: 0 12px;
  background: transparent;
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: var(--md-sys-shape-corner-sm);
  cursor: pointer; color: var(--md-sys-color-on-surface-variant);
  transition: background .15s ease, border-color .15s ease, opacity .15s ease;
}
.legend-item:hover { background: var(--state-hover); }
.legend-item:active { background: var(--state-pressed); }
.legend-item.brush-active {
  background: var(--md-sys-color-secondary-container);
  border-color: transparent;
  color: var(--md-sys-color-on-secondary-container);
}
.legend-item.is-disabled { opacity: 0.38; cursor: not-allowed; }
.legend-item.is-disabled:hover { background: transparent; }
.legend-item.is-disabled:active { background: transparent; }
.legend-canvas {
  width: 36px; height: 36px; flex: 0 0 36px;
  background: #15130e;                              /* 暗色底座：与地图画布一致，保证状态色在图例与地图上一致可读 */
  border: 1px solid var(--md-sys-color-outline);
  border-radius: 50%;
}
.legend-label { font-size: 11.5px; flex: 1; }
.legend-count {
  font-size: 13px; font-weight: 700;
  color: var(--md-sys-color-primary); min-width: 1em; text-align: right;
}

/* ---- 刷点方案（Card 列表） ---- */
.preset-list { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 12px; }
.preset-chip {
  padding: 10px 12px;
  border-radius: var(--md-sys-shape-corner-sm);
  cursor: pointer;
  transition: background .15s ease, opacity .18s ease;
}
.preset-chip:hover { background: var(--state-hover); }
.preset-chip:active { background: var(--state-pressed); }
.preset-head { display: flex; align-items: baseline; gap: 8px; }
.preset-name { font-size: 13px; font-weight: 600; color: var(--md-sys-color-on-surface); }
.preset-status { margin-top: 2px; font-size: 11px; letter-spacing: 0.03em; display: flex; align-items: center; gap: 4px; }
.preset-status svg { flex: 0 0 auto; }
.preset-status.ok { color: var(--md-sys-color-tertiary); }
.preset-status.no { color: var(--md-sys-color-error); }
.preset-chip.is-filtered { opacity: 0.45; }
.preset-chip.is-locked .preset-name { color: var(--md-sys-color-tertiary); font-weight: 700; }

.app-footer {
  text-align: center;
  font-size: 11.5px; color: var(--md-sys-color-on-surface-variant);
  letter-spacing: 0.04em; line-height: 1.8;
}
.app-footer b { color: var(--md-sys-color-primary); font-weight: 600; }
.footer-actions {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}
.footer-credit {
  margin-top: 10px;
  font-size: 12px;
  color: var(--md-sys-color-on-surface-variant);
}

/* ---- 联动关系图例（只读指标：伴生 / 互斥 / 必刷，不可交互，去发光） ---- */
.linkage-legend {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--md-sys-color-outline-variant);
}
.linkage-title {
  margin-bottom: 10px;
  font-size: 11px;
  letter-spacing: 0.04em;
  color: var(--md-sys-color-on-surface-variant);
}
.linkage-items {
  display: flex;
  flex-wrap: wrap;
  gap: 12px 18px;
}
.linkage-item {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 12.5px;
  color: var(--md-sys-color-on-surface-variant);
  cursor: default;
  user-select: none;
}
.linkage-canvas {
  width: 36px; height: 36px; flex: 0 0 36px;
  background: #15130e;                              /* 暗色底座：与地图画布一致 */
  border: 1px solid var(--md-sys-color-outline);
  border-radius: 50%;
}

/* ============ 输入框（MD3 Text Field，基础样式；当前页面暂无输入框，备用） ============ */
.md3-text-field {
  position: relative;
  display: inline-flex;
  align-items: flex-end;
  min-height: 56px;
  padding: 0 16px;
  background: transparent;
  border: 1px solid var(--md-sys-color-outline);
  border-radius: var(--md-sys-shape-corner-xs);
  transition: border-color .15s ease;
}
.md3-text-field:hover { border-color: var(--md-sys-color-on-surface); }
.md3-text-field:focus-within {
  border-color: var(--md-sys-color-primary);
  outline: 1px solid var(--md-sys-color-primary);
  outline-offset: -1px;
}
.md3-text-field input {
  border: none; outline: none; background: transparent;
  font: inherit; color: var(--md-sys-color-on-surface);
  height: 24px; width: 100%; margin: 24px 0 8px;
}
.md3-text-field .md3-text-field-label {
  position: absolute; left: 16px; top: 16px;
  font-size: 16px; color: var(--md-sys-color-on-surface-variant);
  pointer-events: none;
  transition: all .15s ease;
}
.md3-text-field:focus-within .md3-text-field-label,
.md3-text-field input:not(:placeholder-shown) ~ .md3-text-field-label {
  top: 8px; font-size: 12px;
  color: var(--md-sys-color-primary);
}
.md3-text-field.md3-error { border-color: var(--md-sys-color-error); }
.md3-text-field.md3-error .md3-text-field-label { color: var(--md-sys-color-error); }
.md3-text-field--filled {
  background: var(--md-sys-color-surface-container-highest);
  border-color: transparent;
  border-radius: var(--md-sys-shape-corner-xs) var(--md-sys-shape-corner-xs) 0 0;
  border-bottom: 1px solid var(--md-sys-color-on-surface-variant);
}

/* ============ 响应式 ============ */
@media (max-width: 768px) {
  .app {
    flex-direction: column;
    height: auto;
    min-height: 100vh;
    overflow: visible;
  }
  .main {
    height: auto;
    min-height: 0;
    overflow: visible;
    padding: 12px 10px 20px;
  }
  .map-wrap {
    height: auto;
    flex: 0 0 auto;
    aspect-ratio: var(--map-aspect, 1.165);
  }
  .brush-hint {
    white-space: normal;
    overflow: visible;
  }
  #legendPanel { order: 2; }
  #presetPanel { order: 1; }
  .status-panel { margin: -12px -10px 0; padding: 10px 12px; }
  .right-panel {
    flex: 0 0 auto;
    width: 100%;
    height: auto;
    padding: 12px 10px 84px;
    border-left: none;
    border-top: 1px solid var(--md-sys-color-outline-variant);
    overflow: visible;
  }
  .app-footer {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 40;
    padding: 10px 12px;
    background: var(--md-sys-color-surface-container);
    border-top: 1px solid var(--md-sys-color-outline-variant);
  }
  .app-footer .footer-actions { margin-top: 0; }
}

/* ============ 无障碍：减少动态效果 ============ */
@media (prefers-reduced-motion: reduce) {
  .sidebar, .drawer-backdrop { transition: none; }
  .map-item, .icon-btn, .reset-btn, .legend-item, .preset-chip, .sidebar-toggle, .confirm-layout-btn, .name-toggle, .md3-switch, .md3-switch-thumb {
    transition-duration: 0.01ms;
  }
  .map-item:active, .icon-btn:active, .reset-btn:active, .legend-item:active, .confirm-layout-btn:active {
    background: var(--state-hover);
  }
  .sidebar-toggle:active { transform: translateY(-50%); }
  .confirm-layout-btn.is-ready, .map-loading { animation: none; }
  .reset-btn.attention { animation: none; }
  .tour-spotlight, .tour-popover { transition: none; animation: none; }
  .tour-popover.tour-switching .tour-title,
  .tour-popover.tour-switching .tour-body,
  body.tour-closing .tour-popover,
  body.tour-closing .tour-spotlight { animation: none; }
  .tour-btn, .tour-link { transition-duration: 0.01ms; }
}

/* ============ 新手指引 (Onboarding Tour) ============ */
.tour-blocker {
  position: fixed;
  inset: 0;
  z-index: 9000;
  background: transparent;
  pointer-events: auto;
}
.tour-spotlight {
  position: fixed;
  z-index: 9001;
  border-radius: var(--md-sys-shape-corner-md);
  box-shadow:
    0 0 0 2px var(--md-sys-color-primary),
    0 0 0 100vmax color-mix(in srgb, var(--md-sys-color-scrim) 50%, transparent);
  pointer-events: none;
  transition: left .12s cubic-bezier(0.2, 0, 0, 1), top .12s cubic-bezier(0.2, 0, 0, 1),
              width .12s cubic-bezier(0.2, 0, 0, 1), height .12s cubic-bezier(0.2, 0, 0, 1);
}
.tour-popover {
  position: fixed;
  z-index: 9002;
  width: min(360px, calc(100vw - 24px));
  padding: 16px 18px 14px;
  background: var(--md-sys-color-surface-container-high);
  color: var(--md-sys-color-on-surface);
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: var(--md-sys-shape-corner-lg);
  box-shadow: var(--md-sys-elevation-level-3);
  transition: left .18s var(--ease-out), top .18s var(--ease-out);
}
.tour-blocker, .tour-spotlight, .tour-popover { display: none; }
body.tour-active { overflow: hidden; }

.tour-progress {
  position: absolute;
  top: 12px;
  right: 16px;
  font-size: 12px;
  font-weight: 600;
  color: var(--md-sys-color-primary);
  letter-spacing: 0.08em;
}
.tour-title {
  margin: 0 44px 8px 0;
  font-size: 16px;
  font-weight: 600;
  color: var(--md-sys-color-on-surface);
  letter-spacing: 0.04em;
}
.tour-body {
  font-size: 13px;
  line-height: 1.7;
  color: var(--md-sys-color-on-surface);
}
.tour-line { margin: 2px 0; }
.tour-link {
  display: inline-flex;
  align-items: center;
  height: 40px;
  margin-top: 8px;
  padding: 0 24px;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--md-sys-color-on-primary);
  background: var(--md-sys-color-primary);
  border: none;
  border-radius: var(--md-sys-shape-corner-full);
  text-decoration: none;
  transition: filter .15s ease, box-shadow .15s ease;
}
.tour-link:hover { filter: brightness(1.08); box-shadow: var(--md-sys-elevation-level-1); }
.tour-link:active { filter: brightness(0.96); }

.tour-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 14px;
}
.tour-spacer { flex: 1; }
.tour-btn {
  cursor: pointer;
  height: 40px;
  padding: 0 16px;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--md-sys-color-on-surface-variant);
  background: transparent;
  border: none;
  border-radius: var(--md-sys-shape-corner-full);
  transition: background .15s ease, color .15s ease;
}
.tour-btn:hover { background: var(--state-hover); color: var(--md-sys-color-on-surface); }
.tour-btn:active { background: var(--state-pressed); }
.tour-btn:disabled { opacity: 0.38; cursor: not-allowed; }
.tour-btn.tour-primary {
  color: var(--md-sys-color-on-primary);
  background: var(--md-sys-color-primary);
}
.tour-btn.tour-primary:hover { background: var(--md-sys-color-primary); filter: brightness(1.08); color: var(--md-sys-color-on-primary); }
.tour-btn.tour-primary:active { filter: brightness(0.96); }
.tour-skip { color: var(--md-sys-color-on-surface-variant); }

/* 箭头（CSS 边框三角，随 data-placement 切换方向） */
.tour-arrow {
  position: absolute;
  width: 0; height: 0;
  border: 8px solid transparent;
  pointer-events: none;
}
.tour-popover[data-placement="bottom"] .tour-arrow { top: -15px; border-bottom-color: var(--md-sys-color-surface-container-high); }
.tour-popover[data-placement="top"] .tour-arrow { bottom: -15px; border-top-color: var(--md-sys-color-surface-container-high); }
.tour-popover[data-placement="right"] .tour-arrow { left: -15px; border-right-color: var(--md-sys-color-surface-container-high); }
.tour-popover[data-placement="left"] .tour-arrow { right: -15px; border-left-color: var(--md-sys-color-surface-container-high); }

/* 手动重启指引入口（Text Button） */
.restart-tour-btn {
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 36px;
  padding: 0 16px;
  font-size: 12.5px;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--md-sys-color-primary);
  background: transparent;
  border: none;
  border-radius: var(--md-sys-shape-corner-full);
  text-decoration: none;
  transition: background .15s ease;
}
.restart-tour-btn svg { width: 16px; height: 16px; flex: 0 0 auto; }

/* 首次打开入场动画：气泡平滑落入目标、聚光灯淡入 */
@keyframes tour-pop-in {
  from { opacity: 0; transform: translateY(14px) scale(0.94); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}
@keyframes tour-spot-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}
body.tour-active .tour-popover { animation: tour-pop-in .24s var(--ease-out); }
body.tour-active .tour-spotlight { animation: tour-spot-in .24s var(--ease-out); }

/* 步骤切换：内容切入动画（每次「下一步/上一步」重播） */
@keyframes tour-content-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}
.tour-popover.tour-switching .tour-title,
.tour-popover.tour-switching .tour-body {
  animation: tour-content-in .18s var(--ease-out) .08s backwards;
}

/* 完成/跳过：淡出动画 */
@keyframes tour-pop-out {
  from { opacity: 1; transform: translateY(0) scale(1); }
  to   { opacity: 0; transform: translateY(10px) scale(0.96); }
}
@keyframes tour-spot-out {
  from { opacity: 1; }
  to   { opacity: 0; }
}
body.tour-closing .tour-popover { animation: tour-pop-out .2s var(--ease-out) forwards; }
body.tour-closing .tour-spotlight { animation: tour-spot-out .2s var(--ease-out) forwards; }
.restart-tour-btn:hover { background: color-mix(in srgb, var(--md-sys-color-primary) 8%, transparent); }
