/*
 * 記事ページ（ resources/views/articles.html ）の見た目。
 *
 * 記事ページは SPA の外にあり、 uix のテーマが CSS 変数を流し込まない。
 * そのため、 resources/ts/src/config/theme.ts の配色と同じ値を、ここで同じ
 * 名前の変数として定義する（ reset.css もこれを参照する）。テーマの色を
 * 変えたら、ここもそろえること。
 *
 * 本文（ .article-body ）は Skein が出す素の HTML （ h2 ・ p ・ ul ・ pre ・
 * table ・ blockquote ・ img ・ MathML ）で、 class はほぼ付かない。
 */

:root {
	--uix-primary: #2e7d32;
	--uix-bg-default: #f1f8f2;
	--uix-bg-paper: #ffffff;
	--uix-text-primary: #1b2e1c;
	--uix-text-secondary: #3d5c3e;
	--uix-divider: #c8e6c9;
	/* 著者のアイコンが無いときの丸（ランディングの緑の濃淡にそろえる） */
	--articles-brand-gradient: linear-gradient(
		135deg,
		#66bb6a 0%,
		#2e7d32 55%,
		#00695c 100%
	);
	/* 全体の幅。本文の列はサイドバー（ 280px ）を除いた残り（約 800px ） */
	--articles-width: 1160px;
	--articles-sidebar-width: 280px;
	--articles-header-height: 56px;
}

body.articles {
	/* フッターを画面下部に寄せる（内容が短くてもビューポート下端へ）。 */
	display: flex;
	flex-direction: column;
	min-height: 100vh;
	min-height: 100dvh;
	font-family: system-ui, -apple-system, "Hiragino Sans", "Noto Sans JP",
		sans-serif;
	line-height: 1.8;
	touch-action: auto;
}

.articles a {
	color: var(--uix-primary);
}

.articles-container {
	max-width: var(--articles-width);
	margin: 0 auto;
	padding: 0 20px;
}

/* ヘッダー（ランディングページの .lp-header にそろえる） */
.articles-header {
	position: sticky;
	top: 0;
	z-index: 1;
	background: var(--uix-bg-paper);
	border-bottom: 1px solid var(--uix-divider);
}

.articles-header-inner {
	display: flex;
	align-items: center;
	justify-content: space-between;
	height: var(--articles-header-height);
}

.articles-logo img {
	display: block;
	height: 32px;
	width: auto;
}

.articles-nav {
	display: flex;
	gap: 20px;
	font-size: 0.9rem;
}

.articles-nav a {
	text-decoration: none;
}

/*
 * 本文とサイドバーの枠（伸びしろを持たせ、フッターを下端へ押し出す）。
 * 広い画面では 2 列、狭い画面ではサイドバーを本文の下に置く。
 */
.articles-layout {
	flex: 1 0 auto;
	display: grid;
	grid-template-columns: minmax(0, 1fr);
	gap: 32px;
	width: 100%;
	padding-top: 32px;
	padding-bottom: 48px;
}

@media (min-width: 1000px) {
	.articles-layout {
		grid-template-columns: minmax(0, 1fr) var(--articles-sidebar-width);
		gap: 40px;
	}

	/* サイドバーは画面に追従させ、長ければサイドバーの中だけ送る */
	.articles-sidebar {
		position: sticky;
		top: calc(var(--articles-header-height) + 24px);
		align-self: start;
		max-height: calc(100vh - var(--articles-header-height) - 48px);
		overflow-y: auto;
	}

	.articles .articles-narrow-only {
		display: none;
	}
}

/*
 * 狭い画面で隠すもの。 .articles-side-author などの display の指定より後に
 * 書かれていても勝つよう、 body の class を付けて強くしておく。
 */
@media (max-width: 999px) {
	.articles .articles-wide-only {
		display: none;
	}

	/* 中身が広い画面専用だけ（記事の著者と目次）なら、空の枠と余白も消す */
	.articles-sidebar:not(:has(> :not(.articles-wide-only))) {
		display: none;
	}
}

/* 目次の飛び先が固定ヘッダーの下に隠れないようにする */
.article-body :is(h1, h2, h3) {
	scroll-margin-top: calc(var(--articles-header-height) + 16px);
}

