:root {
  --mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

html,
body {
  height: 100%;
  margin: 0;
  color: #e6e6e6;
  background: #111;
  font-size: 1em;
  line-height: 1.4;
  font-family: var(--mono);
  /* Stop the page itself from scrolling/bouncing so touch drags reach the
     map controller instead of triggering pull-to-refresh or rubber-banding. */
  overscroll-behavior: none;
  -webkit-text-size-adjust: 100%;
}

::-moz-selection {
  background: #2a4a72;
  color: #fff;
  text-shadow: none;
}

::selection {
  background: #2a4a72;
  color: #fff;
  text-shadow: none;
}

/* Deck.gl appends an absolutely-positioned canvas; the parent needs to be a
   positioned element so the canvas fills it. */
#map {
  position: relative;
  height: 100vh;
  /* dvh tracks the *visible* viewport, so the canvas isn't clipped behind
     the mobile browser's collapsing address bar. vh stays as the fallback. */
  height: 100dvh;
  width: 100%;
  background: #000;
  /* The canvas owns all pan/pinch gestures; without this the browser would
     intercept them for scroll/zoom. */
  touch-action: none;
}

/* On desktop the wrapper is transparent — the two panels keep positioning
   themselves against the viewport exactly as before. */
#panels {
  display: contents;
}

.info-panel {
  position: absolute;
  top: 1rem;
  bottom: 1rem;
  width: 300px;
  max-width: calc(50vw - 2rem);
  background: rgba(20, 20, 20, 0.94);
  border-radius: 8px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.6);
  padding: 0.9rem 1rem;
  overflow-y: auto;
  z-index: 1000;
  font: 13px/1.4 var(--mono);
  color: #e6e6e6;
}

#nation-panel { left: 1rem; }
#territory-panel { right: 1rem; }

.info-panel.empty {
  display: none;
}

#loading {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #111;
  opacity: 1;
  transition: opacity 0.4s ease;
}

#loading.is-hidden {
  opacity: 0;
  pointer-events: none;
}

.loading-spinner {
  width: 150px;
  height: 150px;
  animation: spin 1.6s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

#coords {
  position: absolute;
  bottom: 1rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1000;
  background: rgba(20, 20, 20, 0.94);
  border-radius: 6px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.6);
  padding: 0.4rem 0.7rem;
  font: 12px/1.3 var(--mono);
  color: #e6e6e6;
  pointer-events: none;
  white-space: nowrap;
}

#coords .coord-chunk {
  color: #888;
  margin-left: 0.6rem;
}

@media (prefers-reduced-motion: reduce) {
  .loading-spinner { animation: none; }
}

.info-panel h2 {
  margin: 0 0 0.4rem 0;
  font-size: 16px;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  word-break: break-word;
}

.info-panel h3 {
  margin: 0.9rem 0 0.3rem 0;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #b8b8b8;
  border-bottom: 1px solid #333;
  padding-bottom: 0.2rem;
}

.info-panel dl {
  margin: 0.4rem 0;
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 0.2rem 0.75rem;
}

.info-panel dt { color: #9a9a9a; }
.info-panel dd { margin: 0; word-break: break-word; }

.info-panel .subtitle {
  color: #888;
  font-size: 12px;
  margin: -0.2rem 0 0.4rem 0;
}

.info-panel ul.scroll-list {
  list-style: none;
  padding: 0;
  margin: 0;
  font-size: 12px;
}

.info-panel ul.scroll-list li {
  padding: 2px 0;
  border-bottom: 1px solid #2a2a2a;
}

.info-panel ul.scroll-list li:last-child { border-bottom: 0; }

/* Close button — only surfaced on the mobile bottom sheet (see media query).
   On desktop you dismiss by tapping empty map, so it stays hidden there. */
#panels-close {
  display: none;
  position: absolute;
  top: 0.4rem;
  right: 0.6rem;
  z-index: 1;
  width: 2rem;
  height: 2rem;
  padding: 0;
  border: 0;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.08);
  color: #e6e6e6;
  font: 20px/1 var(--mono);
  cursor: pointer;
}

#panels-close:active { background: rgba(255, 255, 255, 0.18); }

/* --- Mobile / narrow / touch layout -------------------------------------
   The two side-by-side 300px columns are unreadable on a phone, so below
   720px (or on any coarse-pointer device) the panels collapse into a single
   dismissible bottom sheet that scrolls as one. */
@media (max-width: 720px), (pointer: coarse) {
  #panels {
    display: flex;
    flex-direction: column;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1500;
    max-height: 38dvh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    background: rgba(20, 20, 20, 0.97);
    border-radius: 12px 12px 0 0;
    box-shadow: 0 -2px 16px rgba(0, 0, 0, 0.6);
    /* Clear the home-indicator / rounded corners on notched phones. */
    padding-bottom: env(safe-area-inset-bottom);
  }

  /* Sheet collapses entirely when nothing is selected so it never covers
     the map for no reason. */
  #panels:not(.has-content) { display: none; }

  #panels.has-content #panels-close { display: block; }

  .info-panel {
    position: static;
    top: auto;
    bottom: auto;
    width: auto;
    max-width: none;
    border-radius: 0;
    box-shadow: none;
    background: transparent;
    overflow: visible;
    z-index: auto;
  }

  /* Divider between the two stacked panels (only when both are present). */
  #nation-panel:not(.empty) + #territory-panel:not(.empty) {
    border-top: 1px solid #333;
  }

  /* Coords readout sits at the bottom (clear of the home indicator); when
     the sheet is up it rides just above its 45dvh top edge instead. */
  #coords { bottom: calc(1rem + env(safe-area-inset-bottom)); }
  #panels.has-content ~ #coords { bottom: calc(38dvh + 0.5rem); }
}
