/* ============================================================
   Thaw — home page
   Tokens mirror the iOS design system (ios/Thaw/DesignSystem):
   DSColors, DSTypography, DSButton sizes, DSCornerRadius.
   Legal pages still use styles.css.
   ============================================================ */

/* ---------- Tokens ---------- */
:root {
  /* DSColors — light */
  --text-primary: #000000;                    /* .label */
  --text-secondary: rgba(60, 60, 67, 0.6);    /* .secondaryLabel */
  --bg-primary: #FFFFFF;                      /* .systemBackground */
  --separator: rgba(60, 60, 67, 0.29);        /* .separator */
  --btn-primary: #000000;
  --btn-primary-pressed: #1A1A1A;             /* white 0.10 */
  --on-primary: #FFFFFF;
  --btn-secondary: rgba(229, 229, 234, 0.65); /* systemGray5 @ 0.65 */
  --btn-secondary-pressed: rgba(209, 209, 214, 0.75); /* systemGray4 @ 0.75 */
  --screen-shadow: 0 24px 60px rgba(0, 0, 0, 0.10), 0 2px 8px rgba(0, 0, 0, 0.06);

  /* DSTypography — SF Pro, as in the app */
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display",
          system-ui, "Helvetica Neue", "Segoe UI", Roboto, Arial, sans-serif;
  --h0: 700 40px/1.12 var(--font);            /* Heading.h0 */
  --h1: 700 34px/1.2 var(--font);             /* Heading.h1 = largeTitle bold */
  --h2: 700 28px/1.2 var(--font);             /* Heading.h2 = title bold */
  --body: 500 17px/1.3 var(--font);           /* Text.body = body medium */
  --subhead: 500 15px/1.33 var(--font);       /* subheadline medium */
  --caption: 500 12px/1.33 var(--font);       /* Text.caption = caption medium */

  /* DSButton sizes */
  --btn-small-h: 40px;   --btn-small-r: 12px;  --btn-small-px: 14px;
  --btn-large-h: 56px;   --btn-large-r: 20px;  --btn-large-px: 18px;

  /* DSLayout.Page */
  --page-x: 16px;
  --container: 1120px;

  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    /* DSColors — dark */
    --text-primary: #EBEBEB;                    /* white 0.92 */
    --text-secondary: rgba(235, 235, 245, 0.6);
    --bg-primary: #141414;                      /* white 0.08 */
    --separator: rgba(84, 84, 88, 0.6);
    --btn-primary: #EBEBEB;                     /* inverted primary */
    --btn-primary-pressed: #D1D1D1;             /* white 0.82 */
    --on-primary: #1F1F1F;                      /* white 0.12 */
    --btn-secondary: rgba(44, 44, 46, 0.65);
    --btn-secondary-pressed: rgba(58, 58, 60, 0.75);
    --screen-shadow: 0 24px 60px rgba(0, 0, 0, 0.5), 0 0 0 1px rgba(255, 255, 255, 0.06);

    color-scheme: dark;
  }
}

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

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--bg-primary);
  color: var(--text-primary);
  font: var(--body);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Footer sticks to the bottom on tall screens; the spare height is split
   above and below the hero, so the gap to the footer stays balanced. */
main {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

a { color: inherit; }

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

.container {
  width: 100%;
  max-width: var(--container);
  margin: 0 auto;
  padding: 0 var(--page-x);
}

@media (min-width: 768px) {
  :root { --page-x: 32px; }
}

.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.skip-link {
  position: absolute;
  left: 8px; top: -100px;
  padding: 8px 12px;
  border-radius: 12px;
  background: var(--btn-primary);
  color: var(--on-primary);
  font: var(--subhead);
  z-index: 10;
}
.skip-link:focus { top: 8px; }

:focus-visible {
  outline: 2px solid var(--text-primary);
  outline-offset: 2px;
}

/* ---------- Buttons (DSButton) ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  white-space: nowrap;
  text-decoration: none;
  font: var(--body);
  border: 0;
  cursor: pointer;
  transition: background-color 0.15s ease, transform 0.15s ease;
  -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: scale(0.98); }

.btn-small {
  height: var(--btn-small-h);
  padding: 0 var(--btn-small-px);
  border-radius: var(--btn-small-r);
  font: var(--subhead);
}
.btn-regular {
  height: 48px;                               /* DSButton .regular */
  padding: 0 24px;
  border-radius: 16px;
}
.btn-large {
  height: var(--btn-large-h);
  padding: 0 calc(var(--btn-large-px) * 2.5);
  border-radius: var(--btn-large-r);
  min-width: 220px;
}

.btn-primary { background: var(--btn-primary); color: var(--on-primary); }
.btn-primary:hover, .btn-primary:active { background: var(--btn-primary-pressed); }

.btn-ghost { background: transparent; color: var(--text-primary); }
.btn-ghost:hover, .btn-ghost:active { background: var(--btn-secondary); }

/* ---------- Header ---------- */
.header {
  position: sticky;
  top: 0;
  z-index: 5;
  background: var(--bg-primary);
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  height: 64px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
  flex-shrink: 0;
}
.brand-name { font: 700 20px/1 var(--font); }  /* title3 bold = Heading.h4 */

