/*
 * 本文表示用スタイル
 *
 * App\Services\Html\PostBodySanitizer でサニタイズ済みの HTML
 * （p, h2, h3, ul, ol, li, br, hr, strong, b, em, i, u, s, a）を表示するための共通クラス。
 * ストーリー本文・ポートフォリオの本文系フィールドの両方の詳細画面で使う想定
 * （組み込みは S05 / S13）。呼び出し側は `<div class="post-body">{!! $safeHtml !!}</div>`
 * のように、本文コンテナへこのクラスを付与する。
 *
 * SunEditor が出力しサニタイザーを通過した HTML は固定の要素セットで、
 * 個々の要素へクラスを追加する余地がない（要素にクラスを付けるとサニタイザーの
 * allowlist で属性ごと落ちる）。そのため本文コンテナ配下をタグセレクタで装飾する
 * 構成を取る。プロジェクト CLAUDE.md「No parent-child selectors in CSS」に対する
 * 例外規定（インライン要素のタグセレクタは可）は h2/p/ul/ol のような block 要素を
 * 明示的にはカバーしていないが、同種の制約が既に .announcement-detail__content
 * （src/public/css/announcements.css）で採用されており、今回もサニタイズ済み HTML の
 * 表示という同一の事情のため同じ構成を踏襲する。判断根拠は作業記録 § 6 を参照。
 *
 * `.sun-editor-editable` は本文エディタ（SunEditor, public/js/utils/post-editor.js）の
 * 編集領域が iframe 内で持つクラス。このファイルを iframe 内にも読み込ませて
 * （iframe_cssFileName オプション）編集時の見た目を公開ページに揃えるため、
 * 各ルールを `.post-body` と同時に適用する。`var(--fontcolor)` は iframe 内では
 * 定義元の app.css を読み込まないため解決できず、フォールバック値が必須。
 */
