:root {
  --sg-blue: #2C374C;
  --sg-gold: #C7B299;
  --sg-light-grey: #ACB2B8;
  --sg-grey: #666666;
  --sg-dark-grey: #444444;
  --sg-white: #FFFFFF;
  --sg-footer-height: 2.5rem;
  --sg-header-height: 5.5rem;

  /* Categorical graph palette: fixed order required for colorblind readability (see style-guide.md) */
  --sg-graph-color-1: #2a78d6;
  --sg-graph-color-2: #eb6834;
  --sg-graph-color-3: #1baf7a;
  --sg-graph-color-4: #eda100;
  --sg-graph-color-5: #e87ba4;
  --sg-graph-color-6: #008300;
  --sg-graph-color-7: #4a3aa7;
  --sg-graph-color-8: #e34948;
}

body {
  font-family: "Ubuntu", sans-serif;
  font-weight: 400;
  color: var(--sg-grey);
  background-color: var(--sg-white);
  min-height: 100vh;
  padding-bottom: var(--sg-footer-height);
}

h1, h2, h3 {
  font-weight: 700;
  color: var(--sg-dark-grey);
}

h4, h5, h6 {
  font-weight: 500;
  color: var(--sg-dark-grey);
}

small {
  font-weight: 300;
  color: var(--sg-grey);
}

/* Header */

.sg-header {
  position: sticky;
  top: 0;
  z-index: 1060;
  background-color: var(--sg-blue);
  color: var(--sg-white);
  padding: 0.75rem 0;
  border-bottom: 2px solid var(--sg-gold);
}

.sg-header-logo {
  height: 48px;
  width: auto;
}

.sg-header-title {
  font-weight: 700;
  font-size: 1.25rem;
  color: var(--sg-white);
}

.sg-lang-flag {
  font-size: 1rem;
  line-height: 1;
}

.sg-header-tagline {
  font-weight: 300;
  font-size: 0.85rem;
  color: var(--sg-white);
}

.sg-header-actions {
  flex-shrink: 0;
}

.sg-header-universe {
  min-width: 0;
  flex: 1 1 0%;
}

.sg-header-cover {
  height: 3.75rem;
  width: auto;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  border-radius: 0.375rem;
  flex-shrink: 0;
}

.sg-header-universe-info {
  min-width: 0;
  flex: 1 1 0%;
}

.sg-header-universe-title {
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--sg-white);
}

/* Home */

.sg-home-title {
  margin-bottom: 1.5rem;
}

.sg-home-section + .sg-home-section {
  margin-top: 3rem;
}

.sg-home-section-title {
  margin-bottom: 1.5rem;
}

.sg-home-empty {
  color: var(--sg-grey);
}

/* Universe */

.sg-universe-empty {
  color: var(--sg-grey);
}

/* Mosaic view / Graph view switcher (in the header, see style-guide.md) */

.sg-view-switcher-btn {
  color: var(--sg-white);
  background-color: transparent;
  border-color: rgba(255, 255, 255, 0.4);
}

.sg-view-switcher-btn:hover,
.sg-view-switcher-btn:focus {
  color: var(--sg-gold);
  border-color: var(--sg-gold);
}

.sg-view-switcher-btn.active {
  background-color: var(--sg-gold);
  color: var(--sg-blue);
  border-color: var(--sg-gold);
}

/* Cards (mosaics) */

.sg-card-link {
  display: block;
  color: inherit;
}

.sg-card {
  background-color: var(--sg-white);
  border-color: var(--sg-light-grey);
  transition: box-shadow 0.2s ease, border-color 0.2s ease;
}

.sg-card:hover,
.sg-card-link:focus .sg-card,
.sg-card:focus-within {
  box-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.15);
  border-color: var(--sg-gold);
}

.sg-card-img {
  aspect-ratio: 16 / 9;
  object-fit: cover;
}

.sg-character-portrait {
  aspect-ratio: 1 / 1;
  object-fit: cover;
}

