body {
  padding: 0 12px;
  margin: 1rem auto 3rem;
  font-family: system-ui, sans-serif;
  line-height: 1.5;
  font-size: 1.1rem;
  max-width: 40em;
  -webkit-font-smoothing: antialiased;
  color: #111;
  overflow-wrap: anywhere;
}

h1,
h2,
h3 {
  line-height: 1.2;
  font-weight: 600;
}

h2,
h3 {
  margin-top: 1.5em;
}

h1 {
  margin: 0.5rem 0 0.75rem;
  font-size: 2rem;
}

strong {
  font-weight: 600;
}

a {
  color: currentColor;
}

a:hover {
  text-underline-offset: 0.2lh;
}

a:visited {
  text-decoration-color: white;
}

h1 a {
  text-decoration: none;
}

h1 a:hover {
  text-decoration: underline;
}

/* External link icon on article titles */
article h1 a::after {
  content: "";
  display: inline-block;
  width: 0.6em;
  height: 0.6em;
  margin-left: 0.35em;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23666' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6'/%3E%3Cpolyline points='15 3 21 3 21 9'/%3E%3Cline x1='10' y1='14' x2='21' y2='3'/%3E%3C/svg%3E");
  background-size: contain;
  background-repeat: no-repeat;
  vertical-align: middle;
  transition: opacity 0.2s;
}

article h1 a:hover::after {
  opacity: 0.7;
}

@media (prefers-color-scheme: dark) {
  article h1 a::after {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23999' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6'/%3E%3Cpolyline points='15 3 21 3 21 9'/%3E%3Cline x1='10' y1='14' x2='21' y2='3'/%3E%3C/svg%3E");
  }
}

/* Section label */
.section {
  text-transform: uppercase;
  font-size: 0.85rem;
  font-weight: 500;
  letter-spacing: 0.1em;
  margin-bottom: 1.25rem;
}

/* Authors */
.authors {
  font-size: 0.95rem;
  margin: 0 0 2rem;
}

/* Lead paragraph */
.lead {
  font-size: 1.3rem;
  margin: 0 0 2rem;
}

/* Dim text */
.dim {
  color: #666;
}

/* Repel layout */
.repel {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: var(--repel-vertical-alignment, center);
  gap: var(--gutter, 1rem);
}

/* Page count */
.page-count {
  min-width: 6ch;
  text-align: right;
}

/* Header navigation */
header nav {
  --repel-vertical-alignment: baseline;
  padding-bottom: 1rem;
  border-bottom: 1px solid #e0e0e0;
  margin-bottom: 2.5rem;
}

header nav > div {
  display: flex;
  align-items: baseline;
  gap: 1.5rem;
}

nav a {
  text-decoration: none;
}

nav a:hover {
  text-decoration: underline;
}

/* Footer navigation */
footer nav {
  margin: 3rem 0 2rem;
  padding: 1.5rem 0;
  border-top: 1px solid #e0e0e0;
}

footer nav a {
  text-decoration: none;
  padding: 0.75rem 1.5rem;
  border-radius: 4px;
  font-weight: 600;
  transition: background-color 0.2s;
  background-color: #f5f5f5;
  color: #333;
}

footer nav a:hover {
  background-color: #e0e0e0;
  text-decoration: none;
}

/* List pages */
ul[role="list"] {
  list-style: none;
  margin-block: 0;
  padding: 0;
}

ul[role="list"] li + li {
  margin-top: 1em;
}

li:empty {
  display: none;
}

/* Forms */
main form > div {
  margin-bottom: 1rem;
}

label {
  display: block;
  font-weight: 500;
  margin-bottom: 0.25rem;
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="search"],
input[type="url"],
input[type="number"],
select,
textarea {
  display: block;
  width: 100%;
  padding: 0.5rem 0.75rem;
  font-size: 1rem;
  font-family: inherit;
  line-height: 1.5;
  color: inherit;
  background-color: #fff;
  border: 1px solid #ccc;
  border-radius: 6px;
  box-sizing: border-box;
  transition: border-color 0.15s, box-shadow 0.15s;
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: #111;
  box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.1);
}

button,
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.5rem 1.25rem;
  font-size: 0.95rem;
  font-family: inherit;
  font-weight: 500;
  line-height: 1.5;
  color: #fff;
  background-color: #111;
  border: 1px solid transparent;
  border-radius: 6px;
  cursor: pointer;
  text-decoration: none;
  transition: background-color 0.15s, box-shadow 0.15s;
}

button:hover,
.btn:hover {
  background-color: #333;
}

button:active,
.btn:active {
  background-color: #000;
}

button:focus-visible,
.btn:focus-visible {
  outline: none;
  box-shadow: 0 0 0 2px #fff, 0 0 0 4px #111;
}

