:root {
  --bg: #07110f;
  --panel: rgba(14, 25, 25, 0.88);
  --line: rgba(204, 231, 221, 0.14);
  --text: #edf8f3;
  --muted: #9bb1a9;
  --mint: #6ee7c8;
  --amber: #ffba69;
  --red: #ff6f79;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  color: var(--text);
  font-family: "Segoe UI", "Microsoft YaHei", sans-serif;
  background:
    radial-gradient(circle at 12% 10%, rgba(110, 231, 200, .22), transparent 28rem),
    radial-gradient(circle at 88% 0%, rgba(255, 186, 105, .20), transparent 24rem),
    linear-gradient(145deg, #05100f, #101315 60%, #211812);
  min-height: 100vh;
}

.shell { width: min(1440px, calc(100% - 32px)); margin: 0 auto; padding: 28px 0 42px; }
.hero, .panel, .card {
  border: 1px solid var(--line);
  background: var(--panel);
  box-shadow: 0 24px 80px rgba(0, 0, 0, .28);
  backdrop-filter: blur(14px);
}
.hero {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  border-radius: 28px;
  padding: 30px;
}
.eyebrow, .label { color: var(--muted); letter-spacing: .18em; font-size: 12px; text-transform: uppercase; }
h1 { margin: 8px 0 10px; font-size: clamp(34px, 6vw, 72px); line-height: .95; }
h2 { margin: 4px 0 0; font-size: 24px; }
.sub { color: var(--muted); max-width: 760px; line-height: 1.8; }
.status-stack { display: flex; flex-wrap: wrap; align-content: flex-start; justify-content: flex-end; gap: 10px; }
.pill { padding: 10px 14px; border-radius: 999px; border: 1px solid var(--line); background: rgba(255,255,255,.06); color: var(--muted); }
.pill.ok { color: var(--mint); background: rgba(110, 231, 200, .12); }
.pill.warn { color: var(--amber); background: rgba(255, 186, 105, .13); }
.pill.error { color: var(--red); background: rgba(255, 111, 121, .13); }

.grid { display: grid; gap: 18px; }
.cards { grid-template-columns: repeat(3, minmax(0, 1fr)); margin: 18px 0; }
.card { border-radius: 22px; padding: 20px; min-height: 150px; position: relative; overflow: hidden; }
.card strong { display: block; font-size: 32px; margin: 18px 0 6px; }
.card small { color: var(--muted); font-size: 15px; }
.source-time { display: block; margin-top: 8px; color: rgba(155, 177, 169, .86); font-size: 13px; line-height: 1.45; }
.device-picker { margin-top: 14px; }
.device-picker select {
  width: 100%;
  min-height: 42px;
  color: var(--text);
  background: rgba(255,255,255,.08);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0 12px;
  font: inherit;
  outline: none;
}
.device-picker select:focus {
  border-color: rgba(110, 231, 200, .72);
  box-shadow: 0 0 0 3px rgba(110, 231, 200, .14);
}
.battery { width: 120px; height: 46px; border: 3px solid rgba(237,248,243,.8); border-radius: 14px; padding: 4px; margin-top: 16px; position: relative; }
.battery::after { content: ""; position: absolute; right: -12px; top: 12px; width: 8px; height: 18px; background: rgba(237,248,243,.8); border-radius: 0 5px 5px 0; }
#batteryFill { width: 0%; height: 100%; border-radius: 9px; background: linear-gradient(90deg, var(--amber), var(--mint)); transition: width .35s ease; }
.battery.low #batteryFill { background: var(--red); }
.battery.charging #batteryFill { animation: charge 1.2s ease-in-out infinite alternate; }
@keyframes charge { from { filter: brightness(.8); } to { filter: brightness(1.35); } }

.main-grid { display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(0, .9fr); gap: 18px; margin-top: 18px; }
.panel { border-radius: 26px; padding: 22px; min-height: 320px; min-width: 0; overflow: hidden; }
.panel-head { display: flex; justify-content: space-between; gap: 18px; align-items: flex-start; margin-bottom: 16px; color: var(--muted); min-width: 0; }
.panel-head > * { min-width: 0; }
.panel-meta { display: grid; justify-items: end; gap: 6px; text-align: right; }
.map-head-meta { display: grid; justify-items: end; gap: 6px; text-align: right; }
.map-head-meta span { overflow-wrap: anywhere; }
.panel-meta .source-time, .map-head-meta .source-time { margin-top: 0; }
#mapTileStatus {
  padding: 5px 9px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255,255,255,.05);
  font-size: 12px;
}
.map-panel { position: relative; }
#map { height: 420px; border-radius: 20px; overflow: hidden; background: #0b1716; }
.map-locate {
  position: absolute;
  right: 38px;
  top: 118px;
  z-index: 520;
  min-height: 38px;
  padding: 0 13px;
  border: 1px solid rgba(17, 24, 39, .24);
  border-radius: 999px;
  color: #10201c;
  background: rgba(255, 255, 255, .9);
  box-shadow: 0 12px 28px rgba(0, 0, 0, .22);
  backdrop-filter: blur(10px);
  font: inherit;
  font-size: 13px;
  font-weight: 800;
  cursor: pointer;
}
.map-locate:hover { background: #fff; }
.map-locate:active { transform: translateY(1px); }
.map-locate.warn { color: #7c2d12; background: rgba(255, 236, 213, .94); }
.map-legend {
  position: absolute;
  left: 38px;
  bottom: 34px;
  z-index: 500;
  display: flex;
  flex-wrap: wrap;
  gap: 8px 12px;
  max-width: min(520px, calc(100% - 76px));
  padding: 10px 12px;
  border: 1px solid rgba(17, 24, 39, .24);
  border-radius: 14px;
  color: #10201c;
  background: rgba(255, 255, 255, .88);
  box-shadow: 0 12px 28px rgba(0, 0, 0, .22);
  backdrop-filter: blur(10px);
  pointer-events: none;
  font-size: 13px;
  font-weight: 700;
}
.map-legend span { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.legend-dot { width: 12px; height: 12px; border-radius: 999px; display: inline-block; border: 2px solid #fff; box-shadow: 0 0 0 1px rgba(17,24,39,.28); }
.legend-dot.current { background: #ff1744; width: 16px; height: 16px; }
.legend-dot.start { background: #2979ff; }
.legend-dot.history { background: #ff1744; width: 10px; height: 10px; }
.legend-line { width: 30px; height: 0; border-top: 5px solid #ff1744; border-radius: 999px; box-shadow: 0 0 0 2px rgba(17,24,39,.72); }
.imu-readout {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 14px;
  margin: -2px 0 12px;
  color: var(--muted);
}
.imu-readout span {
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255,255,255,.05);
  padding: 8px 12px;
}
.imu-status.ok {
  color: var(--mint);
  border-color: rgba(110, 231, 200, .42);
  background: rgba(110, 231, 200, .10);
}
.imu-status.warn {
  color: var(--amber);
  border-color: rgba(255, 186, 105, .42);
  background: rgba(255, 186, 105, .10);
}
.scene { height: 420px; display: grid; place-items: center; perspective: 900px; }
.collar { width: 270px; height: 270px; position: relative; transform-style: preserve-3d; transition: transform .45s ease; }
.ring { position: absolute; inset: 24px; border: 34px solid #263c3a; border-radius: 50%; box-shadow: inset 0 18px 30px rgba(0,0,0,.4), 0 20px 50px rgba(0,0,0,.35); }
.module { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%) translateZ(42px); width: 112px; height: 72px; border-radius: 24px; display: grid; place-items: center; font-weight: 900; color: #17231f; background: linear-gradient(145deg, var(--mint), var(--amber)); box-shadow: 0 18px 40px rgba(0,0,0,.35); }

.history-grid { display: grid; grid-template-columns: 1fr; gap: 18px; margin-top: 18px; }
.battery-history-panel { min-height: 300px; }
.battery-chart-wrap {
  border: 1px solid var(--line);
  border-radius: 20px;
  background: rgba(0,0,0,.22);
  padding: 12px;
  overflow: hidden;
}
.battery-chart { display: block; width: 100%; height: 220px; }
.battery-chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 16px;
  margin-top: 12px;
  color: var(--muted);
  font-size: 14px;
}
.battery-chart-legend span { display: inline-flex; align-items: center; gap: 7px; }
.battery-key { display: inline-block; flex: 0 0 auto; }
.battery-key.line { width: 28px; height: 0; border-top: 4px solid var(--amber); border-radius: 999px; }
.battery-key.current { width: 14px; height: 14px; border: 3px solid #fff; border-radius: 999px; background: #ff1744; }
.battery-key.charging { width: 14px; height: 14px; border: 2px solid #07110f; border-radius: 999px; background: var(--mint); box-shadow: 0 0 0 2px rgba(110, 231, 200, .28); }
.battery-trend-summary {
  margin-top: 12px;
  color: var(--muted);
  line-height: 1.7;
  overflow-wrap: anywhere;
}

audio { width: 100%; margin: 12px 0; min-width: 0; }
.audio-list { display: grid; gap: 10px; max-height: 280px; overflow: auto; min-width: 0; }
.audio-item { border: 1px solid var(--line); border-radius: 16px; padding: 12px; color: var(--muted); background: rgba(255,255,255,.04); overflow-wrap: anywhere; }
.audio-item.clickable { cursor: pointer; transition: border-color .18s ease, color .18s ease, background .18s ease; }
.audio-item.clickable:hover { color: var(--text); border-color: rgba(110, 231, 200, .52); background: rgba(110, 231, 200, .08); }
.audio-item.decoding { color: var(--amber); border-color: rgba(255, 186, 105, .48); background: rgba(255, 186, 105, .10); }
.audio-item.ready { color: var(--mint); border-color: rgba(110, 231, 200, .42); background: rgba(110, 231, 200, .08); }
pre {
  margin: 0;
  white-space: pre-wrap;
  overflow: auto;
  overflow-wrap: anywhere;
  word-break: break-word;
  max-width: 100%;
  max-height: 420px;
  color: #d9fff0;
  background: rgba(0,0,0,.28);
  border-radius: 18px;
  padding: 16px;
}

@media (max-width: 980px) {
  .hero, .main-grid { grid-template-columns: 1fr; display: grid; }
  .cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 620px) {
  .shell { width: min(100% - 18px, 640px); padding-top: 12px; }
  .hero { padding: 20px; border-radius: 22px; }
  .cards { grid-template-columns: 1fr; }
  #map, .scene { height: 330px; }
  .panel-meta { justify-items: start; text-align: left; }
  .map-head-meta { justify-items: start; text-align: left; }
  .map-locate { right: 22px; top: 108px; min-height: 36px; padding: 0 11px; }
  .map-legend { left: 22px; right: 22px; bottom: 28px; max-width: none; }
}
