/*
 * VCraft map theme: a less realistic, medieval look for Pl3xMap, as plain CSS over the page's own markup.
 * It reaches nothing outside the site (the page's policy allows only its own files), uses only fonts the visitor
 * already has, and styles what the plugin sends: the province names are a tooltip holding <span class="vc-label">,
 * the zone fills and the rest are Pl3xMap's own markers. theme.js adds one class, "vc-far", when the map is zoomed far
 * out. Without the script everything still shows, only busier. legend.js adds the legend tab, styled at the end here.
 */

/* ---- the colours and the type of every panel: Pl3xMap's own variables, in both the light and the dark scheme ---- */
:root {
  color-scheme: light;
  --vc-ink: #3b2a1a;
  --vc-ink-soft: #5a4328;
  --vc-parchment: #f1e4c3;
  --vc-parchment-deep: #e6d3a6;
  --vc-edge: #8a6a3e;
  --vc-halo: #f4e8c8;
  --ui-font: "Palatino Linotype", "Book Antiqua", Palatino, Georgia, serif;
  --ui-border: 1px solid var(--vc-edge);
  --ui-box-shadow: 0 1px 3px rgba(60, 40, 15, 0.45);
  --ui-outline: solid #6b4f2a 0.3rem;
  --ui-background: var(--vc-parchment);
  --ui-background-hover: #ead9ae;
  --ui-background-active: #dcc794;
  --ui-background-selected: #6b4f2a;
  --ui-background-disabled: #cdbb92;
  --ui-text: var(--vc-ink);
  --ui-text-hover: var(--vc-ink);
  --ui-text-active: var(--vc-ink);
  --ui-text-selected: var(--vc-halo);
  --ui-text-disabled: #8d7a58;
}

/* ---- the map: tiles toned to parchment, a paper grain and a darkened rim over it ---- */
.leaflet-tile-pane {
  filter: sepia(0.5) saturate(0.8) contrast(1.02) brightness(1.06);
}

.leaflet-container {
  background: #e9dcb8 !important;
  font-family: var(--ui-font);
}

/*
 * Over the map and under the controls (which sit at 1000 and up). It never takes a click. The first background is the
 * topmost: the darkened rim goes over the paper, not under it.
 */
.leaflet-container::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 450;
  pointer-events: none;
  background: radial-gradient(ellipse at center, rgba(0, 0, 0, 0) 55%, rgba(70, 42, 15, 0.38) 100%), url("parchment.jpg");
  mix-blend-mode: multiply;
}

/* A compass rose in the bottom right, above the attribution line. Drawn with the map, never clickable. */
.leaflet-container::before {
  content: "";
  position: absolute;
  right: 14px;
  bottom: 30px;
  width: 112px;
  height: 112px;
  z-index: 451;
  pointer-events: none;
  background: url("compass.png") center / contain no-repeat;
  opacity: 0.85;
}

@media (max-width: 640px) {
  .leaflet-container::before {
    width: 64px;
    height: 64px;
    bottom: 26px;
  }
}

/* The zone fills are drawn on Pl3xMap's one canvas, and Leaflet shows a pointing hand over any polygon it can hit: keep the map's plain cursor. */
.leaflet-overlay-pane canvas.leaflet-interactive {
  cursor: inherit;
}

/* Icons are drawn at their own size, which is not always a whole number of pixels of the picture. */
.leaflet-marker-icon {
  image-rendering: auto;
  filter: drop-shadow(0 1px 1px rgba(60, 40, 15, 0.45));
}

/* The province flag is pixel art: scaled with hard edges, never smoothed. */
img[src*="vc_province"] {
  image-rendering: pixelated;
}

/* ---- province names: written on the map, ink brown, italic small caps, a parchment halo, no box ---- */
.leaflet-tooltip:has(.vc-label) {
  background: transparent;
  border: 0;
  box-shadow: none;
  padding: 0;
  color: var(--vc-ink);
  font: italic 700 14px "Palatino Linotype", "Book Antiqua", Palatino, Georgia, serif;
  font-variant: small-caps;
  letter-spacing: 0.5px;
  text-shadow: 0 0 3px var(--vc-halo), 0 0 3px var(--vc-halo), 0 0 6px var(--vc-halo);
}

.leaflet-tooltip:has(.vc-label)::before {
  display: none;
}

/* The name hangs a hand's breadth under the foot of the flagpole: drop Leaflet's own margin under the pole. */
.leaflet-tooltip-bottom:has(.vc-label) {
  margin-top: 0;
}

/* Zoomed far out there are no names, no flags and no rumours, so the colours read as a map. */
.vc-far .leaflet-tooltip:has(.vc-label) {
  display: none;
}

/* Markers only: the legend, which sits in the map's container too, keeps its pictures. */
.vc-far img.leaflet-marker-icon[src*="vc_rumour"],
.vc-far img.leaflet-marker-icon[src*="vc_province"] {
  display: none;
}

/* ---- every other tooltip and the popup of a province: a small slip of parchment ---- */
.leaflet-tooltip,
.leaflet-popup-content-wrapper,
.leaflet-popup-tip {
  background: var(--vc-parchment);
  color: var(--vc-ink);
  border: 1px solid var(--vc-edge);
  box-shadow: 0 1px 4px rgba(60, 40, 15, 0.5);
  font-family: var(--ui-font);
}

