/* Apexcience — 深色赛道主题 */
:root {
  --bg: #0b0e14;
  --bg2: #121722;
  --bg3: #1a2130;
  --line: #232c3d;
  --fg: #e8ecf4;
  --fg-dim: #8b96ab;
  --acc: #e10600;       /* 赛道红 */
  --acc2: #e9ff00;        /* 罗西荧光黄（替换原橘黄） */
  --ok: #27c07d;
  --f1purple: #b955ff;  /* F1 fastest 紫 */
  --warn: #ff5f45;
  --gneg: #ff3b30;      /* 纵向 G 减速色：正红，不用偏橙的 --warn */
  --blue: #4da3ff;
  --radius: 12px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; height: 100%; }
/* ★ iOS 防回弹（v1.9.99）：文档层只声明 overscroll（不再用 html{position:fixed}——
   iOS 上 fixed 根元素旋转时会延迟一拍才更新尺寸，画布重绘量到旧布局、
   随后 CSS 尺寸变化不再触发重绘 → 赛道位图被拉伸变形。防拖拽改在触摸层拦截） */
html { overscroll-behavior: none; }
/* ★ iOS 适配：触摸加固（v1.9.81）——去 300ms 点击延迟、禁长按系统呼出菜单
   （收藏长按进批量模式的必要前提）、按钮文字防误选 */
button, select, input, textarea, a, .fav-dd-item, .log-card, .chip { touch-action: manipulation; -webkit-touch-callout: none; }
button, .fav-dd-item, .log-card { -webkit-user-select: none; user-select: none; }
body {
  background: var(--bg); color: var(--fg);
  font-family: -apple-system, "PingFang SC", "HarmonyOS Sans SC", "Noto Sans SC", "Microsoft YaHei", sans-serif;
  display: flex; flex-direction: column;
  overscroll-behavior: none;
}
#topbar {
  display: flex; align-items: center; gap: 10px;
  /* 左 5px / 右 10px：左侧留白减半让 logo 更靠边，右侧保持按钮与边缘的安全距离 */
  padding: calc(env(safe-area-inset-top, 0px) + 8px) 10px 8px 5px;
  background: var(--bg2); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 20;
}
#brand { display: flex; align-items: center; flex: 1 1 auto; min-width: 0; }
/* 顶栏品牌位用横排 logo（图形 + 字标），高度按顶栏高度放大 */
.brand-logo { height: 34px; width: auto; display: block; }
/* 选中的日志名不再显示：顶栏宽度被 logo 和两个按钮吃掉，长文件名只能截成
   "BJ SDBY 0…"，占位不如留白（当前日志在日志页有高亮，各页标题也有上下文） */
#active-title { display: none; }
.icon-btn { background: none; border: none; color: var(--fg); font-size: 19px; padding: 4px 6px; cursor: pointer; }

#pages { flex: 1; overflow: hidden; display: flex; }
/* .page 不再限制 touch-action（原 pan-y 会沿祖先链与子元素的 pan-x 取交集，导致选圈框内完全无法滚动）；横纵手势由各滚动容器自行声明 */
.page { display: none; flex: 1; overflow-y: auto; padding: 14px 14px 90px; overscroll-behavior: contain; }
.page.active { display: block; }

#tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 30;
  display: flex; background: var(--bg2); border-top: 1px solid var(--line);
  /* v1.9.100：下方安全区条让给 #icp-footer（备案号），无安全区时兜底 16px，按钮永不被盖 */
  padding-bottom: max(env(safe-area-inset-bottom, 0px), 16px);
}
#tabbar button {
  flex: 1; background: none; border: none; color: var(--fg-dim);
  font-size: 20px; padding: 7px 0 5px; cursor: pointer; line-height: 1.2;
}
#tabbar button span { display: block; font-size: 10.5px; margin-top: 2px; }
#tabbar button.active { color: var(--acc2); }

/* 备案页脚（v1.9.100）：沉到屏幕最底——底栏按钮区下方的安全区条内，
   与 tabbar 同底色无缝衔接（看起来是底栏的延伸），不新增空白；
   无安全区环境（老机型/Safari 工具栏模式）兜底 16px，tabbar 同步抬高避免按钮被盖；
   横屏为右下角悬浮胶囊（tabbar 是左侧栏） */
#icp-footer {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 31;
  height: max(env(safe-area-inset-bottom, 0px), 16px);
  display: flex; align-items: center; justify-content: center;
  text-align: center; font-size: 10px; line-height: 12px;
  background: var(--bg2);
}
#icp-footer a { color: #8a93a6; text-decoration: none; }
/* base 声明了 display，会盖掉 [hidden] 的 UA 样式 → 显式恢复，保证 APK/file:// 环境不渲染 */
#icp-footer[hidden] { display: none; }
@media (orientation: landscape) and (min-height: 260px) {
  #icp-footer {
    height: auto; display: block; left: auto;
    position: fixed; right: 10px; bottom: 6px; margin: 0; padding: 3px 10px;
    background: rgba(11, 14, 20, .78); border: 1px solid var(--line); border-radius: 999px;
    font-size: 10px; line-height: 1.4;
    z-index: 45; backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  }
}

