/* ===========================================================
   Templates: the /templates index and each template page (src/pages/template.tsx,
   src/pages/templates-index.tsx, src/components/templates.tsx).
   Loaded only on those pages, on top of the inlined site stylesheet, through Layout's
   `stylesheets` prop. Uses the site's tokens throughout, so it follows light and dark mode
   with no rules of its own for either.
   =========================================================== */

/* ---------- The example clip ---------- */

.template-clip {
  margin: 0;
}

.template-clip-frame {
  position: relative;
  aspect-ratio: 16 / 9;
  border-radius: var(--radius-lg);
  overflow: hidden;
  background: var(--surface-sunken);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
}

/* Shorts are 9:16, shown in a portrait frame no wider than a phone. */
.template-clip-vertical {
  max-width: 340px;
  margin-inline: auto;
}

.template-clip-vertical .template-clip-frame {
  aspect-ratio: 9 / 16;
}

.template-clip-frame img,
.template-clip-frame video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* The poster <img> paints first; the video sits over it and shows its own poster until it plays. */
.template-clip-frame video {
  background: transparent;
}

.template-clip-toggle {
  position: absolute;
  right: 0.75rem;
  bottom: 0.75rem;
  display: grid;
  place-items: center;
  width: 2.5rem;
  height: 2.5rem;
  border: 0;
  border-radius: 999px;
  background: rgba(10, 14, 23, 0.6);
  color: #fff;
  cursor: pointer;
}

.template-clip-toggle:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
}

.template-clip-toggle .icon {
  width: 16px;
  height: 16px;
}

.template-clip-toggle .template-clip-play,
.template-clip-toggle.is-paused .template-clip-pause {
  display: none;
}

.template-clip-toggle.is-paused .template-clip-play {
  display: inline-flex;
}

.template-clip figcaption {
  margin-top: 0.6rem;
  font-size: 0.85rem;
  color: var(--text-faint);
  text-align: center;
}

/* ---------- Template page ---------- */

/* A vertical clip needs less of the row, so the copy gets more of it. */
@media (min-width: 941px) {
  .template-hero-vertical .hero-grid {
    grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr);
  }
}

/* Wide screens: the hero gets a wider container than the rest of the page, and a landscape clip
   takes most of the row (about 680px at 1280 wide, 720px at 1440), so the example reads at a size
   people can judge. A Short stays a phone-shaped frame, as tall as the window allows and no more. */
@media (min-width: 1100px) {
  .template-hero .wrap {
    max-width: 1360px;
  }

  .template-hero:not(.template-hero-vertical) .hero-grid {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1.4fr);
  }

  .template-hero-vertical .template-clip-vertical {
    max-width: clamp(320px, calc((100vh - 15rem) * 9 / 16), 420px);
    max-width: clamp(320px, calc((100svh - 15rem) * 9 / 16), 420px);
  }
}

.template-hero-note {
  margin: 1rem 0 0;
  font-size: 0.88rem;
  color: var(--text-muted);
}

.template-two-col {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr);
  gap: clamp(2rem, 5vw, 4.5rem);
  align-items: start;
}

@media (max-width: 860px) {
  .template-two-col {
    grid-template-columns: 1fr;
  }
}

.template-two-col h2,
.template-narrow h2 {
  font-size: clamp(1.45rem, 2.4vw, 1.9rem);
  margin-bottom: 0.75rem;
}

.template-two-col p {
  font-size: 1.04rem;
  line-height: 1.7;
  margin: 0 0 2rem;
}

.template-narrow {
  max-width: calc(46rem + 3rem);
}

.template-narrow > p {
  color: var(--text-muted);
  margin-bottom: 1.5rem;
}

/* What the template sets up: label and value, one row each. */
.template-settings {
  margin: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
}

.template-settings > div {
  display: grid;
  grid-template-columns: 8.5rem minmax(0, 1fr);
  gap: 1rem;
  padding: 0.8rem 1.1rem;
  border-bottom: 1px solid var(--border);
}

.template-settings > div:last-child {
  border-bottom: 0;
}

.template-settings dt {
  font-weight: 600;
  font-size: 0.92rem;
}

.template-settings dd {
  margin: 0;
  font-size: 0.95rem;
  color: var(--text-muted);
}

@media (max-width: 420px) {
  .template-settings > div {
    grid-template-columns: 1fr;
    gap: 0.15rem;
  }
}

.template-two-col .template-settings-note {
  margin-top: 0.75rem;
  font-size: 0.9rem;
  color: var(--text-muted);
}

/* The example opening: a timecode, then the line and what's on screen. */
.template-example {
  list-style: none;
  margin: 0;
  padding: 0;
  border-left: 2px solid var(--border-strong);
}

.template-example li {
  display: grid;
  grid-template-columns: 3.5rem minmax(0, 1fr);
  gap: 0.75rem;
  padding: 0 0 1.4rem 1.1rem;
}

