/*
Styles for custom shortcodes.

Mainroad integration (no theme edits required):
1) Preferred with Mainroad: add this to hugo.toml under [params].
   customCSS = ["css/custom.css", "css/jsm-shortcodes.css"]
2) If you use a layout-level head hook in future, include:
   <link rel="stylesheet" href="{{ "css/jsm-shortcodes.css" | relURL }}">
*/

/* Body photos are at most 800px wide; do not stretch smaller originals. */
.jsm-image {
  max-width: 800px;
  margin: 1.5rem auto;
}

/* Hero images keep their existing width, with the same gap as body photos. */
.jsm-hero-image {
  display: block;
  margin: 0 0 1.5rem;
}

.post__thumbnail,
.list__thumbnail {
  margin-bottom: 1.5rem;
}

.jsm-image a {
  display: block;
  line-height: 0;
}

.jsm-image__img {
  display: block;
  width: auto;
  max-width: 100%;
  height: auto;
  margin: 0 auto;
  border: 0;
}

.jsm-image__caption {
  margin-top: 0.55rem;
  font-size: 0.9rem;
  line-height: 1.4;
  color: #666;
  text-align: center;
}

.jsm-image--center,
.jsm-image--default,
.jsm-image--wide {
  text-align: center;
}

.jsm-image--left,
.jsm-image--right {
  text-align: center;
}

@media (min-width: 900px) {
  .jsm-image--left,
  .jsm-image--right {
    width: min(48%, 30rem);
    margin-top: 0.35rem;
    margin-bottom: 1rem;
  }

  .jsm-image--left {
    float: left;
    margin-right: 1.25rem;
  }

  .jsm-image--right {
    float: right;
    margin-left: 1.25rem;
  }

  .jsm-image--wide {
    width: 100%;
    max-width: 800px;
  }
}

.jsm-map {
  margin: 1.5rem 0;
}

.jsm-map__aspect {
  position: relative;
  width: 100%;
  overflow: hidden;
  border: 1px solid #ddd;
  border-radius: 0.35rem;
  background: #f7f7f7;
  aspect-ratio: 16 / 9;
}

.jsm-map__iframe {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  border: 0;
}

.jsm-map__caption {
  margin-top: 0.55rem;
  font-size: 0.9rem;
  line-height: 1.4;
  color: #666;
  text-align: center;
}

@supports not (aspect-ratio: 16 / 9) {
  .jsm-map__aspect {
    height: 0;
    padding-top: 56.25%;
  }
}

.jsm-related-posts {
  margin: 2rem 0 1rem;
  padding-top: 0.25rem;
}

.jsm-related-posts__heading {
  margin: 0 0 0.85rem;
}

.jsm-related-posts__list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.jsm-related-posts__item {
  display: flex;
  align-items: flex-start;
  gap: 0.9rem;
  margin: 0;
  padding: 0.75rem 0;
  border-top: 1px solid #e8e8e8;
}

.jsm-related-posts__item:last-child {
  border-bottom: 1px solid #e8e8e8;
}

.jsm-related-posts__thumb-link {
  display: block;
  flex: 0 0 160px;
  line-height: 0;
}

.jsm-related-posts__thumb {
  display: block;
  width: 160px;
  height: 100px;
  object-fit: cover;
  border-radius: 0.2rem;
}

