/* ═══════════════════════════════════════
   WORKBENCH MAP EDITOR — a world's map editor in the full window
   (WorkbenchWorldEditor.js, WorkbenchWorldEditorFrame.js,
   WorkbenchWorldEditorPicker.js). The classic Worlds page hosts the same
   editor unstyled by this file: every rule is scoped to .wbme-host or .re-wb.
   ═══════════════════════════════════════ */

.wbme-host {
  position: fixed;
  inset: 0;
  z-index: 300;
  display: flex;
  background: var(--bg-primary);
  color: var(--text-primary);
  font-family: var(--font-sans);
}

.wbme-host[hidden] {
  display: none;
}

.re-wb.region-editor-overlay {
  flex: 1;
  min-width: 0;
  max-height: none;
  height: 100%;
  background: var(--bg-primary);
  font-size: 13px;
}

.re-wb .re-ico,
.re-wb .region-editor-toolbar {
  display: none;
}

.re-wb .re-wb-only {
  display: revert;
}

.re-wb .re-layer-label {
  display: inline;
}

.re-wb input[type="checkbox"],
.re-wb input[type="range"] {
  accent-color: var(--accent);
}

/* ── Top bar: title · tools · view · grid · bake · close ── */
.wbme-bar {
  display: flex;
  align-items: center;
  gap: 4px;
  flex: none;
  height: 44px;
  padding: 0 10px;
  overflow-x: auto;
  scrollbar-width: none;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-subtle);
}

.wbme-title {
  display: flex;
  align-items: center;
  gap: 8px;
  padding-right: 6px;
  white-space: nowrap;
}

.wbme-title b {
  font-weight: 600;
}

.re-wb .wbme-title .re-toolbar-map-info {
  margin-left: 4px;
  font: 11px var(--font-mono);
  color: var(--text-muted);
}

.wbme-sep {
  flex: none;
  width: 1px;
  height: 18px;
  margin: 0 6px;
  background: var(--border);
}

.wbme-group {
  display: flex;
  align-items: center;
  gap: 2px;
}

.wbme-end {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
  padding-left: 12px;
}

.re-wb .wbme-bar .re-toolbar-btn {
  height: 28px;
  padding: 0 10px;
  border: 1px solid transparent;
  border-radius: 5px;
  background: none;
  color: var(--text-secondary);
  font-size: 12px;
}

.re-wb .wbme-bar .re-toolbar-btn:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.re-wb .wbme-bar .re-toolbar-btn.active {
  border-color: var(--border);
  background: var(--wb-selected);
  color: var(--text-primary);
}

.re-wb .wbme-end .re-toolbar-btn {
  border-color: var(--border);
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

.re-wb .wbme-end .re-toolbar-coords {
  min-width: 0;
  max-width: 40ch;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font: 11px var(--font-mono);
  color: var(--text-muted);
}

/* The bake state as a pill-coloured button: amber needs a look, never red —
   an unbaked world still plays, it shows the last bake. */
.re-wb .re-bake-btn {
  height: 28px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg-tertiary);
  color: var(--text-secondary);
  font-size: 12px;
}

.re-wb .re-bake-btn.baked {
  border-color: transparent;
  background: var(--green-dim);
  color: var(--green);
}

.re-wb .re-bake-btn.stale {
  border-color: transparent;
  background: var(--amber-dim);
  color: var(--amber);
}

/* ── A tool's option strip under the bar ── */
.re-wb .re-tool-row {
  gap: 6px;
  padding: 6px 12px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  font-size: 12px;
}

.re-wb .re-tool-row .re-toolbar-btn {
  height: 26px;
  padding: 0 9px;
  border: 1px solid var(--border);
  border-radius: 5px;
  background: var(--bg-tertiary);
  color: var(--text-secondary);
  font-size: 12px;
}

.re-wb .re-tool-row .re-toolbar-btn:hover:not(:disabled) {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.re-wb .re-tool-row .re-toolbar-btn.active {
  border-color: var(--accent);
  background: var(--wb-selected);
  color: var(--text-primary);
}

.re-wb .re-tool-row .re-toolbar-separator {
  height: 16px;
  background: var(--border);
}

.re-wb .re-tool-row .re-toolbar-coords {
  min-width: 0;
  font: 11px var(--font-mono);
  color: var(--text-muted);
}

.re-wb .re-sketch-select {
  min-height: 28px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg-primary);
  color: var(--text-primary);
}

/* ── Body: picker · map · inspector ── */
.re-wb .region-editor-body {
  display: grid;
  grid-template-columns: 276px minmax(0, 1fr) 300px;
  grid-template-rows: minmax(0, 1fr);
}

.wbme-left,
.wbme-right {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--bg-secondary);
}

.wbme-left {
  border-right: 1px solid var(--border-subtle);
}

