:root {
  color-scheme: light dark;
  --background: #f5f6f7;
  --surface: #ffffff;
  --foreground: #191b1d;
  --muted: #858a90;
  --soft: #e9ebed;
  --grid: #e1e4e7;
  --temp: #db704e;
  --hum: #397fc5;
  --online: #27a56a;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--background);
  color: var(--foreground);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
}

main {
  width: min(100%, 920px);
  margin: auto;
  padding: 42px 24px 28px;
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
}

#room-select {
  max-width: 260px;
  border: 0;
  background: transparent;
  color: var(--foreground);
  font: inherit;
  font-size: 21px;
  font-weight: 650;
  cursor: pointer;
}

.connection {
  color: var(--muted);
  font-size: 14px;
  white-space: nowrap;
}

.dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  margin-right: 7px;
  border-radius: 50%;
  background: var(--muted);
}

.dot.online {
  background: var(--online);
}

.readings {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
  margin: 38px 0 22px;
}

.reading {
  padding: 30px 12px;
  border-radius: 20px;
  background: var(--surface);
  text-align: center;
  box-shadow: 0 8px 30px rgba(24, 31, 38, .05);
}

.value {
  font-size: 46px;
  font-weight: 650;
  letter-spacing: -1.5px;
}

.temperature {
  color: var(--temp);
}

.humidity {
  color: var(--hum);
}

.label {
  margin-top: 7px;
  color: var(--muted);
  font-size: 14px;
}

.history {
  padding: 22px;
  border-radius: 20px;
  background: var(--surface);
  box-shadow: 0 8px 30px rgba(24, 31, 38, .05);
}

.history-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-bottom: 12px;
}

.legend {
  display: flex;
  gap: 16px;
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}

.legend i {
  display: inline-block;
  width: 9px;
  height: 9px;
  margin-right: 5px;
  border-radius: 50%;
}

.temp-mark {
  background: var(--temp);
}

.hum-mark {
  background: var(--hum);
}

.ranges {
  display: flex;
  gap: 4px;
  padding: 3px;
  border-radius: 999px;
  background: var(--soft);
}

.ranges button {
  min-height: 34px;
  padding: 6px 12px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}

.ranges button.active {
  background: var(--surface);
  color: var(--foreground);
  box-shadow: 0 2px 8px rgba(24, 31, 38, .08);
}

.chart-wrap {
  position: relative;
  height: 310px;
}

#chart {
  display: block;
  width: 100%;
  height: 100%;
}

.chart-empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--muted);
  font-size: 14px;
  pointer-events: none;
}

.chart-empty[hidden] {
  display: none;
}

footer {
  margin-top: 17px;
  color: var(--muted);
  text-align: center;
  font-size: 13px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --background: #17191b;
    --surface: #232629;
    --foreground: #f0f1f2;
    --muted: #a0a5aa;
    --soft: #303438;
    --grid: #363b3f;
    --temp: #ec8b6d;
    --hum: #69a5df;
    --online: #3bc783;
  }

  .reading,
  .history {
    box-shadow: none;
  }
}

@media (max-width: 620px) {
  main {
    padding: 30px 15px 24px;
  }

  header {
    align-items: flex-start;
    flex-direction: column;
    gap: 7px;
  }

  .readings {
    gap: 10px;
    margin-top: 26px;
  }

  .value {
    font-size: 38px;
  }

  .reading {
    padding: 25px 6px;
  }

  .history {
    padding: 16px 10px 12px;
  }

  .history-head {
    align-items: flex-start;
    flex-direction: column;
  }

  .ranges {
    width: 100%;
  }

  .ranges button {
    flex: 1;
    padding-inline: 4px;
  }

  .chart-wrap {
    height: 275px;
  }
}
