:root {
  --bg: #f9f9f9;
  --surface: #ffffff;
  --ink: #191919;
  --ink-2: #666666;
  --line: #e7e7e7;
  --line-2: #c2c2c2;
  --accent: #257de0;

  --good: #0aac23;
  --warn: #fbb315;
  --serious: #f18a59;
  --crit: #dc3c3d;
  --nodata: #d6d6d6;
  --band: rgba(220, 60, 61, 0.08);

  /* status as text: darker steps so they clear 4.5:1 on white */
  --t-good: #0b7a1d;
  --t-warn: #8a5d00;
  --t-serious: #b04a17;
  --t-crit: #c42b2c;

  --radius: 8px;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b0b0b;
    --surface: #191919;
    --ink: #efefef;
    --ink-2: #9c9c9c;
    --line: #303030;
    --line-2: #474747;
    --accent: #338ced;
    --nodata: #3a3a3a;
    --band: rgba(220, 60, 61, 0.14);
    --t-good: #2fc244;
    --t-warn: #fbb315;
    --t-serious: #f18a59;
    --t-crit: #ef6061;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, 'Segoe UI', Inter, Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); }
code { font: 0.92em ui-monospace, SFMono-Regular, Menlo, monospace; }
.wrap { max-width: 880px; margin: 0 auto; padding: 0 20px; }
.muted { color: var(--ink-2); font-weight: 400; }
.small { font-size: 13px; }
[hidden] { display: none !important; }

/* ---- top bar ---- */
.topbar { background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.topbar-inner { display: flex; align-items: center; justify-content: space-between; height: 60px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 19px; letter-spacing: -0.02em; color: var(--ink); text-decoration: none; }
.pulse { width: 10px; height: 10px; border-radius: 50%; background: var(--good); box-shadow: 0 0 0 0 rgba(10, 172, 35, 0.5); animation: pulse 2s infinite; }
@keyframes pulse { 70% { box-shadow: 0 0 0 8px rgba(10, 172, 35, 0); } 100% { box-shadow: 0 0 0 0 rgba(10, 172, 35, 0); } }
@media (prefers-reduced-motion: reduce) { .pulse { animation: none; } }
.topbar-actions { display: flex; align-items: center; gap: 8px; }

/* km / mi pill toggle */
.units {
  position: relative; display: inline-grid; grid-template-columns: 1fr 1fr;
  padding: 3px; border-radius: 999px; background: var(--bg); border: 1px solid var(--line);
  margin-right: 4px;
}
.units button {
  position: relative; z-index: 1; font: inherit; font-size: 13px; font-weight: 600;
  min-width: 38px; padding: 4px 10px; border: 0; border-radius: 999px; background: none;
  color: var(--ink-2); cursor: pointer; transition: color 0.2s;
}
.units button[aria-checked="true"] { color: var(--ink); cursor: default; }
.units button:not([aria-checked="true"]):hover { color: var(--ink); }
.units button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.units-thumb {
  position: absolute; top: 3px; bottom: 3px; left: 3px; width: calc(50% - 3px);
  border-radius: 999px; background: var(--surface);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.12), 0 0 0 1px var(--line);
  transition: transform 0.2s ease;
}
.units.is-mi .units-thumb { transform: translateX(100%); }
@media (prefers-reduced-motion: reduce) { .units-thumb, .units button { transition: none; } }

.btn {
  font: inherit; font-size: 14px; font-weight: 500; cursor: pointer;
  padding: 7px 14px; border-radius: 6px; border: 1px solid var(--line-2);
  background: var(--surface); color: var(--ink);
}
.btn:hover { border-color: var(--ink-2); }
.btn.primary { background: var(--ink); color: var(--surface); border-color: var(--ink); }
.btn.ghost { border-color: transparent; color: var(--ink-2); }
.btn.ghost:hover { color: var(--ink); background: var(--bg); }
.btn.link { border: 0; background: none; color: var(--accent); padding: 4px 0; }
.btn:focus-visible, .dropzone:focus-visible, input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---- landing ---- */
.landing { max-width: 600px; margin: 0 auto; padding: 64px 0 80px; text-align: center; }
.landing h1 { font-size: 40px; line-height: 1.1; letter-spacing: -0.03em; margin: 0 0 14px; }
.lede { color: var(--ink-2); font-size: 17px; margin: 0 0 32px; }
.lede strong { color: var(--ink); }
.dropzone {
  display: flex; flex-direction: column; align-items: center; gap: 6px; cursor: pointer;
  padding: 40px 24px; border: 2px dashed var(--line-2); border-radius: 12px; background: var(--surface);
  color: var(--ink-2); transition: border-color 0.15s, background 0.15s;
}
.dropzone:hover, .dropzone.over { border-color: var(--good); background: color-mix(in srgb, var(--good) 5%, var(--surface)); }
.dz-title { color: var(--ink); font-weight: 600; font-size: 16px; }
.dz-sub { font-size: 13px; }
.error { color: var(--t-crit); margin: 12px 0 0; }
.or { display: flex; align-items: center; gap: 12px; color: var(--ink-2); font-size: 13px; margin: 28px 0 16px; }
.or::before, .or::after { content: ''; flex: 1; height: 1px; background: var(--line); }
.strava { display: flex; gap: 8px; }
.strava input {
  flex: 1; font: inherit; font-size: 14px; padding: 8px 12px; border-radius: 6px;
  border: 1px solid var(--line-2); background: var(--surface); color: var(--ink);
}
.hint { font-size: 13px; color: var(--ink-2); text-align: left; margin: 8px 0 0; }
.hint.bad { color: var(--t-crit); }
.demo-row { margin-top: 28px; }
.privacy { font-size: 12px; color: var(--ink-2); margin-top: 40px; }

/* ---- status page ---- */
#page { padding: 36px 0 60px; }
.page-head { margin-bottom: 20px; }
.svc-name { font-size: 30px; letter-spacing: -0.02em; margin: 0; line-height: 1.2; }
#svc-name { outline: none; border-radius: 4px; padding: 0 2px; margin: 0 -2px; }
#svc-name:hover, #svc-name:focus { background: var(--surface); box-shadow: 0 0 0 1px var(--line-2); }
.page-head p { margin: 4px 0 0; }

.banner {
  display: flex; align-items: center; gap: 12px; color: #fff; font-weight: 600; font-size: 18px;
  padding: 16px 20px; border-radius: var(--radius); margin-bottom: 20px;
}
.banner.s-operational { background: var(--good); }
.banner.s-degraded { background: var(--warn); color: #0b0b0b; }
.banner.s-partial { background: var(--serious); color: #0b0b0b; }
.banner.s-major { background: var(--crit); }
.banner-icon {
  width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; font-size: 14px;
  background: rgba(255, 255, 255, 0.25);
}
.banner-meta { margin-left: auto; font-size: 13px; font-weight: 400; opacity: 0.9; }

.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; margin-bottom: 20px; }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; box-shadow: var(--shadow); }
.tile-k { font-size: 12px; color: var(--ink-2); text-transform: uppercase; letter-spacing: 0.04em; font-weight: 600; }
.tile-v { font-size: 20px; font-weight: 650; letter-spacing: -0.01em; margin-top: 2px; font-variant-numeric: tabular-nums; }
.tile-sub { font-size: 12px; color: var(--ink-2); }
.tile.hero { grid-column: span 2; }
.tile.hero .tile-v { font-size: 30px; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 20px; box-shadow: var(--shadow); }
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; padding: 14px 20px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.card-head h2 { font-size: 16px; margin: 0; }

.component { padding: 16px 20px; border-bottom: 1px solid var(--line); }
.component:last-child { border-bottom: 0; }
.comp-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 10px; }
.comp-name { font-weight: 600; }
.comp-status { font-size: 14px; }
.help {
  display: inline-grid; place-items: center; width: 16px; height: 16px; border-radius: 50%; font-size: 11px;
  border: 1px solid var(--line-2); color: var(--ink-2); cursor: help; font-weight: 600; vertical-align: 1px; margin-left: 4px;
}
.t-operational { color: var(--t-good); }
.t-degraded { color: var(--t-warn); }
.t-partial { color: var(--t-serious); }
.t-major { color: var(--t-crit); }

