:root {
  --bg: #fbfbfa;
  --surface: #ffffff;
  --text: #24292f;
  --muted: #6b7280;
  --border: #e4e4e7;
  --accent: #008080;
  --code-bg: #f4f4f5;
  --max-width: 1140px;

  /* highlight.js のトークン色 */
  --syn-comment: #6e7781;
  --syn-keyword: #cf222e;
  --syn-string: #0a3069;
  --syn-number: #0550ae;
  --syn-title: #8250df;
  --syn-builtin: #953800;
  --syn-meta: #116329;

  /*
   * サイトヘッダ・サイトフッタ専用の配色。既定では本文と同じ色を指している。
   * 本文と別の色にしたいときは、ここ (とダークモード側) を色の値で上書きする。
   * var() のままにしておいた項目は、本文のライト／ダーク切り替えに追従する。
   */
  --header-bg: #008080;
  --header-text: #ffffff;
  --header-muted: #ffffff;
  --header-border: var(--border);
  --header-accent: var(--accent);

  --footer-bg: #008080;
  --footer-text: #ffffff;
  --footer-muted: #ffffff;
  --footer-border: var(--border);
  --footer-accent: var(--accent);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16181d;
    --surface: #1d2027;
    --text: #dfe3ea;
    --muted: #9aa3b2;
    --border: #2d323c;
    --accent: #7fc6a1;
    --code-bg: #23272f;

    --syn-comment: #8b949e;
    --syn-keyword: #ff7b72;
    --syn-string: #a5d6ff;
    --syn-number: #79c0ff;
    --syn-title: #d2a8ff;
    --syn-builtin: #ffa657;
    --syn-meta: #7ee787;

    /* ヘッダ・フッタをダークモードで別の色にしたいときはここで上書きする。 */
  }
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Hiragino Kaku Gothic ProN", "Noto Sans JP", "Yu Gothic UI", system-ui, sans-serif;
  line-height: 1.8;
  font-size: 16px;
}

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

a:hover {
  text-decoration: underline;
}

/* --- header / footer --------------------------------------------------- */

/*
 * ヘッダ・フッタの中では本文用の変数を専用の配色に差し替える。
 * 中の要素は普段どおり var(--text) などを使えば、専用の色で描かれる。
 */
.site-header {
  --bg: var(--header-bg);
  --surface: var(--header-bg);
  --text: var(--header-text);
  --muted: var(--header-muted);
  --border: var(--header-border);
  --accent: var(--header-accent);
}

.site-footer {
  --bg: var(--footer-bg);
  --surface: var(--footer-bg);
  --text: var(--footer-text);
  --muted: var(--footer-muted);
  --border: var(--footer-border);
  --accent: var(--footer-accent);
}

.site-header,
.site-footer {
  background: var(--bg);
  color: var(--text);
}

.site-header {
  border-bottom: 1px solid var(--border);
}

.site-header__inner,
.site-footer__inner {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 20px 16px;
}

.site-header__brand {
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
}

.site-header__tagline {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.site-footer {
  margin-top: 48px;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 13px;
}

.site-footer__inner {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 24px;
  justify-content: space-between;
}

.site-footer p {
  margin: 0;
}

/* --- layout ------------------------------------------------------------ */

.shell {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 32px 16px 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 260px;
  gap: 40px;
  align-items: start;
}

@media (max-width: 860px) {
  .shell {
    grid-template-columns: minmax(0, 1fr);
    gap: 32px;
  }
}

.main {
  min-width: 0;
}

/* --- article ----------------------------------------------------------- */

.article__header {
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 24px;
}

.article__title {
  margin: 0 0 8px;
  font-size: 28px;
  line-height: 1.4;
}

.article__meta {
  margin: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  color: var(--muted);
  font-size: 13px;
}

.badge {
  padding: 0 8px;
  border-radius: 999px;
  background: #b45309;
  color: #fff;
  font-size: 11px;
}

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

.tag {
  padding: 1px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--muted);
  font-size: 12px;
}

.article__body h2 {
  margin: 40px 0 12px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
  font-size: 22px;
}

.article__body h3 {
  margin: 28px 0 8px;
  font-size: 18px;
}

.article__body p,
.article__body ul,
.article__body ol {
  margin: 0 0 16px;
}

.article__body img {
  max-width: 100%;
  height: auto;
  border: 1px solid var(--border);
  border-radius: 6px;
}

.article__body blockquote {
  margin: 0 0 16px;
  padding: 4px 16px;
  border-left: 3px solid var(--border);
  color: var(--muted);
}

.article__body code {
  font-family: "Cascadia Mono", Consolas, "SFMono-Regular", monospace;
  font-size: 0.9em;
}

/* 背景を付けるのは文中の表記だけ。pre の中は code 側が背景を持つ。 */
.article__body :not(pre) > code {
  padding: 2px 5px;
  border-radius: 4px;
  background: var(--code-bg);
}