.wbme-right {
  border-left: 1px solid var(--border-subtle);
}

/* The shared sub-tabs (Place · Layers), without the page gap under them. */
.wbme-left .wbme-tabs {
  flex: none;
  margin: 0;
  padding: 2px 10px 0;
}

.wbme-left[data-tab="place"] .wbme-layers,
.wbme-left[data-tab="layers"] #rePalette {
  display: none;
}

.wbme-h {
  margin: 12px 0 6px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-secondary);
}

.wbme-right > .wbme-h {
  flex: none;
  margin: 12px 14px 2px;
}

/* ── The picker: the editor's palette as a grid of picture cards ── */
.re-wb #rePalette {
  --wbme-card: 84px;
  --wbme-crop-zoom: 2.2;
  display: flex;
  flex: 1;
  flex-direction: column;
  width: auto;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  background: none;
  border: none;
}

.re-wb #rePalette[data-size="s"] {
  --wbme-card: 62px;
  --wbme-crop-zoom: 1.6;
}

.re-wb #rePalette[data-size="l"] {
  --wbme-card: 118px;
  --wbme-crop-zoom: 3.2;
}

.re-wb .re-palette-search {
  padding: 10px 10px 6px;
  border: none;
}

.re-wb .re-palette-search input,
.re-wb .re-entity-list-search input {
  height: 30px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg-primary);
  color: var(--text-primary);
  font-size: 12.5px;
}

.re-wb .re-palette-search input:focus,
.re-wb .re-entity-list-search input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.re-wb .re-wb-cats {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
  padding: 2px 10px 8px;
  border-bottom: 1px solid var(--border-subtle);
}

.wbme-cat-chips {
  display: contents;
}

.re-wb[data-re-mode="terrain"] .wbme-cat-chips,
.re-wb[data-re-mode="road"] .wbme-cat-chips {
  display: none;
}

.wbme-sizes {
  display: inline-flex;
  gap: 4px;
  margin-left: auto;
}

.re-wb .re-palette-sections {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 8px 10px 16px;
}

/* One section at a time: a painter's packs while it is the tool, otherwise
   the category the chips picked. The section headings give way to the chips. */
.re-wb .re-palette-section,
.re-wb .re-palette-section-header {
  display: none;
  border: none;
}

.re-wb[data-re-mode="terrain"] .re-palette-section[data-section="terrain"],
.re-wb[data-re-mode="road"] .re-palette-section[data-section="road"],
.re-wb:not([data-re-mode="terrain"]):not([data-re-mode="road"])
  #rePalette[data-cat="placements"]
  [data-section="placements"],
.re-wb:not([data-re-mode="terrain"]):not([data-re-mode="road"])
  #rePalette[data-cat="npcs"]
  [data-section="npcs"],
.re-wb:not([data-re-mode="terrain"]):not([data-re-mode="road"])
  #rePalette[data-cat="items"]
  [data-section="items"],
.re-wb:not([data-re-mode="terrain"]):not([data-re-mode="road"])
  #rePalette[data-cat="mounts"]
  [data-section="mounts"],
.re-wb:not([data-re-mode="terrain"]):not([data-re-mode="road"])
  #rePalette[data-cat="portals"]
  [data-section="portals"],
.re-wb:not([data-re-mode="terrain"]):not([data-re-mode="road"])
  #rePalette[data-cat="spawnZones"]
  [data-section="spawnZones"],
.re-wb:not([data-re-mode="terrain"]):not([data-re-mode="road"])
  #rePalette[data-cat="triggers"]
  [data-section="triggers"] {
  display: block;
}

.re-wb .re-palette-list,
.re-wb .re-sub-group-list,
.re-wb .re-palette-section.collapsed > .re-palette-list,
.re-wb .re-sub-group.collapsed > .re-sub-group-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(var(--wbme-card), 1fr));
  gap: 6px;
}

/* A kind's cards sit under a small heading of their own, always open. */
.re-wb .re-palette-list > .re-sub-group,
.re-wb .re-palette-list > .re-palette-empty {
  grid-column: 1 / -1;
}

.re-wb .re-palette-sections .re-sub-group {
  border: none;
}

.re-wb .re-palette-sections .re-sub-group-header {
  padding: 10px 2px 6px;
  background: none;
  color: var(--text-muted);
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  pointer-events: none;
}

.re-wb .re-palette-sections .re-group-chevron {
  display: none;
}

.re-wb .re-group-count {
  background: none;
  font: 11px var(--font-mono);
  color: var(--text-muted);
}

.re-wb .re-palette-item,
.re-wb .re-sub-group-list .re-palette-item {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 4px;
  min-width: 0;
  padding: 5px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg-tertiary);
  color: var(--text-secondary);
  font-size: 11px;
  text-align: center;
}