.template-example li:last-child {
  padding-bottom: 0;
}

.template-example p {
  margin: 0;
}

.template-example-time {
  font-variant-numeric: tabular-nums;
  font-size: 0.85rem;
  color: var(--text-faint);
  padding-top: 0.15rem;
}

.template-example-line {
  font-family: var(--font-display);
  font-size: 1.12rem;
  line-height: 1.5;
}

.template-example-picture {
  margin-top: 0.3rem !important;
  font-size: 0.92rem;
  color: var(--text-muted);
}

.template-example-kind {
  font-weight: 600;
}

/* How to start: three numbered steps down the column. */
.template-steps {
  list-style: none;
  counter-reset: template-step;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 1.5rem;
}

.template-steps li {
  counter-increment: template-step;
  position: relative;
  padding-left: 3rem;
}

.template-steps li::before {
  content: counter(template-step);
  position: absolute;
  left: 0;
  top: 0;
  display: grid;
  place-items: center;
  width: 2rem;
  height: 2rem;
  border-radius: 999px;
  background: var(--primary-soft);
  color: var(--primary);
  font-weight: 650;
}

.template-steps h3 {
  margin-bottom: 0.35rem;
  font-size: 1.1rem;
}

.template-steps p {
  margin: 0;
  color: var(--text-muted);
}

.template-related-links {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 1rem 2rem;
  margin-top: 2rem;
}

.template-related-links p {
  margin: 0;
  font-weight: 600;
}

.template-usecase {
  display: flex;
  align-items: center;
  gap: 0.9rem;
  max-width: 34rem;
  padding: 1rem 1.2rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  color: var(--text);
  text-decoration: none;
}

.template-usecase:hover {
  border-color: color-mix(in srgb, var(--primary) 30%, var(--border));
}

.template-usecase > span {
  display: grid;
  gap: 0.15rem;
  font-size: 0.92rem;
}

.template-usecase > span > span {
  color: var(--text-muted);
}

.template-usecase > .icon {
  flex: none;
  width: 18px;
  height: 18px;
  color: var(--primary);
}

/* ---------- Template cards (index and related) ---------- */

.template-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1.5rem 1.25rem;
}

/* Shorts: portrait posters, four to a row. */
.template-grid-vertical {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

@media (max-width: 900px) {
  .template-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 620px) {
  .template-grid {
    grid-template-columns: 1fr;
  }

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

.template-card {
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
}

.template-card-poster {
  display: block;
  border-radius: var(--radius-lg);
  overflow: hidden;
  border: 1px solid var(--border);
  background: var(--surface-sunken);
}

.template-card-poster img {
  width: 100%;
  height: auto;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  transition: transform 0.25s ease;
}

.template-card-vertical .template-card-poster img {
  aspect-ratio: 9 / 16;
}

.template-card:hover .template-card-poster img {
  transform: scale(1.03);
}

.template-card-body h2,
.template-card-body h3 {
  font-family: var(--font-sans);
  font-size: 1.1rem;
  font-weight: 650;
  margin: 0 0 0.2rem;
}

.template-card-body h2 a,
.template-card-body h3 a {
  color: var(--text);
  text-decoration: none;
}

.template-card-body h2 a:hover,
.template-card-body h3 a:hover {
  text-decoration: underline;
}

.template-card-body p {
  margin: 0;
  font-size: 0.93rem;
  color: var(--text-muted);
}

.template-card-body .template-card-keyword {
  font-size: 0.85rem;
  color: var(--text-faint);
  margin-bottom: 0.4rem;
}

.template-card-start {
  margin-top: 0.6rem !important;
}

.template-card-start a {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-weight: 600;
  font-size: 0.9rem;
  text-decoration: none;
}

.template-card-start a:hover {
  text-decoration: underline;
}

.template-card-start .icon {
  width: 15px;
  height: 15px;
}

/* ---------- The /templates index ---------- */

.templates-head {
  padding: clamp(2rem, 5vw, 3.5rem) 0 1rem;
}

.templates-head h1 {
  font-size: clamp(2rem, 4.2vw, 3rem);
  max-width: 22ch;
}

.templates-lede {
  font-size: 1.2rem;
  line-height: 1.55;
  max-width: 44rem;
  color: var(--text);
}

.templates-sub {
  max-width: 44rem;
  color: var(--text-muted);
}

.templates-group {
  padding-block: clamp(1.75rem, 4vw, 2.75rem);
}

.templates-group-head {
  margin-bottom: 1.25rem;
}

.templates-group-head h2 {
  font-size: clamp(1.45rem, 2.6vw, 1.9rem);
  margin-bottom: 0.3rem;
}

.templates-group-head p {
  margin: 0;
  color: var(--text-muted);
  max-width: 44rem;
}

/* Related templates sit in one row of landscape frames, so a Short's poster is cropped to fit. */
.template-grid-related .template-card-vertical .template-card-poster img {
  aspect-ratio: 16 / 9;
}
