/* The Agora Document — civic, readable, minimal */

:root {
  --text: #1a1a1a;
  --link: #2c5282;
  --link-visited: #553c9a;
  --border: #e2e8f0;
  --bg: #fff;
  --measure: 65ch;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  font-size: 100%;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  font-family: "Public Sans", system-ui, sans-serif;
  font-weight: 400;
  line-height: 1.6;
  color: var(--text);
  background: var(--bg);
}

/* Layout */
.site-header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  padding: 0.75rem 1rem;
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.75rem 1.25rem;
}

.site-title {
  font-size: 0.9375rem;
  font-weight: 600;
  color: #2d3748;
  text-decoration: none;
  letter-spacing: 0.02em;
  padding-right: 0.5rem;
}

.site-title:hover {
  color: var(--text);
}

.site-title:focus {
  outline: 2px solid var(--link);
  outline-offset: 4px;
}

/* Desktop: inline TOC visible; mobile drawer and back-to-top hidden */
.toc-desktop {
  display: flex;
}

.toc-box {
  display: none;
}

.toc-summary {
  display: none;
}

.back-to-top {
  display: none;
}

@media (min-width: 769px) {
  .toc-box {
    display: none;
  }
}

.document {
  flex: 1;
  max-width: var(--measure);
  margin: 0 auto;
  padding: 1.5rem 1.5rem 3rem;
  width: 100%;
  min-height: 0;
}

.site-footer {
  width: 100%;
  margin-top: auto;
  padding: 1.5rem 1.5rem 2rem;
  border-top: 1px solid var(--border);
  font-size: 0.9375rem;
  color: #4a5568;
}

.site-footer-inner {
  max-width: var(--measure);
  margin: 0 auto;
}

/* TOC */
.toc {
  flex: 1;
  min-width: 0;
}

.toc ol {
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1.25rem;
}

.toc a {
  color: var(--link);
  text-decoration: none;
}

.toc a:hover {
  text-decoration: underline;
}

.toc a:focus {
  outline: 2px solid var(--link);
  outline-offset: 4px;
}

/* Mobile: minimal sticky header = title + boxed TOC + back-to-top */
@media (max-width: 768px) {
  .site-header {
    position: sticky;
    top: 0;
    flex-wrap: nowrap;
    align-items: center;
    padding: 0.5rem 0.75rem;
    gap: 0.5rem;
    min-height: auto;
  }

  .site-title {
    display: block;
    font-size: 0.8125rem;
    flex-shrink: 0;
    white-space: nowrap;
  }

  .toc-desktop {
    display: none;
  }

  .toc-box {
    display: block;
    flex: 1;
    min-width: 0;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--bg);
  }

  .toc-summary {
    display: block;
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--link);
    padding: 0.4rem 0.6rem;
    cursor: pointer;
    list-style: none;
  }

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

  .toc-summary::after {
    content: " ▾";
    font-size: 0.75em;
    opacity: 0.8;
  }

  .toc-box[open] .toc-summary::after {
    content: " ▴";
  }

  .toc-box .toc-mobile {
    flex: none;
    padding: 0.5rem 0.6rem 0.6rem;
    border-top: 1px solid var(--border);
  }

  .toc-box .toc-mobile ol {
    flex-direction: column;
    gap: 0.25rem;
  }

  .toc-box .toc-mobile li {
    margin: 0;
  }

  .back-to-top {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 2.25rem;
    height: 2.25rem;
    flex-shrink: 0;
    font-size: 1.25rem;
    line-height: 1;
    color: var(--link);
    text-decoration: none;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--bg);
  }

  .back-to-top:hover {
    color: var(--text);
    background: #f7fafc;
  }

  .back-to-top:focus {
    outline: 2px solid var(--link);
    outline-offset: 2px;
  }

  .document {
    padding: 1rem 1rem 2rem;
    flex: 1;
    min-height: 0;
  }

  .document h2,
  .document h3 {
    scroll-margin-top: 1rem;
  }

  .site-footer {
    padding: 1rem 1rem 1.5rem;
    font-size: 0.875rem;
  }
}

/* Document typography */
.document h1 {
  font-size: 1.75rem;
  font-weight: 700;
  margin: 0 0 0.25em;
  line-height: 1.25;
}

.document h2 {
  font-size: 1.375rem;
  font-weight: 700;
  margin: 2.5em 0 0.75em;
  padding-top: 0.5em;
  scroll-margin-top: 5rem;
}

.document h2:first-of-type {
  margin-top: 0;
  padding-top: 0;
}

.document h3 {
  font-size: 1.125rem;
  font-weight: 600;
  margin: 1.5em 0 0.5em;
  scroll-margin-top: 5rem;
}

.document p {
  margin: 0 0 1em;
}

.document ul,
.document ol {
  margin: 0 0 1em;
  padding-left: 1.5em;
}

.document li {
  margin: 0.25em 0;
}

.document hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 2.5em 0;
}

.document strong {
  font-weight: 600;
}

.document a {
  color: var(--link);
  text-decoration: underline;
  text-underline-offset: 0.15em;
}

.document a:visited {
  color: var(--link-visited);
}

.document a:hover {
  text-decoration-thickness: 2px;
}

.document a:focus {
  outline: 2px solid var(--link);
  outline-offset: 4px;
}

/* Subtitle / draft line under title */
.document h1 + h3,
.document h1 + p {
  margin-top: 0;
  font-size: 1rem;
  font-weight: 400;
  color: #4a5568;
}

/* Footer links */
.site-footer a {
  color: var(--link);
  text-decoration: none;
}

.site-footer a:hover {
  text-decoration: underline;
}

.site-footer p {
  margin: 0;
}

.site-footer p.site-credit {
  margin-top: 0.75rem;
}

.site-credit .py1 {
  padding-block: 0.25rem;
}

.site-credit a {
  font-size: 1em;
}

/* Reduce motion */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