/* ---------- 通用 ---------- */
h2 { margin: 4px 0 10px; font-size: 19px; }
h3 { margin: 0; font-size: 15px; }
h3 small { color: var(--fg-dim); font-weight: 400; font-size: 11px; margin-left: 6px; }
.page-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.actions.wrap { margin-top: 6px; }
.btn {
  background: var(--bg3); color: var(--fg); border: 1px solid var(--line);
  border-radius: 10px; padding: 9px 14px; font-size: 13.5px; cursor: pointer;
}
.btn.primary { background: var(--acc); border-color: var(--acc); color: #fff; font-weight: 600; }
.btn.ghost { background: transparent; }
.btn.tiny { padding: 5px 10px; font-size: 12px; border-radius: 8px; }
.btn.danger { border-color: #5b2019; color: var(--warn); }
.btn.icon { font-size: 15px; min-width: 44px; }
.btn:active { transform: scale(.96); }
.hint { color: var(--fg-dim); font-size: 11.5px; margin: 8px 0; line-height: 1.6; }
.empty { color: var(--fg-dim); text-align: center; padding: 60px 20px; font-size: 14px; }
/* ★ v1.9.88：横屏 #log-list 是多列 grid，空状态作为子项只占第一列导致"暂无日志"
   偏左不居中——跨满整行（非 grid 容器下此属性无效，竖屏不受影响） */
.empty { grid-column: 1 / -1; }

.block {
  background: var(--bg2); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px; margin: 14px 0;
}
.block-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }

/* ---------- 日志列表 ---------- */
.log-list { display: flex; flex-direction: column; gap: 10px; }
.log-card {
  background: var(--bg2); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px; display: flex; gap: 12px; align-items: center; cursor: pointer;
}
/* ===== 左滑删除容器 =====
   卡片本身不裁剪（阴影/圆角保持原样），由外层 .swipe-item 裁切并垫红色按钮。
   touch-action: pan-y 让纵向滚动交给浏览器、横向手势才给 JS。 */
.swipe-item { position: relative; border-radius: var(--radius); overflow: hidden; }
/* 圆角裁剪：卡片自身是 12px 圆角，右上/右下两个角外会漏出底部红色按钮，
   形成一条暗红边——按同样半径裁掉，闭合时完全看不见。 */
/* 宽度 = 露出 84 + 垫到卡片圆角下 12：卡片保持完整圆角，圆角缺口由红色填满，
   两者交界处不会露出月牙形的页面背景。 */
.swipe-act {
  position: absolute; top: 0; right: 0; bottom: 0; width: 96px; display: flex;
  border-radius: 0 var(--radius) var(--radius) 0; overflow: hidden;
  /* 闭合时完全隐藏：否则卡片圆角外会露出红边 */
  opacity: 0; transition: opacity .12s ease;
}
.swipe-item.open .swipe-act, .swipe-item.dragging .swipe-act { opacity: 1; }
.swipe-del {
  flex: 1; width: 100%; border: 0; border-radius: 0; padding: 0 0 0 12px;   /* 左侧 12px 藏在卡片圆角下 */
  background: var(--acc); color: #fff; font-size: 13.5px; font-weight: 700;
  letter-spacing: .5px; font-family: inherit; cursor: pointer;
  touch-action: manipulation;   /* 去掉移动端 300ms 双击缩放等待，点击更跟手 */
}
.swipe-del:active { background: #c00500; }
.swipe-item .log-card { position: relative; z-index: 1; touch-action: pan-y; will-change: transform; }

/* 选中/激活高亮改用内嵌环：卡片外层 .swipe-item 有 overflow:hidden，
   外发光（box-shadow 0 0 0 2px）会被裁掉上下两条，只剩左右——看起来像"边框消失"。 */
.log-card.active { border-color: var(--acc2); box-shadow: inset 0 0 0 1px var(--acc2); }
.log-card.selected {
  border-color: var(--acc2); box-shadow: inset 0 0 0 1px var(--acc2);
  /* 底色单独给一层：渐变两端是带 alpha 的，只有渐变时卡片右侧是半透明的，
     底下红色会透上来染成一层红雾。 */
  background-color: var(--bg2);
  background-image: linear-gradient(90deg, rgba(233,255,0,.12), rgba(18,23,34,0));
}
.log-card .badge {
  min-width: 44px; height: 44px; border-radius: 10px; background: var(--bg3);
  display: flex; align-items: center; justify-content: center; font-size: 21px;
}
.log-card .info { flex: 1; min-width: 0; }
.log-card .name { font-size: 13.5px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
/* 每个 meta 行强制单行：卡片固定 4 行（名称 + 3 行信息），长文本用省略号截断，
   避免长赛道名把行撑成两行导致卡片高度不齐 */
.log-card .meta {
  color: var(--fg-dim); font-size: 11.5px; margin-top: 3px;
  display: flex; gap: 10px; flex-wrap: nowrap; min-width: 0; overflow: hidden;
}
.log-card .meta > span { white-space: nowrap; }
.log-card .meta > span:first-child { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.log-card .meta > span:not(:first-child) { flex: none; }
/* 两列三行图标网格（左列：收藏/重命名/删除，右列：保存/分享）。
   行高/间距复刻旧版单列节奏（按钮 ~23px + 6px 间距），卡片高度不变 */
.log-card .ops { display: grid; grid-template-columns: repeat(2, 23px); grid-auto-rows: 23px; gap: 6px 6px; align-content: start; flex: none; }
.log-card .ops button { background: none; border: none; color: var(--fg-dim); padding: 0; width: 23px; height: 23px; cursor: pointer; flex: none; display: inline-flex; align-items: center; justify-content: center; }
.log-card .ops button svg { width: 18px; height: 18px; display: block; }
.log-card .ops button:active { transform: scale(.88); }

/* ---------- 卡片与表格 ---------- */
.cards { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.card { background: var(--bg2); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px; text-align: center; }
.card .v { font-size: 17px; font-weight: 700; color: var(--acc2); white-space: nowrap; }
.card .k { font-size: 10.5px; color: var(--fg-dim); margin-top: 3px; }
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; touch-action: pan-x pan-y; }
.page { -webkit-overflow-scrolling: touch; }   /* WebView 惯性滚动 */
.table-wrap .data-table th { position: static; } /* sticky 表头在移动端阻碍横向拖动 */
.data-table { border-collapse: collapse; width: 100%; font-size: 12.5px; min-width: 480px; }
.data-table.small { font-size: 11.5px; min-width: 380px; }
.data-table.compact { min-width: 0; }
.data-table.compact th, .data-table.compact td { padding: 5px 6px; }
.data-table th, .data-table td { padding: 6px 8px; text-align: right; border-bottom: 1px solid var(--line); white-space: nowrap; }
.data-table th { color: var(--fg-dim); font-weight: 500; font-size: 11px; position: sticky; top: 0; background: var(--bg2); }
.data-table td:first-child, .data-table th:first-child { text-align: left; }
/* ★ v1.9.50：最快圈/最快段统一紫色 = 选圈模块同款 --f1purple；分段差距用灰色小字 */
.data-table tr.best td { color: var(--f1purple); font-weight: 700; }
.data-table td.seg-best { color: var(--f1purple); font-weight: 700; }
/* ★ v1.9.50：分段报告时间列全部左对齐（最快段时间与其他时间对齐） */
#sector-table th, #sector-table td { text-align: left; }
.data-table td small, .data-table td .seg-gap { color: #8a8fa0; font-weight: 400; }
.data-table td.seg-loss { color: var(--warn); }
.lap-chip { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }
.data-table input[type=checkbox] { width: 16px; height: 16px; accent-color: var(--acc); }

/* ---------- 地图 ---------- */
.map-toolbar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.map-toolbar > * { height: 36px; }   /* 工具栏所有控件统一高度 */
.map-toolbar .chip-select { height: 36px; }
.map-toolbar .toggle { height: 36px; }
.map-toolbar .btn.tiny { height: 36px; }
.map-toolbar .hint { height: auto; align-self: center; }
.chip-select {
  background: var(--bg3); color: var(--fg); border: 1px solid var(--line);
  border-radius: 8px; padding: 6px 8px; font-size: 12.5px;
}
.toggle { display: flex; align-items: center; gap: 5px; font-size: 12.5px; color: var(--fg-dim); }
.toggle input { accent-color: var(--acc); }
#map-holder { position: relative; height: 52vh; min-height: 300px; background: var(--bg2); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
#map-canvas, #track-holder canvas, #chart-holder canvas { width: 100%; height: 100%; display: block; touch-action: none; }
#map-canvas, #map-chart-canvas { background: #0e1118; }   /* 底色改用 CSS，省每帧 fillRect */
/* 地图页图表：必须自己接管触摸，否则右侧滚动容器会抢走双指手势（缩放/平移失效） */
#map-chart-canvas { touch-action: none; }
#track-holder { position: relative; height: 46vh; min-height: 260px; background: var(--bg2); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
#chart-holder { position: relative; height: 50vh; min-height: 280px; background: var(--bg2); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
#map-legend, #chart-legend {
  position: absolute; right: 8px; top: 8px; background: rgba(11,14,20,.78);
  border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; font-size: 10px;
  display: flex; align-items: center; gap: 6px; pointer-events: none;
}
#map-legend .bar { width: 80px; height: 8px; border-radius: 4px; }
#point-card {
  position: absolute; left: 8px; bottom: 8px; background: rgba(11,14,20,.88);
  border: 1px solid var(--line); border-radius: 10px; padding: 5px 9px; font-size: 11.5px;
  max-width: 78%; line-height: 1.5;
}
#point-card b { color: var(--acc2); }
#point-card .row { display: flex; gap: 9px; margin-top: 2px; flex-wrap: wrap; align-items: center; }
#point-card .dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; flex: none; }

/* ---------- 回放 ---------- */
#replay-panel { background: var(--bg2); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px; margin-top: 10px; }

/* 回放进度条：自绘触摸条（全区域可点可拖，44px 触摸区） */
#seek-bar { flex: 1 1 auto; min-width: 0; height: 44px; display: flex; align-items: center; touch-action: none; margin: 4px 0 2px; }
.replay-row2 #replay-speed { flex: 0 0 auto; width: 62px; }   /* 够显示数字即可 */
#seek-track {
  position: relative; width: 100%; height: 6px; border-radius: 3px;
  background: var(--bg3); border: 1px solid var(--line); cursor: pointer;
}
#seek-fill {
  position: absolute; left: 0; top: 0; bottom: 0; width: 0%;
  border-radius: 3px; background: var(--acc2); opacity: .55;
}
#seek-thumb {
  position: absolute; top: 50%; left: 0%;
  width: 26px; height: 26px; border-radius: 50%;
  background: var(--acc2); border: 3px solid #fff;
  transform: translate(-50%, -50%);
  box-shadow: 0 1px 4px rgba(0,0,0,.4); pointer-events: none;
}
.readout { display: flex; gap: 14px; flex-wrap: wrap; font-size: 13px; margin-top: 6px; }
#chart-readout { display: flex; flex-direction: column; gap: 2px; font-size: 12.5px; }
.readout b { color: var(--acc2); font-variant-numeric: tabular-nums; }

