.home-page,
.editor-modal.home-template-modal,
.home-handoff {
  --home-surface: light-dark(
    color-mix(in srgb, var(--power-primary-color) 3%, var(--white)),
    color-mix(in srgb, var(--power-primary-color) 5%, var(--black))
  );
}

.home-surface {
  background: var(--home-surface);
  border-radius: 0.75em;
  border: 1px solid
    light-dark(oklab(0.48 0.01 0.05 / 0.08), oklab(0.95 0.01 0.06 / 0.05));
}

.home-page {
  container: platform-home / inline-size;
  min-height: 100%;
  color: var(--text-primary);
  font-size: 1.125em;
}

.home-content {
  width: min(100%, 85em);
  padding: 0 clamp(1em, 4cqi, 4em);
  margin-inline: auto;
}

.home-hero {
  padding: 5em 0 2.75em;
  margin: 0 0 3.5em 0;
  text-align: center;

  h1 {
    margin: 0 0 0.8em;
    font-family: var(--display-font);
    font-size: clamp(2em, 2.75cqi, 2.55em);
    font-weight: 300;
    letter-spacing: -0.045em;
    line-height: 1.15;
  }
}

.home-prompt-wrap {
  width: min(100%, 59em);
  margin-inline: auto;
  text-align: left;
}

.home-prompt-examples {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 0.6em;
  margin-top: 1.25em;
  color: var(--text-muted);
  font-size: 0.8em;

  button {
    display: inline-flex;
    align-items: center;
    gap: 0.8em;
    padding: 0.6em 0.9em;
    border-radius: 2em;
    color: var(--text-primary);
    background: color-mix(in srgb, var(--home-surface) 50%, transparent);

    &:hover {
      background: var(--home-surface);
    }
  }

  .material-symbols-outlined {
    font-size: 1em;
    color: var(--text-muted);
  }
}

.home-catalog {
  padding-bottom: 2em;
}

.home-featured-section + .home-featured-section {
  margin-top: 3.5em;
}

.home-featured-section .home-collection-heading h3 {
  margin-inline-end: auto;
}

.home-featured-empty {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 1em;
  padding-block: 1em;
  font-size: 0.85em;
  color: var(--text-muted);
}

.templates-page {
  padding-block: 2em 3em;

  > .home-content > .home-resource-link {
    margin-bottom: 1.5em;
  }
}

.home-template-pagination {
  display: flex;
  justify-content: center;
  margin-top: 2em;
}

.home-section-heading {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  justify-content: space-between;
  gap: 2em;
  margin-bottom: 1.8em;

  h1,
  h2 {
    flex: 1 1 14em;
    font-family: var(--display-font);
    font-size: 1.75em;
    font-weight: 350;
    letter-spacing: -0.035em;
    line-height: 1.2;
    margin: 0;
  }
}

.home-template-search {
  display: flex;
  align-items: center;
  gap: 0.7em;
  flex: 1 1 24em;
  max-width: min(100%, 32em);
  padding: 0.75em 0.9em;
  color: var(--text-muted);
  font-size: 0.9em;

  .material-symbols-outlined {
    font-size: 1.4em;
  }

  input {
    width: 100%;
    min-width: 0;
    padding: 0;
    border: 0;
    outline: none;
    background: transparent;
    color: var(--text-primary);
    font: inherit;
  }

  &:focus-within {
    outline: 2px solid var(--power-primary-color);
    outline-offset: 2px;
  }
}

.home-collection-heading {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.75em 2em;
  margin-bottom: 1em;

  h3 {
    font-size: 1.1em;
    font-weight: 550;
    letter-spacing: -0.015em;
  }

  > span {
    font-size: 0.8em;
    color: var(--text-muted);
  }
}

.home-template-row,
.home-template-grid {
  display: grid;
  gap: 1.5em;
}

