:root {
  --bg: #f8fafc;
  --surface: #ffffff;
  --surface-hover: #f1f5f9;
  --border: #e2e8f0;
  --text: #0f172a;
  --text-secondary: #475569;
  --accent: #3b82f6;
  --accent-2: #2563eb;
  --online-bg: rgba(34,197,94,0.10);
  --online-text: #16a34a;
  --offline-bg: rgba(239,68,68,0.10);
  --offline-text: #dc2626;
  --shadow: 0 4px 24px rgba(0,0,0,0.06);
  --radius: 16px;
  --latency-good: #16a34a;
  --latency-mid: #ca8a04;
  --latency-bad: #dc2626;
}

[data-theme="dark"] {
  --bg: #0a0e1a;
  --surface: #12121a;
  --surface-hover: #1a1a24;
  --border: #27272a;
  --text: #e2e8f0;
  --text-secondary: #94a3b8;
  --accent: #60a5fa;
  --accent-2: #3b82f6;
  --online-bg: rgba(34,197,94,0.12);
  --online-text: #4ade80;
  --offline-bg: rgba(239,68,68,0.12);
  --offline-text: #f87171;
  --shadow: 0 8px 32px rgba(0,0,0,0.35);
  --latency-good: #4ade80;
  --latency-mid: #facc15;
  --latency-bad: #f87171;
}

* { margin:0; padding:0; box-sizing:border-box; }
html { font-family: 'Inter', system-ui, -apple-system, sans-serif; }
body {
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  transition: background .25s, color .25s;
  -webkit-font-smoothing: antialiased;
}

.app { max-width: 960px; margin: 0 auto; padding: 40px 20px; }

/* Header */
.header {
  display:flex; align-items:center; justify-content:space-between;
  margin-bottom: 32px; gap: 16px; flex-wrap: wrap;
}
.brand { display:flex; align-items:center; gap: 14px; }
.brand .logo { color: var(--accent); }
.brand h1 { font-size: 22px; font-weight: 700; letter-spacing: -0.3px; }
.brand-sub {
  display:block; font-size: 13px; color: var(--text-secondary); margin-top: 2px;
}

.controls { display:flex; align-items:center; gap: 12px; }
.control-group select {
  display: block;
  background-color: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 32px 8px 12px;
  font-size: 13px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  outline: none;
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  background-size: 12px;
  transition: border-color .2s, box-shadow .2s;
  box-shadow: 0 1px 2px rgba(0,0,0,0.04);
}
.control-group select:hover {
  border-color: var(--accent);
}
.control-group select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(59,130,246,0.15);
}

.theme-btn {
  width: 40px; height: 40px; border-radius: 10px;
  background: var(--surface); border: 1px solid var(--border);
  color: var(--text-secondary); cursor: pointer; display: flex; align-items: center; justify-content: center;
  transition: transform .15s, border-color .2s;
  position: relative;
}
.theme-btn:hover { transform: translateY(-1px); border-color: var(--accent); color: var(--accent); }
.theme-btn svg { position: absolute; transition: opacity .2s, transform .2s; }
[data-theme="dark"] .icon-sun { opacity: 0; transform: scale(0.8); }
[data-theme="dark"] .icon-moon { opacity: 1; transform: scale(1); }
[data-theme="light"] .icon-sun { opacity: 1; transform: scale(1); }
[data-theme="light"] .icon-moon { opacity: 0; transform: scale(0.8); }

/* Grid */
.grid { display: grid; gap: 14px; }

/* Card */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 22px;
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px;
  box-shadow: var(--shadow);
  transition: transform .15s, box-shadow .2s, border-color .2s;
}
.card:hover {
  transform: translateY(-2px);
  box-shadow: 0 12px 40px rgba(0,0,0,0.12);
  border-color: var(--accent);
}
[data-theme="dark"] .card:hover {
  box-shadow: 0 12px 40px rgba(0,0,0,0.45);
}

.card-left { display:flex; align-items:center; gap: 14px; min-width: 0; }
.flag-img {
  width: 40px; height: 28px; border-radius: 6px; object-fit: cover;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15); flex-shrink: 0;
}

/* Pulse dot status */
.pulse-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
  display: inline-block;
}
.pulse-dot.online {
  background: var(--online-text);
  box-shadow: 0 0 0 0 rgba(34,197,94,0.7);
  animation: pulse-green 2s infinite;
}
.pulse-dot.offline {
  background: var(--offline-text);
  box-shadow: 0 0 0 0 rgba(239,68,68,0.7);
  animation: pulse-red 2s infinite;
}
@keyframes pulse-green {
  0% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(34,197,94,0.7); }
  70% { transform: scale(1); box-shadow: 0 0 0 6px rgba(34,197,94,0); }
  100% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(34,197,94,0); }
}
@keyframes pulse-red {
  0% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(239,68,68,0.7); }
  70% { transform: scale(1); box-shadow: 0 0 0 6px rgba(239,68,68,0); }
  100% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(239,68,68,0); }
}

.card-name { font-weight: 600; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.card-right {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  justify-content: center;
  gap: 3px;
  flex-shrink: 0;
  min-height: 40px;
}

.latency-row {
  font-size: 13px;
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
  line-height: 1.4;
  text-align: right;
}

/* Latency colors */
.latency-good { color: var(--latency-good); font-weight: 600; }
.latency-mid   { color: var(--latency-mid); font-weight: 600; }
.latency-bad   { color: var(--latency-bad); font-weight: 600; }

/* Footer */
.footer { 
  margin-top: 28px; 
  text-align: center; 
  font-size: 12px; 
  color: var(--text-secondary); 
  display: flex;
  flex-direction: column;
  gap: 2px;
}

/* Skeleton loader */
.skeleton .skeleton-box {
  background: linear-gradient(90deg, var(--surface) 25%, var(--border) 50%, var(--surface) 75%);
  background-size: 200% 100%;
  animation: skeleton 1.2s infinite;
  border-radius: 6px;
}
@keyframes skeleton {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* Responsive */
@media (max-width: 640px) {
  .app { padding: 24px 16px; }
  .header { flex-direction: column; align-items: flex-start; }
  .card { flex-direction: column; align-items: flex-start; gap: 12px; }
  .card-right { align-items: flex-start; width: 100%; flex-direction: row; justify-content: space-between; }
}
