:root {
  color-scheme: dark;
  --bg: #0b0e14;
  --bg-2: #111722;
  --surface: rgba(20, 27, 39, 0.9);
  --surface-hover: rgba(28, 37, 54, 0.96);
  --border: rgba(255, 255, 255, 0.16);
  --text: #eef2f7;
  --muted: #a7b6ca;
  --accent: #34d399;
  --focus-ring: #93c5fd;
}

html,
body {
  margin: 0;
  width: 100%;
  height: 100vh;
  height: 100dvh;
  overflow: hidden !important;
  overflow-x: clip !important;
  background-color: var(--bg) !important;
  color: var(--text);
  color-scheme: dark;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

#map {
  width: 100%;
  height: 100%;
  background-color: var(--bg) !important;
}

#map:focus {
  outline: none;
}

/* Fix +194px horizontal overflow from collapsed #sidebar and #pin */
#sidebar:not(.show) {
  width: 0 !important;
  padding-left: 0 !important;
  padding-right: 0 !important;
  border-left: none !important;
}

#sidebar:not(.show) fieldset {
  display: none !important;
}

#sidebar:not(.show) #pin {
  position: absolute !important;
  top: 8px !important;
  right: 8px !important;
  margin: 0 !important;
}

/* Dark theme for Squaremap sidebar & pin */
#sidebar,
#sidebar #pin {
  background: var(--surface) !important;
  color: var(--text) !important;
  border: 1px solid var(--border) !important;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

#sidebar fieldset {
  border-color: var(--border) !important;
}

#sidebar legend,
#sidebar span,
#sidebar label,
#sidebar a {
  color: var(--text) !important;
}


/* Dark theme for remaining Leaflet/Squaremap controls (coordinates, link, attribution, layers) */
.leaflet-control-layers,
.leaflet-control-layers-expanded,
div.leaflet-control-layers.coordinates,
div.leaflet-control-layers.link,
.leaflet-container .leaflet-control-attribution,
.leaflet-control-scale-line {
  background: var(--surface) !important;
  color: var(--text) !important;
  border: 1px solid var(--border) !important;
  border-radius: 10px !important;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35) !important;
  text-shadow: none !important;
}

div.leaflet-control-layers.coordinates {
  display: inline-flex !important;
  align-items: center;
  height: auto !important;
  min-height: 36px;
  padding: 6px 12px !important;
  font-size: 0.82rem;
  font-variant-numeric: tabular-nums;
  line-height: 1.3;
}

div.leaflet-control-layers.link {
  display: inline-flex !important;
  align-items: center;
  justify-content: center;
  width: 44px !important;
  height: 44px !important;
  min-width: 44px !important;
  min-height: 44px !important;
  padding: 0 !important;
}

div.leaflet-control-layers.link a,
div.leaflet-control-layers.link img {
  display: block;
}

div.leaflet-control-layers.link img {
  filter: invert(1) brightness(1.15);
}

.leaflet-container .leaflet-control-attribution a {
  color: var(--accent) !important;
}

.leaflet-control-layers-separator {
  border-top-color: var(--border) !important;
}

/* Enforce >= 44x44px touch targets on Squaremap & Leaflet controls */
#sidebar #pin {
  min-width: 44px !important;
  min-height: 44px !important;
  border-radius: 10px !important;
  display: inline-flex !important;
  align-items: center;
  justify-content: center;
  transition: background-color 0.15s ease, border-color 0.15s ease;
}

#sidebar fieldset div,
#minecraft_overworld,
#minecraft_the_nether,
#minecraft_the_end {
  min-height: 44px !important;
  display: flex !important;
  align-items: center !important;
  padding: 4px 8px !important;
  box-sizing: border-box;
}

.leaflet-touch .leaflet-bar a,
.leaflet-control-zoom a,
.leaflet-control-layers-toggle {
  width: 44px !important;
  height: 44px !important;
  min-width: 44px !important;
  min-height: 44px !important;
  line-height: 44px !important;
  background-color: var(--surface) !important;
  color: var(--text) !important;
  border-color: var(--border) !important;
}

.leaflet-bar {
  border: 1px solid var(--border) !important;
  border-radius: 10px !important;
  overflow: hidden;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35) !important;
}

/* Skip Link */
.skip-link {
  box-sizing: border-box;
  position: fixed;
  top: calc(12px + env(safe-area-inset-top));
  left: calc(12px + env(safe-area-inset-left));
  z-index: 10001;
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 10px 16px;
  border-radius: 10px;
  background: #111722;
  color: #eef2f7;
  border: 2px solid var(--focus-ring);
  font-size: 0.9rem;
  font-weight: 600;
  text-decoration: none;
  transform: translateY(-240%);
  transition: transform 0.15s ease;
}

.skip-link:focus-visible {
  transform: translateY(0);
}

/* Unified Top-Left Back Navigation Pills + Leaflet Zoom Offset */
.innil-map-nav {
  position: fixed;
  top: calc(14px + env(safe-area-inset-top));
  left: calc(18px + env(safe-area-inset-left));
  z-index: 1000;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.leaflet-top.leaflet-left {
  top: calc(68px + env(safe-area-inset-top)) !important;
  left: calc(8px + env(safe-area-inset-left)) !important;
}

.innil-map-pill {
  box-sizing: border-box;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 44px;
  min-width: 44px;
  padding: 0 16px;
  border-radius: 999px;
  background: rgba(20, 27, 39, 0.85);
  border: 1px solid rgba(255, 255, 255, 0.14);
  color: var(--text);
  font-size: 0.86rem;
  font-weight: 600;
  line-height: 1;
  text-decoration: none;
  white-space: nowrap;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.36);
  transition: background-color 0.15s ease, border-color 0.15s ease, transform 0.15s ease;
}

.innil-map-pill-muted {
  color: var(--muted);
}

.innil-map-pill:active {
  transform: scale(0.98);
}

/* Focus Outlines */
a:focus-visible,
button:focus-visible,
input:focus-visible,
[tabindex]:not([tabindex="-1"]):focus-visible {
  outline: 3px solid var(--focus-ring) !important;
  outline-offset: 3px !important;
}

@media (hover: hover) and (pointer: fine) {
  .innil-map-pill:hover,
  .leaflet-control-zoom a:hover,
  div.leaflet-control-layers.link:hover,
  #sidebar #pin:hover {
    background: var(--surface-hover) !important;
    background-color: var(--surface-hover) !important;
    border-color: rgba(52, 211, 153, 0.52) !important;
    color: var(--text) !important;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition: none !important;
    animation: none !important;
  }
}

@media (prefers-reduced-transparency: reduce) {
  .innil-map-pill,
  #sidebar,
  #sidebar #pin,
  .leaflet-control-zoom a,
  .leaflet-control-layers,
  div.leaflet-control-layers.coordinates,
  div.leaflet-control-layers.link,
  .leaflet-container .leaflet-control-attribution {
    background: #141b27 !important;
    backdrop-filter: none !important;
    -webkit-backdrop-filter: none !important;
  }
}

@media (prefers-contrast: more) {
  :root {
    --border: rgba(255, 255, 255, 0.48);
    --muted: #dce6f4;
  }
  .innil-map-pill,
  .leaflet-bar,
  .leaflet-control-layers,
  div.leaflet-control-layers.coordinates,
  div.leaflet-control-layers.link {
    border-width: 2px !important;
  }
}

@media (forced-colors: active) {
  .innil-map-pill,
  .leaflet-bar,
  .skip-link {
    border: 1px solid CanvasText !important;
    forced-color-adjust: auto;
  }
}
