:root {
  color-scheme: light;

  /* Candlelit Parchment (default) — neutral & accent ramps (100 -> 900) */
  --neutral-100: #f8f4f4;
  --neutral-200: #eae7e7;
  --neutral-300: #d7d3d3;
  --neutral-400: #bab6b6;
  --neutral-500: #9b9797;
  --neutral-600: #7d7979;
  --neutral-700: #605d5d;
  --neutral-800: #444141;
  --neutral-900: #2d2b2b;
  --accent-100: #fff3e4;
  --accent-200: #ffe3bf;
  --accent-300: #facb8d;
  --accent-400: #e1ad66;
  --accent-500: #c28d41;
  --accent-600: #a06f24;
  --accent-700: #7d5411;
  --accent-800: #5a3b0a;
  --accent-900: #3a270d;

  --bg: #f7f0df;
  --surface: #efe6cd;
  --surface-alt: var(--neutral-100);
  --text: #2a2015;
  --muted: var(--neutral-600);
  --accent: var(--accent-500);
  --accent-secondary: var(--accent-600);
  --success: #57713d;
  --danger: #7a1f2b;
  --danger-bright: #9c2436;
  --border: color-mix(in srgb, #2a2015 16%, transparent);
  --border-strong: var(--accent-600);
  --divider: color-mix(in srgb, #2a2015 16%, transparent);

  --shadow-sm: 0 1px 2px rgba(42, 32, 21, 0.14);
  --shadow-md: 0 3px 10px rgba(42, 32, 21, 0.16);
  --shadow-lg: 0 12px 32px rgba(42, 32, 21, 0.22);

  --radius-sm: 2px;
  --radius-md: 4px;
  --radius-lg: 7px;
  --radius: var(--radius-md);
  --control-radius: var(--radius-sm);
  --control-padding-y: 0.6rem;
  --control-padding-x: 0.85rem;
  --control-padding-right: 2.6rem;
  --filters-width: min(95vw, 360px);

  /* Spacing scale (4.6 / 9.2 / 13.8 / 18.4 / 27.6 / 36.8 px — no space-5) */
  --space-1: 0.2875rem;
  --space-2: 0.575rem;
  --space-3: 0.8625rem;
  --space-4: 1.15rem;
  --space-6: 1.725rem;
  --space-8: 2.3rem;

  --font-display: "Cormorant Garamond", Georgia, serif;
  --font-body: "Lora", Georgia, serif;
  font-family: var(--font-body);
}

/* Verdant Ledger — forest-green ink on pale ledger paper */
[data-theme="ledger"] {
  color-scheme: light;

  --neutral-100: #eef2e9;
  --neutral-200: #dde5d4;
  --neutral-300: #c3d0b3;
  --neutral-400: #a3b48c;
  --neutral-500: #82966a;
  --neutral-600: #647850;
  --neutral-700: #4c5c3c;
  --neutral-800: #35412a;
  --neutral-900: #212a1a;
  --accent-100: #eaf2e4;
  --accent-200: #d3e6c8;
  --accent-300: #b0d1a1;
  --accent-400: #86b874;
  --accent-500: #5f9a4c;
  --accent-600: #457838;
  --accent-700: #345a29;
  --accent-800: #23401c;
  --accent-900: #162811;

  --bg: #eef2e6;
  --surface: #e2e9d7;
  --surface-alt: var(--neutral-100);
  --text: #1e2818;
  --muted: var(--neutral-600);
  --accent: var(--accent-500);
  --accent-secondary: var(--accent-600);
  --success: #4c6b3a;
  --danger: #7a1f2b;
  --danger-bright: #9c2436;
  --border: color-mix(in srgb, #1e2818 14%, transparent);
  --border-strong: var(--accent-600);
  --divider: color-mix(in srgb, #1e2818 14%, transparent);

  --shadow-sm: 0 1px 2px rgba(30, 40, 24, 0.14);
  --shadow-md: 0 3px 10px rgba(30, 40, 24, 0.16);
  --shadow-lg: 0 12px 32px rgba(30, 40, 24, 0.22);
}

/* Quarried Slate — cool stone grey with steel-blue accents (light) */
[data-theme="slate-light"] {
  color-scheme: light;

  --neutral-100: #eef1f2;
  --neutral-200: #dde3e5;
  --neutral-300: #c1cbce;
  --neutral-400: #9fadb2;
  --neutral-500: #7c8c92;
  --neutral-600: #5f6e74;
  --neutral-700: #48545a;
  --neutral-800: #333c40;
  --neutral-900: #202628;
  --accent-100: #e6eef1;
  --accent-200: #cadde3;
  --accent-300: #a1c1cc;
  --accent-400: #74a0ae;
  --accent-500: #4c7e8f;
  --accent-600: #3f6b7a;
  --accent-700: #294650;
  --accent-800: #1b2f37;
  --accent-900: #101c21;

  --bg: #eef1f2;
  --surface: #e2e7e9;
  --surface-alt: var(--neutral-100);
  --text: #1c2528;
  --muted: var(--neutral-600);
  --accent: var(--accent-500);
  --accent-secondary: var(--accent-600);
  --success: #4a7a5c;
  --danger: #8a3a2a;
  --danger-bright: #ad4530;
  --border: color-mix(in srgb, #1c2528 14%, transparent);
  --border-strong: var(--accent-600);
  --divider: color-mix(in srgb, #1c2528 14%, transparent);

  --shadow-sm: 0 1px 2px rgba(20, 26, 28, 0.14);
  --shadow-md: 0 3px 10px rgba(20, 26, 28, 0.16);
  --shadow-lg: 0 12px 32px rgba(20, 26, 28, 0.22);
}

[data-theme="ink"] {
  color-scheme: dark;
  --bg: #171513;
  --surface: #1f1c1a;
  --surface-alt: #262220;
  --text: #efece7;
  --muted: #a89e91;
  --accent: var(--accent-400);
  --accent-secondary: var(--accent-300);
  --success: #4f6a3f;
  --border: rgba(239, 236, 231, 0.14);
  --border-strong: var(--accent-400);
  --divider: rgba(239, 236, 231, 0.14);
  --shadow-sm: 0 1px 0 rgba(255, 255, 255, 0.05), 0 2px 6px rgba(0, 0, 0, 0.5);
  --shadow-md: 0 1px 0 rgba(255, 255, 255, 0.05), 0 6px 16px rgba(0, 0, 0, 0.55);
  --shadow-lg: 0 1px 0 rgba(255, 255, 255, 0.06), 0 16px 40px rgba(0, 0, 0, 0.6);
}

[data-theme="slate"] {
  color-scheme: dark;
  --bg: #15181a;
  --surface: #1c2023;
  --surface-alt: #232729;
  --text: #e9edf0;
  --muted: #9aa4ab;
  --accent: var(--accent-400);
  --accent-secondary: var(--accent-300);
  --success: #4f6a3f;
  --border: rgba(233, 237, 240, 0.14);
  --border-strong: var(--accent-400);
  --divider: rgba(233, 237, 240, 0.14);
  --shadow-sm: 0 1px 0 rgba(255, 255, 255, 0.05), 0 2px 6px rgba(0, 0, 0, 0.5);
  --shadow-md: 0 1px 0 rgba(255, 255, 255, 0.05), 0 6px 16px rgba(0, 0, 0, 0.55);
  --shadow-lg: 0 1px 0 rgba(255, 255, 255, 0.06), 0 16px 40px rgba(0, 0, 0, 0.6);
}

[data-theme="wine"] {
  color-scheme: dark;
  --bg: #1c1315;
  --surface: #241a1c;
  --surface-alt: #2c2022;
  --text: #efe6e5;
  --muted: #ab9793;
  --accent: var(--accent-400);
  --accent-secondary: var(--accent-300);
  --success: #4f6a3f;
  --border: rgba(239, 230, 229, 0.14);
  --border-strong: var(--accent-400);
  --divider: rgba(239, 230, 229, 0.14);
  --shadow-sm: 0 1px 0 rgba(255, 255, 255, 0.05), 0 2px 6px rgba(0, 0, 0, 0.5);
  --shadow-md: 0 1px 0 rgba(255, 255, 255, 0.05), 0 6px 16px rgba(0, 0, 0, 0.55);
  --shadow-lg: 0 1px 0 rgba(255, 255, 255, 0.06), 0 16px 40px rgba(0, 0, 0, 0.6);
}

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

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(ellipse at 50% 20%, color-mix(in srgb, var(--accent) 6%, transparent) 0%, transparent 55%),
    var(--bg);
  color: var(--text);
  font-family: var(--font-body);
}

h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-display);
  font-weight: 600;
  letter-spacing: 0.01em;
}
h1 { font-size: 42px; }
h2 { font-size: 32px; }
h3 { font-size: 25px; }
h4 { font-size: 20px; }
h5 { font-size: 16px; }
h6 {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

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-6); }
.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: var(--control-radius);
  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;
  letter-spacing: 0.05em;
  color: var(--muted);
  margin-bottom: 0.35rem;
}

label:has(select),
label:has(.pill-select-group) {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

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

select,
.pill-dropdown {
  border: 1px solid var(--border);
  border-radius: var(--control-radius);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.02), rgba(0, 0, 0, 0.08)),
    var(--surface-alt);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.03),
    0 10px 24px rgba(0, 0, 0, 0.14);
  transition:
    border-color 0.2s ease,
    box-shadow 0.2s ease,
    background 0.2s ease,
    transform 0.2s ease;
}

