:root {
  --bg: #12151c;
  --panel: #1c2230;
  --panel2: #252c3c;
  --text: #e8eaee;
  --muted: #8b95a8;
  --accent: #6eb5ff;
  --warn: #ffb060;
  --danger: #ff7a6b;
  --ok: #6fdc8c;
  --border: #343c50;

  /* `--line` and `--fg` were used in four places and defined in none, so the
     paint bar silently lost its bottom border and its tools their colour while
     the identical-looking view bar kept both. Aliases rather than new values:
     they were always meant to be these. */
  --line: var(--border);
  --fg: var(--text);

  /* Inter for the interface, JetBrains Mono for anything aligned or technical
     -- build logs, paths, hex, addresses. The system stack stays behind both,
     so a font that fails to load degrades rather than breaking the layout.
     Silkscreen is deliberately absent here: it is a splash face, and the spec
     is explicit that pixel fonts do not belong in editor navigation. */
  --font-ui: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, "Cascadia Mono", Consolas, monospace;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: var(--font-ui);
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  display: flex;
  flex-direction: column;
}

header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

header h1 {
  font-size: 16px;
  margin: 0;
  font-weight: 600;
}

.mode-tabs {
  display: flex;
  gap: 4px;
}

.mode-tabs .tab {
  padding: 4px 10px;
  font-size: 12px;
}

.mode-tabs .tab.active {
  border-color: var(--accent);
  background: #243048;
}

.toolbar { display: flex; gap: 8px; margin-left: auto; flex-wrap: wrap; }

button, select, input[type="search"] {
  background: var(--panel2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 12px;
  font-size: 13px;
}

button { cursor: pointer; }
button.primary { background: #2a5a9e; border-color: #3d74c4; }
button:disabled { opacity: 0.5; cursor: not-allowed; }

#status {
  font-size: 12px;
  color: var(--muted);
  min-width: 120px;
}

#main {
  flex: 1;
  display: grid;
  min-height: 0;
}

/* A grid item is min-content wide by default, and the map canvas is as wide as
   the map. Without this the `1fr` track refuses to shrink below it, the row
   overflows, and the panel on the right is pushed off the edge of the window —
   which is how the placed-objects list arrived half off screen. Each panel
   scrolls its own content instead. */
#main > .panel { min-width: 0; }

/* Two workspaces, and the map one has a **fixed** grid.

   The old three-mode scheme moved panels around on every tab click, which is
   why the palette and the map were never on screen together. Here the columns
   never change: the tabs live *inside* the palette and only change what that
   one column renders, so the canvas never moves, resizes or unmounts. That is
   the whole point of the layout. */
#ws-maps.ws-map #main {
  grid-template-columns:
    var(--list-track, var(--list-w, 180px))
    var(--palette-track, var(--palette-w, 320px))
    minmax(0, 1fr)
    var(--context-track, var(--context-w, 300px));
  grid-template-areas: "list palette canvas context";
}

#ws-maps.ws-map #panel-maps-list  { grid-area: list; display: flex; position: relative; }
#ws-maps.ws-map #panel-palette    { grid-area: palette; display: flex; position: relative; }
#ws-maps.ws-map #panel-map-canvas { grid-area: canvas; display: flex; }
#ws-maps.ws-map #panel-context    { grid-area: context; display: flex; position: relative; }
/* `#panel-passages` belongs here too. setWorkspace sets its `hidden`
   attribute, and `hidden` is only `display: none` until something says
   otherwise -- `.panel { display: flex }` does, so leaving the passage editor
   left its Property / Passage / Passage (4 dir) panel sitting in the map
   layout. The other two were already hidden this way; this one was relying on
   an attribute that cannot win. */
#ws-maps.ws-map #panel-blocks,
#ws-maps.ws-map #panel-passages,
#ws-maps.ws-map #panel-catalog    { display: none !important; }

/* The art-assignment workspace: unchanged, and deliberately plain. */
#ws-maps.ws-art #main {
  grid-template-columns: 1fr 1fr;
}

#ws-maps.ws-art #panel-maps-list,
#ws-maps.ws-art #panel-palette,
#ws-maps.ws-art #panel-map-canvas,
#ws-maps.ws-art #panel-context { display: none !important; }

#ws-maps.ws-art #panel-blocks,
#ws-maps.ws-art #panel-catalog { display: flex; }

