:root {
  --accent: #2a6db5;
  --bg: #ffffff;
  --bg-code: #f0f2f4;
  --bg-subtle: #f5f6f8;
  --border: #d0d4d8;
  --header-bg: #2b2d42;
  --header-text: #f1f1f1;
  --link: #1a5ca0;
  --link-hover: #0e3d6b;
  --link-visited: #5b3a8c;
  --nav-active: #dce3ed;
  --nav-hover: #e2e5ea;
  --text: #1a1a1a;
  --text-secondary: #555;
}

@media (prefers-color-scheme: dark) {
  :root {
    --accent: #6eb0e6;
    --bg: #1a1b26;
    --bg-code: #272838;
    --bg-subtle: #222337;
    --border: #3a3c50;
    --header-bg: #151621;
    --header-text: #d8dae0;
    --link: #6eb0e6;
    --link-hover: #9ccbf5;
    --link-visited: #b89ee6;
    --nav-active: #343660;
    --nav-hover: #2e3048;
    --text: #d8dae0;
    --text-secondary: #999;
  }
}

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

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
               "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.6;
  margin: 0;
  padding: 0;
}

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

h1, h2, h3, h4 {
  line-height: 1.3;
  margin-bottom: 0.6rem;
  margin-top: 1.8rem;
}

h1 { font-size: 1.6rem; }
h2 { border-bottom: 1px solid var(--border); font-size: 1.3rem; padding-bottom: 0.3rem; }
h3 { font-size: 1.1rem; }
h4 { font-size: 1rem; }

main > h1:first-child,
main > h2:first-child {
  margin-top: 0;
}

p { margin: 0.8rem 0; }

code, kbd, tt, samp {
  background: var(--bg-code);
  border-radius: 3px;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  font-size: 0.9em;
  padding: 0.15em 0.35em;
}

pre {
  background: var(--bg-code);
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 0.9rem;
  line-height: 1.5;
  overflow-x: auto;
  padding: 1rem 1.2rem;
  white-space: pre-wrap;
  word-wrap: break-word;
}

pre code {
  background: none;
  border-radius: 0;
  padding: 0;
}

blockquote {
  background: var(--bg-subtle);
  border-left: 3px solid var(--accent);
  color: var(--text-secondary);
  font-style: italic;
  margin: 1rem 0;
  padding: 0.8rem 1.2rem;
}

blockquote p { margin: 0.4rem 0; }

table {
  border-collapse: collapse;
  margin: 1rem 0;
  width: 100%;
}

th, td {
  border: 1px solid var(--border);
  padding: 0.5rem 0.75rem;
  text-align: left;
}

th {
  background: var(--bg-subtle);
  font-weight: 600;
}

hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 2rem 0;
}

.site-header, .site-nav, main, .site-footer {
  margin: 0 auto;
  max-width: 52rem;
}

.site-header {
  background: var(--header-bg);
  color: var(--header-text);
  padding: 1.5rem 2rem;
}

.site-header h1 {
  font-size: 1.6rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  margin: 0;
}

.site-header h1 a {
  color: var(--header-text);
  text-decoration: none;
}

.site-header .subtitle {
  font-size: 0.9rem;
  margin: 0.25rem 0 0;
  opacity: 0.75;
}

.hamburger { display: none; }

.site-nav {
  background: var(--bg-subtle);
  border-bottom: 1px solid var(--border);
  padding: 0 2rem;
}

.site-nav[popover]:not(:popover-open) {
  border: none;
  border-bottom: 1px solid var(--border);
  display: block;
  height: auto;
  inset: auto;
  margin: 0 auto;
  overflow: visible;
  padding: 0 2rem;
  position: static;
  width: auto;
}

.site-nav ul {
  display: flex;
  flex-wrap: wrap;
  list-style: none;
  margin: 0;
  padding: 0;
}

.site-nav li a {
  border-bottom: 2px solid transparent;
  color: var(--text);
  display: block;
  font-size: 0.9rem;
  padding: 0.6rem 1rem;
  text-decoration: none;
  transition: background 0.15s, border-color 0.15s;
}

.site-nav li a:hover {
  background: var(--nav-hover);
  border-bottom-color: var(--accent);
}

.site-nav li a.active {
  background: var(--nav-active);
  border-bottom-color: var(--accent);
  font-weight: 600;
}

main { padding: 2rem; }

.site-footer {
  border-top: 1px solid var(--border);
  color: var(--text-secondary);
  font-size: 0.85rem;
  padding: 1.5rem 2rem;
}

.document-text {
  white-space: pre-wrap;
  word-wrap: break-word;
}

:target {
  position: relative;
}

:target::before {
  animation: arrow-pulse 1s ease-out;
  color: var(--accent);
  content: "\27a1\fe0e";
  display: inline-block;
  font-size: 2em;
  font-weight: 900;
  line-height: 0;
  margin-right: 1.5em;
  position: absolute;
  right: 100%;
  top: 0.5em;
  transform: scaleX(2.5);
}

@keyframes arrow-pulse {
  0%, 50% { opacity: 0; }
  60% { opacity: 1; transform: scaleX(3.5); }
  100% { opacity: 1; }
}

@media (max-width: 64em) {
  :target::before {
    font-size: 1.2em;
    margin-right: 0.3em;
    top: 0.55em;
    transform: scaleX(1.5);
  }

  li:target {
    list-style: none;
  }

  li:target::before {
    margin-right: 0.5em;
    top: 0.9em;
  }
}

.text-small { font-size: 0.9rem; }
.text-subtle { color: var(--text-secondary); }

@media (max-width: 640px) {
  .site-header {
    padding: 1rem;
    position: relative;
  }

  .site-header h1 { font-size: 1.3rem; }

  .hamburger {
    align-items: center;
    background: none;
    border: 2px solid var(--header-text);
    border-radius: 4px;
    color: var(--header-text);
    cursor: pointer;
    display: flex;
    height: 36px;
    justify-content: center;
    padding: 0;
    position: absolute;
    right: 1rem;
    top: 1rem;
    width: 36px;
  }

  .hamburger::before {
    background: currentColor;
    box-shadow: 0 6px 0 currentColor, 0 -6px 0 currentColor;
    content: '';
    display: block;
    height: 2px;
    width: 18px;
  }

  .hamburger:hover {
    background: rgba(255, 255, 255, 0.15);
  }

  .site-nav[popover]:not(:popover-open) { display: none; }

  .site-nav:popover-open {
    background: var(--bg-subtle);
    border: 1px solid var(--border);
    border-radius: 4px;
    box-shadow: 0 4px 12px rgb(0 0 0 / 15%);
    inset: auto;
    margin: 0;
    padding: 0.5rem 0;
    position: fixed;
    right: 1rem;
    top: 3.5rem;
    width: 250px;
  }

  .site-nav:popover-open ul {
    flex-direction: column;
  }

  .site-nav:popover-open li a {
    border-bottom: none;
    font-size: 0.9rem;
    padding: 0.75rem 1rem;
  }

  main {
    overflow-wrap: break-word;
    padding: 1.2rem 1rem;
    word-break: break-word;
  }

  h1 { font-size: 1.3rem; }
  h2 { font-size: 1.15rem; }

  blockquote {
    margin-left: 0;
    margin-right: 0;
    padding: 0.6rem 0.8rem;
  }

  ul, ol { padding-left: 1.2rem; }

  .site-footer { padding: 1rem; }
}