/**
 * 記事本文の基本デザイン（どのデザインを選んでも共通の部分）。
 *
 * 公開画面（.wp-block-post-content）とエディタ（.is-root-container）の両方に
 * 効かせる。クラシックエディタで書かれた既存記事にも効くよう、
 * クラス名ではなくタグで指定する。
 *
 * 見出しとリストのデザインは、設定（LastShot →「記事」）で選んだものだけを
 * 別のファイルで読み込む（content-heading-*.css と content-list-*.css）。
 *
 * 目次やシェアボタンなど LastShot の部品も本文の中に入るので、
 * リストはクラス名に lastshot- の付いていないものだけを対象にする。
 *
 * :where() で囲んでいるのは、子テーマや記事ごとの指定が勝てるようにするため。
 * WordPress 本体の CSS（.wp-block-separator など）に勝つ必要があるところだけ、
 * :where() を使わずにクラスで指定している。
 */

/* --- 見出しと段落の間 ------------------------------------------------- */

/*
 * 見出しのすぐ下は、ブロックの間隔（1.5rem）より狭くして、
 * 見出しと本文のまとまりを分かりやすくする。
 */
.wp-block-post-content :where(h2, h3, h4, h5, h6) + *,
.is-root-container :where(h2, h3, h4, h5, h6) + * {
	margin-block-start: 0.7em;
}

/* --- 文字 ------------------------------------------------------------- */

/*
 * 太字は太さだけで示し、色は変えない（本文と同じ色のまま）。
 * 色を付けるとリンクと見分けにくく、太字の多い記事で画面がうるさくなるため。
 */
:where(.wp-block-post-content, .is-root-container) :where(strong, b) {
	font-weight: 700;
}

/*
 * マーカー。
 *
 * 下 38％だけをマーカーの色で塗って、蛍光ペンで引いたように見せる。
 * 上 62％は本文の背景色で塗りつぶすので、書き手がハイライトで選んだ色に
 * 関係なく、いつも同じ見た目になる（決まり1章）。
 *
 * 効くのは2つ。どちらも <mark> なので、この1か所で見た目が決まる。
 *
 * - ツールバーの「マーカー」ボタン（`mark.lastshot-marker`。1回で付く）
 * - WordPress 標準の「ハイライト」（色を選びたいときに使う）
 */
