/* Legal / help document pages */

.page--legal {
  /* Document scroll — sticky footer at bottom when content is short */
  display: flex;
  flex-direction: column;
  min-height: 100svh;
  min-height: 100dvh;
  align-content: start;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.page--legal .logo {
  cursor: pointer;
}

.page--legal .footer .contact a,
.legal-body a,
.help-body a {
  text-decoration: underline;
  text-underline-offset: 2px;
}

.page--legal .legal-layout,
.page--legal .help-layout {
  flex: 1 1 auto;
}

.page--legal .footer {
  position: relative;
  left: auto;
  right: auto;
  bottom: auto;
  margin-top: auto;
  flex: 0 0 auto;
  z-index: 2;
}

.legal-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: clamp(2rem, 6vw, 5rem);
  align-items: start;
  width: 100%;
  max-width: none;
  margin: 0;
  padding: clamp(28px, 5vh, 48px) 0 clamp(48px, 8vh, 80px);
  min-height: 0;
}

.legal-article {
  min-width: 0;
  max-width: 38rem;
}

.legal-title {
  font-size: clamp(20pt, 3vw, 26pt);
  font-weight: var(--weight-black);
  letter-spacing: -0.04em;
  line-height: 1.1;
  margin: 0 0 10px;
}

.legal-meta {
  font-size: var(--type-meta-size);
  font-weight: var(--weight-regular);
  color: var(--color-text-muted);
  letter-spacing: 0;
  line-height: 1.4;
  margin: 0 0 18px;
}

.legal-rule {
  border: 0;
  border-top: 1px solid #e8e8e8;
  margin: 0 0 28px;
}

.legal-section {
  margin: 0 0 1.55rem;
}

.legal-section:last-child {
  margin-bottom: 0;
}

.legal-heading {
  font-size: 13pt;
  font-weight: var(--weight-bold);
  letter-spacing: -0.02em;
  line-height: 1.3;
  margin: 0 0 8px;
}

.legal-body {
  font-size: 11pt;
  font-weight: var(--weight-regular);
  letter-spacing: -0.01em;
  line-height: 1.55;
  color: var(--color-text);
}

.legal-body p {
  margin: 0 0 0.75em;
}

.legal-body p:last-child {
  margin-bottom: 0;
}

.legal-body strong {
  font-weight: var(--weight-semibold);
}

.legal-body code {
  font-size: 0.92em;
  letter-spacing: 0;
}

.legal-list {
  margin: 0 0 0.85em;
  padding-left: 1.25em;
  list-style: disc;
}

.legal-list li {
  margin: 0 0 0.4em;
  padding-left: 0.15em;
}

.legal-list li:last-child {
  margin-bottom: 0;
}

.legal-list:last-child {
  margin-bottom: 0;
}

.legal-table-wrap {
  width: 100%;
  overflow-x: auto;
  margin: 0 0 0.85em;
  -webkit-overflow-scrolling: touch;
}

.legal-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 10.5pt;
  line-height: 1.45;
}

.legal-table th,
.legal-table td {
  text-align: left;
  vertical-align: top;
  padding: 0.45em 0.75em 0.45em 0;
  border-bottom: 1px solid #ececec;
}

.legal-table th {
  font-weight: var(--weight-bold);
  white-space: nowrap;
  padding-right: 1rem;
}

.legal-table td:first-child,
.legal-table th:first-child {
  min-width: 6.5rem;
}

.legal-table-wrap:last-child {
  margin-bottom: 0;
}

.legal-subheading {
  font-size: 11pt;
  font-weight: var(--weight-bold);
  letter-spacing: -0.01em;
  line-height: 1.4;
  margin: 0.85em 0 0.4em;
}

.legal-body > .legal-subheading:first-child {
  margin-top: 0;
}

/* Right-align with primary nav ("how to") */
.legal-side {
  position: sticky;
  top: var(--page-pad-y);
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 10px;
  padding-top: 4px;
  flex-shrink: 0;
  text-align: right;
  justify-self: end;
}

.legal-side-link {
  font-size: var(--type-nav-size);
  font-weight: var(--weight-semibold);
  letter-spacing: var(--type-nav-tracking);
  line-height: 1.2;
  color: var(--color-text-muted);
  white-space: nowrap;
}