/* ---------- 赛道编辑 ---------- */
.track-name { font-size: 14px; font-weight: 600; }
.shift-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; max-width: 420px; }
.mini-actions { display: flex; gap: 6px; }

/* ---------- 自适应回放面板 ---------- */
/* ★ v1.9.51：固定布局——取消按钮出现/消失不引起重排错位；
   此处对齐位置恒定（播放右侧），跟随镜头恒定最右（横竖屏一致） */
.replay-row1 {
  display: flex; align-items: center; gap: clamp(6px, 2vw, 14px);
  justify-content: flex-start; flex-wrap: nowrap;
}
.replay-row1 .toggle { margin-left: auto; }
.replay-row1 .toggle span { white-space: nowrap; font-size: clamp(11px, 2.8vw, 13px); }
.replay-row1 select { max-width: 100%; font-size: clamp(11px, 2.8vw, 13px); }
/* ★ v1.9.50：与顶部「按时间」等控件统一 36px 高 */
.replay-row1 .btn.icon {
  width: 44px; min-width: 44px; max-width: 44px; flex: none;
  height: 36px; padding: 0; line-height: 34px; font-size: 15px; text-align: center;
  display: inline-flex; align-items: center; justify-content: center;
}
.replay-row1 .btn.tiny { height: 36px; padding: 6px 12px; font-size: 12.5px; touch-action: manipulation; }
.replay-row1 .toggle span { font-size: 12.5px; }
.replay-row2 {
  display: flex; align-items: center; gap: 6px; margin-top: 8px; min-height: 26px;
  flex-wrap: wrap;
  max-width: 100%;
}
.replay-row2 .chip-select { font-size: 12px; padding: 6px 8px; height: 36px; }
/* 单日志分析：下拉独占一行（长文件名不被标题挤压） */
.solo-select { width: 100%; max-width: 100%; font-size: 13px; }
.replay-row2 .btn.tiny { height: 36px; padding: 6px 12px; font-size: 12.5px; touch-action: manipulation; }
.replay-row2 .hint { font-size: 10.5px; }

/* 平板 */
@media (min-width: 600px) {
  .replay-row1 { grid-template-columns: 52px 110px 120px 150px; justify-content: start; gap: 14px; }
  /* ★ v1.9.84：面板必须随地图全宽——原 max-width:720 + margin:auto 在 #map-side
     （flex 列）里触发 auto-margin 收缩：flex 子项有 auto 边距时放弃 stretch，
     收缩到内容宽度并居中，平板宽视口下控制框变得又窄又居中（横屏 845 行
     早已用 margin:0 + width:100% 修过同类问题，竖屏断点漏了） */
  #replay-panel { max-width: none; margin: 10px 0 0; }
  .map-toolbar { max-width: none; }
}

/* 大屏（平板宽视口）：控件与读数同步放大，保持触控舒适 */
@media (min-width: 900px) {
  #replay-panel { padding: 14px 16px; }
  #seek-bar { height: 48px; }
  .replay-row1 .btn.tiny, .replay-row2 .btn.tiny { height: 40px; padding: 8px 14px; font-size: 13.5px; }
  .replay-row1 .btn.icon { width: 50px; min-width: 50px; max-width: 50px; }
  .replay-row1 .toggle span { font-size: 14px; }
  .replay-row2 .chip-select { height: 40px; font-size: 13.5px; }
  .replay-row2 #replay-speed { width: 76px; }
  #replay-readout .cmp-row { font-size: 14px; grid-template-columns: 12px 96px 72px 1fr auto; gap: 10px; }
  #align-offset-info { font-size: 12px; }
}

/* ---------- 回放读数（表格化对齐） ---------- */
/* ★ v1.9.49：数据框（readout）第一行右侧显示秒差（黄字）；进度条/速度同行 */
#readout-wrap { position: relative; margin-top: 6px; }
#align-offset-info {
  position: absolute; top: 0; right: 0; z-index: 2;
  max-width: 62%; text-align: right; color: var(--acc2); font-size: 11px; line-height: 1.5;
}
#replay-readout { display: flex; flex-direction: column; gap: 2px; }
/* ★ v1.9.65：5 列（末列 auto=「完」标记）——此前 4 列 grid 在进度到末尾时
   「完」作为第 5 个子项被挤到隐式第二行（横屏右栏尤其明显） */
.readout .cmp-row { display: grid; grid-template-columns: 12px 76px 58px 1fr auto; align-items: center; gap: 8px; font-size: 12.5px; white-space: nowrap; }
.readout .cmp-row .dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
.readout .cmp-row .t { font-variant-numeric: tabular-nums; color: var(--fg-dim); }
.readout .cmp-row .done { color: var(--fg-dim); font-size: 11px; }

#align-offset-info { color: var(--acc2); }