select {
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  padding:
    var(--control-padding-y)
    var(--control-padding-right)
    var(--control-padding-y)
    var(--control-padding-x);
  background-image:
    linear-gradient(180deg, rgba(255, 255, 255, 0.02), rgba(0, 0, 0, 0.08)),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 14 14' fill='none'%3E%3Cpath d='M3.25 5.5L7 9.25L10.75 5.5' stroke='%23c28d41' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E"),
    linear-gradient(180deg, rgba(255, 255, 255, 0.02), rgba(0, 0, 0, 0.08));
  background-repeat: no-repeat, no-repeat, no-repeat;
  background-position:
    0 0,
    right 0.95rem center,
    0 0;
  background-size:
    auto,
    0.95rem,
    auto;
  cursor: pointer;
}

[data-theme="ledger"] select {
  background-image:
    linear-gradient(180deg, rgba(255, 255, 255, 0.02), rgba(0, 0, 0, 0.08)),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 14 14' fill='none'%3E%3Cpath d='M3.25 5.5L7 9.25L10.75 5.5' stroke='%23457838' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E"),
    linear-gradient(180deg, rgba(255, 255, 255, 0.02), rgba(0, 0, 0, 0.08));
}

[data-theme="slate-light"] select {
  background-image:
    linear-gradient(180deg, rgba(255, 255, 255, 0.02), rgba(0, 0, 0, 0.08)),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 14 14' fill='none'%3E%3Cpath d='M3.25 5.5L7 9.25L10.75 5.5' stroke='%23375f6d' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E"),
    linear-gradient(180deg, rgba(255, 255, 255, 0.02), rgba(0, 0, 0, 0.08));
}

