/* ── Design tokens ──
   明るい / 暗いを決めるのは <html data-theme> だけ（foundation の ui/tokens.css と同じ作り）。
   値は <head> のスクリプトが最初の描画より前に書く: 覚えた選択があればそれ、無ければ端末の設定。
   ヘッダーのボタンで切り替える（kit の colorModeToggle・kit/client/color-mode.ts）。JavaScript が無いときは明るいまま。 */
:root {
  color-scheme: light;
  --bg: #f8fafc;
  --surface: #ffffff;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --text: #0f172a;
  --muted: #64748b;
  --accent: #2563eb;
  --mark: #475569;
  --code-bg: #f1f5f9;
  --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 4px 12px rgba(15, 23, 42, .06);
  --shadow-pop: 0 8px 28px rgba(0, 0, 0, .16);
  --radius: 12px;
  --measure: 760px;
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0b1120;
  --surface: #111827;
  --border: #1f2937;
  --border-strong: #475569;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --accent: #60a5fa;
  --mark: #334155;
  --code-bg: #1e293b;
  /* 暗い地では影が見えないので、明るいときより濃く長く落とす */
  --shadow: 0 1px 3px rgba(0, 0, 0, .5), 0 4px 16px rgba(0, 0, 0, .4);
  --shadow-pop: 0 8px 28px rgba(0, 0, 0, .6);
}

/* ── 土台 ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

@view-transition { navigation: auto; }

body {
  font-family: ui-sans-serif, system-ui, -apple-system, "Hiragino Kaku Gothic ProN",
               "Noto Sans JP", "Yu Gothic", Meiryo, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.8;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  -webkit-text-size-adjust: 100%;
}

a { color: var(--accent); }

.site-main {
  width: 100%;
  max-width: calc(var(--measure) + 48px);
  margin: 0 auto;
  padding: 48px 24px 72px;
  flex: 1;
}
/* 一番上へ移動したあとにフォーカスを預かるだけなので、枠は出さない（site.js） */
.site-main:focus { outline: none; }

@media (max-width: 600px) {
  .site-main { padding: 32px 16px 56px; }
}