/* Character card only (see style-guide.md, Tuiles): border between the portrait
   and the card body, and bottom-right badge for the character's group, white/
   absent when the character has no group. Fixed-height text zone, same
   principle as .sg-universe-card below, but the description is truncated
   (truncatewords in character-card.html) rather than scrollable, so excess
   is clipped instead of scrolled. flex: 0 0 auto keeps the height fixed
   regardless of Bootstrap's card-body flex-grow. */
.sg-character-card .card-body {
  flex: 0 0 auto;
  height: 11rem;
  overflow: hidden;
  border-top: 10px solid var(--sg-white);
}

.sg-character-portrait-wrap {
  position: relative;
}

.sg-character-card-group-logo {
  position: absolute;
  right: 0.5rem;
  bottom: 0.5rem;
  width: 2rem;
  height: 2rem;
  object-fit: contain;
}

/* Universe card only (home page, see style-guide.md, Tuiles): fixed-height,
   scrollable text zone below a fixed cover. Keeps every tile the same height
   regardless of description length. */
.sg-universe-card-cover-wrap {
  position: relative;
}

.sg-universe-card-cover-caption {
  font-weight: 300;
  font-style: italic;
  font-size: 0.8rem;
  color: var(--sg-grey);
  text-align: right;
  margin-top: 0.5rem;
  margin-bottom: 0;
}

/* flex: 0 0 auto so this fixed height is never overridden by flex-grow
   (see .card-body's flex: 1 1 auto in Bootstrap), keeping every tile the
   same height regardless of description length. Column flex so the title
   stays fixed and only .sg-universe-card-scroll below it scrolls. */
.sg-universe-card .card-body {
  flex: 0 0 auto;
  height: calc(9rem + 10px);
  display: flex;
  flex-direction: column;
}

.sg-universe-card .sg-card-title {
  flex: 0 0 auto;
}

/* min-height: 0 overrides the flex item default (min-height: auto), which
   would otherwise let this grow past its share and prevent overflow-y from
   ever kicking in. */
.sg-universe-card-scroll {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
}

.sg-card-title {
  color: var(--sg-dark-grey);
}

.sg-card-text {
  color: var(--sg-grey);
  text-align: justify;
}

/* Footer */

.sg-footer {
  position: fixed;
  bottom: 0;
  left: 0;
  width: 100%;
  padding: 0.5rem 0;
  background-color: var(--sg-dark-grey);
  color: var(--sg-white);
  border-top: 2px solid var(--sg-light-grey);
  z-index: 1020;
  font-size: 0.8rem;
}

.sg-footer a {
  color: var(--sg-white);
}

.sg-footer a:hover {
  color: var(--sg-gold);
}

/* Modal (character sheet) */

.modal.sg-character-modal {
  top: var(--sg-header-height);
  height: calc(100% - var(--sg-header-height));
}

.sg-character-modal .modal-content {
  background-color: var(--sg-white);
  position: relative;
  overflow: hidden;
}

/* Top border and top-left badge for the character's group (see style-guide.md,
   Modale), white/absent when the character has no group. Positioned against
   .modal-content (the nearest positioned ancestor), not against the modal-body
   they live in, since only the modal-body's content is swapped on navigation
   between related characters (see character-modal.js). */
.sg-character-modal-group-bar {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 10px;
  background-color: var(--sg-white);
}

.sg-character-modal-group-logo {
  position: absolute;
  top: 0.75rem;
  left: 0.75rem;
  width: 2.5rem;
  height: 2.5rem;
  object-fit: contain;
  z-index: 4;
}

.sg-character-modal-close {
  position: absolute;
  top: 0.75rem;
  right: 0.75rem;
  z-index: 5;
  background: transparent;
  border: none;
  color: var(--sg-grey);
  font-size: 1.25rem;
  line-height: 1;
  padding: 0.5rem;
}

.sg-character-modal-close:hover {
  color: var(--sg-dark-grey);
}

.sg-character-modal-portrait-wrap {
  margin: 0 0 1rem;
  text-align: center;
}

