/* ==========================================================================
   巡考道 - ブログ用スタイル

   配色・幅は :root のカスタムプロパティに集約してある。
   雰囲気を変えたいときは基本ここだけを触ればよい。
   ========================================================================== */

/* --- デザイントークン ---------------------------------------------------- */

:root {
  color-scheme: light dark;

  --bg: #ffffff;
  --bg-subtle: #f6f7f9;
  --surface: #ffffff;
  --text: #1f2328;
  --text-muted: #6b7280;
  --border: #e5e7eb;
  --border-strong: #d1d5db;
  --accent: #2f6f9f;
  --accent-hover: #1f5480;
  --accent-subtle: #eef4f9;
  --code-bg: #f4f5f7;

  --content-width: 760px; /* 記事本文の幅 */
  --wide-width: 1120px; /* サイドバー付き一覧の幅 */
  --side-width: 260px;
  --radius: 8px;

  /* 日本語を含む本文向けのフォントスタック */
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "Hiragino Sans",
    "Hiragino Kaku Gothic ProN", "Noto Sans JP", Meiryo, sans-serif;
  --font-mono: "SFMono-Regular", "Consolas", "Liberation Mono", Menlo,
    "Noto Sans Mono CJK JP", monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14171a;
    --bg-subtle: #1b1f23;
    --surface: #1b1f23;
    --text: #e4e6e8;
    --text-muted: #949aa3;
    --border: #2c3238;
    --border-strong: #3a424a;
    --accent: #7fb3d9;
    --accent-hover: #a3cbe8;
    --accent-subtle: #1e2a34;
    --code-bg: #22272c;
  }
}

/* --- ベース -------------------------------------------------------------- */

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  /* 日本語は行間を広めに取ったほうが読みやすい */
  line-height: 1.9;
  letter-spacing: 0.02em;
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover {
  color: var(--accent-hover);
  text-decoration: underline;
}

img {
  max-width: 100%;
  height: auto;
}

.container {
  max-width: var(--content-width);
  margin: 0 auto;
  padding: 0 1.25rem;
}

/* --- 2カラムレイアウト --------------------------------------------------- */
/* 一覧ページのみサイドバーを出す。記事本文は読みやすさ優先で1カラムのまま */

.layout {
  max-width: var(--wide-width);
  display: grid;
  grid-template-columns: minmax(0, 1fr) var(--side-width);
  gap: 3.5rem;
  align-items: start;
}

.layout-side {
  position: sticky;
  top: 84px;
  font-size: 0.875rem;
}

@media (max-width: 900px) {
  .layout {
    grid-template-columns: 1fr;
    gap: 2.5rem;
  }

  .layout-side {
    position: static;
  }
}

/* --- ヘッダー ------------------------------------------------------------ */

.site-header {
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  position: sticky;
  top: 0;
  z-index: 10;
}

.site-header-inner {
  max-width: var(--wide-width);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  min-height: 62px;
}

.site-title {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: 0.12em;
  white-space: nowrap;
}

.site-title-heading {
  margin: 0;
  font-size: inherit;
  line-height: inherit;
}

.site-title:hover {
  color: var(--accent);
  text-decoration: none;
}

.site-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 1.4rem;
  font-size: 0.875rem;
}

.site-nav a {
  color: var(--text-muted);
}

.site-nav a:hover {
  color: var(--accent);
  text-decoration: none;
}

/* --- メイン -------------------------------------------------------------- */

main {
  padding-top: 2.5rem;
  padding-bottom: 4rem;
  min-height: 60vh;
}

/* --- ページ見出し -------------------------------------------------------- */

.page-head {
  margin-bottom: 2rem;
  padding-bottom: 1.25rem;
  border-bottom: 1px solid var(--border);
}

.page-eyebrow {
  margin: 0 0 0.25rem;
  font-size: 0.75rem;
  letter-spacing: 0.14em;
  color: var(--text-muted);
}

.page-head h1 {
  margin: 0;
  font-size: 1.5rem;
  line-height: 1.5;
  letter-spacing: 0.06em;
}

.page-lead {
  margin: 0.5rem 0 0;
  font-size: 0.9rem;
  color: var(--text-muted);
}

.empty {
  color: var(--text-muted);
  padding: 3rem 0;
  text-align: center;
}