.home-template-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.home-template-row {
  grid-auto-flow: column;
  grid-auto-columns: clamp(15em, 30%, 22em);
  overflow-x: auto;
  overscroll-behavior-x: contain;
  scroll-snap-type: x mandatory;
  scrollbar-width: none;
  padding-block: 0.4em 0.7em;
  mask-image: linear-gradient(
    to right,
    transparent,
    var(--black) var(--carousel-fade-left),
    var(--black) calc(100% - var(--carousel-fade-right)),
    transparent
  );

  &::-webkit-scrollbar {
    display: none;
  }

  > * {
    scroll-snap-align: start;
  }
}

.home-template-carousel {
  position: relative;
  --carousel-fade-left: 0em;
  --carousel-fade-right: 0em;

  &.has-previous {
    --carousel-fade-left: 3.5em;
  }

  &.has-next {
    --carousel-fade-right: 3.5em;
  }
}

.home-carousel-arrow {
  position: absolute;
  z-index: 1;
  top: 45%;
  translate: 0 -50%;
  display: grid;
  place-items: center;
  width: 2.5em;
  height: 2.5em;
  border-radius: 50%;
  color: var(--text-primary);
  background: color-mix(in srgb, var(--home-surface) 90%, transparent);
  box-shadow: 0 0.2em 1em rgb(0 0 0 / 15%);
  backdrop-filter: blur(0.5em);
  cursor: pointer;
  transition:
    background 150ms ease,
    opacity 150ms ease;

  &.previous {
    left: 0.6em;
  }

  &.next {
    right: 0.6em;
  }

  &:hover,
  &:focus-visible {
    background: var(--home-surface);
  }

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

  &:disabled {
    visibility: hidden;
    opacity: 0;
  }
}

.home-carousel-pages {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  margin-top: 0.4em;

  button {
    display: grid;
    place-items: center;
    min-width: 1.2em;
    height: 1.5em;
    padding-inline: 0.3em;
    color: var(--text-primary);
    opacity: 0.25;

    span {
      width: 0.3em;
      height: 0.3em;
      border-radius: 1em;
      background: currentColor;
      transition: width 150ms ease;
    }

    &:hover,
    &:focus-visible,
    &[aria-current] {
      opacity: 0.85;
    }

    &[aria-current] span {
      width: 1em;
    }
  }
}

.home-template-card {
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
  padding: 0;
  color: var(--text-primary);
  text-align: left;
  box-shadow: 0 0.15em 0.4em rgb(0 0 0 / 2%);
  transition:
    transform 180ms ease,
    box-shadow 180ms ease;

  &:hover,
  &:focus-visible {
    transform: translateY(-0.25em);
    box-shadow: 0 0.7em 1.8em rgb(0 0 0 / 7%);

    .home-template-open {
      opacity: 1;
      transform: translate(0);
    }

    .home-template-image img {
      transform: scale(1.035);
    }
  }
}

.home-template-image,
.home-template-output {
  position: relative;
  width: 100%;
  overflow: hidden;
  background: var(--home-surface);

  img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
  }
}

.home-template-image {
  aspect-ratio: 1.7;

  img {
    transition: transform 300ms ease;
  }
}

.home-template-row .home-template-image {
  aspect-ratio: 1.45;
}

.home-template-kind {
  position: absolute;
  top: 0.75em;
  left: 0.75em;
  padding: 0.5em 0.8em;
  border-radius: 0.55em;
  background: rgb(255 255 255 / 85%);
  color: var(--black);
  backdrop-filter: blur(0.5em);
  font-size: 0.7em;
  font-weight: 550;
}

.home-template-open {
  position: absolute;
  right: 0.8em;
  bottom: 0.8em;
  display: grid;
  place-items: center;
  width: 2.5em;
  height: 2.5em;
  border-radius: 50%;
  background: #fff;
  color: var(--black);
  opacity: 0;
  transform: translateY(0.25em);
  transition:
    opacity 180ms ease,
    transform 180ms ease;

  .material-symbols-outlined {
    font-size: 1.3em;
  }
}

