:root {
  --text: #eef5ff;
  --muted: rgba(214, 220, 230, 0.74);
  --graylight: rgba(204, 212, 224, 0.82);
  --label-blue: #61c8ff;
  --label-green: #8cf0ad;
  --glass: rgba(5, 12, 30, 0.12);
  --line: rgba(90, 144, 255, 0.12);
  --shadow: 0 16px 34px rgba(0, 0, 0, 0.28);
  --btn-shadow: 0 6px 18px rgba(8, 42, 98, 0.16), inset 0 1px 0 rgba(255,255,255,0.08);
  --gauge-width: 360px;
  --gauge-height: 220px;
  --gauge-readout: 2.05rem;
  --page-gap-bottom: 110px;
  --start-size: 120px;
}

* { box-sizing: border-box; }
html, body {
  width: 100%;
  height: 100%;
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  background: #000;
}
body { overflow: hidden; }
button, input { font: inherit; }
button { cursor: pointer; }

.hidden { display: none !important; }

.page-frame {
  width: min(1710px, calc(100vw - 8px));
  height: calc(100dvh - 8px);
  margin: 4px auto;
  border-radius: 34px;
  position: relative;
  overflow: hidden;
  background: #020611;
  box-shadow: 0 0 0 1px rgba(20, 76, 172, 0.1), 0 14px 32px rgba(0, 0, 0, 0.28);
}
.page-frame::before {
  content: "";
  position: absolute;
  inset: -2%;
  background: url('./assets/background.png') center center / cover no-repeat;
  filter: blur(4px) brightness(0.62);
  transform: scale(1.02);
  opacity: 0.92;
  pointer-events: none;
}
.page-frame::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(1, 6, 18, 0.12), rgba(2, 8, 21, 0.06));
  pointer-events: none;
}
.topbar, .main-stage, .sticky-action-stack, .result-modal { position: relative; z-index: 1; }

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 20px 0;
  min-height: 72px;
}
.brand-wrap { display: flex; align-items: center; gap: 14px; }
.logo-badge {
  width: 64px;
  height: 64px;
  border-radius: 16px;
  overflow: hidden;
  display: block;
  flex: 0 0 auto;
}
.logo-badge img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: contain;
}
.brand-text {
  font-size: clamp(1.1rem, 1.5vw, 1.9rem);
  font-weight: 800;
  letter-spacing: 0.015em;
}
.top-actions { display: flex; align-items: center; gap: 12px; }

.action-btn, .top-btn, .icon-globe-btn, .server-link-btn, .server-option, .history-item {
  border: 1px solid rgba(90, 144, 255, 0.16);
  background: rgba(4, 18, 46, 0.22);
  color: var(--text);
  border-radius: 999px;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  box-shadow: var(--btn-shadow);
  transition: transform 0.16s ease, background 0.16s ease, border-color 0.16s ease;
}
.action-btn:hover, .top-btn:hover, .icon-globe-btn:hover, .server-link-btn:hover,
.server-option:hover, .history-item:hover {
  transform: translateY(-1px);
  border-color: rgba(115, 172, 255, 0.34);
}
.action-btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }
.ghost-btn { background: rgba(4, 18, 46, 0.18); }
.primary-btn {
  background: linear-gradient(180deg, rgba(114, 184, 244, 0.94), rgba(74, 129, 189, 0.88));
  color: #fff;
}
.top-btn {
  min-width: 138px;
  height: 52px;
  padding: 0 24px;
  font-size: 0.95rem;
  font-weight: 800;
}

.main-stage {
  width: 100%;
  height: calc(100% - 72px);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 4px 18px var(--page-gap-bottom);
}