.jsm-related-posts__thumb-placeholder {
  display: block;
  width: 160px;
  height: 100px;
  border-radius: 0.2rem;
  background: linear-gradient(135deg, #f2f2f2, #e4e4e4);
}

.jsm-related-posts__content {
  min-width: 0;
}

.jsm-related-posts__title {
  display: inline-block;
  margin: 0 0 0.25rem;
  font-size: 1.06rem;
  line-height: 1.35;
  font-weight: 600;
  text-decoration: none;
}

.jsm-related-posts__title:hover,
.jsm-related-posts__title:focus {
  text-decoration: underline;
}

.jsm-related-posts__excerpt {
  margin: 0;
  font-size: 0.92rem;
  line-height: 1.5;
  color: #666;
}

.jsm-related-posts__all {
  margin-top: 0.65rem;
  padding-top: 0.15rem;
}

.jsm-related-posts__all a {
  font-weight: 600;
}

@media (max-width: 680px) {
  .jsm-related-posts__item {
    gap: 0.7rem;
  }

  .jsm-related-posts__thumb-link {
    flex-basis: 118px;
  }

  .jsm-related-posts__thumb,
  .jsm-related-posts__thumb-placeholder {
    width: 118px;
    height: 74px;
  }
}

@media (max-width: 480px) {
  .jsm-related-posts__item {
    display: block;
  }

  .jsm-related-posts__thumb-link {
    margin-bottom: 0.45rem;
  }
}

/*
Migration table shortcode styles.
Wrapped output: <div class="jsm-table">...table html...</div>
*/
.jsm-table {
  overflow-x: auto;
  margin: 1rem 0;
}

.jsm-table table {
  width: 100%;
  border-collapse: collapse;
  min-width: 32rem;
}

.jsm-table caption {
  caption-side: top;
  text-align: left;
  margin-bottom: 0.45rem;
  font-weight: 600;
  color: #555;
}

.jsm-table th,
.jsm-table td {
  padding: 0.55rem 0.7rem;
  border: 1px solid #ddd;
  vertical-align: top;
}

.jsm-table thead th {
  background: #f4f4f4;
  font-weight: 700;
}

.jsm-table tbody tr:nth-child(even) {
  background: #fafafa;
}

/*
Story navigation:
- Top block appears directly under hero image on story pages.
- Bottom block contains next-part link, and intro page may list additional parts.
*/
.jsm-story-nav {
  margin: 1.1rem 0 1.35rem;
}

.jsm-story-nav__next {
  margin: 0;
}

.jsm-story-nav a {
  text-decoration: underline;
  text-underline-offset: 0.08em;
}

.jsm-story-nav__more {
  margin-top: 0.85rem;
}

.jsm-story-nav__more p {
  margin: 0.35rem 0;
}

.jsm-story-nav__more ul {
  margin: 0.35rem 0 0;
  padding-left: 1.25rem;
}

.jsm-story-nav__more li {
  margin: 0.2rem 0;
}

.jsm-embed {
  margin: 1.5rem 0;
}

.jsm-embed__aspect {
  position: relative;
  width: 100%;
  overflow: hidden;
  border: 1px solid #ddd;
  border-radius: 0.35rem;
  background: #111;
  aspect-ratio: 16 / 9;
}

.jsm-embed--4x3 .jsm-embed__aspect {
  aspect-ratio: 4 / 3;
}

.jsm-embed--1x1 .jsm-embed__aspect {
  aspect-ratio: 1 / 1;
}

.jsm-embed__iframe,
.jsm-embed__preview {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  border: 0;
}

.jsm-embed__preview {
  cursor: pointer;
  padding: 0;
  background-color: #000;
  background-position: center;
  background-repeat: no-repeat;
  background-size: cover;
}

.jsm-embed__preview::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(to bottom, rgba(0, 0, 0, 0.08), rgba(0, 0, 0, 0.36));
}

.jsm-embed__play {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 4.25rem;
  height: 3rem;
  transform: translate(-50%, -50%);
  border-radius: 0.7rem;
  background: rgba(0, 0, 0, 0.72);
  transition: transform 0.2s ease, background-color 0.2s ease;
}

.jsm-embed__play::before {
  content: "";
  position: absolute;
  left: 1.65rem;
  top: 0.8rem;
  border-style: solid;
  border-width: 0.7rem 0 0.7rem 1.2rem;
  border-color: transparent transparent transparent #fff;
}

.jsm-embed__preview:hover .jsm-embed__play,
.jsm-embed__preview:focus-visible .jsm-embed__play {
  transform: translate(-50%, -50%) scale(1.04);
  background: rgba(204, 24, 30, 0.9);
}

.jsm-embed__preview:focus-visible {
  outline: 2px solid #fff;
  outline-offset: -2px;
}

.jsm-embed__caption {
  margin-top: 0.55rem;
  font-size: 0.9rem;
  line-height: 1.4;
  color: #666;
  text-align: center;
}

@supports not (aspect-ratio: 16 / 9) {
  .jsm-embed__aspect {
    height: 0;
    padding-top: 56.25%;
  }

  .jsm-embed--4x3 .jsm-embed__aspect {
    padding-top: 75%;
  }

  .jsm-embed--1x1 .jsm-embed__aspect {
    padding-top: 100%;
  }
}
