:root {
  --bg: #0f1923;
  --card-bg: #1a2733;
  --card-border: #263545;
  --text: #e0e0e0;
  --text-muted: #6b8299;
  --accent-blue: #42a5f5;
  --accent-green: #66bb6a;
  --accent-red: #ef5350;
  --btn-bg: #1a2733;
  --btn-active: #1e88e5;
  --grid: #263545;
  --axis: #6b8299;
}

html.light {
  --bg: #f5f7fa;
  --card-bg: #ffffff;
  --card-border: #e0e0e0;
  --text: #1a2733;
  --text-muted: #6b8299;
  --btn-bg: #e8eef4;
  --btn-active: #1e88e5;
  --grid: #e0e0e0;
  --axis: #5c6b7a;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  height: 100%;
}

body {
  margin: 0;
  min-height: 100%;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Ubuntu, Cantarell, sans-serif;
  font-size: 16px;
}

.app {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  width: 100%;
  padding: 32px 36px 40px;
}

/* Header */
.header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 22px;
}

.title {
  font-size: 1.35rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.time-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.time-btn {
  appearance: none;
  border: 1px solid var(--card-border);
  background: var(--btn-bg);
  color: var(--text);
  padding: 7px 12px;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  line-height: 1.2;
}

.time-btn:hover {
  border-color: var(--accent-blue);
}

.time-btn.active {
  background: var(--btn-active);
  border-color: var(--btn-active);
  color: #fff;
}

#theme-toggle {
  appearance: none;
  border: 1px solid var(--card-border);
  background: var(--btn-bg);
  color: var(--text);
  padding: 7px 12px;
  border-radius: 6px;
  font-size: 16px;
  cursor: pointer;
  line-height: 1.2;
}

#theme-toggle:hover {
  border-color: var(--accent-blue);
}

/* Stats */
.stats-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin-top: 22px;
}

.stat-card {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 10px;
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.stat-label {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--text-muted);
}

.now-card .stat-value {
  color: var(--accent-blue);
}

.peak-card .stat-value {
  color: var(--accent-green);
}

.stat-value {
  font-size: 2.25rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}

.stat-sub {
  font-size: 14px;
  color: var(--text-muted);
  min-height: 1.2em;
}

/* Chart */
#chart {
  flex: 1 1 0;
  min-height: 0;
  width: 100%;
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 10px;
  padding: 8px;
}

#chart .chart-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 300px;
  color: var(--text-muted);
  font-size: 15px;
}

.chart-tooltip {
  position: absolute;
  display: none;
  z-index: 20;
  max-width: min(340px, 92vw);
  padding: 10px 12px;
  font-size: 14px;
  line-height: 1.35;
  pointer-events: none;
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 8px;
  color: var(--text);
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.25);
}

.chart-tooltip .tt-time {
  font-weight: 600;
  margin-bottom: 5px;
  color: var(--text-muted);
  font-size: 13px;
}

.chart-tooltip .tt-row {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-variant-numeric: tabular-nums;
  background: rgba(255, 255, 255, 0.06);
  border-radius: 4px;
  padding: 3px 8px;
  margin: 2px 0;
}

html.light .chart-tooltip .tt-row {
  background: rgba(0, 0, 0, 0.05);
}

.tt-swatch {
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  flex-shrink: 0;
}

.chart-tooltip.tt-locked {
  border-color: var(--accent-blue);
  pointer-events: auto;
}

.tt-pin {
  font-size: 11px;
  margin-left: 3px;
}

/* uPlot tweaks inside card */
#chart .uplot {
  margin: 0 auto;
}

/* Chart footer */
.chart-footer {
  margin-top: 16px;
  padding: 0 4px;
}

.legend-pills {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-bottom: 8px;
}

.legend-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 4px 12px;
  border: 1px solid var(--card-border);
  border-radius: 20px;
  background: var(--card-bg);
}

.legend-pill:empty {
  display: none;
}

.legend-toggle-all {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  user-select: none;
  padding: 2px 6px;
  border-left: 1px solid var(--card-border);
  margin-left: 2px;
  transition: color 0.15s;
}

.legend-toggle-all:hover {
  color: var(--text);
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
  color: var(--text);
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
  transition: opacity 0.15s;
}

.legend-item:hover {
  opacity: 0.8;
}

.legend-item.legend-hidden {
  opacity: 0.35;
  text-decoration: line-through;
}

.legend-swatch {
  display: inline-block;
  width: 12px;
  height: 3px;
  border-radius: 2px;
  flex-shrink: 0;
}

.chart-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.legend-note {
  font-size: 14px;
  color: var(--text-muted);
}

#export-btn {
  appearance: none;
  border: 1px solid var(--card-border);
  background: var(--btn-bg);
  color: var(--text);
  padding: 7px 14px;
  border-radius: 8px;
  font-size: 18px;
  cursor: pointer;
  line-height: 1;
}

#export-btn:hover {
  border-color: var(--accent-blue);
}

@media (max-width: 600px) {
  .app {
    padding: 20px 18px 30px;
  }

  .header {
    flex-direction: column;
    align-items: stretch;
  }

  .time-controls {
    justify-content: flex-start;
  }

  .time-btn {
    padding: 8px 10px;
    font-size: 13px;
  }

  .stats-row {
    grid-template-columns: 1fr;
  }

  .stat-value {
    font-size: 1.85rem;
  }

  #chart {
    border-radius: 8px;
    padding: 6px;
  }
}