.latency-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  margin-top: 6px;
}
.latency-title {
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.22em;
  color: rgba(208, 214, 226, 0.86);
}
.latency-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(90px, 120px));
  gap: 26px;
  align-items: end;
  justify-items: center;
}
.latency-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}
.latency-item-label {
  color: rgba(201, 208, 220, 0.68);
  font-size: 0.72rem;
  letter-spacing: 0.08em;
}
.latency-item-value {
  font-size: 0.98rem;
  font-weight: 900;
  color: #eef6ff;
}
.latency-active-value { color: #ffffff; }

.server-select-row {
  position: relative;
  z-index: 60;
  display: flex;
  align-items: flex-start;
  gap: 12px;
  margin-top: 8px;
}
.icon-globe-btn {
  width: 54px;
  height: 54px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1.35rem;
  padding: 0;
}
.server-picker-wrap {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 160px;
}
.inline-caption {
  color: rgba(220, 227, 238, 0.62);
  font-size: 0.82rem;
  font-weight: 700;
  line-height: 1.1;
}
.server-link-btn {
  border: none;
  background: transparent;
  box-shadow: none;
  padding: 0;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: #ffffff;
  font-size: 0.96rem;
  font-weight: 800;
}
.server-caret { font-size: 0.72em; }
.server-menu {
  position: absolute;
  top: calc(100% + 12px);
  left: 0;
  min-width: 280px;
  max-height: 360px;
  padding: 12px;
  border-radius: 24px;
  background: rgba(2, 18, 50, 0.44);
  border: 1px solid rgba(96, 166, 255, 0.22);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  box-shadow: 0 16px 40px rgba(0,0,0,0.28);
  z-index: 120;
}
.server-menu-head { margin-bottom: 10px; }
.server-search-input {
  width: 100%;
  height: 40px;
  border-radius: 14px;
  border: 1px solid rgba(95, 159, 255, 0.18);
  background: rgba(255, 255, 255, 0.06);
  color: #fff;
  padding: 0 14px;
  outline: none;
}
.server-search-input::placeholder { color: rgba(221, 227, 235, 0.55); }
.server-options {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 286px;
  overflow: auto;
}
.server-option {
  width: 100%;
  border-radius: 18px;
  padding: 12px 14px;
  text-align: left;
  background: rgba(255, 255, 255, 0.03);
}
.server-option strong,
.server-option .server-name {
  display: block;
  font-size: 1rem;
  font-weight: 800;
  color: #f4f8ff;
}
.server-option small,
.server-option .server-desc {
  display: block;
  margin-top: 3px;
  color: rgba(224, 230, 239, 0.7);
  font-size: 0.84rem;
}
.server-option.active {
  border-color: rgba(111, 179, 255, 0.42);
  background: rgba(48, 116, 201, 0.18);
}
.server-empty {
  padding: 18px 10px;
  text-align: center;
  color: rgba(224, 230, 239, 0.65);
}

.workspace-grid {
  width: 100%;
  flex: 1 1 auto;
  display: grid;
  grid-template-columns: minmax(132px, 220px) minmax(620px, 1fr) minmax(132px, 220px);
  align-items: stretch;
  gap: 20px;
  margin-top: 8px;
}
.ads-sidebar {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
}
.ads-card-inner {
  width: min(100%, 220px);
  min-height: clamp(640px, 78vh, 860px);
  height: min(78vh, 860px);
  border-radius: 28px;
  padding: 24px;
  background: linear-gradient(180deg, rgba(255,255,255,0.02), rgba(255,255,255,0.01));
  border: 1px solid rgba(93, 147, 255, 0.08);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.01), 0 8px 18px rgba(0,0,0,0.05);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  text-align: center;
}
.ads-title {
  color: rgba(94, 199, 255, 0.74);
  font-size: 0.76rem;
  font-weight: 800;
  letter-spacing: 0.22em;
  margin-bottom: 12px;
}
.ads-placeholder {
  color: rgba(221, 226, 233, 0.52);
  font-size: 1rem;
  font-weight: 700;
}

