/* Totemia map viewer chrome — masthead bar + layout. Served from _gis/ on every
 * viewer slot; injected by minecraftWorldMapViewerRoute.ts. */

:root {
  --map-gold: #c4981f;
  --map-gold-soft: #dcc48a;
  --map-green: #123c32;
  --map-ink: #14171a;
  --map-muted: #5b636c;
  --map-line: #e3e6ea;
  --map-font: Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --map-head-h: 52px;
}

html.map-viewer-root,
html.map-viewer-root body {
  width: 100%;
  height: 100%;
  margin: 0;
  /* A map app never page-scrolls: lock the document so a touch overscroll can
   * never rubber-band the page and expose the body backdrop (the "screen turns
   * yellow" bleed past the gold masthead). The map handles its own gestures. */
  overflow: hidden;
  overscroll-behavior: none;
  /* Neutral backdrop behind every layer so any pixel briefly revealed during an
   * elastic overscroll reads as dark chrome, not the gold accent. */
  background: #0f1413;
}

body.map-viewer-page {
  position: fixed;
  top: 0;
  left: 0;
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100vh;
  height: 100dvh;
  min-height: 0;
  font-family: var(--map-font);
  background: #0f1413;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
  box-sizing: border-box;
}

body.map-viewer-page #map {
  flex: 1 1 auto;
  width: 100%;
  min-height: 0;
  height: auto !important;
  overscroll-behavior: contain;
  touch-action: none;
  background: #0f1413;
}

/* OpenLayers viewport: reduce iOS callout on long-press; OL handles pan/pinch. */
html.map-viewer-root #map .ol-viewport {
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

body.map-viewer-embed #map {
  height: 100% !important;
}

.map-viewer-head {
  position: relative;
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 14px;
  min-height: var(--map-head-h);
  padding: max(0px, env(safe-area-inset-top, 0px)) max(16px, env(safe-area-inset-right, 0px))
    max(0px, env(safe-area-inset-bottom, 0px)) max(16px, env(safe-area-inset-left, 0px));
  background: #111611;
  border-bottom: 3px solid var(--map-gold);
  color: #ffffff;
  /* Sit above every in-map overlay (legend 5, editor 12, gamepad reticle 25) so
   * the masthead and its account dropdown never collide with map controls. */
  z-index: 40;
}

.map-viewer-crest {
  display: grid;
  place-items: center;
  flex: 0 0 34px;
  width: 34px;
  height: 34px;
}

.map-viewer-crest img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

.map-viewer-head-copy {
  min-width: 0;
  flex: 1 1 auto;
}

.map-viewer-head-title {
  margin: 0;
  color: #ffffff;
  font-size: 15px;
  font-weight: 800;
  line-height: 1.15;
  letter-spacing: -0.02em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.map-viewer-head-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
}

/* Portal masthead account pattern (portalShell.css), scoped to map chrome. */
.map-viewer-account {
  flex-shrink: 0;
  margin-left: 4px;
}

.map-viewer-head .masthead-profile {
  position: relative;
}

.map-viewer-head .masthead-profile-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(255, 255, 255, 0.06);
  color: rgba(255, 255, 255, 0.82);
  border-radius: 8px;
  padding: 5px 8px 5px 5px;
  box-shadow: none;
  text-decoration: none;
  cursor: pointer;
  font-family: inherit;
  font-size: 12px;
  font-weight: 700;
  max-width: min(220px, 42vw);
}

.map-viewer-head .masthead-profile-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(220, 196, 138, 0.45);
}

.map-viewer-head .masthead-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  object-fit: cover;
  background: rgba(251, 246, 230, 0.95);
  color: #9a780f;
  display: grid;
  place-items: center;
  font-size: 11px;
  font-weight: 800;
  flex-shrink: 0;
}

.map-viewer-head .masthead-profile-label {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.map-viewer-head .masthead-caret {
  color: rgba(224, 205, 132, 0.9);
  font-size: 10px;
  flex-shrink: 0;
}

.map-viewer-head .masthead-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  min-width: 184px;
  max-width: min(260px, calc(100vw - 16px));
  max-height: min(70vh, calc(100dvh - var(--map-head-h) - 20px));
  /* Only ever scroll vertically; without an explicit overflow-x, setting
   * overflow-y alone makes overflow-x compute to `auto` and shows a stray
   * horizontal scrollbar under the short menu. */
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  border: 1px solid var(--map-line);
  border-radius: 6px;
  background: #ffffff;
  box-shadow: 0 12px 28px rgba(20, 23, 20, 0.2);
  padding: 6px;
  z-index: 60;
}

.map-viewer-head .masthead-menu[hidden] {
  display: none !important;
}

