/* rin87.com のプロンプトの記事の索引（scripts/articles/lib/rin87-index.mjs が組むブログパーツ 608）と、トップの「新着記事」の見出しの見た目。
   正本はここ。子テーマの css/rin-index.css に置き、inc/rin-index.php がトップとタグの一覧のページでは <head> で読み込み、
   記事のページでは索引の直前に <style> で入れる。手順は scripts/articles/README.md の「プロンプトの記事の索引」。 */

/* トップの「新着記事」の見出し（front_top のウィジェットエリアの最後のカスタム HTML。SWELL の .c-secTitle）。
   索引からは離し（索引の見出しどうしの間より広く）、下の一覧には近づけて、見出しが一覧に付いて見えるようにする。
   見出しより下の余白は見出しの margin だけにする: .w-frontTop の下の余白（3em）を 0 にし、
   .p-homeContent の上の余白（.u-mt-40。margin-top: 4em !important）を 0 にする（!important でしか上書きできない） */
.c-secTitle[data-rin-index="list-head"] {
  margin-block: 3.5em 1em;
}

/* 索引の見出しの横の「新着記事へ ↓」の飛び先（SWELL の一覧 #post_list_tab_1。トップにもタグの一覧にもある）。
   スマホのヘッダーは画面の上に貼り付く（.l-header[data-spfix="1"] は position: sticky）ので、その高さと、
   一覧の上の見出し（トップでは「新着記事」）が隠れないだけ、飛び先の上を空ける */
.p-postListTabBody > .c-tabBody__item {
  scroll-margin-block-start: 7.5rem;
}

.w-frontTop:has([data-rin-index="list-head"]) {
  margin-block-end: 0;

  & + .p-homeContent {
    margin-block-start: 0 !important;
  }
}

/* ページ送りの 2 ページ目から後ろ（#body_wrap に WordPress の .paged が付く）。索引は出ず、代わりに 1 ページ目へ戻るリンク 1 行
   （子テーマの inc/rin-index.php）。一覧の続きを 1 画面目に出すため、索引の後ろに取っていた広い余白を詰める */
.rin-index-back {
  font-size: 0.9em;
}

.paged .c-secTitle[data-rin-index="list-head"] {
  margin-block-start: 1.5em;
}

/* 記事のページの最後（SWELL のウィジェットエリア after_related。.w-afterRelated）。ブログパーツ 608 はトップ用に、先頭に PC だけの余白
   （.wp-block-spacer。38px）、末尾に空の段落を持つ。記事の最後では出さず、関連記事の入れ物（.l-articleBottom__section）の余白だけにする */
.w-afterRelated .p-blogParts:has(.rin-index) {
  > .wp-block-spacer,
  > p:empty {
    display: none;
  }
}

/* プロンプトの記事の索引（題材の見出しと画像のタイル）。RIN Search のトップの .cat-grid / .cat-tile と同じ見せ方。
   SWELL の CSS は層（@layer）に入っていないので、ここを層に入れると SWELL の .post_content h2 などに負ける。
   層には入れず、:scope を付けて詳細度で上回る（.post_content h2 は 0,1,1）。 */
@scope (.rin-index) {
  :scope {
    container-type: inline-size;
    display: grid;
    gap: 1.75em;
  }

  .rin-index__sec {
    display: grid;
    gap: 0.75em;
  }

  /* 全体の見出しと、その横の「新着記事へ ↓」 */
  .rin-index__head {
    display: grid;
    grid-template-columns: 1fr auto;
    align-items: center;
    gap: 0.5em;
  }

  .rin-index__jump {
    padding-block: 0.5em;
    font-size: 0.8em;
    white-space: nowrap;
  }

  /* 全体の見出し「AIイラストのプロンプト集」は、トップの「新着記事」と同じ SWELL の .c-secTitle（左の線はサイトの設定の CSS）。
     本文の h2（.post_content h2。帯の背景・白い文字・余白・大きさ）が .c-secTitle に勝つので、打ち消して .c-secTitle の値に戻す。
     大きさは SWELL の home.css の .c-secTitle と同じ値（600px 未満は 4.5vw、以上は 20px） */
  :scope .rin-index__title {
    margin: 0;
    padding: 0 0.75em;
    border-radius: 0;
    background: none;
    color: inherit;
    font-size: 4.5vw;

    @media (width >= 600px) {
      font-size: 20px;
    }
  }

  /* カテゴリの見出し（h3）。SWELL の本文の h3（余白・斜線の疑似要素）を打ち消す */
  :scope .rin-index__h {
    margin: 0;
    padding: 0 0 0.25em;
    border-radius: 0;
    border-block-end: 2px solid var(--color_main);
    background: none;
    color: var(--color_main);
    font-size: 1.1em;
    line-height: 1.4;

    &::before,
    &::after {
      content: none;
    }
  }

  .rin-index__grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0.5rem;

    @container (width >= 30rem) {
      grid-template-columns: repeat(4, minmax(0, 1fr));
    }

    @container (width >= 42rem) {
      grid-template-columns: repeat(6, minmax(0, 1fr));
    }
  }

  :scope .rin-index__tile {
    display: grid;
    aspect-ratio: 1;
    overflow: clip;
    border: 1px solid var(--color_border);
    border-radius: 0.5rem;
    box-shadow: 0 1px 3px rgb(0 0 0 / 0.08);
    background: var(--color_gray, #f7f7f7);
    color: #fff;
    text-decoration: none;

    > * {
      grid-area: 1 / 1;
    }

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

    @media (hover: hover) and (pointer: fine) {
      &:hover .rin-index__label {
        text-decoration: underline;
      }

      /* ホバーで画像を少し拡大する（2026-12-02、オーナー）。大きさと速さは、子テーマのサイドバーとブログパーツのバナーのホバー
         （1.05 倍・0.3 秒）と同じ。はみ出す分は、タイルの overflow: clip が切る */
      &:hover .rin-index__img img {
        transform: scale(1.05);
      }
    }
  }

  /* 画像は span で包む。子テーマの「ブログパーツ・サイドバーのバナー」の規則
     （:is(#sidebar, .p-blogParts) a[href*="/"]:has(> img)。ID の詳細度で display: block にする）に当てないため */
  .rin-index__img {
    display: block;
    min-block-size: 0;
  }

  /* 縦長の画像（キャラタイプの作例など）は、顔が切れないよう上寄りで切り抜く */
  :scope .rin-index__img img {
    display: block;
    inline-size: 100%;
    block-size: 100%;
    object-fit: cover;
    object-position: 50% 25%;

    @media (prefers-reduced-motion: no-preference) {
      transition: transform 0.3s ease;
    }
  }

  /* 名前は省略せず、入りきらなければ折り返す（文字を大きくしている人にも末尾まで読めるように） */
  .rin-index__label {
    /* ホバーで transform の付いた画像は、重なりの順が位置指定の無い要素より前になる。名前を前に出す（グリッドの子なので z-index が効く） */
    z-index: 1;
    align-self: end;
    padding: 1.25em 0.5em 0.5em;
    background: linear-gradient(180deg, transparent, rgb(0 0 0 / 0.7));
    font-size: 0.8em;
    font-weight: 700;
    line-height: 1.25;
    text-shadow: 0 1px 2px rgb(0 0 0 / 0.5);
  }
}
