:root {
  --text-light: #e0e0e0;
  --text-muted: #a1a1aa;
  --text-secondary: #d1d5db;
  --primary-orange: #ffa500;
  --orange-hover: #ffcc33;
  --orange-tint-10: rgba(255, 165, 0, 0.1);
  --black-80: rgba(0, 0, 0, 0.8);
  --black-50: rgba(0, 0, 0, 0.5);
}

.close-button {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 2rem;
  line-height: 1;
  padding: 0;
  margin: 0;
  cursor: pointer;
  transition: color 0.3s ease;
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 50;
}

.close-button:hover {
  color: #ffffff;
}

.filter-drawer-container {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 30;
}

.filter-toggle-wrapper {
  position: absolute;
  top: 10px;
  right: 10px;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
  max-width: calc(100% - 20px);
}

.filter-toggle-button {
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(26, 26, 26, 0.9);
  color: var(--text-light);
  font-size: 1rem;
  font-weight: 600;
  padding: 10px 20px;
  border: none;
  border-radius: 8px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
  cursor: pointer;
  transition: background 0.2s ease-in-out;
}

.filter-toggle-button:hover {
  background: rgba(26, 26, 26, 1);
}

.filter-toggle-button .chevron {
  margin-left: 8px;
  font-size: 0.875rem;
  transition: transform 0.3s ease;
}

.filter-toggle-button.open .chevron {
  transform: rotate(180deg);
}

.active-filters {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  gap: 8px;
  width: 100%;
}

.filter-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 9999px;
  background: rgba(26, 26, 26, 0.75);
  border: 1px solid rgba(255, 255, 255, 0.25);
  color: var(--text-light);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.2s ease, transform 0.2s ease, border-color 0.2s ease;
}

.filter-pill:hover {
  background: rgba(26, 26, 26, 0.95);
  border-color: rgba(255, 165, 0, 0.6);
  transform: translateY(-1px);
}

.filter-pill-label {
  white-space: nowrap;
}

.filter-pill-close {
  font-size: 0.875rem;
  line-height: 1;
}

@media (max-width: 640px) {
  .filter-toggle-wrapper {
    right: 0;
    left: 0;
    align-items: stretch;
    padding: 0 10px;
  }

  .active-filters {
    justify-content: flex-start;
  }

  .filter-toggle-button {
    width: 100%;
  }
}

.filter-drawer {
  background: rgba(26, 26, 26, 0.95);
  padding: 1rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.2);
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.5);
  transform: translateY(-100%);
  opacity: 0;
  visibility: hidden;
  transition: transform 0.3s ease-in-out, opacity 0.3s ease-in-out, visibility 0.3s ease-in-out;
  position: relative;
  max-height: 80vh;
  overflow-y: auto;
  overflow-x: hidden;
}

.filter-drawer .close-button {
  font-size: 2.5rem;
  top: 8px;
  right: 14px;
}

.filter-drawer.open {
  transform: translateY(0);
  opacity: 1;
  visibility: visible;
}

.filter-tag {
  display: inline-block;
  background: rgba(26, 26, 26, 0.8);
  color: var(--text-light);
  font-size: 1rem;
  font-weight: 500;
  padding: 8px 16px;
  margin: 0;
  border-radius: 9999px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  text-shadow: 0 0 4px rgba(0, 0, 0, 0.5);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
  transition: all 0.2s ease-in-out;
  cursor: pointer;
  z-index: 10;
  flex-shrink: 0;
  white-space: nowrap;
}

.filter-tag.year-tag {
  font-weight: 600;
  background: rgba(26, 26, 26, 0.85);
  padding: 6px 12px;
}

.filter-tag:hover {
  background: rgba(26, 26, 26, 0.95);
  border-color: rgba(255, 255, 255, 0.4);
  transform: translateY(-2px);
}

.filter-tag.active {
  background: var(--primary-orange);
  border-color: var(--primary-orange);
  box-shadow: 0 0 10px rgba(255, 165, 0, 0.5);
  color: #ffffff;
}

.filter-tag.active:hover {
  background: var(--orange-hover);
  transform: translateY(-2px);
}

.year-filter-container,
.tag-filter-container {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  padding: 0.5rem;
  border-radius: 1rem;
  gap: 8px;
  justify-content: flex-start;
  align-content: flex-start;
  max-height: calc(3 * (2.5rem + 8px) + 1rem); /* Approximately 3 rows: button height (~2.5rem) + gap (8px) + container padding (1rem) */
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 165, 0, 0.3) transparent;
  -webkit-overflow-scrolling: touch;
}

