/*
 * 記事ページ (resources/views/articles.html、 KIFG-227) の見た目。
 *
 * 記事ページは SPA の外にあり、 uix のテーマが CSS 変数を流し込まない。
 * そのため、ライトテーマの配色 (resources/ts/src/utils/theme.ts の
 * orangeColors と、紹介ページ pages/landing/page.ts の既定値) と同じ値を、
 * ここで同じ名前の変数として定義する。テーマの色を変えたら、ここもそろえる。
 *
 * reset.css は読まない。 SPA 向けに ul の黒丸や p の余白を消しているため、
 * 記事の本文 (.article-body) で全部戻すことになる。
 *
 * 本文は Skein が出す素の HTML (h2 ・ p ・ ul ・ pre ・ table ・ blockquote ・
 * img ・ MathML) で、 class はほぼ付かない。
 *
 * フォントは端末のものを使う (CSP の font-src が 'none' なので Web フォントは
 * 読めない)。
 */

:root {
	--uix-primary: #f97316;
	--uix-primary-dark: #ea580c;
	--uix-bg-default: #f5f6fa;
	--uix-bg-paper: #ffffff;
	--uix-text-primary: #1a1a1a;
	--uix-text-secondary: #666666;
	--uix-divider: #e5e5e5;
	/* 全体の幅。本文の列はサイドバー (280px) を除いた残り (約 800px) */
	--articles-width: 1160px;
	--articles-sidebar-width: 280px;
	--articles-header-height: 56px;
	/* 著者の写真が無いときの丸 (テーマの橙のグラデーション) */
	--articles-brand-gradient: linear-gradient(
		135deg,
		#fdba74 0%,
		#f97316 55%,
		#ea580c 100%
	);
	/* コードブロックの地と文字 (本文の白から浮かせる暗い色) */
	--articles-code-bg: #27221e;
	--articles-code-text: #f3ede6;
}

*,
*::before,
*::after {
	box-sizing: border-box;
}

body.articles {
	margin: 0;
	/* フッターを画面下部に寄せる（内容が短くてもビューポート下端へ）。 */
	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;
	background: var(--uix-bg-default);
	color: var(--uix-text-primary);
	-webkit-text-size-adjust: 100%;
	text-size-adjust: 100%;
}

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

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

/* ヘッダー */
.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-brand {
	display: flex;
	align-items: center;
	gap: 8px;
	font-weight: 700;
	text-decoration: none;
	color: var(--uix-text-primary) !important;
}

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

.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-narrow-only {
		display: none;
	}
}

@media (max-width: 999px) {
	/*
	 * .articles-side-author などの display: flex より後ろで負けないよう、
	 * body の class を足して強くする。
	 */
	.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;
	line-height: 1.4;
	margin: 0 0 8px;
}

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

.articles-lead {
	margin: 0;
}

/* 一覧 */
.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 a:hover {
	border-color: var(--uix-primary);
}

.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-empty {
	margin: 24px 0;
}

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

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

/*
 * 記事の見出し (タイトルと日付を本文の上に中央寄せで大きく出す)。本文の
 * 白いカードとは分け、ページの地の上に置く。
 */
.article-hero {
	padding: 48px 0 0;
	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-terms-center a {
	background: var(--uix-bg-paper);
	border: 1px solid var(--uix-divider);
}

/* 記事 */
.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;
	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,
.article-body ul,
.article-body ol {
	margin: 0 0 1.4em;
}

.article-body ul,
.article-body ol {
	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 a {
	text-underline-offset: 3px;
}

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

.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: 1px 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 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: var(--articles-code-bg);
	color: var(--articles-code-text);
	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: var(--articles-code-bg);
}

.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;
	line-height: 1.6;
	color: #bfb4a8;
}

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

.article-code-head button:hover {
	background: #3a332d;
}

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

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

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

.article-body blockquote > :last-child {
	margin-bottom: 0;
}

.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;
	line-height: 1.6;
	text-decoration: none;
	cursor: pointer;
}

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

/* hidden 属性は display を上書きされないよう明示する */
.article-share button[hidden] {
	display: none;
}

/* 著者 */
.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 {
	display: block;
	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: 700;
}

.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;
}

.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: 600;
	line-height: 1.55;
	text-decoration: none;
}

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

.article-adjacent span {
	display: block;
	font-size: 0.75rem;
	font-weight: 400;
	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-radius: 8px;
}

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

/* 見出しの階層は字下げで示すので、番号は付けない */
.article-toc-list {
	list-style: none;
	margin: 8px 0 0;
	padding: 0;
	font-size: 0.88rem;
	line-height: 1.6;
}

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

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

.article-toc-list a:hover {
	color: var(--uix-primary-dark);
	text-decoration: underline;
}

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

[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);
}

.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: 700;
}

.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-side-list a {
	color: var(--uix-text-primary);
	text-decoration: none;
}

.articles-side-list a:hover {
	color: var(--uix-primary-dark);
	text-decoration: underline;
}

/* サイドバーの著者 (記事のページ) */
.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: 700;
	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 p {
	margin: 0;
}

.articles-cta-title {
	font-size: 1.1rem;
	font-weight: 700;
	margin-bottom: 4px !important;
}

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

.articles-button:hover {
	background: var(--uix-primary-dark);
}

/* フッター (紹介ページの .lp-footer にそろえる) */
.articles-footer {
	padding: 26px 0 40px;
	font-size: 12px;
	color: var(--uix-text-secondary);
}

.articles-footer nav {
	display: flex;
	justify-content: center;
	align-items: center;
	flex-wrap: wrap;
	gap: 8px;
}

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

.articles-footer a:hover {
	text-decoration: underline;
}

/* 狭い画面 */
@media (max-width: 600px) {
	/* .articles-main の上下の余白を消さないよう、左右だけを詰める。 */
	.articles-container {
		padding-left: 14px;
		padding-right: 14px;
	}

	.article {
		padding: 24px 18px;
	}

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

	.article-author {
		padding: 20px;
	}

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