.map-renderer-host {
  position: fixed !important;
  inset: 30px;
  overflow: hidden;
  background: #f7f8fa;
}

.map-workspace {
  --map-panel-width: 420px;
  position: absolute;
  inset: 0;
  overflow: hidden;
  background-color: #f7f8fa;
  background-image: radial-gradient(circle, rgba(37, 38, 43, 0.11) 1.2px, transparent 1.3px);
  background-size: 26px 26px;
}

.map-workspace[data-map-theme="clean-white"] {
  background-color: #ffffff;
  background-image: none;
}

.map-workspace[data-map-theme="blockgraf-dark"] {
  background-color: #101217;
  background-image: radial-gradient(circle, rgba(255, 255, 255, 0.1) 1.2px, transparent 1.3px);
}

.map-canvas {
  position: absolute;
  inset: 0;
  cursor: default;
  /* Gestures belong to the map (mapRenderer.js), not to page zoom or scroll */
  touch-action: none;
  transition: right 180ms ease;
}

.map-canvas.is-panning,
.map-canvas.is-panning canvas { cursor: grabbing !important; }

.map-workspace.has-panel .map-canvas { right: 0; }

.map-panel {
  position: absolute;
  z-index: 4;
  top: 14px;
  right: 0;
  bottom: 64px;
  width: var(--map-panel-width);
  display: flex;
  flex-direction: column;
  border: 1px solid rgba(255, 255, 255, 0.11);
  border-right: 0;
  border-radius: 24px 0 0 24px;
  background: var(--border-container-color, #000);
  box-shadow: -18px 18px 55px rgba(0, 0, 0, 0.32);
  backdrop-filter: none;
  transform: translateX(calc(100% + 8px));
  opacity: 0;
  pointer-events: none;
  transition: transform 240ms cubic-bezier(0.22, 1, 0.36, 1), opacity 160ms ease;
  font-family: Inter, sans-serif;
}

.map-panel.is-open { transform: translateX(0); opacity: 1; pointer-events: auto; }

.map-panel__header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 20px 20px 16px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.09);
}

.map-panel__eyebrow {
  display: block;
  margin-bottom: 4px;
  color: #8e94a3;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.11em;
  text-transform: uppercase;
}

