/* Single welcome card for the current visitor. It fades in slowly, stays for
   three seconds, then fades out slowly. Fixed positioning so it never shifts
   the page or competes with the timeline for space. */
.geo-stack {
  position: fixed;
  top: calc(var(--geo-top, 90px) + env(safe-area-inset-top, 0px));
  right: clamp(10px, 1.6vw, 26px);
  z-index: 60;
  width: auto;
  max-width: min(350px, calc(100vw - 32px));
  opacity: 0;
  transform: translateY(8px) scale(0.985);
  pointer-events: none;
  /* Slow, soft entrance (~1.1s); the JS waits for it before holding. */
  transition: opacity 1.1s ease, transform 1.1s cubic-bezier(0.22, 0.61, 0.36, 1);
  will-change: opacity, transform;
  backface-visibility: hidden;
}

.geo-stack.is-visible {
  opacity: 1;
  transform: none;
  pointer-events: auto;
}

/* Slow fade-out after the hold. */
.geo-stack.is-leaving {
  opacity: 0;
  transform: translateY(-8px) scale(0.99);
  pointer-events: none;
  transition: opacity 1s ease, transform 1s ease;
}

.geo-welcome {
  display: flex;
  align-items: center;
  gap: 9px;
  max-width: 100%;
  padding: 9px 10px 9px 11px;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: var(--card);
  box-shadow: 0 8px 22px rgba(35, 29, 18, 0.12);
  color: var(--ink);
}

html[data-theme="dark"] .geo-welcome {
  box-shadow: 0 10px 26px rgba(0, 0, 0, 0.4);
}

.geo-welcome-emoji {
  flex: 0 0 auto;
  font-size: 17px;
  line-height: 1;
}

.geo-welcome-text {
  min-width: 0;
  color: var(--ink-soft);
  font-size: 12px;
  line-height: 1.45;
}

.geo-welcome-flag {
  margin-right: 2px;
}

.geo-welcome-close {
  flex: 0 0 auto;
  display: inline-grid;
  place-items: center;
  width: 24px;
  height: 24px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--faint);
  font-size: 17px;
  line-height: 1;
  cursor: pointer;
}

.geo-welcome-close:hover {
  color: var(--ink);
  background: var(--paper-soft);
}

.geo-welcome-close:focus-visible {
  outline: 2px solid var(--red);
  outline-offset: 2px;
}

/* Phones: upper-middle, at about the detail-page title position. The JS
   sets --geo-top from the sticky header bottom; this is an overlay, so it
   does not shift the article. */
@media (max-width: 720px) {
  .geo-stack {
    top: calc(var(--geo-top, 116px) + 32px);
    bottom: auto;
    left: 50%;
    right: auto;
    max-width: min(340px, calc(100vw - 32px));
    transform: translateX(-50%) translateY(8px) scale(0.985);
  }
  .geo-stack.is-visible { transform: translateX(-50%); }
  .geo-stack.is-leaving {
    transform: translateX(-50%) translateY(-8px) scale(0.99);
  }
  .geo-welcome-text { font-size: 11.5px; }
}

@media (max-width: 720px) and (prefers-reduced-motion: reduce) {
  .geo-stack { transform: translateX(-50%); }
}

@media (prefers-reduced-motion: reduce) {
  .geo-stack {
    transition: none;
    transform: none;
  }
  .geo-stack.is-leaving {
    transition: none;
  }
}

/* More robust horizontal centering than left:50%+translateX (which can be
   lost with cached/stale transforms or reduced-motion overrides). */
@media (max-width: 720px) {
  .geo-stack {
    left: 0;
    right: 0;
    margin-left: auto;
    margin-right: auto;
    width: fit-content;
    transform: translateY(8px) scale(0.985);
  }
  .geo-stack.is-visible { transform: none; }
  .geo-stack.is-leaving { transform: translateY(-8px) scale(0.99); }
}

@media (max-width: 720px) and (prefers-reduced-motion: reduce) {
  .geo-stack { transform: none; }
  .geo-stack.is-leaving { transform: none; }
}

/* Final mobile placement: upper area (near the detail headline), still
   right-aligned, not horizontally centered. */
@media (max-width: 720px) {
  .geo-stack {
    left: auto;
    right: 12px;
    margin-left: 0;
    margin-right: 0;
    width: auto;
    max-width: min(340px, calc(100vw - 24px));
    transform: translateY(8px) scale(0.985);
  }
  .geo-stack.is-visible { transform: none; }
  .geo-stack.is-leaving { transform: translateY(-8px) scale(0.99); }
}

@media (max-width: 720px) and (prefers-reduced-motion: reduce) {
  .geo-stack { transform: none; }
  .geo-stack.is-leaving { transform: none; }
}
