:root {
  --bg-deep: #0d0b12;
  --bg-surface: #161320;
  --bg-card: #1e1a2b;
  --bg-card-hover: #272238;
  --bg-elevated: #2a243d;
  --border-subtle: rgba(212, 175, 55, 0.18);
  --border-gold: rgba(212, 175, 55, 0.45);
  --gold-primary: #e2b857;
  --gold-bright: #f7d774;
  --text-main: #f3efe6;
  --text-muted: #a9a1b8;
  --text-dim: #756d86;

  --team-townsfolk: #3b82f6;
  --team-townsfolk-bg: rgba(59, 130, 246, 0.15);
  --team-outsider: #06b6d4;
  --team-outsider-bg: rgba(6, 182, 212, 0.15);
  --team-minion: #f97316;
  --team-minion-bg: rgba(249, 115, 22, 0.15);
  --team-demon: #ef4444;
  --team-demon-bg: rgba(239, 68, 68, 0.16);
  --team-traveller: #a855f7;
  --team-traveller-bg: rgba(168, 85, 247, 0.15);
  --team-fabled: #eab308;
  --team-fabled-bg: rgba(234, 179, 8, 0.15);

  --status-ok: #10b981;
  --status-warn: #f59e0b;
  --status-danger: #ef4444;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.55);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  background: radial-gradient(circle at 50% 0%, #221a36 0%, var(--bg-deep) 70%);
  color: var(--text-main);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
  line-height: 1.5;
  min-height: 100vh;
  overflow-x: hidden;
}

h1, h2, h3, h4, .serif-title {
  font-family: Georgia, 'Times New Roman', serif;
  letter-spacing: 0.02em;
}

button, input, select, textarea {
  font: inherit;
  color: inherit;
}

/* Header & Navigation */
.app-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(16, 13, 24, 0.94);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-subtle);
  padding: 0.65rem 1.25rem;
}