.header-nav {
  display: flex;
  align-items: center;
  gap: 4px;
}
.header-nav .btn-primary { margin-left: 8px; }

/* --- Page-to-page transitions (cross-document View Transitions) ---
   Home has no "Get app" in the header, other pages do. When moving between
   them the button fades and scales in/out, and the links next to it slide
   over instead of jumping. Browsers without support just navigate. */
@view-transition { navigation: auto; }

.header-nav a[href$="privacy/"] { view-transition-name: nav-privacy; }
.header-nav a[href$="terms/"]   { view-transition-name: nav-terms; }
.header-nav a[href$="support/"] { view-transition-name: nav-support; }
.header-nav [data-appstore-link] { view-transition-name: nav-get-app; }

::view-transition-group(*) {
  animation-duration: 0.35s;
  animation-timing-function: cubic-bezier(0.22, 1, 0.36, 1);
}
::view-transition-old(root),
::view-transition-new(root) { animation-duration: 0.2s; }

::view-transition-new(nav-get-app):only-child {
  animation: get-app-in 0.35s cubic-bezier(0.22, 1, 0.36, 1) both;
}
::view-transition-old(nav-get-app):only-child {
  animation: get-app-out 0.25s ease both;
}
@keyframes get-app-in {
  from { opacity: 0; transform: scale(0.85); filter: blur(6px); }
}
@keyframes get-app-out {
  to { opacity: 0; transform: scale(0.85); filter: blur(6px); }
}

@media (prefers-reduced-motion: reduce) {
  ::view-transition-group(*),
  ::view-transition-old(*),
  ::view-transition-new(*) { animation: none !important; }
}

@media (max-width: 480px) {
  .brand-name { display: none; }
  .label-long { display: none; }
  .header-nav { gap: 0; }
  .header-nav .btn-ghost { padding: 0 10px; }
  .header-nav .btn-primary { margin-left: 4px; }
}

/* ---------- Hero ---------- */
.hero {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 64px var(--page-x) 100px;
  text-align: center;
}

/* Heading hierarchy: app name (h0) → subtitle → slide headline (h1/h2). */
.hero-head {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  margin-bottom: 68px;
}
.hero-title {
  margin: 0;
  font: 700 34px/1.15 var(--font);            /* Heading.h1 = largeTitle bold */
  text-wrap: balance;
}
.hero-subtitle {
  margin: 6px 0 0;                           /* extra air under the title */
  font: 500 17px/1.3 var(--font);            /* Text.body */
  color: var(--text-primary);
}

@media (min-width: 768px) {
  .hero { padding-top: 112px; padding-bottom: 120px; }
  .hero-head { gap: 12px; margin-bottom: 92px; }
  .hero-title { font-size: 52px; line-height: 1.08; }
  .hero-subtitle { font-size: 22px; }        /* title2 medium */
}

/* Screenshot height: fit headline + screenshot + Get app into the first screen. */
.hero {
  --screen-h: clamp(400px, calc(100vh - 360px), 600px);
  --screen-w: calc(var(--screen-h) * 738 / 1600);
}
@supports (height: 100dvh) {
  .hero { --screen-h: clamp(400px, calc(100dvh - 360px), 600px); }
}

.carousel {
  position: relative;
  width: 100%;
  display: flex;
  justify-content: center;
}

/* All slides share one grid cell, so they replace each other in place. */
.slides {
  display: grid;
  width: 100%;
  max-width: 720px;
}

.slide {
  grid-area: 1 / 1;
  margin: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 40px;
  pointer-events: none;
}
.slide.is-active { pointer-events: auto; }