#ws-maps.ws-art #panel-blocks,
#ws-maps.ws-art #panel-catalog { display: flex; }

#ws-maps.ws-passages #main {
  grid-template-columns: minmax(0, 1fr);
  grid-template-areas: "passages";
}

#ws-maps.ws-passages #panel-passages { grid-area: passages; display: flex; }
#ws-maps.ws-passages #panel-maps-list,
#ws-maps.ws-passages #panel-palette,
#ws-maps.ws-passages #panel-map-canvas,
#ws-maps.ws-passages #panel-context,
#ws-maps.ws-passages #panel-blocks,
#ws-maps.ws-passages #panel-catalog { display: none !important; }

.passage-editor-host {
  flex: 1;
  min-height: 0;
  display: flex;
}

.passage-editor-layout {
  display: flex;
  flex: 1;
  min-height: 0;
  width: 100%;
}

.passage-editor-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.passage-editor-head {
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.passage-editor-head h2 {
  margin: 0;
  font-size: 13px;
  font-weight: 600;
}

.passage-sheet-scroll {
  flex: 1;
  min-height: 0;
}

.passage-sheet-wrap {
  position: relative;
  image-rendering: pixelated;
}

.passage-sheet-wrap canvas.passage-sheet-art,
.passage-sheet-wrap canvas.passage-sheet-overlay {
  position: absolute;
  left: 0;
  top: 0;
  image-rendering: pixelated;
}

.passage-sheet-wrap canvas.passage-sheet-overlay {
  pointer-events: none;
}

.passage-tile-tip {
  position: absolute;
  left: 4px;
  bottom: 4px;
  background: rgba(0, 0, 0, 0.55);
  padding: 2px 6px;
  border-radius: 4px;
}

.passage-mode-panel {
  width: 148px;
  border-left: 1px solid var(--border);
  padding: 12px 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: var(--panel);
}

.passage-mode-title {
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.passage-mode-btn {
  width: 100%;
  text-align: left;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--panel2);
  color: var(--text);
  cursor: pointer;
}

.passage-mode-btn.active {
  border-color: #6eb5ff;
  background: rgba(110, 181, 255, 0.12);
}

.passage-mode-note {
  font-size: 11px;
  line-height: 1.35;
}

.panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
  border-right: 1px solid var(--border);
}

.panel:last-child { border-right: none; }

.panel-head {
  padding: 10px 12px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.panel-head h2 {
  margin: 0;
  font-size: 13px;
  font-weight: 600;
}

.panel-head input[type="search"] { flex: 1; min-width: 140px; }

.scroll {
  overflow: auto;
  padding: 10px;
  flex: 1;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(108px, 1fr));
  gap: 8px;
}

.card {
  background: var(--panel2);
  border: 2px solid transparent;
  border-radius: 8px;
  padding: 8px;
  cursor: pointer;
  transition: border-color 0.12s;
}

.card:hover { border-color: var(--border); }
.card.selected { border-color: var(--accent); }
.card.warn { outline: 1px solid var(--warn); }

.card img {
  width: 64px;
  height: 64px;
  image-rendering: pixelated;
  display: block;
  margin: 0 auto;
  background: #0e1118;
}

.card .name {
  font-size: 11px;
  font-weight: 600;
  margin-top: 6px;
  word-break: break-all;
}

.card .meta {
  font-size: 10px;
  color: var(--muted);
  word-break: break-all;
}

/* `#selection` is a span inside the status bar now, not a strip of its own.
   It used to sit between the header and the canvas with a reserved height,
   because anything that changed height there moved the canvas under the
   cursor mid-drag. Down in the bar it cannot do that at all. */


/* A run of buttons that belong together.
 *
 * Tight inside, a rule and a wider gap between: the separation is the whole
 * message, because these bars are otherwise a single row of small identical
 * buttons and nothing says which of them are the same kind of thing.
 */
.bar-group {
  display: flex;
  align-items: center;
  gap: 4px;
}

.bar-group + .bar-group,
#paint-bar > .bar-group,
#view-bar > .bar-group + .bar-group {
  margin-left: 10px;
  padding-left: 10px;
  border-left: 1px solid var(--border);
}

.bar-group[hidden] { display: none; }