select:hover,
.pill-dropdown:hover {
  border-color: color-mix(in srgb, var(--accent) 32%, transparent);
}

input:focus-visible,
select:focus-visible,
textarea:focus-visible,
.pill-dropdown:focus-within {
  outline: none;
  border-color: var(--accent);
  box-shadow:
    0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent),
    var(--shadow-md);
}

.btn {
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  padding: 0.5rem 1.05rem;
  border-radius: var(--control-radius);
  font-family: var(--font-body);
  letter-spacing: 0.02em;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn:hover { background: color-mix(in srgb, var(--accent) 8%, transparent); border-color: var(--accent-secondary); }
.btn.primary { background: transparent; border-color: var(--accent); color: var(--accent); }
.btn.primary:hover { background: color-mix(in srgb, var(--accent) 12%, transparent); }
.btn.success { background: transparent; border-color: var(--success); color: var(--success); }
.btn.success:hover { background: color-mix(in srgb, var(--success) 12%, transparent); }
.btn.outline {
  background: transparent;
  border-color: var(--border);
}
.btn.danger {
  background: transparent;
  border-color: var(--danger);
  color: var(--danger-bright);
}
.btn.danger:hover { background: color-mix(in srgb, var(--danger) 12%, transparent); }
.btn.small {
  padding: 0.3rem 0.7rem;
  font-size: 0.8rem;
}
.btn.block {
  width: 100%;
  justify-content: center;
  display: inline-flex;
}
.btn.icon {
  padding: 0.4rem;
  width: 2.2rem;
  height: 2.2rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.btn.ghost {
  background: transparent;
  border-color: transparent;
  color: var(--muted);
}
.btn.ghost:hover { color: var(--text); border-color: transparent; background: transparent; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.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: var(--control-radius);
  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;
}

.disease-check-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 color-mix(in srgb, var(--accent) 14%, transparent);
}

.disease-check-table th,
.disease-check-table td {
  padding: 0.85rem 0.5rem;
  border-bottom: 1px solid rgba(255,255,255,0.05);
  text-align: left;
}

.disease-check-table td.disease-roll-danger {
  color: var(--danger-bright);
  font-weight: 700;
}

.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 {
  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 {
  content: '';
  position: absolute;
  z-index: 11;
  top: 50%;
  left: 50%;
  width: 36px;
  height: 36px;
  margin: -18px;
  border-radius: 50%;
  border: 3px solid rgba(231,223,201,0.25);
  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: var(--accent);
  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: color-mix(in srgb, var(--accent) 30%, transparent); }

tbody tr {
  cursor: pointer;
}

tbody tr:hover {
  background: color-mix(in srgb, var(--accent) 6%, transparent);
}

.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.modal-compact {
  min-width: min(90vw, 440px);
}

dialog::backdrop {
  background: rgba(24, 18, 12, 0.6);
}

dialog {
  box-shadow: var(--shadow-lg);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  flex-wrap: wrap;
  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;
}

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

.modal-danger-bar {
  display: flex;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 0.5rem;
  padding: 0.85rem 1rem;
  border: 1px solid color-mix(in srgb, var(--danger-bright) 40%, transparent);
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--danger) 12%, transparent);
}

