/*
 * テキストエディター風：等幅寄りのフォントで、Markdown の記号（.md-mark）を薄い色で見せる。
 * 色はすべて変数にし、ダークモードは prefers-color-scheme で切り替える。
 */

:root {
  --bg: #fcfcfd;
  --fg: #1f2328;
  --mark: #8c959f; /* Markdown の記号（飾りなので、コントラストは本文より低くてよい） */
  --subtle: #636c76; /* 日付、タグなどの控えめな文字（背景とのコントラスト 4.5 以上） */
  --line: #d8dee4; /* 罫線 */
  --panel: #f3f5f7; /* インラインコード、表の見出しなど */
  --marked: rgb(10 95 194 / 0.1); /* コードブロックで強調した行 */
  --accent: #0a5fc2; /* リンク */
  --note: #0969da;
  --tip: #1a7f37;
  --important: #8250df;
  --warning: #9a6700;
  --caution: #cf222e;

  --mono: ui-monospace, "SFMono-Regular", "SF Mono", Menlo, Consolas, "BIZ UDGothic",
    "Noto Sans Mono CJK JP", monospace;
  --measure: 46rem;

  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1a1d21;
    --fg: #d6dae0;
    --mark: #6e7781;
    --subtle: #9198a1;
    --line: #353b43;
    --panel: #23282e;
    --marked: rgb(108 182 255 / 0.15);
    --accent: #6cb6ff;
    --note: #4493f8;
    --tip: #3fb950;
    --important: #ab7df8;
    --warning: #d29922;
    --caution: #f85149;
  }
}

/* 土台 */

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

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0 auto;
  max-width: calc(var(--measure) + 2rem);
  padding: 1.5rem max(1rem, env(safe-area-inset-right)) 4rem max(1rem, env(safe-area-inset-left));
  background: var(--bg);
  color: var(--fg);
  font-family: var(--mono);
  font-size: 0.95rem;
  line-height: 1.8;
  overflow-wrap: anywhere;
}

a {
  color: var(--accent);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 0.2em;
}

a:hover {
  text-decoration-thickness: 2px;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.md-mark {
  color: var(--mark);
  font-weight: normal;
  font-style: normal;
}

a.md-mark {
  text-decoration: none;
}

/* ヘッダー */

.site-header {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.5rem 1.5rem;
  padding-bottom: 0.75rem;
  margin-bottom: 2rem;
  border-bottom: 1px solid var(--line);
}

.site-title {
  color: var(--fg);
  font-weight: bold;
  text-decoration: none;
}

.site-header nav {
  display: flex;
  gap: 1.25rem;
}

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

.site-header nav a:hover,
.site-header nav a[aria-current="page"] {
  color: var(--fg);
}

/* 見出し：大きさの差は控えめにし、記号と太さで階層を示す */

h1,
h2,
h3,
h4,
h5,
h6 {
  margin: 2.5rem 0 1rem;
  font-size: 1rem;
  line-height: 1.5;
  text-wrap: balance;
}

h1 {
  margin-top: 0;
  font-size: 1.35rem;
}

h2 {
  font-size: 1.15rem;
}

h1 code,
h2 code,
h3 code {
  font-size: 0.95em;
}

/* 記事 */

article > header {
  margin-bottom: 2rem;
}

article > header h1 {
  margin-bottom: 0.5rem;
}

.post-meta {
  margin: 0;
  color: var(--subtle);
  font-size: 0.85rem;
}

.post-meta > span + span {
  margin-left: 1rem;
}

.post-draft {
  color: var(--warning);
  font-weight: bold;
}

.post-tags {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 0 0.75rem;
  margin: 0;
  padding: 0;
  list-style: none;
  font-size: 0.85rem;
}

.post-tags a {
  color: var(--subtle);
  text-decoration: none;
}

.post-tags a::before {
  content: "#";
}

.post-tags a:hover {
  color: var(--accent);
}

/* 本文 */

.post-body > * {
  margin-top: 0;
  margin-bottom: 1.25rem;
}

p {
  margin: 0 0 1.25rem;
}

strong {
  font-weight: bold;
}

del {
  color: var(--subtle);
}

/* リスト：記号は .md-mark で出るので、ブラウザーの記号は消す */

.post-body ul,
.post-body ol {
  padding-left: 0;
  list-style: none;
}

.post-body li > ul,
.post-body li > ol {
  margin: 0;
  padding-left: 2ch;
}

.post-body li {
  padding-left: 2ch;
  text-indent: -2ch;
}

.post-body li > * {
  text-indent: 0;
}

.post-body li input[type="checkbox"] {
  margin: 0 0.5ch 0 0;
  vertical-align: -0.1em;
}

/* 引用と注意書き */

blockquote {
  margin: 0 0 1.25rem;
  padding: 0.25rem 0 0.25rem 1rem;
  border-left: 3px solid var(--line);
  color: var(--subtle);
}

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

/* 色は種類ごとのクラスで --alert に入れる */
blockquote[class^="markdown-alert-"] {
  border-left-color: var(--alert);
  color: var(--fg);
}

blockquote[class^="markdown-alert-"]::before {
  display: block;
  color: var(--alert);
  font-weight: bold;
}

.markdown-alert-note {
  --alert: var(--note);
}

.markdown-alert-note::before {
  content: "Note";
}

.markdown-alert-tip {
  --alert: var(--tip);
}

.markdown-alert-tip::before {
  content: "Tip";
}

.markdown-alert-important {
  --alert: var(--important);
}

.markdown-alert-important::before {
  content: "Important";
}

.markdown-alert-warning {
  --alert: var(--warning);
}

.markdown-alert-warning::before {
  content: "Warning";
}

.markdown-alert-caution {
  --alert: var(--caution);
}

.markdown-alert-caution::before {
  content: "Caution";
}

/* コード */

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

:not(pre) > code {
  padding: 0.1em 0.3em;
  border-radius: 3px;
  background: var(--panel);
}

pre {
  margin: 0 0 1.25rem;
  padding: 0.9rem 1rem;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--panel);
  line-height: 1.6;
}