:where(.wp-block-post-content, .is-root-container) mark {
	padding: 0 0.1em;
	background-color: transparent;
	background-image: linear-gradient(
		var(--lastshot-paper, #fff) 62%,
		var(--lastshot-marker, #fde68a) 62%
	);
	color: inherit;
	/* 複数行にまたがっても、行ごとに同じ見た目にする。 */
	-webkit-box-decoration-break: clone;
	box-decoration-break: clone;
}

/* 本文のリンク。下線を文字から少し離して読みやすくする。 */
:where(.wp-block-post-content, .is-root-container) a:where(:not(.wp-element-button)) {
	text-decoration-thickness: 1px;
	text-underline-offset: 0.18em;
}

/* --- リスト（共通の余白。印の形は content-list-*.css） ---------------- */

:where(.wp-block-post-content, .is-root-container) :where(ul, ol):not([class*="lastshot-"]) {
	padding-left: 1.6em;
	line-height: 1.85;
}

:where(.wp-block-post-content, .is-root-container) :where(ul, ol):not([class*="lastshot-"]) > li {
	margin-block: 0.4em;
}

/* 入れ子のリストは、親の項目に少しだけ近づける。 */
:where(.wp-block-post-content, .is-root-container)
	:where(ul, ol):not([class*="lastshot-"])
	:where(ul, ol):not([class*="lastshot-"]) {
	margin-block: 0.4em 0;
}

/*
 * 中身が空のリストの行は、まるごと出さない（0.11.6 の直し）。
 *
 * 0.11.5 までは、中身が空の行（<li></li> や <li><br></li>）にも
 * リストの印が付いていた。保険HAPPY の記事では、見出しのすぐ上に
 * 小さな四角が1つだけ出ていた（「小さな四角」の印が、空の行に付いていた）。
 *
 * display: none にすると、
 *
 * - 印（li::before）も、ブラウザの印（list-style）も出ない
 * - 行の高さも取らない
 * - 箱を作らないので、番号つきリストの番号も数えない
 *   （見える行が 1・2・3… と続き、番号がずれない）
 *
 * の3つが同時に片付く。記事のデータは書き換えない（見た目だけ直す）。
 *
 * エディタ（.is-root-container）には当てない。書いている人が Enter を
 * 押して作った空の行が消えると、そこに文字を打てなくなるため。
 *
 * 空白だけの行（<li>&nbsp;</li> など）は、CSS では見分けられないので
 * ここでは直せない（文字が入っている行と区別する方法がない）。
 */
.wp-block-post-content :where(ul, ol):not([class*="lastshot-"]) > li:empty {
	display: none;
}

/*
 * <br> だけの行・空の段落だけの行（クラシックエディタで書かれた記事に多い）。
 *
 * :has() を知らない古いブラウザのために、上の :empty とは別の指定にする。
 * まとめて書くと、1つでも分からない書き方があると、ひとまとめで
 * 捨てられてしまうため。
 */
.wp-block-post-content :where(ul, ol):not([class*="lastshot-"]) > li:has(> br:only-child),
.wp-block-post-content :where(ul, ol):not([class*="lastshot-"]) > li:has(> p:empty:only-child),
.wp-block-post-content :where(ul, ol):not([class*="lastshot-"]) > li:has(> p:only-child > br:only-child) {
	display: none;
}

/* --- 引用 ------------------------------------------------------------- */

/*
 * ブロックの引用（.wp-block-quote）は theme.json で指定している。
 * ここはクラシックエディタで書かれた引用に、同じ見た目をそろえる。
 */
:where(.wp-block-post-content, .is-root-container) blockquote:not(.wp-block-quote) {
	margin-inline: 0;
	padding: 0 0 0 var(--wp--preset--spacing--30);
	border-left: 4px solid var(--lastshot-line-strong, #d5d9df);
	background-color: transparent;
	color: var(--lastshot-muted, #5b6270);
}

:where(.wp-block-post-content, .is-root-container) blockquote > :where(p, cite):first-child {
	margin-block-start: 0;
}

/* --- 画像のキャプション ----------------------------------------------- */

/* 文字の色と大きさは theme.json（キャプション）で指定している。 */
:where(.wp-block-post-content, .is-root-container) figcaption {
	text-align: center;
	line-height: 1.7;
}

/* --- 区切り線 --------------------------------------------------------- */

/*
 * WordPress 本体の .wp-block-separator（幅 100px の短い線）に勝つ必要が
 * あるので、ここだけ :where() を使わずにクラスで指定する。
 * 点線のスタイル（is-style-dots）は本体のままにする。
 */
.wp-block-post-content hr,
.is-root-container hr {
	margin-block: var(--wp--preset--spacing--50);
	border-top: 1px solid var(--lastshot-line, #e3e5e8);
	border-bottom: 0;
}

.wp-block-post-content hr.wp-block-separator:not(.is-style-dots),
.is-root-container hr.wp-block-separator:not(.is-style-dots) {
	width: 100%;
	max-width: 100%;
}

/* --- 表 --------------------------------------------------------------- */

/**
 * 本文の表。
 *
 * 横スクロールは、表そのものではなく外側の箱でさせる（表の display を
 * 変えると、セルの並びや罫線が崩れるため）。
 *
 * - ブロックの表：figure.wp-block-table が箱になる
 * - クラシックエディタで書いた表：表示するときに div.lastshot-table-scroll で
 *   包む（functions.php の lastshot_wrap_tables()。記事データは書き換えない）
 */

:where(.wp-block-post-content, .is-root-container) .lastshot-table-scroll,
:where(.wp-block-post-content, .is-root-container) .wp-block-table {
	max-width: 100%;
	overflow-x: auto;
	-webkit-overflow-scrolling: touch;
}

/*
 * 表は本文の幅いっぱいに広げる。入りきらないときだけ、外側の箱が横スクロールする。
 * ブロックの表は WordPress 本体が width: 100% にしているので、クラシックの表と
 * 見た目をそろえるために、ここでも 100% にする。
 */
:where(.wp-block-post-content, .is-root-container) table {
	border-collapse: collapse;
	width: 100%;
	margin: 0;
	line-height: 1.6;
}

/*
 * エディタでは、クラシックの表に div.lastshot-table-scroll が付かない
 * （記事データを書き換えないため）。代わりにクラシックブロックを箱にして、
 * 公開画面と同じように横スクロールさせる。
 */
.is-root-container .wp-block-freeform {
	overflow-x: auto;
}

:where(.wp-block-post-content, .is-root-container) .lastshot-table-scroll {
	margin-bottom: var(--wp--preset--spacing--40);
}

:where(.wp-block-post-content, .is-root-container) th,
:where(.wp-block-post-content, .is-root-container) td {
	padding: 0.5rem 0.75rem;
	border: 1px solid var(--lastshot-line, #e3e5e8);
	text-align: left;
	vertical-align: top;
}

/*
 * 見出しのセルは、下にメイン色の 2px の線を引く（決まり8章）。
 * 背景はうすいメイン色。
 */
:where(.wp-block-post-content, .is-root-container) th,
:where(.wp-block-post-content, .is-root-container) thead td {
	background-color: var(--lastshot-main-soft, #f2f5f9);
	font-weight: 700;
}

:where(.wp-block-post-content, .is-root-container) thead th,
:where(.wp-block-post-content, .is-root-container) thead td {
	border-bottom: 2px solid var(--lastshot-main, #12355b);
	color: var(--lastshot-main, #12355b);
}

/* 1行おきに薄い背景。 */
:where(.wp-block-post-content, .is-root-container) tbody tr:nth-child(even) td {
	background-color: var(--lastshot-info-soft, #f5f6f8);
}

/* 表のすぐ外側にある figure の余白を打ち消さない。 */
:where(.wp-block-post-content, .is-root-container) .wp-block-table {
	margin-bottom: var(--wp--preset--spacing--40);
}

@media (max-width: 599px) {
	:where(.wp-block-post-content, .is-root-container) table {
		font-size: 0.8125rem;
	}

	/*
	 * セルに最小の幅を決めておくと、列の多い表は画面に入りきらず、
	 * 外側の箱が横スクロールになる（列がつぶれて読めなくなるのを防ぐ）。
	 * 列の少ない表は、この幅より広がって画面いっぱいになる。
	 */
	:where(.wp-block-post-content, .is-root-container) th,
	:where(.wp-block-post-content, .is-root-container) td {
		min-width: 6em;
		padding: 0.4rem 0.5rem;
	}
}

/* --- スマホ ----------------------------------------------------------- */

@media (max-width: 599px) {

	/* 画面が狭いぶん、行の間を少しだけ広げて読みやすくする。 */
	:where(.wp-block-post-content, .is-root-container) p {
		line-height: 1.95;
	}

	:where(.wp-block-post-content, .is-root-container) :where(ul, ol):not([class*="lastshot-"]) {
		padding-left: 1.4em;
		line-height: 1.9;
	}
}