.article__body pre {
  margin: 0 0 16px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--code-bg);
  overflow: hidden;
  line-height: 1.6;
}

/*
 * 余白は code 側に持たせる。highlight.js のテーマ CSS は .hljs に background を
 * 指定するので、こうしておくとテーマの背景がブロック全面に効く。
 */
.article__body pre code {
  display: block;
  padding: 14px 16px;
  overflow-x: auto;
}

.article__body table {
  width: 100%;
  margin: 0 0 16px;
  border-collapse: collapse;
  font-size: 14px;
}

.article__body th,
.article__body td {
  padding: 6px 12px;
  border: 1px solid var(--border);
  text-align: left;
}

.article__body th {
  background: var(--code-bg);
}

/* --- sidebar ----------------------------------------------------------- */

.sidebar {
  font-size: 14px;
}

.sidebar__section + .sidebar__section {
  margin-top: 32px;
}

.sidebar__title {
  margin: 0 0 12px;
  font-size: 13px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

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

.sidebar__item + .sidebar__item {
  margin-top: 12px;
}

.sidebar__link {
  display: block;
  line-height: 1.5;
}

.sidebar__date {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.sidebar__category {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
}

/* 開閉の三角ぶんの幅を、子を持たないカテゴリにも空けて名前の頭を揃える。 */
.sidebar__toggle,
.sidebar__leaf {
  position: relative;
  padding-left: 16px;
}

.sidebar__toggle {
  cursor: pointer;
  list-style: none;
}

.sidebar__toggle::-webkit-details-marker {
  display: none;
}

.sidebar__toggle::before {
  content: "";
  position: absolute;
  left: 2px;
  top: 0.55em;
  border-style: solid;
  border-width: 4px 0 4px 6px;
  border-color: transparent transparent transparent var(--muted);
  transition: transform 0.15s ease;
}

.sidebar__group[open] > .sidebar__toggle::before {
  transform: rotate(90deg);
}

.sidebar__link--current {
  font-weight: 600;
}

/* 子階層・孫階層は一段ずつ右へずらし、左の罫線で親子関係を見せる。 */
.sidebar__sublist {
  margin: 8px 0 0 6px;
  padding-left: 10px;
  border-left: 1px solid var(--border);
}

.sidebar__sublist .sidebar__item + .sidebar__item {
  margin-top: 8px;
}

.sidebar__count {
  color: var(--muted);
  font-size: 12px;
}

/* --- index ------------------------------------------------------------- */

.index__header {
  display: flex;
  align-items: baseline;
  gap: 12px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 8px;
}

.index__title {
  margin: 0;
  font-size: 24px;
}

.index__count {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

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

.post-list__item {
  padding: 24px 0;
  border-bottom: 1px solid var(--border);
}

.post-list__date {
  display: block;
  color: var(--muted);
  font-size: 13px;
}

.post-list__title {
  margin: 4px 0 0;
  font-size: 19px;
  line-height: 1.5;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.post-list__excerpt {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.post-list__item .tags {
  margin-top: 10px;
}

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

/* --- pagination -------------------------------------------------------- */

.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 32px;
  font-size: 14px;
}

.pagination__step {
  white-space: nowrap;
}

.pagination__step--disabled {
  color: var(--muted);
  opacity: 0.5;
}

.pagination__pages {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.pagination__page {
  display: inline-block;
  min-width: 32px;
  padding: 3px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  text-align: center;
}

.pagination__page--current {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--surface);
  font-weight: 700;
}

/* --- category ---------------------------------------------------------- */

.index__breadcrumb {
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 13px;
}

.pagination__ellipsis {
  display: inline-block;
  min-width: 32px;
  padding: 3px 4px;
  color: var(--muted);
  text-align: center;
}

/* --- tags -------------------------------------------------------------- */

.tag a {
  color: inherit;
}

.tag:hover {
  border-color: var(--accent);
}

.tag__count {
  margin-left: 6px;
  opacity: 0.7;
  font-size: 11px;
}

.sidebar .tags {
  margin-top: 0;
}

/* --- back to top ------------------------------------------------------- */

.to-top {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--surface);
  color: var(--text);
  font-size: 18px;
  line-height: 1;
  box-shadow: 0 2px 8px rgb(0 0 0 / 0.14);
}

.to-top:hover {
  border-color: var(--accent);
  color: var(--accent);
  text-decoration: none;
}

@media (max-width: 860px) {
  .to-top {
    right: 16px;
    bottom: 16px;
  }
}

/*
 * スクロール連動アニメーションが使えるブラウザでは、少し下ってから出す。
 * 使えない場合は常時表示になるだけで、機能は変わらない。
 */
@supports (animation-timeline: scroll()) {
  .to-top {
    animation: to-top-reveal linear both;
    animation-timeline: scroll(root block);
    animation-range: 240px 480px;
  }
}

@keyframes to-top-reveal {
  from {
    opacity: 0;
    pointer-events: none;
  }
  to {
    opacity: 1;
    pointer-events: auto;
  }
}
