:root {
  --background: #fbfbff;
  --foreground: #101b49;
  --card: rgba(255, 255, 255, 0.94);
  --primary: #5548ff;
  --primary-hover: #4234e8;
  --violet: #7b42f6;
  --pink: #e834c8;
  --green: #24c978;
  --brand-blue: #101b49;
  --brand-red: #ef1f31;
  --muted: #586282;
  --border: #e4e5f5;
  --danger: #d72545;
  --danger-bg: #fff1f5;
  --radius: 18px;
  --shadow: 0 20px 56px rgba(65, 55, 190, 0.09);
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
}

* { box-sizing: border-box; }
html { font-size: 16px; scroll-behavior: smooth; }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--foreground);
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at 48% 22%, rgba(105, 69, 255, 0.035), transparent 31rem),
    linear-gradient(180deg, #fff 0 100px, var(--background) 100px 100%);
  overflow-x: hidden;
}

body::before,
body::after {
  content: "";
  position: fixed;
  z-index: -1;
  width: 330px;
  height: 330px;
  border: 1px solid rgba(104, 76, 240, 0.09);
  border-radius: 50%;
  box-shadow:
    0 0 0 16px rgba(104, 76, 240, 0.035),
    0 0 0 34px rgba(104, 76, 240, 0.028),
    0 0 0 54px rgba(104, 76, 240, 0.024),
    0 0 0 76px rgba(104, 76, 240, 0.02),
    0 0 0 100px rgba(104, 76, 240, 0.016);
  pointer-events: none;
}

body::before { top: 72px; left: -245px; }
body::after { right: -240px; bottom: -115px; }

a { color: var(--primary); font-weight: 500; text-decoration: none; }
a:hover { color: var(--primary-hover); }
button, a { -webkit-tap-highlight-color: transparent; }

button:focus-visible,
a:focus-visible { outline: 3px solid rgba(85, 72, 255, 0.27); outline-offset: 3px; }

.skip-link {
  position: fixed;
  z-index: 20;
  top: 12px;
  left: 12px;
  padding: 10px 16px;
  border-radius: 10px;
  background: var(--foreground);
  color: #fff;
  transform: translateY(-150%);
  transition: transform 180ms ease;
}