/* ---------- 按日志分列的圈速选择 ---------- */
.log-columns {
  display: flex; gap: 10px;
  overflow-y: auto; overflow-x: hidden;  /* ≤3列：禁横向滚动，列平分屏宽，绝无多余右滑 */
  -webkit-overflow-scrolling: touch;
  max-height: 40vh;            /* 限高：圈多时框内纵向滚动，不再占满整屏 */
  overscroll-behavior: auto;   /* 滚到顶/底后继续滑，交给页面滚动（不要 contain） */
  touch-action: pan-y;         /* 纵滑=框内列表（列不多时无横向可滚） */
  padding: 0 0 6px;            /* 顶部无 padding：避免滚动内容从吸附列头上缘露出 */
}
.log-columns.many {            /* ≥4列：启用横向滚动 */
  overflow-x: auto;
  touch-action: pan-x pan-y;
}
.log-col { flex: 1 1 0; min-width: 0; }   /* min-width 0：窄屏也强制平分，不产生溢出 */
.log-columns.many .log-col {
  /* 列宽 = 容器一半（与 2 列平分时完全一致）：初始只见前两列，第 3+ 列右滑查看 */
  flex: 0 0 calc(50% - 5px); width: calc(50% - 5px); min-width: 0; max-width: calc(50% - 5px);
}
.log-col .col-head {
  position: sticky; top: 0; z-index: 2;       /* 框内下拉时固定日志名，只滚圈列表 */
  background: var(--bg2);
  display: flex; align-items: center; gap: 6px; font-size: 12.5px; font-weight: 600;
  color: var(--fg-dim); padding: 4px 2px 8px; border-bottom: 1px solid var(--line);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.log-col .col-head .chip { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.lap-item {
  display: flex; align-items: center; gap: 8px; padding: 5px 8px; margin-top: 4px;
  background: var(--bg3); border: 1px solid var(--line); border-radius: 9px;
  cursor: pointer; user-select: none; font-size: 12.5px; white-space: nowrap;
}
.lap-item.on { border-color: var(--acc2); box-shadow: 0 0 0 1px var(--acc2); }
.lap-item .t { font-variant-numeric: tabular-nums; margin-left: auto; color: var(--fg-dim); }
.lap-item.on .t { color: var(--acc2); font-weight: 700; }
.lap-item .cb { accent-color: var(--acc); width: 16px; height: 16px; flex: none; }

/* ---------- F1 风格最快值（紫）与理想圈（绿） ---------- */
.data-table td.f1-fastest { color: var(--f1purple); font-weight: 400; }
.data-table th.ideal-col { color: var(--ok); }

/* ---------- 横向滚动时左侧标识列固定（对比分析·段 / 单圈报告·圈 / 分段报告·圈） ---------- */
.data-table th:first-child, .data-table td:first-child {
  position: sticky; left: 0; background: var(--bg2); z-index: 2;
}
.data-table th:first-child { z-index: 3; }
/* 单圈报告：checkbox + 圈号两列一起固定（圈号列 left = 首列定宽） */
#lap-table th:first-child, #lap-table td:first-child { width: 34px; min-width: 34px; }
#lap-table th:nth-child(2), #lap-table td:nth-child(2) {
  position: sticky; left: 34px; background: var(--bg2); z-index: 2;
}
#lap-table th:nth-child(2) { z-index: 3; }
/* 对比分析表：内容自适应，圈少时无横向滚动（原 min-width:480px 强制撑宽） */
#cross-compare-table { min-width: 0; }

/* ---------- 收藏夹（持久库，点击载入） ---------- */
.fav-bar {
  display: flex; align-items: center; gap: 6px; flex-wrap: wrap;
  background: var(--bg3); border: 1px solid var(--line); border-radius: 10px;
  padding: 8px 10px; margin: 10px 0;
}
.fav-bar .cmp-title { font-size: 12px; color: var(--acc2); font-weight: 600; white-space: nowrap; }
.fav-bar .cmp-item {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--bg2); border: 1px solid var(--line); border-radius: 8px;
  padding: 5px 9px; font-size: 12px; cursor: pointer; user-select: none;
}
.fav-bar .cmp-item:active { border-color: var(--acc2); }
.fav-bar .cmp-item.fav-loaded { border-color: var(--ok); }
.fav-bar .fav-row { display: flex; align-items: center; gap: 8px; width: 100%; }
.fav-bar .fav-row .chip-select { flex: 1; min-width: 0; height: 30px; font-size: 11.5px; padding: 3px 8px; }
/* 已收藏的日志卡：星标橘黄（SVG 填充） */
.log-card .ops button.faved { color: var(--acc2); }
.log-card .ops button.faved svg { fill: currentColor; }

/* ---------- 内联对比指示 ---------- */
.cmp-inline { display: flex; align-items: center; gap: 5px; flex-wrap: wrap; }
.cmp-inline .ci { display: inline-flex; align-items: center; gap: 4px; font-size: 11px; background: var(--bg3); border-radius: 6px; padding: 2px 7px; }
.cmp-inline .ci i { width: 9px; height: 9px; border-radius: 3px; display: inline-block; }
.cmp-inline .clear { color: var(--fg-dim); font-size: 11px; cursor: pointer; border: none; background: none; }

/* ---------- 对比条 ---------- */
.compare-bar {
  background: var(--bg2); border: 1px solid var(--acc2); border-radius: var(--radius);
  padding: 9px 12px; margin-bottom: 10px; font-size: 12.5px;
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
}
.compare-bar .cmp-item { display: flex; align-items: center; gap: 5px; background: var(--bg3); border-radius: 8px; padding: 4px 8px; }
.compare-bar .cmp-item i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.compare-bar .cmp-title { color: var(--acc2); font-weight: 600; }
.compare-bar .spacer { flex: 1; }
.compare-bar .hint { margin: 0; }

/* ---------- 设备 ---------- */
.usb-status { font-size: 13px; margin: 10px 0; color: var(--fg-dim); }
.usb-status.ok { color: var(--ok); }
.usb-status.err { color: var(--warn); }
.console {
  background: #05070b; border: 1px solid var(--line); border-radius: 10px;
  height: 240px; overflow-y: auto; padding: 10px; font-size: 11px; line-height: 1.55;
  font-family: ui-monospace, Menlo, Consolas, monospace; color: #9fe8b8; white-space: pre-wrap; word-break: break-all; margin: 0;
}
#proto-table td { text-align: left !important; }