/* The active mode, layer and tool, said by aria-pressed rather than by a class
   alone -- the state has to be readable by something other than a colour.
   Stronger than the old `.active`, because "which mode am I in" is the first
   question the toolbar has to answer. */
#paint-bar .tool[aria-pressed="true"],
#view-bar .tool.active,
#paint-bar .tool.active {
  color: var(--text);
  background: rgba(50, 168, 255, 0.20);
  border-color: rgba(86, 199, 255, 0.72);
  box-shadow:
    0 0 0 1px rgba(50, 168, 255, 0.10) inset,
    0 0 12px rgba(50, 168, 255, 0.10);
}

.overlays-group { position: relative; display: inline-flex; }

/* Icons sit on the text baseline and take the button's colour, so a disabled
   control's icon greys out with its label and nothing has to be told. */
.tool .smce-icon,
button .smce-icon {
  vertical-align: -3px;
  margin-right: 6px;
}

/* Icon-only controls have no label to sit beside. Their accessible name comes
   from aria-label, which `decorate` moves the text into rather than dropping. */
.is-icon-only .smce-icon { margin-right: 0; }

/* A map row is an icon and two lines: what kind of place it is, its name, and
   its id and size beneath. */
.map-item {
  display: flex;
  align-items: center;
  gap: 8px;
}

.map-item .rows { min-width: 0; flex: 1 1 auto; }

.map-item .smce-icon--domain {
  flex: 0 0 auto;
  /* Whole pixels only: a pixel icon scaled to a fraction is mush. */
  image-rendering: pixelated;
}

.tool.is-icon-only,
button.is-icon-only {
  /* The spec's 30x30 minimum hit area, which a bare 17px glyph would miss. */
  min-width: 30px;
  padding-left: 6px;
  padding-right: 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* Overlay rows are checkboxes, not commands: they line up down the popover
   and keep it open so several can be turned on at once. */
#overlays-menu .overlay-item {
  display: block;
  width: 100%;
  text-align: left;
}

#view-bar > .bar-group:first-child { margin-left: 0; padding-left: 0; border-left: 0; }

.slot-pills { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }

.pill {
  padding: 4px 8px;
  border-radius: 999px;
  background: var(--panel2);
  border: 1px solid var(--border);
  font-size: 11px;
  cursor: pointer;
}

.pill.active { border-color: var(--accent); background: #243048; }

.catalog .card.pickable:hover { border-color: var(--ok); }

#toast {
  position: fixed;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  background: #243048;
  border: 1px solid var(--border);
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
  z-index: 10;
}

#toast.show { opacity: 1; }

.muted-label {
  font-size: 11px;
  color: var(--muted);
}

#object-budget.warn { color: var(--warn); font-weight: 600; }

.map-list .map-item {
  display: block;
  width: calc(100% - (var(--map-depth, 0) * 14px));
  margin-left: calc(var(--map-depth, 0) * 14px);
  text-align: left;
  margin-bottom: 6px;
  padding: 8px 10px;
  background: var(--panel2);
  border: 2px solid transparent;
  border-radius: 8px;
  cursor: pointer;
}

