:root {
  color-scheme: dark;
  --bg: #0b0e14;
  --surface: #151922;
  --surface-alt: #1f2430;
  --border: #31261c;
  --text: #f0d7c0;
  --muted: #b58d74;
  --accent: #d74f25;
  --accent-secondary: #f3c14b;
  --success: #81b65c;
  --danger: #d1302e;
  --radius: 14px;
  --filters-width: min(95vw, 360px);
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.5rem;
  --space-6: 2rem;
  font-family: "Jost", system-ui, sans-serif;
}

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

body {
  margin: 0;
  min-height: 100vh;
  background: radial-gradient(circle at top, #1b1d27, #0d0e12 55%);
  color: var(--text);
}

body.modal-open {
  overflow: hidden;
  height: 100vh;
}

.stack {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}
.stack-sm { gap: var(--space-2); }
.stack-lg { gap: var(--space-5); }
.cluster {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-3);
}
.cluster-tight { gap: var(--space-2); }
.section-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
}
.badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  border-radius: 999px;
  padding: 0.15rem 0.6rem;
  border: 1px solid var(--border);
  font-size: 0.8rem;
  color: var(--muted);
}

h1, h2, h3 { margin: 0; }

.top-bar {
  display: flex;
  justify-content: space-between;
  gap: 2rem;
  padding: 2rem clamp(1.5rem, 5vw, 4rem);
}

.top-actions {
  display: flex;
  gap: 0.75rem;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.mobile-only {
  display: none;
}
.only-desktop {
  display: inline-flex;
}

.fav-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.9rem;
  color: var(--muted);
  padding: 0.35rem 0.75rem;
  border-radius: 999px;
  border: 1px solid var(--border);
}
.fav-toggle input {
  width: auto;
}

.eyebrow {
  text-transform: uppercase;
  letter-spacing: 0.15em;
  font-size: 0.75rem;
  color: var(--muted);
  margin-bottom: 0.35rem;
}

.muted { color: var(--muted); margin-top: 0.35rem; }

.layout {
  display: grid;
  grid-template-columns: minmax(240px, 320px) 1fr;
  gap: 1.5rem;
  padding: 0 clamp(1.5rem, 5vw, 4rem) 2rem;
}

.filters-panel,
.table-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  overflow-x: auto;
}

.filters-panel {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 0.35rem;
}

input,
select,
textarea {
  width: 100%;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.55rem 0.75rem;
  color: var(--text);
  font-size: 1rem;
}
textarea {
  min-height: 96px;
  resize: vertical;
}

.btn {
  border: 1px solid transparent;
  background: var(--surface-alt);
  color: var(--text);
  padding: 0.5rem 1rem;
  border-radius: 999px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn:hover { filter: brightness(1.08); }
.btn.primary { background: var(--accent); color: #1b0f08; }
.btn.outline {
  background: transparent;
  border-color: var(--border);
}
.btn.small {
  padding: 0.3rem 0.7rem;
  font-size: 0.8rem;
}
.btn.ghost {
  background: transparent;
  border-color: transparent;
  color: var(--muted);
}

.btn:focus-visible,
.collapsible-toggle:focus-visible,
.sort-btn:focus-visible,
.star-btn:focus-visible {
  outline: 2px solid var(--accent-secondary);
  outline-offset: 2px;
}

.pill-select {
  appearance: none;
  border-radius: 999px;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  padding: 0.4rem 0.75rem;
  color: var(--text);
  font-weight: 600;
  position: relative;
}
.pill-select:focus-visible {
  outline: 2px solid var(--accent-secondary);
  outline-offset: 2px;
}

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

thead th {
  text-align: left;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  padding: 0.75rem 0.5rem;
  border-bottom: 1px solid var(--border);
}

tbody td {
  padding: 0.85rem 0.5rem;
  border-bottom: 1px solid rgba(255,255,255,0.05);
}

.sort-btn {
  background: none;
  border: none;
  color: var(--muted);
  font-weight: 600;
  letter-spacing: 0.06em;
  cursor: pointer;
  display: inline-flex;
  gap: 0.25rem;
  align-items: center;
}
.sort-btn.active {
  color: var(--text);
}
.sort-btn::after {
  content: attr(data-indicator);
  font-size: 0.8rem;
  color: var(--muted);
}

.sort-btn {
  background: none;
  border: none;
  color: var(--muted);
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  cursor: pointer;
  display: inline-flex;
  gap: 0.35rem;
  align-items: center;
}
.sort-btn.active {
  color: var(--text);
}
.sort-btn::after {
  content: attr(data-indicator);
  font-size: 0.8rem;
  color: var(--muted);
}

.cards-container {
  display: none;
  margin-top: 1rem;
  grid-template-columns: 1fr;
  gap: 0.75rem;
  position: relative;
}

.character-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.8rem;
  background: var(--surface-alt);
  display: flex;
  gap: 0.65rem;
  align-items: flex-start;
}
.character-card .card-main { flex: 1; }
.character-card h4 { margin: 0; font-size: 0.95rem; }
.character-card .meta { font-size: 0.8rem; color: var(--muted); }
.character-card .status-pill { display: inline-block; margin-top: 0.25rem; }
.card-actions {
  display: flex;
  gap: 0.35rem;
  flex-wrap: wrap;
  margin-top: 0.65rem;
}

.row-actions {
  display: flex;
  gap: 0.35rem;
  justify-content: flex-end;
}
.actions-col {
  width: 140px;
  text-align: right;
}

@keyframes spinner {
  to { transform: rotate(360deg); }
}

body.loading .table-panel::after,
body.loading .cards-container::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: rgba(11, 14, 20, 0.8);
  backdrop-filter: blur(2px);
  z-index: 10;
}