/* ---------- 设置浮层 ---------- */
#settings-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.55); z-index: 50;
  display: flex; align-items: flex-end; justify-content: center;
}
#settings-overlay[hidden] { display: none; }
/* 屏幕几何诊断浮层：复用设置卡片视觉 */
#screen-info-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.55); z-index: 50;
  display: flex; align-items: flex-end; justify-content: center;
}
#screen-info-overlay[hidden] { display: none; }
.settings-card {
  background: var(--bg2); border-radius: 18px 18px 0 0; width: 100%; max-width: 560px;
  padding: 16px 16px calc(env(safe-area-inset-bottom, 0px) + 24px);
  max-height: 80vh; overflow-y: auto;
}
.setting-row { display: flex; align-items: center; justify-content: space-between; padding: 12px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.setting-row select { background: var(--bg3); color: var(--fg); border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; }
.switch { position: relative; display: inline-block; width: 46px; height: 26px; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch i { position: absolute; inset: 0; background: var(--bg3); border: 1px solid var(--line); border-radius: 14px; transition: .18s; }
.switch i::before { content: ""; position: absolute; width: 20px; height: 20px; left: 2px; top: 2px; border-radius: 50%; background: var(--fg-dim); transition: .18s; }
.switch input:checked + i { background: var(--acc2); border-color: var(--acc2); }  /* 罗西荧光黄，与主题统一 */
.switch input:checked + i::before { transform: translateX(20px); background: var(--bg3); box-shadow: 0 1px 3px rgba(0,0,0,.35); }  /* 深色圆点：荧光黄上对比最强，且不引入新色相 */
.about { color: var(--fg-dim); font-size: 11.5px; line-height: 1.8; margin-top: 14px; }

@media (min-width: 700px) {
  .cards { grid-template-columns: repeat(6, 1fr); }
  #map-holder { height: 62vh; }
}

/* ---------- 收藏夹 log 自定义下拉（每项可删除） ---------- */
.fav-dd { position: relative; flex: 1; min-width: 0; }
.fav-dd-trigger {
  background: var(--bg3); border: 1px solid var(--line); border-radius: 8px;
  color: var(--fg); font-size: 12px; padding: 6px 10px; cursor: pointer;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.fav-dd-trigger::after { content: " ▾"; color: var(--fg-dim); }
.fav-dd-panel {
  position: absolute; left: 0; right: 0; top: calc(100% + 4px); z-index: 50;
  background: var(--bg2); border: 1px solid var(--line); border-radius: 10px;
  max-height: 46vh; overflow-y: auto; box-shadow: 0 8px 24px rgba(0,0,0,.5);
}
.fav-dd-item {
  display: flex; align-items: center; gap: 8px; padding: 10px 12px;
  font-size: 12.5px; cursor: pointer; border-bottom: 1px solid var(--line);
}
.fav-dd-item:last-child { border-bottom: none; }
.fav-dd-item:active { background: var(--bg3); }
.fav-dd-item.loaded { color: var(--ok); }
.fav-dd-name { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.fav-dd-check { color: var(--ok); flex: none; }
.fav-dd-del, .fav-dd-ren {
  background: none; border: 1px solid var(--line); border-radius: 7px;
  color: var(--fg-dim); width: 26px; height: 26px; flex: none;
  font-size: 12px; cursor: pointer; line-height: 1;
  font-variant-emoji: text; -webkit-appearance: none; appearance: none;
}
/* 悬停高亮只在鼠标设备生效：触屏上 :hover 会"粘住"，点完铅笔一直红着 */
@media (hover: hover) and (pointer: fine) {
  .fav-dd-del:hover { color: var(--warn); border-color: var(--warn); }
  .fav-dd-ren:hover { color: var(--acc); border-color: var(--acc); }
}
/* 触屏：只在按下瞬间反馈，松开即恢复 */
.fav-dd-del:active { color: var(--warn); border-color: var(--warn); }
.fav-dd-ren:active { color: var(--acc); border-color: var(--acc); }
.fav-dd-del:focus, .fav-dd-ren:focus { outline: none; }

.fav-dd-count { color: var(--fg-dim); font-size: 11px; flex: none; }
.fav-dd-item.active { color: var(--ok); }
.fav-dd-item.active .fav-dd-name { font-weight: 700; }

/* ===== 设备直连卡（日志页，收藏夹上方）===== */
.dev-bar { margin: 10px 0 0; }
.dev-row { display: flex; align-items: center; gap: 8px; width: 100%; }
.dev-read-btn {
  height: 30px; padding: 0 14px; font-size: 12px; font-weight: 700;
  border-radius: 8px; border: none; color: #fff; white-space: nowrap;
  background: #b03a2e; transition: background .2s;
}
.dev-read-btn.reading { background: #8a6d1a; }
.dev-read-btn.ready { background: #2e7d32; }
.dev-read-btn:active { opacity: .8; }
.dev-bar .fav-dd-item .dev-dl-state { color: var(--fg-dim); font-size: 11px; margin-left: auto; white-space: nowrap; }

/* ===== 下载进度环（设备 log 条目最右侧）===== */
.dl-ring { width: 20px; height: 20px; flex: none; display: inline-flex; align-items: center; }
.dl-ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.dl-ring .trk { stroke: var(--bg3); }
.dl-ring .prg { stroke: var(--acc2); transition: stroke-dashoffset .18s linear; }
.dl-ring.indet svg { animation: dlring-spin .9s linear infinite; }
.dl-ring.indet .prg { transition: none; }
@keyframes dlring-spin { from { transform: rotate(-90deg); } to { transform: rotate(270deg); } }

/* ===== 统一线条图标（与日志卡片同风格）===== */
.ico { display: inline-flex; align-items: center; justify-content: center; }
.ico svg { display: block; width: 18px; height: 18px; }
#tabbar .ico svg { width: 22px; height: 22px; }
#topbar .icon-btn .ico svg { width: 21px; height: 21px; }
.ico.inline { vertical-align: -3px; margin: 0 1px; }
.ico.inline svg { width: 13px; height: 13px; }
.btn .ico svg { width: 16px; height: 16px; }
.icon-btn { display: inline-flex; align-items: center; justify-content: center; border-radius: 9px; line-height: 1; }
.icon-btn:active { background: var(--bg3); }

/* ===== 顶栏右上角菜单 ===== */
.top-actions { display: flex; align-items: center; gap: 2px; }
.menu {
  position: fixed; top: auto; right: 10px; bottom: auto; min-width: 186px;
  background: var(--bg3); border: 1px solid var(--line); border-radius: 12px;
  padding: 6px; box-shadow: 0 12px 30px rgba(0,0,0,.5); z-index: 60;
}
.menu button {
  display: flex; align-items: center; gap: 10px; width: 100%;
  background: none; border: none; color: var(--fg); text-align: left;
  padding: 11px 12px; border-radius: 8px; font-size: 14px; cursor: pointer;
}
.menu button:active { background: var(--line); }
.menu .ico svg { width: 18px; height: 18px; color: var(--fg-dim); }

/* ===== 排行榜 ===== */
.rank-list { display: flex; flex-direction: column; gap: 9px; }
.rank-track-title {
  display: flex; align-items: center; gap: 10px;
  color: var(--fg-dim); font-size: 12px; margin: 16px 2px 3px;
}
.rank-track-title::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.lb-row {
  display: flex; align-items: center; gap: 12px;
  background: var(--bg2); border: 1px solid var(--line); border-radius: 12px;
  padding: 12px 14px; cursor: pointer;
}
.lb-row:active { background: var(--bg3); }
.lb-rank {
  width: 30px; height: 30px; flex: none; border-radius: 9px;
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 14px; color: var(--fg-dim); background: var(--bg3);
  font-variant-numeric: tabular-nums;
}
.lb-row.top1 .lb-rank { background: var(--acc2); color: #1a1200; }
.lb-row.top2 .lb-rank { background: #b9c2cf; color: #12161d; }
.lb-row.top3 .lb-rank { background: #b87333; color: #fff; }
.lb-main { flex: 1; min-width: 0; }
.lb-time { font-size: 19px; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: .3px; }
.lb-sub { color: var(--fg-dim); font-size: 11.5px; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lb-side { text-align: right; flex: none; }
.lb-side b { font-size: 13px; font-variant-numeric: tabular-nums; }
.lb-side span { display: block; color: var(--fg-dim); font-size: 10.5px; margin-top: 2px; }

/* 卡片徽标/元信息里的图标 */
.log-card .badge .ico svg { width: 22px; height: 22px; }
.log-card .meta .mi { display: inline-flex; align-items: center; gap: 3px; }
.log-card .meta .mi .ico svg { width: 12px; height: 12px; }

/* data-ico 兜底尺寸（HTML 里直接写 <i data-ico>，不一定带 .ico 类） */
[data-ico] { display: inline-flex; align-items: center; justify-content: center; flex: none; }
[data-ico] svg { display: block; width: 18px; height: 18px; }
#tabbar [data-ico] svg { width: 22px; height: 22px; }
#topbar [data-ico] svg { width: 21px; height: 21px; }
.btn [data-ico] svg { width: 16px; height: 16px; }
.menu [data-ico] svg { width: 18px; height: 18px; color: var(--fg-dim); }
.ico.inline svg, [data-ico].inline svg { width: 13px; height: 13px; }
.log-card .meta .mi [data-ico] svg { width: 12px; height: 12px; }

/* 设备读取按钮 / 下拉勾选标记里的图标尺寸 */
.dev-read-btn .ico svg, .dev-read-btn svg { width: 14px; height: 14px; vertical-align: -2px; }
.fav-dd-check svg { width: 13px; height: 13px; }
.fav-dd-del svg { width: 13px; height: 13px; }

/* 回放读数的时间行：独占一行（.cmp-row 是 4 列 grid，塞进去会被压成 12px 宽） */
.readout .ts-row { flex: 1 0 100%; font-size: 12.5px; }

/* ===== 编辑日志弹层 ===== */
#edit-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.62); z-index: 80;
  display: flex; align-items: flex-end; justify-content: center;
}
#edit-overlay[hidden] { display: none; }
.edit-card {
  width: 100%; max-width: 540px; background: var(--bg2);
  border: 1px solid var(--line); border-radius: 18px 18px 0 0;
  padding: 16px 16px calc(env(safe-area-inset-bottom, 0px) + 18px);
}
.edit-row { margin: 14px 0; }
.edit-row > label { display: block; font-size: 12px; color: var(--fg-dim); margin-bottom: 7px; }
.edit-row > input, .combo input {
  width: 100%; height: 44px; background: var(--bg3); border: 1px solid var(--line);
  border-radius: 11px; color: var(--fg); padding: 0 13px; font-size: 14.5px;
}
.edit-row > input:focus, .combo input:focus { outline: none; border-color: var(--acc2); }
.combo { position: relative; display: flex; gap: 8px; }
.combo input { flex: 1; min-width: 0; }
.combo-btn {
  width: 44px; height: 44px; flex: none; background: var(--bg3); border: 1px solid var(--line);
  border-radius: 11px; color: var(--fg-dim); display: inline-flex; align-items: center; justify-content: center;
}
.combo-btn svg { width: 18px; height: 18px; }
.combo-panel {
  position: absolute; left: 0; right: 0; bottom: 52px; max-height: 34vh; overflow-y: auto;
  background: var(--bg3); border: 1px solid var(--line); border-radius: 12px;
  padding: 6px; z-index: 5; box-shadow: 0 14px 34px rgba(0,0,0,.55);
}
.combo-group { color: var(--acc2); font-size: 10.5px; padding: 9px 10px 4px; letter-spacing: .4px; opacity: .85; }
.combo-item { padding: 10px; border-radius: 8px; font-size: 13.5px; cursor: pointer; }
.combo-item:active, .combo-item.on { background: var(--line); }
.combo-empty { padding: 12px 10px; color: var(--fg-dim); font-size: 12px; }
.edit-hint { color: var(--fg-dim); font-size: 11px; line-height: 1.6; margin-top: 4px; }
.edit-actions { display: flex; gap: 10px; margin-top: 18px; }
.edit-actions .btn { flex: 1; height: 46px; }

/* 排行榜：车手 + 时间为主，车型/日期为次 */
.lb-rider {
  font-size: 15px; font-weight: 600; color: var(--fg);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.lb-time {
  font-size: 21px; font-weight: 700; color: var(--acc2);
  font-variant-numeric: tabular-nums; letter-spacing: .3px;
  margin-left: auto; text-align: right; flex: none;
}
.lb-row .lb-main { flex: 1; min-width: 0; }

/* ===== 溢出修复 ===== */
/* 页头：标题与操作分列，放不下时操作整行下移 */
.page-head { justify-content: space-between; row-gap: 8px; }
.page-head h2 { flex: none; }
.page-head .actions { margin-left: auto; }

/* 排行榜副标题：车型可省略，日期始终可见 */
.lb-sub { display: flex; align-items: baseline; gap: 6px; min-width: 0; }
.lb-bike { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-date { flex: none; opacity: .72; }

/* 顶栏文件名给按钮留足空间 */
#active-title { min-width: 0; }

/* ===== 横屏：导航栏移到左侧，内容区一屏铺满 ===== */
@media (orientation: landscape) and (min-height: 260px) {
  body { flex-direction: row; }

  /* 横屏不需要顶栏：品牌/文件名占的是垂直空间，全部让给内容。
     ⋮ 与设置的入口由 JS 移到左侧导航底部（layoutOrientation）。 */
  #topbar { display: none; }
  #pages { margin-top: 0; margin-left: calc(clamp(70px, 9vw, 96px) + env(safe-area-inset-left, 0px)); }



  #tabbar {
    --side-w: clamp(70px, 9vw, 96px);
    --safe-l: env(safe-area-inset-left, 0px);
    top: 0; bottom: 0; left: 0; right: auto;
    width: calc(var(--side-w) + var(--safe-l));
    padding-left: var(--safe-l);
    flex-direction: column; justify-content: flex-start;
    border-top: none; border-right: 1px solid var(--line);
    padding: calc(env(safe-area-inset-top, 0px) + 8px) 0 8px;
  }
  /* 5 个入口均分整条侧栏高度（不再挤在顶部留一大片空白） */
  #tabbar button {
    flex: 1 1 0; min-height: 0; display: flex; flex-direction: column;
    align-items: center; justify-content: center; gap: 4px; padding: 0 2px;
  }
  #tabbar button span { font-size: 10.5px; margin-top: 0; line-height: 1.2; }
  #tabbar [data-ico] svg { width: 24px; height: 24px; }

  .page { padding: 10px 14px 12px; }

  /* 图表页：工具栏一行、曲线与读数并排，整页不滚动 */
  #page-chart.active { display: flex; flex-direction: column; height: 100%; }
  #chart-content:not([hidden]) {
    display: grid; grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr); gap: 8px;
    flex: 1; min-height: 0; position: relative;
  }
  #chart-content .map-toolbar { grid-column: 1; }
  #chart-holder { grid-column: 1; grid-row: 2; height: auto; min-height: 0; }
  /* 横屏：游标旁已有浮动数值框（跟着竖线走，位置不挡曲线），
     右下角再放一份完全相同的数据纯属重复，直接隐藏 */
  #chart-readout { display: none; }
  #chart-content > .hint { display: none; }

  /* 地图页同样铺满 */
  #page-map.active { display: flex; flex-direction: column; height: 100%; }
  #map-content:not([hidden]) { display: flex; flex-direction: column; flex: 1; min-height: 0; }
  #map-holder { flex: 1; min-height: 0; height: auto; }

  /* 日志卡片横屏两列，减少滚动 */
  #log-list { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .log-card { margin: 0; }
}

/* 横屏布局：收藏夹与设备直连统一两列网格——
   第一列 = 标题/按钮（max-content，各自自然宽度=竖屏短设计），
   第二列 = 下拉（1fr 拉满剩余宽度）；
   ★ v1.9.87：第二行单个下拉改回 grid-column:1/-1 从卡片左缘拉满整行
   （对齐竖屏样式，v1.9.86 曾把它放第二列）；读取设备按钮不再拉满 */
@media (orientation: landscape) and (min-height: 260px) {
  .fav-bar .fav-row, .fav-bar .dev-row {
    display: grid; grid-template-columns: max-content minmax(0, 1fr);
    gap: 8px; align-items: center;
  }
  /* 行内只有单个下拉时：占满整行（左缘起，与竖屏一致） */
  .fav-bar .fav-row > .fav-dd:only-child, .fav-bar .dev-row > .fav-dd:only-child { grid-column: 1 / -1; }
}

/* 榜单：名称与成绩最小间距（长名称时不贴边） */
.lb-main { padding-right: 12px; }

/* 页头：按钮文字不折行；极窄屏时按钮整组下移，避免挤压标题 */
.page-head h2 { white-space: nowrap; }
.page-head .actions { flex-wrap: wrap; row-gap: 8px; }
.btn { white-space: nowrap; }

/* 榜单副标题固定占一行高度（无车型时也保持行高一致，日期已移除） */
.lb-sub { min-height: 15px; }

/* 读取按钮：宽度锁定为收藏夹标题宽（对齐需求），文案过长时省略而不是画出按钮外 */
.dev-read-btn { overflow: hidden; text-overflow: ellipsis; }

/* 横屏地图页：左地图 + 右控制面板（覆盖前面的上下堆叠规则） */
@media (orientation: landscape) and (min-height: 260px) {
  #map-content:not([hidden]) {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(256px, 330px);
    grid-template-rows: auto minmax(0, 1fr);
    gap: 8px; flex: 1; min-height: 0;
  }
  #map-content .map-toolbar { grid-column: 1 / -1; grid-row: 1; }
  #map-holder { grid-column: 1; grid-row: 2; height: auto; min-height: 0; }
  #replay-panel {
    grid-column: 2; grid-row: 2; margin: 0;
    width: 100%; max-width: none;
    overflow-y: auto; min-height: 0;
  }
  #map-content .map-toolbar { max-width: none; }
  #replay-panel .replay-row1,
  #replay-panel .replay-row2 { flex-wrap: wrap; row-gap: 6px; }
  #replay-panel .readout { font-size: 12px; }
}

/* ===== 横屏：圈速选圈列保持竖屏宽度，不随屏幕拉伸 ===== */
@media (orientation: landscape) and (min-height: 260px) {
  .log-columns { justify-content: flex-start; overflow-x: auto; }
  .log-col { flex: 0 0 144px; max-width: 144px; }
  .log-columns.many .log-col {
    flex: 0 0 144px; width: 144px; max-width: 144px;
  }
}

/* ===== 横屏地图页：地图占满左侧全高，工具栏移到右栏顶部 ===== */
@media (orientation: landscape) and (min-height: 260px) {
  #map-content:not([hidden]) {
    grid-template-columns: minmax(0, 1fr) minmax(280px, 340px);
    grid-template-rows: auto minmax(0, 1fr);
  }
  #map-holder { grid-column: 1; grid-row: 1 / span 2; height: auto; min-height: 0; }
  #map-content .map-toolbar {
    grid-column: 2; grid-row: 1; max-width: none;
    padding: 0; margin: 0; row-gap: 6px; flex-wrap: wrap;
  }
  #replay-panel { grid-column: 2; grid-row: 2; }
}

/* 横屏选圈区：高度上限按横屏视口放大，避免只露三行 */
@media (orientation: landscape) and (min-height: 260px) {
  .log-columns { max-height: 300px; }
}

/* 横屏侧栏菜单：加宽避免「设备直连（调试）」折行 */
@media (orientation: landscape) and (min-height: 260px) {
  #tabbar #more-menu { min-width: 212px; }
  #tabbar #more-menu button { white-space: nowrap; }
}


/* ===== 侧栏底部固定入口（横屏专用，不依赖 JS 移动 DOM） ===== */
.side-actions { display: none; }
@media (orientation: landscape) and (min-height: 260px) {
  .side-actions {
    display: flex; flex: 0 0 auto; margin-top: auto; width: 100%;
    justify-content: center; gap: 6px;
    padding: 8px 4px; border-top: 1px solid var(--line);
  }
  .side-actions .icon-btn { flex: 1; padding: 8px 4px; border-radius: 10px; }
  .side-actions [data-ico] svg { width: 21px; height: 21px; }

  /* 菜单在横屏贴侧栏右侧（JS 负责具体坐标，这里兜底） */
  #more-menu { left: 84px; right: auto; bottom: 58px; top: auto; min-width: 212px; }
  #more-menu button { white-space: nowrap; }

  /* 图表：对比清单压成一行，避免工具栏占两行高 */
  #chart-laps-hint {
    flex: 1; min-width: 0; white-space: nowrap;
    overflow: hidden; text-overflow: ellipsis; margin-left: 4px;
  }
}

/* 矮横屏（手机横置常见 240–340 CSS 高）：间距与图标略收，仍保持均分 */
@media (orientation: landscape) and (max-height: 340px) {
  #tabbar { padding-top: 2px; padding-bottom: 2px; }
  #tabbar button { gap: 2px; }
  #tabbar [data-ico] svg { width: 21px; height: 21px; }
  #tabbar button span { font-size: 9.5px; }
  .side-actions { padding: 5px 4px; }
  .side-actions [data-ico] svg { width: 19px; height: 19px; }
}

/* ===== 大屏（折叠展开 / 平板）：内容限宽居中，避免文字行拉到 800px+ ===== */
@media (min-width: 760px) {
  #page-logs, #page-laps, #page-rank {
    width: 100%; max-width: 820px;
    margin-left: auto; margin-right: auto;
  }
}
/* 折叠屏展开/平板竖持：日志卡两列，避免单卡 800px 宽 */
@media (min-width: 760px) and (orientation: portrait) {
  #log-list { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .log-card { margin: 0; }
}
@media (min-width: 1180px) {
  #log-list { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

/* 横屏侧栏宽度变量同步到内容区（含安全区） */
@media (orientation: landscape) and (min-height: 260px) {
  #topbar { left: calc(clamp(70px, 9vw, 96px) + env(safe-area-inset-left, 0px)); }
  #more-menu { left: calc(clamp(70px, 9vw, 96px) + env(safe-area-inset-left, 0px) + 8px); }
}

/* 窄横屏（<700）日志卡保持单列，否则每列不到 160px 读不了 */
@media (orientation: landscape) and (min-height: 260px) and (max-width: 699px) {
  #log-list { grid-template-columns: minmax(0, 1fr); }
}

/* 大屏竖持（折叠展开/平板）：底栏按钮居中不拉满 */
@media (min-width: 760px) and (orientation: portrait) {
  #tabbar { justify-content: center; gap: 28px; }
  #tabbar button { flex: 0 0 86px; }
}

/* ===== 地图页：轨迹标记层 + 右侧可滚动栏（控制面板 + 迷你图表） ===== */
#map-trace-layer { position: absolute; inset: 0; pointer-events: none; z-index: 4; }
.mt-dot {
  position: absolute; width: 11px; height: 11px; margin: -5.5px 0 0 -5.5px;
  border-radius: 50%; border: 2px solid #fff; background: #e9ff00;
  box-shadow: 0 0 0 1px rgba(0,0,0,.65), 0 0 9px rgba(0,0,0,.55);
}
.mt-dot.pulse { animation: mtPulse 1.2s ease-out infinite; }
@keyframes mtPulse { 0% { box-shadow: 0 0 0 0 rgba(233,255,0,.55); } 100% { box-shadow: 0 0 0 12px rgba(233,255,0,0); } }

#map-chart-block { display: none; }   /* 仅横屏显示 */

#map-side { display: flex; flex-direction: column; gap: 8px; }

@media (orientation: landscape) and (min-height: 260px) {
  #map-side {
    grid-column: 2; grid-row: 2;
    min-height: 0; display: flex; flex-direction: column; gap: 8px;
    overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain;
    padding-right: 2px;
  }
  #replay-panel { grid-column: auto; grid-row: auto; margin: 0; width: 100%; max-width: none; flex: 0 0 auto; }
  /* ★ v1.9.49：横屏右侧图表自适应高度——占满右栏剩余空间，底边与地图底边对齐 */
  #map-chart-block {
    display: flex; flex-direction: column; flex: 1 1 auto; min-height: 150px;
    background: var(--bg2); border: 1px solid var(--line); border-radius: var(--radius);
    padding: 6px 10px 8px;
  }
  #map-chart-canvas { flex: 1 1 auto; min-height: 0; width: 100%; height: auto; }
  #mc-head {
    display: flex; align-items: center; justify-content: space-between;
    font-size: 11.5px; color: var(--fg-dim); margin-bottom: 6px;
  }
  #mc-head #mc-readout { color: var(--acc2); font-variant-numeric: tabular-nums; }

}