.bars { display: flex; gap: 2px; height: 34px; }
.bar { flex: 1; border-radius: 2px; min-width: 2px; cursor: default; transition: opacity 0.1s; }
.bars:hover .bar { opacity: 0.55; }
.bars .bar:hover { opacity: 1; }
.s-operational { background: var(--good); }
.s-degraded { background: var(--warn); }
.s-partial { background: var(--serious); }
.s-major { background: var(--crit); }
.s-nodata { background: var(--nodata); }
.bars-foot { display: flex; align-items: center; gap: 10px; font-size: 12px; color: var(--ink-2); margin-top: 8px; }
.bars-foot .rule { flex: 1; height: 1px; background: var(--line); }

/* charts */
.chart { padding: 16px 20px 12px; border-bottom: 1px solid var(--line); }
.chart:last-child { border-bottom: 0; }
.chart-title { font-weight: 600; font-size: 14px; margin-bottom: 8px; }
.chart-body { display: flex; gap: 8px; }
.y-axis { display: flex; flex-direction: column; justify-content: space-between; font-size: 11px; color: var(--ink-2); width: 64px; text-align: right; font-variant-numeric: tabular-nums; }
.plot { position: relative; flex: 1; height: 140px; cursor: crosshair; touch-action: pan-y; }
.plot svg { display: block; width: 100%; height: 100%; overflow: visible; }
.plot .grid { stroke: var(--line); stroke-width: 1; vector-effect: non-scaling-stroke; }
.plot .base { stroke: var(--line-2); stroke-width: 1; vector-effect: non-scaling-stroke; }
.plot .line { fill: none; stroke: var(--accent); stroke-width: 2; vector-effect: non-scaling-stroke; stroke-linejoin: round; }
.plot .area { fill: var(--accent); opacity: 0.1; }
.plot .stop-band { fill: var(--band); }
.crosshair { position: absolute; top: 0; bottom: 0; width: 1px; background: var(--line-2); pointer-events: none; }
.dot { position: absolute; width: 10px; height: 10px; margin: -5px 0 0 -5px; border-radius: 50%; background: var(--accent); border: 2px solid var(--surface); pointer-events: none; }
.x-axis { display: flex; justify-content: space-between; font-size: 11px; color: var(--ink-2); margin: 6px 0 0 72px; }