body.loading .table-panel::before,
body.loading .cards-container::before {
  content: '';
  position: absolute;
  z-index: 11;
  top: 50%;
  left: 50%;
  width: 36px;
  height: 36px;
  margin: -18px;
  border-radius: 50%;
  border: 3px solid rgba(255,255,255,0.3);
  border-top-color: var(--accent-secondary);
  animation: spinner 0.8s linear infinite;
}
.row-actions {
  display: flex;
  gap: 0.35rem;
  justify-content: flex-end;
}

.star-cell {
  width: 40px;
  text-align: center;
}

.star-btn {
  background: none;
  border: none;
  color: #fbbf24;
  font-size: 1.1rem;
  cursor: pointer;
  width: 32px;
  height: 32px;
  transition: transform 0.2s ease;
}
.star-btn:hover { transform: scale(1.1); }
.star-btn.inactive { color: #4b5563; }

tbody tr {
  cursor: pointer;
}

tbody tr:hover {
  background: rgba(255,255,255,0.04);
}

.placeholder {
  text-align: center;
  color: var(--muted);
  padding: 3rem 0;
}

dialog {
  border: none;
  border-radius: var(--radius);
  padding: 0;
  background: var(--surface);
  color: var(--text);
  min-width: min(90vw, 960px);
}

dialog::backdrop {
  background: rgba(0,0,0,0.7);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  padding: 1.5rem;
  border-bottom: 1px solid var(--border);
}

.modal-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.modal-body {
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.modal-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 1rem;
}

.modal-section {
  background: var(--surface-alt);
  border-radius: var(--radius);
  padding: 1rem;
  border: 1px solid var(--border);
}

.collapsible {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0;
}
.collapsible-toggle {
  width: 100%;
  background: transparent;
  border: none;
  color: var(--text);
  font-weight: 600;
  padding: 0.75rem 1rem;
  text-align: left;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.collapsible-toggle::after {
  content: '●';
  font-size: 0.75rem;
  color: var(--accent-secondary);
  transition: color 0.2s ease;
}
.collapsible-content {
  padding: 0.75rem 1rem 1rem;
  border-top: 1px solid var(--border);
}
.collapsible.collapsed .collapsible-content {
  display: none;
}
.collapsible.collapsed .collapsible-toggle::after {
  content: '○';
  color: var(--muted);
}

.section-header-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
}

.info-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 0.75rem;
}
.info-grid .full-width {
  grid-column: 1 / -1;
}

.info-grid dt {
  font-size: 0.75rem;
  text-transform: uppercase;
  color: var(--muted);
}

.info-grid dd {
  margin: 0;
  font-weight: 600;
}

.retainer-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.retainer-card {
  padding: 0.75rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: #15161d;
}

.modal-edit-bar {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
}

.modal-edit-bar.hidden { display: none; }

.form-grid {
  display: grid;
  gap: 1rem;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
}

.party-body {
  min-width: min(90vw, 840px);
}

.party-header {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.party-filter {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 0.75rem;
}

.party-actions-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.party-columns {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 1rem;
}

.party-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  max-height: 50vh;
  overflow-y: auto;
}

.party-list li {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.5rem 0.75rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: #15161d;
  cursor: pointer;
}

.party-list li span {
  font-size: 0.85rem;
  color: var(--muted);
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 1rem;
}

.chart-card {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
}

