/* ==========================================================================
   Design tokens
   Palette is sampled from the HealthCoach app icon and in-app UI so the card
   and the product read as one brand.
   ========================================================================== */

:root {
  /* Brand */
  --brand-purple: #5b2fd9;
  --brand-purple-strong: #4a24b8;
  --brand-purple-light: #8b5cf6;
  --brand-magenta: #e0218a;
  --brand-amber: #ff9f0a;

  /* Surfaces. Light theme is the default definition. */
  --surface-page: #f7f6fb;
  --surface-card: #ffffff;
  --surface-sunken: #eeecf5;
  --border-subtle: #ddd9e8;

  /* Text. All pairings below meet WCAG AA on their stated surface. */
  --text-primary: #1a1626;
  --text-secondary: #55506b;
  --text-on-brand: #ffffff;

  /* Focus ring: must stay visible against both surfaces. */
  --focus-ring: #1a1626;

  /* Type scale */
  --font-sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --text-xs: 0.8125rem;
  --text-sm: 0.9375rem;
  --text-base: 1rem;
  --text-lg: 1.125rem;
  --text-xl: 1.375rem;
  --text-2xl: 1.75rem;

  /* Spacing */
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.5rem;
  --space-6: 2rem;
  --space-7: 3rem;

  /* Shape */
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --radius-pill: 999px;

  --shadow-card: 0 1px 2px rgb(26 22 38 / 6%), 0 8px 24px rgb(26 22 38 / 8%);

  /* Layout */
  --content-max: 34rem;

  /* Spec §2.3: minimum 44x44 CSS-pixel touch targets. */
  --touch-target-min: 44px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --surface-page: #100d18;
    --surface-card: #1a1626;
    --surface-sunken: #241f33;
    --border-subtle: #342d47;

    --text-primary: #f4f2f9;
    --text-secondary: #b3adc7;

    --focus-ring: #ffffff;

    /* Lift the brand purple in dark mode; the light-theme value does not carry
       enough contrast against a dark surface for text or icon use. */
    --brand-purple: #8b5cf6;
    --brand-purple-strong: #a78bfa;

    --shadow-card: 0 1px 2px rgb(0 0 0 / 40%), 0 8px 24px rgb(0 0 0 / 30%);
  }
}

:root[data-theme="dark"] {
  --surface-page: #100d18;
  --surface-card: #1a1626;
  --surface-sunken: #241f33;
  --border-subtle: #342d47;

  --text-primary: #f4f2f9;
  --text-secondary: #b3adc7;

  --focus-ring: #ffffff;

  --brand-purple: #8b5cf6;
  --brand-purple-strong: #a78bfa;

  --shadow-card: 0 1px 2px rgb(0 0 0 / 40%), 0 8px 24px rgb(0 0 0 / 30%);
}

/* ==========================================================================
   Base
   ========================================================================== */

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

html {
  /* Never disable user scaling. Spec §2.3 requires text scaling to 200%. */
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background-color: var(--surface-page);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;

  /* Respect display cutouts on the S26 Ultra and notched iPhones. */
  padding:
    env(safe-area-inset-top)
    env(safe-area-inset-right)
    env(safe-area-inset-bottom)
    env(safe-area-inset-left);
}

h1, h2, h3 {
  line-height: 1.25;
  margin: 0;
  text-wrap: balance;
}

p {
  margin: 0;
  text-wrap: pretty;
}

img {
  max-width: 100%;
  height: auto;
  display: block;
}

a {
  color: var(--brand-purple);
}

/* A single visible focus treatment for every interactive element. Using
   :focus-visible keeps it off mouse clicks but guarantees it for keyboard. */
:focus-visible {
  outline: 3px solid var(--focus-ring);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

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

/* ==========================================================================
   Utilities
   ========================================================================== */

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: absolute;
  top: var(--space-2);
  left: var(--space-2);
  z-index: 100;
  padding: var(--space-2) var(--space-4);
  background: var(--surface-card);
  color: var(--text-primary);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-card);
  transform: translateY(-150%);
}

.skip-link:focus {
  transform: translateY(0);
}

/* ==========================================================================
   Layout
   ========================================================================== */