button.link {
  display: inline;
  background: none;
  border: none;
  padding: 0;
  color: currentColor;
  text-decoration: none;
  font-size: inherit;
  font-weight: normal;
  cursor: pointer;
}

button.link:hover {
  background: none;
  text-decoration: underline;
}

.btn-danger {
  background-color: #b91c1c;
}

.btn-danger:hover {
  background-color: #991b1b;
}

.btn-danger:active {
  background-color: #7f1d1d;
}

.error {
  color: #b91c1c;
}

span.error {
  display: block;
  font-size: 0.9rem;
}

/* Admin */
.admin-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 1rem;
  margin-bottom: 2rem;
}

.admin-stats .stat {
  padding: 1rem;
  border: 1px solid #e0e0e0;
  border-radius: 4px;
}

.admin-stats .stat dt {
  font-size: 0.85rem;
  color: #666;
}

.admin-stats .stat dd {
  font-size: 1.5rem;
  font-weight: 600;
  margin: 0;
}

.flash {
  padding: 0.75rem 1rem;
  border-radius: 6px;
  background-color: #f0fdf4;
  border: 1px solid #bbf7d0;
  color: #166534;
}

.flash-error {
  background-color: #fef2f2;
  border-color: #fecaca;
  color: #991b1b;
}

.admin-nav {
  display: flex;
  gap: 1.5rem;
  margin-bottom: 2rem;
}

.admin-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 2rem;
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th, td {
  text-align: left;
  padding: 0.5rem;
  border-bottom: 1px solid #e0e0e0;
  white-space: nowrap;
}

th {
  font-weight: 600;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

td.wrap {
  white-space: normal;
}

/* Keyboard shortcuts overlay */
.shortcuts-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.shortcuts-dialog {
  background: #fff;
  color: #111;
  padding: 1.5rem 2rem;
  border-radius: 8px;
  max-width: 400px;
  position: relative;
}

.shortcuts-dialog h2 {
  margin: 0 2rem 1rem 0;
}

.shortcuts-dialog dl {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.5rem 1rem;
  margin: 0;
}

.shortcuts-dialog dt {
  font-family: monospace;
  background: #eee;
  padding: 0.1em 0.4em;
  border-radius: 3px;
}

.shortcuts-dialog dd {
  margin: 0;
}

.shortcuts-close {
  position: absolute;
  top: 0.75rem;
  right: 0.75rem;
  border: none;
  border-radius: 4px;
  background: transparent;
  font-size: 1.5rem;
  cursor: pointer;
  padding: 0.2em 0.4em;
  line-height: 1;
}

.shortcuts-close:hover {
  background: rgba(0, 0, 0, 0.1);
}

/* Dark mode */
@media (prefers-color-scheme: dark) {
  body {
    color: unset;
  }

  a:visited {
    text-decoration-color: black;
  }

  .dim {
    color: #999;
  }

  header nav,
  footer nav {
    border-color: #333;
  }

  footer nav a {
    background-color: #2a2a2a;
    color: #e0e0e0;
  }

  footer nav a:hover {
    background-color: #333;
  }

  .shortcuts-dialog {
    background: #222;
    color: #eee;
  }

  .shortcuts-dialog dt {
    background: #444;
  }

  .shortcuts-close:hover {
    background: rgba(255, 255, 255, 0.15);
  }

  input[type="text"],
  input[type="email"],
  input[type="password"],
  input[type="search"],
  input[type="url"],
  input[type="number"],
  select,
  textarea {
    background-color: #1a1a1a;
    border-color: #444;
  }

  input:focus,
  select:focus,
  textarea:focus {
    border-color: #ddd;
    box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.15);
  }

  button,
  .btn {
    background-color: #e0e0e0;
    color: #111;
  }

  button:hover,
  .btn:hover {
    background-color: #ccc;
  }

  button:active,
  .btn:active {
    background-color: #bbb;
  }

  button:focus-visible,
  .btn:focus-visible {
    box-shadow: 0 0 0 2px #111, 0 0 0 4px #ddd;
  }

  .btn-danger {
    background-color: #dc2626;
    color: #fff;
  }

  .btn-danger:hover {
    background-color: #b91c1c;
  }

  .error {
    color: #ef4444;
  }

  .flash {
    background-color: #052e16;
    border-color: #166534;
    color: #bbf7d0;
  }

  .flash-error {
    background-color: #450a0a;
    border-color: #991b1b;
    color: #fecaca;
  }

  .admin-stats .stat {
    border-color: #333;
  }

  .admin-stats .stat dt {
    color: #999;
  }

  th, td {
    border-color: #333;
  }
}