/* 画面には出さず、読み上げにだけ渡す（トップの見出しなど） */
.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ── ヘッダー（サイト名と色モードの切り替えだけ。ナビは置かない） ── */
.site-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  position: sticky;
  top: 0;
  z-index: 10;
}
.site-header-inner {
  max-width: var(--measure);
  margin: 0 auto;
  height: 56px;
  display: flex;
  align-items: center;
}
.site-header-name {
  display: flex; align-items: center; gap: 10px;
  font-size: 15px; font-weight: 700; letter-spacing: .02em;
  color: var(--text);
  text-decoration: none;
}
.site-header-mark {
  width: 28px; height: 28px;
  background: var(--mark);
  color: #fff;
  border-radius: 6px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.site-header-mark svg { display: block; }

.site-header-actions { margin-left: auto; display: flex; align-items: center; }

/* 色モードの切り替え（foundation の .icon-btn と同じ 44×44・透明の器）。
   印は「押すと変わる先」: 明るいときは月・暗いときは太陽 */
.color-mode-toggle {
  min-width: 44px;
  min-height: 44px;
  margin-right: -12px; /* 印の右端を本文の右端にそろえる */
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 8px;
  color: var(--muted);
  cursor: pointer;
}
.color-mode-toggle svg { display: block; }
@media (hover: hover) {
  .color-mode-toggle:hover { background: var(--bg); color: var(--text); }
}
.color-mode-toggle:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
:root[data-theme="dark"] .color-mode-toggle-moon,
:root:not([data-theme="dark"]) .color-mode-toggle-sun { display: none; }
/* data-theme が無い = <head> のスクリプトが走っていない（JavaScript なし）→ 押しても変わらないので出さない */
:root:not([data-theme]) .color-mode-toggle { display: none; }

@media (max-width: 600px) {
  .site-header { padding: 0 16px; }
}

/* ── ページの見出し ── */
.page-title { margin-bottom: 20px; }
.page-title h1 {
  font-size: clamp(24px, 4.2vw, 34px);
  font-weight: 800;
  letter-spacing: -.02em;
  line-height: 1.35;
}
.page-title-lead { margin-top: 10px; color: var(--muted); font-size: 15px; }

/* ── 本文（Markdown から作った HTML） ── */
.prose { font-size: 16px; line-height: 1.9; overflow-wrap: anywhere; }
.prose > * + * { margin-top: 1em; }

.prose h1, .prose h2, .prose h3, .prose h4 {
  line-height: 1.4;
  letter-spacing: -.01em;
  scroll-margin-top: 72px; /* 固定ヘッダーの下に隠れないように */
}
.prose h1 { font-size: 24px; margin-top: 2em; }
.prose h2 {
  font-size: 21px;
  margin-top: 2.2em;
  padding-bottom: .3em;
  border-bottom: 1px solid var(--border);
}
.prose h3 { font-size: 18px; margin-top: 1.8em; }
.prose h4 { font-size: 16px; margin-top: 1.5em; }
.prose > :first-child { margin-top: 0; }

.prose ul, .prose ol { padding-left: 1.5em; }
.prose li + li, .prose li > ul, .prose li > ol { margin-top: .3em; }

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

.prose hr { border: 0; border-top: 1px solid var(--border); margin: 2.4em 0; }

.prose blockquote {
  border-left: 3px solid var(--border);
  padding-left: 1em;
  color: var(--muted);
}

.prose code {
  background: var(--code-bg);
  border-radius: 4px;
  padding: .1em .35em;
  font-size: .9em;
}
.prose pre { background: var(--code-bg); border-radius: 8px; padding: 12px 16px; overflow-x: auto; }
.prose pre code { background: none; padding: 0; }

/* 表は狭い画面で横にスクロールさせる */
.prose table {
  display: block;
  overflow-x: auto;
  border-collapse: collapse;
  font-size: 14px;
  line-height: 1.6;
}
.prose th, .prose td { border: 1px solid var(--border); padding: 6px 10px; text-align: left; vertical-align: top; }
.prose th { background: var(--surface); white-space: nowrap; }

/* ── 目次（頭に置く・開閉式） ── */
.toc {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 18px;
  margin: 20px 0 32px;
  font-size: 14px;
}
.toc summary { cursor: pointer; font-weight: 700; padding: 2px 0; }
.toc-list { list-style: none; padding: 6px 0 4px; line-height: 1.7; }
/* 見出し自体に番号が付いている記事が多いので、リストの番号は出さない */
.toc-list ol { list-style: none; padding-left: 1.2em; }
.toc-list li + li, .toc-list li > ol { margin-top: .2em; }
.toc-list a { color: var(--text); text-decoration: none; }
.toc-list a:hover { color: var(--accent); text-decoration: underline; }

/* ── 記事の日付・トップ画像・トップの英語記事の見出し ── */
.post-meta {
  display: flex; flex-wrap: wrap; gap: 4px 16px;
  font-size: 13px; color: var(--muted);
  margin: -8px 0 20px;
}
.post-meta time { font-variant-numeric: tabular-nums; }

.post-cover {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 2 / 1; /* 目次が最初の画面に入るように高さを抑える */
  object-fit: cover;
  border-radius: var(--radius);
  border: 1px solid var(--border);
}

.home-posts { margin-top: 48px; }
.home-posts h2 {
  font-size: 12px; font-weight: 700;
  letter-spacing: .1em;
  color: var(--muted);
  margin-bottom: 12px;
}

.not-found-home { margin-top: 24px; }

/* ── トップの記事カード（画像・タイトル・説明・日付。カード全体がリンク） ── */
.post-cards {
  list-style: none;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 220px), 1fr));
  gap: 20px;
  margin-top: 12px;
}
.post-card a {
  display: flex;
  flex-direction: column;
  height: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  color: var(--text);
  text-decoration: none;
  transition: border-color .15s ease, box-shadow .15s ease, transform .15s ease;
}
.post-card-image {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 1.91 / 1; /* トップ画像の大半（OGP の比率） */
  object-fit: cover;
  background: var(--code-bg);
  border-bottom: 1px solid var(--border);
}
.post-card-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 12px 14px 14px;
}
.post-card-title,
.post-card-desc {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.post-card-title { font-size: 15px; font-weight: 700; line-height: 1.5; -webkit-line-clamp: 3; }
.post-card-desc { font-size: 13px; line-height: 1.6; color: var(--muted); -webkit-line-clamp: 2; }
.post-card-date {
  margin-top: auto; /* 同じ行のカードで日付の高さをそろえる */
  padding-top: 2px;
  font-size: 12px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

@media (hover: hover) {
  .post-card a:hover { border-color: var(--border-strong); box-shadow: var(--shadow); transform: translateY(-2px); }
  .post-card a:hover .post-card-title { color: var(--accent); }
}
.post-card a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) {
  .post-card a { transition: none; }
  .post-card a:hover { transform: none; }
}

/* 狭い画面: 1 列の横長カード（画像が左・説明は出さない） */
@media (max-width: 480px) {
  .post-cards { grid-template-columns: 1fr; gap: 12px; }
  .post-card a { flex-direction: row; }
  .post-card-image {
    width: 38%;
    flex-shrink: 0;
    align-self: stretch;
    border-bottom: 0;
    border-right: 1px solid var(--border);
  }
  .post-card-body { padding: 10px 12px; gap: 4px; }
  .post-card-title { font-size: 14px; }
  .post-card-desc { display: none; }
}

/* ── 本文のリンクカード（リンクだけの行から作る横長の小さいカード。kit/link-cards.ts） ──
   形はトップのカードの狭い画面版と同じ: 画像が左・タイトルと日付が右 */
.link-cards { display: grid; gap: 10px; }
.link-card {
  display: flex;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  color: var(--text);
  text-decoration: none;
  line-height: 1.5;
  transition: border-color .15s ease, box-shadow .15s ease;
}
/* .prose img（中央寄せ・余白・角丸）を打ち消す */
.prose .link-card-image,
.link-card-image {
  flex: 0 0 min(34%, 168px);
  width: min(34%, 168px);
  max-width: none;
  height: auto;
  min-height: 88px;
  margin: 0;
  align-self: stretch;
  object-fit: cover;
  border-radius: 0;
  border-right: 1px solid var(--border);
  background: var(--code-bg);
}
.link-card-body {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 10px 14px;
}
.link-card-title,
.link-card-desc {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.link-card-title { font-size: 15px; font-weight: 700; -webkit-line-clamp: 2; }
.link-card-desc { font-size: 13px; color: var(--muted); -webkit-line-clamp: 1; }
.link-card-date {
  margin-top: auto;
  font-size: 12px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
@media (hover: hover) {
  .link-card:hover { border-color: var(--border-strong); box-shadow: var(--shadow); }
  .link-card:hover .link-card-title { color: var(--accent); }
}
.link-card:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) {
  .link-card { transition: none; }
}
@media (max-width: 480px) {
  .link-card-title { font-size: 14px; -webkit-line-clamp: 3; }
  .link-card-desc { display: none; }
  .link-card-body { padding: 8px 12px; }
}

/* ── 一番上へ移動する浮動ボタン（foundation の components.css .scroll-top の写し） ──
   400px を超えて下へスクロールしたら出す（site.js）。器は 44×44 の丸・印は文字の Up。 */
.scroll-top {
  position: fixed;
  right: calc(12px + env(safe-area-inset-right, 0px));
  bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  z-index: 30;
  min-width: 44px;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 999px;
  box-shadow: var(--shadow-pop);
  font: inherit;
  cursor: pointer;
  animation: scroll-top-in 120ms ease;
}
.scroll-top[hidden] { display: none; }
.scroll-top-text { font-size: 13px; font-weight: 700; }
/* hover の手掛かりは枠色だけ（面は --surface のまま = 浮いて見える）。hover を持つ端末だけ */
@media (hover: hover) {
  .scroll-top:hover { border-color: var(--border-strong); }
}
@keyframes scroll-top-in {
  from { opacity: 0; }
  to { opacity: 1; }
}
@media (prefers-reduced-motion: reduce) {
  .scroll-top { animation: none; }
}

/* ── フッター（書き手の紹介 = アイコン・名前・短い文と、小さな 1 行） ── */
.site-footer {
  border-top: 1px solid var(--border);
  background: var(--surface);
  padding: 28px 24px 24px;
}
.site-footer-inner {
  max-width: var(--measure);
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.author-box { display: flex; gap: 14px; align-items: flex-start; }
.author-box-avatar {
  flex-shrink: 0;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: #fff;
}
.author-box-body { min-width: 0; }
.author-box-name { font-size: 15px; font-weight: 700; line-height: 1.5; }
.author-box-text { margin-top: 2px; font-size: 14px; line-height: 1.75; color: var(--muted); }
.author-box-text > * + * { margin-top: .5em; }

.site-footer-links {
  display: flex; flex-wrap: wrap; gap: 4px 16px;
  font-size: 12px;
  color: var(--muted);
}
.site-footer-links a { color: inherit; }

@media (max-width: 600px) {
  .site-footer { padding: 24px 16px 20px; }
}
