/* Base reset and shared styles */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

::selection {
  background: var(--text);
  color: var(--bg);
}

:root {
  --text: #111;
  --text-muted: #444;
  --text-faint: #707070;
  --text-micro: #767676;
  --bg: #fafafa;
  --border: #eee;
  --border-muted: #ccc;
  --border-hover: #111;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --text: #eee;
    --text-muted: #aaa;
    --text-faint: #9a9a9a;
    --text-micro: #909090;
    --bg: #111;
    --border: #222;
    --border-muted: #444;
    --border-hover: #eee;
  }
}

[data-theme="dark"] {
  --text: #eee;
  --text-muted: #aaa;
  --text-faint: #9a9a9a;
  --text-micro: #909090;
  --bg: #111;
  --border: #222;
  --border-muted: #444;
  --border-hover: #eee;
}

/* Theme toggle */
.theme-toggle {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  background: none;
  border: none;
  padding: 0.75rem;
  margin: -0.75rem;
  cursor: pointer;
  color: var(--text-faint);
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 20;
}

.theme-toggle .material-symbols-outlined {
  font-size: 20px;
}

.theme-toggle:hover {
  border-color: var(--border-hover);
  color: var(--text);
}

.theme-toggle:focus-visible {
  outline: 2px solid var(--text-faint);
  outline-offset: 2px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  font-size: clamp(1rem, 1.1vw, 1.125rem);
  line-height: 1.7;
  max-width: 600px;
  margin: 0 auto;
  padding: 4rem 1.5rem;
  color: var(--text);
  background: var(--bg);
  transition: color 200ms ease, background-color 200ms ease;
}

h1 {
  font-size: 1.25rem;
  font-weight: 600;
  letter-spacing: -0.02em;
}

h2 {
  font-size: 0.75rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-faint);
  margin-top: 3rem;
  margin-bottom: 1rem;
}

p {
  margin-bottom: 1.5rem;
  color: var(--text-muted);
}

a {
  color: inherit;
  text-decoration: none;
  border-bottom: 1px solid var(--border-muted);
}

a:hover {
  border-color: var(--border-hover);
}

a:focus-visible {
  outline: 2px solid var(--text-faint);
  outline-offset: 2px;
  border-radius: 2px;
}

ul {
  list-style: none;
}

li {
  margin-bottom: 0.75rem;
}

li a {
  border-bottom: none;
}

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

small {
  font-size: 0.8rem;
  color: var(--text-micro);
}

/* Search */
input[type="search"] {
  width: 100%;
  padding: 1rem 1.25rem;
  font-size: 1rem;
  font-family: inherit;
  border: 1px solid var(--border-muted);
  border-radius: 1rem;
  background: transparent;
  color: var(--text);
  margin-bottom: 2rem;
}

input[type="search"]:focus {
  outline: none;
  border-color: var(--text-faint);
}

input[type="search"]::placeholder {
  color: var(--text-muted);
}

/* Back link */
.back {
  display: inline-block;
  font-size: 0.85rem;
  color: var(--text-faint);
  margin-bottom: 2rem;
  border-bottom: none;
}

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

/* Breadcrumbs */
.breadcrumb {
  position: relative;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.85rem;
  color: var(--text-faint);
  margin-bottom: 2rem;
  margin-left: calc(-50vw + 50%);
  margin-right: calc(-50vw + 50%);
  padding-left: calc(50vw - 300px + 1.5rem);
  padding-right: 1.5rem;
  border-bottom: 1px solid var(--border);
  padding-bottom: 1rem;
}

.breadcrumb a {
  border-bottom: none;
  color: var(--text-faint);
}

.breadcrumb a:hover {
  color: var(--text);
}

.breadcrumb span {
  color: var(--border-muted);
}

/* Mobile styles */
@media (max-width: 480px) {
  body {
    padding: 2.5rem 1.5rem;
    padding-top: max(2.5rem, env(safe-area-inset-top));
    padding-bottom: max(3rem, env(safe-area-inset-bottom));
    font-size: 1.125rem;
    line-height: 1.8;
  }

  h1 {
    font-size: 1.25rem;
  }

  h2 {
    margin-top: 2.5rem;
  }

  p {
    margin-bottom: 1.75rem;
  }

  li {
    margin-bottom: 1rem;
  }

  li a {
    display: block;
    padding: 0.5rem 0;
  }

  .theme-toggle {
    bottom: max(1.25rem, env(safe-area-inset-bottom));
    right: max(1.25rem, env(safe-area-inset-right));
    width: 44px;
    height: 44px;
    border: 1px solid var(--border-muted);
    border-radius: 50%;
    background: var(--bg);
  }

  .breadcrumb {
    font-size: 0.8rem;
    margin-bottom: 2rem;
    margin-left: 0;
    margin-right: 0;
    padding-left: 0;
    padding-right: 0;
    border-bottom: none;
    padding-bottom: 0;
  }

  hr {
    margin: 3rem 0 2rem;
  }

  input[type="search"] {
    padding: 1rem 1.25rem;
    border-radius: 1.25rem;
    margin-bottom: 2.5rem;
  }
}

/* Skip to content link - accessibility */
.skip-link {
  position: absolute;
  top: 0;
  left: 0;
  transform: translateY(-100%);
  background: var(--text);
  color: var(--bg);
  padding: 0.5rem 1rem;
  font-size: 0.875rem;
  z-index: 100;
  border: none;
}

.skip-link:focus {
  transform: translateY(0);
  outline: 2px solid var(--text-faint);
  outline-offset: 2px;
}

/* Print styles */
@media print {
  body {
    max-width: none;
    padding: 0;
    font-size: 12pt;
    line-height: 1.5;
    color: #000;
    background: #fff;
  }

  .theme-toggle,
  .skip-link,
  .toc,
  .back,
  .related,
  .back-to-top,
  .progress-bar,
  .citation-tooltip,
  .copy-toast,
  .heading-anchor,
  input[type="search"] {
    display: none !important;
  }

  a {
    color: #000;
    border-bottom: none;
    text-decoration: underline;
  }

  a[href^="http"]::after {
    content: " (" attr(href) ")";
    font-size: 0.8em;
    color: #666;
  }

  .references a[href^="http"]::after {
    content: none;
  }

  h1, h2, h3 {
    page-break-after: avoid;
  }

  article {
    page-break-inside: avoid;
  }

  .breadcrumb {
    margin-bottom: 1rem;
  }

  hr {
    display: none;
  }
}
