/* Website speed test. Brand tokens and shared components come from /admin/styles.css; the
   shapes follow the Android app (docs/APP-DESIGN.md "Brand"): gradient pill primary button,
   outline pill Stop, 20px cards, Inter, tabular figures. */
/* --upload is the app's upload accent (bars, tints); --upload-text is its AA-safe shade for small text. */
:root { --upload: #0D9488; --upload-text: #0F766E; --halo: rgba(79, 70, 229, 0.28); }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) { --upload: #2DD4BF; --upload-text: #5EEAD4; --halo: rgba(139, 135, 255, 0.35); }
}
:root[data-theme="dark"] { --upload: #2DD4BF; --upload-text: #5EEAD4; --halo: rgba(139, 135, 255, 0.35); }

.topbar-title { font-weight: 600; color: var(--ink-muted); }
body:has(main.web) { min-height: 100svh; display: flex; flex-direction: column; }
main.web { max-width: 760px; width: 100%; flex: 1; display: flex; flex-direction: column; }

.hero { display: flex; flex-direction: column; align-items: center; text-align: center; padding: 24px 0 4px; }
/* Until results exist the control and the provider/server row sit in the middle of the screen. */
main.web:has(#results[hidden]) .hero { flex: 1; justify-content: center; padding-bottom: 56px; }
.dial { width: 100%; max-width: 440px; }

/* ---- Start Speed Test: the app's primary button (brand gradient pill) ---- */
.start-btn {
  width: 100%; min-height: 64px; border: 0; border-radius: 999px; cursor: pointer;
  display: flex; align-items: center; justify-content: center; gap: 10px;
  background: var(--gradient); color: #fff; font-size: 20px; font-weight: 700; letter-spacing: 0.2px;
  box-shadow: 0 10px 24px var(--halo); transition: transform 0.12s ease, filter 0.15s ease;
  -webkit-tap-highlight-color: transparent;
}
.start-btn:hover { filter: brightness(1.06); }
.start-btn:active { transform: scale(0.96); }
.start-btn:focus-visible { outline: 3px solid var(--brand); outline-offset: 4px; }
.dial[data-state="idle"] .start-btn { animation: halo 2.4s ease-in-out infinite; }
@keyframes halo {
  0%, 100% { box-shadow: 0 10px 24px var(--halo), 0 0 0 0 var(--brand-soft); }
  50% { box-shadow: 0 10px 24px var(--halo), 0 0 0 10px var(--brand-soft); }
}

/* ---- live card during a run: step, value, bar (the app's Running card) ---- */
.live { margin: 0; text-align: left; }
.live-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 30px; }
.step-chip { font-size: 14px; font-weight: 500; padding: 5px 12px; border-radius: 999px; background: var(--brand-soft); color: var(--brand-text); }
.dial[data-step="upload"] .step-chip { color: var(--upload-text);background: color-mix(in srgb, var(--upload) 14%, transparent); }
.live-num { display: flex; align-items: baseline; justify-content: center; gap: 8px; margin: 10px 0 14px; }
.live-value { font-size: 56px; font-weight: 800; line-height: 1; }
.live-unit { font-size: 18px; color: var(--ink-muted); }
.bar { position: relative; height: 10px; border-radius: 999px; background: var(--surface-alt); overflow: hidden; }
.bar-fill {
  position: absolute; inset: 0 auto 0 0; width: calc(var(--p, 0) * 1%); border-radius: 999px;
  background: var(--gradient); transition: width 0.25s linear;
}
.dial[data-step="upload"] .bar-fill { background: var(--upload); }
.dial[data-mode="wait"] .bar-fill { width: 30%; animation: slide 1.2s ease-in-out infinite; }
@keyframes slide { from { left: -30%; } to { left: 100%; } }
.scale { display: flex; justify-content: space-between; margin-top: 6px; font-size: 12px; color: var(--ink-muted); }
.dial[data-step="ping"] .scale, .dial[data-step=""] .scale { visibility: hidden; }

/* ---- step dots, error line, Stop test (the app's outline pill) ---- */
.steps { display: flex; gap: 18px; list-style: none; padding: 0; margin: 16px 0 0; font-size: 13px; font-weight: 500; color: var(--ink-muted); }
.steps li { display: flex; align-items: center; gap: 6px; }
.steps li::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--outline); }
.steps li.now { color: var(--brand-text); }
.steps li.now::before { background: var(--brand); box-shadow: 0 0 0 4px var(--brand-soft); }
.steps li.done::before { background: var(--ink-muted); }
.dial[data-state="idle"] + .steps { display: none; }
.phase-error { margin: 12px 0 0; max-width: 440px; color: var(--danger); font-size: 15px; }
.stop-btn {
  display: flex; align-items: center; justify-content: center; gap: 10px; width: 100%; max-width: 440px; min-height: 52px; margin-top: 14px;
  border: 1.5px solid var(--outline); border-radius: 999px; background: transparent; color: var(--danger);
  font-size: 17px; font-weight: 600; cursor: pointer;
}
.stop-btn:hover:not(:disabled) { background: var(--surface-alt); }
.stop-btn:focus-visible { outline: 3px solid var(--brand); outline-offset: 3px; }
.stop-btn:disabled { opacity: 0.55; cursor: default; }
.stop-square { width: 14px; height: 14px; border-radius: 2px; background: currentColor; }