.card-shell {
  max-width: var(--content-max);
  margin-inline: auto;
  padding: var(--space-5) var(--space-4) var(--space-7);
}

/* ==========================================================================
   Sections
   ========================================================================== */

.section__heading {
  font-size: var(--text-xl);
  font-weight: 650;
  margin-block: var(--space-6) var(--space-3);
  letter-spacing: -0.01em;
}

/* ==========================================================================
   Hero
   ========================================================================== */

.hero {
  text-align: center;
  padding-block-end: var(--space-4);
}

.hero__photo {
  inline-size: 8.5rem;
  block-size: 8.5rem;
  margin-inline: auto;
  border-radius: 50%;
  object-fit: cover;
  border: 3px solid var(--surface-card);
  box-shadow: var(--shadow-card);
  background-color: var(--surface-sunken);
}

.hero__name {
  font-size: var(--text-2xl);
  font-weight: 700;
  letter-spacing: -0.02em;
  margin-block-start: var(--space-4);
}

.hero__title {
  color: var(--brand-purple);
  font-weight: 600;
  margin-block-start: var(--space-1);
}

.hero__summary {
  color: var(--text-secondary);
  margin-block-start: var(--space-3);
  max-inline-size: 30rem;
  margin-inline: auto;
}

/* ==========================================================================
   Store badges
   ========================================================================== */

.stores__row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3);
  align-items: center;
  justify-content: center;
}

.stores__badge {
  display: inline-flex;
  align-items: center;
  border-radius: var(--radius-sm);
  /* Badge art carries its own padding, so the tap area is enforced here. */
  min-block-size: var(--touch-target-min);
  opacity: 0.72;
  transition: opacity 150ms ease, transform 150ms ease;
}

.stores__badge img {
  block-size: 3rem;
  inline-size: auto;
}

/* The detected platform's badge is fully opaque; the other stays visible but
   recedes. Emphasis is never conveyed by colour alone. */
.stores__badge--primary {
  opacity: 1;
  transform: scale(1.06);
}

.stores__badge:hover,
.stores__badge:focus-visible {
  opacity: 1;
}

/* ==========================================================================
   Actions
   ========================================================================== */

/* Actions carry no heading of their own, so unlike every other section nothing
   else creates separation from whatever precedes them. */
.actions {
  margin-block-start: var(--space-5);
}

/* Inside a section that already opened with a heading, the heading's bottom
   margin is the separation; a second gap on top of it reads as a break. */
.contact .actions,
.hc .actions {
  margin-block-start: 0;
}

.actions__list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: var(--space-3);
}

.action {
  display: flex;
  align-items: center;
  justify-content: center;
  min-block-size: var(--touch-target-min);
  padding: var(--space-3) var(--space-4);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-pill);
  background: var(--surface-card);
  color: var(--text-primary);
  font: inherit;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  inline-size: 100%;
  transition: transform 150ms ease, box-shadow 150ms ease;
}

.action:hover {
  box-shadow: var(--shadow-card);
  transform: translateY(-1px);
}

.action--primary {
  background: var(--brand-purple);
  border-color: var(--brand-purple);
  color: var(--text-on-brand);
}

.action--secondary {
  background: var(--surface-sunken);
}

/* ==========================================================================
   HealthCoach
   ========================================================================== */

.hc__tagline {
  font-weight: 600;
  color: var(--brand-purple);
}

.hc__description {
  color: var(--text-secondary);
  margin-block-start: var(--space-2);
}

.hc__features {
  margin-block-start: var(--space-4);
  padding-inline-start: var(--space-5);
  display: grid;
  gap: var(--space-2);
  color: var(--text-secondary);
}

.hc__figure {
  margin: var(--space-5) 0 0;
}

.hc__figure img {
  inline-size: 100%;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
}

.hc__figure figcaption {
  margin-block-start: var(--space-2);
  font-size: var(--text-sm);
  color: var(--text-secondary);
  text-align: center;
}

/* ==========================================================================
   Share
   ========================================================================== */

.share {
  margin-block-start: var(--space-4);
}

.share__status {
  min-block-size: 1.5rem;   /* reserved so feedback does not shift layout (CLS) */
  margin-block-start: var(--space-2);
  font-size: var(--text-sm);
  color: var(--text-secondary);
  text-align: center;
}

