/* Cloudflare-style layout. The original page uses style.css (see classic.html). */

:root {
  color-scheme: light;
  --bg: #ffffff;
  --panel: #ffffff;
  --panel-2: #f6f6f6;
  --border: #e3e3e3;
  --grid: #e9e9e9;
  --text: #1b1b1b;
  --muted: #6b6b6b;
  --down: #f38020;
  --up: #8e5fe0;
  --lat: #3c7ce0;
  --error: #d0312d;
  --overlay: rgba(255, 255, 255, 0.55);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #111111;
    --panel: #111111;
    --panel-2: #1b1b1b;
    --border: #2e2e2e;
    --grid: #2a2a2a;
    --text: #f2f2f2;
    --muted: #a0a0a0;
    --up: #c3a3f7;
    --lat: #7fabf3;
    --error: #ff6b6b;
    --overlay: rgba(17, 17, 17, 0.55);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111111;
  --panel: #111111;
  --panel-2: #1b1b1b;
  --border: #2e2e2e;
  --grid: #2a2a2a;
  --text: #f2f2f2;
  --muted: #a0a0a0;
  --up: #c3a3f7;
  --lat: #7fabf3;
  --error: #ff6b6b;
  --overlay: rgba(17, 17, 17, 0.55);
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
  overflow-x: clip;
}
button { font: inherit; color: inherit; }
svg { display: block; }

.top, .layout, .foot {
  width: 100%;
  max-width: 1480px;
  margin: 0 auto;
  padding-inline: 28px;
}

/* Header */
.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-block: 18px;
  position: relative;
}
.top::after {
  content: "";
  position: absolute;
  left: 28px; right: 28px; bottom: 0;
  border-bottom: 1px solid var(--border);
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
  text-decoration: none;
  font-size: 1.45rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}
.brand-mark { width: 34px; height: 34px; }
.brand-mark .bm-arc { stroke: var(--down); }

.icon-btn {
  display: grid;
  place-items: center;
  width: 36px; height: 36px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  cursor: pointer;
}
.icon-btn:hover:not(:disabled) { background: var(--panel-2); }
.icon-btn:disabled { opacity: .4; cursor: default; }
.icon-btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn.round { border: 1px solid var(--border); border-radius: 50%; width: 40px; height: 40px; }
#theme .sun { display: none; }
#pause .i-play { display: none; }
#pause.paused .i-pause { display: none; }
#pause.paused .i-play { display: inline; }
:root[data-theme="dark"] #theme .moon { display: none; }
:root[data-theme="dark"] #theme .sun { display: inline; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) #theme .moon { display: none; }
  :root:not([data-theme="light"]) #theme .sun { display: inline; }
}
:focus-visible { outline: 2px solid var(--down); outline-offset: 2px; }

/* Layout */
.layout {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(0, 2fr) minmax(0, 1fr);
  grid-template-areas:
    "speed location"
    "meas meas";
  align-items: start;
  /* Rows keep their content height; free space stays below them, not between them. */
  align-content: start;
  column-gap: 16px;
  row-gap: 22px;
  padding-block: 26px 40px;
}
.speed { grid-area: speed; }
.location { grid-area: location; }
.details { grid-area: meas; }

.h { margin: 0 0 10px; font-size: 1.15rem; font-weight: 700; letter-spacing: -0.01em; }
.panel { border: 1px solid var(--border); border-radius: 4px; background: var(--panel); }

