/* iOS dark-mode system palette and type scale. */
:root {
  --bg: #000;
  --card: #1c1c1e;
  --label: #fff;
  --label-2: rgba(235, 235, 245, 0.6);
  --label-3: rgba(235, 235, 245, 0.3);
  --separator: rgba(84, 84, 88, 0.6);
  --fill: rgba(120, 120, 128, 0.24);
  --bar: rgba(235, 235, 245, 0.32);
  --green: #30d158;
  --yellow: #ffd60a;
  --orange: #ff9f0a;
  --red: #ff453a;
  --blue: #0a84ff;
  --radius: 16px;
  --ease: cubic-bezier(0.32, 0.72, 0, 1);
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--label);
  font: 17px/1.29 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue", sans-serif;
  letter-spacing: -0.01em;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
}

main {
  max-width: 520px;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 12px) 16px calc(env(safe-area-inset-bottom) + 32px);
}

button { font: inherit; color: inherit; border: 0; background: none; padding: 0; cursor: pointer; }
button:active { opacity: 0.6; }
ol { list-style: none; margin: 0; padding: 0; }
[hidden] { display: none !important; }

/* Header */
.masthead { display: flex; align-items: flex-start; justify-content: space-between; padding-top: 8px; }
h1 { margin: 0; font-size: 34px; line-height: 41px; font-weight: 700; letter-spacing: 0.01em; }
.subtitle { margin: 0; font-size: 20px; line-height: 25px; font-weight: 600; color: var(--label-2); }
.open-status { display: flex; align-items: center; gap: 6px; margin: 8px 0 20px; font-size: 15px; color: var(--label-2); }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--green); }
.open-status.is-closed .status-dot { background: var(--label-3); }

.round-btn {
  width: 36px; height: 36px; margin-top: 4px; border-radius: 50%;
  display: grid; place-items: center; background: var(--fill); color: var(--blue);
}
.round-btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.round-btn.spinning svg { animation: spin 0.8s linear infinite; }

/* Segmented control */
.segmented {
  position: relative; display: grid; grid-template-columns: 1fr 1fr;
  height: 32px; padding: 2px; margin-bottom: 16px; border-radius: 9px; background: var(--fill);
}
.segmented button { position: relative; z-index: 1; font-size: 13px; font-weight: 500; }
.segmented button[aria-selected="true"] { font-weight: 600; }
.segmented button:active { opacity: 1; }
.segmented-thumb {
  position: absolute; top: 2px; bottom: 2px; left: 2px; width: calc(50% - 2px); border-radius: 7px;
  background: #636366; box-shadow: 0 3px 8px rgba(0, 0, 0, 0.12), 0 3px 1px rgba(0, 0, 0, 0.04);
  transition: transform 0.3s var(--ease);
}
.segmented[data-selected="1"] .segmented-thumb { transform: translateX(100%); }

/* Cards */
.card { background: var(--card); border-radius: var(--radius); padding: 14px 16px 16px; margin-bottom: 12px; }
h2 { margin: 0; font-size: 13px; line-height: 18px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.02em; color: var(--label-2); }
.card > h2, .card-head { padding-bottom: 10px; margin-bottom: 2px; border-bottom: 0.5px solid var(--separator); }
.card-head { display: flex; justify-content: space-between; align-items: baseline; }
.caption { font-size: 13px; color: var(--label-2); font-variant-numeric: tabular-nums; }
.footnote { margin: 12px 0 0; font-size: 13px; color: var(--label-2); }
.footnote:empty { display: none; }

/* Hero */
.hero { padding: 16px 16px 18px; }
.hero-top { display: flex; justify-content: space-between; align-items: center; }
.pill { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 600; color: var(--label-2); }
.pill.live { color: var(--red); }
.pill.live::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; animation: blink 2s ease-in-out infinite; }
.hero-reading { display: flex; align-items: flex-start; margin-top: 6px; }
.hero-number { font-size: 76px; line-height: 1; font-weight: 200; letter-spacing: -0.04em; font-variant-numeric: tabular-nums; }
.hero-unit { font-size: 28px; line-height: 1; font-weight: 300; margin: 8px 0 0 2px; color: var(--label-2); }
.hero-level { margin-top: 6px; font-size: 22px; line-height: 28px; font-weight: 600; }
.hero-detail { margin-top: 2px; font-size: 15px; line-height: 20px; color: var(--label-2); }

.scale { margin-top: 16px; }
.scale-track {
  position: relative; height: 6px; border-radius: 3px;
  background: linear-gradient(90deg, var(--green), var(--yellow) 38%, var(--orange) 66%, var(--red));
}
.scale-dot {
  position: absolute; top: 50%; width: 14px; height: 14px; border-radius: 50%;
  background: #fff; border: 3px solid var(--card); transform: translate(-50%, -50%);
  transition: left 0.6s var(--ease);
}
.scale-labels { display: flex; justify-content: space-between; margin-top: 6px; font-size: 12px; color: var(--label-3); }

