:root {
  --bg: #16181d;
  --panel: #1f2229;
  --panel-2: #282c35;
  --border: #353a45;
  --text: #e7e9ee;
  --muted: #9aa1ae;
  --accent: #4caf50;
  --danger: #e5484d;
  --overworld: #4caf50;
  --nether: #d0433a;
  --end: #a57fd6;
  --sidebar-w: 310px;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

body { display: flex; flex-direction: column; overflow: hidden; }

button, input, select {
  font: inherit;
  color: inherit;
}

button {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 5px 10px;
  cursor: pointer;
}
button:hover { border-color: #56607a; background: #30353f; }
button.primary { background: var(--accent); border-color: var(--accent); color: #0d1a0e; font-weight: 600; }
button.primary:hover { filter: brightness(1.1); }
button.danger { color: #ff9a9d; }
button.danger:hover { border-color: var(--danger); }
button[hidden] { display: none; }

input[type="text"], input[type="number"], input[type="search"], select, textarea {
  background: #14161b;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 5px 8px;
  min-width: 0;
}
input:focus, select:focus, button:focus-visible { outline: 2px solid #5b8def; outline-offset: 1px; }

/* --- Barre du haut -------------------------------------------------------- */

.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 12px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
  z-index: 1000;
}
.topbar h1 { font-size: 17px; margin: 0; letter-spacing: 0.5px; }
.icon-btn { font-size: 17px; line-height: 1; padding: 5px 9px; }

.dims { display: flex; gap: 4px; }
.dim-btn { border-radius: 999px; padding: 5px 14px; }
.dim-btn.active { color: #111; font-weight: 600; }
.dim-overworld.active { background: var(--overworld); border-color: var(--overworld); }
.dim-nether.active { background: var(--nether); border-color: var(--nether); color: #fff; }
.dim-end.active { background: var(--end); border-color: var(--end); }

.search { position: relative; margin-left: auto; }
.search input { width: 300px; }
.search-results {
  position: absolute;
  top: calc(100% + 4px);
  right: 0;
  z-index: 1200;
  width: 360px;
  max-width: calc(100vw - 20px);
  max-height: 60vh;
  overflow-y: auto;
  margin: 0;
  padding: 4px;
  list-style: none;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
}
.search-results[hidden] { display: none; }
.search-item { display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-radius: 6px; cursor: pointer; }
.search-item.active, .search-item:hover { background: var(--panel-2); }
.search-results .empty { padding: 6px 8px; color: var(--muted); }
.search-icon { width: 14px; text-align: center; }

/* --- Mise en page ----------------------------------------------------------- */

.layout { flex: 1; display: flex; min-height: 0; position: relative; }

#sidebar {
  width: var(--sidebar-w);
  flex: none;
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  transition: margin-left 0.2s ease;
  z-index: 900;
}
body.sidebar-hidden #sidebar { margin-left: calc(-1 * var(--sidebar-w)); }

.tabs { display: flex; border-bottom: 1px solid var(--border); }
.tab {
  flex: 1;
  border: 0;
  border-radius: 0;
  background: transparent;
  padding: 10px 6px;
  color: var(--muted);
  border-bottom: 2px solid transparent;
}
.tab:hover { background: var(--panel-2); }
.tab.active { color: var(--text); border-bottom-color: var(--accent); }

.panel { display: none; padding: 10px; overflow-y: auto; flex: 1; }
.panel.active { display: block; }
.panel h3, .settings h3 { font-size: 12px; text-transform: uppercase; letter-spacing: 1px; color: var(--muted); margin: 16px 0 8px; }
.panel h3:first-child, .settings > h3:first-child { margin-top: 4px; }

/* Réglages : fenêtre à part, en-tête fixe pendant le défilement */
.settings-dialog { width: min(480px, calc(100vw - 32px)); }
.dialog-head {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 12px 8px 18px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}
.settings { padding: 6px 18px 18px; }

.row { display: flex; gap: 6px; align-items: center; }
.row > input, .row > .clearable { flex: 1; }

/* Champ avec croix d'effacement */
.clearable { position: relative; display: flex; min-width: 0; }
.clearable > input, .clearable > textarea { flex: 1; min-width: 0; padding-right: 26px; }
.clearable .clear-btn {
  position: absolute;
  right: 3px;
  top: 50%;
  transform: translateY(-50%);
  min-height: 0;
  padding: 0 5px;
  border: 0;
  background: none;
  color: var(--muted);
  font-size: 16px;
  line-height: 1;
  opacity: 0.55;
}
.clearable .clear-btn:hover { opacity: 1; color: var(--text); background: none; }
.clearable > textarea + .clear-btn { top: 5px; transform: none; }
.clearable > :placeholder-shown + .clear-btn { display: none; }
input[type="search"]::-webkit-search-cancel-button { -webkit-appearance: none; appearance: none; }
.row.wrap { flex-wrap: wrap; }
.grow { flex: 1; }
.check { display: flex; flex-direction: row; gap: 8px; align-items: center; margin: 8px 2px; color: var(--muted); cursor: pointer; }
dialog label.check { font-size: 14px; }
.hint { color: var(--muted); font-size: 12px; margin: 6px 0; }
.help { padding-left: 18px; color: var(--muted); font-size: 12.5px; }
.help li { margin-bottom: 6px; }

.list { list-style: none; margin: 8px 0 0; padding: 0; }
.item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 8px;
  border-radius: 6px;
  cursor: pointer;
}
.item:hover { background: var(--panel-2); }
.item-main { display: flex; flex-direction: column; flex: 1; min-width: 0; }
.item-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item-sub { color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item-links { color: var(--muted); font-size: 12px; }
.empty { color: var(--muted); padding: 12px 4px; font-size: 13px; }

.dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  flex: none;
  display: inline-block;
  border: 2px solid rgba(255, 255, 255, 0.85);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.5);
}
.dot-item {
  width: 20px;
  height: 20px;
  border-radius: 4px;
  border-width: 2px;
  background: rgba(20, 22, 27, 0.85);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.dot-item img { width: 14px; height: 14px; }
.swatch-line { width: 18px; height: 4px; border-radius: 2px; flex: none; display: inline-block; }
.swatch-zone { width: 14px; height: 14px; border-radius: 3px; flex: none; display: inline-block; opacity: 0.85; }

.badge {
  font-size: 10.5px;
  padding: 1px 6px;
  border-radius: 999px;
  font-weight: 600;
  flex: none;
}
.badge-overworld { background: rgba(76, 175, 80, 0.25); color: #9be09e; }
.badge-nether { background: rgba(208, 67, 58, 0.25); color: #ff9c95; }
.badge-end { background: rgba(165, 127, 214, 0.25); color: #d2b8f5; }

/* --- Carte ---------------------------------------------------------------- */

.map-wrap { flex: 1; position: relative; min-width: 0; }
/* Contexte d'empilement propre : les contrôles Leaflet (z-index 1000) restent sous le panneau. */
#map { position: absolute; inset: 0; background: #6f9a53; isolation: isolate; }
#map.drawing, #map.drawing .leaflet-interactive { cursor: crosshair; }
/* Chrome entoure d'un cadre le tracé SVG cliqué (focus) : inutile ici. */
#map path.leaflet-interactive:focus { outline: none; }

.crosshair {
  display: none;
  position: absolute;
  left: 50%;
  top: 50%;
  width: 22px;
  height: 22px;
  margin: -11px 0 0 -11px;
  z-index: 700;
  pointer-events: none;
  background:
    linear-gradient(#fff, #fff) center / 2px 100% no-repeat,
    linear-gradient(#fff, #fff) center / 100% 2px no-repeat;
  filter: drop-shadow(0 0 1.5px rgba(0, 0, 0, 0.9));
}
body.touch .crosshair { display: block; }

.coords {
  position: absolute;
  left: 10px;
  bottom: 10px;
  z-index: 800;
  background: rgba(15, 17, 21, 0.82);
  padding: 4px 10px;
  border-radius: 6px;
  font: 12px/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  white-space: pre;
  pointer-events: none;
  max-width: calc(100% - 20px);
  overflow: hidden;
  text-overflow: ellipsis;
}

.mode-banner {
  position: absolute;
  top: 10px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 850;
  background: rgba(15, 17, 21, 0.92);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  max-width: calc(100% - 100px);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.4);
}
.mode-banner[hidden] { display: none; }
.mode-actions { display: flex; gap: 6px; }

/* Marqueurs de POI */
.poi-icon { background: none; border: 0; }
.poi-pin {
  position: absolute;
  left: -8px;
  top: -8px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2.5px solid #fff;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.6), 0 2px 6px rgba(0, 0, 0, 0.5);
  cursor: pointer;
}
.poi-label {
  position: absolute;
  left: 12px;
  top: -10px;
  white-space: nowrap;
  font-weight: 600;
  font-size: 12.5px;
  color: #fff;
  text-shadow: 0 0 3px #000, 0 0 3px #000, 0 0 2px #000;
  pointer-events: none;
}
#map.hide-labels .poi-label { display: none; }
/* Nom d'une zone, centré sur son centre de gravité. */
.zone-label { pointer-events: none; }
.zone-label span {
  position: absolute;
  transform: translate(-50%, -50%);
  white-space: nowrap;
  font-weight: 700;
  font-size: 13px;
  letter-spacing: 0.3px;
  color: #fff;
  text-shadow: 0 0 3px #000, 0 0 3px #000, 0 0 2px #000;
}
.poi-pin-item {
  left: -14px;
  top: -14px;
  width: 28px;
  height: 28px;
  border-radius: 6px;
  background: rgba(20, 22, 27, 0.85);
  border-width: 2px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.poi-pin-item img, .dot-item img, .icon-current img, .icon-cell img {
  image-rendering: pixelated;
  display: block;
}
.poi-pin-item img { width: 20px; height: 20px; }
.poi-pin-item + .poi-label { left: 18px; }
.poi-icon.pulse .poi-pin { animation: pulse 0.9s ease-out 2; }
@keyframes pulse {
  0% { box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.6), 0 0 0 0 rgba(255, 255, 255, 0.9); }
  100% { box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.6), 0 0 0 16px rgba(255, 255, 255, 0); }
}

.vertex-icon {
  background: #fff;
  border: 2px solid #111;
  border-radius: 2px;
  cursor: move;
}

/* Popups */
.leaflet-popup-content-wrapper, .leaflet-popup-tip {
  background: var(--panel);
  color: var(--text);
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.5);
}
.leaflet-popup-content { margin: 12px 14px; font-size: 13px; }
.leaflet-container a.leaflet-popup-close-button { color: var(--muted); }
.popup-title { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 15px; margin-bottom: 6px; padding-right: 14px; }
.popup-cat { font-size: 12.5px; color: var(--muted); margin: -2px 0 4px; }
.cat-filter { display: flex; flex-wrap: wrap; gap: 6px; margin: 4px 0 8px; }
.cat-filter[hidden] { display: none; }
.cat-chip { border-radius: 999px; padding: 3px 10px; font-size: 12.5px; }
.cat-chip.off { opacity: 0.45; text-decoration: line-through; }
.popup-coords { display: flex; gap: 10px; font-family: ui-monospace, Menlo, Consolas, monospace; }
.popup-coords .y { color: var(--muted); }
.popup-sub { color: var(--muted); font-size: 12px; margin-top: 4px; }
.popup-label { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: 1px; margin: 10px 0 4px; }
.popup-links { display: flex; flex-direction: column; gap: 4px; }
.link-btn { display: flex; align-items: center; gap: 8px; text-align: left; width: 100%; }
.link-btn .link-name { flex: 1; }
.link-btn .arrow { color: var(--muted); }
.link-btn:hover .arrow { color: var(--text); }
.popup-actions { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 12px; }
.popup-actions button { padding: 4px 8px; font-size: 12.5px; }
.append-path { width: 100%; margin-top: 8px; font-size: 12.5px; }

.leaflet-tooltip { background: var(--panel); color: var(--text); border-color: var(--border); }
.leaflet-tooltip-left::before { border-left-color: var(--panel); }
.leaflet-tooltip-right::before { border-right-color: var(--panel); }

.leaflet-bar a { background: var(--panel); color: var(--text); border-bottom-color: var(--border); }
.leaflet-bar a:hover { background: var(--panel-2); color: var(--text); }
.leaflet-bar a.leaflet-disabled { background: var(--panel); color: #555; }
.fit-all { font-size: 17px; font-weight: 600; }

/* Menu contextuel */
.context-menu {
  position: fixed;
  z-index: 2000;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 4px;
  min-width: 210px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
  display: flex;
  flex-direction: column;
}
.context-menu[hidden] { display: none; }
.context-menu .menu-title { color: var(--muted); font-size: 12px; padding: 4px 8px 6px; font-family: ui-monospace, Menlo, Consolas, monospace; }
.context-menu button { background: none; border: 0; text-align: left; padding: 7px 10px; }
.context-menu button:hover { background: var(--panel-2); }

/* Dialogues */
dialog {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0;
  width: min(440px, calc(100vw - 32px));
  max-height: calc(100dvh - 24px);
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
}
dialog::backdrop { background: rgba(0, 0, 0, 0.5); }
dialog form { padding: 18px; display: flex; flex-direction: column; gap: 12px; }
dialog h2 { margin: 0; font-size: 17px; }
dialog label, dialog .field { display: flex; flex-direction: column; gap: 4px; color: var(--muted); font-size: 12.5px; }
dialog label input, dialog label select, dialog label textarea { color: var(--text); font-size: 14px; }
dialog textarea { resize: vertical; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
#path-info.error { color: #ff9a9d; }
.xyz { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.xyz input { width: 100%; }
.color-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
input[type="color"] { width: 42px; height: 32px; padding: 2px; border: 1px solid var(--border); border-radius: 6px; background: #14161b; cursor: pointer; }
.swatches { display: flex; gap: 4px; flex-wrap: wrap; }
.swatch { width: 20px; height: 20px; padding: 0; border-radius: 4px; border: 1px solid rgba(255, 255, 255, 0.3); }
.link-picker {
  max-height: 180px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px;
  background: #14161b;
}
.link-option { flex-direction: row !important; align-items: center; gap: 8px !important; padding: 4px 6px; border-radius: 4px; cursor: pointer; color: var(--text) !important; font-size: 13px !important; }
.link-option:hover { background: var(--panel-2); }
.link-option .link-name { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.icon-current { display: flex; align-items: center; gap: 8px; flex: 1; min-width: 140px; color: var(--text); font-size: 13px; }
.icon-current img { width: 28px; height: 28px; }
.icon-none { width: 28px; text-align: center; color: var(--muted); }
.icon-picker { display: flex; flex-direction: column; gap: 6px; margin-top: 6px; }
.icon-picker[hidden] { display: none; }
.icon-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(38px, 1fr));
  gap: 4px;
  max-height: 200px;
  overflow-y: auto;
  padding: 4px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #14161b;
}
.icon-grid .hint { grid-column: 1 / -1; }
.icon-cell { padding: 4px; display: flex; justify-content: center; background: transparent; border-color: transparent; }
.icon-cell:hover { background: var(--panel-2); border-color: var(--border); }
.icon-cell.selected { border-color: var(--accent); }
.icon-cell img { width: 28px; height: 28px; }
input[type="range"] { width: 100%; accent-color: var(--accent); }
.weight-preview-box { height: 20px; display: flex; align-items: center; padding: 0 4px; background: #14161b; border: 1px solid var(--border); border-radius: 6px; }
#weight-preview { width: 100%; border-radius: 8px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }

.history-btns { display: flex; gap: 2px; }
.history-btns .icon-btn:disabled { opacity: 0.35; cursor: default; }
.sync-badge {
  border-radius: 999px;
  padding: 3px 10px;
  font-size: 15px;
  line-height: 1.2;
}
.sync-badge[hidden] { display: none; }
.sync-badge[data-kind="idle"] { color: #7ed67f; }
.sync-badge[data-kind="pending"], .sync-badge[data-kind="syncing"] { color: #f0c64a; }
.sync-badge[data-kind="error"] { color: #ff8589; border-color: var(--danger); }
.sync-badge[data-kind="off"] { color: var(--muted); }
#sync-section[hidden], #sync-off[hidden], #sync-on[hidden] { display: none; }
#sync-join { margin-top: 6px; }
.sync-code-row { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.sync-code { font: 600 18px/1 ui-monospace, Menlo, Consolas, monospace; letter-spacing: 2px; flex: 1; }
.sync-status { font-size: 12.5px; margin: 8px 0 4px; color: var(--muted); }
.sync-status[data-kind="error"] { color: #ff9a9d; }
.sync-status[data-kind="idle"] { color: #9be09e; }

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: #0f1115;
  border: 1px solid var(--border);
  padding: 8px 14px;
  border-radius: 8px;
  z-index: 3000;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.5);
}
.toast[hidden] { display: none; }

/* --- Lecture seule ---------------------------------------------------------- */

body.readonly .edit { display: none !important; }
.readonly-chip {
  background: #26324a;
  border: 1px solid #3b4d70;
  border-radius: 999px;
  padding: 3px 10px;
  font-size: 13px;
  white-space: nowrap;
}
.readonly-chip[hidden] { display: none; }
.readonly-chip.error { background: #4a1f22; border-color: #7a3035; }
.readonly-chip a { color: #9cc1ff; }
.share-box { margin-top: 10px; display: flex; flex-direction: column; gap: 6px; align-items: flex-start; }
.share-on { display: flex; flex-direction: column; gap: 6px; width: 100%; }
.share-on[hidden] { display: none; }
#share-url { width: 100%; font-size: 12px; }

/* --- Petits écrans --------------------------------------------------------- */

@media (max-width: 720px) {
  :root { --sidebar-w: min(100vw, 380px); }
  .topbar { gap: 8px; padding: 6px 8px; }
  .topbar h1 { display: none; }
  .search { margin-left: 0; width: 100%; }
  .search input, .search .clearable { width: 100%; }
  .search-results { left: 0; right: 0; width: auto; }
  #sidebar { position: absolute; top: 0; bottom: 0; left: 0; box-shadow: 8px 0 24px rgba(0, 0, 0, 0.4); }
  .mode-banner { max-width: calc(100% - 20px); top: auto; bottom: 44px; font-size: 12.5px; }
  .coords { font-size: 11px; }
}

/* --- Écrans tactiles : cibles plus grandes -------------------------------------- */

@media (pointer: coarse) {
  button { min-height: 36px; }
  .dim-btn { padding: 6px 12px; }
  .icon-btn { min-width: 38px; }
  /* 16 px : pas de zoom automatique d'iOS sur les champs. */
  input[type="text"], input[type="number"], input[type="search"], select, textarea { font-size: 16px; padding: 7px 9px; }
  .item { padding: 11px 8px; }
  .search-item { padding: 11px 8px; }
  .context-menu button { padding: 12px 14px; }
  .tab { padding: 13px 6px; }
  .leaflet-touch .leaflet-bar a { width: 40px; height: 40px; line-height: 40px; }
}

/* Version du projet (VER-09) : discrète, en bas de la barre latérale. */
.app-version { margin: 16px 0 8px; text-align: center; font-size: 11px; color: var(--muted); }