.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;
}

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

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

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

.compact-form-grid {
  grid-template-columns: 1fr;
}

.modal-note {
  margin: 0;
}

.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: var(--radius);
  padding: 0.5rem 0.75rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--surface-alt);
  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;
}

.stats-wide {
  grid-column: 1 / -1;
}

.stats-card-heading {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
}

.stats-card-note {
  margin: 0.35rem 0 0;
  color: var(--text);
  font-size: 0.9rem;
}

.stat-card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 0.75rem;
}

.stat-card {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  min-height: 116px;
  padding: 0.9rem;
  background: color-mix(in srgb, var(--accent) 4%, var(--surface-alt));
  border: 1px solid color-mix(in srgb, var(--accent) 18%, transparent);
  border-radius: var(--radius);
}

.stat-card h4 {
  margin: 0;
  font-size: 0.78rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text);
}

.stat-card-detail {
  margin: 0;
  line-height: 1.35;
}

.stat-card-value {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 2.5rem;
  margin-top: auto;
  padding: 0.25rem 0.65rem;
  border-radius: var(--control-radius);
  background: color-mix(in srgb, var(--accent) 16%, transparent);
  border: 1px solid color-mix(in srgb, var(--accent) 30%, transparent);
  color: var(--accent-secondary);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.stat-card.is-empty .stat-card-value {
  opacity: 0.8;
}

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

.status-pill {
  display: inline-block;
  padding: 0.16rem 0.6rem 0.16rem 0.5rem;
  border-radius: var(--control-radius);
  border: 1px solid currentColor;
  font-size: 0.72rem;
  letter-spacing: 0.02em;
  background: transparent;
}

/* Alive — filled accent tag */
.status-alive {
  color: #fff;
  border-color: var(--success);
  background: var(--success);
}
.status-alive::before { content: "\25c6\a0"; }

/* Dead — neutral tag */
.status-dead {
  color: var(--neutral-800);
  border-color: var(--neutral-400);
  background: var(--neutral-200);
  text-decoration: line-through;
  text-decoration-color: var(--neutral-500);
}
.status-dead::before { content: "\2715\a0"; text-decoration: none; display: inline-block; }

.status-missing {
  color: var(--muted);
  border-color: var(--border);
  border-style: dashed;
  background: transparent;
}
.status-missing::before { content: "?\a0"; }

/* Enslaved — outlined tag */
.status-enslaved {
  color: var(--accent);
  border-color: var(--accent);
  background: transparent;
}
.status-enslaved::before { content: "\25c8\a0"; }

.time-jail-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.2rem 0.6rem;
  border-radius: var(--control-radius);
  background: color-mix(in srgb, var(--danger) 14%, transparent);
  border: 1px solid color-mix(in srgb, var(--danger-bright) 55%, transparent);
  color: var(--muted);
  font-size: 0.74rem;
  letter-spacing: 0.05em;
  vertical-align: middle;
}
.time-jail-badge::before {
  content: '\23f3';
  font-size: 0.85em;
  color: var(--danger-bright);
}
.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: auto;
    left: 50%;
    bottom: 0;
    z-index: 80;
    transform: translate(-50%, 100%);
    background: var(--surface);
    padding: 1.75rem 1.1rem 2rem;
    overflow-y: auto;
    max-height: 82vh;
    width: var(--filters-width);
    transition: transform 0.3s ease;
    border-radius: 16px 16px 0 0;
    border: 1px solid var(--border);
    border-bottom: none;
  }
  .filters-panel::before {
    content: '';
    position: absolute;
    top: 10px;
    left: 50%;
    transform: translateX(-50%);
    width: 40px;
    height: 4px;
    border-radius: 3px;
    background: var(--border-strong);
  }
  .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-6); }