/* 右栏：控制面板不压缩；图表块自适应占满（v1.9.49） */
@media (orientation: landscape) and (min-height: 260px) {
  #map-side > * { flex: 0 0 auto; }
  #map-side > #map-chart-block { flex: 1 1 auto; }
  /* ★ v1.9.65：图表框高度 = 整列高度——滚到底部时其顶边正好在
     「按时间/全览」工具栏下方（此前 min-height:150px 只占回放面板
     之后的剩余空间，整个框矮了一截） */
  #map-chart-block { min-height: 100%; }
  /* ★ v1.9.65：进度到末尾时「完」不换行（同竖屏）——横屏左列地图窄，
     卡片 78% 宽度放不下末尾的「完」，收紧间距并放宽上限 */
  #point-card { max-width: 94%; }
  #point-card .row { flex-wrap: nowrap; gap: 6px; white-space: nowrap; }
}


/* ===== 地图页图表：控件与读数（与图表页同口径） ===== */
#mc-head { display: flex; align-items: center; gap: 8px; }
#mc-head .chip-select { height: 26px; font-size: 11.5px; padding: 0 6px; flex: none; }
#mc-head .toggle { font-size: 11px; gap: 4px; }
#mc-axis { margin-left: auto; font-size: 10.5px; color: var(--fg-dim); white-space: nowrap; }
#mc-legend { display: flex; flex-wrap: wrap; gap: 8px; font-size: 10.5px; color: var(--fg-dim); margin: 2px 0 4px; }
#mc-readout { font-size: 11px; line-height: 1.55; margin-top: 4px; min-height: 0; color: var(--fg); }