/* --- 記事カード ---------------------------------------------------------- */

.card-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.card {
  display: grid;
  grid-template-columns: 200px minmax(0, 1fr);
  gap: 1.5rem;
  padding: 1.75rem 0;
  border-bottom: 1px solid var(--border);
}

.card:first-child {
  padding-top: 0;
}

.card-thumb {
  display: block;
  aspect-ratio: 2 / 1;
  overflow: hidden;
  border-radius: var(--radius);
  background: var(--bg-subtle);
  border: 1px solid var(--border);
}

.card-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: transform 0.25s ease;
}

.card:hover .card-thumb img {
  transform: scale(1.04);
}

/* サムネイル未設定の記事でもカードの形が崩れないようにする */
.card-thumb-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  font-size: 0.8rem;
  letter-spacing: 0.16em;
  color: var(--text-muted);
  opacity: 0.55;
}

.card-body {
  min-width: 0;
}

.card-date {
  display: block;
  font-size: 0.775rem;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.06em;
}

.card-title {
  margin: 0.3rem 0 0.5rem;
  font-size: 1.15rem;
  line-height: 1.6;
}

.card-title a {
  color: var(--text);
}

.card-title a:hover {
  color: var(--accent);
  text-decoration: none;
}

.card-excerpt {
  margin: 0;
  font-size: 0.9rem;
  line-height: 1.8;
  color: var(--text-muted);
  /* 抜粋は3行で打ち切り、カードの高さを揃える */
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.card-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin: 0.85rem 0 0;
}

@media (max-width: 640px) {
  .card {
    grid-template-columns: 1fr;
    gap: 0.9rem;
  }
}

/* --- ページネーション ---------------------------------------------------- */

.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-top: 2.5rem;
  font-size: 0.875rem;
}

.page-numbers {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.page-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 2.1rem;
  height: 2.1rem;
  padding: 0 0.6rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.page-link:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-subtle);
  text-decoration: none;
}

.page-link.is-current {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 700;
}

/* 前へ/次へは端に着いたら押せないことが見て分かるようにする */
.page-link.is-disabled {
  opacity: 0.35;
  border-style: dashed;
}

.page-gap {
  color: var(--text-muted);
  padding: 0 0.15rem;
}

@media (max-width: 640px) {
  .pagination {
    flex-wrap: wrap;
    justify-content: center;
  }

  .page-numbers {
    order: -1;
    width: 100%;
    justify-content: center;
    margin-bottom: 0.5rem;
  }
}

/* --- タグ ---------------------------------------------------------------- */

.tag {
  display: inline-block;
  padding: 0.05rem 0.65rem;
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  font-size: 0.75rem;
  line-height: 1.8;
  color: var(--text-muted);
  white-space: nowrap;
}

.tag:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-subtle);
  text-decoration: none;
}

/* --- サイドバーのウィジェット -------------------------------------------- */

.widget {
  margin-bottom: 2.25rem;
}

.widget-title {
  margin: 0 0 0.9rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  color: var(--text-muted);
}

.widget-avatar {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  object-fit: cover;
  margin-bottom: 0.5rem;
}

.widget-bio {
  margin: 0;
  line-height: 1.8;
  color: var(--text-muted);
}

.widget-author {
  margin: 0.5rem 0 0;
  font-weight: 700;
  font-size: 0.85rem;
}

.widget-links {
  list-style: none;
  margin: 0;
  padding: 0;
}

.widget-links li {
  padding: 0.25rem 0;
}

.tag-cloud {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  margin: 0;
}

.tag-count {
  margin-left: 0.4rem;
  font-size: 0.7rem;
  opacity: 0.7;
  font-variant-numeric: tabular-nums;
}

/* --- 記事ヘッダー -------------------------------------------------------- */

.post-header {
  margin-bottom: 2rem;
  padding-bottom: 1.25rem;
  border-bottom: 1px solid var(--border);
}

.post-header h1 {
  font-size: 1.8rem;
  line-height: 1.55;
  margin: 0 0 0.85rem;
}

.post-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  margin: 0;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.post-meta time {
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.06em;
}

/* --- 目次 ---------------------------------------------------------------- */

.toc {
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem 1.5rem;
  margin: 2rem 0 2.5rem;
  font-size: 0.9rem;
}

