:root {
  --rail-width: 8rem;
  --rail-gap: 3rem;
}

.site-shell {
  display: grid;
  grid-template-columns: var(--rail-width) minmax(0, var(--content-width));
  column-gap: var(--rail-gap);
  align-items: start;
  width: min(100%, calc(var(--rail-width) + var(--rail-gap) + var(--content-width)));
  margin: 0 auto;
}

body[data-centered='false'] .site-shell {
  margin-left: 0;
}

.layout-wrapper {
  width: 100%;
  min-width: 0;
}

.site-rail {
  position: sticky;
  top: 3.5rem;
  width: var(--rail-width);
  min-width: 0;
  z-index: 10;
  view-transition-name: serein-rail;
}

.rail-header {
  min-height: 1.75rem;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
}

.rail-brand {
  font-family: var(--sans);
  color: var(--text-primary);
  font-weight: var(--font-weight-bold);
  text-decoration: none;
}

.rail-toggle {
  display: none;
  appearance: none;
  border: 0;
  padding: 0;
  background: transparent;
  color: var(--text-secondary);
  font: inherit;
  font-family: var(--serif);
  letter-spacing: 0;
  cursor: pointer;
}

.rail-panel {
  margin-top: 2.5rem;
}

.site-nav {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.35rem;
  font-family: var(--serif);
}

.site-nav a {
  position: relative;
  color: var(--text-secondary);
  text-decoration: none;
  transition:
    color 0.15s ease-out,
    transform 0.15s ease-out;
}

.site-nav a:hover,
.site-nav a[aria-current='page'] {
  color: var(--text-primary);
  transform: translateX(0.2rem);
}

.site-nav a[aria-current='page'] {
  font-family: var(--serif);
  letter-spacing: 0;
}

.toc-container {
  width: 100%;
  margin-top: 3rem;
  opacity: 1;
}

.toc-nav {
  display: block;
  width: 100%; /* Keep hover labels within the full TOC rail. */
  font-family: var(--serif);
}

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

.toc-list {
  display: block;
  width: 100%;
}

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

.toc-item::before,
.toc-item::marker {
  display: none !important;
}

.toc-link {
  display: block;
  color: transparent;
  text-decoration: none;
  position: relative;
  height: 1.125rem;
  width: 100%;
  min-height: 1rem;
  font-size: 0;
  line-height: 1.125rem;
  text-indent: 2rem;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  cursor: pointer;
}

.toc-link::after {
  content: attr(data-text);
  position: absolute;
  left: 2rem;
  top: 0;
  max-width: calc(100% - 2rem);
  overflow: hidden;
  color: var(--text-primary);
  font-family: var(--serif);
  font-size: var(--font-size-s);
  letter-spacing: var(--spacing-m);
  line-height: 1.125rem;
  opacity: 0;
  pointer-events: none;
  text-overflow: ellipsis;
  text-indent: 0;
  white-space: nowrap;
  transition:
    opacity 0.2s ease-out,
    left 0.2s ease-out;
}

.toc-link:hover::after,
.toc-link:focus-visible::after {
  left: 1.25rem;
  opacity: 1;
}

.toc-level-0 > .toc-link:hover::after,
.toc-level-0 > .toc-link:focus-visible::after {
  opacity: 0;
}

.toc-link::before {
  content: '';
  position: absolute;
  left: 0;
  top: 50%;
  width: 1.75rem;
  height: 1px;
  background-color: var(--text-tertiary);
  transform: translateY(-50%);
  opacity: 0.4;
  transition:
    width 0.1s ease-out,
    opacity 0.1s ease-out,
    background-color 0.1s ease-out;
}

.toc-item:not(.toc-level-0) > .toc-link:hover::before,
.toc-item:not(.toc-level-0) > .toc-link:focus-visible::before {
  width: 0.75rem;
}

.toc-link:hover::before,
.toc-link:focus-visible::before,
.toc-link.active::before {
  opacity: 0.8;
  background-color: var(--text-primary);
}

html[data-toc-style='text'] .toc-container {
  margin-top: 2.5rem;
}

html[data-toc-style='text'] .toc-link {
  width: 100%;
  height: auto;
  min-height: 0;
  color: var(--text-secondary);
  font-size: var(--font-size-s);
  line-height: 1.5;
  text-indent: 0;
  text-overflow: ellipsis;
}

html[data-toc-style='text'] .toc-link::before,
html[data-toc-style='text'] .toc-link::after {
  display: none;
}

html[data-toc-style='text'] .toc-link:hover,
html[data-toc-style='text'] .toc-link:focus-visible,
html[data-toc-style='text'] .toc-link.active {
  color: var(--text-primary);
}

html[data-toc-style='text'] .toc-title {
  margin-bottom: 0.5rem;
  font-family: var(--serif);
  letter-spacing: 0;
}

html[data-toc-style='text'] .toc-level-3 > .toc-link {
  padding-left: 0.75rem;
}

html[data-toc-style='text'] .toc-level-4 > .toc-link {
  padding-left: 1.5rem;
}

.rail-fallback {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  margin-top: 3rem;
  color: var(--text-secondary);
  font-size: var(--font-size-s);
}

.rail-fallback strong {
  max-width: 100%;
  overflow: hidden;
  color: var(--text-primary);
  font-size: var(--font-size-s);
  font-weight: var(--font-weight-regular);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.rail-fallback time {
  font-variant-numeric: tabular-nums;
}

@media (max-width: 900px) {
  :root {
    --rail-gap: 0;
  }

  .site-shell {
    display: block;
    width: 100%;
  }

  .site-rail {
    position: relative;
    top: auto;
    width: 100%;
    margin-bottom: 2.5rem;
  }

  .rail-toggle {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
  }

  .rail-toggle::after {
    content: '';
    width: 0.35rem;
    height: 0.35rem;
    border-right: 1px solid currentColor;
    border-bottom: 1px solid currentColor;
    transform: rotate(45deg) translateY(-0.1rem);
    transition: transform 0.15s ease-out;
  }

  .rail-toggle[aria-expanded='true']::after {
    transform: rotate(225deg) translate(-0.1rem, -0.1rem);
  }

  .rail-panel {
    display: none;
    max-height: min(55vh, 22rem);
    margin-top: 0.75rem;
    padding: 0.75rem 0;
    border-bottom: 1px solid var(--border);
    overflow-y: auto;
    overscroll-behavior: contain;
  }

  .rail-panel[data-open='true'] {
    display: block;
  }

  .site-nav {
    gap: 0.5rem;
  }

  .site-nav a:hover,
  .site-nav a[aria-current='page'] {
    transform: none;
  }

  .toc-container {
    margin-top: 0;
  }

  .toc-link {
    width: 100%;
    height: auto;
    min-height: 0;
    padding: 0.2rem 0;
    color: var(--text-secondary);
    font-size: var(--font-size-s);
    line-height: 1.45;
    text-indent: 0;
    white-space: normal;
  }

  .toc-link::before,
  .toc-link::after {
    display: none;
  }

  .toc-link:hover,
  .toc-link:focus-visible,
  .toc-link.active {
    color: var(--text-primary);
  }

  .toc-title {
    margin-bottom: 0.35rem;
  }

  .toc-level-3 > .toc-link {
    padding-left: 0.75rem;
  }

  .toc-level-4 > .toc-link {
    padding-left: 1.5rem;
  }

  .rail-fallback {
    margin-top: 0;
  }
}

@media (max-width: 768px) {
  .site-rail {
    margin-bottom: 2rem;
  }
}