.home-template-info {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 0.8em;
  width: 100%;
  padding: 1.4em;

  h3 {
    font-family: var(--display-font);
    font-size: 1.45em;
    font-weight: 500;
    letter-spacing: -0.03em;
    line-height: 1.2;
  }

  p {
    color: var(--text-muted);
    font-size: 0.85em;
    line-height: 1.6;
  }
}

.home-template-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.65em;
  color: var(--text-muted);
  font-size: 0.7em;
}

.home-template-filters,
.home-filter-group {
  display: flex;
  flex-wrap: wrap;
  gap: 1em;
}

.home-template-filters {
  justify-content: space-between;
  gap: 1em 2em;
  padding: 1.2em 0;
  margin-bottom: 1.5em;
}

.home-filter {
  display: flex;
  align-items: center;
  gap: 0.8em;
  color: var(--text-muted);
  font-size: 0.8em;

  select {
    max-width: 16em;
    min-width: 9em;
    padding: 0.65em 1.8em 0.65em 0.8em;
    border: 0;
    border-radius: 0.5em;
    color: var(--text-primary);
    background: var(--home-surface);
    font: inherit;
    cursor: pointer;
  }
}

.home-compact-filters {
  gap: 0.4em;

  .home-filter > span {
    display: none;
  }

  select {
    min-width: 0;
    padding: 0.4em 1.8em 0.4em 0.6em;
    color: inherit;
    background: transparent;

    &:hover,
    &:focus-visible {
      color: var(--text-primary);
      background: var(--home-surface);
    }
  }
}

.home-template-empty {
  padding: 5em 1em;
  text-align: center;

  > .material-symbols-outlined {
    color: var(--text-muted);
    font-size: 2em;
    margin-bottom: 0.6em;
  }

  h3 {
    margin-bottom: 1em;
    font-size: 1.5em;
    font-weight: 500;
  }
}

.home-primary-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 2em;
  padding: 1em 1.4em;
  border-radius: 0.7em;
  color: var(--white);
  background: var(--power-primary-color);
  font: inherit;
  font-size: 0.9em;
  font-weight: 550;

  .material-symbols-outlined {
    font-size: 1.25em;
  }
}

.home-get-started {
  padding-block: 2em 4em;
  margin-top: 2em;
}

.home-resource-label {
  display: flex;
  align-items: center;
  gap: 0.6em;
  margin: 0em;
  color: var(--text-muted);
  font-size: 0.75em;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.home-section-dot {
  width: 0.45em;
  height: 0.45em;
  border-radius: 50%;
  background: var(--power-primary-color);
}

.home-resource-grid {
  display: grid;
  grid-template-columns: minmax(0, 3fr) minmax(0, 2fr);
  gap: 1.5em;
}

.home-resource {
  display: flex;
  flex-direction: column;
  gap: 1.25em;
  padding: 1.5em;
  min-width: 0;

  h3 {
    font-family: var(--display-font);
    font-size: 1.45em;
    font-weight: 450;
    letter-spacing: -0.03em;
  }

  p:not(.home-resource-label) {
    color: var(--text-muted);
    font-size: 0.75em;
    line-height: 1.6;
  }
}

.home-optimizer-intro {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-items: start;
  gap: 1.5em;

  p {
    margin-top: 0.8em;
  }
}

.home-title {
  display: flex;
  align-items: center;
  gap: 0.33em;
  .icon {
    font-size: 0.9em;
    opacity: 0.5;
  }
}
.home-resource-heading {
  > p:last-child {
    margin-top: 0.4em;
  }
}

.home-optimizer-features {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.75em;
  list-style: none;
  padding: 0;
  font-size: 0.85em;

  li {
    padding: 0.75em;
    border-radius: 0.5em;
    background: color-mix(in srgb, var(--text-primary) 4%, transparent);
    opacity: 0.8;
    font-size: 0.8em;
  }
}

.home-resource-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 1em 2em;
  margin-top: auto;
}

