/* ── Fonts ── */
@font-face {
  font-family: Sarabun;
  src: url('/assets/Sarabun-Regular.ttf') format('truetype');
  font-weight: 400;
  font-display: swap;
}
@font-face {
  font-family: Sarabun;
  src: url('/assets/Sarabun-SemiBold.ttf') format('truetype');
  font-weight: 600 900;
  font-display: swap;
}

/* ── Design tokens ── */
:root {
  color-scheme: light;
  --primary: #596579;
  --ink: #1d1d1f;
  --muted: #64646b;
  --line: #e5e5ea;
  --teal: #8695a5;
}

/* ── Reset & base ── */
* { box-sizing: border-box; }

body {
  margin: 0;
  background: radial-gradient(ellipse at 15% 0%, #fff 0%, transparent 52%),
              linear-gradient(145deg, #f5f5f7, #edf0f4 65%, #fafafa);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Sarabun", sans-serif;
  font-size: 16px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
}

a { color: #375b7d; text-decoration: none; }
a:hover { text-decoration: underline; }
button, a, input { touch-action: manipulation; }
:focus-visible { outline: 3px solid #2869bf; outline-offset: 4px; }
button { font: inherit; cursor: pointer; }
button:disabled { opacity: .55; cursor: wait; }
[hidden] { display: none !important; }

/* ── Skip link ── */
.skip {
  position: absolute; left: 16px; top: -100px;
  padding: 10px; background: #fff; z-index: 10; border-radius: 12px;
}
.skip:focus { top: 10px; }

/* ── Header ── */
.header {
  background: rgba(255, 255, 255, .78);
  border-bottom: 1px solid rgba(205, 210, 219, .5);
  backdrop-filter: blur(22px);
  -webkit-backdrop-filter: blur(22px);
}
.header-inner {
  max-width: 1200px; margin: auto;
  padding: 14px 32px;
  display: flex; justify-content: space-between; align-items: center; gap: 24px;
}
.brand {
  display: flex; align-items: center; gap: 13px; color: var(--ink);
}
.brand img { object-fit: contain; border-radius: 12px; }
.brand strong {
  font-size: 22px; display: block; letter-spacing: -.7px;
}
.brand small {
  display: block; font-size: 12px; color: #64646b;
}
nav { display: flex; align-items: center; gap: 26px; font-size: 14px; }
.nav-connect {
  color: #3b4653;
  background: linear-gradient(160deg, #ffffffeb, #ffffff85);
  border: 1px solid #fff; border-radius: 999px;
  padding: 9px 16px; white-space: nowrap;
  box-shadow: 0 2px 9px #25314a09, inset 0 0 0 1px #202b4010;
}

/* ── Main ── */
main { max-width: 1120px; margin: auto; padding: 24px 24px 42px; }

.intro { margin-bottom: 20px; }
.eyebrow { display: none; }
h1 {
  font-size: 28px; font-weight: 600; line-height: 1.4;
  margin: 0 0 8px; letter-spacing: -.8px;
}
h1 span { color: #505866; }
.intro > p:last-child { color: var(--muted); margin: 0; font-size: 15px; }

h2, h3, p { margin-top: 0; }
h2 { font-size: 17px; font-weight: 600; }
h3 { font-size: 16px; font-weight: 600; }

/* ── Test card (glass) ── */
.test-card, .network, .quality {
  background: rgba(255, 255, 255, .9);
  border: 1px solid #fff; border-radius: 28px;
  box-shadow: 0 12px 40px #28334608, 0 2px 5px #28334604, inset 0 1px 0 #fff;
  overflow: hidden;
}
.card-top {
  padding: 18px 26px;
  border-bottom: 1px solid #e9eaee;
  background: linear-gradient(110deg, #ffffffbd, #f8f9fb8f);
  display: flex; justify-content: space-between; gap: 12px; align-items: center;
}
.card-top h2 { margin: 0; }
.badge {
  font-size: 12px; color: #64646b;
  padding: 4px 10px; background: #ffffffa8;
  border: 1px solid #e8e9ed; border-radius: 999px;
}

/* ── Top results row ── */
.top-results {
  display: grid; grid-template-columns: 1.4fr 1.4fr 1fr 1fr;
  gap: 0; margin: 16px 18px 0; padding: 19px 8px 16px;
  border-radius: 20px;
  background: linear-gradient(150deg, #f5f6f8, #fafbfc);
  border: 1px solid #eff0f3;
}
.top-results .metric {
  border: 0; border-radius: 0; box-shadow: none;
  padding: 0 20px; background: transparent; min-width: 0;
}
.top-results .metric + .metric { border-left: 1px solid #dedfe5; }
.top-results .metric-icon {
  position: static; display: inline-block;
  width: 26px; height: 26px; line-height: 24px;
  border-radius: 50%; margin-right: 6px; font-size: 20px;
  vertical-align: middle;
  background: #fff; color: #556274;
  box-shadow: 0 1px 5px #23324c0d; border: 1px solid #eceef2;
}
.top-results .metric h2 {
  display: inline; font-size: 15px; color: #4f535c;
}
.top-results .metric h2 small {
  font-size: 14px; font-weight: 400; white-space: nowrap;
}
.top-results .metric p {
  display: flex; flex-wrap: wrap; align-items: baseline;
  column-gap: 4px; margin-top: 8px; gap: 0 6px;
  justify-content: flex-start; white-space: normal;
}
.top-results .metric strong {
  font-size: clamp(28px, 4vw, 38px);
  font-weight: 600; line-height: 1.3;
  letter-spacing: -.7px; color: #1d1d1f;
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}
.top-results .metric p span { font-size: 13px; }

/* Ping/Jitter smaller */
.top-results .metric:nth-child(n+3) strong {
  font-size: clamp(22px, 3vw, 28px);
}
.top-results .metric:nth-child(n+3) h2 {
  display: inline-block;
}
.top-results .metric:nth-child(n+3) h2 small {
  display: block; font-size: 12px; margin-top: 3px;
}

.metric-help {
  text-align: center; font-size: 13px; color: var(--muted);
  margin: 0; padding: 12px 16px 0;
}
.metric-help strong { font-weight: 600; color: var(--ink); }
.metric-help > span { padding: 0 6px; }

/* ── Test layout (gauge + graph) ── */
.test-layout {
  display: grid; grid-template-columns: 1.3fr 1fr;
  padding: 20px 28px 24px; gap: 24px;
}

/* ── Gauge ── */
.gauge-section { text-align: center; min-width: 0; }
.gauge {
  width: 100%; max-width: 440px; margin: auto; position: relative;
}
.gauge svg { display: block; width: 100%; overflow: visible; }
.gauge path { fill: none; stroke-width: 22; stroke-linecap: round; }
.gauge-track { stroke: #e8ebef; }
#gauge-arc {
  stroke: var(--primary);
  stroke-dasharray: 100; stroke-dashoffset: 100;
  transition: stroke-dashoffset .3s;
}
/* Tick labels on gauge — properly sized */
.gauge text {
  font: 600 14px -apple-system, BlinkMacSystemFont, "Sarabun", sans-serif;
  fill: #64646b;
}
.gauge text.reached { fill: #2e3b4e; font-weight: 700; }

/* Needle */
#gauge-needle { stroke: var(--primary); stroke-width: 7; stroke-linecap: round; }
.needle-hub { fill: var(--primary); }

/* Center value — stable positioning via absolute within gauge */
.gauge-value {
  position: absolute; bottom: 12%; left: 0; right: 0;
  display: flex; flex-direction: column; align-items: center;
  line-height: 1.25; color: var(--muted); font-size: 14px; gap: 4px;
}
.gauge-value strong {
  font-size: clamp(40px, 5.5vw, 56px);
  line-height: 1.12; color: #202631;
  font-family: -apple-system, BlinkMacSystemFont, "Sarabun", sans-serif;
  font-weight: 300; font-variant-numeric: tabular-nums;
  letter-spacing: -2px;
}
.gauge-value .long-value { font-size: clamp(32px, 4.5vw, 44px); }
.gauge-value > span { font-size: 15px; }
.speed-unit small {
  display: block; font-size: 12px; color: var(--muted); margin-top: 3px;
}

/* Scale note */
.scale-note {
  font-size: 12px; color: #59616e; margin: 8px 0 0;
}

/* ── Controls ── */
.controls { display: flex; justify-content: center; gap: 10px; margin-top: 16px; }

.primary, #stop, .secondary {
  border-radius: 999px; min-height: 48px;
  background: linear-gradient(165deg, #fff 20%, #f0f2f5);
  border: 1px solid #d5dae2; color: #263344;
  box-shadow: 0 4px 12px #25314a0d, inset 0 1px 1px #fff;
  transition: background .15s, box-shadow .15s, transform .15s;
}
.primary {
  box-shadow: 0 6px 20px #25314a16, inset 0 1px 0 #fff;
  border-color: #c6cdd7; font-weight: 600;
  padding: 12px 35px; min-width: 190px; width: 230px; max-width: 100%;
}
.primary span { font-size: 12px; margin-right: 9px; }
.primary:hover, #stop:hover, .secondary:hover {
  background: linear-gradient(165deg, #fff, #e6eaf0);
  box-shadow: 0 6px 20px #25314a1a;
}
.primary:active, #stop:active, .secondary:active { transform: scale(.98); }
.primary:disabled { opacity: .55; }

.secondary {
  border: 1px solid #d9dee5; border-radius: 999px;
  background: #fff; color: #495769; padding: 10px 18px;
}
.secondary:hover { background: #f7f8fa; }

#stop {
  border-color: #495769; color: #3b4653; background: #f7f8fa;
  width: 230px; max-width: 100%; font-weight: 600;
}

/* ── Status & progress ── */
#status { font-size: 14px; margin: 11px 0 4px; min-height: 24px; }
#status.error { color: #484850; }
progress {
  appearance: none; border: 0; height: 4px; width: 74%;
  border-radius: 5px; background: #e9ebef;
}
progress::-webkit-progress-bar { background: #e9ebef; border-radius: 5px; }
progress::-webkit-progress-value { background: var(--primary); border-radius: 5px; }
progress::-moz-progress-bar { background: var(--primary); }
.data-note { font-size: 12px; color: var(--muted); margin: 6px 0 0; }

/* ── Phase highlights ── */
.test-card[data-phase="1"] .metric:first-child strong,
.test-card[data-phase="3"] .metric:nth-child(2) strong { color: #375b7d; }
.test-card[data-phase="1"] .metric:first-child h2,
.test-card[data-phase="3"] .metric:nth-child(2) h2 { color: #375b7d; }

/* ── Graph section ── */
.graph-section {
  border-left: 1px solid #e5e7ed; padding-left: 28px;
  display: flex; flex-direction: column; justify-content: center;
}
.graph-heading {
  display: flex; align-items: center; justify-content: space-between;
}
.graph-heading h3 { margin: 0; }
.live-label { display: none; }

.legend {
  display: flex; gap: 18px; font-size: 12px; color: var(--muted); margin: 13px 0 9px;
}
.legend span:last-child { margin-left: auto; }
.dl-dot:before, .ul-dot:before {
  content: ''; display: inline-block;
  width: 8px; height: 8px; margin-right: 6px;
  border-radius: 50%; background: var(--primary);
}
.ul-dot:before { background: var(--teal); }

.chart-wrap { position: relative; min-width: 0; }
#chart { width: 100%; height: auto; display: block; overflow: visible; }
#chart text { fill: var(--muted); font: 12px Sarabun, sans-serif; }
.grid path { stroke: #e1e5eb; fill: none; stroke-dasharray: 4 5; }
#download-line, #upload-line {
  fill: none; stroke: var(--primary); stroke-width: 2.5; stroke-linejoin: round;
}
#upload-line { stroke: var(--teal); }

#chart-empty {
  position: absolute; top: 36%; left: 0; right: 0;
  text-align: center; font-size: 13px; color: var(--muted); margin: 0;
}

/* Steps indicator */
.steps {
  display: flex; list-style: none; padding: 18px 0 0; margin: 10px 0 0;
  border-top: 1px solid var(--line);
  justify-content: space-between; gap: 12px;
  font-size: 12px; color: var(--muted);
}
.steps li { display: flex; align-items: center; gap: 7px; }
.steps .active { color: #495769; font-weight: 600; }

/* ── Metric cards (standalone — used for grid layout) ── */
.metric {
  background: #fff; border: 1px solid var(--line); border-radius: 16px;
  box-shadow: 0 4px 18px #15395404;
  padding: 19px 22px; position: relative;
}
.metric h2 { font-size: 14px; color: var(--muted); margin: 0 0 12px; }
.metric p { margin: 0; white-space: nowrap; }
.metric strong {
  font-size: 30px; font-weight: 600; letter-spacing: -1px;
  font-variant-numeric: tabular-nums;
}
.metric p span { color: var(--muted); font-size: 13px; }
.metric-icon {
  position: absolute; top: 16px; right: 18px;
  font-size: 21px; line-height: 32px; text-align: center;
  width: 32px; border-radius: 8px;
}
.blue { color: #495769; background: #f2f3f5; }
.teal { color: #596c80; background: #eff2f5; }

/* ── Network info ── */
.network { padding: 22px 26px; margin-top: 18px; }
.network h2 { margin-bottom: 19px; }
.network dl {
  display: grid; grid-template-columns: 1fr 1fr 1.4fr 1.3fr;
  gap: 20px; margin: 0;
}
.network dt { font-size: 12px; color: var(--muted); margin-bottom: 7px; }
.network dd { margin: 0; font-size: 14px; overflow-wrap: anywhere; }
.private-label { font-size: 10px; color: #596c80; margin-left: 5px; }
.network-note {
  font-size: 12px; color: var(--muted); margin: 18px 0 0;
  padding-top: 13px; border-top: 1px solid var(--line);
}

/* ── Tips ── */
.tips {
  display: flex; gap: 16px; margin-top: 16px;
  background: #ffffff9c; border: 1px solid #fff; border-radius: 22px;
  box-shadow: 0 4px 20px #28334604; padding: 21px 25px;
}
.tips h2 { font-size: 15px; margin-bottom: 5px; }
.tips p { font-size: 14px; margin-bottom: 5px; color: #555e6c; }
.tips small { font-size: 12px; color: var(--muted); }
.tip-icon {
  border: 1.5px solid #8691a2; border-radius: 50%;
  min-width: 21px; height: 21px; line-height: 19px;
  text-align: center; font-size: 14px; margin-top: 4px; color: #556274;
}

/* ── Quality result ── */
.quality {
  display: flex; gap: 20px; justify-content: space-between; align-items: center;
  padding: 22px 26px; margin-top: 18px; border-left: 1px solid #fff;
}
.quality h2 { margin: 0 0 4px; color: #375b7d; }
.quality p { margin: 0; font-size: 14px; }
.quality small { font-size: 12px; color: var(--muted); }
.quality button { flex-shrink: 0; }

/* ── Local notice ── */
.local-notice {
  margin: 12px 18px 0; padding: 9px 12px;
  background: #f3f5f8; color: #59616e;
  border: 1px solid #e3e6ec; border-radius: 14px;
  text-align: center; font-size: 13px;
}

/* ── Footer ── */
footer {
  border-top: 1px solid #dfe3e9;
  max-width: 1088px; margin: auto; padding: 25px 0 30px;
  display: flex; justify-content: space-between; gap: 25px;
  color: var(--muted); font-size: 12px;
}
footer strong { font-weight: 400; }
footer p { margin: 4px 0; }
.footer-links { display: flex; gap: 22px; align-items: flex-start; }
.footer-links a { color: #556274; }

/* ═══════════════════════════════════════════════
   RESPONSIVE — Tablet (601–800px)
   ═══════════════════════════════════════════════ */
@media (max-width: 800px) {
  .header-inner { padding: 14px 24px; }
  .brand small { max-width: 210px; font-size: 11px; }
  nav { gap: 12px; }
  nav > a:first-child { display: none; }

  .top-results { padding: 20px 12px; }
  .top-results .metric { padding: 0 10px; }
  .top-results .metric strong { font-size: clamp(24px, 4vw, 32px); }
  .top-results .metric h2 { font-size: 14px; }
  .top-results .metric h2 small { font-size: 12px; }
  .top-results .metric:nth-child(n+3) strong { font-size: clamp(20px, 3vw, 24px); }

  .test-layout { grid-template-columns: 1.25fr 1fr; gap: 16px; padding: 18px; }
  .gauge-value strong { font-size: clamp(40px, 6vw, 52px); }
  .gauge-value .long-value { font-size: clamp(32px, 5vw, 40px); }

  .graph-section { padding-left: 18px; }

  .metric { padding: 17px 15px; }
  .metric-icon { right: 10px; width: 25px; }
  .metric strong { font-size: 25px; }

  .network dl { grid-template-columns: 1fr 1fr; }
  footer { margin: 0 24px; flex-wrap: wrap; }
  .quality { flex-wrap: wrap; }
}

/* ═══════════════════════════════════════════════
   RESPONSIVE — Mobile (≤600px)
   ═══════════════════════════════════════════════ */
@media (max-width: 600px) {
  main { padding: 17px 12px 26px; }
  .header-inner { padding: 12px; gap: 10px; }

  .brand { gap: 8px; }
  .brand img { width: 35px; height: 35px; }
  .brand strong { font-size: 17px; }
  .brand small { font-size: 10px; max-width: 165px; }
  .nav-connect { font-size: 11px; padding: 8px 11px; }

  .intro { margin-bottom: 14px; }
  h1 { font-size: 23px; margin-bottom: 3px; }
  .intro > p:last-child { font-size: 13px; }

  .test-card, .network, .quality { border-radius: 24px; }
  .card-top { padding: 14px 17px; flex-direction: row; align-items: center; }
  .card-top h2 { font-size: 14px; }
  .badge { font-size: 10px; padding: 3px 7px; }

  /* Metrics — 2-column on mobile */
  .top-results {
    grid-template-columns: 1fr 1fr;
    margin: 12px 10px 0; padding: 17px 6px 12px;
    border-radius: 18px; row-gap: 15px;
  }
  .top-results .metric { padding: 0 8px; text-align: center; }
  .top-results .metric h2 { font-size: 16px; }
  .top-results .metric h2 small { font-size: 13px; }
  .top-results .metric p { justify-content: center; margin-top: 9px; }
  .top-results .metric strong {
    font-size: clamp(26px, 8.5vw, 36px); letter-spacing: -.8px;
  }
  .top-results .metric p span { font-size: 12px; }

  /* Ping/Jitter compact on mobile */
  .top-results .metric:nth-child(3) { border-left: 0; }
  .top-results .metric:nth-child(n+3) {
    display: block; text-align: left; padding-top: 12px;
    border-top: 1px solid #e2e5eb;
  }
  .top-results .metric:nth-child(n+3) .metric-icon { display: none; }
  .top-results .metric:nth-child(n+3) h2 { font-size: 13px; }
  .top-results .metric:nth-child(n+3) h2 small {
    display: inline; margin-left: 4px; font-size: 11px;
  }
  .top-results .metric:nth-child(n+3) p {
    display: flex; justify-content: flex-start; align-items: baseline;
    gap: 5px; margin-top: 4px;
  }
  .top-results .metric:nth-child(n+3) strong {
    font-size: 24px; margin-left: 0;
  }

  .metric-help {
    font-size: 12px; max-width: 290px; margin: auto; padding-top: 6px; line-height: 1.8;
  }
  .metric-help > span { display: none; }
  .metric-help strong:first-of-type:after { content: ''; display: block; }

  /* Test area */
  .test-layout {
    display: flex; flex-direction: column;
    padding: 10px 10px 18px; gap: 18px;
  }
  .gauge { max-width: 300px; }
  .gauge text { font-size: 13px; }
  .gauge-value { bottom: 8%; }
  .gauge-value strong { font-size: clamp(38px, 10vw, 50px); }
  .gauge-value .long-value { font-size: clamp(30px, 8vw, 40px); }
  .gauge-value > span { font-size: 13px; }

  .controls { margin: 14px 6px 0; flex-wrap: wrap; }
  .primary, #stop { width: 100%; max-width: 320px; }
  #status { font-size: 14px; }
  .scale-note { padding: 0 8px; }
  .data-note { font-size: 11px; padding: 0 10px; }

  /* Graph */
  .graph-section {
    border-left: 0; border-top: 1px solid var(--line);
    padding: 16px 0 0; margin: 0 6px;
  }
  .graph-heading h3 { font-size: 14px; }
  #chart { max-height: 150px; }
  .steps { padding-top: 12px; font-size: 12px; }

  /* Other sections */
  .network { padding: 18px; }
  .network dd { font-size: 14px; }
  .network dt { font-size: 13px; }
  .tips { border-radius: 20px; padding: 18px; gap: 12px; }
  .tips p { font-size: 14px; }
  .quality { padding: 20px; }
  .quality button { width: 100%; }
  footer { margin: 0 16px; padding: 22px 0; font-size: 11px; }
  .footer-links { gap: 20px; }
}

/* ═══════════════════════════════════════════════
   RESPONSIVE — Very small (≤350px)
   ═══════════════════════════════════════════════ */
@media (max-width: 350px) {
  .badge { display: none; }
  .brand small { max-width: 135px; }
  .nav-connect { padding: 7px 9px; }
  .top-results .metric-icon { width: 22px; height: 22px; line-height: 20px; font-size: 18px; margin-right: 3px; }
  .top-results .metric h2 { font-size: 14px; }
  .top-results .metric h2 small { font-size: 12px; }
  .top-results .metric:nth-child(n+3) h2 small { font-size: 11px; }
  .top-results .metric { padding-left: 5px; padding-right: 5px; }
  .top-results .metric strong { font-size: 25px; }
  .gauge-value strong { font-size: clamp(34px, 9vw, 42px); }
  .gauge-value .long-value { font-size: clamp(28px, 7.5vw, 36px); }
}

/* ═══════════════════════════════════════════════
   RESPONSIVE — Large desktop (≥1500px)
   ═══════════════════════════════════════════════ */
@media (min-width: 1500px) {
  main { padding-top: 48px; }
  .test-layout { padding-top: 35px; padding-bottom: 32px; }
}

/* ═══════════════════════════════════════════════
   Accessibility: motion & transparency
   ═══════════════════════════════════════════════ */
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
  .primary, #stop, .secondary { transform: none; }
}
@media (prefers-reduced-transparency: reduce) {
  .header, .test-card, .network, .quality, .tips {
    background: #fff; backdrop-filter: none; -webkit-backdrop-filter: none;
  }
}