.map-tree-group {
  margin: 10px 4px 5px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.map-tree-group:first-child { margin-top: 4px; }
.map-tree-group.warning { color: var(--warn); }

.map-list .map-item[data-depth]:not([data-depth="0"]) {
  border-left-color: color-mix(in srgb, var(--accent) 35%, transparent);
}

.map-list .map-item:hover { border-color: var(--border); }
.map-list .map-item.selected { border-color: var(--accent); }

.map-list .map-item .name {
  font-size: 12px;
  font-weight: 600;
}

.map-list .map-item .meta {
  font-size: 10px;
  color: var(--muted);
  margin-top: 2px;
}

/* A world is a set of maps you can walk between. Two exist: the hand-authored
   region and the generated one, which were listed together as though they were
   one place. */
.world-section + .world-section { margin-top: 10px; }

.world-head {
  display: flex;
  align-items: baseline;
  justify-content: flex-start;
  gap: 6px;
  width: 100%;
  padding: 8px 4px 4px;
  border: none;
  border-bottom: 1px solid var(--border);
  margin-bottom: 6px;
  background: transparent;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.world-head:hover { color: var(--accent); }
.world-head .chevron {
  flex: 0 0 auto;
  font-size: 10px;
  color: var(--muted);
  transition: transform 0.12s;
}
.world-head.collapsed .chevron { transform: rotate(-90deg); }
.world-head .label { flex: 1; font-size: 11px; font-weight: 700; letter-spacing: 0.03em; }
.world-head .count { font-size: 10px; color: var(--muted); white-space: nowrap; }

.world-body.collapsed { display: none; }

/* The generated world is shown to be looked at, not drawn on. */
.world-head.generated .label { color: var(--muted); font-weight: 600; }
.map-list .map-item.generated .name { color: var(--muted); }

.map-resize-dialog {
  padding: 8px 12px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}

.map-resize-form {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.map-resize-form label {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  color: var(--muted);
}

.map-resize-form input[type="number"] {
  width: 4.5em;
}

/* The canvas and the room around it.
 *
 * `safe center` rather than `center`: a map larger than the box overflows *both*
 * ways when centred, and the top-left of it -- where every map starts, and
 * where the scroll position begins -- becomes unreachable. `safe` falls back to
 * start-alignment exactly when that would happen, so a small map sits in the
 * middle and a large one stays scrollable.
 *
 * The dead space is a shade off the map's own background. They were the same
 * colour, so a map with dark edges had no visible boundary and the canvas
 * appeared to extend to the panel. */
.map-canvas-wrap {
  display: flex;
  justify-content: safe center;
  align-items: safe center;
  background: var(--canvas-void, #15181f);
  padding: 12px;
}

/* Four canvases stacked in one box. The map layers hold the picture at its
   native 16px per cell and are stretched here; `pixelated` makes that identical
   to the NEAREST upscale the server used to do, which is why zoom is free. */
#map-canvas-host {
  position: relative;
  display: inline-block;
  /* Darker than the space around it, so the map reads as an object sitting in
     a room rather than as the room itself. */
  background: #0e1118;
  flex: 0 0 auto;
  border: 1px solid var(--border);
  border-radius: 4px;
  transition: opacity 0.15s;
}

#map-canvas-host canvas {
  position: absolute;
  inset: 0;
  image-rendering: pixelated;
  /* Only the topmost layer takes the pointer; the rest would swallow it. */
  pointer-events: none;
}

#map-canvas-host #layer-terrain { z-index: 0; }
#map-canvas-host #layer-objects { z-index: 1; transition: opacity 0.12s; }
#map-canvas-host #layer-grid    { z-index: 2; }

/* Scoped to the host so it outweighs the `#map-canvas-host canvas` rule above.
   Written as a bare `#layer-overlay` it lost on specificity — id+element beats
   id alone — and the whole map went deaf to the mouse. */
#map-canvas-host #layer-overlay {
  z-index: 3;
  pointer-events: auto;
  cursor: crosshair;
}

#map-tooltip {
  position: fixed;
  pointer-events: none;
  background: #243048;
  border: 1px solid var(--border);
  padding: 4px 8px;
  border-radius: 6px;
  font-size: 11px;
  z-index: 5;
  white-space: nowrap;
}

@media (max-width: 900px) {
  body.mode-blocks main { grid-template-columns: 1fr; grid-template-rows: 1fr 1fr; }
  body.mode-maps main { grid-template-columns: 1fr; grid-template-rows: auto 1fr 1fr; }
}

/* --- autotile families ---------------------------------------------------
   A family card stands for 47 tiles, so it is marked out from the single
   blocks beside it rather than looking like one more of them. */
.card.family {
  border-color: #4a6fa5;
  background: linear-gradient(180deg, rgba(74, 111, 165, 0.16), transparent 60%);
}

.card.family.selected {
  border-color: #6eb5ff;
}

/* The whole family, read-only: which sprite each mask got. Useful for
   answering "why does that corner look wrong", not for clicking. */
.variant-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 2px;
  margin-top: 8px;
  max-height: 84px;
  overflow-y: auto;
}

.variant-strip .variant {
  width: 24px;
  height: 24px;
  image-rendering: pixelated;
  border: 1px solid var(--border);
  background: #1b1f27;
}

/* --- objects -------------------------------------------------------------
   The object tab: pick a sheet on the left, drag a rectangle out of it on the
   right. A building is one picture that happens to be stored as cells, so it
   is chosen as a region rather than a cell at a time. */
body.mode-objects #panel-blocks,
body.mode-objects #panel-catalog,
body.mode-objects #panel-maps-list,
body.mode-objects #panel-map-canvas { display: none !important; }

