:root {
  color-scheme: light;
  --canvas: #f1f0ed;
  --foundation: #e7e4df;
  --surface-raised: #fcfbf8;
  --text-primary: #292725;
  --text-secondary: #625e59;
  --text-tertiary: #817b75;
  --structure-soft: rgba(82, 76, 70, 0.18);
  --structure-control: rgba(82, 76, 70, 0.32);
  --signal: #d97706;
  --ds-action-primary: #a64b00;
  --ds-action-primary-hover: #8f3f00;
  --ds-action-primary-active: #763300;
  --ds-on-action-primary: #ffffff;
  --danger: #b95049;
  --glass-object: rgba(252, 251, 248, 0.9);
  --font-sans: "IBM Plex Sans Variable", "Noto Sans SC Variable", "PingFang SC", "Microsoft YaHei UI", "Microsoft YaHei", system-ui, sans-serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

html {
  background: var(--canvas);
}

body {
  margin: 0;
  color: var(--text-primary);
  background-color: var(--canvas);
  background-image:
    radial-gradient(circle at 18% 8%, rgba(255, 255, 255, 0.88), transparent 34%),
    radial-gradient(circle at 84% 92%, rgba(217, 119, 6, 0.08), transparent 30%);
  font-family: var(--font-sans);
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

button,
input,
textarea,
select {
  font: inherit;
}

::selection {
  color: var(--text-primary);
  background: rgba(217, 119, 6, 0.24);
}

.stage {
  display: grid;
  min-height: 100dvh;
  place-items: center;
  padding: 32px;
}

.connection-shell {
  width: min(100%, 520px);
  padding: 32px;
  overflow: hidden;
  border: 1px solid rgba(82, 76, 70, 0.22);
  border-radius: 16px;
  background-color: var(--surface-raised);
  background-image:
    linear-gradient(145deg, rgba(255, 255, 255, 0.7), transparent 42%),
    linear-gradient(180deg, var(--glass-object), rgba(247, 246, 243, 0.9));
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.82),
    inset 0 -1px 0 rgba(82, 76, 70, 0.08),
    0 24px 64px -36px rgba(82, 76, 70, 0.58);
  -webkit-backdrop-filter: blur(24px) saturate(138%);
  backdrop-filter: blur(24px) saturate(138%);
}

.brand {
  display: flex;
  justify-content: center;
  margin-bottom: 36px;
}

.brand-logo {
  display: block;
  width: min(100%, 230px);
  height: auto;
  filter: brightness(0);
  opacity: 0.84;
}

.state-panel {
  text-align: center;
}

.hidden {
  display: none !important;
}

.signal-path {
  display: flex;
  width: min(100%, 360px);
  align-items: center;
  margin: 0 auto 28px;
}

.signal-node {
  position: relative;
  z-index: 1;
  flex: 0 0 auto;
  width: 12px;
  height: 12px;
  border: 2px solid var(--structure-control);
  border-radius: 50%;
  background: var(--surface-raised);
  transition:
    border-color 180ms ease,
    background-color 180ms ease,
    transform 180ms ease;
}

.signal-node-origin {
  border-color: var(--signal);
  background: var(--signal);
}

.signal-track {
  position: relative;
  height: 3px;
  flex: 1 1 auto;
  overflow: hidden;
  background: var(--structure-soft);
}

.signal-pulse {
  position: absolute;
  inset: 0 auto 0 0;
  width: 34%;
  background: linear-gradient(90deg, transparent, var(--signal) 42%, var(--signal));
  transform: translateX(-100%);
  animation: route-scan 1.6s cubic-bezier(0.16, 1, 0.3, 1) infinite;
}

.connection-shell[data-phase="probe"] .signal-pulse {
  width: 46%;
  animation-duration: 1.15s;
}

.connection-shell[data-phase="redirect"] .signal-pulse {
  width: 100%;
  animation: none;
  transform: translateX(0);
  background: var(--signal);
}

.connection-shell[data-phase="redirect"] .signal-node-target {
  border-color: var(--signal);
  background: var(--signal);
  transform: scale(1.08);
}

.state-copy h1,
.fallback h1 {
  margin: 0;
  color: var(--text-primary);
  font-size: 24px;
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1.25;
  text-wrap: balance;
}

.status {
  min-height: 26px;
  margin: 10px auto 0;
  color: var(--text-secondary);
  font-size: 16px;
  line-height: 1.6;
}

.route-phases {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin: 32px 0 0;
  padding: 0;
  list-style: none;
}

.route-phases li {
  min-width: 0;
  padding-top: 10px;
  border-top: 2px solid var(--structure-soft);
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 500;
  line-height: 1.4;
  transition:
    border-color 180ms ease,
    color 180ms ease;
}

.route-phases li.is-active {
  border-color: var(--signal);
  color: var(--text-primary);
}

.route-phases li.is-complete {
  border-color: rgba(217, 119, 6, 0.48);
  color: var(--text-secondary);
}

.state-note,
.support-hint {
  margin: 24px 0 0;
  color: var(--text-secondary);
  font-size: 12px;
  line-height: 1.5;
}

.fallback {
  padding-top: 4px;
}

.fallback::before {
  display: block;
  width: 48px;
  height: 3px;
  margin: 0 auto 24px;
  border-radius: 4px;
  background: var(--danger);
  content: "";
}

.fallback p:not(.support-hint) {
  max-width: 34em;
  margin: 12px auto 0;
  color: var(--text-secondary);
  line-height: 1.65;
}

.fallback-actions {
  display: flex;
  justify-content: center;
  margin-top: 28px;
}

.retry-button {
  min-width: 128px;
  min-height: 44px;
  padding: 10px 20px;
  border: 1px solid var(--ds-action-primary);
  border-radius: 16px;
  color: var(--ds-on-action-primary);
  background-color: var(--ds-action-primary);
  background-image: linear-gradient(180deg, rgba(255, 255, 255, 0.24), transparent 52%);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.42),
    0 10px 24px -18px rgba(170, 86, 2, 0.9);
  cursor: pointer;
  font-weight: 600;
  transition:
    background-color 120ms ease,
    border-color 120ms ease,
    transform 120ms ease;
}