.cluster {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-3);
}
.cluster-tight { gap: var(--space-2); }

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





.pill-group {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}
.pill {
  border: 1px solid var(--border);
  border-radius: var(--control-radius);
  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;
}
.pill-select-group .pill {
  padding: 0.22rem 0.75rem;
  font-size: 0.8rem;
}
.pill-dropdown {
  overflow: hidden;
}
.pill-dropdown-summary {
  width: 100%;
  border: none;
  background: transparent;
  color: var(--text);
  font-weight: 600;
  font-size: 1rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
  gap: 0.5rem;
  text-align: left;
  padding:
    var(--control-padding-y)
    var(--control-padding-right)
    var(--control-padding-y)
    var(--control-padding-x);
}
.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;
  padding: 0 0.55rem 0.55rem;
  border-top: 1px solid color-mix(in srgb, var(--accent) 25%, transparent);
}
.pill-list[hidden] {
  display: none;
}
.pill-list .pill {
  width: 100%;
  text-align: left;
}
.pill-summary-label {
  color: inherit;
}
.pill-badge-group {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
}

/* ---------- Campaign Calendar ---------- */
.calendar-body {
  min-width: min(94vw, 1360px);
}

.month-nav {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}
.month-nav .month-label {
  font-family: var(--font-display);
  letter-spacing: 0.06em;
  font-size: 1.05rem;
  min-width: 11ch;
  text-align: center;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem 1.5rem;
  padding: 0.75rem 1rem;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.legend-item {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.85rem;
  color: var(--muted);
}

.calendar-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 1.5rem;
  align-items: start;
}
@media (max-width: 900px) {
  .calendar-layout {
    grid-template-columns: 1fr;
  }
}

.calendar-scroll {
  overflow-x: auto;
}
.calendar-panel {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(135px, 1fr));
  min-width: 940px;
}
.cal-weekday {
  font-family: var(--font-display);
  letter-spacing: 0.08em;
  color: var(--accent);
  font-size: 0.82rem;
  text-align: center;
  padding: 0.6rem 0.4rem;
  border-bottom: 1px solid var(--border);
  border-right: 1px solid var(--border);
  background: var(--surface);
}
.cal-weekday:last-child {
  border-right: none;
}

.cal-day {
  min-height: 128px;
  padding: 0.5rem 0.55rem 0.6rem;
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  cursor: pointer;
}
.calendar-grid > .cal-day:nth-child(7n) {
  border-right: none;
}
.cal-day:hover {
  background: color-mix(in srgb, var(--accent) 6%, transparent);
}
.cal-day.outside {
  background: rgba(0, 0, 0, 0.15);
  color: var(--muted);
  cursor: default;
}
.cal-day.outside:hover {
  background: rgba(0, 0, 0, 0.15);
}
.cal-day.outside .cal-day-num {
  opacity: 0.45;
}
.cal-day-num {
  font-family: var(--font-display);
  font-size: 1rem;
  color: var(--text);
}
.cal-day.today {
  background: color-mix(in srgb, var(--accent) 10%, transparent);
  box-shadow: inset 0 0 0 2px var(--accent);
}
.cal-day.today .cal-day-num {
  color: var(--accent-secondary);
  font-weight: 600;
}
.cal-day.selected {
  box-shadow: inset 0 0 0 2px var(--accent-secondary);
}