/* ★ v1.9.45 设备日志批量下载 */
.dev-bar .fav-dd-panel { user-select: none; -webkit-user-select: none; }
.dev-bar .fav-dd-item.batching { cursor: pointer; }
.dev-bar .fav-dd-item.batch-sel { background: rgba(59, 130, 246, .16); }
.dev-bar .fav-dd-item.batch-sel .fav-dd-name { color: var(--acc2); font-weight: 700; }
#dev-batch-bar, #fav-batch-bar { display: flex; gap: 6px; padding: 8px 10px; border-top: 1px solid var(--line); align-items: center; flex-wrap: wrap; }
#dev-batch-bar button, #fav-batch-bar button { flex: 1 1 auto; padding: 7px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg2); color: var(--fg); font-size: 12px; min-width: 64px; }
#dev-batch-bar button.primary, #fav-batch-bar button.primary { background: var(--acc2); color: #0b0b0b; border-color: var(--acc2); font-weight: 700; }
#dev-batch-bar button:disabled, #fav-batch-bar button:disabled { opacity: .45; }
#dev-batch-bar #dev-batch-status, #fav-batch-bar #fav-batch-status { flex-basis: 100%; font-size: 11px; color: var(--fg-dim); text-align: center; }

/* v1.9.47 批量模式：操作条固定面板底部（列表区滚动），行宽保持 */
.fav-dd-panel.batching { display: flex; flex-direction: column; }
.fav-dd-panel.batching .fav-dd-scroll { flex: 1 1 auto; overflow-y: auto; min-height: 0; }
.fav-dd-panel.batching #fav-batch-bar, .fav-dd-panel.batching #dev-batch-bar { flex: 0 0 auto; border-top: 1px solid var(--line); }