body.mode-objects .obj-panel { display: flex; }

#object-sheet-host {
  position: relative;
  display: inline-block;
  background:
    repeating-conic-gradient(#22262e 0% 25%, #1b1f27 0% 50%) 50% / 16px 16px;
}

#object-sheet-canvas {
  display: block;
  image-rendering: pixelated;
  cursor: crosshair;
}

.stamp-form {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-top: 8px;
  flex-wrap: wrap;
}

.stamp-form label { display: flex; gap: 4px; align-items: center; }


/* --- placed object stamps ------------------------------------------------ */

.placed-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  text-align: left;
  /* The row must not push the panel wider than its column: a sheet path is
     long enough to shove the Remove button off the edge, which makes the one
     control on the row unreachable. */
  min-width: 0;
}

.placed-row > div { min-width: 0; }

.placed-row .name,
.placed-row .meta {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.placed-row .name { font-size: 12px; }

#placed-count { white-space: nowrap; }

button.danger {
  flex: none;
  padding: 3px 8px;
  font-size: 11px;
  color: #ffd7d7;
  background: #4a2530;
  border: 1px solid #7a3a45;
  border-radius: 4px;
  cursor: pointer;
}

button.danger:hover { background: #63303c; }

.panel-note {
  padding: 4px 10px 8px;
  font-size: 11px;
  color: var(--muted);
  border-bottom: 1px solid var(--line);
}


/* --- terrain painting ----------------------------------------------------- */

#paint-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  min-height: 34px;
}

#paint-bar .tool {
  padding: 3px 10px;
  font-size: 11px;
  color: var(--fg);
  background: #262b35;
  border: 1px solid var(--line);
  border-radius: 4px;
  cursor: pointer;
}

#paint-bar .tool.active { background: #2d5c8a; border-color: #4d86bd; }
#paint-bar .tool:disabled { opacity: 0.4; cursor: default; }

.paint-status { margin-left: auto; font-size: 11px; color: var(--muted); }

/* Zoom, grid and object visibility — what you look at the map *with*, as
   opposed to what you draw on it with, which is why it is its own bar. */
#view-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}

/* The popover is a child of this bar. Horizontal scrolling clipped it at the
   bar's bottom edge, making it look as if the map canvas was drawn over it. */
#ws-maps #view-bar {
  position: relative;
  z-index: 20;
  overflow: visible;
}

#overlays-menu { z-index: 80; }

#view-bar .tool {
  padding: 3px 9px;
  font-size: 11px;
  color: var(--text);
  background: #262b35;
  border: 1px solid var(--border);
  border-radius: 4px;
  cursor: pointer;
}

#view-bar .tool.active { background: #2d5c8a; border-color: #4d86bd; }
#view-bar #btn-objects { margin-left: auto; }

/* The terrain palette: tiles, packed, no captions — the way RPG Maker's is.
   A caption under every swatch triples the height of the column and repeats
   what the picture already says, so the name lives on hover instead. */
#paint-palette { display: block; }

.swatch-row {
  display: flex;
  flex-wrap: wrap;
  gap: 2px;
}

/* Autotiles keep the top rows, in a band of their own. An autotile is a whole
   group that behaves differently when drawn with, and it is what you reach for
   most; mixed in alphabetically it read as one more lone rock. */
.swatch-row.autotiles {
  padding-bottom: 6px;
  margin-bottom: 6px;
  border-bottom: 1px solid var(--border);
}

.swatch {
  width: 34px;
  height: 34px;
  padding: 0;
  border: 2px solid transparent;
  border-radius: 3px;
  background: #0e1118;
  cursor: pointer;
  line-height: 0;
}

.swatch img {
  width: 30px;
  height: 30px;
  image-rendering: pixelated;
  display: block;
}

.swatch:hover { border-color: var(--border); }
.swatch.selected { border-color: var(--accent); }

/* Marked as a group without a caption saying so. */
.swatch-row.autotiles .swatch { box-shadow: inset 0 0 0 1px rgba(110, 181, 255, 0.35); }


/* --- the palette column --------------------------------------------------- */

#palette-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 3px;
  padding: 6px 8px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}

#palette-tabs .ptab {
  padding: 3px 9px;
  font-size: 11px;
  color: var(--text);
  background: #262b35;
  border: 1px solid var(--border);
  border-radius: 4px;
  cursor: pointer;
}

