:root {
  --bg: #0f1419;
  --panel: #1a2332;
  --border: #2a3548;
  --text: #e7ecf3;
  --muted: #8b9bb4;
  --accent: #3b82f6;
  --accent2: #22c55e;
  --warn: #f59e0b;
  --pink: #ec4899;
  --cyan: #06b6d4;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: "SF Pro Text", "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  min-height: 100dvh;
  padding-bottom: var(--safe-bottom);
}
.top {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem 1rem;
  justify-content: space-between;
  align-items: flex-start;
  padding: 1.25rem 1.5rem 0.5rem;
}
.brand { min-width: 0; flex: 1 1 180px; }
.brand h1 {
  margin: 0;
  font-size: clamp(1.15rem, 4vw, 1.4rem);
  font-weight: 650;
}
.sub {
  margin: 0.35rem 0 0;
  color: var(--muted);
  font-size: 0.8rem;
  line-height: 1.4;
  word-break: break-word;
}
.ranges {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  flex: 1 1 100%;
  width: 100%;
}
.ranges button {
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--muted);
  padding: 0.55rem 0.85rem;
  min-height: 40px;
  border-radius: 999px;
  cursor: pointer;
  font-size: 0.8rem;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  flex: 1 1 auto;
  text-align: center;
}
.ranges button:hover { color: var(--text); border-color: var(--accent); }
.ranges button.active {
  background: rgba(59, 130, 246, 0.18);
  border-color: var(--accent);
  color: #93c5fd;
}
.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 0.75rem;
  padding: 1rem 1.5rem;
}
.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.85rem 1rem;
  min-width: 0;
}
.card .label { color: var(--muted); font-size: 0.75rem; margin-bottom: 0.35rem; }
.card .value {
  font-size: clamp(0.95rem, 3.5vw, 1.15rem);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  word-break: break-word;
  line-height: 1.3;
}
.charts {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 320px), 1fr));
  gap: 1rem;
  padding: 0 1.5rem 1.5rem;
}
.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 1rem 0.75rem 0.5rem;
  min-width: 0;
  overflow: hidden;
}
.panel h2 {
  margin: 0 0 0.5rem;
  padding: 0 0.25rem;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--muted);
}
.chart-wrap {
  position: relative;
  width: 100%;
  height: 220px;
}
.panel canvas { width: 100% !important; height: 100% !important; }
.foot {
  padding: 0 1.5rem calc(1.5rem + var(--safe-bottom));
  color: var(--muted);
  font-size: 0.8rem;
  line-height: 1.4;
}

/* Phone / narrow */
@media (max-width: 640px) {
  .top { padding: 0.85rem 0.85rem 0.35rem; gap: 0.65rem; }
  .cards {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.55rem;
    padding: 0.75rem 0.85rem;
  }
  .card { padding: 0.7rem 0.75rem; }
  .charts {
    grid-template-columns: 1fr;
    gap: 0.75rem;
    padding: 0 0.85rem 1rem;
  }
  .chart-wrap { height: 200px; }
  .ranges button {
    flex: 1 1 calc(50% - 0.45rem);
    min-width: calc(50% - 0.45rem);
    font-size: 0.78rem;
    padding: 0.6rem 0.5rem;
  }
  .foot { padding: 0 0.85rem calc(1rem + var(--safe-bottom)); }
}

/* Very small phones */
@media (max-width: 360px) {
  .cards { grid-template-columns: 1fr 1fr; }
  .ranges button {
    flex: 1 1 100%;
    min-width: 100%;
  }
  .chart-wrap { height: 180px; }
}

/* Landscape phone */
@media (max-height: 480px) and (orientation: landscape) {
  .chart-wrap { height: 160px; }
  .cards { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