/* v1.9.48 批量模式勾选圆点：行末统一右侧；选中=实心圆，未选中=空心圆圈 */
.batch-dot {
  margin-left: auto; width: 17px; height: 17px; border-radius: 50%;
  border: 2px solid rgba(160, 170, 190, .75); flex-shrink: 0;
  box-sizing: border-box; background: transparent;
  transition: background .12s, border-color .12s;
}
.batch-dot.on { background: var(--acc2, #e8ff47); border-color: var(--acc2, #e8ff47); }


/* ★ v1.9.54 批量模式：进度环与选中圆点同尺寸同右缘（中心线一致） */
.fav-dd-panel.batching .dl-ring { width: 17px; height: 17px; margin-left: auto; flex: none; }
.fav-dd-panel.batching .dl-ring svg { width: 100%; height: 100%; }
.fav-dd-panel.batching .batch-dot { width: 17px; height: 17px; }

/* ★ v1.9.56 批量下载完成标记：居中绿色实心圆（几何与 batch-dot 完全一致） */
.batch-done-dot {
  width: 17px; height: 17px; border-radius: 50%; flex: none;
  background: var(--ok); box-shadow: 0 0 0 1.5px rgba(0,0,0,.35);
}
.fav-dd-panel.batching .batch-done-dot { margin-left: auto; }

/* ===== 桌面/网页端专属优化（v1.9.93）=====
   仅 ≥1180px 横屏生效：手机横屏(~850px)、平板横屏(1024px)均不命中，安卓端零影响 */
@media (min-width: 1180px) and (orientation: landscape) {
  /* 日志/圈速/排行：内容限宽居中（跟随微信/点评的"定宽版心"做法），卡列随宽度自适应铺满 */
  #page-logs, #page-laps, #page-rank { max-width: 1080px; }
  #log-list { grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); }
  /* 地图页：左右均分（地图 ~50%）——地图框不再绝对主导画幅，右侧回放面板/速度图
     获得等宽可读面积。★ v1.9.101 根因：此前选择器为 #map-content（特异性 0,1,0），
     输给横屏基础规则的 #map-content:not([hidden])（0,2,0），整条桌面覆盖从未生效，
     右栏一直锁在 340px；补 :not([hidden]) 对齐特异性后此规则才真正起效 */
  #map-content:not([hidden]) { grid-template-columns: minmax(0, 1fr) minmax(400px, 1fr); }
}

/* ===== 桌面右栏一屏无滚动（v1.9.102）=====
   根因：横屏触屏规则 #map-chart-block{min-height:100%}（图表块=整列高，靠滚动看全）
   在桌面同样命中 → 回放面板 + 整列高的图表块 = 2 倍列高，必滚动。
   桌面改为图表块 min-height:0 纯 flex 吸收剩余高度（对比开启后读数多两行也由画布吸收），
   控件从触屏尺寸(40px)回落到桌面尺寸压缩面板高度。手机/平板（≤1024px）不命中此块 */
@media (min-width: 1180px) and (orientation: landscape) {
  #map-chart-block { min-height: 0; }
  #replay-panel { padding: 8px 10px; }
  .replay-row2 { margin-top: 6px; }
  #seek-bar { height: 30px; }
  .replay-row1 .btn.tiny, .replay-row2 .btn.tiny { height: 30px; padding: 4px 10px; font-size: 12px; }
  .replay-row1 .btn.icon { width: 40px; min-width: 40px; max-width: 40px; }
  .replay-row1 .toggle span { font-size: 12px; }
  .replay-row2 .chip-select { height: 30px; font-size: 12px; }
  .replay-row2 #replay-speed { width: 62px; }
  #replay-readout .cmp-row { font-size: 12px; }
  #readout-wrap { margin-top: 4px; }
}

/* 鼠标悬停反馈：仅精确指针设备生效（触屏无 hover，不产生粘滞高亮） */
@media (hover: hover) and (pointer: fine) {
  .log-card { transition: border-color .12s ease, background .12s ease; }
  .log-card:hover { border-color: var(--acc2); background: var(--bg3); }
  .btn:hover, .icon-btn:hover { background: var(--bg3); }
  #tabbar button:hover { color: var(--fg); }
  .side-actions .icon-btn:hover { background: var(--bg3); }
  select:hover { border-color: var(--fg-dim); }
  /* 桌面滚动条：窄条深色主题化 */
  ::-webkit-scrollbar { width: 10px; height: 10px; }
  ::-webkit-scrollbar-track { background: transparent; }
  ::-webkit-scrollbar-thumb { background: var(--bg3); border-radius: 5px; }
  ::-webkit-scrollbar-thumb:hover { background: #2a3346; }
}
