:root {
  --bg: #ffffff;
  --fg: #1a1a1a;
  --subtle: #6b7280;
  --border: #e5e7eb;
  --code-bg: #f3f4f6;
  --accent: #0066cc;
  --font-mono: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', monospace;
  --font-sans: system-ui, -apple-system, sans-serif;
}
html.dark {
  --bg: #0d1117;
  --fg: #e6edf3;
  --subtle: #8b949e;
  --border: #30363d;
  --code-bg: #161b22;
  --accent: #58a6ff;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-sans);
  line-height: 1.7;
  max-width: 800px;
  margin: 0 auto;
  padding: 1rem 1.5rem;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code, pre { font-family: var(--font-mono); }
pre { background: var(--code-bg); padding: 1rem; border-radius: 6px; overflow-x: auto; }
h1, h2, h3 { margin: 1.5rem 0 0.5rem; line-height: 1.3; }
p { margin: 0.75rem 0; }
hr { border: none; border-top: 1px solid var(--border); margin: 2rem 0; }

/* Bottom nav mobile padding */
@media (max-width: 767px) {
  body { padding-bottom: calc(64px + env(safe-area-inset-bottom, 0px)); }
}

/* Shiki dual theme support */
.shiki, .shiki span {
  color: var(--shiki-light) !important;
  background-color: var(--shiki-light-bg) !important;
}
html.dark .shiki, html.dark .shiki span {
  color: var(--shiki-dark) !important;
  background-color: var(--shiki-dark-bg) !important;
}

/* === PC: サイドノート === */
.sidenote {
  float: right;
  clear: right;
  margin-right: -50%;
  width: 45%;
  font-size: 0.85rem;
  line-height: 1.5;
  color: var(--subtle);
  padding: 0.25em 0;
}
.sidenote .sidenote-number {
  font-weight: 600;
  color: var(--accent);
  margin-right: 0.3em;
}
/* 本文中の注釈番号sup要素リセット（a側で上付き制御） */
sup.sidenote-number {
  vertical-align: baseline;
  font-size: inherit;
}
/* 本文中の注釈番号（PC/モバイル共通） */
.sidenote-number a,
a[data-sn-ref] {
  background: none;
  border: none;
  padding: 0;
  margin: 0;
  color: var(--accent);
  text-decoration: none;
  font-size: 0.75em;
  vertical-align: super;
  font-weight: 600;
  cursor: pointer;
  line-height: 1;
  display: inline;
}
.sidenote-number a:hover,
a[data-sn-ref]:hover {
  text-decoration: underline;
}
.sidenote:target {
  background: var(--code-bg);
  border-radius: 4px;
  padding: 0.25em 0.5em;
}

/* === PC: footnotes非表示 === */
@media (min-width: 960px) {
  .footnotes, [data-footnotes] { display: none; }
}

/* === モバイル: サイドノート非表示 === */
@media (max-width: 959px) {
  .sidenote { display: none; }
}

/* === Popover本体（モバイルJSが動的生成） === */
.sidenote-popover {
  position: fixed;
  bottom: 10%;
  left: 5%;
  right: 5%;
  max-width: 600px;
  margin-inline: auto;
  padding: 1em 1.25em;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--fg);
  font-size: 0.9rem;
  line-height: 1.6;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.15);
  max-height: 40vh;
  overflow-y: auto;
}
.sidenote-popover::backdrop {
  background: rgba(0, 0, 0, 0.1);
}

@media (min-width: 960px) {
  .sidenote-popover { display: none !important; }
}

/* === TIPS annotation === */
.tips-trigger {
  appearance: none;
  background: rgba(0, 200, 120, 0.12);
  border: none;
  border-radius: 2px;
  padding: 0 2px;
  margin: 0;
  font: inherit;
  display: inline;
  color: inherit;
  text-decoration: none;
  cursor: help;
}
.tips-trigger[data-read] {
  background: rgba(0, 200, 120, 0.05);
}
.tips-trigger:hover {
  background: rgba(0, 200, 120, 0.22);
}
html.dark .tips-trigger {
  background: rgba(60, 220, 150, 0.15);
}
html.dark .tips-trigger[data-read] {
  background: rgba(60, 220, 150, 0.06);
}
html.dark .tips-trigger:hover {
  background: rgba(60, 220, 150, 0.25);
}

.tips-popover {
  position: fixed;
  margin: 0;
  padding: 1em 1.25em;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--fg);
  font-size: 0.9rem;
  line-height: 1.6;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.15);
  max-height: 40vh;
  max-width: min(500px, 90vw);
  overflow-y: auto;
}
.tips-popover::backdrop {
  background: rgba(0, 0, 0, 0.1);
}
.tips-popover .tips-title {
  display: block;
  font-size: 0.85rem;
  color: var(--accent);
  margin-bottom: 0.5em;
}
.tips-popover .tips-body {
  margin: 0;
}
.tips-popover--nested {
  z-index: 1;
}
