/* =========================================================
   CODEX ASSET STATE / RENDERED IMAGE LAYERS
   ========================================================= */

[data-codex-image-source].codex-image-missing {
  --codex-record-image: none !important;
  --codex-map-image: none !important;
}

[data-codex-image-source].codex-image-loaded {
  --codex-record-image: none !important;
  --codex-map-image: none !important;
}

.codex-placeholder-npc.codex-image-loaded::before,
.codex-placeholder-settlement.codex-image-loaded::before,
.codex-placeholder-poi.codex-image-loaded::before,
.codex-placeholder-region.codex-image-loaded::before {
  opacity: 0 !important;
}

.codex-placeholder-npc.codex-image-missing::before,
.codex-placeholder-settlement.codex-image-missing::before,
.codex-placeholder-poi.codex-image-missing::before,
.codex-placeholder-region.codex-image-missing::before {
  opacity: 0.90;
}

.codex-rendered-image-layer {
  position: absolute;
  z-index: 1;

  display: block;
  max-width: none;
  max-height: none;

  object-fit: cover;
  object-position: center;

  opacity: 0;
  transition: opacity 0.16s ease;

  pointer-events: none;

  -webkit-mask-image:
    linear-gradient(
      to right,
      transparent 0%,
      rgba(0, 0, 0, 0.22) 4%,
      rgba(0, 0, 0, 0.82) 11%,
      black 20%,
      black 80%,
      rgba(0, 0, 0, 0.82) 89%,
      rgba(0, 0, 0, 0.22) 96%,
      transparent 100%
    ),
    linear-gradient(
      to bottom,
      transparent 0%,
      rgba(0, 0, 0, 0.22) 4%,
      rgba(0, 0, 0, 0.82) 11%,
      black 20%,
      black 80%,
      rgba(0, 0, 0, 0.82) 89%,
      rgba(0, 0, 0, 0.22) 96%,
      transparent 100%
    );
  -webkit-mask-composite: source-in;

  mask-image:
    linear-gradient(
      to right,
      transparent 0%,
      rgba(0, 0, 0, 0.22) 4%,
      rgba(0, 0, 0, 0.82) 11%,
      black 20%,
      black 80%,
      rgba(0, 0, 0, 0.82) 89%,
      rgba(0, 0, 0, 0.22) 96%,
      transparent 100%
    ),
    linear-gradient(
      to bottom,
      transparent 0%,
      rgba(0, 0, 0, 0.22) 4%,
      rgba(0, 0, 0, 0.82) 11%,
      black 20%,
      black 80%,
      rgba(0, 0, 0, 0.82) 89%,
      rgba(0, 0, 0, 0.22) 96%,
      transparent 100%
    );
  mask-composite: intersect;
}

.codex-image-loaded > .codex-rendered-image-layer {
  opacity: 1;
}

.codex-image-missing > .codex-rendered-image-layer {
  display: none;
}

#codex-content .codex-detail-portrait-slot {
  isolation: isolate;

  -webkit-mask-image: none !important;
  mask-image: none !important;

  background: transparent !important;
  box-shadow: none !important;
  outline: none !important;
}

