/* ============================================================
   LagTest — estilo Apple (minimal, claro/escuro)
   ============================================================ */

:root {
  --bg:        #fbfbfd;
  --card:      #ffffff;
  --text:      #1d1d1f;
  --text-2:    #6e6e73;
  --text-3:    #86868b;
  --border:    rgba(0, 0, 0, .09);
  --border-2:  rgba(0, 0, 0, .14);
  --track:     rgba(0, 0, 0, .08);
  --hover:     rgba(0, 0, 0, .03);

  --accent:      #0071e3;
  --accent-hover:#0077ed;
  --green:       #34c759;
  --red:         #ff3b30;
  --amber:       #ff9500;

  --shadow: 0 4px 24px rgba(0, 0, 0, .06), 0 1px 3px rgba(0, 0, 0, .04);

  --r:    28px;
  --r-sm: 18px;
  --ease: cubic-bezier(.4, 0, .2, 1);
  --font: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'SF Pro Text',
          'Inter', 'Helvetica Neue', system-ui, sans-serif;
}

html[data-theme="dark"] {
  --bg:        #000000;
  --card:      #1c1c1e;
  --text:      #f5f5f7;
  --text-2:    #aeaeb2;
  --text-3:    #8e8e93;
  --border:    rgba(255, 255, 255, .10);
  --border-2:  rgba(255, 255, 255, .18);
  --track:     rgba(255, 255, 255, .11);
  --hover:     rgba(255, 255, 255, .06);

  --accent:      #0a84ff;
  --accent-hover:#409cff;
  --green:       #30d158;
  --red:         #ff453a;
  --amber:       #ff9f0a;

  --shadow: 0 8px 40px rgba(0, 0, 0, .5);
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  letter-spacing: -.01em;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  transition: background .5s var(--ease), color .5s var(--ease);
}

h1 { margin: 0; }
p  { margin: 0; }
ul { margin: 0; padding: 0; list-style: none; }
a  { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; -webkit-tap-highlight-color: transparent; }
svg { display: block; width: 100%; height: 100%; }
b, i { font-style: normal; font-weight: inherit; }

/* ============================ NAV ============================ */

.nav {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px clamp(20px, 5vw, 40px);
  background: color-mix(in srgb, var(--bg) 78%, transparent);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 1px solid var(--border);
}

.brand { font-size: 20px; font-weight: 600; letter-spacing: -.02em; }

.theme-toggle {
  position: relative;
  display: grid;
  place-items: center;
  width: 36px; height: 36px;
  border-radius: 50%;
  color: var(--text-2);
  transition: background .2s var(--ease), color .2s var(--ease);
}
.theme-toggle:hover { background: var(--hover); color: var(--text); }
.theme-toggle svg { position: absolute; width: 20px; height: 20px; transition: opacity .35s var(--ease), transform .35s var(--ease); }
.icon-sun  { opacity: 0; transform: rotate(-90deg) scale(.5); }
.icon-moon { opacity: 1; transform: none; }
html[data-theme="dark"] .icon-sun  { opacity: 1; transform: none; }
html[data-theme="dark"] .icon-moon { opacity: 0; transform: rotate(90deg) scale(.5); }

/* ============================ LAYOUT ============================ */

main {
  max-width: 600px;
  margin: 0 auto;
  padding: clamp(40px, 8vw, 72px) clamp(20px, 5vw, 24px) 60px;
  display: grid;
  gap: 20px;
}

.hero { text-align: center; margin-bottom: 8px; }
.hero h1 {
  font-size: clamp(34px, 7vw, 52px);
  font-weight: 700;
  letter-spacing: -.035em;
  line-height: 1.05;
}
.hero p {
  max-width: 420px;
  margin: 16px auto 0;
  font-size: clamp(16px, 2.4vw, 19px);
  line-height: 1.5;
  color: var(--text-2);
  font-weight: 400;
}

.card {
  padding: clamp(24px, 5vw, 40px);
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--r);
  box-shadow: var(--shadow);
}

/* ============================ RING ============================ */

.ring-wrap {
  position: relative;
  width: min(320px, 78vw);
  aspect-ratio: 1;
  margin: 0 auto 6px;
}

.ring { overflow: visible; }

.ring-track {
  fill: none;
  stroke: var(--track);
  stroke-width: 12;
  stroke-linecap: round;
}
.ring-fill {
  fill: none;
  stroke: var(--accent);
  stroke-width: 12;
  stroke-linecap: round;
  stroke-dasharray: 754;
  stroke-dashoffset: 754;
  transition: stroke-dashoffset .2s linear, stroke .5s var(--ease);
}
.ring-thumb {
  fill: var(--card);
  stroke: var(--accent);
  stroke-width: 4;
  opacity: 0;
  transition: opacity .4s var(--ease), stroke .5s var(--ease);
}
#tester[data-state="running"] .ring-thumb,
#tester[data-state="done"] .ring-thumb { opacity: 1; }

