:root {
  --long-form-header-offset: 6.75rem;
  --long-form-rail-width: clamp(13.5rem, 18vw, 16rem);
}

[data-long-form-layout="rail"] {
  display: grid;
  grid-template-columns: var(--long-form-rail-width) minmax(0, 1fr);
  gap: clamp(1.75rem, 4vw, 3.5rem);
  align-items: start;
}

[data-long-form-layout="rail"] > .long-form-toc {
  grid-column: 1;
  grid-row: 1;
}

[data-long-form-layout="rail"] > :not(.long-form-toc) {
  grid-column: 2;
  min-width: 0;
}

.long-form-toc {
  position: sticky;
  top: var(--long-form-header-offset);
  z-index: 40;
  align-self: start;
  color: var(--ds-text, #17233f);
}

.long-form-toc details {
  overflow: hidden;
  border: 1px solid var(--ds-border, #d4dce7);
  border-radius: var(--ds-radius-md, 0.75rem);
  background: var(--ds-surface, #fff);
  box-shadow: 0 10px 30px rgba(13, 31, 60, 0.08);
}

.long-form-toc summary {
  display: flex;
  min-height: 44px;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.8rem 1rem;
  color: var(--ds-text, #17233f);
  cursor: pointer;
  font-weight: 800;
  list-style: none;
}

.long-form-toc summary::-webkit-details-marker {
  display: none;
}

.long-form-toc summary::after {
  content: "+";
  color: var(--ds-accent, #b84716);
  font-size: 1.25rem;
  line-height: 1;
}

.long-form-toc details[open] summary::after {
  content: "−";
}

.long-form-toc summary:focus-visible,
.long-form-toc a:focus-visible,
.long-form-table-region:focus-visible,
.long-form-decision-action a:focus-visible {
  outline: 3px solid var(--ds-focus, #f5a623);
  outline-offset: 3px;
}

.long-form-toc nav {
  max-height: calc(100vh - 12rem);
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 0 0.55rem 0.8rem;
  scrollbar-width: thin;
}

.long-form-toc ol {
  display: grid;
  gap: 0.15rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.long-form-toc a {
  display: block;
  border-left: 3px solid transparent;
  border-radius: 0.35rem;
  padding: 0.5rem 0.65rem;
  color: var(--ds-text-muted, #536176);
  font-size: 0.84rem;
  font-weight: 650;
  line-height: 1.35;
  text-decoration: none;
}

.long-form-toc a:hover,
.long-form-toc a[aria-current="location"] {
  border-left-color: var(--ds-accent, #b84716);
  background: rgba(184, 71, 22, 0.08);
  color: var(--ds-text, #17233f);
}

.long-form-toc--home {
  top: 4.5rem;
  width: 100%;
  padding: 0.7rem clamp(1rem, 4vw, 3rem);
  pointer-events: none;
}

.long-form-toc--home details {
  position: relative;
  width: min(22rem, 100%);
  margin-inline: auto;
  overflow: visible;
  pointer-events: auto;
}

.long-form-toc--home nav {
  position: absolute;
  z-index: 50;
  top: calc(100% + 0.45rem);
  left: 0;
  width: min(30rem, calc(100vw - 2rem));
  max-height: min(25rem, 58vh);
  padding: 0.55rem;
  border: 1px solid var(--ds-border, #d4dce7);
  border-radius: var(--ds-radius-md, 0.75rem);
  background: var(--ds-surface, #fff);
  box-shadow: 0 18px 46px rgba(13, 31, 60, 0.17);
}

.long-form-toc--home ol {
  grid-template-columns: 1fr;
}

[data-long-form-content] :where(p, ul, ol, blockquote, dl) {
  max-inline-size: 68ch;
}

[data-long-form-content] > article.panel {
  padding: clamp(1.5rem, 3vw, 2.25rem);
}

[data-long-form-content] article.panel :where(h2) {
  margin-block: 2rem 0.75rem;
  font-size: clamp(1.55rem, 2.2vw, 2rem);
  line-height: 1.25;
}

[data-long-form-content] article.panel :where(p, li, dd) {
  line-height: 1.6;
}

[data-long-form-content] article.panel p {
  margin-block: 0.75rem;
}

[data-long-form-content] :where(h2, h3)[id] {
  scroll-margin-top: calc(var(--long-form-header-offset) + 1.25rem);
}

[data-long-form-layout="home"] :where(h2, h3)[id] {
  scroll-margin-top: 10.5rem;
}

.long-form-table-region {
  max-width: 100%;
  margin-block: 1.25rem;
  overflow-x: auto;
  overscroll-behavior-inline: contain;
  border-radius: var(--ds-radius-md, 0.75rem);
  -webkit-overflow-scrolling: touch;
}

.long-form-table-region table {
  width: 100%;
  min-width: 42rem;
  margin: 0;
}

.long-form-decision-action {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 1rem;
  align-items: center;
  max-width: 68rem;
  margin: 1.5rem auto 2rem;
  padding: 1rem 1.15rem;
  border: 1px solid rgba(184, 71, 22, 0.28);
  border-radius: var(--ds-radius-md, 0.75rem);
  background: #fff7f2;
}

.long-form-decision-action p {
  max-width: 68ch;
  margin: 0;
  color: var(--ds-text, #17233f);
}

.long-form-decision-action a {
  display: inline-flex;
  min-height: 44px;
  align-items: center;
  justify-content: center;
  padding: 0.7rem 1rem;
  border-radius: var(--ds-radius-sm, 0.5rem);
  background: var(--ds-accent, #b84716);
  color: #fff;
  font-weight: 800;
  text-decoration: none;
  white-space: nowrap;
}

.long-form-secondary-detail {
  max-width: 68ch;
  margin-block: 0.75rem;
  overflow: hidden;
  border: 1px solid var(--ds-border, #d4dce7);
  border-radius: var(--ds-radius-md, 0.75rem);
  background: var(--ds-surface, #fff);
}

.long-form-secondary-detail summary {
  display: flex;
  min-height: 44px;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.8rem 1rem;
  cursor: pointer;
  font-weight: 800;
}

.long-form-secondary-detail summary::after {
  content: "+";
  color: var(--ds-accent, #b84716);
  font-size: 1.2rem;
}

.long-form-secondary-detail[open] summary::after {
  content: "−";
}

.long-form-secondary-detail__body {
  padding: 0 1rem 1rem;
}

@media (max-width: 63.99rem) {
  :root {
    --long-form-header-offset: 6rem;
  }

  [data-long-form-layout="rail"] {
    display: block;
  }

  .long-form-toc,
  .long-form-toc--home {
    position: relative;
    top: auto;
    z-index: 1;
    width: auto;
    margin: 0 0 1.5rem;
    padding: 0;
    background: transparent;
    box-shadow: none;
    backdrop-filter: none;
  }

  .long-form-toc nav,
  .long-form-toc--home nav {
    max-height: min(55vh, 28rem);
  }

  .long-form-toc--home ol {
    grid-template-columns: 1fr;
  }

  [data-long-form-layout="home"] :where(h2, h3)[id] {
    scroll-margin-top: var(--long-form-header-offset);
  }

  .long-form-decision-action {
    grid-template-columns: 1fr;
  }

  .long-form-decision-action a {
    width: 100%;
  }
}

@media (max-width: 24rem) {
  .long-form-toc a {
    padding-block: 0.6rem;
    font-size: 0.9rem;
  }

  .long-form-table-region table {
    min-width: 36rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  [data-long-form-page] {
    scroll-behavior: auto;
  }
}