#codex-content .codex-detail-portrait-slot::before,
#codex-content .codex-detail-portrait-slot > .codex-rendered-image-layer {
  z-index: 1;

  -webkit-mask-image:
    linear-gradient(
      to right,
      transparent 0%,
      rgba(0, 0, 0, 0.22) 4%,
      rgba(0, 0, 0, 0.82) 10%,
      black 18%,
      black 82%,
      rgba(0, 0, 0, 0.82) 90%,
      rgba(0, 0, 0, 0.22) 96%,
      transparent 100%
    ),
    linear-gradient(
      to bottom,
      transparent 0%,
      rgba(0, 0, 0, 0.22) 4%,
      rgba(0, 0, 0, 0.82) 10%,
      black 18%,
      black 82%,
      rgba(0, 0, 0, 0.82) 90%,
      rgba(0, 0, 0, 0.22) 96%,
      transparent 100%
    ) !important;
  -webkit-mask-composite: source-in;
  mask-image:
    linear-gradient(
      to right,
      transparent 0%,
      rgba(0, 0, 0, 0.22) 4%,
      rgba(0, 0, 0, 0.82) 10%,
      black 18%,
      black 82%,
      rgba(0, 0, 0, 0.82) 90%,
      rgba(0, 0, 0, 0.22) 96%,
      transparent 100%
    ),
    linear-gradient(
      to bottom,
      transparent 0%,
      rgba(0, 0, 0, 0.22) 4%,
      rgba(0, 0, 0, 0.82) 10%,
      black 18%,
      black 82%,
      rgba(0, 0, 0, 0.82) 90%,
      rgba(0, 0, 0, 0.22) 96%,
      transparent 100%
    ) !important;
  mask-composite: intersect !important;
}

#codex-content .codex-detail-portrait-slot.codex-image-loaded {
  background: transparent !important;
  border: 0 !important;
  box-shadow: none !important;
  outline: none !important;
}

#codex-content .codex-detail-portrait-slot.codex-image-loaded::before,
#codex-content .codex-detail-portrait-slot.codex-image-loaded::after {
  opacity: 0 !important;
  background: transparent !important;
  border: 0 !important;
  box-shadow: none !important;
  outline: none !important;
}

#codex-content .codex-detail-portrait-slot.codex-image-loaded > .codex-rendered-image-layer {
  background: transparent !important;
  border: 0 !important;
  box-shadow: none !important;
  outline: none !important;
}

#codex-content .codex-detail-portrait-slot[data-codex-image-kind="icon"] > .codex-rendered-image-layer {
  opacity: 1 !important;
  -webkit-mask-image: none !important;
  mask-image: none !important;
  -webkit-mask-composite: source-over !important;
  mask-composite: add !important;
  filter: brightness(0) saturate(100%) invert(20%) sepia(30%) saturate(900%) hue-rotate(352deg) brightness(92%) contrast(90%);
}

#codex-content .codex-detail-portrait-slot.codex-image-loaded > .codex-rendered-image-layer[data-codex-image-fit="cover"] {
  left: -1px !important;
  width: calc(100% + 2px) !important;
}

#codex-content .codex-detail-portrait-slot.codex-region-detail-image {
  /* Region thumbnails share the base image treatment; only the stroke is region-specific. */
}

#codex-content .codex-detail-portrait-slot.codex-region-detail-image .codex-region-detail-stroke {
  position: absolute;
  inset: 9px;
  z-index: 3;

  border: 4px solid var(--codex-region-color, transparent) !important;
  border-radius: 12px;
  box-shadow:
    0 0 0 1px rgba(47, 29, 16, 0.22),
    0 0 12px rgba(47, 29, 16, 0.16);
  opacity: 0.94 !important;
  pointer-events: none;
}

.codex-placeholder-npc,
.codex-map-card::before {
  background-size: contain !important;
  background-position: center !important;
  background-repeat: no-repeat !important;
}

.codex-placeholder-settlement,
.codex-placeholder-poi,
.codex-placeholder-region,
.codex-region-tile-image {
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
}

.codex-image-expandable {
  cursor: zoom-in;
}

.codex-image-expandable:focus-visible {
  outline: none;
}

.codex-map-card {
  border-radius: 16px;
}

.codex-map-card::before {
  background:
    radial-gradient(circle at center, rgba(255, 232, 174, 0.18), transparent 62%),
    rgba(94, 55, 22, 0.08) !important;
  background-size: cover, auto !important;
  background-position: center, center !important;
  background-repeat: no-repeat, no-repeat !important;
}

