:root {
  --bg: #f7f7f6;
  --ink: #161513;
  --highlight: #111111;
  --muted: #5c5852;
  --gutter: clamp(1.5rem, 7vw, 5.5rem);
  --font-body: "IBM Plex Sans", "Segoe UI", system-ui, sans-serif;
  --font-display: "Instrument Serif", Georgia, serif;
  --font-lede: "IBM Plex Sans", "Segoe UI", system-ui, sans-serif;
}

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

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

html {
  --story-dim: 0;
  font-size: 110%;
  color-scheme: light;
  background-color: var(--bg);
}

::selection {
  /* Safari fades a fully opaque selection color. Just under opaque stays solid, matching other browsers. */
  background-color: rgb(from var(--highlight) r g b / 0.99);
  color: var(--bg);
}

body {
  position: relative;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  overflow-x: hidden;
  color: var(--ink);
  background: var(--bg);
  font-family: var(--font-body);
  font-size: 1.0625rem;
  line-height: 1.5;
}

#silk {
  position: fixed;
  inset: 0;
  z-index: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  background-color: var(--bg);
}

.screen {
  position: relative;
  display: flex;
  flex: 1;
  flex-direction: column;
  min-height: 100vh;
}

.site-header,
.hero,
.site-footer {
  position: relative;
  z-index: 1;
}

.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.75rem var(--gutter) 0;
}

.wordmark {
  display: block;
  width: calc(1.5rem * 655 / 133);
  height: 1.5rem;
  background: url("public/assets/artificialTextLogo.svg") center / 100% 100% no-repeat;
  text-decoration: none;
  user-select: none;
  -webkit-user-select: none;
}

.nav-link,
.site-footer {
  color: var(--muted);
  text-decoration: none;
}

.nav-link {
  font-size: 0.95rem;
  font-weight: 500;
  color: var(--muted);
  text-decoration: none;
  transition: color 0.2s ease;
}

.nav-link:hover {
  color: var(--ink);
}

.cta:hover {
  opacity: 0.6;
}

.hero {
  flex: 1;
  max-width: 42rem;
  padding: clamp(4rem, 16vh, 9rem) var(--gutter) 4rem;
}

h1 {
  margin: 0 0 1.85rem;
  font-family: var(--font-display);
  font-size: clamp(2.6rem, 6.6vw, 4.75rem);
  font-weight: 400;
  letter-spacing: -0.02em;
  line-height: 1.05;
}

.hero h1 {
  white-space: nowrap;
  user-select: none;
  -webkit-user-select: none;
}

.hero h1 .word {
  display: inline-block;
  position: relative;
  line-height: 1.3;
  margin-block: -0.125em;
  opacity: 0;
  user-select: none;
  -webkit-user-select: none;
  transition: opacity 0.64s linear;
  transition-delay: var(--delay, 0s);
}

.hero h1 .word:nth-child(-n+3) { z-index: 3; }
.hero h1 .word:nth-child(5),
.hero h1 .word:nth-child(6) { z-index: 2; }
.hero h1 .word:nth-child(8) { z-index: 1; }

.hero h1 .word.y-hit::after {
  content: attr(data-text);
  position: absolute;
  inset: 0;
  color: var(--bg);
  white-space: nowrap;
  pointer-events: none;
  user-select: none;
  -webkit-user-select: none;
  clip-path: inset(var(--y-top) var(--y-right) -0.25em var(--y-left));
}

.hero.is-ready .word {
  opacity: 1;
}

.hero.is-settled .word {
  user-select: text;
  -webkit-user-select: text;
}

.story-open {
  display: block;
  width: fit-content;
  margin: 0;
  padding: 0.5rem 1.05rem;
  border: 1px solid rgba(22, 21, 19, 0.18);
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font-family: var(--font-lede);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  opacity: 0;
  transition: color 0.2s ease, border-color 0.2s ease;
}

.hero.is-ready .story-open {
  animation: fade-in 0.8s linear 0.9s forwards;
}

.story-open:hover,
.story-close:hover {
  color: var(--ink);
  border-color: rgba(22, 21, 19, 0.55);
}