.re-wb .re-palette-item:hover {
  border-color: var(--accent);
  background: var(--bg-hover);
  color: var(--text-primary);
}

/* The picked card: the one the next click on the map places. The draw tool
   also paints the card inline, which this has to outrank. */
.re-wb .re-palette-item.armed,
.re-wb .re-palette-item.active {
  border-color: var(--accent);
  background: var(--wb-selected) !important;
  box-shadow: inset 0 0 0 1px var(--accent);
  color: var(--text-primary);
}

.re-wb .re-palette-item > span:not([style]) {
  display: block;
  min-width: 0;
}

.re-wb .re-palette-item-name,
.re-wb .re-palette-item-sub {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.re-wb .re-palette-item-name {
  font-weight: 500;
}

.re-wb .re-palette-item-sub {
  margin: 0;
  color: var(--text-muted);
  font-size: 10px;
}

.re-wb #rePalette[data-size="s"] .re-palette-item-sub {
  display: none;
}

/* The art on a checker, so a cut-out's edges read against the card. */
.re-wb .re-palette-item-thumb,
.re-wb .re-palette-item:not(.re-terrain-item):not(:has(> img))::before {
  width: 100%;
  height: auto;
  aspect-ratio: 1;
  margin: 0;
  border-radius: 4px;
  background-color: var(--bg-primary);
  background-image:
    linear-gradient(45deg, var(--bg-secondary) 25%, transparent 25%),
    linear-gradient(-45deg, var(--bg-secondary) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, var(--bg-secondary) 75%),
    linear-gradient(-45deg, transparent 75%, var(--bg-secondary) 75%);
  background-size: 12px 12px;
  background-position:
    0 0,
    0 6px,
    6px -6px,
    -6px 0;
  object-fit: contain;
  object-position: center;
}

/* A template with no picture (a zone, a trigger, an NPC without a sprite
   pack) gets a plain mark in the art box instead; its kind is on the chip. */
.re-wb .re-palette-item:not(.re-terrain-item):not(:has(> img))::before {
  content: "•";
  display: grid;
  place-items: center;
  font: 600 18px var(--font-mono);
  color: var(--text-muted);
}

.re-wb .re-palette-item[data-type="spawnZones"]::before {
  content: "◎";
}

.re-wb .re-palette-item[data-type="triggers"]::before {
  content: "⚡";
}

/* A terrain chip's thumbnail is a 32px crop of the pack sheet; zoom scales the
   crop's background with it, which a transform would not lay out. */
.re-wb .re-terrain-item > span[style] {
  align-self: center;
  zoom: var(--wbme-crop-zoom);
}

.re-wb .re-palette-empty {
  padding: 16px 4px;
  color: var(--text-muted);
  font-size: 12px;
  text-align: left;
}

/* ── Layers tab: every toggle as a row, lit when shown ── */
.wbme-layers {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 0 10px 16px;
}

.wbme-rows {
  display: flex;
  flex-direction: column;
}

.re-wb .re-layer-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  height: 28px;
  padding: 0 6px;
  border: none;
  border-radius: 5px;
  background: none;
  color: var(--text-muted);
  font-size: 12.5px;
  text-align: left;
  opacity: 1;
}

.re-wb .re-layer-toggle.re-layer-toggle-empty {
  display: none;
}

.re-wb .re-layer-toggle:hover {
  background: var(--bg-hover);
}

.re-wb .re-layer-toggle::before {
  content: "";
  flex: none;
  width: 9px;
  height: 9px;
  border: 1.5px solid var(--text-muted);
  border-radius: 50%;
}

.re-wb .re-layer-toggle.active {
  color: var(--text-primary);
}

.re-wb .re-layer-toggle.active::before {
  border-color: var(--accent);
  background: var(--accent);
}

.re-wb .re-layer-icon {
  display: none;
}

.re-wb .re-layer-count {
  margin-left: auto;
  font: 11px var(--font-mono);
  color: var(--text-muted);
}

/* The sketch strip, stacked to fit the column. */
.re-wb .wbme-layers .re-tool-row {
  flex-direction: column;
  align-items: stretch;
  padding: 0;
  background: none;
  border: none;
}

.re-wb .wbme-layers .re-tool-row > span:first-child {
  display: none;
}

.re-wb .wbme-layers .re-sketch-layers,
.re-wb .wbme-layers .re-sketch-move {
  flex-wrap: wrap;
}

/* ── The map ── */
.re-wb .re-canvas-wrap,
.re-wb .re-loading {
  background: var(--bg-primary);
  color: var(--text-muted);
}

.re-wb .re-hud {
  position: absolute;
  left: 10px;
  bottom: 10px;
  z-index: 6;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 3px 6px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg-secondary);
  color: var(--text-secondary);
  font: 11px var(--font-mono);
  pointer-events: none;
}

