:root {
  color-scheme: light dark;
  --border: #8884;
}

body {
  font-family: system-ui, sans-serif;
  max-width: 900px;
  margin: 0 auto;
  padding: 1rem;
}

header {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.75rem 1.5rem;
  border-bottom: 1px solid var(--border);
  padding-bottom: 1rem;
  margin-bottom: 1rem;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.series-title select {
  font-size: 1.5rem;
  font-weight: 700;
  border: none;
  background: transparent;
  color: inherit;
  padding: 0;
  cursor: pointer;
}

.series-title select:hover,
.series-title select:focus {
  text-decoration: underline;
}

.tabs {
  display: flex;
  gap: 1.25rem;
}

.tabs a {
  color: inherit;
  text-decoration: none;
  opacity: 0.6;
  padding-bottom: 0.2rem;
  border-bottom: 2px solid transparent;
}

.tabs a:hover {
  opacity: 0.85;
}

.tabs a.active {
  opacity: 1;
  border-bottom-color: currentColor;
}

.position-picker {
  display: flex;
  gap: 1rem;
  margin-left: auto;
}

.position-picker label {
  display: flex;
  flex-direction: column;
  font-size: 0.85rem;
  gap: 0.25rem;
}

/* On phones the picker gets its own full-width row, and the book select
   shrinks (long book titles otherwise push the chapter stepper off-screen). */
@media (max-width: 700px) {
  .position-picker {
    width: 100%;
    margin-left: 0;
  }

  .position-picker label:first-child {
    flex: 1;
    min-width: 0;
  }

  .position-picker select {
    width: 100%;
    min-width: 0;
  }
}

.chapter-stepper {
  display: flex;
  align-items: stretch;
}

.chapter-stepper button {
  width: 2.25rem;
  font-size: 1.25rem;
  line-height: 1;
  border: 1px solid var(--border);
  background: transparent;
  color: inherit;
  cursor: pointer;
}

.chapter-stepper button:first-child {
  border-radius: 4px 0 0 4px;
  border-right: none;
}

.chapter-stepper button:last-child {
  border-radius: 0 4px 4px 0;
  border-left: none;
}

.chapter-stepper button:hover {
  background: #8882;
}

.chapter-stepper button:disabled {
  opacity: 0.4;
  cursor: default;
  background: transparent;
}

.chapter-stepper input {
  width: 4rem;
  text-align: center;
  border: 1px solid var(--border);
  border-radius: 0;
  font-size: 1rem;
  -moz-appearance: textfield;
}

.chapter-stepper input::-webkit-outer-spin-button,
.chapter-stepper input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

/* Characters page: name list beside the cards on wide screens, a
   collapsible menu above them on narrow ones. */
body:has(.characters-layout) {
  max-width: 1100px;
}

.characters-layout {
  display: grid;
  grid-template-columns: 13rem 1fr;
  gap: 1.5rem;
  align-items: start;
}

.character-nav {
  position: sticky;
  top: 1rem;
  max-height: calc(100vh - 2rem);
  overflow-y: auto;
}

.character-nav ul {
  list-style: none;
  margin: 0;
  padding: 0;
}

.character-nav a {
  display: block;
  padding: 0.35rem 0.6rem;
  border-radius: 4px;
  color: inherit;
  text-decoration: none;
}

.character-nav a:hover {
  background: #8882;
}

.character-nav a.active {
  background: #8884;
  font-weight: 600;
}

.character-nav-toggle {
  display: none;
}

.character-scope {
  display: flex;
  margin-bottom: 0.5rem;
}

.character-scope button {
  flex: 1;
  padding: 0.4rem 0.3rem;
  font: inherit;
  font-size: 0.85rem;
  color: inherit;
  background: transparent;
  border: 1px solid var(--border);
  cursor: pointer;
}

.character-scope button:first-child {
  border-radius: 4px 0 0 4px;
  border-right: none;
}

.character-scope button:last-child {
  border-radius: 0 4px 4px 0;
}

.character-scope button[aria-pressed="true"] {
  background: #8884;
  font-weight: 600;
}

@media (max-width: 700px) {
  .characters-layout {
    grid-template-columns: 1fr;
    gap: 1rem;
  }

  .character-nav {
    position: static;
    max-height: none;
    overflow: visible;
  }

  .character-nav-toggle {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    padding: 0.6rem 0.75rem;
    font: inherit;
    font-weight: 600;
    color: inherit;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 8px;
    cursor: pointer;
  }

  .character-nav-toggle::after {
    content: "\25BE";
  }

  .character-nav-toggle[aria-expanded="true"]::after {
    content: "\25B4";
  }

  .character-nav ul {
    display: none;
    margin-top: 0.25rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.25rem;
    max-height: 60vh;
    overflow-y: auto;
  }

  .character-nav ul.open {
    display: block;
  }

  .character-nav a {
    padding: 0.6rem 0.75rem;
  }
}

.character-card {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1rem;
  margin-bottom: 1rem;
}

.character-card h2 {
  margin-top: 0;
}

table.fields {
  border-collapse: collapse;
  margin-bottom: 1rem;
}

table.fields th,
table.fields td {
  text-align: left;
  padding: 0.25rem 0.75rem 0.25rem 0;
  vertical-align: top;
}

table.fields th {
  font-weight: 600;
  white-space: nowrap;
}

.empty {
  color: #888;
  font-style: italic;
}

.collection {
  border-top: 1px solid var(--border);
  padding-top: 0.75rem;
  margin-bottom: 1rem;
}

.collection h3 {
  margin: 0 0 0.5rem;
  font-size: 1rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: #888;
}

.collection-item {
  margin-bottom: 0.75rem;
  padding-left: 0.75rem;
  border-left: 2px solid var(--border);
}

.collection-item h4 {
  margin: 0 0 0.25rem;
}

.summary-block {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.75rem 1rem;
  margin-bottom: 1rem;
}

.summary-block summary {
  cursor: pointer;
  font-weight: 600;
}

.summary-block[open] summary {
  margin-bottom: 0.5rem;
}

.summary-body :first-child {
  margin-top: 0;
}

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

/* ---------- Series-specific character sheets (view.json) ---------- */

.sheet-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  margin-bottom: 0.75rem;
}