.home-resource-link {
  display: inline-flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6em;
  color: inherit;
  font-size: 0.8em;

  &:hover,
  &:focus-visible {
    text-decoration: underline;
    text-underline-offset: 0.2em;
  }

  .material-symbols-outlined {
    font-size: 1.1em;
    opacity: 0.45;
  }
}

.home-guide-links {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1em 3em;
  margin-top: 1em;
}

.home-tutorial {
  position: relative;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  border-radius: 0.5em;
  box-shadow: 0 0.25em 0.5em #0000004d;

  button,
  iframe,
  img {
    display: block;
    width: 100%;
    height: 100%;
    border: 0;
  }

  img {
    object-fit: cover;
    transition: transform 180ms ease;
  }

  button:hover img {
    transform: scale(1.04);
  }
}

.home-tutorial-play {
  position: absolute;
  inset: 50% auto auto 50%;
  translate: -50% -50%;
  display: grid;
  place-items: center;
  width: 3em;
  height: 3em;
  border-radius: 50%;
  color: var(--black);
  background: var(--white);
}

.home-tutorial-caption {
  position: absolute;
  inset: auto 0 0;
  padding: 2em 0.8em 0.8em;
  background: linear-gradient(transparent, var(--black));
  color: var(--white);
  font-size: 0.75em;
  text-align: left;
}

@container platform-home (max-width: 60em) {
  .home-resource-grid {
    grid-template-columns: minmax(0, 1fr);
  }
}