#tester[data-phase="up"] .ring-fill,
#tester[data-phase="up"] .ring-thumb { stroke: var(--green); }

.ring-center {
  position: absolute;
  inset: 22%;
  display: grid;
  place-items: center;
  text-align: center;
}

.readout {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  gap: 4px;
  transition: opacity .4s var(--ease), transform .4s var(--ease);
  pointer-events: none;
}
#tester[data-state="idle"] .readout { opacity: .5; }

.readout-phase {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-3);
}
.readout-value { display: flex; align-items: baseline; justify-content: center; gap: 5px; }
.readout-value b {
  font-size: clamp(40px, 11vw, 56px);
  font-weight: 600;
  letter-spacing: -.04em;
  font-variant-numeric: tabular-nums;
}
.readout-value i { font-size: 15px; font-weight: 500; color: var(--text-3); }

.status {
  margin-top: 4px;
  text-align: center;
  font-size: 15px;
  line-height: 1.45;
  color: var(--text-2);
  min-height: 22px;
}
.status b { font-weight: 600; color: var(--text); }
.status.warn b, .status.warn { color: var(--amber); }

/* ============================ STATS ============================ */

.stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin-top: 28px;
}
.stat {
  padding: 16px 12px;
  text-align: center;
  border-radius: var(--r-sm);
  background: var(--bg);
  border: 1px solid var(--border);
  transition: border-color .3s var(--ease), transform .3s var(--ease);
}
.stat.active { border-color: var(--accent); transform: translateY(-2px); }
#tester[data-phase="up"] .stat[data-metric="up"].active { border-color: var(--green); }

/* sinalização de lag no ping */
.stat[data-metric="ping"].lag { border-color: color-mix(in srgb, var(--red) 45%, transparent); }
.stat[data-metric="ping"].lag .stat-value b { color: var(--red); }
.stat[data-metric="ping"].lag .stat-label::after {
  content: 'lag';
  margin-left: 6px;
  padding: 1px 6px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: .02em;
  color: var(--red);
  background: color-mix(in srgb, var(--red) 14%, transparent);
  border-radius: 6px;
  vertical-align: 1px;
}
.stat-label { display: block; font-size: 12.5px; font-weight: 500; color: var(--text-3); }
.stat-value { display: flex; align-items: baseline; justify-content: center; gap: 4px; margin-top: 8px; }
.stat-value b { font-size: clamp(19px, 5vw, 24px); font-weight: 600; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.stat-value i { font-size: 12px; font-weight: 500; color: var(--text-3); }

.restart {
  display: block;
  margin: 24px auto 0;
  padding: 11px 26px;
  font-size: 15px;
  font-weight: 500;
  color: var(--accent);
  border: 1px solid var(--border-2);
  border-radius: 980px;
  transition: background .2s var(--ease), border-color .2s;
}
.restart:hover { background: var(--hover); border-color: var(--accent); }

/* ============================ TESTE DE CONEXÃO ============================ */

.conn-form { display: flex; gap: 10px; }

.conn-field {
  position: relative;
  flex: 1;
  display: flex;
  align-items: center;
}
.conn-globe {
  position: absolute;
  left: 14px;
  width: 18px; height: 18px;
  color: var(--text-3);
  pointer-events: none;
}
.conn-input {
  width: 100%;
  padding: 13px 16px 13px 42px;
  font-family: inherit;
  font-size: 15px;
  font-weight: 500;
  letter-spacing: -.01em;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border-2);
  border-radius: 12px;
  outline: none;
  transition: border-color .2s var(--ease), box-shadow .2s var(--ease);
}
.conn-input::placeholder { color: var(--text-3); font-weight: 400; }
.conn-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 18%, transparent);
}
.conn-input.err {
  border-color: var(--red);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--red) 16%, transparent);
  animation: shake .32s var(--ease);
}
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-5px); }
  75% { transform: translateX(5px); }
}

.conn-hint {
  margin: 10px 2px 0;
  font-size: 12.5px;
  line-height: 1.4;
  color: var(--text-3);
  transition: color .2s var(--ease);
}
.conn-hint.err { color: var(--red); }