.sg-character-modal-portrait {
  width: 160px;
  height: 160px;
  object-fit: cover;
  border-radius: 50%;
}

.sg-character-modal-portrait-caption {
  font-weight: 300;
  font-style: italic;
  font-size: 0.8rem;
  color: var(--sg-grey);
  text-align: right;
  margin-top: 1.5rem;
  margin-bottom: 0;
}

.sg-character-modal-title {
  color: var(--sg-dark-grey);
  text-align: center;
}

.sg-character-modal-description {
  color: var(--sg-grey);
  text-align: justify;
}

.sg-character-modal-metadata {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.25rem 0.75rem;
  color: var(--sg-grey);
  margin-top: 1rem;
}

.sg-character-modal-metadata dt {
  font-weight: 500;
  color: var(--sg-dark-grey);
}

.sg-character-modal-metadata dd {
  margin: 0;
}

.sg-character-modal-external-link {
  margin-top: 1rem;
}

.sg-character-modal-portrait-caption a,
.sg-character-modal-relation a,
.sg-character-modal-external-link a,
.sg-universe-card-cover-caption a {
  color: var(--sg-gold);
  text-decoration: none;
}

.sg-character-modal-portrait-caption a:hover,
.sg-character-modal-relation a:hover,
.sg-character-modal-external-link a:hover,
.sg-universe-card-cover-caption a:hover {
  color: var(--sg-grey);
  text-decoration: none;
}

.sg-character-modal-relations-heading {
  margin-top: 1.5rem;
  margin-bottom: 1rem;
}

.sg-character-modal-relations {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.sg-relation-group-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin-top: 0;
}

.sg-character-modal-relation::marker {
  font-size: 1.4em;
}

.sg-relation-group-heading {
  color: var(--sg-blue);
  font-weight: 500;
  font-size: 1rem;
  margin: 0;
}

.sg-relation-description {
  color: var(--sg-grey);
  font-size: 0.85rem;
  margin: 0.15rem 0 0;
}

.sg-character-modal-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  padding: 2rem 0;
  color: var(--sg-grey);
}

.sg-character-modal-error,
.sg-not-available {
  color: var(--sg-grey);
  text-align: center;
  padding: 2rem 0;
}

/* Neutral "outline" button: graph zoom, search/filter controls */

.sg-btn-outline-neutral {
  border-color: var(--sg-grey);
  color: var(--sg-dark-grey);
}

.sg-btn-outline-neutral:hover,
.sg-btn-outline-neutral:focus {
  border-color: var(--sg-gold);
  color: var(--sg-blue);
}

/* Search / filters (bar shared by Mosaic view and Graph view; the relation type
   filter, below the graph in Graph view, reuses these same classes on its own
   block, see search-filter.md and graph-view.md) */

.sg-search-filter {
  margin-bottom: 1.5rem;
}

.sg-search-filter-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 1rem 1.5rem;
}

/* Group filters sit on their own row, below the search bar (see search-filter.md). */
.sg-search-filter-row-groups {
  margin-top: 0.75rem;
}

.sg-search-input-group {
  max-width: 320px;
}

.sg-search-icon {
  background-color: var(--sg-white);
  color: var(--sg-grey);
  border-color: var(--sg-light-grey);
}

.sg-search-input {
  border-color: var(--sg-light-grey);
}

.sg-filter-label {
  cursor: pointer;
}

/* Graph view */

.sg-graph-container {
  position: relative;
  margin-bottom: 1.5rem;
}

.sg-graph-zoom-controls {
  position: absolute;
  top: 0.75rem;
  right: 0.75rem;
  z-index: 5;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.sg-graph-zoom-btn {
  width: 2rem;
  height: 2rem;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: var(--sg-white);
}

.sg-graph {
  width: 100%;
  height: 70vh;
  min-height: 480px;
  background-color: var(--sg-white);
  border: 1px solid var(--sg-light-grey);
  border-radius: 0.375rem;
  overflow: hidden;
  touch-action: none;
}

.sg-graph-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  height: 100%;
  color: var(--sg-grey);
}