.cal-day-events {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  overflow: hidden;
}
.evt {
  display: flex;
  align-items: center;
  gap: 0.28rem;
  font-size: 0.68rem;
  padding: 0.1rem 0.3rem;
  border-radius: var(--control-radius);
  border: 1px solid transparent;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.evt-icon {
  flex: 0 0 auto;
  line-height: 1;
}
.evt-label {
  overflow: hidden;
  text-overflow: ellipsis;
}
.evt-anniversary {
  color: var(--accent-secondary);
  border-color: color-mix(in srgb, var(--accent-secondary) 55%, transparent);
  background: linear-gradient(90deg, color-mix(in srgb, var(--success) 12%, transparent), color-mix(in srgb, var(--accent) 12%, transparent));
}
.evt-deathday {
  color: var(--danger-bright);
  border-color: color-mix(in srgb, var(--danger-bright) 55%, transparent);
  background: color-mix(in srgb, var(--danger-bright) 8%, transparent);
}
.evt-session {
  color: var(--accent-secondary);
  border-color: color-mix(in srgb, var(--accent-secondary) 50%, transparent);
  background: color-mix(in srgb, var(--accent-secondary) 8%, transparent);
}
.evt-timejail {
  color: var(--danger-bright);
  border: 1px dashed var(--danger-bright);
  background: color-mix(in srgb, var(--danger) 10%, transparent);
}
.evt-neverforget {
  color: #a48ce0;
  border-color: rgba(122, 92, 194, 0.5);
  background: rgba(122, 92, 194, 0.12);
}

.detail-rail {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.1rem 1.25rem;
}
.detail-rail-eyebrow {
  font-family: var(--font-display);
  letter-spacing: 0.08em;
  color: var(--muted);
  font-size: 0.78rem;
  margin-bottom: 0.15rem;
}
.detail-rail-date {
  font-size: 1.1rem;
  color: var(--accent);
  margin-bottom: 0.8rem;
  padding-bottom: 0.7rem;
  border-bottom: 1px solid var(--border);
}
.detail-session-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.4rem;
  color: var(--accent-secondary);
  font-family: var(--font-display);
  letter-spacing: 0.07em;
  font-size: 0.85rem;
  margin-bottom: 0.6rem;
}
.detail-session-header-label {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}
.detail-edit-btn {
  font-variant: normal;
  letter-spacing: normal;
  flex: 0 0 auto;
}
.detail-session-actions {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  flex: 0 0 auto;
}
.detail-field {
  margin-bottom: 0.85rem;
}
.detail-field-label {
  display: block;
  font-family: var(--font-display);
  letter-spacing: 0.07em;
  color: var(--muted);
  font-size: 0.78rem;
  margin-bottom: 0.35rem;
}
.detail-field-value {
  color: var(--muted);
  font-size: 0.9rem;
}
.detail-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}
.pill-static {
  display: inline-block;
  font-size: 0.78rem;
  padding: 0.18rem 0.55rem;
  border: 1px solid var(--accent);
  border-radius: var(--control-radius);
  color: var(--text);
  background: color-mix(in srgb, var(--accent) 12%, transparent);
}
.detail-notes {
  color: var(--muted);
  font-size: 0.9rem;
  margin: 0;
  line-height: 1.5;
}
.detail-divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 0.85rem 0;
}

/* ---------- DM-only gating ---------- */
body:not(.dm-view) [data-dm-only] {
  display: none !important;
}

/* ---------- Guest gating ---------- */
body.guest-view [data-guest-hide] {
  display: none !important;
}
body.guest-view #identityChip {
  cursor: default;
  pointer-events: none;
}

/* ---------- Per-tab gating ---------- */
body:not([data-active-tab="roster"]) [data-tab-only="roster"] {
  display: none !important;
}

/* ---------- Header identity & theme controls ---------- */
.header-controls {
  align-items: flex-end;
}
.identity-row {
  justify-content: flex-end;
}
.identity-chip strong { color: var(--text); }
.identity-chip {
  font-family: inherit;
  background: var(--surface);
  cursor: pointer;
  transition: border-color 0.15s ease;
}
.identity-chip:hover {
  border-color: var(--accent);
}
.link-btn {
  background: none;
  border: none;
  padding: 0;
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 2px;
  cursor: pointer;
  font-size: 0.85rem;
  font-family: var(--font-body);
}
.link-btn:hover { color: var(--accent-secondary); }
.theme-select {
  width: auto;
  padding: 0.3rem 1.8rem 0.3rem 0.6rem;
  font-size: 0.8rem;
}