@container platform-home (max-width: 35em) {
  .home-optimizer-intro {
    grid-template-columns: minmax(0, 1fr);
  }

  .home-optimizer-features {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

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

/* Reuse the existing modal's keyboard, focus trap and focus restoration. */
.editor-modal.home-template-modal {
  display: grid;
  grid-template: minmax(0, auto) / minmax(0, 64em);
  place-content: center;
  place-items: center;
  padding: clamp(1em, 3vw, 3em);
  background: color-mix(in srgb, var(--home-surface) 40%, transparent);
  backdrop-filter: blur(0.6em);
  color: var(--text-primary);
  container: template-preview / inline-size;

  &[role='region'] {
    border-radius: var(--grid-corners-radius);
  }

  > .editor-modal-body {
    grid-area: 1 / 1;
    width: 100%;
    height: auto;
    max-height: 100%;
    overflow-y: auto;
    border: 1px solid var(--border-subtle-color);
    border-radius: 1.25em;
    background: var(--home-surface);
    box-shadow: 0 1.5em 5em light-dark(rgb(0 0 0 / 8%), rgb(0 0 0 / 16%));
  }

  > .editor-close {
    grid-area: 1 / 1;
    position: relative;
    inset: auto;
    align-self: start;
    justify-self: end;
    width: 2.25em;
    height: 2.25em;
    margin: 0.65em;
    color-scheme: inherit;
    color: var(--text-primary);
    background: color-mix(in srgb, var(--text-primary) 6%, var(--home-surface));
    border-radius: 50%;
    box-shadow: none;

    &:hover,
    &:focus-visible {
      background: color-mix(
        in srgb,
        var(--text-primary) 12%,
        var(--home-surface)
      );
    }
  }
}

.home-template-detail {
  display: grid;
  grid-template-columns: 0.9fr 1.1fr;
}

.home-template-description,
.home-template-preview {
  display: flex;
  flex-direction: column;
  gap: 1em;
  padding: 1.75em;
}

.home-template-description {
  align-items: start;

  h2 {
    margin: 0;
    font-family: var(--display-font);
    font-size: 2.2em;
    font-weight: 450;
    line-height: 1.05;
    letter-spacing: -0.045em;
  }

  > p {
    margin: 0;
    color: var(--text-muted);
    line-height: 1.7;
  }

  > .home-primary-button {
    margin-top: auto;
  }
}

.home-template-facts {
  width: 100%;
  margin: 0;
  font-size: 0.85em;

  > div {
    display: flex;
    justify-content: space-between;
    gap: 1em;
    padding: 0.75em 0;
    border-bottom: 1px solid var(--border-main-color);
  }

  dt {
    color: var(--text-muted);
  }

  dd {
    margin: 0;
    text-align: right;
  }
}

.home-template-preview {
  min-width: 0;
}

.home-template-output {
  border-radius: 0.8em;
  aspect-ratio: 4 / 3;

  > span {
    position: absolute;
    bottom: 1em;
    left: 1em;
    display: flex;
    align-items: center;
    gap: 0.6em;
    padding: 0.7em 1em;
    border-radius: 2em;
    background: rgb(255 255 255 / 90%);
    color: var(--black);
    font-size: 0.8em;

    .material-symbols-outlined {
      font-size: 1.3em;
    }
  }
}

.home-template-steps {
  h3 {
    margin: 0;
    font-size: 1em;
    font-weight: 550;
  }

  ol {
    display: flex;
    flex-direction: column;
    gap: 0.8em;
    list-style: none;
    margin: 1em 0 0;
    padding: 0;
  }

  li {
    display: flex;
    align-items: center;
    gap: 1em;
    font-size: 0.9em;
  }
}

.home-step-number {
  display: grid;
  place-items: center;
  width: 2em;
  height: 2em;
  flex-shrink: 0;
  border-radius: 50%;
  background: color-mix(in srgb, var(--text-primary) 8%, transparent);
  color: var(--text-muted);
  font-size: 0.8em;
}

#flow-page > .template-launch {
  position: absolute;
  bottom: 0;
  left: 0;
  z-index: 20;
}

.template-launch {
  display: flex;
  align-items: center;
  gap: 0.5em;
  padding: 0.33em 0.5em;

  background-color: var(--background-main);
  color: var(--text-primary);

  opacity: 0.8;

  .icon {
    font-size: 1em;
  }
  .text {
    font-size: 0.85em;
    opacity: 0.9;
  }

  &.template {
    background-color: var(--power-primary-color);
    color: var(--text-on-accent);
    opacity: 1;
  }
  &:hover {
    opacity: 1;
  }
}

.template-fields {
  min-width: 0;
  border: 0;
  padding: 0;
  margin: 0;
}

.template-input {
  display: block;
  width: 100%;
  min-width: 0;
  margin: 0;
  padding: 0.65em 0.8em;
  border: 1px solid var(--border-main-color);
  border-radius: 0.55em;
  background: linear-gradient(
    color-mix(in srgb, var(--text-primary) 3%, var(--home-surface)),
    color-mix(in srgb, var(--text-primary) 1%, var(--home-surface))
  );
  color: inherit;
  font: inherit;
  line-height: 1.5;
  text-align: inherit;
  user-select: text;
  resize: vertical;
  field-sizing: content;

  &:focus {
    border-color: var(--power-primary-color);
    box-shadow: 0 0 0 0.2em
      color-mix(in srgb, var(--power-primary-color) 10%, transparent);
  }
}

.template-editor {
  .home-template-description h2,
  .home-template-description > p {
    width: 100%;
  }

  h2 .template-input {
    padding: 0.3em 0.4em;
    border-radius: 0.3em;
    line-height: 1.15;
    resize: none;
  }

  .home-template-facts {
    > div {
      display: grid;
      grid-template-columns: 6em minmax(0, 1fr);
      align-items: center;
      gap: 0.75em;
      padding-block: 0.4em;
      border: 0;
    }

    dd {
      min-width: 0;
      text-align: left;
    }
  }
}

.template-multiline {
  min-height: 3lh;
}

.template-thumbnail {
  display: grid;
  place-items: center;
  border: 1px dashed var(--border-main-color);
  font-size: 0.9em;

  &.drag-over {
    border-color: var(--power-primary-color);
    outline: 2px solid var(--power-primary-color);
    outline-offset: 2px;
  }

  img {
    position: absolute;
    inset: 0;
  }

  &:has(img) {
    align-items: end;

    .template-image-actions {
      color: var(--white);
      background: linear-gradient(
        transparent,
        color-mix(in srgb, var(--black) 80%, transparent) 65%
      );
      padding: 2em 0.9em 0.8em;

      > span {
        flex-basis: auto;
        margin-inline-end: auto;
        text-align: left;
      }

      button {
        background: color-mix(in srgb, var(--white) 12%, transparent);

        &:hover {
          background: color-mix(in srgb, var(--white) 22%, transparent);
        }
      }
    }
  }
}

.template-image-actions,
.template-featured {
  display: flex;
  align-items: center;
  gap: 0.75em;
}

.template-image-actions {
  position: relative;
  width: 100%;
  justify-content: center;
  flex-wrap: wrap;
  padding: 1em;

  button {
    padding: 0.55em 0.75em;
    border-radius: 0.5em;
    color: inherit;
    font-size: 0.85em;
  }

  > span {
    flex-basis: 100%;
    text-align: center;
  }
}

.template-featured {
  font-size: 0.9em;

  input {
    width: 1.1em;
    height: 1.1em;
    margin: 0;
    accent-color: var(--power-primary-color);
  }
}

.template-editor-actions {
  display: flex;
  flex-direction: column;
  align-items: start;
  gap: 1em;
  margin-top: 0.5em;
  width: 100%;
}

.template-save-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1em;
  width: 100%;
  padding-top: 0.85em;
  border-top: 1px solid var(--border-subtle-color);
}