.map-viewer-head .masthead-menu a,
.map-viewer-head .masthead-menu button {
  display: block;
  width: 100%;
  border: 0;
  background: transparent;
  color: var(--map-ink);
  box-shadow: none;
  text-align: left;
  padding: 9px 10px;
  border-radius: 4px;
  font-size: 12px;
  text-decoration: none;
  cursor: pointer;
  font-family: inherit;
}

.map-viewer-head .masthead-menu a:hover,
.map-viewer-head .masthead-menu button:hover {
  background: #fbf6e6;
  color: #123c32;
}

.map-viewer-head .masthead-menu hr {
  border: 0;
  height: 1px;
  margin: 6px 0;
  background: var(--map-line);
}

.map-viewer-head-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 32px;
  padding: 0 12px;
  border: 1px solid rgba(220, 196, 138, 0.45);
  border-radius: 999px;
  color: #ffffff;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  text-decoration: none;
}

.map-viewer-head-link:hover {
  background: rgba(196, 152, 31, 0.18);
  border-color: var(--map-gold);
}

.map-viewer-head-link.primary {
  background: var(--map-gold);
  border-color: var(--map-gold);
  color: #111611;
}

.map-viewer-head-link.primary:hover {
  filter: brightness(1.05);
}

body.map-viewer-embed .map-viewer-head {
  display: none;
}

@media (pointer: coarse) {
  .map-viewer-head-link {
    min-height: 44px;
    padding: 0 14px;
  }

  .map-viewer-head .masthead-profile-btn {
    min-height: 44px;
    padding: 6px 10px 6px 6px;
  }

  .ol-ctx-menu-container.map-viewer-ctx-menu li {
    padding-top: 12px;
    padding-bottom: 12px;
  }
}

@media (max-width: 560px) {
  .map-viewer-head {
    gap: 10px;
    padding: max(0px, env(safe-area-inset-top, 0px)) max(12px, env(safe-area-inset-right, 0px))
      max(0px, env(safe-area-inset-bottom, 0px)) max(12px, env(safe-area-inset-left, 0px));
  }

  .map-viewer-head-title {
    font-size: 14px;
  }

  .map-viewer-head-link {
    padding: 0 10px;
    font-size: 10px;
  }

  /* Avatar-only account chip so the masthead never overflows (and clips) on a
   * phone; the name still shows inside the dropdown's Profile link. */
  .map-viewer-head .masthead-profile-label,
  .map-viewer-head .masthead-caret {
    display: none;
  }

  .map-viewer-head .masthead-profile-btn {
    padding: 4px;
    gap: 0;
  }

  /* Pin the dropdown to the viewport so no ancestor (or the locked, overflow-
   * hidden body) can clip it — the reported "settings overlap". */
  .map-viewer-head .masthead-menu {
    position: fixed;
    top: calc(var(--map-head-h) + max(6px, env(safe-area-inset-top, 0px)));
    right: max(8px, env(safe-area-inset-right, 0px));
    left: auto;
  }
}

@media (max-width: 470px) {
  /* Keep the primary "Share" action; the full viewer index is one tap away from
   * the portal, so drop the secondary link rather than let the bar overflow. */
  .map-viewer-head-link:not(.primary) {
    display: none;
  }
}

/* ── Map overlay text (axis ticks, scale, etc.) — Inter + legible contrast ─ */

html.map-viewer-root #map .ol-overlaycontainer-stopevent {
  font-family: var(--map-font);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

html.map-viewer-root #map .ol-scale-line-inner {
  font-family: var(--map-font);
  font-weight: 800;
  font-size: 12px;
  font-variant-numeric: tabular-nums lining-nums;
  letter-spacing: 0.02em;
  color: #0f1614;
  text-shadow:
    0 0 3px rgba(255, 253, 245, 0.95),
    0 0 8px rgba(255, 253, 245, 0.75),
    1px 1px 0 rgba(255, 253, 245, 0.85),
    -1px -1px 0 rgba(255, 253, 245, 0.85);
}

/* uNmINeD / OL graticule or tick labels (when present) */
html.map-viewer-root #map .ol-graticule,
html.map-viewer-root #map .ol-graticule * {
  font-family: var(--map-font) !important;
  font-weight: 800 !important;
  font-size: 12px !important;
  font-variant-numeric: tabular-nums lining-nums !important;
  letter-spacing: 0.02em !important;
  color: #0f1614 !important;
  text-shadow:
    0 0 3px rgba(255, 253, 245, 0.95),
    0 0 8px rgba(255, 253, 245, 0.75),
    1px 1px 0 rgba(255, 253, 245, 0.85),
    -1px -1px 0 rgba(255, 253, 245, 0.85) !important;
}

/* ── Right-click map menu (ol-contextmenu) ───────────────────────────── */