/* 分類・月別の一覧の上に出す、記事一覧への道しるべ */
.articles-crumb {
	margin: 0 0 4px;
	font-size: 0.85rem;
	color: var(--uix-text-secondary);
}

.articles-crumb span {
	margin: 0 6px;
}

.articles-heading {
	font-size: 1.6rem;
	margin: 0 0 8px;
}

.articles-lead,
.articles-excerpt,
.article-meta {
	color: var(--uix-text-secondary);
}

/* 一覧 */
.articles-list {
	list-style: none;
	margin: 24px 0;
	padding: 0;
}

.articles-item a {
	display: block;
	padding: 16px 20px;
	margin-bottom: 12px;
	background: var(--uix-bg-paper);
	border: 1px solid var(--uix-divider);
	border-radius: 12px;
	color: inherit;
	text-decoration: none;
}

.articles-item h2 {
	font-size: 1.15rem;
	margin: 0 0 4px;
	color: var(--uix-text-primary);
}

.articles-excerpt {
	margin: 0 0 4px;
	font-size: 0.9rem;
}

.articles-item-meta {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: 6px 10px;
	margin: 0;
	font-size: 0.8rem;
	color: var(--uix-text-secondary);
}

/* 一覧の分類は飾り（カード全体が 1 つのリンクなので、ここはリンクにしない） */
.articles-item-meta span {
	padding: 0 10px;
	border-radius: 999px;
	background: var(--uix-bg-default);
}

.articles-pager {
	display: flex;
	justify-content: space-between;
	margin: 24px 0;
}

.articles-back {
	margin: 32px 0;
}

/*
 * 記事の見出し（タイトルと日付を、本文の上に中央寄せで大きく出す）。
 * 本文の白いカードとは分け、ページの地の上に置く。
 */
.article-hero {
	padding: 48px 0 8px;
	text-align: center;
}

.article-title {
	max-width: 880px;
	margin: 0 auto 14px;
	font-size: clamp(1.55rem, 3.6vw, 2.2rem);
	line-height: 1.45;
	letter-spacing: 0.01em;
}

.article-meta {
	display: flex;
	flex-wrap: wrap;
	justify-content: center;
	gap: 6px 16px;
	font-size: 0.85rem;
	margin: 0;
}

.article-terms-center {
	justify-content: center;
}

/* 記事 */
.article {
	background: var(--uix-bg-paper);
	border: 1px solid var(--uix-divider);
	border-radius: 12px;
	padding: 40px 48px;
}

.article-terms {
	display: flex;
	flex-wrap: wrap;
	gap: 8px;
	list-style: none;
	padding: 0;
	margin: 12px 0 0;
}

.article-terms a {
	display: inline-block;
	padding: 2px 10px;
	border-radius: 999px;
	/* 見出しではページの地の上に置くので、枠線で形を見せる */
	border: 1px solid var(--uix-divider);
	background: var(--uix-bg-default);
	font-size: 0.8rem;
	text-decoration: none;
}

/* 本文。長文を読む前提で、行間と段落の間を広めに取る */
.article-body {
	font-size: 1.0625rem;
	line-height: 1.9;
	letter-spacing: 0.01em;
	overflow-wrap: anywhere;
}

.article-body > :first-child {
	margin-top: 0;
}

.article-body p {
	margin: 0 0 1.4em;
}

.article-body h1,
.article-body h2 {
	font-size: 1.5rem;
	line-height: 1.5;
	margin: 2.4em 0 0.8em;
	padding-bottom: 0.35em;
	border-bottom: 2px solid var(--uix-divider);
}

.article-body h3 {
	font-size: 1.25rem;
	line-height: 1.5;
	margin: 2em 0 0.6em;
}

.article-body h4 {
	font-size: 1.08rem;
	margin: 1.6em 0 0.5em;
}

.article-body a {
	text-decoration: underline;
	text-underline-offset: 3px;
}

.article-body hr {
	margin: 2.5em 0;
	border: none;
	border-top: 1px solid var(--uix-divider);
}