.toc-title {
  margin: 0 0 0.5rem;
  font-weight: 700;
  font-size: 0.8rem;
  letter-spacing: 0.14em;
  color: var(--text-muted);
}

.toc ul {
  list-style: none;
  margin: 0;
  padding: 0;
}

.toc li {
  line-height: 1.85;
}

.toc li a {
  color: var(--text);
}

.toc li a:hover {
  color: var(--accent);
}

.toc-depth-3 {
  padding-left: 1.25rem;
  font-size: 0.85rem;
}

.toc-depth-3 a {
  color: var(--text-muted);
}

/* --- 本文 ---------------------------------------------------------------- */

.post-body {
  overflow-wrap: break-word;
}

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

.post-body h2 {
  font-size: 1.35rem;
  line-height: 1.6;
  margin: 3rem 0 1.25rem;
  padding-bottom: 0.5rem;
  border-bottom: 2px solid var(--border);
}

.post-body h3 {
  font-size: 1.1rem;
  line-height: 1.6;
  margin: 2.25rem 0 1rem;
  padding-left: 0.7rem;
  border-left: 3px solid var(--accent);
}

.post-body h4 {
  font-size: 1rem;
  margin: 2rem 0 0.75rem;
}

.post-body p {
  margin: 1.4rem 0;
}

.post-body a {
  text-decoration: underline;
  text-underline-offset: 0.2em;
  text-decoration-thickness: 1px;
}

.post-body ul,
.post-body ol {
  margin: 1.4rem 0;
  padding-left: 1.6rem;
}

.post-body li {
  margin: 0.4rem 0;
}

.post-body li::marker {
  color: var(--text-muted);
}

.post-body blockquote {
  margin: 1.75rem 0;
  padding: 0.25rem 0 0.25rem 1.25rem;
  border-left: 3px solid var(--border-strong);
  color: var(--text-muted);
}

.post-body blockquote p {
  margin: 0.6rem 0;
}

.post-body hr {
  border: 0;
  border-top: 1px solid var(--border);
  margin: 3rem 0;
}

.post-body img {
  display: block;
  border-radius: var(--radius);
  margin: 1.75rem auto;
}

/* 幅の広い表がページ全体を横スクロールさせないよう、表の中だけでスクロールさせる */
.post-body table {
  display: block;
  overflow-x: auto;
  width: 100%;
  border-collapse: collapse;
  margin: 1.75rem 0;
  font-size: 0.9rem;
}

.post-body th,
.post-body td {
  border: 1px solid var(--border);
  padding: 0.5rem 0.85rem;
  text-align: left;
}

.post-body th {
  background: var(--bg-subtle);
  font-weight: 700;
  white-space: nowrap;
}

/* 画像のキャプション (生HTMLで <figure> を書いた場合) */
.post-body figure {
  margin: 1.75rem 0;
}

.post-body figure img {
  margin: 0 auto;
}

.post-body figcaption {
  margin-top: 0.6rem;
  text-align: center;
  font-size: 0.825rem;
  color: var(--text-muted);
}

/* タスクリスト */
.post-body .contains-task-list {
  list-style: none;
  padding-left: 0.25rem;
}

.post-body .task-list-item input {
  margin-right: 0.5rem;
  accent-color: var(--accent);
}

/* 脚注 */
.post-body .footnotes {
  margin-top: 3rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--border);
  font-size: 0.875rem;
  color: var(--text-muted);
}

.post-body .footnotes h2 {
  font-size: 0.8rem;
  letter-spacing: 0.14em;
  border: 0;
  margin: 0 0 0.5rem;
  padding: 0;
}

.post-body del {
  color: var(--text-muted);
}

/* --- コード -------------------------------------------------------------- */

code {
  font-family: var(--font-mono);
  font-size: 0.875em;
}

/* インラインコードのみ。shikiのブロック内はハイライト色を優先する */
.post-body :not(pre) > code {
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.1em 0.35em;
  letter-spacing: 0;
}

pre {
  padding: 1.1rem 1.25rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  overflow-x: auto;
  line-height: 1.7;
  font-size: 0.875rem;
  margin: 1.75rem 0;
  letter-spacing: 0;
}

pre code {
  font-size: inherit;
}