.retry-button:hover {
  border-color: var(--ds-action-primary-hover);
  background-color: var(--ds-action-primary-hover);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.54),
    0 12px 26px -18px rgba(170, 86, 2, 0.94);
}

.retry-button:active {
  border-color: var(--ds-action-primary-active);
  background-color: var(--ds-action-primary-active);
  transform: translateY(1px);
}

.retry-button:focus-visible {
  outline: 2px solid var(--signal);
  outline-offset: 3px;
}

.retry-button:disabled {
  color: var(--text-secondary);
  border-color: var(--structure-soft);
  background: var(--foundation);
  box-shadow: none;
  cursor: not-allowed;
}

@keyframes route-scan {
  from {
    transform: translateX(-100%);
  }

  to {
    transform: translateX(300%);
  }
}

@supports not ((-webkit-backdrop-filter: blur(1px)) or (backdrop-filter: blur(1px))) {
  .connection-shell {
    background: var(--surface-raised);
  }
}

@media (max-width: 640px) {
  .stage {
    align-items: center;
    padding: 16px;
  }

  .connection-shell {
    padding: 28px 20px;
    background-color: rgba(252, 251, 248, 0.96);
    -webkit-backdrop-filter: blur(12px) saturate(120%);
    backdrop-filter: blur(12px) saturate(120%);
  }

  .brand {
    margin-bottom: 32px;
  }

  .brand-logo {
    width: min(100%, 208px);
  }

  .signal-path {
    margin-bottom: 24px;
  }

  .state-copy h1,
  .fallback h1 {
    font-size: 22px;
  }

  .route-phases {
    gap: 8px;
    margin-top: 28px;
  }
}

@media (max-width: 340px) {
  .stage {
    padding: 12px;
  }

  .connection-shell {
    padding: 24px 16px;
  }

  .route-phases {
    gap: 6px;
  }

  .route-phases li {
    font-size: 12px;
  }
}

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

  .signal-pulse {
    width: 42%;
    transform: translateX(72%);
  }

  .connection-shell[data-phase="redirect"] .signal-pulse {
    width: 100%;
    transform: translateX(0);
  }
}

@media (prefers-reduced-transparency: reduce) {
  .connection-shell {
    background: var(--surface-raised);
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
  }
}