.codex-map-card > .codex-rendered-image-layer {
  -webkit-mask-image:
    linear-gradient(
      to right,
      transparent 0%,
      rgba(0, 0, 0, 0.18) 4%,
      rgba(0, 0, 0, 0.78) 12%,
      black 22%,
      black 78%,
      rgba(0, 0, 0, 0.78) 88%,
      rgba(0, 0, 0, 0.18) 96%,
      transparent 100%
    ),
    linear-gradient(
      to bottom,
      transparent 0%,
      rgba(0, 0, 0, 0.18) 4%,
      rgba(0, 0, 0, 0.78) 12%,
      black 22%,
      black 50%,
      rgba(0, 0, 0, 0.24) 66%,
      transparent 78%,
      transparent 100%
    ) !important;
  -webkit-mask-composite: source-in !important;

  mask-image:
    linear-gradient(
      to right,
      transparent 0%,
      rgba(0, 0, 0, 0.18) 4%,
      rgba(0, 0, 0, 0.78) 12%,
      black 22%,
      black 78%,
      rgba(0, 0, 0, 0.78) 88%,
      rgba(0, 0, 0, 0.18) 96%,
      transparent 100%
    ),
    linear-gradient(
      to bottom,
      transparent 0%,
      rgba(0, 0, 0, 0.18) 4%,
      rgba(0, 0, 0, 0.78) 12%,
      black 22%,
      black 50%,
      rgba(0, 0, 0, 0.24) 66%,
      transparent 78%,
      transparent 100%
    ) !important;
  mask-composite: intersect !important;
}

.codex-map-card-info {
  z-index: 2;
  min-height: 33.333%;
  padding: 12px 14px 14px !important;

  align-items: center;
  justify-content: center;
  text-align: center;

  background: transparent !important;
  border-top: 0 !important;
  border-radius: 0 !important;
  backdrop-filter: none !important;
  -webkit-backdrop-filter: none !important;
  box-shadow: none !important;

  text-shadow:
    0 0 1px rgba(238, 211, 158, 1),
    0 0 2px rgba(238, 211, 158, 1),
    0 0 3px rgba(238, 211, 158, 1),
    0 0 5px rgba(238, 211, 158, 1),
    0 0 7px rgba(238, 211, 158, 1),
    0 0 10px rgba(238, 211, 158, 0.98),
    0 0 14px rgba(238, 211, 158, 0.92),
    0 0 19px rgba(238, 211, 158, 0.82),
    0 0 25px rgba(238, 211, 158, 0.66),
    0 1px 2px rgba(47, 29, 16, 0.52),
    0 2px 4px rgba(47, 29, 16, 0.42) !important;
}

.codex-map-card-title {
  width: 100%;

  font-size: clamp(0.94rem, 1.38vw, 1.22rem) !important;
  font-weight: 800 !important;
  line-height: 1.05 !important;
  letter-spacing: 0.04em !important;

  text-align: center !important;
  white-space: normal !important;
  overflow: visible !important;
  text-overflow: clip !important;

  -webkit-text-stroke: 1.35px rgba(238, 211, 158, 1);
  paint-order: stroke fill;
}

.codex-image-state-label {
  position: absolute;
  left: 50%;
  top: 50%;
  z-index: 4;

  display: none;
  transform: translate(-50%, -50%);

  max-width: 82%;
  padding: 6px 9px;

  border: 1px solid rgba(72, 43, 18, 0.28);
  border-radius: 999px;

  background: rgba(239, 211, 158, 0.76);
  color: rgba(47, 29, 16, 0.86);

  font-family: 'Marcellus SC', Georgia, serif;
  font-size: 0.72rem;
  line-height: 1.05;
  letter-spacing: 0.045em;
  text-align: center;
  text-transform: uppercase;

  box-shadow:
    0 1px 4px rgba(45, 25, 8, 0.12),
    inset 0 1px 0 rgba(255, 242, 210, 0.30);

  pointer-events: none;
}

.codex-image-missing > .codex-image-state-label,
.codex-map-card-missing > .codex-image-state-label {
  display: block;
}

.codex-map-card-missing::before {
  opacity: 0.42;
}

.codex-image-missing {
  outline: none !important;
}
