/* Lag Watch: calm single-column layout, mobile first. System fonts only (CSP font-src 'self'). */

:root {
  color-scheme: light dark;

  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --fg: #15181e;
  --muted: #4b5262;
  --border: #dde1e7;
  --border-strong: #767d8c;
  --focus: #1d4ed8;
  --btn-bg: #1d4ed8;
  --btn-fg: #ffffff;
  --notice-bg: #fff4d6;
  --notice-fg: #4a3500;
  --demo-bg: #5b21b6;
  --demo-fg: #ffffff;
  --tag-bg: #ffffff;
  --switch-on: #1d4ed8;
  --switch-off: #767d8c;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 4px 16px rgba(16, 24, 40, 0.06);

  --tint-clear: #e2f3e7;
  --icon-clear: #17713a;
  --tint-minor: #fbf1cf;
  --icon-minor: #7a5600;
  --tint-laggy: #fde4cf;
  --icon-laggy: #9a3f00;
  --tint-severe: #fadcdc;
  --icon-severe: #a8201a;
  --tint-neutral: #e9edf2;
  --icon-neutral: #4b5262;
  --tint-problem: #ece3f6;
  --icon-problem: #5b2a91;

  /* Read by js/chart.js (re-read on a colour-scheme change). */
  --chart-line: #1d4ed8;
  --chart-base: #5b6270;
  --chart-grid: #e4e7ec;
  --chart-text: #4b5262;
  --chart-up: #b54708;
  --chart-down: #6d28d9;
  --chart-both: #a21caf;

  --radius: 14px;
  --radius-small: 10px;
  --gutter: 16px;
  --column: 44rem;
  --duration: 300ms;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1116;
    --surface: #161a21;
    --surface-2: #1d222b;
    --fg: #e9ecf1;
    --muted: #aab1be;
    --border: #2c323d;
    --border-strong: #7a8292;
    --focus: #7ea6ff;
    --btn-bg: #7ea6ff;
    --btn-fg: #0b0e13;
    --notice-bg: #3a2e0a;
    --notice-fg: #fbe7a6;
    --demo-bg: #c4b5fd;
    --demo-fg: #1e0b4b;
    --tag-bg: #0e1116;
    --switch-on: #7ea6ff;
    --switch-off: #7a8292;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 4px 16px rgba(0, 0, 0, 0.3);

    --tint-clear: #10291a;
    --icon-clear: #5ad08a;
    --tint-minor: #2e260b;
    --icon-minor: #f2c94c;
    --tint-laggy: #36210f;
    --icon-laggy: #ffa463;
    --tint-severe: #3a1517;
    --icon-severe: #ff8b85;
    --tint-neutral: #1f242d;
    --icon-neutral: #aab1be;
    --tint-problem: #2a1d3b;
    --icon-problem: #c8a2f5;

    --chart-line: #7ea6ff;
    --chart-base: #aab1be;
    --chart-grid: #2a303a;
    --chart-text: #aab1be;
    --chart-up: #ffa463;
    --chart-down: #c8a2f5;
    --chart-both: #f78fd0;
  }
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  scroll-padding-top: 4rem; /* keeps focused controls clear of the sticky demo banner */
}

body {
  margin: 0;
  min-width: 320px;
  background: var(--bg);
  color: var(--fg);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
  font-size: 1.125rem;
  line-height: 1.55;
  overflow-wrap: break-word;
}

.site-header,
main,
.site-footer {
  width: 100%;
  max-width: calc(var(--column) + 2 * var(--gutter));
  margin: 0 auto;
  padding: 0 var(--gutter);
}

h1,
h2,
h3 {
  line-height: 1.2;
  margin: 0 0 0.5rem;
}

h1 {
  font-size: 1.75rem;
  letter-spacing: -0.01em;
}

h2 {
  font-size: 1.375rem;
}

h3 {
  font-size: 1.125rem;
}

p {
  margin: 0 0 0.75rem;
}

a {
  color: var(--focus);
}