/* The QR link sits directly in the section rather than in an actions list, so
   it needs its own separation from the share block above it. */
.contact > .action {
  margin-block-start: var(--space-3);
}

/* ==========================================================================
   Footer
   ========================================================================== */

.footer {
  margin-block-start: var(--space-7);
  padding-block-start: var(--space-5);
  border-block-start: 1px solid var(--border-subtle);
}

.project {
  margin-block-end: var(--space-4);
}

.project__name {
  font-size: var(--text-lg);
  font-weight: 650;
}

.project__description {
  color: var(--text-secondary);
  font-size: var(--text-sm);
  margin-block-start: var(--space-1);
}

.footer__legal {
  font-size: var(--text-xs);
  color: var(--text-secondary);
  text-align: center;
  margin-block-start: var(--space-2);
}

.footer__legal--muted {
  opacity: 0.8;
}

/* ==========================================================================
   Wider viewports
   ========================================================================== */

@media (min-width: 48rem) {
  .actions__list {
    grid-template-columns: repeat(2, 1fr);
  }

  .actions__list:has(> li:only-child) {
    grid-template-columns: 1fr;
  }
}

/* ==========================================================================
   Full-screen QR (spec §5.2)
   Forced light regardless of theme: scanners need dark modules on white, and an
   inverted code fails on a number of camera apps.
   ========================================================================== */

.qr-screen {
  position: fixed;
  inset: 0;
  z-index: 500;
  background: #ffffff;
  color: #1a1626;
  display: grid;
  place-items: center;
  padding: var(--space-5);
  overflow-y: auto;
}

.qr-screen__inner {
  text-align: center;
  display: grid;
  gap: var(--space-4);
  justify-items: center;
  max-inline-size: 26rem;
}

.qr-screen__heading {
  font-size: var(--text-xl);
  font-weight: 650;
  color: #1a1626;
}

.qr-screen__code {
  inline-size: min(78vw, 20rem);
  block-size: auto;
  aspect-ratio: 1;
  background: #ffffff;
}

.qr-screen__url {
  font-size: var(--text-sm);
  color: #55506b;
  word-break: break-all;
}

.qr-screen__hint {
  font-size: var(--text-xs);
  color: #55506b;
}

.qr-screen__close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-block-size: var(--touch-target-min);
  min-inline-size: 8rem;
  padding: var(--space-3) var(--space-5);
  border: 1px solid #ddd9e8;
  border-radius: var(--radius-pill);
  background: #f7f6fb;
  color: #1a1626;
  font: inherit;
  font-weight: 600;
  text-decoration: none;   /* it is an anchor, styled as a button */
  cursor: pointer;
}

.qr-screen__close:focus-visible {
  outline: 3px solid #1a1626;
  outline-offset: 2px;
}

/* ==========================================================================
   Store badge emphasis (FR-02)
   The platform is stamped on <html> by an inline script before paint, so the
   correct badge is emphasised on first render with no flash and no layout shift.
   Both badges always remain visible and tappable.
   ========================================================================== */

html[data-platform="android"] .stores__badge[data-platform="android"],
html[data-platform="ios"]     .stores__badge[data-platform="ios"] {
  opacity: 1;
  transform: scale(1.06);
  order: -1;   /* emphasised store comes first visually */
}

/* Desktop, or platform unknown: both badges equal. */
html[data-platform="desktop"] .stores__badge {
  opacity: 1;
  transform: none;
}

.qr-body {
  margin: 0;
}

/* Shown only on Android, and only when Save Contact fell back to a download.
   Android has no way to import a vCard straight from a web page, so the tap
   otherwise produces no visible result and reads as a broken button. */
.vcard-hint {
  margin-block-start: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  background: var(--surface-sunken);
  color: var(--text-primary);
  font-size: var(--text-sm);
  text-align: center;
}

/* Only rendered when ?debug=share is present. Diagnosing the Web Share file
   allowlist needs a real Android device, and this is less setup than remote
   debugging. Invisible to normal visitors. */
.debug-box {
  margin: var(--space-4);
  padding: var(--space-3);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  background: var(--surface-sunken);
  color: var(--text-primary);
  font-size: var(--text-xs);
  white-space: pre-wrap;
  word-break: break-word;
}
