:root {
  --max-width: 720px;

  --bg: #ffffff;
  --surface: #f9fafb;
  --text: #222;
  --sub: #6b7280;
  --border: #e5e7eb;
  --accent: #3b82f6;
  --shadow: rgba(0, 0, 0, 0.15);
}

body.dark {
  --bg: #0f172a;
  --surface: #1e293b;
  --text: #f1f5f9;
  --sub: #94a3b8;
  --border: #334155;
  --accent: #60a5fa;
  --shadow: rgba(0, 0, 0, 0.5);
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.9;
}

/* ================= Overlay ================= */

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.35);
  -webkit-backdrop-filter: blur(2px);
  backdrop-filter: blur(2px);
  opacity: 0;
  pointer-events: none;
  transition: 0.3s ease;
  z-index: 4000;
}

body.toc-open .overlay {
  opacity: 1;
  pointer-events: auto;
}

/* ================= Sidebar ================= */

.toc {
  position: fixed;
  top: 0;
  left: 0;
  width: 320px;
  height: 100vh;
  padding: 100px 30px;
  overflow-y: auto;

  background: rgba(255, 255, 255, 0.85);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);

  transform: translateX(-100%);
  transition: transform 0.3s ease;
  z-index: 5000;

  box-shadow: 4px 0 40px var(--shadow);
}

body.dark .toc {
  background: rgba(15, 23, 42, 0.85);
}

body.toc-open .toc {
  transform: translateX(0);
}

.toc a {
  display: block;
  margin: 8px 0;
  text-decoration: none;
  color: var(--sub);
}

.toc a:hover,
.toc a.active {
  color: var(--text);
  font-weight: 600;
}
/* サイドバー */
.toc .h2 {
  padding-left: 12px; /* ★追加 */
}

.toc .h3 {
  padding-left: 24px; /* 16px → 24px に変更 */
  font-size: 0.9rem;
}

/* ================= Toggle Button ================= */

.toc-toggle {
  position: fixed;
  top: 20px;
  left: 20px;
  z-index: 6000;

  display: flex;
  align-items: center;
  gap: 12px;

  padding: 10px 18px;
  border-radius: 999px;
  border: 2px solid var(--accent);

  background: var(--surface);
  color: var(--text);
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 6px 20px var(--shadow);
  transition: 0.25s ease;
}

.toc-toggle:hover {
  background: var(--accent);
  color: white;
}

.icon {
  font-size: 18px;
}

/* ================= Article ================= */

.article {
  max-width: var(--max-width);
  margin: 100px auto;
  padding: 0 24px;
}

.thumbnail {
  width: 100%;
  border-radius: 12px;
  margin-bottom: 40px;
}

#post-body a,
#markdown-content a {
  color: var(--accent);
  text-decoration-thickness: 0.08em;
  text-underline-offset: 0.16em;
}

#post-body a:hover,
#markdown-content a:hover {
  opacity: 0.85;
}

/* ================= TOC Box ================= */

.toc-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 24px;
  margin: 40px 0;
}

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

.toc-box li {
  margin: 6px 0;
}

.toc-box a {
  text-decoration: none;
  color: var(--sub);
}

.toc-box a:hover {
  color: var(--text);
}
/* インライン目次 */
.toc-box .h2 {
  padding-left: 12px; /* ★追加 */
}

.toc-box .h3 {
  padding-left: 24px; /* 16px → 24px に変更 */
  font-size: 0.9rem;
}

.toc .h4,
.toc-box .h4 {
  padding-left: 32px;
  font-size: 0.85rem;
}

/* ================= Responsive ================= */

@media (max-width: 768px) {
  .toc {
    width: 85%;
  }
}

.table-scroll {
  width: 100%;
  overflow-x: auto;
  margin: 32px 0;
  -webkit-overflow-scrolling: touch;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.95rem;
}

.table-scroll > table {
  width: max-content;
  min-width: 100%;
  margin: 0;
}

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

th {
  background: var(--surface);
  font-weight: 600;
}

tr:nth-child(even) td {
  background: var(--surface);
}

blockquote {
  border-left: 4px solid var(--accent);
  margin: 24px 0;
  padding: 12px 20px;
  color: var(--sub);
  background: var(--surface);
  border-radius: 0 8px 8px 0;
}

input[type="checkbox"] {
  accent-color: var(--accent);
  margin-right: 6px;
}

/* =====================
   BACK LINK (post pages)
===================== */

.back-link {
  position: fixed;
  top: 20px;
  left: 20px;
  z-index: 6000;

  display: inline-flex;
  align-items: center;
  gap: 8px;

  font-size: 0.85rem;
  font-weight: 500;
  text-decoration: none;
  color: var(--sub);

  padding: 9px 18px 9px 14px;
  border-radius: 999px;
  border: 2px solid var(--border);
  background: var(--surface);
  box-shadow: 0 4px 12px var(--shadow);

  transition: all 0.2s ease;
}

.back-link svg {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  stroke: currentColor;
}

.back-link:hover {
  color: var(--accent);
  border-color: var(--accent);
  transform: translateX(-3px);
  box-shadow: 0 6px 18px var(--shadow);
}

/* back-link があるときは toc-toggle を右にずらす */
body:has(.back-link) .toc-toggle {
  left: 148px;
}

/* =====================
   FOOTER
===================== */

.site-footer-bottom {
  text-align: center;
  padding: 32px 24px 48px;
  font-size: 0.8rem;
  color: var(--sub);
  border-top: 1px solid var(--border);
}

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

/* =====================
   PAGE LOADER BAR
   (append to css/styles.css)
===================== */

.page-loader {
  position: fixed;
  top: 0;
  left: 0;
  height: 3px;
  width: 0%;
  background: var(--accent);
  z-index: 9999;
  display: none;
  border-radius: 0 2px 2px 0;
}

.page-loader.loading {
  display: block;
  animation: loader-advance 1.4s ease-in-out infinite alternate;
}

.page-loader.done {
  display: block;
  width: 100% !important;
  animation: none;
  transition: opacity 0.4s ease 0.15s;
  opacity: 0;
}

@keyframes loader-advance {
  0% {
    width: 15%;
    opacity: 1;
  }
  100% {
    width: 82%;
    opacity: 1;
  }
}
