.v5-preview {
  --preview-max-width: 704px;
}
.v5-preview :is(.home-introduction, .project-list) { padding-block: 40px !important; }
/* Keep the header fade above the intro at rest, so the blur doesn't smear its first line. */
:root.v5-preview .home-header { --header-fade: 32px; }
.v5-preview .card .project-cover {
  height: auto;
  aspect-ratio: 704 / 480 !important;
}
.v5-preview .project-cover > span[aria-hidden="true"] { display: none; }
/* Only the desktop carousel has a current card; mobile stacks them, so all stay full strength. */
@media (min-width: 768px) {
  .v5-preview .card[data-current="false"] .project-cover { opacity: 0.36; }
}
.v5-preview .card { cursor: pointer; }
@media (prefers-reduced-motion: no-preference) {
  .v5-preview .project-cover { transition: opacity 220ms ease-out; }
}
@media (forced-colors: active) {
  .v5-preview .project-cover { outline: 1px solid GrayText; }
}

@media (min-width: 768px) {
  .v5-preview .home-introduction { --v4-reading-width: var(--preview-caption-width, 656px); }
  .v5-preview .portfolio-layout {
    height: 100dvh !important;
    min-height: 0 !important;
  }
  .v5-preview .project-list {
    container-type: size;
    flex: 1 1 0 !important;
    min-height: 340px;
    --rail-gap: 24px;
    /* Heading, gap, and the shared two-line subtitle. */
    --caption-height: calc(30px + 6px + 48px);
    --card-width: min(var(--preview-max-width), calc(100cqw - 48px),
      calc((100cqh - var(--caption-height) - var(--rail-gap)) * 704 / 480));
  }
  .v5-preview .desktop-project-caption {
    order: 1;
    width: var(--card-width);
    max-width: none;
    padding-inline: min(24px, 2vw);
  }
  .v5-preview .rail {
    --gutter: calc((100cqw - var(--card-width)) / 2);
    padding-inline: var(--gutter) !important;
    scroll-padding-inline: var(--gutter) !important;
    flex: none;
  }
  .v5-preview .card { flex-basis: var(--card-width) !important; }
  .v5-preview :is(.home-header, .home-introduction, .project-pager-footer) { flex: none; }
}

@media (min-width: 768px) and (max-width: 1024px) and (max-height: 768px) {
  .v5-preview .project-list { padding-block: 12px !important; }
}

@media (max-width: 767px) {
  .v5-preview .home-header > nav[aria-label="Social links"] { display: none !important; }
  /* Mobile intro: shorter header fade, readable body size, tighter gap to the first project. */
  :root.v5-preview .home-header { --header-fade: 24px; }
  .v5-preview .home-introduction { padding-block: 28px 8px !important; }
  .v5-preview .project-list { padding-block-start: 32px !important; }
  .v5-preview .home-introduction [aria-label="Introduction"] { gap: 4px !important; }
  .v5-preview .home-introduction [aria-label="Introduction"] > p {
    font-size: 16px !important;
    line-height: 1.6 !important;
    letter-spacing: -0.005em !important;
  }
  .v5-preview .intro-social-links {
    gap: 0 !important;
    margin-inline-start: -8px;
    font: 500 15px/20px var(--v4-nav-font) !important;
  }
  /* 44px tall tap targets without moving the text. */
  .v5-preview .intro-social-links a {
    padding: 12px 8px;
    -webkit-tap-highlight-color: transparent;
  }
  .v5-preview .intro-social-links a:is(:hover, :focus-visible, :active) { color: var(--v4-nav-text) !important; }
  .v5-preview :is(.home-header, .home-introduction, .rail) {
    padding-inline: 16px !important;
  }
  .v5-preview .home-introduction { --v4-reading-width: var(--preview-max-width); }
  .v5-preview .card {
    width: 100%;
    max-width: var(--preview-max-width);
    margin-inline: auto;
  }
}

.v5-preview .preview-toast-region {
  position: fixed;
  inset-inline: 12px;
  --toast-inset: calc(72px + env(safe-area-inset-bottom, 0px));
  bottom: var(--toast-inset);
  z-index: 10;
  display: grid;
  justify-items: center;
  pointer-events: none;
}
.v5-preview .preview-toast {
  grid-area: 1 / 1;
  --stack-scale: 1;
  --stack-offset: 0px;
  visibility: hidden;
  opacity: 0;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  border-radius: 14px;
  background: #222;
  color: #fff;
  box-shadow: 0 6px 20px rgb(0 0 0 / 20%);
  font: 500 14px/20px var(--v4-nav-font);
}
.v5-preview .preview-toast[data-visible="true"] {
  visibility: visible;
  opacity: 1;
  scale: var(--stack-scale);
  transform: translateY(var(--stack-offset));
}
.v5-preview .preview-toast:has(~ .preview-toast[data-visible="true"]) {
  --stack-scale: .96;
  --stack-offset: -9px;
}
.v5-preview .preview-toast:has(~ .preview-toast[data-visible="true"] ~ .preview-toast[data-visible="true"]) {
  --stack-scale: .92;
  --stack-offset: -18px;
}
@media (max-width: 767px) {
  .v5-preview .preview-toast-region { --toast-inset: calc(16px + env(safe-area-inset-bottom, 0px)); }
}
@media (prefers-reduced-motion: no-preference) {
  .v5-preview .preview-toast {
    scale: .86;
    transform-origin: center bottom;
    transform: translateY(calc(100% + var(--toast-inset)));
    transition: scale 240ms cubic-bezier(.35, -.3, .7, .5), transform 240ms cubic-bezier(.4, 0, 1, 1), opacity 220ms ease-in, visibility 0s 240ms;
  }
  .v5-preview .preview-toast[data-visible="true"] {
    transition: scale 360ms cubic-bezier(.2, 1.65, .4, 1), transform 360ms cubic-bezier(.2, .8, .2, 1), opacity 200ms ease-out, visibility 0s;
  }
  .v5-preview .preview-toast[data-visible="true"] .preview-toast-feather {
    transform-origin: center;
    animation: preview-feather-write 1.6s ease-in-out both;
  }
  @keyframes preview-feather-write {
    0%, 100% { transform: translate(0, 0) rotate(0); }
    25% { transform: translate(2px, -4px) rotate(-8deg); }
    50% { transform: translate(-2px, -2px) rotate(4deg); }
    75% { transform: translate(1px, -1px) rotate(-3deg); }
  }
}
