:root {
  --bg: #ffffff;
  --text: #2e3440;
  --muted: #6b7280;
  --accent: #E2494C;
  --accent-rgb: 226, 73, 76;
  --content-max-width: 1200px;
  --toc-width: 180px;
  --toc-gap: 3rem;
}

:root, body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell,
               "Helvetica Neue", Helvetica, Arial, "Noto Sans", "Apple SD Gothic Neo", sans-serif,
               "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Justify paragraphs */
p {
  text-align: justify;
  text-justify: inter-word;
}

/* Apply background/text */
html, body { background: var(--bg); color: var(--text); }

a { color: var(--accent); }
a:hover { opacity: .9; }

main {
  max-width: var(--content-max-width);
  margin: 0 auto;
  width: 100%;
}

#nav-bar a { color: var(--text); opacity: .8; }
#nav-bar a.active { color: var(--accent); opacity: 1; }
#nav-bar a:hover { opacity: 1; }

h1, h2, h3 { color: var(--text); }
h1 { letter-spacing: -0.01em; }

pre, code { font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; }

/* Inline code highlighting */
:not(pre) > code {
  background-color: #e5e7eb;
  color: #D7494C;
  padding: 0.125rem 0.25rem;
  border-radius: 0.25rem;
}

/* Code block styling */
pre {
  padding: 1rem;
  border-radius: 0.5rem;
  overflow-x: auto;
  line-height: 1.5;
  background-color: #f5f5f5 !important;
}

pre code {
  background: none !important;
  color: inherit;
  padding: 0;
  font-size: 0.875rem;
}


/* Footnote back-reference styling */
.footnote-backref {
  color: var(--accent);
  text-decoration: none;
  margin-left: 0.25rem;
  font-size: 1rem;
  font-weight: bold;
  transition: transform 0.2s ease;
  display: inline-block;
}

.footnote-backref:hover {
  transform: scale(1.3);
  text-decoration: none;
}

sup.footnote-reference {
  transition: background-color 0.3s ease, color 0.3s ease;
  padding: 0.1rem 0.2rem;
  border-radius: 0.2rem;
}

.sidebar-toc {
  flex: 0 0 var(--toc-width);
  position: sticky;
  top: 2rem;
  max-height: calc(100vh - 4rem);
  overflow-y: auto;
  padding: 0.2rem;
  background: var(--bg);
  border-right: 1px solid var(--muted);
  border-left: 0;
  margin-left: calc(-1 * (var(--toc-width) + var(--toc-gap)));
  margin-right: var(--toc-gap);
  opacity: 0.9;
}

.article-with-sidebar {
  display: flex;
  align-items: flex-start;
  margin: 0;
  padding-left: 0.5rem;
  padding-right: 0.0rem;
  gap: 0;
  width: 100%;
  font-size: 1.0rem;
}

.post-with-toc {
  flex: 1 1 auto;
  max-width: none;
  margin-right: 0;
  min-width: 0;
}

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

.sidebar-toc:hover {
  opacity: 1;
}

.sidebar-toc::-webkit-scrollbar {
  width: 4px;
}

.sidebar-toc::-webkit-scrollbar-track {
  background: transparent;
}

.sidebar-toc::-webkit-scrollbar-thumb {
  background: var(--muted);
  border-radius: 2px;
}

.sidebar-toc::-webkit-scrollbar-thumb:hover {
  background: var(--accent);
}

.toc-title {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text);
  margin: 0 0 0.75rem 0;
  padding-bottom: 0.4rem;
  border-bottom: 2px solid var(--accent);
}

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

.toc-item {
  margin: 0;
  line-height: 1.6;
}

.toc-h1 {
  margin-bottom: 0.6rem;
}

.toc-h1 > a {
  font-weight: 500;
  font-size: 0.6rem;
}

.toc-sublist {
  list-style: none;
  padding-left: 0.875rem;
  margin: 0.2rem 0 0.4rem 0;
}

.toc-h2 > a {
  font-size: 0.6rem;
  color: var(--muted);
}

.toc-h3 > a,
.toc-h4 > a,
.toc-h5 > a,
.toc-h6 > a {
  font-size: 0.55rem;
  color: var(--muted);
  opacity: 0.9;
}

.toc-item a {
  display: block;
  padding: 0.2rem 0.4rem;
  color: var(--text);
  text-decoration: none;
  border-left: 2px solid transparent;
  transition: all 0.2s ease;
}

.toc-item a:hover {
  color: var(--accent);
  border-left-color: var(--accent);
  background: rgba(var(--accent-rgb), 0.05);
}

.toc-item a.active {
  color: var(--accent);
  border-left-color: var(--accent);
  background: rgba(var(--accent-rgb), 0.1);
  font-weight: 500;
}

/* Focus states for accessibility */
.toc-item a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

@media (max-width: 1024px) {
  .sidebar-toc {
    display: none;
  }

  .post-with-toc {
    max-width: 100%;
  }
}

/* Mobile optimization */
@media (max-width: 768px) {
  .article-with-sidebar {
    padding: 0 1rem;
  }
}