/* ---------- Segmented control (Player / DM view) ---------- */
.segmented {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 2px;
  gap: 2px;
}
.segmented input {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  opacity: 0;
}
.segmented label {
  padding: 0.4rem 0.95rem;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.15s ease;
}
.segmented input:checked + label {
  background: var(--accent);
  color: #fff;
}
.segmented input:focus-visible + label {
  outline: 2px solid var(--accent-secondary);
  outline-offset: 2px;
}

/* ---------- Tab navigation ---------- */
.tab-nav {
  display: flex;
  gap: var(--space-6);
  padding: 0 clamp(1.5rem, 5vw, 4rem);
  border-bottom: 1px solid var(--border);
  margin-bottom: var(--space-4);
  overflow-x: auto;
}
.tab-btn {
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  padding: 0.75rem 0.1rem;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.05rem;
  color: var(--muted);
  cursor: pointer;
  white-space: nowrap;
}
.tab-btn:hover { color: var(--text); }
.tab-btn.active {
  color: var(--text);
  border-bottom-color: var(--accent);
}
.tab-panel {
  padding: 0 clamp(1.5rem, 5vw, 4rem) 2rem;
}
.tab-panel[hidden] {
  display: none !important;
}

/* ---------- Portrait plate ---------- */
.plate {
  width: 100%;
  height: 150px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background-color: var(--surface-alt);
  background-size: cover;
  background-position: center;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  color: var(--muted);
  font-size: 0.8rem;
  filter: sepia(0.15) saturate(0.9);
}
.plate.dead {
  filter: grayscale(1) sepia(0.35);
}
.plate.tall {
  height: 190px;
}
.plate-hint {
  padding: 0 1rem;
  text-align: center;
}
.plate.has-image .plate-hint {
  display: none;
}
.portrait-upload {
  display: block;
  margin-bottom: var(--space-3);
}
.portrait-upload:not(.editable) {
  pointer-events: none;
}
.portrait-upload.editable {
  cursor: pointer;
}
.portrait-upload.editable:hover .plate {
  border-color: var(--accent);
}
.portrait-upload.editable .plate-hint::after {
  content: ' (click to upload)';
}
.modal-portrait-row {
  max-width: 260px;
}

/* ---------- In Memoriam ---------- */
.memoriam-sort {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}
.memoriam-sort .label {
  color: var(--muted);
  font-size: 0.8rem;
}
.memoriam-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(270px, 1fr));
  gap: var(--space-4);
}
.memoriam-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-4);
  background: var(--surface);
}
.memoriam-card h3 { margin: 0 0 0.2rem; }
.memoriam-card .plate { margin-bottom: var(--space-3); }
.memoriam-class-line {
  color: var(--muted);
  font-size: 0.85rem;
  margin: 0 0 0.5rem;
}
.memoriam-cause {
  font-style: italic;
  color: var(--muted);
  margin: 0 0 0.5rem;
}
.memoriam-meta {
  font-size: 0.8rem;
  color: var(--muted);
  margin: 0 0 0.5rem;
}
.memoriam-actions {
  margin-top: var(--space-2);
}

/* ---------- Activity feed ---------- */
.activity-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}
.activity-row {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}
.activity-icon {
  flex: 0 0 auto;
  width: 2rem;
  height: 2rem;
  border-radius: 50%;
  border: 1px solid var(--accent);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.95rem;
}
.activity-body { flex: 1; }
.activity-title { font-weight: 600; }
.activity-detail {
  color: var(--muted);
  font-size: 0.88rem;
  margin: 0.15rem 0 0;
}
.activity-date {
  flex: 0 0 auto;
  color: var(--muted);
  font-size: 0.8rem;
  white-space: nowrap;
}

/* ---------- Identity ("Who are you?") modal ---------- */
#identityModal { min-width: min(90vw, 460px); }
.identity-players {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

@media (max-width: 900px) {
  .header-controls { align-items: stretch; }
  .identity-row { justify-content: flex-start; }
  .tab-nav { gap: var(--space-4); }
}