.slide-title {
  margin: 0;
  max-width: 18em;
  font: 700 24px/1.2 var(--font);             /* title2 bold, a step below the app name */
  text-wrap: balance;
  /* Every slide reserves the height of the tallest headline (set from JS),
     and the text sits at its bottom: the screenshot never jumps. */
  min-height: var(--slide-title-h, auto);
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

@media (min-width: 768px) {
  .slide { gap: 48px; }
  /* Narrower than the shortest headline (~20 em), wide enough for the
     longest (~33 em) in two: every headline takes exactly two lines. */
  .slide-title { font-size: 34px; max-width: 18em; }
}

/* Screenshot with iPhone-like corners (~14% of width). */
.screen {
  height: var(--screen-h);
  aspect-ratio: 738 / 1600;
  border-radius: 14% / 6.46%;
  overflow: hidden;
  box-shadow: var(--screen-shadow);
  background: var(--bg-primary);
}
.screen img { width: 100%; height: 100%; object-fit: cover; }

/* --- Transition: blur replace (as SwiftUI .blurReplace) ---
   Outgoing slide blurs, shrinks a touch and fades; incoming one comes
   into focus from the same state. Screenshot trails the headline. */
.slide-title,
.screen {
  opacity: 0;
  filter: blur(16px);
  transform: scale(0.94);
  transition:
    opacity 0.5s ease,
    filter 0.6s ease,
    transform 0.7s cubic-bezier(0.22, 1, 0.36, 1);
}

.slide.is-active .slide-title,
.slide.is-active .screen {
  opacity: 1;
  filter: blur(0);
  transform: none;
}
.slide.is-active .slide-title { transition-delay: 0.12s; }
.slide.is-active .screen { transition-delay: 0.2s; }

.slide.is-leaving .screen { transition-delay: 0.05s; }

@media (prefers-reduced-motion: reduce) {
  .slide-title, .screen {
    filter: none;
    transform: none;
    transition: opacity 0.3s ease;
  }
}

/* ---------- Arrows ---------- */
.arrow {
  position: absolute;
  z-index: 2;
  /* Vertically centered on the screenshot, just outside its edges. */
  bottom: calc(var(--screen-h) / 2 - 22px);
  width: 44px;
  height: 44px;
  padding: 0;
  border: 0;
  border-radius: 22px;
  display: grid;
  place-items: center;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  transition: color 0.15s ease, transform 0.15s ease;
  -webkit-tap-highlight-color: transparent;
}
/* Secondary by default, primary on hover; no background. */
.arrow:hover,
.arrow:active { color: var(--text-primary); }
.arrow:active { transform: scale(0.94); }
.arrow-prev { right: calc(50% + var(--screen-w) / 2 + 40px); }
.arrow-next { left: calc(50% + var(--screen-w) / 2 + 40px); }

@media (max-width: 480px) {
  .arrow-prev { right: calc(50% + var(--screen-w) / 2 + 8px); }
  .arrow-next { left: calc(50% + var(--screen-w) / 2 + 8px); }
}

/* ---------- Toast (DSToast) ---------- */
.toast {
  position: fixed;
  z-index: 20;
  top: 72px;                                  /* just under the header */
  left: 50%;
  max-width: calc(100% - 2 * var(--page-x));
  padding: 12px 16px;
  border-radius: 16px;
  background: var(--btn-primary);
  color: var(--on-primary);
  font: var(--body);
  text-align: center;
  pointer-events: none;
  opacity: 0;
  transform: translate(-50%, -16px);
  transition: opacity 0.25s ease, transform 0.25s ease;
}
.toast.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* Get app under the subtitle, before the carousel. */
.hero-cta { margin-top: 10px; }
.btn-icon { margin-right: 8px; margin-top: -3px; }
@media (min-width: 768px) {
  .hero-cta { margin-top: 14px; }
}

/* ---------- Legal pages (Privacy, Terms, Support) ---------- */
/* Text pages start at the top instead of centering in spare height. */
main.legal { justify-content: flex-start; }

.legal-inner {
  max-width: calc(680px + 2 * var(--page-x));
  padding-top: 48px;
  padding-bottom: 100px;
  font: 400 17px/1.55 var(--font);           /* body, regular for long reading */
}
@media (min-width: 768px) {
  .legal-inner { padding-top: 80px; padding-bottom: 120px; }
}

.legal-head {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 40px;
}
.legal-title {
  margin: 0;
  font: 700 34px/1.15 var(--font);            /* Heading.h1, as the home title */
}
@media (min-width: 768px) {
  .legal-head { gap: 12px; margin-bottom: 56px; }
  .legal-title { font-size: 52px; line-height: 1.08; }
}
.legal-meta {
  margin: 0;
  font: var(--body);
  color: var(--text-secondary);
}

.legal-inner h2 {
  margin: 48px 0 12px;
  font: 700 22px/1.25 var(--font);            /* Heading.h3 = title2 bold */
}
.legal-inner h3 {
  margin: 32px 0 8px;
  font: 700 17px/1.3 var(--font);             /* Heading.h5 = headline bold */
}
.legal-inner p { margin: 0 0 16px; }
.legal-inner ul,
.legal-inner ol {
  margin: 0 0 16px;
  padding-left: 1.25em;
}
.legal-inner li { margin-bottom: 8px; }
.legal-inner li::marker { color: var(--text-secondary); }
.legal-inner strong { font-weight: 600; }
.legal-inner a:not(.btn) {
  text-underline-offset: 3px;
  text-decoration-thickness: 1px;
  text-decoration-color: var(--text-secondary);
}
.legal-inner a:not(.btn):hover { text-decoration-color: currentColor; }
.legal-inner .btn { margin: 4px 0; }

.header-nav .btn-ghost[aria-current="page"] { background: var(--btn-secondary); }

/* ---------- Footer ---------- */
.footer {
  padding: 32px 0 40px;
  color: var(--text-secondary);
  font: var(--caption);
}
/* Divider spans the content width (same edges as the header), not the screen. */
.footer-inner {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.footer-inner::before {
  content: "";
  position: absolute;
  top: -32px;
  left: var(--page-x);
  right: var(--page-x);
  border-top: 0.5px solid var(--separator);
}
.footer p { margin: 0; }
.footer strong { font-weight: 600; }
.footer a { text-decoration: none; }
.footer a:hover { color: var(--text-primary); text-decoration: underline; }