.sg-graph-empty,
.sg-search-filter-empty {
  color: var(--sg-grey);
  margin-top: 0.75rem;
}

.sg-graph-svg {
  display: block;
  width: 100%;
  height: 100%;
}

.sg-graph-link {
  fill: none;
  stroke-width: 1.5px;
}

.sg-graph-link-filtered {
  display: none;
}

/* Compensates for lower contrast on white background for these three hues (see style-guide.md) */
.sg-graph-link[data-color-index="3"],
.sg-graph-link[data-color-index="4"],
.sg-graph-link[data-color-index="5"] {
  stroke-width: 2.5px;
}

.sg-graph-node {
  cursor: pointer;
}

/* Opaque white backdrop only: masks link start-points under the node and any
   transparent corners of the portrait. The visible group border is a separate
   circle drawn on top of the portrait, see .sg-graph-node-border below. */
.sg-graph-node-ring {
  fill: var(--sg-white);
}

/* Group border color, set per node via --sg-node-ring-color (see graph.js);
   white when the character has no group (see "Groupe" in data-model.md). */
.sg-graph-node-border {
  fill: none;
  stroke: var(--sg-node-ring-color, var(--sg-white));
  stroke-width: 3px;
  transition: stroke-opacity 0.15s ease;
}

.sg-graph-node-group-logo {
  pointer-events: none;
}

/* Group filter: hides the node outright, and (via graph.js data-source/data-target
   attributes, matched in search-filter.js) the edges attached to it, unlike the
   type filter which only ever hides edges (see search-filter.md). */
.sg-graph-node-hidden {
  display: none;
}

.sg-graph-node-portrait {
  transition: opacity 0.15s ease;
}

/* The ring's (opaque) fill stays unchanged so it keeps masking where links start
   under the node; only the border and the portrait dim (see search-filter.md). */
.sg-graph-node-dimmed .sg-graph-node-border {
  stroke-opacity: 0.2;
}

.sg-graph-node-dimmed .sg-graph-node-portrait {
  opacity: 0.2;
}

.sg-graph-node:hover .sg-graph-node-border,
.sg-graph-node:focus .sg-graph-node-border {
  stroke: var(--sg-gold);
}

.sg-graph-node-label {
  opacity: 0;
  transition: opacity 0.15s ease;
  pointer-events: none;
}

.sg-graph-node:hover .sg-graph-node-label,
.sg-graph-node:focus .sg-graph-node-label {
  opacity: 1;
}

.sg-graph-node-label-bg {
  fill: var(--sg-white);
}

.sg-graph-node-label-text {
  font-size: 0.7rem;
  font-weight: 500;
  fill: var(--sg-dark-grey);
}

.sg-graph-tooltip {
  position: absolute;
  z-index: 10;
  max-width: 220px;
  padding: 0.5rem 0.75rem;
  background-color: var(--sg-blue);
  color: var(--sg-white);
  border-radius: 0.25rem;
  font-size: 0.8rem;
  pointer-events: none;
}

.sg-graph-tooltip strong {
  color: var(--sg-white);
  font-weight: 500;
}

.sg-graph-tooltip p {
  font-weight: 300;
  margin: 0.25rem 0 0;
}

.sg-legend-list {
  /* Each filter joins the flex-wrap of its parent .sg-search-filter-row. */
  display: contents;
}

.sg-legend-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--sg-dark-grey);
}

.sg-legend-swatch,
.sg-legend-logo {
  flex: 0 0 auto;
}

.sg-legend-swatch {
  width: 0.85rem;
  height: 0.85rem;
  border-radius: 50%;
}

/* Group filters use the group's own logo as their visual identifier instead of a
   color swatch (see "Barre de recherche / filtres" in style-guide.md). */
.sg-legend-logo {
  width: 1.1rem;
  height: 1.1rem;
  object-fit: contain;
}

/* Unavailability message (404): see .sg-character-modal-error above */
