body.dark {
  background-color: #111;
  color: #ddd;
}
body.dark .site-header,
body.dark .site-footer {
  background-color: #111;
  color: #ddd;
  border-color: #444;
}
body.dark a:link { color: #5bf; }
body.dark a:visited { color: #6bf; }
body.dark a:hover { color: #39d; }
body.dark .site-title, body.dark .site-title:visited { color: #ddd; }
body.dark code, body.dark pre, body.dark .highlight {
  background-color: #1a1a1a;
  color: #eee;
  border-color: #444;
}
body.dark h1, body.dark h2, body.dark h3, body.dark h4 { color: #ddd; }
body.dark strong { color: #fff; }
body.dark hr { border-color: #444; }
body.dark table th { background: #444; color: #fff; }
body.dark table td, body.dark table th { border-color: #444; }
body.dark table tr:nth-child(even) { background: #1a1a1a; }
body.dark img { filter: brightness(0.9); }

.theme-switch {
  display: inline-block;
  position: fixed;
  top: 10px;
  right: 10px;
  z-index: 99999;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  padding: 4px;
}
.theme-switch-track {
  width: 50px;
  height: 24px;
  border-radius: 30px;
  border: 1px solid #555;
  background-color: hsl(222, 14%, 7%);
  position: relative;
  transition: all 0.2s ease;
}
.theme-switch-icon {
  position: absolute;
  width: 17px;
  height: 17px;
  top: 0; bottom: 0;
  margin: auto 0;
  line-height: 0;
  transition: opacity 0.25s ease;
}
.theme-switch-icon--light {
  left: 5px;
  opacity: 0;
}
.theme-switch-icon--dark {
  right: 5px;
  opacity: 1;
}
.theme-switch.active .theme-switch-icon--light { opacity: 1; }
.theme-switch.active .theme-switch-icon--dark { opacity: 0; }
.theme-switch-thumb {
  position: absolute;
  top: 1px;
  left: 1px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #fafafa;
  transition: all 0.3s cubic-bezier(0.23, 1, 0.32, 1) 0ms;
  transform: translateX(0);
}
.theme-switch.active .theme-switch-thumb {
  transform: translateX(26px);
}

/* --- Sidebar --- */
.layout-with-sidebar {
  display: flex;
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 15px;
  gap: 2rem;
}
.layout-with-sidebar > .wrapper {
  flex: 1;
  min-width: 0;
  max-width: none;
  padding: 0;
}
.post-sidebar {
  width: 200px;
  flex-shrink: 0;
  position: sticky;
  top: 20px;
  align-self: flex-start;
  padding-top: 30px;
}
.post-sidebar h3 {
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.8rem;
  color: #555;
}
.post-sidebar ul {
  list-style: none;
  margin: 0;
  padding: 0;
}
.post-sidebar li {
  margin-bottom: 0.6rem;
}
.post-sidebar li a {
  font-size: 0.85rem;
  text-decoration: none;
}
.post-sidebar li.current a {
  font-weight: bold;
}
.post-sidebar .sidebar-date {
  display: block;
  font-size: 0.7rem;
  color: #999;
}
/* Dark mode sidebar */
body.dark .post-sidebar h3 { color: #888; }
body.dark .post-sidebar li a { color: #5bf; }
body.dark .post-sidebar li a:visited { color: #6bf; }
body.dark .post-sidebar .sidebar-date { color: #666; }

/* Header Posts button — hidden on desktop, visible on mobile */
.posts-bar-trigger { display: none; }

/* Bottom sheet (dialog) — hidden on desktop */
.posts-sheet { display: none; }

/* Mobile */
@media screen and (max-width: 768px) {
  .layout-with-sidebar {
    display: block;
    padding: 0 15px;
  }
  .post-sidebar {
    display: none;
  }
  .posts-bar-trigger {
    display: inline-block;
    background: none;
    border: 1px solid #555;
    color: #ddd;
    padding: 4px 12px;
    border-radius: 4px;
    font-size: 0.8rem;
    cursor: pointer;
    margin-left: 12px;
    vertical-align: middle;
  }
  body:not(.dark) .posts-bar-trigger {
    border-color: #ccc;
    color: #333;
  }
  .posts-sheet {
    display: block;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    top: auto;
    margin: 0;
    max-height: 60vh;
    width: 100%;
    max-width: 100%;
    border: none;
    border-radius: 12px 12px 0 0;
    background: #1a1a1a;
    color: #ddd;
    padding: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    transform: translateY(100%);
    transition: transform 0.25s ease;
  }
  .posts-sheet[open] {
    transform: translateY(0);
  }
  @starting-style {
    .posts-sheet[open] { transform: translateY(100%); }
  }
  .posts-sheet::backdrop {
    background: rgba(0,0,0,0.5);
    opacity: 0;
    transition: opacity 0.25s;
  }
  .posts-sheet[open]::backdrop {
    opacity: 1;
  }
  @starting-style {
    .posts-sheet[open]::backdrop { opacity: 0; }
  }
  .posts-sheet-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 16px 10px;
    font-weight: bold;
    font-size: 0.95rem;
    border-bottom: 1px solid #333;
    position: relative;
  }
  .posts-sheet-header::before {
    content: '';
    position: absolute;
    top: 6px;
    left: 50%;
    transform: translateX(-50%);
    width: 32px;
    height: 4px;
    border-radius: 2px;
    background: #555;
  }
  .posts-sheet-close {
    background: none;
    border: none;
    color: #999;
    font-size: 1.4rem;
    cursor: pointer;
    padding: 0 4px;
    line-height: 1;
  }
  .posts-sheet-list {
    list-style: none;
    margin: 0;
    padding: 8px 0 calc(env(safe-area-inset-bottom, 0px) + 8px);
  }
  .posts-sheet-list li a {
    display: block;
    padding: 12px 16px 4px;
    text-decoration: none;
    color: #5bf;
    font-size: 0.9rem;
  }
  .posts-sheet-list li.current a {
    font-weight: bold;
    color: #fff;
  }
  .posts-sheet-list .posts-sheet-date {
    display: block;
    padding: 0 16px 8px;
    font-size: 0.7rem;
    color: #666;
  }
  /* Light mode sheet */
  body:not(.dark) .posts-sheet {
    background: #fff;
    color: #333;
  }
  body:not(.dark) .posts-sheet-header { border-bottom-color: #eee; }
  body:not(.dark) .posts-sheet-header::before { background: #ccc; }
  body:not(.dark) .posts-sheet-list li a { color: #0066cc; }
  body:not(.dark) .posts-sheet-list li.current a { color: #000; }
  body:not(.dark) .posts-sheet-list .posts-sheet-date { color: #999; }
}
