:root {
  color-scheme: dark;
  --bg: #050b10;
  --panel: #0a151d;
  --panel-2: #111f2a;
  --line: rgba(255,255,255,.12);
  --text: #f6fbff;
  --muted: #a9bdca;
  --cyan: #29d3ff;
  --green: #32e6a1;
  --red: #ff6b78;
  --yellow: #ffd166;
  --steel: #d9e5ec;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at 18% 0%, rgba(41,211,255,.13), transparent 30%),
    radial-gradient(circle at 78% 100%, rgba(50,230,161,.10), transparent 32%),
    linear-gradient(135deg, rgba(255,209,102,.045), transparent 36%),
    var(--bg);
  color: var(--text);
  overflow: hidden;
}

.shell {
  height: 100dvh;
  display: grid;
  grid-template-rows: auto 1fr;
  overflow: hidden;
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 64px;
  padding: 10px clamp(16px, 3vw, 34px);
  border-bottom: 1px solid var(--line);
  background: rgba(7,16,24,.86);
  backdrop-filter: blur(16px);
  position: sticky;
  top: 0;
  z-index: 5;
  max-width: 100vw;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  font-weight: 800;
  letter-spacing: 0;
  min-width: 0;
}

.logo {
  display: block;
  width: 96px;
  height: 96px;
  object-fit: contain;
}

#serverStatus {
  text-align: right;
  overflow-wrap: anywhere;
}

.mark {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  color: #03131a;
  background: linear-gradient(135deg, var(--cyan), var(--green));
  font-weight: 900;
}

main {
  height: 100%;
  min-height: 0;
  padding: clamp(12px, 2vw, 22px);
  width: min(1240px, 100%);
  margin: 0 auto;
  overflow-x: hidden;
}

.speedtest-layout {
  height: 100%;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(480px, 1.15fr) minmax(330px, .85fr);
  gap: 16px;
  align-items: stretch;
}

.panel,
.meter-panel,
.control-panel {
  background:
    linear-gradient(180deg, rgba(255,255,255,.07), rgba(255,255,255,.025)),
    var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: clamp(14px, 2vw, 22px);
  box-shadow: 0 20px 70px rgba(0,0,0,.28);
}

.meter-panel {
  display: grid;
  align-content: center;
  justify-items: center;
  gap: 12px;
  min-height: 0;
}

.control-panel {
  align-self: stretch;
  align-content: center;
}

h1, h2, h3, p {
  margin-top: 0;
}

h1 {
  font-size: clamp(34px, 4.2vw, 56px);
  line-height: 1;
  letter-spacing: 0;
  margin-bottom: 12px;
}

h2 {
  font-size: 18px;
}

.muted {
  color: var(--muted);
}

select, input {
  width: 100%;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  border-radius: 8px;
  padding: 11px;
  font: inherit;
}

button {
  border: 0;
  border-radius: 8px;
  padding: 11px 16px;
  font: inherit;
  font-weight: 800;
  color: #03131a;
  background: linear-gradient(135deg, var(--green), var(--cyan));
  cursor: pointer;
  min-height: 48px;
  box-shadow: 0 14px 30px rgba(41,211,255,.18);
}

button:disabled {
  opacity: .55;
  cursor: wait;
}

.secondary {
  background: var(--cyan);
}

.stack {
  display: grid;
  gap: 12px;
}

.gauge-card {
  width: min(660px, 100%);
  display: grid;
  justify-items: center;
  gap: 12px;
}

.dial {
  width: min(620px, 100%);
  height: clamp(218px, 38vh, 310px);
  min-height: 0;
  border-radius: 26px;
  display: grid;
  place-items: center;
  position: relative;
  overflow: hidden;
  isolation: isolate;
  background: transparent;
  text-align: center;
  box-shadow: 0 24px 70px rgba(0,0,0,.22);
}

.dial::before {
  content: none;
}

.dial::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: 12%;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background:
    radial-gradient(circle at 35% 30%, #ffffff, #bdefff 45%, #1bd8ff 70%);
  transform: translate(-50%, 50%);
  box-shadow:
    0 0 0 7px rgba(41,211,255,.16),
    0 0 34px rgba(41,211,255,.55);
  z-index: 7;
}