/* Speed panel */
.speed-body { position: relative; }
.speed-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) minmax(140px, 0.42fr);
  gap: 18px;
}
.m-label { margin: 0; font-size: .95rem; font-weight: 600; }
.m-value {
  margin: 2px 0 0;
  font-size: 1.85rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.m-value.big { font-size: clamp(2.2rem, 4.2vw, 3.1rem); }
.m-value small { font-size: .55em; font-weight: 600; margin-left: 4px; letter-spacing: 0; }
.m-value.big small { font-size: .5em; }

.chart { height: 170px; margin-top: 10px; position: relative; }
.chart svg { width: 100%; height: 100%; overflow: visible; }
.chart .area { stroke: none; }
.chart .line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .pt { stroke: none; }
.chart .p90 { stroke: var(--muted); stroke-width: 1; opacity: .7; }
.chart .p90-label { fill: var(--text); font-size: 11px; }
.chart .base { stroke: var(--grid); stroke-width: 1; }
.down .line, .down .pt { stroke: var(--down); fill: var(--down); }
.down .line { fill: none; }
.up .line, .up .pt { stroke: var(--up); fill: var(--up); }
.up .line { fill: none; }
.down stop { stop-color: var(--down); }
.up stop { stop-color: var(--up); }

.side { display: grid; align-content: start; gap: 18px; }
.loaded { margin: 4px 0 0; display: flex; gap: 14px; font-size: .9rem; font-variant-numeric: tabular-nums; white-space: nowrap; }
.loaded b { font-weight: 600; }
.loaded i { font-style: normal; }
.loaded .ld i { color: var(--down); }
.loaded .lu i { color: var(--up); }

/* Controls and chevron progress */
.controls {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  margin-top: 16px;
}
.progress-wrap { flex: 1; min-width: 0; display: grid; gap: 4px; margin-left: 6px; }
.status {
  margin: 0;
  font-size: .85rem;
  font-weight: 600;
  min-height: 1.2em;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.status.latency { color: var(--lat); }
.status.download { color: var(--down); }
.status.upload { color: var(--up); }
.status.error { color: var(--error); }
.status .spin {
  display: inline-block;
  width: 10px; height: 10px;
  margin-right: 6px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  vertical-align: -1px;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.progress { display: flex; gap: 1px; height: 18px; }
.progress i {
  flex: 1 1 0;
  min-width: 1px;
  background: var(--grid);
  clip-path: polygon(0 0, 55% 0, 100% 50%, 55% 100%, 0 100%, 45% 50%);
  transition: background .2s, opacity .2s;
}
.progress i.done.latency { background: var(--lat); }
.progress i.done.download { background: var(--down); }
.progress i.done.upload { background: var(--up); }
.progress i.active { animation: pulse 1s ease-in-out infinite; }
.progress i.active.latency { background: var(--lat); }
.progress i.active.download { background: var(--down); }
.progress i.active.upload { background: var(--up); }
.progress i.skip { opacity: .35; }
@keyframes pulse { 50% { opacity: .35; } }

/* Start overlay */
.overlay {
  position: absolute;
  inset: -6px;
  display: grid;
  place-items: center;
  background: var(--overlay);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  border-radius: 6px;
  z-index: 2;
}
.overlay[hidden] { display: none; }
.start {
  display: grid;
  place-items: center;
  align-content: center;
  gap: 4px;
  width: 136px; height: 136px;
  border-radius: 50%;
  border: 2px solid var(--muted);
  background: var(--panel-2);
  color: var(--text);
  cursor: pointer;
  font-size: .8rem;
  font-weight: 600;
  letter-spacing: .12em;
  text-transform: uppercase;
  transition: border-color .2s, transform .2s, color .2s;
}
.start svg { width: 46px; height: 46px; fill: none; stroke: currentColor; stroke-width: 1.4; stroke-linejoin: round; }
.start:hover { border-color: var(--down); color: var(--down); transform: scale(1.03); }

/* Location panel */
.loc-panel { padding: 14px; display: grid; gap: 14px; }
.server-list { display: grid; gap: 8px; }
.server {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--panel);
  text-align: left;
  cursor: pointer;
  transition: border-color .2s, background .2s;
}
.server:hover:not(:disabled) { border-color: var(--down); }
.server:disabled { cursor: not-allowed; opacity: .5; }
.server[aria-checked="true"] { border-color: var(--down); background: var(--panel-2); box-shadow: inset 3px 0 0 var(--down); }
.server .cc {
  display: grid;
  place-items: center;
  width: 34px; height: 34px;
  border-radius: 4px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  font-size: .78rem;
  font-weight: 700;
}
.server .meta { display: grid; flex: 1; min-width: 0; }
.server .name { font-weight: 600; }
.server .sub { font-size: .8rem; color: var(--muted); }
.server .ms { font-size: .85rem; font-weight: 600; font-variant-numeric: tabular-nums; }

.facts { margin: 0; display: grid; gap: 6px; font-size: .88rem; }
.facts div { display: flex; gap: 6px; }
.facts dt { color: var(--muted); }
.facts dt::after { content: ":"; }
.facts dd { margin: 0; font-weight: 600; min-width: 0; overflow-wrap: anywhere; }

/* Detailed measurements (collapsible) */
.details[hidden] { display: none; }
.details summary {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px 8px 10px;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 1.05rem;
  font-weight: 700;
  cursor: pointer;
  list-style: none;
  user-select: none;
  transition: border-color .2s;
}
.details summary::-webkit-details-marker { display: none; }
.details summary:hover { border-color: var(--down); }
.details summary svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; transition: transform .2s; }
.details[open] summary svg { transform: rotate(90deg); }
.measurements {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
  align-items: start;
  margin-top: 16px;
}
.boxes { display: grid; gap: 16px; }
.box { padding: 14px 16px 10px; }
.box h3 { margin: 0 0 6px; font-size: .95rem; font-weight: 700; }
.box h3 small { font-size: .85em; font-weight: 600; color: var(--muted); margin-left: 4px; }
.box svg { width: 100%; height: auto; overflow: visible; }
.box .tick { stroke: var(--grid); stroke-width: 1; }
.box .tick-label, .box .unit { fill: var(--text); font-size: 11px; }
.box .tick-label { text-anchor: middle; }
.box .bx { stroke-width: 1.2; }
.box .med { stroke-width: 1.4; }
.box .mean { stroke-width: 1.2; stroke-dasharray: 2 2; }
.boxes .bx, .boxes .whisk, .boxes .med, .boxes .mean { stroke: var(--lat); }
.boxes .bx { fill: color-mix(in srgb, var(--lat) 35%, transparent); }
.boxes .dotp { fill: var(--lat); }
.boxes .lat-down .bx { fill: color-mix(in srgb, var(--down) 35%, transparent); }
.boxes.down .bx, .boxes .lat-down .bx { fill: color-mix(in srgb, var(--down) 35%, transparent); }
.boxes.down .bx, .boxes.down .whisk, .boxes.down .med, .boxes.down .mean,
.boxes .lat-down .bx, .boxes .lat-down .whisk, .boxes .lat-down .med, .boxes .lat-down .mean { stroke: var(--down); }
.boxes.down .dotp, .boxes .lat-down .dotp { fill: var(--down); }
.boxes.up .bx, .boxes .lat-up .bx { fill: color-mix(in srgb, var(--up) 35%, transparent); }
.boxes.up .bx, .boxes.up .whisk, .boxes.up .med, .boxes.up .mean,
.boxes .lat-up .bx, .boxes .lat-up .whisk, .boxes .lat-up .med, .boxes .lat-up .mean { stroke: var(--up); }
.boxes.up .dotp, .boxes .lat-up .dotp { fill: var(--up); }

.foot {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 8px 24px;
  padding-block: 18px 24px;
  font-size: .82rem;
  color: var(--muted);
  border-top: 1px solid var(--border);
  max-width: calc(1480px - 56px);
  padding-inline: 0;
  width: calc(100% - 56px);
}

/* Responsive */
@media (max-width: 1100px) {
  .layout {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas: "speed" "location" "meas";
  }
  .measurements { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 720px) {
  .top, .layout { padding-inline: 16px; }
  .top::after { left: 16px; right: 16px; }
  .foot { width: calc(100% - 32px); }
  .speed-grid { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .side { grid-column: 1 / -1; grid-template-columns: 1fr 1fr; }
  .chart { height: 130px; }
  .measurements { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 460px) {
  .speed-grid { grid-template-columns: minmax(0, 1fr); }
  .side { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