.year-filter-container::-webkit-scrollbar,
.tag-filter-container::-webkit-scrollbar {
  width: 6px;
}

.year-filter-container::-webkit-scrollbar-track,
.tag-filter-container::-webkit-scrollbar-track {
  background: transparent;
}

.year-filter-container::-webkit-scrollbar-thumb,
.tag-filter-container::-webkit-scrollbar-thumb {
  background: rgba(255, 165, 0, 0.3);
  border-radius: 3px;
}

.year-filter-container::-webkit-scrollbar-thumb:hover,
.tag-filter-container::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 165, 0, 0.5);
}

.characters-container {
  padding: 0.5rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  margin-bottom: 1rem;
}

.characters-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.75rem;
}

.characters-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-light);
  margin: 0;
}

.character-comic-button {
  width: 80px;
  height: 80px;
  min-width: 80px;
  background: rgba(26, 26, 26, 0.8);
  color: var(--text-light);
  font-size: 1.5rem;
  font-weight: 500;
  padding: 0;
  border: 2px solid rgba(255, 255, 255, 0.2);
  border-radius: 50%;
  cursor: pointer;
  transition: all 0.2s ease-in-out;
  flex-shrink: 0;
  align-self: flex-start;
  margin-top: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.character-comic-button:hover {
  background: var(--primary-orange);
  border-color: var(--primary-orange);
  color: #ffffff;
}

.characters-avatars {
  display: flex;
  flex-direction: row;
  align-items: flex-start;
  gap: 12px;
  overflow-x: auto;
  overflow-y: hidden;
  padding: 8px 0;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 165, 0, 0.3) transparent;
  -webkit-overflow-scrolling: touch;
}

.characters-avatars::-webkit-scrollbar {
  height: 6px;
}

.characters-avatars::-webkit-scrollbar-track {
  background: transparent;
}

.characters-avatars::-webkit-scrollbar-thumb {
  background: rgba(255, 165, 0, 0.3);
  border-radius: 3px;
}

.characters-avatars::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 165, 0, 0.5);
}

.character-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
  min-width: 90px;
}

.character-avatar {
  width: 80px;
  height: 80px;
  min-width: 80px;
  flex-shrink: 0;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.2);
  background: rgba(26, 26, 26, 0.8);
  cursor: pointer;
  transition: all 0.2s ease-in-out;
  padding: 0;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

.character-avatar:hover {
  border-color: var(--primary-orange);
  transform: scale(1.1);
  box-shadow: 0 0 10px rgba(255, 165, 0, 0.5);
}

.character-avatar-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 50%;
}

.character-avatar-wrapper {
  position: relative;
  width: 100%;
  height: 100%;
}

.character-avatar-placeholder {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-light);
  font-size: 1.25rem;
  font-weight: 600;
  background: var(--primary-orange);
  border-radius: 50%;
  z-index: 1;
}

.character-name {
  font-size: 0.875rem;
  color: var(--text-light);
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 90px;
  font-weight: 700;
}

.character-nickname {
  font-size: 0.7rem;
  color: var(--text-secondary);
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 90px;
}

#globeViz {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 100vh;
  height: 100dvh; /* dynamic viewport: corrects after orientation/keyboard */
  width: 100%;
  z-index: 1;
}

.popover {
  z-index: 40;
}

.popover-static {
  position: fixed;
  top: 45%;
  right: 10px;
  transform: translateY(-50%);
}

.popover-content {
  background: rgba(26, 26, 26, 0.95);
  border-radius: 8px;
  padding: 15px;
  width: 300px;
  box-shadow: 0 4px 10px var(--black-50);
  position: relative;
  border: 1px solid var(--orange-tint-10);
}

.popover-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
  position: relative;
}

.popover-title {
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--text-light);
  word-wrap: break-word;
  overflow-wrap: break-word;
  padding-right: 30px;
}

.popover-body {
  font-size: 0.875rem;
  color: var(--text-secondary);
  margin-bottom: 10px;
}

.popover-footer {
  text-align: right;
}

.popover-enhanced {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 10px;
}

.popover-image-container {
  margin-bottom: 10px;
}

.popover-image-enhanced {
  width: 150px;
  height: 150px;
  border-radius: 50%;
  object-fit: cover;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
}

.popover-title-enhanced {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text-light);
  text-align: center;
  margin: 8px 0;
  word-wrap: break-word;
  overflow-wrap: break-word;
  width: 100%;
  padding-right: 30px;
}