/* ---- provider and server under the control ---- */
/* Provider and test server joined by a dotted line with one dot travelling along it. */
.route { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 14px; width: 100%; max-width: 560px; margin-top: 40px; }
.node { display: flex; align-items: center; gap: 10px; min-width: 0; }
.node.server { flex-direction: row-reverse; }
.node-text { display: flex; flex-direction: column; min-width: 0; text-align: left; }
.node.server .node-text { text-align: right; }
.node-name { font-size: 17px; font-weight: 600; color: var(--ink); overflow-wrap: anywhere; }
.node-sub { font-size: 14px; color: var(--ink-muted); overflow-wrap: anywhere; }
.wire { position: relative; height: 2px; min-width: 40px; background: repeating-linear-gradient(90deg, var(--outline) 0 6px, transparent 6px 12px); }
.wire::after {
  content: ""; position: absolute; top: -3px; left: 0; width: 8px; height: 8px; border-radius: 50%;
  background: var(--brand); box-shadow: 0 0 10px var(--brand); animation: travel 8s ease-in-out infinite;
}
@keyframes travel { 0%, 100% { left: 0; } 50% { left: calc(100% - 8px); } }
@keyframes travel-down { 0%, 100% { top: 0; } 50% { top: calc(100% - 8px); } }
@media (prefers-reduced-motion: reduce) { .wire::after { animation: none; left: calc(50% - 4px); } }
.end-icon {
  flex: none; display: grid; place-items: center; width: 42px; height: 42px; border-radius: 50%;
  background: var(--brand-soft); color: var(--brand);
}

/* ---- results ---- */
.headline { margin: 24px 0 12px; grid-template-columns: repeat(3, minmax(0, 1fr)); }
.metric { display: grid; gap: 2px; align-content: start; background: var(--surface); border: 1px solid var(--outline); border-radius: 20px; box-shadow: var(--shadow); }
.metric.down .eyebrow { color: var(--brand-text); }
.metric.up .eyebrow { color: var(--upload-text); }
.metric .value { font-size: 26px; font-weight: 700; }
.metric.live .value { color: var(--ink-muted); }
/* Ping card: two-arrow ping icon (same drawing as the admin page's), then the download and upload pings under it. */
.metric .ping-icon { width: 22px; height: 22px; margin-right: 6px; vertical-align: -2px; fill: none; stroke: var(--ink-muted); stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.metric .loaded { font-size: 14px; color: var(--ink-muted); }

.runid { display: grid; gap: 6px; }
.runid-row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.runid-size { container-type: inline-size; width: min(100%, 39ch + 1px); font-size: 15px; }
#runid-text { display: block; white-space: nowrap; font-size: min(15px, calc(15px * 100cqi / 39ch)); }
.runid .btn.ghost { border-radius: 999px; }
.saved { font-size: 14px; color: var(--danger); }

table.kv { width: 100%; border-collapse: collapse; font-size: 15px; }
table.kv th, table.kv td { text-align: left; padding: 8px 0; border-bottom: 1px solid var(--outline); vertical-align: top; }
table.kv tr:last-child th, table.kv tr:last-child td { border-bottom: 0; }
table.kv th { width: 40%; padding-right: 12px; font-weight: 400; color: var(--ink-muted); }
table.kv td { overflow-wrap: anywhere; }

@media (max-width: 480px) {
  .hero { padding-top: 16px; }
  .live-value { font-size: 48px; }
  .route { grid-template-columns: 1fr; gap: 10px; justify-items: center; margin-top: 36px; }
  .node.server { flex-direction: row; }
  .node.server .node-text { text-align: left; }
  .wire { width: 2px; height: 28px; min-width: 0; background: repeating-linear-gradient(180deg, var(--outline) 0 6px, transparent 6px 12px); }
  .wire::after { left: -3px; animation-name: travel-down; }
  .node-name { font-size: 16px; }
  .headline { gap: 6px; }
  .metric { padding: 8px; }
  .metric .eyebrow { font-size: 11px; letter-spacing: 0; }
  .metric .value { font-size: 18px; }
  .metric .unit { font-size: 11px; margin-left: 2px; }
  .metric .ping-icon { width: 15px; height: 15px; margin-right: 3px; }
  .metric .loaded { font-size: 10px; white-space: nowrap; }
}
@media (prefers-reduced-motion: reduce) {
  .dial .start-btn { animation: none !important; transition: none; }
  .start-btn:active { transform: none; }
  .bar-fill { transition: none; }
  .dial[data-mode="wait"] .bar-fill { animation: none; left: 0; width: 100%; opacity: 0.35; }
}