pre code {
  font-size: 0.85rem;
}

figure {
  margin: 0 0 1.25rem;
}

figure > pre {
  margin: 0;
  border-top-left-radius: 0;
}

/* タイトル付きのコードブロックは、エディターのタブのように見せる */
figcaption {
  display: inline-block;
  padding: 0.15rem 0.9rem;
  border: 1px solid var(--line);
  border-bottom: none;
  border-radius: 4px 4px 0 0;
  background: var(--panel);
  color: var(--subtle);
  font-size: 0.8rem;
}

/* 表：幅が足りなければ表だけを横にスクロールする */

.table-wrap {
  max-width: 100%;
  overflow-x: auto;
  margin: 0 0 1.25rem;
}

table {
  border-collapse: collapse;
  font-size: 0.9rem;
  font-variant-numeric: tabular-nums;
}

th,
td {
  padding: 0.35rem 0.75rem;
  border: 1px solid var(--line);
}

th {
  background: var(--panel);
}

.align-left {
  text-align: left;
}

.align-center {
  text-align: center;
}

.align-right {
  text-align: right;
}

/* その他 */

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

hr {
  margin: 2rem 0;
  border: none;
  border-top: 1px dashed var(--line);
}

sup {
  line-height: 0;
}

.footnote-reference a {
  text-decoration: none;
}

.footnote-reference a::before {
  content: "[";
}

.footnote-reference a::after {
  content: "]";
}

.footnote-definition {
  display: flex;
  gap: 0.5ch;
  color: var(--subtle);
  font-size: 0.85rem;
}

/* 最初の脚注の前に区切りを入れる */
:not(.footnote-definition) + .footnote-definition {
  margin-top: 2.5rem;
  padding-top: 1rem;
  border-top: 1px dashed var(--line);
}

.footnote-definition-label::before {
  content: "[^";
}

.footnote-definition-label::after {
  content: "]:";
}

.footnote-definition-label {
  font-size: inherit;
  line-height: inherit;
}

.footnote-definition > p {
  margin: 0;
}

/* 記事一覧 */

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

.post-list > li {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0 1rem;
  padding: 0.3rem 0;
}

.post-list time {
  color: var(--subtle);
  font-size: 0.85rem;
  font-variant-numeric: tabular-nums;
}

.post-list > li > a {
  min-width: 0;
}

/* タグ一覧 */

.tag-list {
  padding: 0;
  list-style: none;
}

.tag-list a::before {
  content: "#";
}

.tag-count {
  color: var(--subtle);
  font-size: 0.85rem;
}

/* 行番号と強調した行 */

pre.code code {
  display: block;
  min-width: fit-content;
}

.line {
  display: inline-block;
  min-width: 100%;
}

.line-number {
  margin-right: 2ch;
  color: var(--mark);
  user-select: none; /* コピーに含めない */
}

.line.marked {
  background: var(--marked);
}