.party-badges {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.status-pill {
  padding: 0.15rem 0.65rem;
  border-radius: 999px;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.status-alive { background: rgba(16,185,129,0.2); color: var(--success); }
.status-dead { background: rgba(239,68,68,0.2); color: var(--danger); }
.status-missing { background: rgba(251,191,36,0.2); color: #fbbf24; }
.status-enslaved { background: rgba(147,51,234,0.2); color: #c084fc; }

.time-jail-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.2rem 0.65rem;
  border-radius: 999px;
  background: rgba(243, 193, 75, 0.18);
  border: 1px solid rgba(243, 193, 75, 0.4);
  color: var(--accent-secondary);
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  box-shadow: 0 0 14px rgba(243, 193, 75, 0.2);
  vertical-align: middle;
}
.time-jail-badge::before {
  content: '';
  width: 0.35rem;
  height: 0.35rem;
  border-radius: 50%;
  background: var(--accent-secondary);
  box-shadow: 0 0 8px rgba(243, 193, 75, 0.8);
}
.table-panel td .time-jail-badge {
  white-space: nowrap;
}

@media (max-width: 900px){
  .layout {
    grid-template-columns: 1fr;
  }
  .top-bar {
    flex-direction: column;
  }
  dialog {
    min-width: 90vw;
  }
  .mobile-only {
    display: inline-flex;
  }
  .only-desktop {
    display: none !important;
  }
  .filters-close-btn {
    width: 100%;
    justify-content: center;
    margin-bottom: 1rem;
  }
  .filters-panel {
    position: fixed;
    top: 0;
    left: 50%;
    bottom: 0;
    z-index: 80;
    transform: translateY(-100%);
    transform: translate(-50%, -100%);
    background: rgba(11, 14, 20, 0.98);
    padding: 1.5rem 1rem 2.5rem;
    overflow-y: auto;
    width: var(--filters-width);
    transition: transform 0.3s ease;
    border-radius: 16px;
    border: 1px solid var(--border);
  }
  .filters-panel.open {
    transform: translate(-50%, 0);
  }
  .table-panel table {
    display: none;
  }
  .cards-container {
    display: grid;
  }
}

@media (max-width: 600px){
  .character-card {
    flex-direction: row;
    align-items: center;
    gap: 0.5rem;
  }
  .character-card h4 {
    font-size: 0.9rem;
  }
  .character-card .meta {
    font-size: 0.75rem;
  }
  .star-btn {
    width: 24px;
    height: 24px;
  }
  .top-actions {
    justify-content: flex-start;
  }
}



.stack {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}
.stack-sm { gap: var(--space-2); }
.stack-lg { gap: var(--space-5); }
.cluster {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-3);
}
.cluster-tight { gap: var(--space-2); }
.section-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
}

.table-panel,
.cards-container {
  position: relative;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

body.loading .table-panel::after,
body.loading .cards-container::after {
  content: '';
  position: absolute;
  inset: 0;
  background: rgba(11, 14, 20, 0.75);
  border-radius: inherit;
  z-index: 10;
  backdrop-filter: blur(2px);
}

body.loading .table-panel::before,
body.loading .cards-container::before {
  content: '';
  position: absolute;
  z-index: 11;
  top: 50%;
  left: 50%;
  width: 36px;
  height: 36px;
  margin: -18px;
  border-radius: 50%;
  border: 3px solid rgba(255,255,255,0.2);
  border-top-color: var(--accent-secondary);
  animation: spin 0.8s linear infinite;
}

@media (max-width: 900px){
  .filters-panel {
    transform: translate(-50%, -110%);
  }
  .filters-panel.open {
    transform: translate(-50%, 0);
  }
}




.pill-group {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}
.pill {
  border: 1px solid var(--border);
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  padding: 0.25rem 0.8rem;
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.2s ease;
}
.pill-active {
  background: var(--accent-secondary);
  color: #1b0f08;
  border-color: var(--accent-secondary);
}
.pill:focus-visible {
  outline: 2px solid var(--accent-secondary);
  outline-offset: 2px;
}
.pill-select-group {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin-top: 0.35rem;
}
.pill-select-group .pill {
  padding: 0.22rem 0.75rem;
  font-size: 0.8rem;
}
.pill-dropdown {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-alt);
  padding: 0.35rem 0.6rem;
}
.pill-dropdown-summary {
  width: 100%;
  border: none;
  background: transparent;
  color: var(--muted);
  font-weight: 600;
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
  gap: 0.5rem;
}
.pill-dropdown-summary.open .pill-chevron {
  transform: rotate(180deg);
}
.pill-chevron {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1rem;
  height: 1rem;
  transition: transform 0.2s ease;
}
.pill-chevron::before {
  content: '▾';
  font-size: 0.75rem;
  line-height: 1;
}
.pill-list {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin-top: 0.5rem;
}
.pill-list[hidden] {
  display: none;
}
.pill-list .pill {
  width: 100%;
  text-align: left;
}
.pill-badge-group {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
}