#palette-tabs .ptab.active { background: #2d5c8a; border-color: #4d86bd; }

#palette-sub {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 5px 8px;
  border-bottom: 1px solid var(--border);
}

/* An explicit `display` beats the `hidden` attribute, so every element in the
   palette that switches between the two contents has to say it again. */
#palette-recent {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 4px;
  padding: 6px 8px;
  background: #171c26;
  border-bottom: 1px solid var(--border);
}

#palette-recent .recent {
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 3px;
  background-color: #0e1118;
  background-repeat: no-repeat;
  image-rendering: pixelated;
  cursor: pointer;
}

#palette-recent .recent:hover { border-color: var(--accent); }

#palette-recent[hidden],
#palette-sub[hidden],
#palette-sheet[hidden],
#paint-palette[hidden],
#prefab-palette[hidden],
#palette-sheet-host[hidden] { display: none; }

/* A prefab shows the thing itself, cropped out of its own sheet — a house
   should look like the house about to be placed, not like a name in a list.
   Which is also why there is no name: the picture is the label. */
#prefab-palette {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 4px;
}

#prefab-palette .prefab {
  padding: 2px;
  border: 2px solid transparent;
  border-radius: 3px;
  background: #0e1118;
  cursor: pointer;
  line-height: 0;
}

#prefab-palette .prefab:hover { border-color: var(--border); }
#prefab-palette .prefab.selected { border-color: var(--accent); }

#prefab-palette .prefab-art {
  image-rendering: pixelated;
  background-repeat: no-repeat;
  background-color: transparent;
}

#palette-sub select { flex: 1; min-width: 0; font-size: 11px; padding: 3px 6px; }

#palette-sub .tool {
  padding: 2px 7px;
  font-size: 11px;
  color: var(--text);
  background: #262b35;
  border: 1px solid var(--border);
  border-radius: 4px;
  cursor: pointer;
}

#palette-sub .tool.active { background: #2d5c8a; border-color: #4d86bd; }

/* A sheet is up to 40 cells across, so it scrolls both ways rather than being
   reflowed — reflowing would cut multi-cell furniture apart, and dragging a
   rectangle across a picture is the entire gesture. */
#palette-sheet-host {
  display: inline-block;
  background: repeating-conic-gradient(#22262e 0% 25%, #1b1f27 0% 50%) 50% / 16px 16px;
}

#object-sheet-canvas { display: block; image-rendering: pixelated; cursor: crosshair; }

/* The separator between two columns.
 *
 * Straddling the boundary rather than sitting inside one panel: a 6px target
 * is small enough already, and half of it on each side is what makes the
 * cursor change where the eye expects the edge to be. The panels it separates
 * need `position: relative` for that, which the grid areas already set. */
.dock-resize {
  position: absolute;
  top: 0;
  right: -3px;
  width: 6px;
  height: 100%;
  cursor: col-resize;
  z-index: 4;
}

.dock-resize--left { right: auto; left: -3px; }

.dock-resize:hover,
.dock-resize:focus-visible {
  background: var(--accent);
  opacity: 0.4;
}

/* Focusable, so it needs to be visible when focused -- the outline is the only
   thing that says a keyboard is now driving this control. */
.dock-resize:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }

body.resizing { cursor: col-resize; user-select: none; }

/* Context rail: form scrolls; stamp options stay pinned below when armed. */
#panel-context {
  flex-direction: column;
}
#context-form-host {
  flex: 1;
  min-height: 0;
}

#stamp-form-host:not(:empty) {
  padding: 8px 10px;
  border-top: 1px solid var(--border);
  background: #182030;
  font-size: 12px;
}

#stamp-form-host .stamp-form { flex-direction: column; align-items: flex-start; gap: 6px; }

/* `hidden` has to beat the display below, and only here.
 *
 * The attribute is `display: none` from the user-agent stylesheet alone, so any
 * rule giving an element a display wins -- which is why this form sat
 * permanently in the inspector taking 175px between the map's music and its
 * battleback, the "operation filed among properties" the audit called out and
 * the code claimed to have fixed. The element said `hidden`; the stylesheet
 * said `flex`; the stylesheet won.
 *
 * Scoped rather than global. A blanket `[hidden] { display: none !important }`
 * looks like the obvious fix and takes the editor apart: the workspace
 * switcher marks every panel `hidden` in the markup and *relies* on its own
 * display rules to reveal the ones the current workspace uses, so the blanket
 * version hides the canvas, the map list and the palette along with this. */