.skip-link:focus { color: #fff; transform: translateY(0); }

.site-header {
  min-height: 100px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px 24px;
  background: rgba(255, 255, 255, 0.9);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(14px);
}

.brand { display: inline-flex; align-items: center; }
.brand img { width: min(322px, 64vw); height: auto; display: block; }

.shell { width: min(1032px, calc(100% - 40px)); margin: 0 auto; padding: 42px 0 28px; }
.narrow { width: min(940px, calc(100% - 40px)); }

h1, h2, p { margin: 0; }

h1 {
  margin-bottom: 18px;
  color: var(--foreground);
  font-size: clamp(2rem, 4vw, 2.6rem);
  line-height: 1.14;
  font-weight: 650;
  letter-spacing: -0.035em;
  text-align: center;
}

h2 { color: var(--foreground); font-size: 1.2rem; line-height: 1.4; font-weight: 650; letter-spacing: -0.015em; }

.notice {
  max-width: 900px;
  margin: 0 auto 36px;
  color: var(--muted);
  font-size: 0.94rem;
  line-height: 1.75;
  text-align: center;
}

button,
.as-button {
  min-height: 44px;
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 0 20px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  color: var(--foreground);
  font: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  line-height: 1.4;
  cursor: pointer;
  transition: transform 220ms var(--ease), box-shadow 220ms var(--ease), background 220ms ease;
}

button:disabled { opacity: 0.55; cursor: progress; }

.primary {
  min-width: 348px;
  min-height: 70px;
  padding: 0 38px;
  border: 0;
  border-radius: 10px;
  background: linear-gradient(112deg, #4845ff 0%, #8a3ff3 52%, #e52dca 100%);
  color: #fff;
  box-shadow: 0 15px 28px rgba(109, 60, 238, 0.22);
  font-size: 1.25rem;
}

.primary:hover:not(:disabled) { color: #fff; transform: translateY(-2px); box-shadow: 0 19px 34px rgba(109, 60, 238, 0.3); }

.start-glyph {
  width: 27px;
  height: 27px;
  display: inline-grid;
  place-items: center;
  border: 2px dotted currentColor;
  border-radius: 50%;
  font-size: 0;
}

.start-glyph::after {
  content: "";
  width: 4px;
  height: 11px;
  border-radius: 3px;
  background: currentColor;
  transform: rotate(42deg) translate(1px, -2px);
  transform-origin: bottom center;
}

.secondary { background: #fff; color: var(--primary); border-color: var(--border); }
.secondary:hover:not(:disabled) { background: #f7f6ff; transform: translateY(-1px); }

.panel {
  position: relative;
  margin-bottom: 26px;
  padding: 28px 32px;
  overflow: hidden;
  border: 1px solid rgba(232, 232, 248, 0.9);
  border-radius: var(--radius);
  background: var(--card);
  box-shadow: var(--shadow);
}

.test-panel { padding: 30px; }

.actions,
.hero-actions,
.section-head,
.page-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }

.actions { min-height: 82px; margin-bottom: 18px; justify-content: center; }
.actions .secondary { min-height: 54px; }
.section-head, .page-head { justify-content: space-between; }
.section-head { margin-bottom: 10px; }
.page-head { margin-bottom: 28px; }
.page-head h1 { margin: 0; text-align: left; }
.hero-actions .primary { min-width: 0; min-height: 44px; padding: 0 20px; font-size: 0.9rem; }

.runtime { display: grid; gap: 16px; margin-bottom: 25px; }
.status-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.stage-line { display: flex; align-items: center; gap: 10px; min-width: 0; }
.stage-line strong, .speed-readout { font-size: 0.9rem; font-weight: 600; }
.muted { color: var(--muted); font-size: 0.9rem; }

.status-icon {
  width: 16px;
  height: 16px;
  border: 4px solid #fff;
  border-radius: 50%;
  background: var(--violet);
  box-shadow: 0 0 0 2px rgba(123, 66, 246, 0.22);
  flex: 0 0 auto;
}

.progress { position: relative; height: 6px; overflow: hidden; border-radius: 999px; background: #f0effc; }
.progress div { position: absolute; inset: 0 auto 0 0; width: 0; border-radius: inherit; background: linear-gradient(90deg, #4e49ff, #dd31cc); transition: width 260ms ease; }
.steps { display: none; }

.metrics { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 22px; }

.metric {
  min-width: 0;
  min-height: 154px;
  padding: 24px 22px;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.76);
  box-shadow: 0 10px 24px rgba(47, 43, 127, 0.035);
}

.metric-label { display: flex; align-items: center; gap: 18px; margin-bottom: 19px; color: var(--foreground); font-size: 0.94rem; font-weight: 500; }

.metric-icon {
  width: 48px;
  height: 48px;
  display: inline-grid;
  place-items: center;
  flex: 0 0 auto;
  border-radius: 50%;
  color: #fff;
  background: linear-gradient(145deg, #6977ff, #4657ed);
  box-shadow: 0 8px 14px rgba(73, 90, 236, 0.24);
  font-size: 2rem;
  font-weight: 300;
  line-height: 1;
}

.upload-icon { background: linear-gradient(145deg, #30d784, #10b961); box-shadow: 0 8px 14px rgba(20, 186, 100, 0.24); }
.ping-icon { background: linear-gradient(145deg, #9b58ff, #6335e8); box-shadow: 0 8px 14px rgba(109, 58, 232, 0.24); font-size: 1.35rem; }
.jitter-icon { background: linear-gradient(145deg, #ff64bf, #e9349b); box-shadow: 0 8px 14px rgba(232, 54, 158, 0.22); font-size: 1.7rem; }

.metric strong { font-size: 1.55rem; line-height: 1.25; font-weight: 600; letter-spacing: 0.08em; }
.metric small { margin-left: 11px; color: var(--foreground); font-size: 1rem; }
.result-metrics { margin-bottom: 26px; }
.result-metrics .metric { min-height: 144px; }
.result-metrics .metric strong { font-size: 2rem; letter-spacing: -0.02em; }

.details { display: grid; gap: 0; margin: 18px 0 0; }
.details div { display: grid; grid-template-columns: 150px minmax(0, 1fr); gap: 16px; padding: 14px 0; border-bottom: 1px solid var(--border); }
.details div:last-child { border-bottom: 0; }
dt { color: var(--muted); font-size: 0.82rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.055em; }
dd { margin: 0; min-width: 0; color: var(--foreground); font-size: 0.9rem; font-weight: 500; overflow-wrap: anywhere; }

.table-wrap { overflow-x: auto; }
table { width: 100%; min-width: 760px; border-collapse: collapse; }
th, td { padding: 11px 8px; border-bottom: 1px solid var(--border); text-align: left; font-size: 0.86rem; }
th { color: var(--muted); font-weight: 500; }
td { color: var(--foreground); }
tbody tr:last-child td { border-bottom: 0; }
tbody tr { transition: background 160ms ease; }
tbody tr:hover { background: rgba(99, 73, 245, 0.025); }
.refresh-button { min-height: 40px; padding: 0 15px; }
.refresh-button span { font-size: 1.25rem; font-weight: 400; }

.error { max-width: 480px; margin: 12vh auto 0; padding: 36px; text-align: center; }
.error::before { content: "!"; width: 58px; height: 58px; margin: 0 auto 16px; display: grid; place-items: center; border-radius: 50%; background: var(--danger-bg); color: var(--danger); font-size: 1.8rem; font-weight: 700; }
.error h2 { margin-bottom: 8px; }
.error p { color: var(--muted); }
.error-banner { margin: 0 0 18px; padding: 12px 16px; border: 1px solid rgba(215, 37, 69, 0.28); border-radius: 10px; background: var(--danger-bg); color: var(--danger); font-size: 0.9rem; line-height: 1.4; text-align: center; }
.footer { padding: 4px 0 0; color: #7b839d; font-size: 0.8rem; text-align: center; }
.result-page { min-height: calc(100vh - 100px); }
[hidden] { display: none !important; }

@media (max-width: 860px) {
  .shell, .narrow { width: min(100% - 28px, 720px); padding-top: 30px; }
  .metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
  .metric { min-height: 136px; }
  .page-head { align-items: flex-start; flex-direction: column; }
  .hero-actions { width: 100%; }
}

@media (max-width: 560px) {
  body { background: linear-gradient(180deg, #fff 0 78px, var(--background) 78px 100%); }
  body::before, body::after { opacity: 0.6; }
  .site-header { min-height: 78px; padding: 14px 20px; }
  .brand img { width: min(230px, 70vw); }
  .shell, .narrow { width: calc(100% - 24px); padding: 26px 0 20px; }
  h1 { margin-bottom: 14px; font-size: clamp(1.72rem, 8vw, 2.1rem); }
  .notice { margin-bottom: 24px; font-size: 0.84rem; line-height: 1.62; }
  .panel, .test-panel { padding: 20px; border-radius: 16px; }
  .actions { min-height: 68px; margin-bottom: 14px; }
  .primary { width: 100%; min-width: 0; min-height: 58px; font-size: 1.05rem; }
  .actions .secondary { width: 100%; }
  .status-row { align-items: flex-start; }
  .stage-line { gap: 8px; }
  .muted, .stage-line strong, .speed-readout { font-size: 0.78rem; }
  .metrics { gap: 10px; }
  .metric { min-height: 128px; padding: 18px 14px; }
  .metric-label { gap: 10px; margin-bottom: 15px; font-size: 0.78rem; }
  .metric-icon { width: 39px; height: 39px; font-size: 1.6rem; }
  .ping-icon { font-size: 1.08rem; }
  .jitter-icon { font-size: 1.38rem; }
  .metric strong { font-size: 1.3rem; }
  .metric small { margin-left: 5px; font-size: 0.78rem; }
  .section-head { align-items: stretch; flex-direction: column; }
  .section-head .secondary { width: 100%; }
  .table-wrap { overflow: visible; }
  table, tbody, tr, td { display: block; width: 100%; min-width: 0; }
  thead { display: none; }
  tbody { display: grid; gap: 10px; margin-top: 14px; }
  tbody tr { padding: 13px 14px; border: 1px solid var(--border); border-radius: 12px; background: #fff; }
  tbody td { display: grid; grid-template-columns: 88px 1fr; gap: 8px; padding: 4px 0; border: 0; font-size: 0.8rem; }
  tbody td::before { content: attr(data-label); color: var(--muted); font-size: 0.68rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; }
  tbody td[colspan] { display: block; text-align: center; }
  tbody td[colspan]::before { display: none; }
  tbody td:last-child a { display: block; padding: 7px 12px; border-radius: 8px; background: #f2f0ff; text-align: center; }
  .hero-actions { display: grid; grid-template-columns: 1fr; }
  .hero-actions button, .hero-actions .as-button { width: 100%; }
  .details div { grid-template-columns: 1fr; gap: 5px; }
  .result-metrics .metric strong { font-size: 1.55rem; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; }
}