/* --- アフィリエイト枠 ---------------------------------------------------- */

.affiliate-box {
  display: flex;
  gap: 1.1rem;
  align-items: flex-start;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.1rem;
  margin: 2rem 0;
}

.affiliate-box img {
  width: 96px;
  height: 96px;
  object-fit: cover;
  border-radius: 6px;
  flex-shrink: 0;
  margin: 0;
}

.affiliate-box-body {
  flex: 1;
  min-width: 0;
}

.affiliate-box-title {
  margin: 0 0 0.35rem;
  font-weight: 700;
  line-height: 1.6;
}

.affiliate-box-note {
  margin: 0 0 0.75rem;
  font-size: 0.875rem;
  color: var(--text-muted);
  line-height: 1.8;
}

.affiliate-box a {
  display: inline-block;
  padding: 0.4rem 1.1rem;
  background: var(--accent);
  color: #fff;
  border-radius: 6px;
  font-size: 0.875rem;
  font-weight: 700;
  text-decoration: none;
}

.affiliate-box a:hover {
  background: var(--accent-hover);
  color: #fff;
  text-decoration: none;
}

/* 記事冒頭のPR表示。景表法(ステマ規制)対応で、本文より前に必ず見える位置に置く */
.affiliate-notice {
  margin: 0 0 1.5rem;
  padding: 0.5rem 0.85rem;
  background: var(--bg-subtle);
  border-left: 3px solid var(--border-strong);
  border-radius: 0 var(--radius) var(--radius) 0;
  font-size: 0.8125rem;
  color: var(--text-muted);
}

/* フッターのアソシエイト開示文 */
.affiliate-disclosure {
  margin: 0 0 0.5rem;
  font-size: 0.75rem;
  color: var(--text-muted);
  line-height: 1.8;
}

/* --- 広告枠 -------------------------------------------------------------- */

/* 広告読み込み時にレイアウトが跳ねる(CLS悪化)のを防ぐため、枠の高さを先に確保する */
.ad-slot {
  min-height: 280px;
  margin: 3rem 0 0;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
}

.ad-slot-label {
  font-size: 0.7rem;
  color: var(--text-muted);
  margin: 0 0 0.5rem;
  letter-spacing: 0.14em;
}

/* --- 固定ページ ---------------------------------------------------------- */

.static-page .post-header h1 {
  font-size: 1.5rem;
}

/* --- フッター ------------------------------------------------------------ */

.site-footer {
  border-top: 1px solid var(--border);
  background: var(--bg-subtle);
  padding: 2rem 0 2.5rem;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.site-footer .container {
  max-width: var(--wide-width);
}

.footer-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 1.25rem;
  margin-bottom: 1rem;
}

.footer-nav a {
  color: var(--text-muted);
}

.footer-nav a:hover {
  color: var(--accent);
}

.copyright {
  margin: 0;
  font-size: 0.8rem;
}

/* --- 狭い画面 ------------------------------------------------------------ */

@media (max-width: 640px) {
  body {
    font-size: 15px;
    line-height: 1.85;
  }

  .site-header-inner {
    min-height: 56px;
  }

  .site-nav {
    gap: 1rem;
    font-size: 0.8rem;
  }

  main {
    padding-top: 1.75rem;
  }

  .post-header h1 {
    font-size: 1.4rem;
  }

  .post-body h2 {
    font-size: 1.2rem;
    margin-top: 2.5rem;
  }

  .affiliate-box {
    flex-direction: column;
  }

  .affiliate-box img {
    width: 100%;
    height: 160px;
  }

  .affiliate-box a {
    display: block;
    text-align: center;
  }
}

/* --- shiki のライト/ダーク切り替え --------------------------------------- */
/* createHighlighter を defaultColor: false で使っているため、
   どちらの色を採用するかをCSS側で選ぶ必要がある */

@media (prefers-color-scheme: dark) {
  .shiki,
  .shiki span {
    color: var(--shiki-dark) !important;
    background-color: var(--shiki-dark-bg) !important;
  }
}

@media (prefers-color-scheme: light) {
  .shiki,
  .shiki span {
    color: var(--shiki-light) !important;
    background-color: var(--shiki-light-bg) !important;
  }
}

.post-updated {
  color: var(--text-muted);
}