.map-shift-form[hidden] { display: none; }

.map-shift-form {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.map-shift-row {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 10px;
}

.map-shift-row label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 11px;
  color: var(--muted);
}

.map-shift-row input[type="number"] {
  width: 72px;
}

.rmxp-layer-tabs {
  display: flex;
  gap: 4px;
  /* The first group in the bar: what you are editing. Separated from the
     tools that follow it by the same rule every other group uses. */
  margin-right: 10px;
  padding-right: 10px;
  border-right: 1px solid var(--border);
  flex-wrap: wrap;
  margin-right: 8px;
}

.rmxp-layer-tabs .tool,
.rmxp-layer-tabs .ptab {
  font-size: 11px;
  padding: 4px 8px;
}

.rmxp-tileset-host {
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 0;
}

.rmxp-pick-row {
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 8px 6px 4px;
  border-bottom: 1px solid var(--border);
}

#rmxp-pick-preview {
  /* Half what it was. A 32px tile shown at 96px is three times its own size
     and took a quarter of the panel's height; the sheet below is what the
     panel is for. Still 2x, so a 32px tile stays legible. */
  width: 48px;
  height: 48px;
  image-rendering: pixelated;
  border: 1px solid var(--border);
  background: #10141c;
  flex-shrink: 0;
}

.rmxp-pick-meta {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
}

.rmxp-pick-label {
  font-size: 13px;
  font-weight: 600;
}

.rmxp-sheet-zoom {
  display: flex;
  gap: 4px;
  align-items: center;
  flex-wrap: wrap;
}

.rmxp-sheet-wrap {
  position: relative;
  display: block;
  flex-shrink: 0;
}

.rmxp-sheet-wrap canvas.rmxp-sheet-art {
  display: block;
  image-rendering: pixelated;
  cursor: crosshair;
  border: 1px solid var(--border);
}

.rmxp-sheet-wrap canvas.rmxp-sheet-overlay {
  position: absolute;
  left: 0;
  top: 0;
  pointer-events: none;
  image-rendering: pixelated;
}

.rmxp-tile-tip {
  margin-top: 4px;
  font-size: 11px;
}

.marker-tools {
  display: inline-flex;
  gap: 4px;
  /* Shown only under the Events tab, where it stands in for the paint tools,
     so it sits in the same place with the same separation. */
  margin-left: 10px;
  padding-left: 10px;
  border-left: 1px solid var(--border);
  margin-left: 8px;
  padding-left: 8px;
  border-left: 1px solid var(--border);
}

/* Warp destination picker (map list + preview). */
.warp-dest-dialog {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(8, 10, 14, 0.72);
  padding: 24px;
}

.warp-dest-panel {
  display: flex;
  flex-direction: column;
  width: min(1100px, 96vw);
  height: min(720px, 90vh);
  background: var(--panel, #151922);
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
  overflow: hidden;
}

.warp-dest-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.warp-dest-head h2 {
  margin: 0;
  font-size: 15px;
}

.warp-dest-status {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.warp-dest-body {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 240px minmax(0, 1fr);
}

.warp-dest-list {
  border-right: 1px solid var(--border);
  padding: 6px;
}

.warp-dest-map-item {
  display: block;
  width: 100%;
  text-align: left;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 4px;
  color: inherit;
  padding: 6px 8px;
  margin-bottom: 2px;
  cursor: pointer;
}

.warp-dest-map-item:hover {
  background: rgba(110, 181, 255, 0.08);
}

.warp-dest-map-item.active {
  border-color: rgba(110, 181, 255, 0.55);
  background: rgba(110, 181, 255, 0.14);
}

.warp-dest-preview-wrap {
  padding: 12px;
  background: #0e1118;
}

.warp-dest-preview-host {
  position: relative;
  display: inline-block;
  line-height: 0;
  border: 1px solid var(--border);
  background: #0a0c10;
}

.warp-dest-img {
  display: block;
  image-rendering: pixelated;
  max-width: none;
}

.warp-dest-overlay {
  position: absolute;
  left: 0;
  top: 0;
  cursor: crosshair;
  image-rendering: pixelated;
}