.content-stage {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  min-height: 100%;
  padding-top: 8px;
}
.center-start-stack {
  position: absolute;
  top: 92px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  z-index: 50;
}
.start-btn {
  width: var(--start-size);
  height: var(--start-size);
  min-width: var(--start-size);
  border-radius: 50%;
  padding: 0;
  background: rgba(116, 181, 243, 0.18);
  border-color: rgba(116, 181, 243, 0.38);
  font-size: clamp(1rem, 1.5vw, 1.2rem);
  font-weight: 900;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.duration-center {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}
.duration-caption {
  color: rgba(228, 234, 245, 0.84);
  font-size: 0.82rem;
  font-weight: 700;
}
.duration-line {
  display: flex;
  align-items: center;
  gap: 12px;
}
.duration-line input {
  width: 74px;
  height: 38px;
  border-radius: 18px;
  border: 1px solid rgba(89, 144, 255, 0.14);
  background: rgba(2, 14, 42, 0.22);
  color: var(--text);
  text-align: center;
  font-size: 1rem;
  font-weight: 800;
  outline: none;
}
.duration-line span {
  color: var(--text);
  font-size: 0.9rem;
  font-weight: 700;
}
.center-start-stack.is-running {
  visibility: hidden;
  pointer-events: none;
}

.traffic-overlay {
  position: absolute;
  inset: 130px 8% 150px;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.28s ease;
  z-index: 12;
}
.content-stage.is-running .traffic-overlay { opacity: 1; }
.traffic-stream {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 36%;
}
.traffic-stream-left { left: 50%; transform: translateX(-100%); }
.traffic-stream-right { left: 50%; }
.traffic-line {
  position: absolute;
  left: 50%;
  top: 6%;
  width: 2px;
  height: 88%;
  transform-origin: top center;
  background: linear-gradient(180deg, rgba(92, 207, 255, 0.02), rgba(92, 207, 255, 0.14), rgba(92, 207, 255, 0.02));
  box-shadow: 0 0 18px rgba(92, 207, 255, 0.18);
}
.traffic-stream-left .traffic-line { transform: translateX(-50%) rotate(18deg); }
.traffic-stream-right .traffic-line { transform: translateX(-50%) rotate(-18deg); }
.traffic-dot {
  position: absolute;
  left: 50%;
  top: 8%;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(166, 240, 255, 0.98) 0%, rgba(92, 207, 255, 0.8) 52%, rgba(92, 207, 255, 0) 72%);
  filter: drop-shadow(0 0 8px rgba(92, 207, 255, 0.55));
  animation: flow-down 1.5s linear infinite;
}
.traffic-stream-left .traffic-dot { transform-origin: top center; transform: translateX(-50%) rotate(18deg); }
.traffic-stream-right .traffic-dot { transform-origin: top center; transform: translateX(-50%) rotate(-18deg); }
.traffic-dot.reverse { animation-name: flow-up; }
.traffic-dot-b { animation-delay: 0.45s; }
.traffic-dot-c { animation-delay: 0.8s; }
@keyframes flow-down {
  0% { top: 8%; opacity: 0; }
  12% { opacity: 1; }
  100% { top: 88%; opacity: 0; }
}
@keyframes flow-up {
  0% { top: 88%; opacity: 0; }
  12% { opacity: 1; }
  100% { top: 8%; opacity: 0; }
}