/* :focus for browsers without :focus-visible (Chromium < 86, Safari < 15.4); newer ones drop the ring on click. */
:focus {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

:focus:not(:focus-visible) {
  outline: none;
}

:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

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

.sprite {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
}

.muted {
  color: var(--muted);
}

.hint {
  color: var(--muted);
  font-size: 1.125rem;
  margin: 0.35rem 0 0;
}

/* ---- header / banners ---- */

.site-header {
  padding-top: 1.5rem;
  padding-bottom: 0.5rem;
}

.hero {
  color: var(--muted);
  max-width: 34rem;
}

.demo-banner {
  position: sticky;
  top: 0;
  z-index: 10;
  margin: 0;
  padding: 0.6rem var(--gutter);
  text-align: center;
  font-weight: 700;
  letter-spacing: 0.02em;
  background: var(--demo-bg);
  color: var(--demo-fg);
}

.notice,
.needs-newer {
  background: var(--notice-bg);
  color: var(--notice-fg);
  border-radius: var(--radius-small);
  padding: 0.75rem 1rem;
}

.needs-newer {
  font-weight: 600;
}

/* ---- status card ---- */

.live {
  margin-top: 0.5rem;
}

.card {
  --tint: var(--tint-neutral);
  --icon: var(--icon-neutral);
  background: var(--tint);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.25rem 1.25rem 1rem;
  margin-bottom: 0.75rem;
  transition: background-color var(--duration) ease;
}

.card[data-level="clear"] {
  --tint: var(--tint-clear);
  --icon: var(--icon-clear);
}

.card[data-level="minor"] {
  --tint: var(--tint-minor);
  --icon: var(--icon-minor);
}

.card[data-level="laggy"] {
  --tint: var(--tint-laggy);
  --icon: var(--icon-laggy);
}

.card[data-level="severe"],
.card[data-level="no-reply"] {
  --tint: var(--tint-severe);
  --icon: var(--icon-severe);
}

.card[data-level="offline"],
.card[data-level="unreachable"] {
  --tint: var(--tint-problem);
  --icon: var(--icon-problem);
}

.card-head {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.25rem;
}

.level-icon {
  flex: none;
  width: 2.75rem;
  height: 2.75rem;
  color: var(--icon);
}

.level {
  margin: 0;
  font-size: 2rem;
  font-weight: 750;
  line-height: 1.15;
  letter-spacing: -0.01em;
  min-width: 0;
}

.live-dot {
  flex: none;
  width: 0.75rem;
  height: 0.75rem;
  margin-left: auto;
  border-radius: 50%;
  background: var(--icon);
  opacity: 0;
}

.card[data-live="true"] .live-dot {
  opacity: 1;
  animation: live-pulse 2s ease-in-out infinite;
}

@keyframes live-pulse {
  0%,
  100% {
    opacity: 1;
  }

  50% {
    opacity: 0.3;
  }
}

.added {
  margin: 0.25rem 0 0.5rem;
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.5rem;
}

.added-value {
  font-size: 2.75rem;
  font-weight: 750;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}

.added-label {
  color: var(--muted);
  font-weight: 600;
}

.detail {
  font-size: 1.125rem;
}

.ping {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}

.direction {
  font-weight: 600;
  border-left: 4px solid var(--icon);
  padding-left: 0.75rem;
}

.retry {
  color: var(--muted);
}

.advice {
  margin: 0 0 0.75rem;
  padding-left: 1.25rem;
}

.advice li + li {
  margin-top: 0.4rem;
}

.tags {
  list-style: none;
  margin: 0.25rem 0 0.25rem;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.tags li {
  background: var(--tag-bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.2rem 0.75rem;
  font-size: 1.125rem;
}

.cell-hold {
  margin: 0.5rem 0 0.25rem;
}

.data-note {
  color: var(--muted);
  font-size: 1.125rem;
  margin-bottom: 1.25rem;
}

/* ---- buttons and toggles ---- */

.btn {
  font: inherit;
  font-weight: 600;
  min-height: 44px;
  min-width: 44px;
  padding: 0.55rem 1.1rem;
  border-radius: var(--radius-small);
  border: 2px solid var(--border-strong);
  background: var(--surface);
  color: var(--fg);
  cursor: pointer;
  text-align: center;
}

.btn:hover {
  background: var(--surface-2);
}

.btn:active {
  transform: translateY(1px);
}

.btn-primary {
  background: var(--btn-bg);
  border-color: var(--btn-bg);
  color: var(--btn-fg);
}

.btn-primary:hover {
  background: var(--btn-bg);
  filter: brightness(1.08);
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none;
}

.controls {
  display: grid;
  gap: 0.75rem;
  margin-bottom: 1.5rem;
}

.controls > .btn-primary {
  justify-self: start;
  min-width: 8rem;
}

.toggle {
  display: flex;
  align-items: flex-start;
  gap: 0.85rem;
  width: 100%;
  text-align: left;
  font-weight: 400;
}

.toggle-name {
  font-weight: 700;
}

.toggle-desc {
  color: var(--muted);
}

.switch {
  flex: none;
  position: relative;
  width: 2.75rem;
  height: 1.5rem;
  margin-top: 0.1rem;
  border-radius: 999px;
  border: 2px solid var(--switch-off);
  background: var(--surface);
  transition: background-color var(--duration) ease;
}

.switch::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: calc(1.5rem - 8px);
  height: calc(1.5rem - 8px);
  border-radius: 50%;
  background: var(--switch-off);
  transition: transform var(--duration) ease;
}

.toggle[aria-pressed="true"] .switch {
  background: var(--switch-on);
  border-color: var(--switch-on);
}

.toggle[aria-pressed="true"] .switch::after {
  background: var(--btn-fg);
  transform: translateX(1.25rem);
}

.wake .notice {
  margin-top: 0.5rem;
}

.button-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
}

/* ---- panels: chart, events, details, test, limits ---- */

.panel {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1rem 1.25rem;
  margin-bottom: 1.25rem;
}

.chart {
  width: 100%;
  max-width: 100%;
  overflow: hidden;
}

.events {
  list-style: none;
  margin: 0;
  padding: 0;
}

.events li {
  padding: 0.55rem 0;
  border-top: 1px solid var(--border);
  font-variant-numeric: tabular-nums;
}

.events li:first-child {
  border-top: 0;
}

/* display:flex drops the native disclosure marker, so draw one (and hide WebKit's own). */
.details summary {
  cursor: pointer;
  font-weight: 700;
  min-height: 44px;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  list-style: none;
}

.details summary::-webkit-details-marker {
  display: none;
}

.details summary::before {
  content: "▸";
  flex: none;
  width: 1rem;
  color: var(--muted);
}

.details[open] summary::before {
  content: "▾";
}

.details[open] summary {
  margin-bottom: 0.5rem;
}

.debug {
  font-family: ui-monospace, "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 1rem;
  color: var(--muted);
}

.test .confirm {
  border: 2px solid var(--border-strong);
  border-radius: var(--radius-small);
  padding: 1rem;
  margin-bottom: 1rem;
}

.progress {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.result {
  border-top: 1px solid var(--border);
  padding-top: 1rem;
}

.result-headline {
  font-size: 1.375rem;
  font-weight: 700;
  line-height: 1.35;
}

.result-grade {
  color: var(--muted);
  font-size: 1.125rem;
}

.result-notes {
  padding-left: 1.25rem;
  color: var(--muted);
}

.limits ul {
  margin: 0;
  padding-left: 1.25rem;
}

.limits li + li {
  margin-top: 0.6rem;
}

.site-footer {
  color: var(--muted);
  font-size: 1.125rem;
  padding-top: 0.5rem;
  padding-bottom: 2.5rem;
}

.not-found {
  margin-top: 1rem;
}

.not-found .btn {
  display: inline-block;
  text-decoration: none;
}

/* 320 px: leave the card title room for "Connection" on one line */
@media (max-width: 22.5rem) {
  .level {
    font-size: 1.75rem;
  }
}

@media (min-width: 40rem) {
  h1 {
    font-size: 2.125rem;
  }

  .card {
    padding: 1.5rem 1.75rem 1.25rem;
  }

  .level {
    font-size: 2.375rem;
  }

  .added-value {
    font-size: 3.25rem;
  }
}

/* Forced colours (Windows High Contrast): the UA repaints backgrounds as Canvas, which would hide the switch knob
   and its "on" fill. Paint the switch with system colours; the knob's border and position also carry the state. */
@media (forced-colors: active) {
  .switch {
    forced-color-adjust: none;
    background: Canvas;
    border-color: ButtonText;
  }

  .switch::after {
    background: ButtonText;
    border: 2px solid ButtonText;
  }

  .toggle[aria-pressed="true"] .switch {
    background: Highlight;
    border-color: Highlight;
  }

  .toggle[aria-pressed="true"] .switch::after {
    background: HighlightText;
    border-color: HighlightText;
  }

  /* The chart canvas is drawn in the page's own colours: keep the background they were chosen for. */
  .chart {
    forced-color-adjust: none;
    background: var(--surface);
  }
}

@media (prefers-reduced-motion: reduce) {
  .card,
  .switch,
  .switch::after {
    transition: none;
  }

  .card[data-live="true"] .live-dot {
    animation: none;
  }

  .btn:active {
    transform: none;
  }
}