.post-body,
.sun-editor-editable {
    font-size: 16px;
    line-height: 2;
    color: var(--fontcolor, #1e1420);
    word-break: break-word;
}

.post-body p,
.sun-editor-editable p {
    font-size: 16px;
    line-height: 2;
    margin-bottom: 32px;
}

.post-body p:last-child,
.sun-editor-editable p:last-child {
    margin-bottom: 0;
}

.post-body h2,
.sun-editor-editable h2 {
    font-size: 24px;
    font-weight: 600;
    margin-bottom: 20px;
    color: var(--fontcolor, #1e1420);
}

.post-body h3,
.sun-editor-editable h3 {
    font-size: 20px;
    font-weight: 600;
    margin-bottom: 20px;
    color: var(--fontcolor, #1e1420);
}

.post-body ul,
.post-body ol,
.sun-editor-editable ul,
.sun-editor-editable ol {
    margin-bottom: 20px;
    padding-left: 25px;
}

.post-body li,
.sun-editor-editable li {
    margin-bottom: 4px;
    font-size: 16px;
    line-height: 1.6;
}

.post-body hr,
.sun-editor-editable hr {
    margin: 30px 0;
    border: none;
    border-top: 1px solid #e0e0e0;
}

.post-body a,
.sun-editor-editable a {
    color: #0066cc;
    text-decoration: underline;
}

.post-body a:hover,
.sun-editor-editable a:hover {
    text-decoration: none;
}

/*
 * インライン画像（ストーリー本文限定。spec 20260829-01、独自ダイアログ化は spec 20260904-02）。
 *
 * 保存後（.post-body）のHTMLは「画像 → 直後の <p data-image-caption>」という2つの隣接ブロック
 * （OGPリンクカードと同じ平坦な形。post-editor.js の getImagePlugin() 参照）。画像は `src` が
 * user_images ライブラリのパスであることを表す属性セレクタ、キャプションは data-image-caption の
 * 属性セレクタで対象要素自身を指定する。編集領域（.sun-editor-editable）では post-editor.js が
 * 付け直す専用クラスを対象にする（OGPカードと同じ使い分け）。
 */
.post-body img[src^="/storage/user_images/"],
.sun-editor-editable .post-editor-image__img {
    display: block;
    max-width: 100%;
    height: auto;
    border-radius: 8px;
}

.post-body p[data-image-caption],
.sun-editor-editable .post-editor-image__caption {
    margin-top: 6px;
    font-size: 15px;
    line-height: 1.6;
    text-align: center;
}

/*
 * OGPリンクカード（ストーリー本文限定「OGPリンクカード挿入」機能。現在の名称は「埋め込み」）。
 *
 * ストーリーの「関連するPortfolio」と同じ形式（サムネイルを左、タイトルを右に並べる横長のカード。
 * link-card.css）で表示する。
 *
 * 保存後のHTMLは「画像 → 直後の <p data-ogp-card><a>...</a></p>」という2つの隣接ブロックで、
 * このままでは横並びのカードを組めない。そのため公開ページ・プレビューでは
 * App\Services\Html\PostBodyLinkCardRenderer が表示の直前に `<a class="link-card post-body__link-card">`
 * へ組み替える。見た目は link-card.css が担い、ここでは本文中に置くための差分だけを指定する
 * （`.post-body a` の文字色・下線を打ち消す。詳細度を上回るためクラスを 2 つ重ねる）。
 *
 * 編集領域（.sun-editor-editable）は保存後とDOM構造が異なる。SunEditor の
 * ogpCard プラグイン（post-editor.js）がカードをブロックコンポーネント化するため、
 * 画像・本文（<p>）は同じ `<figure>`（`<div class="se-component post-editor-ogp-card">`
 * の中）に同居し、かつ挿入・保存済みHTMLからの再構築のどちらの経路でも各要素へ
 * `.post-editor-ogp-card__figure` / `__image` 等の専用クラスを付ける（post-editor.js の
 * wrapOgpCardComponent() / buildOgpCardImageElement() / buildOgpCardBodyElement() / retainFormat() 参照）。
 * このクラスはSunEditorが毎回付け直すもので保存時には残らない。編集領域の iframe は link-card.css を
 * 読み込まないため、link-card.css と同じ値をここで指定する。
 */
.link-card.post-body__link-card {
    color: inherit;
    text-decoration: none;
    margin-bottom: 32px;
}

.link-card.post-body__link-card:last-child {
    margin-bottom: 0;
}

.sun-editor-editable .post-editor-ogp-card__figure {
    /* 外側のコンポーネント（SunEditor の se-component）が flex コンテナのため、幅を指定しないと
       内容の幅まで縮む（画像の無いカードで顕著） */
    width: 100%;
    display: flex;
    align-items: center;
    gap: 12px;
    border: solid 1px #dddce1;
    border-radius: 5px;
}

.sun-editor-editable .post-editor-ogp-card__image {
    display: block;
    flex: 0 0 160px;
    width: 160px;
    aspect-ratio: 16 / 9;
    object-fit: cover;
    /* object-fit: cover ではみ出した部分の切り取りを明示する。編集領域では SunEditor 本体の
       CSS が `figure img` へ position: relative / z-index: 0 を当てて画像を位置指定要素に
       するため、Chromium が object-fit のはみ出しを既定のボックス（width×aspect-ratio）で
       切り取らず、元画像の縦横比のまま（1500x1500 の画像なら 398x398）画像を描画してしまう。
       画像は位置指定要素として通常フローのテキストより手前に描画されるため、カード上下の
       段落やカード自身のタイトル・説明文が画像に覆い隠される（実機検証で判明。公開ページ側
       （.post-body）は位置指定されないため発生しない）。 */
    overflow: hidden;
    background: #e8e8e8;
    border-top-left-radius: 4px;
    border-bottom-left-radius: 4px;
}

.sun-editor-editable .post-editor-ogp-card__body {
    flex: 1 1 auto;
    min-width: 0;
    margin: 0;
    padding-right: 12px;
}

/* テキストのみのカード（画像なし）は、公開ページと同じく左に空のサムネイル枠を描く */
.sun-editor-editable .post-editor-ogp-card__body:first-child {
    display: flex;
    align-items: center;
    min-height: 90px;
    padding-left: 172px;
    background: linear-gradient(#e8e8e8, #e8e8e8) left center / 160px 90px no-repeat;
}

.sun-editor-editable .post-editor-ogp-card__link {
    /* 説明文（<br> の後のテキストノード）はクラスを付けられないため、リンク全体を
       4 行（タイトル＋説明文）で省略する。公開ページはタイトル・説明文をそれぞれ 2 行で省略する
       （link-card.css）ため行の配分は異なることがあるが、90px のサムネイルに収まる高さは揃う */
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 4;
    line-clamp: 4;
    overflow: hidden;
    overflow-wrap: anywhere;
    /* SunEditor 自身の基本CSS（suneditor.min.css）が編集領域内の a へ
       white-space: nowrap を当てており、上書きしないと説明文が折り返さず
       カード外へはみ出す（実機検証で判明） */
    white-space: normal;
    font-size: 12px;
    line-height: 1.4;
    color: #6b7280;
    text-decoration: none;
}

.sun-editor-editable .post-editor-ogp-card__link:hover {
    /* 編集領域では SunEditor 本体の `.sun-editor-editable a:hover` が
       通常時のルールより詳細度が高く、ホバー中だけ説明文が青くなるため色を指定し直す */
    color: #6b7280;
    text-decoration: none;
}

.sun-editor-editable .post-editor-ogp-card__title {
    font-size: 13px;
    font-weight: normal;
    line-height: 1.3;
    color: var(--fontcolor, #1e1420);
}

/*
 * YouTube 動画の埋め込み（ストーリー本文限定「埋め込み」機能。spec 20260904-03）。
 *
 * 保存後（.post-body）のHTMLは単独の `<iframe>`（PostBodySanitizer が src を YouTube の埋め込み URL に
 * 限定し属性を固定値で組み立て直す）。本文中の iframe はこの機能でしか生成されないため、
 * `.post-body a` などと同じくタグセレクタで装飾する。
 *
 * 編集領域（.sun-editor-editable）では iframe ではなくサムネイル画像のプレースホルダー
 * （`.post-editor-embed-video__thumb`。post-editor.js の buildEmbedVideoPlaceholder() 参照）を
 * 同じ 16:9 の枠で表示し、コンテナ（`.post-editor-embed-video`）の ::after で再生アイコンを重ねて
 * 画像ではなく動画であることを示す。SunEditor 本体の CSS が figure::after に透明なオーバーレイ
 * （z-index: 10）を置くため、アイコンはその下に描いてもよい（クリックはオーバーレイが受ける）。
 *
 * 16:9 の枠に幅いっぱいで収める。高さは aspect-ratio で決めるため width/height 属性を持たなくてよい。
 */
.post-body iframe,
.sun-editor-editable .post-editor-embed-video__thumb {
    display: block;
    width: 100%;
    max-width: 640px;
    aspect-ratio: 16 / 9;
    object-fit: cover;
    /* object-fit: cover ではみ出した部分の切り取りを明示する。編集領域では SunEditor 本体の CSS が
       `figure img` を位置指定要素にするため、Chromium が object-fit のはみ出しを既定のボックス
       （width×aspect-ratio）で切り取らず、サムネイル（480×360 の 4:3）が元の縦横比のまま描画されて
       前後の段落を覆い隠す（OGP カード画像 `.post-editor-ogp-card__image` と同じ現象。実機検証で判明）。
       公開ページ側の iframe には影響しない。 */
    overflow: hidden;
    border: none;
    border-radius: 12px;
    background: #f3f4f6;
    margin-top: 4px;
}
.post-body iframe{
    margin-bottom: 32px;
}
.sun-editor-editable .post-editor-embed-video {
    position: relative;
    max-width: 640px;
}

.sun-editor-editable .post-editor-embed-video::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 64px;
    height: 64px;
    transform: translate(-50%, -50%);
    background: url(../images/icons/play-circle.svg) center / contain no-repeat;
    pointer-events: none;
    z-index: 1;
}

@media (max-width: 768px) {
    .post-body,
    .sun-editor-editable {
        font-size: 13px;
    }

    .post-body iframe,
    .sun-editor-editable .post-editor-embed-video__thumb {
        border-radius: 8px;
    }
    .post-body iframe{
        margin-bottom: 24px;
    }
    .sun-editor-editable .post-editor-embed-video::after {
        width: 48px;
        height: 48px;
    }

    .post-body h2,
    .sun-editor-editable h2 {
        font-size: 20px;
    }

    .post-body h3,
    .sun-editor-editable h3 {
        font-size: 18px;
    }
}