.speed-row {
  width: min(860px, 100%);
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 22px;
  align-items: start;
  justify-items: center;
  margin-top: 180px;
  position: relative;
  z-index: 20;
}
.gauge-card {
  width: min(var(--gauge-width), 100%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}
.metric-label {
  font-size: 0.74rem;
  font-weight: 800;
  letter-spacing: 0.2em;
}
.gauge-label {
  margin-bottom: -2px;
  transform: translateY(-2px);
}
.download-label { color: var(--label-blue); }
.upload-label { color: var(--label-green); }
.gauge-shell {
  position: relative;
  width: var(--gauge-width);
  height: var(--gauge-height);
}
.gauge-shell canvas {
  width: 100%;
  height: 100%;
  display: block;
}
.gauge-live-readout {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  pointer-events: none;
  text-shadow: 0 4px 14px rgba(0,0,0,0.28);
}
.gauge-readout-below { margin-top: -4px; }
.gauge-live-readout strong {
  font-size: clamp(1.78rem, 2.3vw, 2.55rem);
  line-height: 0.92;
  font-weight: 900;
  color: #f2f8ff;
}
.gauge-live-readout span {
  font-size: 0.82rem;
  font-weight: 800;
  color: rgba(244, 247, 252, 0.94);
}
.gauge-upload-readout strong,
.gauge-upload-readout span { color: #f0ffe0; }

.info-stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  margin-top: 6px;
  margin-bottom: 88px;
  text-align: center;
  position: relative;
  z-index: 24;
}
.earth-icon {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 1rem;
  color: #86d7ff;
  background: rgba(3, 18, 52, 0.22);
  border: 1px solid rgba(95, 159, 255, 0.14);
}
.isp-line {
  font-size: 1.02rem;
  font-weight: 800;
  color: #edf5ff;
}
.ip-line, .location-line {
  font-size: 0.9rem;
  font-weight: 700;
  color: rgba(220, 226, 234, 0.9);
}

.sticky-action-stack {
  position: fixed;
  left: 50%;
  bottom: 10px;
  transform: translateX(-50%);
  z-index: 70;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}
.sticky-top-row {
  display: flex;
  align-items: center;
  gap: 14px;
}
.center-btn {
  min-width: 128px;
  height: 40px;
  padding: 0 20px;
  font-size: 0.96rem;
  font-weight: 800;
}
.history-main-btn { min-width: 142px; }
.history-dropdown {
  position: absolute;
  bottom: calc(100% + 12px);
  left: 50%;
  transform: translateX(-50%);
  width: min(420px, calc(100vw - 40px));
  background: rgba(3, 16, 46, 0.72);
  border: 1px solid rgba(89, 144, 255, 0.16);
  border-radius: 20px;
  padding: 12px;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  box-shadow: var(--shadow);
  max-height: 340px;
  overflow: hidden;
}
.history-dropdown-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
  gap: 12px;
}
.mini-link-btn {
  background: transparent;
  border: none;
  color: var(--label-blue);
  font-weight: 700;
  padding: 0;
  box-shadow: none;
}
.history-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 272px;
  overflow: auto;
}
.history-item {
  width: 100%;
  text-align: left;
  padding: 12px 14px;
  border-radius: 18px;
}
.history-item strong { display: block; font-size: 0.92rem; margin-bottom: 2px; }
.history-item span { display: block; font-size: 0.8rem; color: rgba(220, 226, 234, 0.76); }
.history-empty { color: rgba(220,226,234,0.76); text-align: center; padding: 20px 0; }

.result-modal {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(0, 6, 16, 0.38);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  z-index: 200;
}
.result-modal-card {
  position: relative;
  width: min(92vw, 860px);
  padding: 18px 18px 16px;
  border-radius: 28px;
  background: rgba(2, 12, 34, 0.62);
  border: 1px solid rgba(96, 166, 255, 0.16);
  box-shadow: 0 24px 50px rgba(0,0,0,0.34);
}
.result-modal-x {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 1px solid rgba(96, 166, 255, 0.16);
  background: rgba(3, 18, 52, 0.22);
  color: #fff;
  font-size: 1.6rem;
}
.result-preview-canvas {
  width: 100%;
  height: auto;
  display: block;
  border-radius: 20px;
  background: rgba(0, 0, 0, 0.08);
}
.result-modal-actions {
  display: flex;
  justify-content: center;
  gap: 12px;
  margin-top: 14px;
  flex-wrap: wrap;
}
.result-modal-actions .action-btn {
  min-width: 126px;
  height: 44px;
  font-weight: 800;
}

html[data-screen-mode="tablet"] {
  --gauge-width: 290px;
  --gauge-height: 182px;
  --start-size: 104px;
}
html[data-screen-mode="tablet"] .page-frame {
  width: calc(100vw - 4px);
  height: calc(100dvh - 4px);
  margin: 2px auto;
  border-radius: 24px;
}
html[data-screen-mode="tablet"] .workspace-grid {
  grid-template-columns: 1fr;
}
html[data-screen-mode="tablet"] .ads-sidebar { display: none; }
html[data-screen-mode="tablet"] .speed-row { width: min(760px, 100%); margin-top: 162px; }
html[data-screen-mode="tablet"] .center-start-stack { top: 88px; }
html[data-screen-mode="tablet"] .server-menu { min-width: 250px; }