.header-inner {
  max-width: 1480px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.brand-emblem {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: radial-gradient(circle, #4a1525 0%, #1c0c1b 100%);
  border: 2px solid var(--gold-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.3rem;
  box-shadow: 0 0 12px rgba(226, 184, 87, 0.25);
}

.brand-title {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--gold-bright);
  line-height: 1.15;
}

.brand-subtitle {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.nav-tabs {
  display: flex;
  gap: 0.35rem;
  flex-wrap: wrap;
}

.nav-tab {
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-muted);
  padding: 0.5rem 0.9rem;
  border-radius: var(--radius-md);
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  transition: all 0.16s ease;
}

.nav-tab:hover {
  color: var(--text-main);
  background: rgba(255, 255, 255, 0.05);
}

.nav-tab.active {
  color: var(--gold-bright);
  background: rgba(226, 184, 87, 0.14);
  border-color: var(--border-gold);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  padding: 0.5rem 0.95rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-subtle);
  background: var(--bg-elevated);
  color: var(--text-main);
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
}

.btn:hover {
  background: #362e4f;
  border-color: var(--border-gold);
}

.btn-primary {
  background: linear-gradient(135deg, #8b1e3f 0%, #5e1129 100%);
  border-color: #d45b7a;
  color: #fff;
}

.btn-primary:hover {
  background: linear-gradient(135deg, #a5244b 0%, #731633 100%);
  border-color: var(--gold-bright);
}

.btn-gold {
  background: linear-gradient(135deg, #b88928 0%, #876012 100%);
  border-color: var(--gold-bright);
  color: #fff;
}

.btn-gold:hover {
  background: linear-gradient(135deg, #cfa038 0%, #9c7119 100%);
}

.btn-sm {
  padding: 0.3rem 0.65rem;
  font-size: 0.8rem;
}

.btn-danger {
  background: rgba(239, 68, 68, 0.18);
  border-color: rgba(239, 68, 68, 0.45);
  color: #fca5a5;
}

.btn-danger:hover {
  background: rgba(239, 68, 68, 0.3);
}

/* Main Container */
.main-container {
  max-width: 1480px;
  margin: 0 auto;
  padding: 1.25rem;
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
}

/* Grid & Panels */
.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.25rem;
}

.grid-setup {
  display: grid;
  grid-template-columns: 380px 1fr;
  gap: 1.25rem;
  align-items: start;
}

.grid-grimoire {
  display: grid;
  grid-template-columns: 1fr 390px;
  gap: 1.25rem;
  align-items: start;
}

@media (max-width: 1100px) {
  .grid-2, .grid-setup, .grid-grimoire {
    grid-template-columns: 1fr;
  }
}

.panel {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 1.15rem;
  box-shadow: var(--shadow-lg);
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 1rem;
  padding-bottom: 0.65rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.07);
  flex-wrap: wrap;
}

.panel-title {
  font-size: 1.1rem;
  color: var(--gold-bright);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* Form Controls */
.form-group {
  margin-bottom: 0.9rem;
}

.form-label {
  display: block;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 0.35rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.input, .select, .textarea {
  width: 100%;
  padding: 0.55rem 0.75rem;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  color: var(--text-main);
  font-size: 0.92rem;
}

.input:focus, .select:focus, .textarea:focus {
  outline: none;
  border-color: var(--gold-primary);
}

/* Distribution Pills */
.dist-bar {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.5rem;
  margin: 0.75rem 0;
}

.dist-pill {
  padding: 0.55rem 0.4rem;
  border-radius: var(--radius-md);
  text-align: center;
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.dist-pill .count {
  font-size: 1.35rem;
  font-weight: 800;
  line-height: 1.1;
}

.dist-pill .label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  opacity: 0.9;
}

.dist-pill .mod-tag {
  font-size: 0.7rem;
  display: block;
  margin-top: 2px;
  color: var(--gold-bright);
}

.team-townsfolk {
  background: var(--team-townsfolk-bg);
  border-color: rgba(59, 130, 246, 0.4);
  color: #93c5fd;
}
.team-outsider {
  background: var(--team-outsider-bg);
  border-color: rgba(6, 182, 212, 0.4);
  color: #67e8f9;
}
.team-minion {
  background: var(--team-minion-bg);
  border-color: rgba(249, 115, 22, 0.4);
  color: #fdba74;
}
.team-demon {
  background: var(--team-demon-bg);
  border-color: rgba(239, 68, 68, 0.45);
  color: #fca5a5;
}
.team-traveller {
  background: var(--team-traveller-bg);
  border-color: rgba(168, 85, 247, 0.4);
  color: #d8b4fe;
}
.team-fabled {
  background: var(--team-fabled-bg);
  border-color: rgba(234, 179, 8, 0.45);
  color: #fde047;
}

/* Character Token Cards */
.role-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(235px, 1fr));
  gap: 0.65rem;
}

.role-card {
  background: var(--bg-card);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: var(--radius-md);
  padding: 0.65rem 0.75rem;
  display: flex;
  gap: 0.65rem;
  align-items: flex-start;
  cursor: pointer;
  transition: all 0.14s ease;
  position: relative;
}

.role-card:hover {
  background: var(--bg-card-hover);
  border-color: rgba(255, 255, 255, 0.22);
}

.role-card.selected {
  border-width: 2px;
  box-shadow: 0 0 14px rgba(226, 184, 87, 0.2);
}

.role-card.selected.card-townsfolk {
  border-color: var(--team-townsfolk);
  background: rgba(59, 130, 246, 0.14);
}
.role-card.selected.card-outsider {
  border-color: var(--team-outsider);
  background: rgba(6, 182, 212, 0.14);
}
.role-card.selected.card-minion {
  border-color: var(--team-minion);
  background: rgba(249, 115, 22, 0.14);
}
.role-card.selected.card-demon {
  border-color: var(--team-demon);
  background: rgba(239, 68, 68, 0.16);
}

.role-token-icon {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
  background: radial-gradient(circle, #2e2742 0%, #161221 100%);
  border: 2px solid rgba(255, 255, 255, 0.2);
}

.card-townsfolk .role-token-icon { border-color: var(--team-townsfolk); }
.card-outsider .role-token-icon { border-color: var(--team-outsider); }
.card-minion .role-token-icon { border-color: var(--team-minion); }
.card-demon .role-token-icon { border-color: var(--team-demon); }
.card-traveller .role-token-icon { border-color: var(--team-traveller); }
.card-fabled .role-token-icon { border-color: var(--team-fabled); }

.role-card-body {
  flex: 1;
  min-width: 0;
}

.role-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.35rem;
}

.role-name {
  font-weight: 700;
  font-size: 0.92rem;
  color: var(--text-main);
}

.role-ability {
  font-size: 0.76rem;
  color: var(--text-muted);
  margin-top: 0.2rem;
  line-height: 1.35;
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.12rem 0.45rem;
  border-radius: 999px;
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.badge-setup {
  background: rgba(234, 179, 8, 0.2);
  color: #fde047;
  border: 1px solid rgba(234, 179, 8, 0.45);
}

/* Status Banner */
.validation-banner {
  padding: 0.75rem 1rem;
  border-radius: var(--radius-md);
  margin-bottom: 1rem;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.validation-banner.valid {
  background: rgba(16, 185, 129, 0.13);
  border: 1px solid rgba(16, 185, 129, 0.45);
  color: #a7f3d0;
}

.validation-banner.invalid {
  background: rgba(245, 158, 11, 0.14);
  border: 1px solid rgba(245, 158, 11, 0.45);
  color: #fde68a;
}

/* Grimoire Town Square Circle */
.grimoire-board {
  position: relative;
  width: 100%;
  min-height: 620px;
  background: radial-gradient(circle at center, #231c35 0%, #120e1c 72%);
  border: 1px solid var(--border-gold);
  border-radius: var(--radius-lg);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

.grimoire-center-hub {
  width: 240px;
  padding: 1rem;
  border-radius: 50%;
  aspect-ratio: 1;
  background: rgba(15, 12, 24, 0.88);
  border: 1px dashed var(--border-gold);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  z-index: 2;
  pointer-events: auto;
}

.seat-node {
  position: absolute;
  width: 128px;
  transform: translate(-50%, -50%);
  background: rgba(26, 22, 38, 0.95);
  border: 2px solid rgba(255, 255, 255, 0.18);
  border-radius: var(--radius-md);
  padding: 0.45rem 0.5rem;
  text-align: center;
  cursor: pointer;
  transition: transform 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
  z-index: 5;
}

.seat-node:hover {
  transform: translate(-50%, -50%) scale(1.05);
  border-color: var(--gold-bright);
  z-index: 10;
}

.seat-node.active-seat {
  border-color: var(--gold-bright);
  box-shadow: 0 0 18px rgba(247, 215, 116, 0.45);
  z-index: 12;
}

.seat-node.is-dead {
  opacity: 0.78;
  background: rgba(14, 12, 20, 0.95);
  border-style: dashed;
}

.seat-shroud {
  position: absolute;
  top: -8px;
  right: -8px;
  background: #111;
  border: 1px solid #ef4444;
  border-radius: 999px;
  padding: 1px 6px;
  font-size: 0.65rem;
  color: #fca5a5;
  font-weight: 700;
}

.seat-ghost-vote {
  position: absolute;
  top: -8px;
  left: -8px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
  background: #3b82f6;
  color: #fff;
  border: 1px solid #93c5fd;
  box-shadow: 0 0 8px rgba(59, 130, 246, 0.6);
}

.seat-ghost-vote.used {
  background: #374151;
  border-color: #6b7280;
  color: #9ca3af;
  box-shadow: none;
  text-decoration: line-through;
}

.seat-token-circle {
  width: 44px;
  height: 44px;
  margin: 0 auto 0.25rem;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
  background: radial-gradient(circle, #32294a 0%, #161221 100%);
  border: 2px solid rgba(255, 255, 255, 0.25);
}

.seat-player-name {
  font-size: 0.8rem;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.seat-role-name {
  font-size: 0.72rem;
  color: var(--gold-bright);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.seat-believes {
  font-size: 0.65rem;
  color: #67e8f9;
  background: rgba(6, 182, 212, 0.15);
  border-radius: 4px;
  padding: 0 4px;
  margin-top: 2px;
  display: inline-block;
}

.seat-reminders {
  display: flex;
  flex-wrap: wrap;
  gap: 3px;
  justify-content: center;
  margin-top: 4px;
}

.reminder-pill {
  font-size: 0.62rem;
  padding: 1px 5px;
  border-radius: 999px;
  background: #3b2d54;
  border: 1px solid var(--gold-primary);
  color: #fde68a;
  max-width: 115px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Night Order Table / List */
.night-step {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 0.8rem 1rem;
  margin-bottom: 0.6rem;
  display: flex;
  align-items: flex-start;
  gap: 0.85rem;
  transition: opacity 0.15s ease;
}

.night-step.checked {
  opacity: 0.52;
  background: rgba(20, 17, 29, 0.6);
}

.night-step-check {
  width: 22px;
  height: 22px;
  margin-top: 0.2rem;
  accent-color: var(--gold-primary);
  cursor: pointer;
}

/* Fullscreen Show-Player Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(5, 4, 9, 0.95);
  z-index: 1000;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}

.modal-backdrop.open {
  display: flex;
}

.show-card-screen {
  width: 100%;
  max-width: 900px;
  min-height: 75vh;
  background: radial-gradient(circle at center, #281d3f 0%, #0d0914 100%);
  border: 3px solid var(--gold-primary);
  border-radius: 20px;
  padding: 2.5rem 2rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  box-shadow: 0 0 60px rgba(0, 0, 0, 0.9);
  position: relative;
}

.show-card-heading {
  font-size: clamp(1.4rem, 3.5vw, 2.4rem);
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.12em;
  margin-bottom: 1.5rem;
}

.show-card-tokens {
  display: flex;
  flex-wrap: wrap;
  gap: 1.75rem;
  justify-content: center;
  align-items: center;
  margin: 1rem 0 1.75rem;
}

.giant-token {
  width: 170px;
  height: 170px;
  border-radius: 50%;
  background: radial-gradient(circle, #3b2d54 0%, #151022 100%);
  border: 4px solid var(--gold-bright);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.65);
}

.giant-token .icon {
  font-size: 3.4rem;
  line-height: 1;
}

.giant-token .name {
  font-family: Georgia, serif;
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--gold-bright);
  margin-top: 0.45rem;
}

.show-card-bigtext {
  font-size: clamp(2rem, 5.5vw, 4.2rem);
  font-weight: 800;
  color: #fff;
  margin: 0.5rem 0;
  line-height: 1.2;
}

.show-card-ability {
  max-width: 650px;
  font-size: clamp(1.05rem, 2.2vw, 1.35rem);
  color: var(--text-main);
  margin-top: 0.75rem;
  opacity: 0.92;
}

/* Sub-navigation / Pills */
.pill-group {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.pill-btn {
  padding: 0.35rem 0.75rem;
  border-radius: 999px;
  border: 1px solid var(--border-subtle);
  background: var(--bg-card);
  color: var(--text-muted);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
}

.pill-btn.active {
  background: rgba(226, 184, 87, 0.2);
  border-color: var(--gold-bright);
  color: var(--gold-bright);
}

/* Table */
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.86rem;
}

.data-table th, .data-table td {
  padding: 0.55rem 0.7rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.07);
  text-align: left;
}

.data-table th {
  color: var(--gold-primary);
  font-weight: 700;
  text-transform: uppercase;
  font-size: 0.74rem;
  letter-spacing: 0.04em;
}

.data-table tr.highlight-row {
  background: rgba(226, 184, 87, 0.14);
  font-weight: 700;
}

/* Mobile Responsive Adjustments */
@media (max-width: 768px) {
  .grimoire-board {
    min-height: 500px;
  }
  .seat-node {
    width: 98px;
    padding: 0.3rem;
  }
  .seat-token-circle {
    width: 34px;
    height: 34px;
    font-size: 1.1rem;
  }
  .grimoire-center-hub {
    width: 165px;
    padding: 0.6rem;
    font-size: 0.8rem;
  }
}

/* Print Stylesheet for Script & Night Order Reference Sheets */
@media print {
  body {
    background: #fff !important;
    color: #000 !important;
  }
  .app-header, .no-print {
    display: none !important;
  }
  .panel {
    background: #fff !important;
    border: 1px solid #ccc !important;
    box-shadow: none !important;
    color: #000 !important;
  }
}