.tinted-btn {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%; height: 44px; margin-top: 18px; border-radius: 12px;
  font-size: 17px; font-weight: 600; color: var(--blue); background: rgba(10, 132, 255, 0.15);
}
.spinner { display: none; width: 16px; height: 16px; border-radius: 50%; border: 2px solid currentColor; border-right-color: transparent; animation: spin 0.8s linear infinite; }
.tinted-btn.spinning .spinner { display: block; }
.tinted-btn.spinning { pointer-events: none; }

/* Rows */
.rows li {
  display: grid; grid-template-columns: minmax(64px, auto) 1fr 100px; align-items: center; gap: 12px;
  min-height: 44px; border-bottom: 0.5px solid var(--separator);
}
.rows li:last-child { border-bottom: 0; }
.rows li.window-row { grid-template-columns: 1fr auto; }
.level-dot { display: inline-block; width: 8px; height: 8px; margin-right: 8px; border-radius: 50%; vertical-align: 1px; }
.rows li.empty { display: block; padding: 12px 0 0; min-height: 0; font-size: 15px; color: var(--label-2); }
.row-label { font-size: 17px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.capsule { height: 6px; border-radius: 3px; background: var(--fill); overflow: hidden; }
.capsule-fill { display: block; height: 100%; border-radius: 3px; transition: width 0.6s var(--ease); }
.row-value { font-size: 15px; color: var(--label-2); text-align: right; }

/* Chart */
.chart { position: relative; height: 176px; margin-top: 12px; touch-action: none; cursor: pointer; }
.chart-labels { position: absolute; top: 0; left: 0; right: 0; height: 16px; font-size: 11px; font-weight: 500; color: var(--label-2); }
.boundary-label { position: absolute; top: 0; white-space: nowrap; }
.boundary-label-open { transform: translateX(4px); }
.boundary-label-close { transform: translateX(calc(-100% - 4px)); }
.plot { position: absolute; top: 22px; left: 0; right: 0; bottom: 0; }
.gridlines {
  position: absolute; inset: 0; pointer-events: none; opacity: 0.6;
  background: repeating-linear-gradient(to top, var(--separator) 0 0.5px, transparent 0.5px 50%);
}
.bars { position: absolute; inset: 0; display: flex; align-items: flex-end; gap: 3px; }
.col { position: relative; flex: 1; height: 100%; display: flex; align-items: flex-end; border-radius: 3px; }
.closed-band { position: absolute; top: 0; bottom: 0; border-radius: 4px; background: rgba(120, 120, 128, 0.1); }
.bar { width: 100%; border-radius: 3px 3px 1px 1px; background: var(--bar); opacity: 0.8; transition: height 0.5s var(--ease), opacity 0.3s; }
.col.past .bar { opacity: 0.25; }
.col.now .bar { opacity: 1; }
.col.selected .bar { opacity: 1; box-shadow: inset 0 0 0 1.5px rgba(255, 255, 255, 0.85); }
.boundary { position: absolute; top: -6px; bottom: 0; width: 0; border-left: 1px dashed var(--label-3); }

.now-marker { position: absolute; left: 50%; width: 0; height: 0; pointer-events: none; z-index: 2; }
.now-dot {
  position: absolute; left: -6px; top: -6px; width: 12px; height: 12px; border-radius: 50%;
  background: var(--label); box-shadow: 0 0 0 2.5px var(--card);
}
.now-dot::after {
  content: ""; position: absolute; inset: -2px; border-radius: 50%;
  background: var(--level); animation: ripple 1.8s var(--ease) infinite;
}
.now-tag {
  position: absolute; bottom: 12px; left: 0; transform: translateX(-50%); white-space: nowrap;
  padding: 2px 7px; border-radius: 6px; font-size: 11px; font-weight: 600; color: #000; background: var(--label);
}
.now-tag.below { bottom: auto; top: 12px; }
.now-marker.is-live .now-tag { background: var(--level); }

.chart-axis { position: relative; height: 16px; margin-top: 6px; font-size: 11px; color: var(--label-2); }
.chart-axis span { position: absolute; top: 0; white-space: nowrap; }
.readout { margin: 10px 0 0; font-size: 15px; color: var(--label-2); font-variant-numeric: tabular-nums; }

.footer { margin: 16px 0 0; text-align: center; font-size: 12px; line-height: 16px; color: var(--label-3); }
.footer.error { color: var(--red); }

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes blink { 50% { opacity: 0.3; } }
@keyframes ripple {
  0% { transform: scale(1); opacity: 0.6; }
  100% { transform: scale(3.2); opacity: 0; }
}

body.loading .card { opacity: 0.5; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