/* reset.css が消した箇条書きの印を、本文の中だけ戻す */
.article-body ul,
.article-body ol {
	margin: 0 0 1.4em;
	padding-left: 1.6em;
}

.article-body li {
	margin: 0.3em 0;
}

.article-body li > ul,
.article-body li > ol {
	margin: 0.3em 0 0;
}

.article-body ul {
	list-style: disc;
}

.article-body ol {
	list-style: decimal;
}

.article-body img {
	display: block;
	max-width: 100%;
	height: auto;
	margin: 1.6em auto;
	border-radius: 8px;
}

/*
 * コード。 public/articles/articles.js が pre を .article-code で包み、
 * 言語名とコピーボタンの帯（ .article-code-head ）を足す。スクリプトが
 * 無くても pre だけで読める。地はテーマの緑を落とした暗い色にする。
 */
.article-body pre {
	overflow-x: auto;
	margin: 0 0 1.4em;
	padding: 16px 20px;
	background: #1c2b1e;
	color: #e8f1e9;
	border-radius: 10px;
	font-size: 0.88rem;
	line-height: 1.7;
	letter-spacing: 0;
	tab-size: 4;
}

.article-code {
	margin: 0 0 1.4em;
	border-radius: 10px;
	overflow: hidden;
	background: #1c2b1e;
}

.article-code pre {
	margin: 0;
	border-radius: 0;
	padding-top: 6px;
}

.article-code-head {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 8px;
	padding: 6px 10px 0 20px;
	font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
	font-size: 0.75rem;
	color: #a5bfa7;
}

.article-code-head button {
	padding: 2px 10px;
	border: 1px solid #3a5a3d;
	border-radius: 6px;
	background: transparent;
	color: #c8dcca;
	font: inherit;
	cursor: pointer;
}

.article-code-head button:hover {
	background: #2a3f2c;
}