/* incidents */
.incidents .day { font-size: 15px; margin: 0; padding: 14px 20px 0; border-bottom: 0; }
.incidents > .muted { padding: 0 20px 6px; }
.incident { padding: 14px 20px; border-bottom: 1px solid var(--line); }
.incident:last-child { border-bottom: 0; }
.incident h4 { margin: 0 0 8px; font-size: 16px; }
.upd { margin: 0 0 10px; font-size: 14px; }
.incident > p:last-child { margin: 0; }

.maint-item { padding: 14px 20px; }
.maint-title { font-weight: 600; color: var(--accent); margin-bottom: 4px; }
.maint-item p { margin: 0 0 4px; font-size: 14px; }

.foot { text-align: center; padding: 10px 0 0; }
.legend { display: flex; justify-content: center; flex-wrap: wrap; gap: 16px; font-size: 13px; color: var(--ink-2); margin-bottom: 10px; }
.sw { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 6px; vertical-align: -1px; }

.credit { text-align: center; font-size: 13px; color: var(--ink-2); padding: 0 20px 32px; }
.credit a { color: var(--ink); font-weight: 500; text-decoration: none; border-bottom: 1px solid var(--line-2); }
.credit a:hover { border-bottom-color: var(--ink); }

/* shared view */
.shared-note {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 10px 16px; margin-bottom: 24px; font-size: 14px; color: var(--ink-2);
}

/* share dialog */
.share-dialog {
  width: min(640px, calc(100vw - 32px)); border: 1px solid var(--line); border-radius: 12px; padding: 20px;
  background: var(--surface); color: var(--ink); box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25);
}
.share-dialog::backdrop { background: rgba(0, 0, 0, 0.45); }
.share-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.share-head h2 { font-size: 18px; margin: 0; }
.share-head .close { padding: 4px 10px; }
.share-preview { border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: #fff; aspect-ratio: 1200 / 675; }
.share-preview img { display: block; width: 100%; height: 100%; }
.share-actions { display: flex; gap: 8px; flex-wrap: wrap; margin: 14px 0 18px; }
.share-link-label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; }
.share-link { display: flex; gap: 8px; }
.share-link input {
  flex: 1; min-width: 0; font: 13px ui-monospace, SFMono-Regular, Menlo, monospace; padding: 8px 10px;
  border-radius: 6px; border: 1px solid var(--line-2); background: var(--bg); color: var(--ink-2);
}
.share-dialog p { margin: 12px 0 0; }

/* tooltip + toast */
.tooltip {
  position: absolute; z-index: 20; pointer-events: none; max-width: 280px;
  background: var(--surface); color: var(--ink); border: 1px solid var(--line-2); border-radius: 6px;
  padding: 8px 10px; font-size: 13px; box-shadow: 0 6px 20px rgba(0, 0, 0, 0.12);
}
.tt-time { font-size: 12px; color: var(--ink-2); }
.tt-status { font-weight: 600; }
.tt-val { font-variant-numeric: tabular-nums; }
.tt-inc { font-size: 12px; margin-top: 4px; padding-top: 4px; border-top: 1px solid var(--line); }
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 30;
  background: var(--ink); color: var(--surface); padding: 10px 16px; border-radius: 8px; font-size: 14px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.2);
}

@media (max-width: 600px) {
  .landing h1 { font-size: 30px; }
  .tile.hero { grid-column: span 1; }
  .banner { flex-wrap: wrap; font-size: 16px; }
  .banner-meta { margin-left: 38px; }
  .topbar-actions #subscribe { display: none; }
  .topbar-actions { gap: 4px; }
  .bars { height: 28px; gap: 1px; }
  .bar { border-radius: 1px; }
  .y-axis { width: 52px; }
  .x-axis { margin-left: 60px; }
}