.template-delete {
  padding: 0.7em 0.8em;
  border-radius: 0.6em;
  color: var(--text-muted);

  &:hover,
  &:focus-visible {
    color: var(--text-primary);
    background: color-mix(in srgb, var(--text-primary) 5%, transparent);
  }
}

.template-editor-status {
  padding: 2em;
}

.home-handoff {
  position: fixed;
  z-index: 6000;
  left: var(--left);
  top: var(--top);
  width: var(--width);
  height: var(--height);
  box-shadow: 0 0.7em 4em rgb(0 0 0 / 12%);
  pointer-events: none;
  animation: home-to-sidebar 320ms cubic-bezier(0.3, 0, 0.15, 1) both;
}

.is-launching .prompt-composer {
  opacity: 0;
}

@keyframes home-to-sidebar {
  to {
    left: var(--target-left);
    top: var(--target-top);
    width: min(21em, 85vw);
    height: var(--target-height);
    border-radius: var(--grid-corners-radius);
    opacity: 0.6;
  }
}

@container platform-home (max-width: 70em) {
  .home-filter {
    flex-direction: column;
    align-items: start;
    gap: 0.5em;
  }
}

@container platform-home (max-width: 48em) {
  .home-template-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .prompt-drop-hint {
    display: none;
  }
}

@container platform-home (max-width: 30em) {
  .home-template-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .home-filter-group {
    width: 100%;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .home-compact-filters {
    order: 1;
  }

  .home-filter select {
    width: 100%;
    max-width: 100%;
    min-width: 0;
  }
}

@container template-preview (max-width: 50em) {
  .home-template-detail {
    grid-template-columns: minmax(0, 1fr);
  }
}

@media (hover: none) {
  .home-template-open {
    opacity: 1;
    transform: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  .home-handoff {
    animation: none;
    display: none;
  }

  .is-launching .prompt-composer {
    opacity: 1;
  }

  .home-template-card,
  .home-template-image img,
  .home-template-open,
  .home-tutorial img,
  .home-carousel-arrow,
  .home-carousel-pages button span {
    transition: none;
    transform: none;
  }
}
