:root {
  --bg: #0b1017;
  --panel: rgba(16, 24, 34, 0.94);
  --panel-solid: #16202c;
  --line: #2c3b4d;
  --text: #dce7f0;
  --dim: #93a7ba;
  --accent: #35c6e8;
  --accent2: #ffb74d;
  --route: #ffc107;
}

* { box-sizing: border-box; }

/* 必须放最前并加 !important：
   #trainPanel / #results / #basemapMenu 都显式设了 display，
   会覆盖 hidden 属性，导致"没选中车次车次面板也显示"这类 bug。 */
[hidden] { display: none !important; }

html, body {
  margin: 0; padding: 0; height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 -apple-system, "Segoe UI", "Microsoft YaHei", "PingFang SC", sans-serif;
  overflow: hidden;
  -webkit-text-size-adjust: 100%;
}

#map { position: absolute; inset: 0; }

/* MapLibre 自带控件在深色下过亮 */
.maplibregl-ctrl-attrib { background: rgba(11,16,23,.75) !important; }
.maplibregl-ctrl-attrib a { color: var(--dim) !important; }
.maplibregl-ctrl-group { background: var(--panel-solid) !important; }
.maplibregl-ctrl-group button + button { border-top-color: var(--line) !important; }
.maplibregl-ctrl-group button span { filter: invert(1) opacity(.85); }

.panel {
  position: absolute;
  background: var(--panel);
  backdrop-filter: blur(12px);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: 0 8px 28px rgba(0,0,0,.45);
  z-index: 5;
}

/* ---------------- 顶栏 ---------------- */
#topbar {
  top: 10px; left: 10px; right: 10px;
  padding: 10px;
  display: flex; flex-direction: column; gap: 8px;
  max-width: 560px;
}

.searchrow { display: flex; gap: 6px; align-items: center; }

#q {
  flex: 1; min-width: 0;
  background: #0e1620;
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--text);
  padding: 10px 12px;
  font-size: 15px;
  outline: none;
}
#q:focus { border-color: var(--accent); }
#q::placeholder { color: #6b8098; }

.icon {
  background: transparent; border: 1px solid var(--line);
  color: var(--dim); border-radius: 9px;
  width: 34px; height: 34px; flex: 0 0 34px;
  cursor: pointer; font-size: 14px; line-height: 1;
}
.icon:hover { color: var(--text); border-color: var(--accent); }

.basemap-btn {
  display: flex; align-items: center; gap: 8px;
  background: #0e1620; border: 1px solid var(--line);
  color: var(--dim); border-radius: 10px;
  padding: 7px 10px; cursor: pointer;
  font-size: 12.5px; text-align: left;
}
.basemap-btn:hover { border-color: var(--accent); }
.basemap-btn .dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--accent); flex: 0 0 7px;
}
.basemap-btn .chev { margin-left: auto; opacity: .6; }

.results {
  max-height: 46vh; overflow-y: auto;
  border-top: 1px solid var(--line);
  margin: 0 -10px -10px; padding: 4px 0;
}
.rgroup { padding: 6px 12px 2px; font-size: 11.5px; color: var(--accent); letter-spacing: .5px; }
.rrow {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px; cursor: pointer;
}
.rrow:hover { background: rgba(53,198,232,.10); }
.rrow .b {
  font-family: ui-monospace, Consolas, monospace; font-weight: 700;
  color: var(--accent); background: rgba(53,198,232,.15);
  border-radius: 6px; padding: 2px 7px; font-size: 12px;
}
.rrow .b.k { color: var(--accent2); background: rgba(255,183,77,.15); }
.rrow .t1 { font-size: 13.5px; }
.rrow .t2 { font-size: 11.5px; color: var(--dim); }