.conn-btn {
  flex-shrink: 0;
  padding: 0 22px;
  font-size: 15px;
  font-weight: 500;
  color: #fff;
  background: var(--accent);
  border-radius: 12px;
  transition: background .2s, transform .2s var(--ease);
}
.conn-btn:hover  { background: var(--accent-hover); }
.conn-btn:active { transform: scale(.97); }
.conn-btn:disabled { opacity: .55; pointer-events: none; }

.conn-result {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 24px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
}

.conn-status {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 5px 12px 5px 10px;
  font-size: 13px;
  font-weight: 500;
  border-radius: 980px;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text-2);
}
.conn-status .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--text-3); transition: background .3s; }
.conn-status[data-state="checking"] .dot { background: var(--amber); animation: blink 1s ease-in-out infinite; }
.conn-status[data-state="online"]  { color: var(--green); border-color: color-mix(in srgb, var(--green) 40%, transparent); }
.conn-status[data-state="online"] .dot { background: var(--green); box-shadow: 0 0 0 0 color-mix(in srgb, var(--green) 55%, transparent); animation: pulse 2s infinite; }
.conn-status[data-state="lag"]     { color: var(--red); border-color: color-mix(in srgb, var(--red) 42%, transparent); }
.conn-status[data-state="lag"] .dot { background: var(--red); animation: blink 1.1s ease-in-out infinite; }
.conn-status[data-state="offline"] { color: var(--red); border-color: color-mix(in srgb, var(--red) 40%, transparent); }
.conn-status[data-state="offline"] .dot { background: var(--red); }

@keyframes blink { 50% { opacity: .3; } }
@keyframes pulse { 70% { box-shadow: 0 0 0 7px transparent; } 100% { box-shadow: 0 0 0 0 transparent; } }

.conn-host { font-size: 12.5px; color: var(--text-3); font-variant-numeric: tabular-nums; }
.conn-latency { display: inline-flex; align-items: baseline; gap: 5px; margin-left: auto; }
.conn-latency b { font-size: 17px; font-weight: 600; font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
.conn-latency i { font-size: 12px; color: var(--text-3); }
.conn-result[data-state="lag"] .conn-latency b { color: var(--red); }

.divider { height: 1px; border: 0; background: var(--border); margin: 24px 0; }

/* ============================ IP ============================ */

.ips { display: grid; grid-template-columns: 1fr; gap: 14px; }

.ip {
  padding: 16px 18px;
  border-radius: var(--r-sm);
  background: var(--bg);
  border: 1px solid var(--border);
}
.ip-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--text-3);
}
.ip-value {
  display: block;
  margin-top: 8px;
  font-size: clamp(15px, 3.4vw, 18px);
  font-weight: 600;
  letter-spacing: -.01em;
  font-variant-numeric: tabular-nums;
  word-break: break-all;
  line-height: 1.3;
}
.ip-value.flip { animation: flip .45s var(--ease); }
@keyframes flip {
  from { opacity: 0; transform: translateY(-6px); filter: blur(3px); }
  to   { opacity: 1; transform: none; filter: none; }
}
.ip-sub { display: block; margin-top: 6px; font-size: 11.5px; color: var(--text-3); }

/* ============================ DETALHES ============================ */

.details-title {
  display: block;
  margin-bottom: 6px;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--text-3);
}
.details { display: grid; }
.details li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 0;
  font-size: 14px;
  border-bottom: 1px solid var(--border);
}
.details li:last-child { border-bottom: 0; padding-bottom: 0; }
.details span { color: var(--text-3); }
.details b {
  font-weight: 600;
  text-align: right;
  letter-spacing: -.01em;
  font-variant-numeric: tabular-nums;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 62%;
}
.details b[data-q="good"] { color: var(--green); }
.details b[data-q="ok"]   { color: var(--amber); }
.details b[data-q="bad"]  { color: var(--red); }

/* ============================ RODAPÉ ============================ */

.foot {
  margin-top: 4px;
  text-align: center;
  font-size: 12.5px;
  color: var(--text-3);
}

/* ============================ TOAST ============================ */

.toast {
  position: fixed;
  left: 50%;
  bottom: 26px;
  z-index: 40;
  padding: 11px 20px;
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
  background: var(--card);
  border: 1px solid var(--border-2);
  border-radius: 14px;
  box-shadow: var(--shadow);
  transform: translate(-50%, 16px);
  opacity: 0;
  pointer-events: none;
  transition: opacity .3s var(--ease), transform .3s var(--ease);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ============================ RESPONSIVO ============================ */

@media (max-width: 560px) {
  .stats { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 460px) {
  .conn-form { flex-direction: column; }
  .conn-btn { padding: 13px; }
  .conn-latency { margin-left: 0; }
  .ips { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
}