html[data-screen-mode="mobile"] {
  --gauge-width: calc((100vw - 58px) / 2);
  --gauge-height: calc((100vw - 58px) / 2 * 0.62);
  --start-size: 86px;
  --page-gap-bottom: 102px;
}
html[data-screen-mode="mobile"] body { overflow: hidden; }
html[data-screen-mode="mobile"] .page-frame {
  width: 100vw;
  height: 100dvh;
  margin: 0;
  border-radius: 0;
}
html[data-screen-mode="mobile"] .topbar {
  min-height: 64px;
  padding: 10px 12px 0;
}
html[data-screen-mode="mobile"] .logo-badge { width: 48px; height: 48px; border-radius: 12px; }
html[data-screen-mode="mobile"] .brand-wrap { gap: 10px; }
html[data-screen-mode="mobile"] .brand-text { font-size: 1rem; }
html[data-screen-mode="mobile"] .top-btn {
  min-width: 92px;
  height: 42px;
  padding: 0 16px;
  font-size: 0.82rem;
}
html[data-screen-mode="mobile"] .top-actions { gap: 8px; }
html[data-screen-mode="mobile"] .main-stage { padding: 2px 10px var(--page-gap-bottom); }
html[data-screen-mode="mobile"] .latency-grid {
  grid-template-columns: repeat(3, minmax(74px, 1fr));
  gap: 12px;
}
html[data-screen-mode="mobile"] .latency-title { font-size: 0.68rem; }
html[data-screen-mode="mobile"] .latency-item-label { font-size: 0.64rem; }
html[data-screen-mode="mobile"] .latency-item-value { font-size: 0.9rem; }
html[data-screen-mode="mobile"] .icon-globe-btn { width: 44px; height: 44px; font-size: 1.1rem; }
html[data-screen-mode="mobile"] .inline-caption { font-size: 0.74rem; }
html[data-screen-mode="mobile"] .server-link-btn { font-size: 0.88rem; }
html[data-screen-mode="mobile"] .server-menu {
  min-width: min(78vw, 290px);
  left: 50%;
  transform: translateX(-50%);
}
html[data-screen-mode="mobile"] .workspace-grid { grid-template-columns: 1fr; gap: 0; }
html[data-screen-mode="mobile"] .ads-sidebar { display: none; }
html[data-screen-mode="mobile"] .content-stage { padding-top: 2px; }
html[data-screen-mode="mobile"] .center-start-stack { top: 74px; gap: 8px; }
html[data-screen-mode="mobile"] .duration-caption { font-size: 0.74rem; }
html[data-screen-mode="mobile"] .duration-line { gap: 8px; }
html[data-screen-mode="mobile"] .duration-line input { width: 58px; height: 34px; font-size: 0.92rem; }
html[data-screen-mode="mobile"] .speed-row {
  width: 100%;
  gap: 8px;
  margin-top: 142px;
}
html[data-screen-mode="mobile"] .gauge-card { width: 100%; }
html[data-screen-mode="mobile"] .metric-label { font-size: 0.68rem; letter-spacing: 0.16em; }
html[data-screen-mode="mobile"] .gauge-live-readout strong { font-size: 1.28rem; }
html[data-screen-mode="mobile"] .gauge-live-readout span { font-size: 0.64rem; }
html[data-screen-mode="mobile"] .info-stage {
  margin-top: 6px;
  margin-bottom: 86px;
}
html[data-screen-mode="mobile"] .earth-icon { width: 30px; height: 30px; font-size: 0.9rem; }
html[data-screen-mode="mobile"] .isp-line { font-size: 0.86rem; }
html[data-screen-mode="mobile"] .ip-line,
html[data-screen-mode="mobile"] .location-line { font-size: 0.76rem; }
html[data-screen-mode="mobile"] .sticky-action-stack {
  width: calc(100% - 20px);
  bottom: 8px;
}
html[data-screen-mode="mobile"] .sticky-top-row { gap: 10px; width: 100%; justify-content: center; }
html[data-screen-mode="mobile"] .center-btn { min-width: 112px; height: 38px; font-size: 0.88rem; }
html[data-screen-mode="mobile"] .history-main-btn { min-width: 132px; }
html[data-screen-mode="mobile"] .history-dropdown { width: calc(100vw - 24px); }
html[data-screen-mode="mobile"] .result-modal-card { width: min(96vw, 620px); padding: 14px 14px 12px; }
html[data-screen-mode="mobile"] .result-modal-actions .action-btn { min-width: 104px; height: 42px; }
html[data-screen-mode="mobile"] .traffic-overlay { inset: 112px 4% 132px; }

@media (max-height: 760px) {
  .ads-card-inner { min-height: 520px; height: min(70vh, 620px); }
  .speed-row { margin-top: 160px; }
  .info-stage { margin-bottom: 74px; }
}