.gauge-aura {
  display: none;
}

.gauge-face {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  z-index: 1;
  user-select: none;
  pointer-events: none;
}

.gauge-track,
.gauge-ring,
.gauge-marks {
  display: none;
}

.gauge-track {
  background:
    conic-gradient(from 270deg at 50% 50%,
      rgba(255,255,255,.18) 0deg 180deg,
      transparent 181deg 360deg);
  z-index: 2;
}

.gauge-ring {
  background:
    conic-gradient(from 270deg at 50% 50%,
      rgba(217,229,236,.88) 0deg,
      #ffffff 90deg,
      rgba(217,229,236,.88) 180deg,
      transparent 181deg 360deg);
  mask: radial-gradient(circle at center, transparent 0 57%, #000 58% 63%, transparent 64%);
  -webkit-mask: radial-gradient(circle at center, transparent 0 57%, #000 58% 63%, transparent 64%);
  z-index: 3;
}

.gauge-marks {
  background:
    repeating-conic-gradient(from 270deg at 50% 50%,
      rgba(255,255,255,.92) 0deg 1.2deg,
      transparent 1.2deg 6deg);
  mask: radial-gradient(circle at center, transparent 0 68%, #000 69% 76%, transparent 77%);
  -webkit-mask: radial-gradient(circle at center, transparent 0 68%, #000 69% 76%, transparent 77%);
  z-index: 4;
}

.needle {
  position: absolute;
  left: 50%;
  bottom: 11.5%;
  width: min(250px, 40%);
  height: 6px;
  border-radius: 999px;
  background:
    linear-gradient(90deg, transparent 0 8%, rgba(255,255,255,.78) 8% 16%, #ffffff 16% 74%, #ff4b5c 100%);
  transform-origin: 0 50%;
  transform: rotate(var(--needle-rotation, -90deg));
  transition: transform .18s cubic-bezier(.2,.8,.2,1);
  box-shadow: 0 0 22px rgba(255,75,92,.45);
  z-index: 6;
}

.tick {
  display: none;
}

.tick-left {
  left: 7%;
}

.tick-low {
  left: 22%;
  bottom: 53%;
}

.tick-mid {
  left: 50%;
  transform: translateX(-50%);
  bottom: 80%;
}

.tick-high {
  right: 22%;
  bottom: 53%;
}

.tick-right {
  right: 6%;
}

.dial-content {
  position: relative;
  z-index: 9;
  display: grid;
  gap: 2px;
  justify-items: center;
  width: min(430px, 94%);
  min-width: 0;
  margin-top: 0;
  padding: 15px 22px 13px;
  border: 1px solid rgba(255,255,255,.10);
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(255,255,255,.09), rgba(255,255,255,.025)),
    rgba(3,12,18,.70);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.08), 0 18px 50px rgba(0,0,0,.22);
  backdrop-filter: blur(10px);
}

.result-modal {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(0,0,0,.58);
  backdrop-filter: blur(10px);
}

.result-dialog {
  width: min(520px, 100%);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: clamp(18px, 3vw, 28px);
  background:
    linear-gradient(180deg, rgba(255,255,255,.08), rgba(255,255,255,.03)),
    var(--panel);
  box-shadow: 0 28px 90px rgba(0,0,0,.48);
}

.result-dialog h2 {
  font-size: clamp(24px, 4vw, 36px);
  margin-bottom: 8px;
}

.result-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin: 18px 0;
}

.result-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.speed {
  width: 100%;
  font-size: clamp(44px, 6vw, 78px);
  line-height: .95;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  text-align: center;
  white-space: nowrap;
  text-shadow: 0 0 30px rgba(41,211,255,.32);
}

.unit {
  color: var(--muted);
  font-weight: 700;
  font-size: 12px;
  text-transform: uppercase;
}

.stage {
  color: var(--steel);
  font-size: 13px;
  font-weight: 800;
  text-transform: uppercase;
}

.progress-track {
  width: min(520px, 100%);
  height: 8px;
  background: rgba(255,255,255,.08);
  border-radius: 999px;
  overflow: hidden;
}

.progress-fill {
  width: var(--progress, 0%);
  height: 100%;
  background: linear-gradient(90deg, var(--cyan), var(--green), var(--yellow));
  transition: width .2s ease;
  box-shadow: 0 0 20px rgba(41,211,255,.35);
}

.stats {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.network-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.network-card {
  min-width: 0;
  background:
    linear-gradient(180deg, rgba(255,255,255,.055), rgba(255,255,255,.025));
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
}

.network-card b {
  display: block;
  margin-top: 4px;
  font-size: 15px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.stat {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
}

.stat b {
  display: block;
  font-size: clamp(18px, 2vw, 24px);
  margin-top: 5px;
  white-space: nowrap;
}

.run-note {
  min-height: 42px;
  border: 1px solid var(--line);
  background: rgba(255,255,255,.04);
  border-radius: 8px;
  padding: 11px;
  color: var(--muted);
  line-height: 1.25;
  font-size: 14px;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th, td {
  border-bottom: 1px solid var(--line);
  padding: 12px;
  text-align: left;
  vertical-align: top;
}

th {
  color: var(--muted);
  font-size: 13px;
}

.admin-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 12px;
  margin-bottom: 18px;
}

.admin-main {
  overflow: auto;
}

.admin-login {
  width: min(430px, 100%);
  margin: clamp(30px, 8vh, 80px) auto;
  text-align: center;
}

.admin-content {
  width: 100%;
}

.login-logo {
  width: 150px;
  height: 150px;
  object-fit: contain;
  margin: 0 auto 12px;
}

.captcha-row {
  display: grid;
  grid-template-columns: 1fr 52px;
  gap: 10px;
  align-items: stretch;
}

.captcha-box {
  min-height: 52px;
  display: grid;
  align-content: center;
  justify-items: start;
  gap: 2px;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255,255,255,.055);
  text-align: left;
}

.captcha-box b {
  font-size: 20px;
  letter-spacing: 0;
}

.icon-button {
  min-height: 52px;
  padding: 0;
  display: grid;
  place-items: center;
  font-size: 22px;
}

.ghost-button {
  background: rgba(255,255,255,.08);
  color: var(--text);
  border: 1px solid var(--line);
  box-shadow: none;
}

@media (max-width: 880px) {
  .speedtest-layout {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(300px, 48vh) 1fr;
    gap: 10px;
  }

  .admin-grid,
  .stats {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  header {
    position: static;
    min-height: 56px;
    padding: 8px 14px;
  }

  #serverStatus {
    text-align: right;
    font-size: 12px;
  }

  .meter-panel {
    padding: 10px 12px;
    gap: 8px;
  }

  .dial {
    width: min(360px, 100%);
    height: clamp(172px, 25vh, 205px);
  }

  .control-panel {
    padding: 12px;
    align-content: start;
  }

  .logo {
    width: 66px;
    height: 66px;
  }

  .brand {
    gap: 9px;
  }

  .brand span {
    font-size: 15px;
  }

  select, input {
    padding: 9px 10px;
  }

  button {
    min-height: 42px;
    padding: 9px 14px;
  }

  .stack {
    gap: 9px;
  }

  .stat {
    padding: 9px;
  }

  .stat b {
    font-size: 18px;
  }

  .network-grid {
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }

  .network-card {
    padding: 8px;
  }

  .network-card b {
    font-size: 12px;
  }

  .dial-content {
    width: min(330px, 94%);
    padding: 11px 16px 9px;
  }

  .run-note {
    min-height: 36px;
    font-size: 12px;
    padding: 9px;
  }
}

@media (max-width: 420px) {
  .speedtest-layout {
    grid-template-rows: minmax(284px, 46vh) 1fr;
  }

  .dial {
    height: clamp(160px, 23vh, 188px);
  }

  .tick {
    font-size: 10px;
  }

  .speed {
    font-size: clamp(38px, 13vw, 52px);
  }

  .unit,
  .stage {
    font-size: 11px;
  }

  .network-card b {
    font-size: 11px;
  }
}

@media (max-height: 720px) {
  header {
    min-height: 52px;
  }

  main {
    padding: 10px;
  }

  .dial {
    height: clamp(178px, 36vh, 260px);
  }

  .meter-panel,
  .control-panel {
    padding: 10px;
  }

  .speed {
    font-size: clamp(38px, 5.6vw, 64px);
  }
}