.legal-side-link.is-active {
  color: var(--color-text);
  font-weight: var(--weight-bold);
  text-decoration: none;
}

.legal-side-link:hover {
  color: var(--color-text);
}

/* Tablet homepage pins footer fixed — keep legal/help footer in document flow */
@media (max-width: 940px) {
  .page--legal.page {
    padding-bottom: calc(
      var(--page-pad-y) + env(safe-area-inset-bottom, 0px)
    );
  }

  .page--legal .footer {
    position: relative;
    left: auto;
    right: auto;
    bottom: auto;
    z-index: 2;
    padding: 0;
    background: transparent;
    pointer-events: none;
  }

  .page--legal .footer .credit,
  .page--legal .footer .meta,
  .page--legal .footer .date,
  .page--legal .footer .contact {
    pointer-events: auto;
  }
}

/* Phone — match homepage wordmark placement (centered under menu row) */
@media (max-width: 720px) {
  .page--legal.page {
    --phone-edge-x: 20px;
    --phone-edge-top: calc(20px - 3pt);
    --phone-edge-bottom: calc(20px - 3pt);
    --phone-menu-row: calc(28px - 4pt);
    --phone-min-menu-clearance: 12pt;
    --phone-min-footer-clearance: 22pt;

    display: flex;
    flex-direction: column;
    grid-template-rows: none;
    height: auto;
    max-height: none;
    min-height: 100svh;
    min-height: 100dvh;
    overflow-x: hidden;
    overflow-y: auto;
    padding: calc(
        env(safe-area-inset-top, 0px) + var(--phone-edge-top) +
          var(--phone-menu-row)
      )
      var(--phone-edge-x)
      calc(var(--phone-edge-bottom) + env(safe-area-inset-bottom, 0px));
  }

  /* Homepage uses flex spacers; keep a fixed top clearance so logo Y matches
     the homepage wordmark when the well stack is on screen (spacer ≈ min). */
  .page--legal.page::before {
    content: "";
    display: block;
    flex: 0 0 auto;
    order: 1;
    min-height: var(--phone-min-menu-clearance);
    height: var(--phone-min-menu-clearance);
    pointer-events: none;
  }

  .page--legal.page::after {
    content: none;
    display: none;
  }

  .page--legal .header {
    order: 2;
    position: static;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    flex: 0 0 auto;
    min-height: 0;
  }

  .page--legal .logo {
    display: block;
    width: fit-content;
    margin: 0 auto;
    font-size: 28pt;
  }

  .page--legal .menu-toggle {
    display: flex;
    position: absolute;
    top: calc(var(--phone-edge-top) + env(safe-area-inset-top, 0px));
    right: var(--phone-edge-x);
    z-index: 5;
  }

  .page--legal .nav {
    position: absolute;
    top: calc(var(--phone-edge-top) + env(safe-area-inset-top, 0px));
    left: 0;
    right: 0;
    width: 100%;
    justify-content: center;
    padding: 6px 40px;
    background: var(--color-bg);
    z-index: 4;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transform: translateX(16px);
    transition:
      opacity 0.28s ease,
      transform 0.32s cubic-bezier(0.4, 0, 0.2, 1),
      visibility 0.32s;
  }

  .page--legal .nav.is-open {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transform: translateX(0);
  }

  .page--legal .legal-layout {
    order: 3;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    padding: 24px 0 40px;
    max-width: none;
  }

  .page--legal .legal-side {
    position: static;
    order: -1;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: flex-start;
    justify-content: flex-start;
    gap: 0.75rem 1.1rem;
    padding-top: 0;
    text-align: left;
    justify-self: start;
  }

  .page--legal .legal-article {
    max-width: none;
  }

  .page--legal .legal-title {
    font-size: 20pt;
  }

  .page--legal .footer {
    order: 4;
    position: relative;
    left: auto;
    right: auto;
    bottom: auto;
    margin-top: auto;
    flex: 0 0 auto;
    padding: 0;
    pointer-events: none;
  }

  .page--legal .footer .credit,
  .page--legal .footer .meta,
  .page--legal .footer .date,
  .page--legal .footer .contact {
    pointer-events: auto;
  }
}
