/* Sasonis Studios — SasoniSpeed Stylesheet */
:root {
  --bg: #000000;
  --ink: #f4f2ee;
  --mute: #8a8a90;
  --line: rgba(255, 255, 255, 0.09);
  --a1: #f4f2ee;
  --a2: #7aa7ff;
  --font: "Manrope", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  scroll-behavior: smooth;
  overflow-x: hidden;
  overflow-y: auto;
  min-height: 100%;
  -webkit-overflow-scrolling: touch;
}

.speedtest-body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: hidden;
  overflow-y: visible;
  background-image: radial-gradient(60% 50% at 50% 42%, rgba(122, 167, 255, 0.10), transparent 70%);
  -webkit-font-smoothing: antialiased;
  -webkit-overflow-scrolling: touch;
}

/* Header */
.speedtest-header {
  position: relative;
  z-index: 20;
  padding: 1.1rem 2rem;
  border-bottom: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(16px);
}

.speedtest-header .header-inner {
  max-width: 1080px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.speedtest-header .brand-link {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  text-decoration: none;
  color: inherit;
}

.speedtest-header .brand-icon-box {
  width: 38px;
  height: 38px;
  background: rgba(122, 167, 255, 0.08);
  border: 1px solid rgba(122, 167, 255, 0.25);
  border-radius: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 0 15px rgba(122, 167, 255, 0.15);
}

.speedtest-header .brand-title {
  display: flex;
  flex-direction: column;
}

.speedtest-header .brand-main {
  font-size: 0.95rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: #ffffff;
}

.speedtest-header .brand-sub {
  font-size: 0.7rem;
  color: var(--mute);
  letter-spacing: 0.04em;
}

.speedtest-nav {
  display: flex;
  align-items: center;
  gap: 1.5rem;
}

.speedtest-nav .nav-item {
  color: var(--mute);
  text-decoration: none;
  font-size: 0.88rem;
  font-weight: 500;
  transition: color 0.2s ease;
}

.speedtest-nav .nav-item:hover,
.speedtest-nav .nav-item.active {
  color: var(--ink);
}

.header-right .back-pill-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  color: var(--ink);
  text-decoration: none;
  font-size: 0.8rem;
  font-weight: 600;
  transition: background 0.2s, border-color 0.2s;
}

.header-right .back-pill-btn:hover {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.3);
}

/* Main Container */
.speed-main {
  flex: 1;
  width: 100%;
  max-width: 560px;
  margin: 0 auto;
  padding: 48px 20px 40px;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

.speed-title {
  font-weight: 200;
  font-size: clamp(28px, 5.5vw, 36px);
  letter-spacing: 0.02em;
  color: var(--ink);
}

.sub {
  margin-top: 8px;
  color: var(--mute);
  font-size: 14px;
  min-height: 20px;
}

/* SVG Gauge */
.gauge {
  position: relative;
  width: min(340px, 86vw);
  aspect-ratio: 1;
  margin: 36px 0 28px;
}

.gauge svg {
  width: 100%;
  height: 100%;
  display: block;
}

.track {
  stroke: rgba(255, 255, 255, 0.08);
}

#arc {
  stroke: url(#g);
  filter: drop-shadow(0 0 10px rgba(122, 167, 255, 0.55));
  transition: opacity 0.3s;
}

.readout {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
}

#val {
  font-weight: 200;
  font-size: clamp(56px, 16vw, 84px);
  line-height: 1;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
  color: var(--ink);
}

.unit {
  color: var(--mute);
  font-size: 14px;
}

#phase {
  margin-top: 10px;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
  opacity: 0.85;
  min-height: 18px;
}

/* Action Button */
.speed-btn {
  appearance: none;
  border: 1px solid rgba(255, 255, 255, 0.22);
  background: transparent;
  color: var(--ink);
  font: 600 15px var(--font);
  letter-spacing: 0.04em;
  padding: 15px 44px;
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.25s, color 0.25s, border-color 0.25s, transform 0.15s;
}

.speed-btn:hover:not(:disabled) {
  background: var(--ink);
  color: #000;
  border-color: var(--ink);
}

.speed-btn:active:not(:disabled) {
  transform: scale(0.97);
}

.speed-btn:disabled {
  opacity: 0.4;
  cursor: default;
}

.speed-btn:focus-visible {
  outline: 2px solid var(--a2);
  outline-offset: 4px;
}

/* Stats 4-column Grid */
.stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  width: 100%;
  margin-top: 48px;
  border-top: 1px solid var(--line);
}

.stat {
  padding: 22px 6px 0;
  border-left: 1px solid var(--line);
}

.stat:first-child {
  border-left: 0;
}

.stat b {
  display: block;
  font-weight: 200;
  font-size: clamp(22px, 5.5vw, 30px);
  font-variant-numeric: tabular-nums;
  color: var(--ink);
}

.stat span {
  display: block;
  margin-top: 4px;
  font-size: 12px;
  color: var(--mute);
}

.stat small {
  color: var(--mute);
  font-size: 11px;
  margin-left: 2px;
}

/* Fallback Note */
.note {
  margin-top: 28px;
  font-size: 12px;
  color: var(--mute);
  max-width: 380px;
}

.note[hidden] {
  display: none;
}

/* Minimal Post-Test Action Toolbar */
.post-test-actions {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-top: 28px;
}

.action-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 18px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.04);
  color: var(--mute);
  font: 500 13px var(--font);
  cursor: pointer;
  transition: all 0.2s ease;
}

.action-btn:hover {
  background: rgba(255, 255, 255, 0.08);
  color: var(--ink);
  border-color: rgba(255, 255, 255, 0.2);
}

/* Collapsible History Drawer */
.history-drawer {
  width: 100%;
  margin-top: 24px;
  padding: 16px 20px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--line);
  border-radius: 14px;
  text-align: left;
}

.history-drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
  margin-bottom: 12px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 8px;
}

.close-history-btn {
  background: none;
  border: none;
  color: var(--mute);
  font-size: 18px;
  cursor: pointer;
  line-height: 1;
}

.close-history-btn:hover {
  color: var(--ink);
}

.history-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
  font-size: 12px;
  color: var(--mute);
}

.history-item:last-child {
  border-bottom: none;
}

.history-item-metrics {
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

.history-empty {
  font-size: 12px;
  color: var(--mute);
  padding: 10px 0;
  text-align: center;
}

/* Footer */
.speedtest-footer {
  margin-top: auto;
  padding: 24px 20px;
  border-top: 1px solid var(--line);
  text-align: center;
  font-size: 12px;
  color: var(--mute);
}

/* Toast */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.speed-toast {
  padding: 10px 20px;
  border-radius: 8px;
  background: #111;
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.15);
  font-size: 13px;
  opacity: 0;
  transform: translateY(10px);
  transition: opacity 0.25s, transform 0.25s;
  pointer-events: auto;
}

.speed-toast.show {
  opacity: 1;
  transform: translateY(0);
}

/* Responsive adjustments */
@media (max-width: 480px) {
  .speedtest-header {
    padding: 1rem 1.25rem;
  }
  .speedtest-nav {
    display: none;
  }
  .stats {
    grid-template-columns: repeat(2, 1fr);
  }
  .stat:nth-child(3) {
    border-left: 0;
  }
  .stat:nth-child(n+3) {
    margin-top: 14px;
    border-top: 1px solid var(--line);
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    transition: none !important;
  }
}