@keyframes fade-in {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

.lede {
  margin: 0 0 0.9rem;
  max-width: 32rem;
  color: var(--muted);
  font-family: var(--font-lede);
  font-size: 1.0625rem;
  line-height: 1.6;
}

.story {
  position: fixed;
  z-index: 4;
  top: 2.1vh;
  right: 0;
  bottom: 0;
  left: 0;
  width: auto;
  max-width: none;
  height: auto;
  max-height: none;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 1rem 1rem 0 0;
  background-color: var(--bg);
  overflow-x: hidden;
  overflow-y: scroll;
  scrollbar-gutter: stable;
  scrollbar-width: thin;
  scrollbar-color: #c4c1bb transparent;
  transform: translateY(110%);
  transition: transform 0.45s ease;
  overscroll-behavior: none;
}

.story:focus,
.story:focus-visible {
  outline: none;
}

.story::-webkit-scrollbar {
  width: 10px;
}

.story::-webkit-scrollbar-track {
  background: transparent;
}

.story::-webkit-scrollbar-thumb {
  background: #c4c1bb;
  border: 2px solid var(--bg);
  border-radius: 10px;
}

.story.is-in {
  transform: translateY(0);
}

.story.is-dragging {
  transition: none;
}

.story::backdrop {
  background-color: transparent;
}

.screen::after {
  content: "";
  position: absolute;
  z-index: 2;
  left: 0;
  right: 0;
  top: 0;
  bottom: 0;
  background-color: rgba(22, 21, 19, 0.18);
  opacity: var(--story-dim);
  pointer-events: none;
  transition: opacity 0.45s ease;
}

html:has(.story.is-in) {
  --story-dim: 1;
}

html:has(.story.is-in) .screen::after {
  pointer-events: auto;
}

html:has(.story.is-dragging) .screen::after {
  transition: none;
}

.story-close {
  position: sticky;
  top: 1.1rem;
  z-index: 2;
  display: grid;
  place-items: center;
  width: 2.35rem;
  height: 2.35rem;
  margin: 1.1rem 0.85rem 0 auto;
  padding: 0;
  border: 1px solid rgba(22, 21, 19, 0.18);
  border-radius: 50%;
  background: var(--bg);
  color: var(--muted);
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  transition: color 0.2s ease, border-color 0.2s ease;
}

.story-close::before,
.story-close::after {
  content: "";
  grid-area: 1 / 1;
  width: 0.7rem;
  height: 1px;
  background: currentColor;
  border-radius: 1px;
}

.story-close::before {
  transform: rotate(45deg);
}

.story-close::after {
  transform: rotate(-45deg);
}

.story-panel {
  max-width: 36rem;
  margin: -2.6rem auto 0;
  padding: 3.25rem 1.5rem 20vh;
}

.story-lead {
  margin: 0;
  font-family: var(--font-display);
  font-size: clamp(1.5rem, 3vw, 2.15rem);
  font-weight: 400;
  letter-spacing: -0.02em;
  line-height: 1.28;
}

.story-body {
  margin-top: 2.25rem;
  color: var(--muted);
  font-family: var(--font-body);
  font-size: 1rem;
  line-height: 1.65;
}

.story-body p {
  margin: 0 0 1.15rem;
}

.story-body p:last-child {
  margin-bottom: 0;
}

.cta {
  display: inline-block;
  margin-top: 1.35rem;
  color: var(--ink);
  font-family: var(--font-lede);
  font-size: 0.95rem;
  font-weight: 500;
  text-decoration: none;
}

.site-footer {
  padding: 0 var(--gutter) 1.75rem;
  font-size: 0.75rem;
  font-weight: 500;
}

.site-footer p {
  margin: 0;
}

html.is-phone {
  --safari-chrome-top: max(62px, env(safe-area-inset-top, 0px));
  --story-top: calc(var(--safari-chrome-top) + 12px);
  --safari-top-bleed: 360px;
  --safari-bottom-bleed: 420px;
  --safari-scroll-offset: 360px;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: none;
  background-color: #e4e2de;
  scrollbar-width: none;
}

html.is-phone::-webkit-scrollbar,
html.is-phone body::-webkit-scrollbar {
  display: none;
  width: 0;
  height: 0;
}

html.is-phone body {
  display: block;
  min-height: calc(100lvh + var(--safari-scroll-offset) + 40px);
  overflow: visible;
  background-color: #e4e2de;
  scrollbar-width: none;
}

html.is-phone .screen {
  height: 100dvh;
  min-height: 100dvh;
  margin-top: var(--safari-scroll-offset);
}

html.is-phone #silk {
  position: absolute;
  top: calc(-1 * var(--safari-top-bleed));
  left: 0;
  width: 100%;
  height: calc(100% + var(--safari-top-bleed) + var(--safari-bottom-bleed));
  background-color: transparent;
}

