:root {
  color-scheme: dark;
  --bg: #0f0f0f;
  --chart: #131722;
  --border: #2a2e39;
  --text: #e0e0e0;
  --muted: #8b8f99;
  --blue: #5b7cfa;
  --green: #26a69a;
  --red: #ef5350;
  --orange: #ff9800;
  --magenta: #e040fb;
  --cyan: #00bcd4;
}

* { box-sizing: border-box; }

html,
body {
  min-width: 320px;
  min-height: 100%;
  margin: 0;
  background: var(--bg);
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: hidden;
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}

button,
output { font: inherit; }

button:focus-visible,
#chart:focus-visible {
  outline: 2px solid #8ea4ff;
  outline-offset: 2px;
}

[hidden] { display: none !important; }

main {
  width: min(100%, 1200px);
  margin: 0 auto;
  padding: 20px max(24px, env(safe-area-inset-right)) max(20px, env(safe-area-inset-bottom)) max(24px, env(safe-area-inset-left));
}

.chart-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 18px;
  min-height: 44px;
  margin-bottom: 6px;
}

.identity,
.reading {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 8px 12px;
  min-width: 0;
}

h1 {
  margin: 0;
  color: #f2f2f2;
  font-size: 1rem;
  font-weight: 650;
  letter-spacing: -0.02em;
}

.station,
.reading-meta,
.data-status,
.chart-summary {
  color: var(--muted);
  font-size: 0.75rem;
}

.temperature {
  color: #f2f2f2;
  font-size: 1.35rem;
  font-weight: 700;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.temperature[data-band="cold"] { color: #6d8cff; }
.temperature[data-band="mild"] { color: #45bbae; }
.temperature[data-band="warm"] { color: #f06a67; }

.reading-meta {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 1px;
  line-height: 1.25;
  font-variant-numeric: tabular-nums;
}

.freshness { font-weight: 650; }
.freshness[data-freshness="fresh"] { display: none; }
.freshness[data-freshness="delayed"] { color: #e9b96e; }
.freshness[data-freshness="stale"],
.freshness[data-freshness="error"] { color: #f07b78; }

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 4px 12px;
  min-height: 38px;
}

.timeframes {
  display: flex;
  gap: 2px;
}

.timeframes button,
.retry {
  min-height: 32px;
  border: 0;
  border-radius: 4px;
  color: var(--muted);
  background: transparent;
  cursor: pointer;
  font-size: 0.8rem;
  font-weight: 550;
}

.timeframes button {
  min-width: 64px;
  padding: 0 12px;
}

.timeframes button:hover,
.timeframes button[aria-pressed="true"] {
  color: #fff;
  background: #2a2a2a;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  color: #747985;
  font-size: 0.72rem;
}

.legend span::before {
  content: "";
  display: inline-block;
  width: 12px;
  height: 2px;
  margin-right: 4px;
  vertical-align: middle;
  background: currentColor;
}

.close-line { color: rgba(91, 124, 250, 0.82); }
.ma7 { color: var(--orange); }
.ma50 { color: var(--magenta); }
.ma99 { color: var(--cyan); }

.data-status {
  display: flex;
  align-items: center;
  gap: 7px;
  min-height: 24px;
  padding: 1px 3px 5px;
  line-height: 1.25;
}

.data-status[data-state="delayed"] { color: #d6aa68; }
.data-status[data-state="fresh"] { display: none; }
.data-status[data-state="stale"],
.data-status[data-state="error"] { color: #df7471; }

.status-dot {
  width: 6px;
  height: 6px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: currentColor;
}

.data-status[data-state="loading"] .status-dot {
  animation: pulse 1.1s ease-in-out infinite alternate;
}

.retry {
  min-width: 72px;
  margin-left: 4px;
  padding: 0 10px;
  border: 1px solid #414653;
  color: #c7cbd3;
  background: #20242e;
}

.chart-section {
  min-width: 0;
}

.chart-shell {
  position: relative;
  width: 100%;
  height: clamp(360px, 45vw, 520px);
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--chart);
}

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

.chart-overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  margin: 0;
  color: #8b8f99;
  background: rgba(19, 23, 34, 0.88);
  font-size: 0.8rem;
}

.chart-summary {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

@keyframes pulse {
  from { opacity: 0.35; }
  to { opacity: 1; }
}

@media (max-width: 560px) {
  main {
    padding: 10px max(10px, env(safe-area-inset-right)) max(10px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
  }

  .chart-header { align-items: flex-start; }
  .reading { width: 100%; justify-content: space-between; }
  .reading-meta { text-align: right; }
  .toolbar { align-items: flex-start; }
  .timeframes { width: 100%; }
  .timeframes button { min-height: 48px; flex: 1 1 0; }
  .legend { min-height: 22px; align-items: center; }
  .data-status { flex-wrap: wrap; }
  .chart-shell {
    height: min(420px, calc(100dvh - 190px));
    min-height: 320px;
  }
}

@media (max-width: 360px) {
  main {
    padding-left: max(9px, env(safe-area-inset-left));
    padding-right: max(9px, env(safe-area-inset-right));
  }

  .legend { gap: 6px 10px; }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