.article-body code {
	font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

.article-body :not(pre) > code {
	padding: 0.15em 0.4em;
	background: #e8f3e9;
	color: #1f4a22;
	border-radius: 5px;
	font-size: 0.88em;
}

.article-body blockquote {
	margin: 1.2em 0;
	padding: 0.2em 1em;
	border-left: 4px solid var(--uix-divider);
	color: var(--uix-text-secondary);
}

.article-body table {
	display: block;
	overflow-x: auto;
	border-collapse: collapse;
	margin: 1.6em 0;
	font-size: 0.95rem;
}

.article-body th {
	background: var(--uix-bg-default);
}

.article-body th,
.article-body td {
	padding: 6px 12px;
	border: 1px solid var(--uix-divider);
}

.article-body math[display="block"] {
	overflow-x: auto;
	margin: 1em 0;
}

.article-raw {
	white-space: pre-wrap;
	font-family: inherit;
}

/* 本文のあと: 分類と共有 */
.article-foot {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	justify-content: space-between;
	gap: 16px;
	margin-top: 48px;
	padding-top: 24px;
	border-top: 1px solid var(--uix-divider);
}

.article-foot .article-terms {
	margin: 0;
}

.article-share {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: 8px;
	font-size: 0.85rem;
	color: var(--uix-text-secondary);
}

.article-share a,
.article-share button {
	padding: 4px 14px;
	border: 1px solid var(--uix-divider);
	border-radius: 999px;
	background: var(--uix-bg-paper);
	color: var(--uix-text-primary);
	font: inherit;
	text-decoration: none;
	cursor: pointer;
}

.article-share a:hover,
.article-share button:hover {
	border-color: var(--uix-primary);
	color: var(--uix-primary);
}

/* 著者 */
.article-author {
	display: flex;
	gap: 18px;
	margin-top: 24px;
	padding: 24px 28px;
	background: var(--uix-bg-paper);
	border: 1px solid var(--uix-divider);
	border-radius: 12px;
}

/* アイコンが無いときは空の丸（名前の頭文字は切り出さない） */
.article-author-avatar,
.articles-side-author img,
.articles-side-author span {
	flex: none;
	width: 64px;
	height: 64px;
	border-radius: 50%;
	object-fit: cover;
	background: var(--articles-brand-gradient);
}

.article-author p {
	margin: 0;
}

.article-author-label {
	font-size: 0.75rem;
	color: var(--uix-text-secondary);
}

.article-author-name {
	font-weight: bold;
}

.article-author-bio {
	margin-top: 4px !important;
	font-size: 0.9rem;
	color: var(--uix-text-secondary);
	white-space: pre-line;
}

.article-author-link {
	font-size: 0.85rem;
	overflow-wrap: anywhere;
}

/* 前後の記事 */
.article-adjacent {
	display: grid;
	grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
	gap: 12px;
	margin-top: 24px;
}

.articles .article-adjacent a {
	display: block;
	padding: 14px 18px;
	background: var(--uix-bg-paper);
	border: 1px solid var(--uix-divider);
	border-radius: 12px;
	color: var(--uix-text-primary);
	font-weight: bold;
	line-height: 1.55;
	text-decoration: none;
}

.articles .article-adjacent a:hover {
	border-color: var(--uix-primary);
}

.article-adjacent span {
	display: block;
	font-size: 0.75rem;
	font-weight: normal;
	color: var(--uix-text-secondary);
}

.article-adjacent-older {
	text-align: right;
	grid-column: -2;
}

/* 関連する記事 */
.article-related {
	margin-top: 40px;
}

.article-related h2 {
	font-size: 1.1rem;
	margin: 0 0 12px;
}

.articles-list-compact {
	margin: 0;
}

.articles-list-compact .articles-item a {
	padding: 14px 18px;
	margin-bottom: 10px;
}

.articles-list-compact h3 {
	font-size: 1rem;
	line-height: 1.55;
	margin: 0 0 2px;
	color: var(--uix-text-primary);
}

/* 目次（狭い画面では本文の上に折りたたみで、広い画面ではサイドバーに出す） */
details.article-toc {
	margin: 0 0 28px;
	padding: 10px 16px;
	background: var(--uix-bg-default);
	border: 1px solid var(--uix-divider);
	border-radius: 12px;
}

details.article-toc summary {
	cursor: pointer;
	font-weight: bold;
}

.article-toc-list {
	margin: 8px 0 0;
	font-size: 0.88rem;
	line-height: 1.6;
}

.article-toc-list li {
	margin: 4px 0;
}

.articles .article-toc-list a {
	color: var(--uix-text-secondary);
	text-decoration: none;
}

.articles .article-toc-list a:hover {
	color: var(--uix-primary);
}

/* 読んでいる見出し（ public/articles/articles.js が付ける） */
.articles .article-toc-list a.is-active {
	color: var(--uix-primary);
	font-weight: bold;
}

[data-toc] .article-toc-list {
	border-left: 2px solid var(--uix-divider);
}

[data-toc] .article-toc-list li {
	margin: 0;
	padding-top: 3px;
	padding-bottom: 3px;
}

[data-toc] .article-toc-list a {
	display: block;
	margin-left: -2px;
	padding-left: 12px;
	border-left: 2px solid transparent;
}

[data-toc] .article-toc-list a.is-active {
	border-left-color: var(--uix-primary);
}

/* 字下げは padding で付ける（ li の margin の指定に打ち消されないように） */
.article-toc-level-2 {
	padding-left: 1em;
}

.article-toc-level-3 {
	padding-left: 2em;
}

/* サイドバー */
.articles-sidebar {
	display: flex;
	flex-direction: column;
	gap: 16px;
}

.articles-side-box {
	padding: 16px 18px;
	background: var(--uix-bg-paper);
	border: 1px solid var(--uix-divider);
	border-radius: 12px;
}

.articles-side-title {
	margin: 0 0 8px;
	font-size: 0.9rem;
	font-weight: bold;
}

.articles-side-list {
	list-style: none;
	margin: 0;
	padding: 0;
	font-size: 0.88rem;
	line-height: 1.6;
}

.articles-side-list li {
	display: flex;
	justify-content: space-between;
	gap: 8px;
	padding: 5px 0;
	border-top: 1px solid var(--uix-divider);
}

.articles-side-list li:first-child {
	border-top: none;
}

.articles-sidebar .articles-side-list a {
	color: var(--uix-text-primary);
	text-decoration: none;
}

.articles-sidebar .articles-side-list a:hover {
	color: var(--uix-primary);
}

/* サイドバーの著者（記事のページ） */
.articles-side-author {
	display: flex;
	align-items: center;
	gap: 12px;
}

.articles-side-author img,
.articles-side-author span {
	width: 40px;
	height: 40px;
}

.articles-side-author p {
	margin: 0;
	font-weight: bold;
	font-size: 0.95rem;
}

.articles-feed {
	margin: 0;
	padding: 0 4px;
	font-size: 0.85rem;
}

.articles-count {
	flex: none;
	margin-left: 4px;
	font-size: 0.75rem;
	color: var(--uix-text-secondary);
}

/* アプリへの案内 */
.articles-cta {
	margin-top: 40px;
	padding: 24px;
	text-align: center;
	background: var(--uix-bg-paper);
	border: 1px solid var(--uix-divider);
	border-radius: 12px;
}

.articles-cta-title {
	font-size: 1.1rem;
	font-weight: bold;
	margin: 0 0 4px;
}

.articles-button {
	display: inline-block;
	margin-top: 12px;
	padding: 10px 24px;
	border-radius: 999px;
	background: var(--uix-primary);
	color: #ffffff !important;
	text-decoration: none;
}

/* フッター（ランディングページのフッターにそろえる） */
.articles-footer {
	padding: 32px 0;
	text-align: center;
	font-size: 0.8rem;
	color: var(--uix-text-secondary);
	background: var(--uix-bg-paper);
	border-top: 1px solid var(--uix-divider);
}

.articles-footer-logo {
	/* reset.css で img はブロックになるので、中央へは margin で寄せる */
	display: block;
	height: 28px;
	width: auto;
	margin: 0 auto;
}

.articles-footer nav {
	display: flex;
	justify-content: center;
	flex-wrap: wrap;
	gap: 16px;
	margin: 8px 0;
}

/* 狭い画面では、本文のカードの余白と著者の枠を詰める */
@media (max-width: 599px) {
	.article {
		padding: 24px 18px;
	}

	.article-hero {
		padding-top: 32px;
	}

	.article-author {
		padding: 20px;
	}

	.article-adjacent-older {
		grid-column: auto;
	}
}

/* ------------------------------------------------------------------ *
 * 一覧カードのアイキャッチ（サムネイル）と記事のアイキャッチ（ヒーロー画像）。
 * 画像の無い記事でもカードが崩れないよう、空きはサイトマークで埋める。
 * ------------------------------------------------------------------ */
.articles-list {
	display: grid;
	grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
	gap: 18px;
	margin: 24px 0;
}
.articles-item { margin: 0; }
.articles-item a {
	display: flex;
	flex-direction: column;
	height: 100%;
	padding: 0;
	margin: 0;
	overflow: hidden;
	background: var(--uix-background-paper);
	border: 1px solid var(--uix-divider);
	border-radius: 14px;
	color: inherit;
	transition: border-color 0.18s ease, box-shadow 0.18s ease, transform 0.18s ease;
}
.articles-item a:hover {
	border-color: var(--uix-primary);
	box-shadow: 0 8px 24px rgba(0, 0, 0, 0.08);
	transform: translateY(-2px);
}
.articles-item-thumb {
	display: block;
	aspect-ratio: 16 / 9;
	overflow: hidden;
	background: var(--uix-background-default);
}
.articles-item-thumb img { display: block; width: 100%; height: 100%; object-fit: cover; }
.articles-item-thumb-empty { display: flex; align-items: center; justify-content: center; }
.articles-item-thumb-empty img { width: 48px; height: 48px; object-fit: contain; opacity: 0.3; }
.articles-item-text {
	display: flex;
	flex-direction: column;
	gap: 6px;
	padding: 14px 16px 16px;
	flex: 1;
}
.articles-item-text .articles-item-meta { margin-top: auto; }
.articles-list-compact {
	grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
	gap: 14px;
}
.articles-list-compact .articles-item-thumb { aspect-ratio: 16 / 10; }
.article-eyecatch { margin: 12px 0 0; }
.article-eyecatch img {
	display: block;
	width: 100%;
	max-height: 460px;
	object-fit: cover;
	border-radius: 16px;
}