.sheet-header h2 {
  margin: 0;
}

.sheet-header .aka,
.sheet-header .subtitle {
  margin: 0.2rem 0 0;
  color: #888;
}

.sheet-header .aka {
  font-style: italic;
}

.badges {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  justify-content: flex-end;
}

.badge,
.meta {
  display: inline-block;
  padding: 0.1rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 0.8rem;
  white-space: nowrap;
}

.badge {
  background: #8882;
  font-weight: 600;
}

.meta {
  margin-left: 0.4rem;
  color: #888;
}

.field-group {
  margin-bottom: 1rem;
}

.group-label {
  margin: 0 0 0.5rem;
  font-size: 1rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: #888;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(7.5rem, 1fr));
  gap: 0.5rem;
}

.stat-tile {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  padding: 0.5rem 0.65rem;
  border: 1px solid var(--border);
  border-radius: 6px;
}

.stat-tile span {
  font-size: 0.75rem;
  color: #888;
}

.collection .count {
  font-size: 0.8rem;
  font-weight: normal;
  margin-left: 0.3rem;
}

details.collection > summary {
  cursor: pointer;
  list-style: none;
}

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

details.collection > summary h3 {
  display: inline;
}

details.collection > summary::before {
  content: "\25B8";
  display: inline-block;
  width: 1rem;
  color: #888;
}

details.collection[open] > summary::before {
  content: "\25BE";
}

details.collection[open] > summary {
  margin-bottom: 0.5rem;
}

.item-group {
  margin: 0.75rem 0 0.4rem;
  font-size: 0.9rem;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.chip {
  padding: 0.2rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 0.9rem;
}

.chip[title] {
  cursor: help;
}

.item-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.item-list li {
  padding: 0.35rem 0;
  border-bottom: 1px solid var(--border);
}

.item-list li:last-child {
  border-bottom: none;
}

.item-list summary {
  cursor: pointer;
}

.item-list details p {
  margin: 0.4rem 0 0.25rem 1rem;
}

.item-list details table.fields {
  margin: 0.25rem 0 0.25rem 1rem;
}

.item-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(16rem, 1fr));
  gap: 0.6rem;
}

.item-card {
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 6px;
}

.item-card-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.25rem;
}

.item-card-head h4 {
  margin: 0;
}

.item-card-head .meta {
  margin-left: 0;
}

.item-card p {
  margin: 0.4rem 0 0;
  font-size: 0.9rem;
}

.item-card table.fields {
  margin: 0.4rem 0 0;
  font-size: 0.9rem;
}