.ol-ctx-menu-container.map-viewer-ctx-menu {
  min-width: 252px;
  width: max-content !important;
  max-width: min(340px, 92vw);
  padding: 8px;
  border: 2px solid var(--map-line);
  border-top: 3px solid var(--map-gold);
  border-radius: 0;
  background: #ffffff;
  color: var(--map-ink);
  font-family: var(--map-font);
  font-size: 14px;
  font-weight: 600;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  box-shadow: 0 8px 22px rgba(20, 23, 20, 0.16);
}

.ol-ctx-menu-container.map-viewer-ctx-menu ul {
  display: grid;
  gap: 2px;
}

.ol-ctx-menu-container.map-viewer-ctx-menu li {
  line-height: 1.35;
  padding: 9px 12px;
  border-radius: 0;
  white-space: normal;
  overflow-wrap: anywhere;
  font-variant-numeric: tabular-nums lining-nums;
}

.ol-ctx-menu-container.map-viewer-ctx-menu li:not(.ol-ctx-menu-separator):hover {
  cursor: pointer;
  background: rgba(196, 152, 31, 0.12);
  color: var(--map-green);
}

.ol-ctx-menu-container.map-viewer-ctx-menu li.ol-ctx-menu-separator {
  padding: 0;
  margin: 2px 0;
}

.ol-ctx-menu-container.map-viewer-ctx-menu li.ol-ctx-menu-separator hr {
  height: 1px;
  margin: 0;
  border: 0;
  background: var(--map-line);
  background-image: none;
}

.ol-ctx-menu-container.map-viewer-ctx-menu li.map-ctx-tp {
  font-weight: 800;
  color: var(--map-green);
  font-variant-numeric: tabular-nums lining-nums;
  letter-spacing: 0.01em;
}

.ol-ctx-menu-container.map-viewer-ctx-menu li.map-ctx-marker {
  font-weight: 700;
}

.ol-ctx-menu-container.map-viewer-ctx-menu li.map-ctx-toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  color: var(--map-ink);
  padding-left: 12px !important;
}

.ol-ctx-menu-container.map-viewer-ctx-menu li.map-ctx-toggle::before {
  content: "";
  flex: 0 0 16px;
  width: 16px;
  height: 16px;
  margin: 0 !important;
  border: 2px solid var(--map-line);
  border-radius: 0;
  background: #ffffff;
  display: inline-block;
}

.ol-ctx-menu-container.map-viewer-ctx-menu li.map-ctx-toggle.is-checked::before {
  border-color: var(--map-gold);
  background-color: var(--map-gold);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'%3E%3Cpath fill='none' stroke='%23111611' stroke-width='2' stroke-linecap='round' stroke-linejoin='round' d='M2.5 6.2 5 8.7 9.5 3.8'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: center;
  background-size: 11px 11px;
}

/* ── Gamepad aim reticle (gis-gamepad.js; coordinates = viewport center) ─ */

html.map-viewer-gamepad-active #map .ol-viewport {
  cursor: none;
}

.totemia-gamepad-reticle {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 32px;
  height: 32px;
  margin: -16px 0 0 -16px;
  pointer-events: none;
  z-index: 25;
  filter: drop-shadow(0 0 2px rgba(255, 253, 245, 0.95));
}

.totemia-gamepad-reticle img {
  display: block;
  width: 32px;
  height: 32px;
}

.totemia-gamepad-reticle[hidden] {
  display: none !important;
}

@media (prefers-reduced-motion: reduce) {
  .totemia-gamepad-reticle {
    filter: none;
  }
}

/* ── Coordinate readout + map toasts ───────────────────────────────── */

/* Square readout, solid frame (no pill / thin hairline look). */
div.ol-mouse-position {
  background: #ffffff;
  border: 2px solid var(--map-line);
  border-top: 3px solid var(--map-gold);
  border-radius: 0;
  padding: 8px 12px;
  box-shadow: 0 2px 8px rgba(20, 23, 20, 0.1);
  color: var(--map-green);
  font-family: var(--map-font);
  font-size: 13px;
  font-weight: 800;
  font-variant-numeric: tabular-nums lining-nums;
  letter-spacing: 0.03em;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.6);
}

body.map-viewer-page div.ol-mouse-position,
body.map-viewer-embed div.ol-mouse-position {
  border-radius: 0 !important;
}

.toastify.map-viewer-toast {
  color: var(--map-ink) !important;
  background: #ffffff !important;
  border: 1px solid var(--map-line) !important;
  border-top: 3px solid var(--map-gold) !important;
  border-radius: 10px !important;
  box-shadow: 0 10px 24px rgba(20, 23, 20, 0.18) !important;
  font-family: var(--map-font) !important;
  font-size: 13px !important;
  font-weight: 700 !important;
  padding: 12px 16px !important;
}
