:root {
  color-scheme: light dark;
  --canvas: #fafafb;
  --surface: #ffffff;
  --recessed: #f1f1f3;
  --ink: #202126;
  --muted: #71737b;
  --faint: #a3a5ad;
  --hairline: #eaeaed;
  --exercise: #7ea6ff;
  --supplement: #62c489;
  --meal: #f2a23a;
  --focus: rgba(126, 166, 255, 0.55);
  --card-shadow: 0 12px 26px rgba(0, 0, 0, 0.055);
  --font: system-ui, -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

html {
  min-width: 320px;
  min-height: 100%;
  background: var(--canvas);
}

body {
  min-height: 100vh;
  min-height: 100svh;
  margin: 0;
  background: var(--canvas);
  color: var(--ink);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

a, button { -webkit-tap-highlight-color: transparent; }

.page-shell {
  display: grid;
  min-height: 100vh;
  min-height: 100svh;
  place-items: center;
  padding: clamp(20px, 5vw, 64px);
}

.connefi-surface {
  width: min(100%, 920px);
  overflow: hidden;
  border: 1px solid var(--hairline);
  border-radius: 32px;
  background: var(--surface);
  box-shadow: var(--card-shadow);
}

.handoff-surface {
  display: grid;
  grid-template-columns: minmax(0, 1.08fr) minmax(340px, 0.92fr);
}

.brand-panel, .action-panel, .not-found-panel {
  padding: clamp(28px, 5vw, 56px);
}

.brand-panel {
  display: flex;
  min-height: 570px;
  flex-direction: column;
}

.brand-lockup {
  display: inline-flex;
  min-height: 44px;
  align-items: center;
  align-self: flex-start;
  gap: 11px;
  color: var(--ink);
  text-decoration: none;
}

.brand-mark {
  display: block;
  width: 34px;
  height: 34px;
  object-fit: contain;
}

.brand-name {
  font-size: 15px;
  font-weight: 850;
  letter-spacing: 0.08em;
  line-height: 1;
}

.brand-copy {
  display: flex;
  flex: 1;
  flex-direction: column;
  justify-content: center;
  padding: 54px 0 40px;
}

.status-line {
  display: inline-flex;
  min-height: 34px;
  align-items: center;
  align-self: flex-start;
  gap: 9px;
  margin: 0 0 22px;
  padding: 0 12px;
  border-radius: 999px;
  background: var(--recessed);
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
  line-height: 1;
}

.signal {
  display: inline-flex;
  align-items: center;
  gap: 3px;
}

.signal i {
  display: block;
  flex: 0 0 auto;
  border-radius: 999px;
}

.signal i {
  width: 5px;
  height: 5px;
  animation: signal-pulse 1.4s ease-in-out infinite;
}

.signal i:nth-child(1) { background: var(--exercise); }
.signal i:nth-child(2) { background: var(--supplement); }
.signal i:nth-child(2) { animation-delay: 140ms; }
.signal i:nth-child(3) { background: var(--meal); }
.signal i:nth-child(3) { animation-delay: 280ms; }

@keyframes signal-pulse {
  0%, 100% { opacity: 0.38; transform: scale(0.82); }
  45% { opacity: 1; transform: scale(1); }
}

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

h1 {
  max-width: 470px;
  margin-bottom: 20px;
  font-size: clamp(38px, 5vw, 58px);
  font-weight: 760;
  letter-spacing: -0.035em;
  line-height: 0.98;
  text-wrap: balance;
}

.lead {
  max-width: 480px;
  margin-bottom: 30px;
  color: var(--muted);
  font-size: clamp(16px, 2vw, 18px);
  font-weight: 470;
  line-height: 1.48;
}

.connected-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.connected-item {
  display: inline-flex;
  min-height: 36px;
  align-items: center;
  gap: 7px;
  padding: 0 12px;
  border: 1px solid var(--hairline);
  border-radius: 999px;
  background: color-mix(in srgb, var(--surface) 76%, transparent);
  color: var(--ink);
  font-size: 13px;
  font-weight: 780;
  line-height: 1;
}

.connected-icon {
  width: 15px;
  height: 15px;
  flex: 0 0 auto;
}

.connected-item--exercise .connected-icon {
  color: #438bff;
  filter: drop-shadow(0 0 5px color-mix(in srgb, #438bff 42%, transparent));
}

.connected-item--supplement .connected-icon {
  color: #55be31;
  filter: drop-shadow(0 0 5px color-mix(in srgb, #55be31 38%, transparent));
}

.connected-item--meal .connected-icon {
  color: #ffa21a;
  filter: drop-shadow(0 0 5px color-mix(in srgb, #ffa21a 38%, transparent));
}

.action-panel {
  display: flex;
  flex-direction: column;
  justify-content: center;
  margin: 12px;
  border-radius: 24px;
  background: var(--recessed);
}

.action-title {
  margin-bottom: 10px;
  font-size: 23px;
  font-weight: 780;
  letter-spacing: -0.02em;
  line-height: 1.06;
}

.action-copy {
  margin-bottom: 24px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 500;
  line-height: 1.42;
}

.button-stack { display: grid; gap: 10px; }

.btn {
  display: flex;
  min-height: 52px;
  align-items: center;
  justify-content: center;
  padding: 0 20px;
  border: 1px solid transparent;
  border-radius: 999px;
  font-family: var(--font);
  font-size: 15px;
  font-weight: 760;
  line-height: 1;
  text-align: center;
  text-decoration: none;
  transition: transform 180ms ease-out, opacity 160ms ease-out, background-color 180ms ease-out, border-color 180ms ease-out;
}

.btn:hover { transform: translateY(-1px); }
.btn:active { transform: scale(0.985); }

.btn:focus-visible, .brand-lockup:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 3px;
}

.btn-primary { background: var(--ink); color: var(--surface); }
.btn-secondary { border-color: var(--hairline); background: var(--surface); color: var(--ink); }
.btn[aria-busy="true"] { opacity: 0.68; pointer-events: none; }

.install-label {
  margin: 24px 0 10px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 680;
  line-height: 1.35;
  text-align: center;
}

.store-links {
  display: grid;
  width: 100%;
  justify-items: center;
  gap: 10px;
}

.store-badge-link {
  display: inline-flex;
  width: 164px;
  min-height: 60px;
  align-items: center;
  justify-content: center;
  overflow: visible;
  border-radius: 16px;
  background: var(--surface);
  box-shadow: var(--card-shadow);
  transition: transform 180ms ease-out, opacity 160ms ease-out;
}

.store-badge-link:hover {
  transform: translateY(-1px);
  opacity: 0.92;
}
.store-badge-link:active { transform: scale(0.985); }

.store-badge-link:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 3px;
}

.store-badge {
  display: block;
  width: 144px;
  height: auto;
  object-fit: contain;
}

.store-badge-white { display: none; }

.handoff-hint {
  display: none;
  margin-top: 16px;
  padding: 14px 15px;
  border: 1px solid color-mix(in srgb, var(--exercise) 30%, var(--hairline));
  border-radius: 16px;
  background: color-mix(in srgb, var(--exercise) 8%, var(--surface));
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
  line-height: 1.42;
}

.handoff-hint.is-visible { display: block; }

.handoff-hint strong {
  display: block;
  margin-bottom: 3px;
  color: var(--ink);
  font-size: 13px;
  font-weight: 780;
}

.fine-print {
  margin: 20px 0 0;
  color: var(--faint);
  font-size: 11px;
  font-weight: 550;
  line-height: 1.45;
  text-align: center;
}

body[data-platform="ios"] .store-android,
body[data-platform="android"] .store-ios { display: none; }

body[data-platform="desktop"] .open-app,
body[data-platform="desktop"] .install-label { display: none; }

.not-found-surface { width: min(100%, 720px); }
.not-found-panel { min-height: 520px; }

.not-found-copy {
  display: flex;
  min-height: 390px;
  align-items: flex-start;
  justify-content: center;
  flex-direction: column;
  padding-top: 54px;
}

.not-found-code {
  margin-bottom: 18px;
  color: var(--faint);
  font-size: 14px;
  font-weight: 820;
  letter-spacing: 0.08em;
  line-height: 1;
}

.not-found-copy h1 { margin-bottom: 16px; }
.not-found-copy .lead { max-width: 520px; margin-bottom: 28px; }
.not-found-copy .btn { align-self: flex-start; min-width: 180px; }

@media (max-width: 720px) {
  html, body, .page-shell { background: var(--surface); }
  .page-shell { display: block; padding: 0; }
  body, .page-shell, .connefi-surface {
    min-height: 100vh;
    min-height: 100svh;
    min-height: 100dvh;
  }
  .connefi-surface { border: 0; border-radius: 0; box-shadow: none; }
  .handoff-surface { display: flex; flex-direction: column; }
  .brand-panel {
    min-height: auto;
    padding: 24px max(20px, env(safe-area-inset-right)) 16px
      max(20px, env(safe-area-inset-left));
  }
  .brand-copy { display: block; padding: 36px 0 16px; }
  h1 { margin-bottom: 16px; font-size: clamp(32px, 9.5vw, 40px); }
  .lead { margin-bottom: 20px; font-size: 15px; line-height: 1.42; }
  .action-panel {
    flex: none;
    justify-content: flex-start;
    margin: 0 max(10px, env(safe-area-inset-right)) 10px
      max(10px, env(safe-area-inset-left));
    padding: 18px 18px max(18px, env(safe-area-inset-bottom));
    border-radius: 24px;
  }
  .button-stack { justify-items: center; }
  .open-app {
    width: 144px;
    min-height: 49px;
    padding: 0 12px;
  }
  .not-found-panel { min-height: 100vh; min-height: 100svh; padding: 28px 22px calc(28px + env(safe-area-inset-bottom)); }
  .not-found-copy { min-height: calc(100svh - 100px); padding-top: 42px; }
}

@media (max-width: 420px) {
  .brand-copy { padding-top: 32px; }
  .connected-list { gap: 6px; }
  .connected-item { min-height: 34px; padding: 0 10px; font-size: 12px; }
}

@media (orientation: landscape) and (min-width: 560px) and (max-height: 500px) {
  .page-shell {
    display: grid;
    padding: max(12px, env(safe-area-inset-top))
      max(12px, env(safe-area-inset-right))
      max(12px, env(safe-area-inset-bottom))
      max(12px, env(safe-area-inset-left));
  }

  .connefi-surface {
    min-height: auto;
    border: 1px solid var(--hairline);
    border-radius: 24px;
    box-shadow: var(--card-shadow);
  }

  .handoff-surface {
    display: grid;
    grid-template-columns: minmax(0, 1.06fr) minmax(260px, 0.94fr);
  }

  .brand-panel { min-height: 330px; padding: 20px 22px; }
  .brand-copy { display: flex; padding: 16px 0 0; }
  .status-line { min-height: 30px; margin-bottom: 14px; }
  h1 { max-width: 340px; margin-bottom: 12px; font-size: clamp(30px, 5vw, 36px); }
  .lead { max-width: 360px; margin-bottom: 16px; font-size: 14px; line-height: 1.38; }
  .connected-list { gap: 6px; }
  .connected-item { min-height: 32px; padding: 0 10px; font-size: 12px; }
  .connected-icon { width: 14px; height: 14px; }

  .action-panel {
    justify-content: center;
    margin: 8px;
    padding: 18px;
    border-radius: 20px;
  }

  .action-title { margin-bottom: 8px; font-size: 20px; }
  .action-copy { margin-bottom: 16px; font-size: 13px; }
  .fine-print { margin-top: 14px; }
}

@media (prefers-color-scheme: dark) {
  :root {
    --canvas: #080a0e;
    --surface: #17191e;
    --recessed: #111318;
    --ink: #f7f7f8;
    --muted: #b5b7be;
    --faint: #85878f;
    --hairline: rgba(255, 255, 255, 0.09);
    --focus: rgba(126, 166, 255, 0.7);
    --card-shadow: 0 12px 26px rgba(0, 0, 0, 0.22);
  }
  .btn-primary { background: var(--ink); color: #202126; }
  body[data-platform="ios"] .store-badge-black { display: none; }
  body[data-platform="ios"] .store-badge-white { display: block; }
}

@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;
  }
}
