/* ============================================================
   REIDOS World — overlays.css
   Full-screen overlays: the Signal (first-arrival question),
   the Observatory (map), and the Librarian (dockable chat).
   Variant classes go on .overlay-panel (e.g. "overlay-panel
   signal") or on the overlay itself (e.g. "overlay
   overlay-map") — both spellings are supported.
   ============================================================ */

/* ---------- the veil ---------- */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(13, 11, 20, .92);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  animation: overlay-in .25s ease both;
}
@keyframes overlay-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}

/* ---------- the panel ---------- */
.overlay-panel {
  position: relative;
  width: min(680px, calc(100% - 28px));
  margin: max(7vh, 64px) auto max(10vh, 72px);
  padding: 24px 20px;
  background: var(--panel);
  border: 1px solid var(--line-2);
  border-radius: var(--r);
  box-shadow: var(--shadow);
  animation: panel-rise .35s ease both;
}
@media (min-width: 821px) {
  .overlay-panel { padding: 30px 32px; }
}
@keyframes panel-rise {
  from { opacity: 0; transform: translateY(14px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ---------- close button (top-right, stays put while scrolling) ---------- */
.overlay-close, .overlay .close-btn {
  position: fixed;
  top: 12px;
  right: 12px;
  z-index: 5;
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  border: 1px solid var(--line-2);
  background: var(--panel-2);
  color: var(--muted);
  font-size: 17px;
  line-height: 1;
  cursor: pointer;
  transition: color .15s ease, border-color .15s ease, background-color .15s ease;
}
.overlay-close:hover, .overlay .close-btn:hover {
  color: var(--gold);
  border-color: var(--gold-deep);
  background: var(--panel-3);
}

/* ============================================================
   Variant: the Signal — centered question column
   ============================================================ */
.overlay-panel.signal, .overlay-signal .overlay-panel {
  max-width: 560px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  text-align: center;
}
.overlay-panel.signal h1, .overlay-panel.signal h2,
.overlay-signal .overlay-panel h1, .overlay-signal .overlay-panel h2 {
  font-size: clamp(24px, 5.5vw, 34px);
  margin-bottom: 0;
}
.sig-chips {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
}
.sig-free {
  width: 100%;
  display: flex;
  gap: 10px;
}
.sig-free input { flex: 1 1 auto; min-width: 0; }
.sig-skip {
  font-size: 12px;
  letter-spacing: .08em;
  color: var(--dim);
}
.sig-skip:hover { color: var(--muted); }

/* ============================================================
   Variant: the Observatory — full-bleed canvas + side card
   ============================================================ */
.overlay-map { overflow: hidden; }
.overlay:has(.overlay-panel.map) { overflow: hidden; }

.overlay-panel.map, .overlay-map .overlay-panel {
  width: 100%;
  height: 100%;
  max-width: none;
  margin: 0;
  padding: 0;
  background: transparent;
  border: 0;
  border-radius: 0;
  box-shadow: none;
  animation: none;
  overflow: hidden;
}
.overlay-panel.map canvas, .overlay-map canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  cursor: grab;
  touch-action: none;
}
.overlay-panel.map canvas:active, .overlay-map canvas:active { cursor: grabbing; }

/* Side panel: bottom sheet on mobile, right card on desktop. */
.map-panel {
  position: absolute;
  left: 10px;
  right: 10px;
  bottom: calc(10px + env(safe-area-inset-bottom));
  z-index: 4;
  max-height: 46vh;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 16px;
  background: linear-gradient(160deg, var(--panel-2), var(--panel));
  border: 1px solid var(--line-2);
  border-radius: var(--r);
  box-shadow: var(--shadow);
  animation: panel-rise .3s ease both;
}
.map-panel:empty { display: none; }
@media (min-width: 821px) {
  .map-panel {
    left: auto;
    right: 18px;
    top: 64px;
    bottom: auto;
    width: 350px;
    max-height: calc(100vh - 96px);
  }
}

/* Hover tooltip for stars (positioned by JS). */
.map-tip {
  position: absolute;
  z-index: 3;
  pointer-events: none;
  max-width: 260px;
  padding: 6px 10px;
  border-radius: var(--r-sm);
  border: 1px solid var(--line-2);
  background: rgba(13, 11, 20, .92);
  color: var(--ink);
  font-size: 12px;
  line-height: 1.4;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ============================================================
   Variant: the Librarian — centered chat column
   ============================================================ */
.overlay-panel.librarian, .overlay-librarian .overlay-panel {
  max-width: 640px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* Message stream — also used by the #/librarian route view. */
.lib-msgs {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.lib-msg {
  align-self: flex-start;
  max-width: 88%;
  padding: 11px 15px;
  border-radius: 16px;
  border-bottom-left-radius: 6px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--ink);
  font-size: 14px;
  line-height: 1.55;
}
.lib-msg.user, .lib-msg.me, .lib-msg[data-role="user"] {
  align-self: flex-end;
  border-radius: 16px;
  border-bottom-right-radius: 6px;
  border-color: var(--gold-deep);
  background: rgba(232, 196, 118, .1);
}
.lib-msg a { text-decoration: underline; text-underline-offset: 2px; }
.lib-input {
  display: flex;
  gap: 10px;
  margin-top: 6px;
}
.lib-input input { flex: 1 1 auto; min-width: 0; }
.lib-note {
  font-size: 11.5px;
  letter-spacing: .04em;
  color: var(--dim);
  text-align: center;
}

/* ---------- reduced motion: arrive without ceremony ---------- */
@media (prefers-reduced-motion: reduce) {
  .overlay, .overlay-panel, .map-panel { animation: none; }
}
