:root {
  color-scheme: dark;
  --bg: #08111f;
  --panel: #0e1a2c;
  --line: #1d2c44;
  --fg: #ffffff;
  --dim: #93a4bd;
  --off: #5d6b80;
  --sky: #4fc3f7;
  --up: #ffb547;
  --down: #4fc3f7;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--fg); }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
}
button { font: inherit; color: inherit; cursor: pointer; }
a { color: #7cc8ff; }

.app {
  min-height: 100%;
  max-width: 640px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  padding: max(10px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}

.top { position: relative; min-height: 44px; display: flex; align-items: center; justify-content: center; }
.status { display: inline-flex; align-items: center; color: var(--dim); font-size: 15px; }
.dot { width: 10px; height: 10px; border-radius: 50%; margin-right: 8px; background: var(--off); }
.info {
  position: absolute; right: 0; top: 6px; width: 32px; height: 32px; border-radius: 50%;
  border: 1px solid var(--line); background: transparent; color: var(--dim); font-weight: 700; font-style: italic;
}

.reading { flex: 1; min-height: 170px; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.numberRow { display: flex; align-items: flex-end; justify-content: center; max-width: 100%; }
.number {
  font-size: clamp(64px, 24vw, 150px); line-height: 1; font-weight: 700; letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums; white-space: nowrap;
}
.number.stale { color: var(--off); }
.unit { font-size: clamp(22px, 6vw, 36px); color: var(--dim); font-weight: 600; margin: 0 0 0.35em 8px; }
.sub { margin-top: 8px; color: var(--dim); font-size: 16px; min-height: 1.3em; text-align: center; }
.hint { margin-top: 12px; color: var(--dim); font-size: 15px; line-height: 1.4; text-align: center; max-width: 340px; }

.profile { margin-top: 8px; }
.profileHead { display: flex; justify-content: space-between; color: var(--dim); font-size: 13px; letter-spacing: 0.06em; text-transform: uppercase; margin-bottom: 6px; }
.profileHead span:last-child { text-transform: none; letter-spacing: 0; }
.graphBox { position: relative; height: 128px; border-radius: 14px; background: var(--panel); border: 1px solid var(--line); overflow: hidden; }
.graph { display: block; width: 100%; height: 100%; }
.axis { position: absolute; right: 8px; color: var(--dim); font-size: 11px; font-variant-numeric: tabular-nums; }
.axisTop { top: 4px; }
.axisBottom { bottom: 4px; }
.empty { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: var(--off); font-size: 14px; }

.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-top: 14px; }
.stat { text-align: center; padding: 10px 2px; border-radius: 12px; background: var(--panel); border: 1px solid var(--line); min-width: 0; }
.statLabel { color: var(--dim); font-size: 12px; letter-spacing: 0.06em; text-transform: uppercase; }
.statValue { font-size: clamp(17px, 5vw, 24px); font-weight: 600; margin-top: 2px; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.statValue.up { color: var(--up); }
.statValue.down { color: var(--down); }

.buttons { display: flex; gap: 10px; justify-content: center; margin-top: 14px; flex-wrap: wrap; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 22px; overflow: hidden; }
.seg button { min-height: 44px; min-width: 84px; border: 0; background: transparent; color: var(--dim); font-size: 16px; }
.seg button[aria-pressed="true"] { background: var(--sky); color: #04101f; font-weight: 700; }
.reset { min-height: 44px; min-width: 120px; padding: 0 20px; border-radius: 22px; border: 1px solid var(--line); background: var(--panel); font-size: 16px; }
.reset.armed { border-color: var(--up); color: var(--up); }

.sheet {
  position: fixed; inset: 0; background: var(--bg); display: flex; align-items: center; justify-content: center;
  padding: 24px max(24px, env(safe-area-inset-right)) 24px max(24px, env(safe-area-inset-left));
}
.card { max-width: 360px; text-align: center; }
.logo { border-radius: 16px; }
.card h1 { font-size: 30px; margin: 14px 0 8px; }
.card p { color: var(--dim); font-size: 17px; line-height: 1.45; margin: 0 0 22px; }
.card .small { font-size: 15px; margin-top: 22px; }
.card .small a { color: var(--dim); }
.primary {
  min-height: 52px; min-width: 180px; padding: 0 28px; border: 0; border-radius: 26px; background: var(--sky);
  color: #04101f; font-size: 19px; font-weight: 700;
}

dialog {
  width: min(92vw, 400px); background: #0f1b2e; color: var(--fg); border: 1px solid var(--line); border-radius: 18px;
  padding: 22px; line-height: 1.45;
}
dialog::backdrop { background: rgba(0, 0, 0, 0.7); }
dialog h2 { margin: 0 0 6px; font-size: 24px; }
dialog p { color: var(--dim); font-size: 15px; }
dialog .primary { display: block; margin: 18px auto 0; }

@media (max-height: 640px) {
  .reading { min-height: 130px; }
  .graphBox { height: 96px; }
  .number { font-size: clamp(56px, 20vw, 110px); }
}