html.is-phone .site-header {
  padding-top: calc(1.75rem + env(safe-area-inset-top, 0px));
}

html.is-phone,
html.is-phone * {
  touch-action: manipulation;
}

html.is-phone .hero h1,
html.is-phone .hero h1 * {
  touch-action: none;
}

html.is-phone .hero h1 .word.y-hit::after {
  color: var(--ink);
}

html.is-phone .site-footer {
  padding-bottom: calc(1.75rem + env(safe-area-inset-bottom, 0px));
}

html.is-phone .story {
  position: absolute;
  top: var(--story-top);
  bottom: auto;
  /* In-app browsers (X) can report a stale landscape lvh until the phone rotates. */
  height: calc(max(100lvh, 100dvh) - var(--story-top) + 48px);
  overflow: hidden;
}

html.is-phone .story-close {
  position: absolute;
  top: 1.1rem;
  right: 0.85rem;
  margin: 0;
}

html.is-phone .story-panel {
  height: 100%;
  margin-top: 0;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: none;
  scrollbar-width: thin;
  scrollbar-color: #c4c1bb transparent;
}

html.is-phone .story-panel::-webkit-scrollbar {
  width: 10px;
}

html.is-phone .story-panel::-webkit-scrollbar-track {
  background: transparent;
}

html.is-phone .story-panel::-webkit-scrollbar-thumb {
  background: #c4c1bb;
  border: 2px solid var(--bg);
  border-radius: 10px;
}

html.is-phone .screen::after {
  top: calc(-1 * var(--safari-top-bleed));
  bottom: 0;
}

@media (orientation: landscape) and (max-height: 500px) {
  html.is-phone {
    --story-top: calc(max(12px, env(safe-area-inset-top, 0px)) + 33px);
  }

  html.is-phone .site-header {
    padding-top: calc(0.7rem + env(safe-area-inset-top, 0px));
  }

  html.is-phone .hero {
    padding-top: 0.75rem;
    padding-bottom: 1rem;
    padding-left: max(var(--gutter), env(safe-area-inset-left, 0px));
    padding-right: max(var(--gutter), env(safe-area-inset-right, 0px));
  }

  html.is-phone .site-footer {
    padding-bottom: calc(0.7rem + env(safe-area-inset-bottom, 0px));
  }

  html.is-phone .story-close {
    right: max(0.85rem, env(safe-area-inset-right, 0px));
  }

  html.is-phone .story-panel {
    max-width: none;
    padding-left: max(1.5rem, env(safe-area-inset-left, 0px));
    padding-right: max(1.5rem, env(safe-area-inset-right, 0px));
  }

  html.is-phone .story-lead,
  html.is-phone .story-body {
    max-width: 36rem;
    margin-inline: auto;
  }
}

.story-bottom {
  display: none;
}

@media (prefers-reduced-motion: reduce) {
  #silk {
    display: none;
  }

  .story,
  .story::backdrop {
    transition: none;
  }

  .hero h1 .word,
  .story-open {
    opacity: 1;
    user-select: text;
    -webkit-user-select: text;
    transition: none;
    animation: none;
  }

  body {
    background:
      radial-gradient(50% 60% at 78% 18%, #e4e2de, #f7f7f6 70%);
  }
}