.re-hud-btn {
  width: 20px;
  height: 20px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--bg-tertiary);
  color: var(--text-secondary);
  line-height: 1;
  cursor: pointer;
  pointer-events: auto;
}

.re-hud-btn:hover {
  color: var(--text-primary);
}

#reHudTile:empty {
  display: none;
}

.re-wb .re-hint {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 6;
  padding: 3px 8px;
  border-radius: 5px;
  border: 1px solid var(--border);
  background: var(--bg-secondary);
  color: var(--text-muted);
  font-size: 11.5px;
  pointer-events: none;
}

.re-wb .re-hint:empty {
  display: none;
}

/* ── Right column: the inspector over what is on the map ── */
.re-wb .re-inspector {
  flex: 0 1 auto;
  width: auto;
  min-width: 0;
  max-height: 62%;
  overflow-y: auto;
  background: none;
  border: none;
  border-bottom: 1px solid var(--border-subtle);
}

.re-wb .re-inspector-empty {
  height: auto;
  flex-direction: row;
  justify-content: flex-start;
  padding: 4px 14px 14px;
  color: var(--text-muted);
  font-size: 12px;
}

.re-wb .re-inspector-empty .re-inspector-icon {
  display: none;
}

.re-wb .re-inspector-content {
  padding: 8px 14px 14px;
}

.re-wb .re-insp-name {
  color: var(--text-primary);
}

.re-wb .re-insp-fields {
  gap: 10px;
}

.re-wb .re-insp-row {
  gap: 8px;
}

.re-wb .re-insp-field label {
  color: var(--text-muted);
  font-weight: 400;
}

.re-wb .re-insp-field input,
.re-wb .re-insp-field textarea,
.re-wb .re-insp-field select {
  min-height: 30px;
  padding: 5px 9px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg-primary);
  color: var(--text-primary);
  font-size: 12.5px;
}

.re-wb .re-insp-field input:focus,
.re-wb .re-insp-field textarea:focus,
.re-wb .re-insp-field select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.re-wb .re-insp-field textarea {
  font: 11.5px var(--font-mono);
}

.re-wb .re-insp-checkbox span {
  color: var(--text-secondary);
}

.re-wb .re-insp-section-label {
  border-bottom-color: var(--border-subtle);
  color: var(--text-secondary);
  letter-spacing: 0.08em;
}

.re-wb .re-insp-actions {
  flex-direction: row;
  flex-wrap: wrap;
  border-top-color: var(--border-subtle);
}

.re-wb .re-insp-btn {
  height: 30px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

.re-wb .re-insp-btn:hover {
  background: var(--bg-hover);
}

.re-wb .re-insp-delete {
  border-color: var(--red-dim);
  background: none;
  color: var(--red);
}

.re-wb .re-insp-delete:hover {
  background: var(--red-dim);
}

.re-wb .re-insp-status {
  color: var(--text-muted);
}

.re-wb .re-insp-status.saved {
  color: var(--green);
}

.re-wb .re-insp-status.error {
  color: var(--red);
}

.re-wb .re-entity-list {
  flex: 1;
  width: auto;
  min-width: 0;
  min-height: 0;
  background: none;
  border: none;
}

.re-wb .re-entity-list-search {
  padding: 6px 12px 8px;
  border: none;
}

.re-wb .re-entity-list-section,
.re-wb .re-entity-list-sections .re-sub-group {
  border-color: var(--border-subtle);
}

.re-wb .re-entity-list-section-header,
.re-wb .re-entity-list-sections .re-sub-group-header {
  background: none;
  color: var(--text-secondary);
}

.re-wb .re-entity-list-section-header:hover,
.re-wb .re-entity-list-sections .re-sub-group-header:hover,
.re-wb .re-entity-list-item:hover {
  background: var(--bg-hover);
}

.re-wb .re-entity-list-item {
  color: var(--text-secondary);
}

.re-wb .re-entity-list-item.selected {
  background: var(--wb-selected);
  box-shadow: inset 2px 0 0 var(--accent);
  color: var(--text-primary);
}

.re-wb .re-entity-list-item-coords {
  font-family: var(--font-mono);
  color: var(--text-muted);
}

@media (max-width: 1180px) {
  .re-wb .region-editor-body {
    grid-template-columns: 240px minmax(0, 1fr) 260px;
  }
}

/* ── Hover help, as everywhere in the workbench (workbench-pages.css): the
   editor's titles become data-help while it is up (WorkbenchWorldEditorTips) ── */
.wbme-host [data-help] {
  cursor: help;
}

.wbme-host .wbme-h span[data-help] {
  text-decoration: underline dotted;
  text-decoration-color: var(--text-muted);
  text-underline-offset: 3px;
}