/* ---------------- 底栏 ---------------- */
#bottombar {
  left: 10px; right: 10px; bottom: 10px;
  padding: 10px 14px 6px;
  max-width: 560px;
}
.clockrow { display: flex; align-items: center; gap: 10px; }
.clock {
  font-family: ui-monospace, Consolas, monospace;
  font-size: 21px; font-weight: 700; color: var(--accent);
}
.stat { font-size: 12.5px; color: var(--dim); }
.live {
  margin-left: auto; background: transparent;
  border: 1px solid var(--line); color: var(--dim);
  border-radius: 8px; padding: 4px 9px; font-size: 12px; cursor: pointer;
}
.live:hover { color: var(--text); border-color: var(--accent); }

#timeslider { width: 100%; margin: 8px 0 2px; accent-color: var(--accent); }

/* ---------------- 车次详情 ---------------- */
#trainPanel {
  right: 10px; bottom: 96px;
  width: min(400px, calc(100vw - 20px));
  max-height: 52vh;
  display: flex; flex-direction: column;
  overflow: hidden;
}
.trainhead {
  display: flex; align-items: center; gap: 10px;
  padding: 12px; border-bottom: 1px solid var(--line);
}
.badge {
  font-family: ui-monospace, Consolas, monospace; font-weight: 700;
  background: rgba(53,198,232,.16); color: var(--accent);
  border-radius: 7px; padding: 3px 9px; font-size: 13px;
}
.trainmeta { display: flex; flex-direction: column; min-width: 0; }
.trainmeta strong { font-size: 13.5px; }
.sub { font-size: 11.5px; color: var(--dim); }
#tClose { margin-left: auto; }

.tablewrap { overflow-y: auto; }
#tTable { width: 100%; border-collapse: collapse; font-size: 12.5px; }
#tTable td { padding: 6px 12px; border-bottom: 1px solid rgba(44,59,77,.45); }
#tTable tr:last-child td { border-bottom: 0; }
#tTable .nm { }
#tTable .num {
  font-family: ui-monospace, Consolas, monospace;
  color: var(--dim); text-align: right; white-space: nowrap;
}
#tTable .km { color: var(--accent2); }
#tTable tr.cur { background: rgba(255,193,7,.10); }
#tTable tr.cur .nm { color: var(--route); font-weight: 600; }

/* ---------------- 底图菜单 ---------------- */
#basemapMenu {
  top: 132px; left: 10px;
  width: min(340px, calc(100vw - 20px));
  max-height: 60vh; overflow-y: auto;
  padding: 6px 0;
}
.bmrow {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 14px; cursor: pointer; font-size: 13px;
}
.bmrow:hover { background: rgba(53,198,232,.10); }
.bmrow .tag {
  margin-left: auto; font-size: 10.5px; color: var(--accent2);
  border: 1px solid rgba(255,183,77,.35); border-radius: 5px; padding: 1px 5px;
}
.bmrow.on { color: var(--accent); font-weight: 600; }
.bmnote { padding: 8px 14px 10px; font-size: 11.5px; color: var(--dim); line-height: 1.7; }

/* ---------------- 悬浮信息卡 ---------------- */
#hovercard {
  position: fixed;
  z-index: 30;
  pointer-events: none;          /* 不能挡住地图的鼠标事件，否则悬停会闪 */
  background: rgba(16, 24, 34, 0.97);
  border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  border-radius: 10px;
  padding: 8px 12px;
  box-shadow: 0 6px 20px rgba(0,0,0,.55);
  max-width: 250px;
  font-size: 12.5px;
  line-height: 1.55;
}
#hovercard .hc-no {
  font-family: ui-monospace, Consolas, monospace;
  font-weight: 700; font-size: 14px; color: var(--accent);
}
#hovercard .hc-route { color: var(--text); }
#hovercard .hc-sub { color: var(--dim); font-size: 11.5px; }
#hovercard .hc-status { color: var(--accent2); font-size: 11.5px; margin-top: 2px; }

/* ---------------- 载入 ---------------- */
#loading {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%,-50%);
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 12px; padding: 16px 22px; z-index: 20; font-size: 14px;
}

@media (max-width: 720px) {
  #trainPanel { right: 10px; left: 10px; width: auto; bottom: 92px; max-height: 44vh; }
  #bottombar { max-width: none; }
}