/* Leaflet writes a tooltip at 12 px: too small to read on the parchment. The province names keep their own size above. */
.leaflet-tooltip:not(:has(.vc-label)) {
  padding: 7px 10px;
  font-size: 14px;
  line-height: 1.4;
}

.leaflet-tooltip-top::before {
  border-top-color: var(--vc-edge);
}

.leaflet-tooltip-bottom::before {
  border-bottom-color: var(--vc-edge);
}

.leaflet-tooltip-left::before {
  border-left-color: var(--vc-edge);
}

.leaflet-tooltip-right::before {
  border-right-color: var(--vc-edge);
}

.leaflet-popup-content-wrapper {
  border-radius: 6px;
}

.leaflet-popup-content {
  margin: 12px 22px 12px 16px;
  font-size: 14px;
  line-height: 1.45;
}

.leaflet-container a.leaflet-popup-close-button {
  color: var(--vc-ink-soft);
}

/* ---- panels: the sidebar, the layer list and the zoom buttons ---- */
#sidebar #sidebar__content,
.leaflet-control-layers.leaflet-control-layers-expanded .leaflet-control-layers-list {
  background-image: url("parchment.jpg");
  background-blend-mode: multiply;
  color: var(--vc-ink);
  font-family: var(--ui-font);
}

.leaflet-bar a,
#sidebar #sidebar__buttons button {
  font-family: var(--ui-font);
}

/* One world with one style and no players on the map: the Worlds and Players tabs offer nothing, so they are not shown. */
#sidebar #sidebar__buttons button[aria-controls="sidebar__worlds"],
#sidebar #sidebar__buttons button[aria-controls="sidebar__players"] {
  display: none;
}

/*
 * ---- the legend tab legend.js adds: a picture, swatch or line, then a few words ----
 * Pl3xMap's page sets the root font to 10 px, so 1rem is 10 px here and not 16: every size below is written for that.
 * The panel is Pl3xMap's own sidebar, made wider through its own variable so a row seldom wraps; on a phone it keeps
 * to the screen.
 */
:root {
  --ui-sidebar-width: min(34rem, calc(100vw - 8rem));
}

#sidebar .vc-legend h3 {
  margin: 1.5rem 0 0.5rem;
  font-size: 1.7rem;
}

.vc-key-row {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin: 0.45rem 0;
  font-size: 1.4rem;
  line-height: 1.3;
}

.vc-key-pic {
  flex: 0 0 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 24px;
}

.vc-key-pic img {
  max-width: 24px;
  max-height: 24px;
  filter: drop-shadow(0 1px 1px rgba(60, 40, 15, 0.45));
}

/* Every row is a link to its wiki page: ink like the rest, a dotted line under it, a solid one under the pointer. */
#sidebar a.vc-key-text,
#sidebar a.vc-key-text:visited {
  color: var(--vc-ink);
  text-decoration: underline dotted var(--vc-edge);
  text-underline-offset: 3px;
}

#sidebar a.vc-key-text:hover,
#sidebar a.vc-key-text:focus-visible {
  color: var(--vc-ink-soft);
  text-decoration: underline solid var(--vc-ink-soft);
}

.vc-key-note {
  margin: 1.5rem 0 0.4rem;
  font-size: 1.3rem;
  line-height: 1.3;
  font-style: italic;
  color: var(--vc-ink-soft);
}

/* The danger colours of the zone fills (the plugin's Zone), stronger than on the map so they read on the parchment. */
.vc-key-fill {
  width: 24px;
  height: 16px;
  border: 1px solid var(--vc-edge);
  opacity: 0.6;
}

.vc-key-safe {
  background: #3f8f2a;
}

.vc-key-unsafe {
  background: #f0b000;
}

.vc-key-corrupted {
  background: #c21b12;
}

.vc-key-line {
  width: 26px;
}

/* TownyProvinces' province border: civilized, weight 1. */
.vc-key-border {
  border-top: 1px solid rgba(59, 42, 26, 0.8);
}

/* The road of the roads plugin: a pale ribbon under a dashed ink core, 8 px dash and 5 px gap. */
.vc-key-road {
  height: 3px;
  border: 1.5px solid rgba(239, 224, 189, 0.55);
  background: repeating-linear-gradient(90deg, rgba(74, 48, 24, 0.9) 0 8px, transparent 8px 13px);
}

/* Pl3xMap's world border layer: red, weight 3. */
.vc-key-edge {
  border-top: 3px solid #ff0000;
}

#sidebar #sidebar__content h2,
#sidebar #sidebar__content h3 {
  font-variant: small-caps;
  letter-spacing: 0.5px;
  color: var(--vc-ink);
}

.leaflet-control-attribution {
  background: rgba(241, 228, 195, 0.85) !important;
  color: var(--vc-ink-soft);
  font-family: var(--ui-font);
}

.leaflet-control-attribution a,
.leaflet-control-attribution a:visited,
.leaflet-control-attribution a:active,
.leaflet-control-attribution a:hover {
  color: var(--vc-ink-soft);
}