.popover-body-enhanced {
  font-size: 0.85rem;
  color: var(--text-secondary);
  text-align: center;
  margin-bottom: 10px;
}

.popover-footer-enhanced {
  text-align: center;
}

.popover-link {
  display: inline-block;
  background: linear-gradient(90deg, var(--primary-orange), #ff8c00);
  color: #ffffff;
  font-size: 1rem;
  font-weight: 700;
  padding: 8px 16px;
  border-radius: 9999px;
  border: 1px solid var(--primary-orange);
  text-decoration: none;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
  transition: all 0.3s ease-in-out;
  cursor: pointer;
}

.popover-link:hover {
  background: linear-gradient(90deg, var(--orange-hover), #ffb84d);
  border-color: var(--orange-hover);
  box-shadow: 0 4px 10px rgba(255, 165, 0, 0.4);
  transform: scale(1.05);
  text-decoration: none;
}

.popover-link:focus {
  outline: none;
  box-shadow: 0 0 0 3px rgba(255, 165, 0, 0.3);
}

.popover-link:active {
  transform: scale(0.95);
}

#globeViz .scene-container .site-label {
  display: block !important;
  background: transparent !important;
  color: var(--primary-orange) !important;
  font-family: 'Inter', sans-serif !important;
  font-size: 12px !important;
  font-weight: bold !important;
  padding: 0 !important;
  border-radius: 0 !important;
  text-shadow: 0 0 6px var(--black-80), 0 0 6px var(--black-80) !important;
  white-space: nowrap !important;
  z-index: 5 !important;
  transition: none !important;
  transform: translate(-50%, 0) !important;
  text-align: center !important;
  opacity: 1 !important;
}

.hex-highlight {
  outline: 2px solid var(--primary-orange);
  outline-offset: 2px;
  box-shadow: 0 0 8px var(--primary-orange);
}

@media (max-width: 640px) {
  #globeViz {
    height: 100vh;
    height: 100dvh;
  }
  .filter-tag {
    font-size: 0.875rem;
    padding: 6px 12px;
    margin: 4px;
  }
  .filter-tag.year-tag {
    font-size: 0.875rem;
    padding: 5px 10px;
  }
  .year-filter-container,
  .tag-filter-container {
    padding: 0.25rem;
    gap: 6px;
  }
  .characters-container {
    padding: 0.25rem;
    margin-top: 0.5rem;
  }
  .characters-title {
    font-size: 0.875rem;
  }
  .character-comic-button {
    width: 70px;
    height: 70px;
    min-width: 70px;
    font-size: 1.25rem;
    padding: 0;
  }
  .character-item {
    min-width: 80px;
  }
  .character-avatar {
    width: 70px;
    height: 70px;
    min-width: 70px;
  }
  .character-name {
    font-size: 0.75rem;
    max-width: 80px;
  }
  .character-avatar-placeholder {
    font-size: 1rem;
  }
  .filter-drawer {
    padding: 0.5rem;
  }

  .close-button {
    top: -4px;
    right: 0px;
    font-size: 2.25rem;
    padding: 8px;
    color: var(--text-light);
    text-shadow: 0 0 4px var(--black-80);
    z-index: 51;
  }

  .popover-static {
    right: 50%;
    transform: translate(50%, -50%);
    width: 90%;
    max-width: 300px;
  }
}

/* Orientation: ensure layout responds when rotating device (e.g. portrait ↔ landscape) */
@media (orientation: portrait) {
  #globeViz {
    height: 100vh;
    height: 100dvh;
  }
}

@media (orientation: landscape) and (max-width: 640px) {
  /* Narrow landscape (e.g. phone rotated): keep popover usable */
  .popover-static {
    right: 10px;
    transform: translateY(-50%);
    width: 90%;
    max-width: 280px;
  }
  .popover-content {
    width: 100%;
  }
}

@media (max-width: 640px) {
  /* .popover-static for portrait is in the block above; landscape narrow uses (orientation: landscape) block */
  .popover-content {
    width: 100%;
    padding: 10px;
  }
  .popover-title {
    font-size: 1rem;
  }
  .popover-body {
    font-size: 0.75rem;
  }
  .popover-link {
    font-size: 0.875rem;
    padding: 6px 12px;
  }
  .popover-image-enhanced {
    width: 120px;
    height: 120px;
  }
  .popover-title-enhanced {
    font-size: 1rem;
  }
  .popover-body-enhanced {
    font-size: 0.75rem;
  }
}