.map-panel h2 { margin: 0; color: #f5f7fb; font-size: 19px; line-height: 1.25; }
.map-panel h3 { margin: 0 0 11px; color: #d7dae2; font-size: 12px; font-weight: 700; letter-spacing: 0.02em; }

.map-panel__close {
  width: 30px;
  height: 30px;
  border: 0;
  border-radius: 9px;
  background: rgba(255, 255, 255, 0.08);
  color: #d8dbe2;
  font-size: 21px;
  line-height: 1;
}

.map-panel__body { flex: 1; overflow-y: auto; padding: 6px 20px 16px; }
.map-panel__section { padding: 15px 0; border-bottom: 1px solid rgba(255, 255, 255, 0.08); }
.map-panel__section:last-child { border-bottom: 0; }

.map-panel__field { display: block; margin-bottom: 11px; }
.map-panel__field:last-child { margin-bottom: 0; }
.map-panel__field > span { display: block; margin-bottom: 5px; color: #a8adba; font-size: 11px; font-weight: 600; }

.map-panel__field input,
.map-panel__field textarea,
.map-panel__field select {
  width: 100%;
  box-sizing: border-box;
  border: 1px solid rgba(255, 255, 255, 0.13);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.065);
  color: #f0f2f6;
  font: 13px/1.4 Inter, sans-serif;
  outline: none;
  padding: 9px 10px;
  transition: border-color 120ms ease, box-shadow 120ms ease;
}

.map-panel__field textarea { min-height: 72px; resize: vertical; }
.map-panel__field input::placeholder,
.map-panel__field textarea::placeholder { color: #747a88; }
.map-panel__field input:focus,
.map-panel__field textarea:focus,
.map-panel__field select:focus { border-color: #8a74ff; box-shadow: 0 0 0 3px rgba(114, 92, 255, 0.2); }
.map-panel__field select { appearance: auto; cursor: pointer; }
.map-panel__field select option {
  background: #ffffff;
  color: #171923;
}
.map-panel__field input[type="color"] { height: 38px; padding: 4px; cursor: pointer; }

.map-panel__format-toolbar {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-bottom: 6px;
}
.map-panel__format-button {
  flex: 0 0 30px;
  width: 30px;
  height: 26px;
  border: 1px solid rgba(255, 255, 255, 0.13);
  border-radius: 7px;
  background: rgba(255, 255, 255, 0.065);
  color: #d8dbe2;
  font-size: 11px;
  cursor: pointer;
  transition: background 120ms ease;
}
.map-panel__format-button:hover { background: rgba(255, 255, 255, 0.14); }
.map-panel__format-separator {
  flex: 0 0 1px;
  width: 1px;
  height: 18px;
  background: rgba(255, 255, 255, 0.13);
}
.map-panel__format-swatch {
  flex: 0 0 20px;
  width: 20px;
  height: 20px;
  border: 1px solid rgba(0, 0, 0, 0.25);
  border-radius: 6px;
  cursor: pointer;
  transition: transform 120ms ease;
}
.map-panel__format-swatch:hover { transform: scale(1.12); }
.map-panel__format-button--expand { margin-left: auto; }

.map-panel__editor {
  width: 100%;
  box-sizing: border-box;
  min-height: 96px;
  max-height: 300px;
  overflow-y: auto;
  resize: vertical;
  border: 1px solid rgba(255, 255, 255, 0.13);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.065);
  color: #f0f2f6;
  font: 13px/1.45 Inter, sans-serif;
  outline: none;
  padding: 9px 10px;
  transition: border-color 120ms ease, box-shadow 120ms ease;
}
.map-panel__editor:focus { border-color: #8a74ff; box-shadow: 0 0 0 3px rgba(114, 92, 255, 0.2); }
.map-panel__editor ul { margin: 2px 0; padding-left: 20px; list-style: disc; }
.map-panel__editor ul ul { list-style: circle; }
.map-panel__editor ul ul ul { list-style: square; }
.map-panel__editor li { margin: 1px 0; }
.map-panel__editor span[style] { border-radius: 3px; padding: 0 1px; color: #1f2430; }

/* Expanded mode: larger editing surface floating left of the panel; the panel
   re-render on close/selection change resets it to the default state. */
.map-panel__editor-close { display: none; }
.map-panel__description.is-expanded {
  position: fixed;
  top: 64px;
  right: calc(var(--map-panel-width, 330px) + 22px);
  bottom: 76px;
  width: min(560px, calc(100vw - var(--map-panel-width, 330px) - 60px));
  z-index: 60;
  display: flex;
  flex-direction: column;
  padding: 14px;
  border: 1px solid rgba(255, 255, 255, 0.13);
  border-radius: 14px;
  background: var(--border-container-color, #000);
  box-shadow: 0 18px 44px rgba(0, 0, 0, 0.5);
}
.map-panel__description.is-expanded .map-panel__editor {
  flex: 1;
  max-height: none;
  resize: none;
  font-size: 14px;
}
.map-panel__description.is-expanded .map-panel__format-toolbar { margin-right: 34px; }
.map-panel__description.is-expanded .map-panel__editor-close {
  display: flex;
  align-items: center;
  justify-content: center;
  position: absolute;
  top: 10px;
  right: 10px;
  width: 26px;
  height: 26px;
  border: 0;
  border-radius: 9px;
  background: rgba(255, 255, 255, 0.08);
  color: #d8dbe2;
  font-size: 17px;
  line-height: 1;
  cursor: pointer;
}
.map-panel__description.is-expanded .map-panel__editor-close:hover { background: rgba(255, 255, 255, 0.16); }
.map-panel__field input[type="range"] {
  height: 24px;
  padding: 0;
  border: 0;
  background: transparent;
  box-shadow: none;
  accent-color: #8a74ff;
  cursor: ew-resize;
}
.map-panel__field > .map-panel__range-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.map-panel__range-label output { color: #c8beff; font-size: 10px; font-weight: 700; }
.map-panel__toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin: 4px 0 11px;
  color: #d7dae2;
  cursor: pointer;
}
.map-panel__toggle > span { display: grid; gap: 2px; }
.map-panel__toggle strong { font-size: 11px; font-weight: 650; }
.map-panel__toggle small { color: #858b98; font-size: 9px; }
.map-panel__toggle input {
  width: 34px;
  height: 18px;
  accent-color: #8a74ff;
  cursor: pointer;
}
.map-panel__hint { margin: 7px 0 0; color: #858b98; font-size: 10px; line-height: 1.4; }

.map-panel__image-preview {
  display: grid;
  place-items: center;
  min-height: 92px;
  margin-bottom: 10px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.04);
}
.map-panel__image-preview img { display: block; box-sizing: border-box; max-width: 100%; max-height: 150px; object-fit: contain; }

.map-panel__upload {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 38px;
  margin-bottom: 11px;
  border: 1px dashed rgba(255, 255, 255, 0.22);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.045);
  color: #b7bbc5;
  cursor: pointer;
  font-size: 11px;
  font-weight: 650;
}
.map-panel__upload:hover { border-color: #8a74ff; color: #c8beff; background: rgba(114, 92, 255, 0.12); }
.map-panel__upload-status { min-height: 0; margin: -4px 0 7px; color: #9da2ae; font-size: 10px; }
.map-panel__upload-status:empty { display: none; }
.map-panel__image-section:focus { outline: 2px solid #8a74ff; outline-offset: -2px; border-radius: 10px; }
.map-panel__image-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.map-panel__text-action { border: 0; background: transparent; color: #c94747; font: 600 10px Inter, sans-serif; padding: 2px 0; }
.map-panel__visibility-action { color: #bcaeff; cursor: pointer; }
.map-panel__section-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 9px; }
.map-panel__section-heading h3 { margin-bottom: 0; }
.map-panel__section-heading .map-panel__text-action { color: #bcaeff; cursor: pointer; }
.map-panel__heading-actions { display: flex; align-items: center; gap: 10px; }
.map-panel__button-list { display: grid; gap: 7px; margin-top: 11px; }
.map-panel__button-item {
  display: flex;
  align-items: center;
  gap: 7px;
  min-height: 38px;
  padding: 5px 6px 5px 10px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.045);
}
.map-panel__button-name {
  min-width: 0;
  flex: 1;
  overflow: hidden;
  border: 0;
  background: transparent;
  color: #eef0f5;
  font: 600 11px Inter, sans-serif;
  text-align: left;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.map-panel__button-order { display: flex; gap: 3px; }
.map-panel__button-order button {
  display: grid;
  place-items: center;
  width: 25px;
  height: 25px;
  border: 0;
  border-radius: 7px;
  background: rgba(255, 255, 255, 0.07);
  color: #aeb3bf;
  font-size: 9px;
}
.map-panel__button-order button:last-child { color: #ff8585; }
.map-panel__button-order button:disabled { opacity: 0.25; }
.map-panel__empty { margin: 0; color: #777d8a; font: 11px Inter, sans-serif; }

.map-panel__move-body {
  display: flex;
  align-items: center;
}
.map-panel__move-body .map-panel__section { width: 100%; text-align: center; }
.map-panel__move-icon {
  display: grid;
  place-items: center;
  width: 54px;
  height: 54px;
  margin: 0 auto 18px;
  border: 1px solid rgba(0, 114, 230, 0.42);
  border-radius: 16px;
  background: rgba(0, 114, 230, 0.14);
  color: #69b4ff;
  font-size: 21px;
}
.map-panel__move-copy {
  margin: 0 0 14px;
  color: #c7cbd4;
  font-size: 12px;
  line-height: 1.55;
}

.map-panel__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 14px 16px;
  border-top: 1px solid rgba(255, 255, 255, 0.09);
}

.map-panel__button {
  min-height: 36px;
  border: 1px solid rgba(255, 255, 255, 0.13);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.07);
  color: #d8dbe2;
  font: 600 11px Inter, sans-serif;
  padding: 0 12px;
}
.map-panel__button--primary { flex: 1; border-color: #725cff; background: #725cff; color: #fff; }
.map-panel__button--danger { border-color: rgba(235, 91, 91, 0.28); color: #ff8585; }
.map-panel__button--center,
.map-panel__button--json {
  flex: 0 0 38px;
  padding: 0;
  border-color: var(--bgf-accent);
  color: var(--bgf-text);
}
.map-panel__button--order {
  flex: 0 0 38px;
  padding: 0;
  color: #c5baff;
}
.map-panel__button:disabled { opacity: 0.32; cursor: default; filter: none; }

.map-panel--json { width: min(620px, calc(100vw - 36px)); }
.map-panel__json-body { display: flex; min-height: 0; flex-direction: column; gap: 10px; }
.map-panel__json-editor {
  flex: 1;
  width: 100%;
  min-height: 260px;
  box-sizing: border-box;
  resize: none;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 12px;
  background: #111318;
  color: #e7e9ef;
  outline: none;
  padding: 12px;
  tab-size: 2;
  font: 12px/1.5 Consolas, "SFMono-Regular", monospace;
}
.map-panel__json-editor:focus { border-color: #8a74ff; box-shadow: 0 0 0 3px rgba(114, 92, 255, 0.2); }
.map-panel__json-status {
  min-height: 38px;
  max-height: 110px;
  overflow: auto;
  margin: 0;
  white-space: pre-wrap;
  color: #b9bfcb;
  font: 10px/1.45 Consolas, "SFMono-Regular", monospace;
}
.map-panel__json-actions .map-panel__button { flex: 1 1 auto; }

.map-panel__body {
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.2) transparent;
}
.map-panel__body::-webkit-scrollbar { width: 7px; }
.map-panel__body::-webkit-scrollbar-thumb { border-radius: 8px; background: rgba(255, 255, 255, 0.18); }

.map-section-a11y {
  position: absolute;
  z-index: 5;
  left: 20px;
  top: 116px;
  width: 1px;
  height: 1px;
  overflow: hidden;
  opacity: 0;
}
.map-section-a11y:focus-within {
  display: grid;
  width: min(290px, calc(100vw - 40px));
  height: auto;
  max-height: 50vh;
  gap: 6px;
  overflow: auto;
  opacity: 1;
  padding: 10px;
  border: 1px solid var(--bgf-accent);
  border-radius: 12px;
  background: #17191f;
  box-shadow: 0 12px 36px rgba(0, 0, 0, 0.38);
}
.map-section-a11y button {
  min-height: 34px;
  border: 1px solid rgba(255, 255, 255, 0.13);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.07);
  color: #eef0f5;
  padding: 7px 9px;
  font: 600 11px/1.3 Inter, sans-serif;
  text-align: left;
}
.map-section-a11y button:focus { outline: 2px solid #8a74ff; outline-offset: 1px; }

.map-zoom-tools {
  position: absolute;
  z-index: 3;
  left: 20px;
  top: 20px;
  display: flex;
  overflow: hidden;
  border: 1px solid rgba(32, 34, 42, 0.1);
  border-radius: 11px;
  background: rgba(255, 255, 255, 0.88);
  box-shadow: 0 8px 24px rgba(20, 22, 28, 0.08);
  backdrop-filter: blur(8px);
}
.map-zoom-tools button {
  width: 36px;
  height: 34px;
  border: 0;
  border-right: 1px solid #e8e9ed;
  background: transparent;
  color: #555a66;
  font-size: 17px;
}
.map-zoom-tools button:last-child { border-right: 0; }
.map-workspace[data-map-theme="blockgraf-dark"] .map-zoom-tools {
  border-color: rgba(255, 255, 255, 0.14);
  background: rgba(27, 30, 37, 0.92);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
}
.map-workspace[data-map-theme="blockgraf-dark"] .map-zoom-tools button {
  border-right-color: rgba(255, 255, 255, 0.1);
  color: #e3e6ed;
}
.map-zoom-tools button:hover,
.map-history-tools button:hover:not(:disabled),
.map-panel__button:hover,
.map-panel__close:hover { filter: brightness(0.96); }

.map-history-tools {
  position: absolute;
  z-index: 3;
  left: 20px;
  top: 68px;
  display: none;
  overflow: hidden;
  border: 1px solid rgba(32, 34, 42, 0.12);
  border-radius: 11px;
  background: rgba(255, 255, 255, 0.9);
  box-shadow: 0 8px 24px rgba(20, 22, 28, 0.1);
  backdrop-filter: blur(8px);
}
.map-workspace.is-editable .map-history-tools { display: flex; }
.map-history-tools button {
  width: 38px;
  height: 36px;
  border: 0;
  border-right: 1px solid #e8e9ed;
  background: transparent;
  color: #4e5562;
  font-size: 13px;
}
.map-history-tools button:last-child { border-right: 0; }
.map-history-tools button:disabled { opacity: 0.32; cursor: default; }
.map-workspace[data-map-theme="blockgraf-dark"] .map-history-tools {
  border-color: rgba(255, 255, 255, 0.14);
  background: rgba(27, 30, 37, 0.92);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
}
.map-workspace[data-map-theme="blockgraf-dark"] .map-history-tools button {
  border-right-color: rgba(255, 255, 255, 0.1);
  color: #e3e6ed;
}

/* Phones: the block editor is a bottom sheet, as in mobile canvas apps, so
   the map stays visible above it instead of being squeezed to a strip. */
@media (max-width: 760px) {
  .map-workspace.has-panel .map-canvas { right: 0; }
  .map-panel {
    top: auto;
    left: 0;
    right: 0;
    bottom: 0;
    width: auto;
    height: min(58%, 520px);
    border-right: 1px solid var(--bgf-border);
    border-bottom: 0;
    border-radius: 20px 20px 0 0;
    box-shadow: var(--bgf-shadow);
    transform: translateY(calc(100% + 8px));
  }
  .map-panel.is-open { transform: translateY(0); }
  .map-panel--json { width: auto; height: 82%; }
  .map-panel__header { padding: 14px 16px 10px; }
  .map-panel__body { padding: 4px 16px 12px; }
}
