#worldmap-stage {
.worldmap {
  display: flex;
  flex-direction: column;
  height: 100%;
  width: 100%;
  min-height: 0;
}

/* Top control bar — mirrors .skills-bar (flex row, ink border-bottom). */
.worldmap-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  border-bottom: 2px solid var(--ink);
  background: var(--paper-2);
  flex-wrap: wrap;
}

.worldmap-title {
  font-family: var(--font-sans);
  font-weight: 600;
  color: var(--ink);
}
.worldmap-title small {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: .04em;
  color: var(--ink-muted);
}

/* Seed field — mirrors .classes-field (mono uppercase label + ink-bordered input). */
.worldmap-seed {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--ink-muted);
}
.worldmap-seed input {
  width: 84px;
  padding: 5px 6px;
  border: 1.5px solid var(--ink);
  background: var(--paper);
  font-family: var(--font-mono);
  font-size: 12px;
  letter-spacing: 0;
  color: var(--ink);
}

/* Buttons — mirror .classes-attack-btn (ink fill, mono uppercase). */
.worldmap-btn {
  padding: 6px 12px;
  border: 1.5px solid var(--ink);
  background: var(--ink);
  color: var(--paper);
  cursor: pointer;
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: .1em;
  text-transform: uppercase;
}
.worldmap-btn:hover:not(:disabled) { background: var(--ink-2); }
.worldmap-btn:disabled { opacity: .45; cursor: default; }

.worldmap-meta {
  margin-left: auto;
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--ink-muted);
}

/* Legend — chips mirror .classes-fx-chip, with a per-biome colour swatch. */
.worldmap-legend {
  display: flex;
  gap: 6px;
  padding: 8px 16px;
  flex-wrap: wrap;
  border-bottom: 1px solid var(--ink-faint);
  background: var(--paper);
}
.worldmap-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: .06em;
  text-transform: uppercase;
  padding: 2px 8px;
  border: 1.5px solid var(--ink);
  background: var(--paper);
  color: var(--ink);
}
.worldmap-chip::before {
  content: '';
  width: 9px;
  height: 9px;
  border: 1px solid var(--ink);
  background: var(--sw, #888);
}
/* Swatches roughly match the tile fills. */
.biome-0 { --sw: #4772d1; } /* water */
.biome-1 { --sw: #cdb98a; } /* beach (sand) */
.biome-2 { --sw: #6fa430; } /* grass */
.biome-3 { --sw: #3f6f2a; } /* forest */
.biome-4 { --sw: #7a4a1e; } /* hills/dirt */
.biome-5 { --sw: #737373; } /* mountain */
.biome-6 { --sw: #4f8fd1; } /* river */

.worldmap-host {
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  background: var(--ink);
}
.worldmap-host canvas { display: block; }

/* ── Map sandbox shell: header + top-right pills (mirrors .battle-header) ──── */
.mapsandbox { display: flex; flex-direction: column; height: 100%; width: 100%; min-height: 0; }
.mapsandbox-header {
  display: flex; align-items: center; gap: 14px;
  padding: 12px 20px; border-bottom: 2px solid var(--ink); background: var(--paper);
}
.mapsandbox-header h1 {
  margin: 0; font-family: var(--font-display); font-weight: 800;
  font-size: 24px; letter-spacing: -.015em;
}
.mapsandbox-pills { margin-left: auto; display: flex; gap: 0; }
.mapsandbox-pills button {
  padding: 5px 14px; border: 1.5px solid var(--ink); background: var(--paper);
  color: var(--ink); cursor: pointer; font-family: var(--font-sans);
  font-weight: 600; font-size: 12px;
}
.mapsandbox-pills button:first-child { border-radius: 4px 0 0 4px; }
.mapsandbox-pills button:last-child { border-radius: 0 4px 4px 0; border-left: none; }
.mapsandbox-pills button.active { background: var(--ink); color: var(--paper); }
/* Sub-pill row (revealed under a group pill, e.g. Biome → its biome sandboxes). Left-aligned,
   full-width, with its own separator below the header. */
.mapsandbox-subpills {
  margin-left: 0; padding: 8px 20px; gap: 0;
  border-bottom: 2px solid var(--ink); background: var(--paper);
}
.mapsandbox-body { flex: 1 1 auto; min-height: 0; display: flex; }
.mapsandbox-body > * { flex: 1 1 auto; min-height: 0; }

/* Mobile: let the subpage pills drop to their own full-width row and scroll
   horizontally, so every pill (incl. the last one) stays reachable when the
   header is too narrow to fit them all on one line. */
@media (max-width: 720px) {
  .mapsandbox-header { flex-wrap: wrap; gap: 8px; padding: 10px 12px; }
  .mapsandbox-header h1 { font-size: 20px; }
  .mapsandbox-pills {
    margin-left: 0; width: 100%; max-width: 100%;
    overflow-x: auto; -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
  }
  .mapsandbox-pills button { flex: 0 0 auto; padding: 7px 14px; font-size: 13px; }
}

/* ── Necropolis layer toggles — chips, coloured by build-up group ──────────── */
.necro { display: flex; flex-direction: column; height: 100%; width: 100%; min-height: 0; }
.necro-layers {
  display: flex; gap: 6px; padding: 8px 16px; flex-wrap: wrap;
  border-bottom: 1px solid var(--ink-faint); background: var(--paper);
}
.necro-chip {
  display: inline-flex; align-items: center; gap: 6px;
  font-family: var(--font-mono); font-size: 10px; letter-spacing: .06em;
  text-transform: uppercase; padding: 3px 8px;
  border: 1.5px solid var(--ink); background: var(--paper); color: var(--ink-muted);
  cursor: pointer; opacity: .55;
}
.necro-chip.on { opacity: 1; color: var(--ink); }
.necro-chip input { accent-color: var(--ink); margin: 0; }
.necro-chip::after {
  content: ''; width: 8px; height: 8px; border: 1px solid var(--ink); background: var(--g, #888);
}
.necro-chip.group-ground { --g: #6b6f4a; }
.necro-chip.group-paths { --g: #b09a6a; }
.necro-chip.group-structure { --g: #8a7d9c; }
.necro-chip.group-scatter { --g: #b8b09a; }
.necro-chip.group-lighting { --g: #5fd0d8; }

/* Generated grid + index overlay, and the Tilesheet view. */
.necro-grid-toggle {
  display: inline-flex; align-items: center; gap: 6px;
  font-family: var(--font-mono); font-size: 10px; letter-spacing: .08em;
  text-transform: uppercase; color: var(--ink-muted);
}
.necro-stage { position: relative; flex: 1 1 auto; min-height: 0; display: flex; }
.necro-stage > .worldmap-host { flex: 1 1 auto; min-height: 0; }
.necro-grid-overlay { position: absolute; inset: 0; pointer-events: none; }
/* On-screen zoom buttons (also gives touch users zoom; wheel/pinch work too). */
.necro-zoom { position: absolute; right: 12px; bottom: 12px; display: flex; flex-direction: column; gap: 4px; }
.necro-zoom button {
  width: 32px; height: 32px; border: 1.5px solid var(--ink); background: var(--paper);
  color: var(--ink); font-size: 20px; line-height: 1; font-family: var(--font-mono);
  cursor: pointer; border-radius: 4px; padding: 0; display: flex; align-items: center; justify-content: center;
}
.necro-zoom button:hover { background: var(--paper-2); }
.necro-zoom button:active { background: var(--ink); color: var(--paper); }
/* Tilesheet view: a fixed selector bar on top + a scrollable sheet body below.
   min-width:0 keeps the flex item from expanding to the wide sheet so the inner
   scroll area handles BOTH axes. */
.necro-tilesheet { flex: 1 1 auto; min-height: 0; min-width: 0; display: flex; flex-direction: column; }
.necro-sheet-scroll { flex: 1 1 auto; min-height: 0; min-width: 0; overflow: auto; background: var(--ink); padding: 16px; }
/* Selector bar — mirrors the reference layer bar (.necro-layers); chip buttons reuse
   .necro-chip styling so the sheet picker matches the reference checkboxes. */
.necro-sheet-bar {
  display: flex; gap: 6px; padding: 8px 16px; flex-wrap: wrap; align-items: center;
  border-bottom: 1px solid var(--ink-faint); background: var(--paper);
}
.necro-sheet-bar .necro-chip::after { content: none; } /* no colour swatch on sheet chips */
.necro-sheet-dims { margin-left: auto; font-family: var(--font-mono); font-size: 10px; letter-spacing: .06em; color: var(--ink-muted); }
/* Placeholder shown in tabs that aren't built yet (e.g. Orc Kingdom → Generated). */
.necro-coming-soon {
  flex: 1 1 auto; display: flex; align-items: center; justify-content: center;
  background: var(--ink); color: var(--paper); opacity: .6;
  font-family: var(--font-mono); font-size: 13px; letter-spacing: .04em;
}
.necro-sheet-stage { position: relative; }
.necro-sheet-img { image-rendering: pixelated; image-rendering: crisp-edges; display: block; }
.necro-sheet-grid { position: absolute; top: 0; left: 0; pointer-events: none; }

/* Tilesheet body: the scrollable sheet + an optional prop catalogue sidebar to its right. */
.tilesheet-main { flex: 1 1 auto; min-height: 0; min-width: 0; display: flex; }
.tilesheet-catalog {
  flex: 0 0 252px; min-height: 0; overflow-y: auto;
  border-left: 2px solid var(--ink); background: var(--paper);
  font-family: var(--font-sans); font-size: 12px;
}
.tcat-head {
  position: sticky; top: 0; z-index: 1; padding: 9px 12px;
  background: var(--ink); color: var(--paper);
  font-weight: 700; font-size: 11px; letter-spacing: .03em;
}
.tcat-item {
  display: flex; gap: 10px; align-items: center;
  padding: 8px 12px; border-bottom: 1px solid var(--ink-faint);
  cursor: pointer;
}
.tcat-item:hover { background: var(--paper-2, rgba(0,0,0,.04)); }
.tcat-item.is-selected { background: rgba(255, 208, 0, .22); box-shadow: inset 3px 0 0 #ffd000; }
.tcat-item.is-unused { opacity: .55; }
.tcat-thumbwrap {
  flex: 0 0 56px; height: 56px; display: flex; align-items: center; justify-content: center;
  background: repeating-conic-gradient(#cfc5b0 0% 25%, #ded6c4 0% 50%) 50% / 12px 12px;
  border: 1px solid var(--ink-faint); border-radius: 3px;
}
.tcat-thumb { flex: 0 0 auto; }
.tcat-thumb-ext {
  width: 40px; height: 40px; display: flex; align-items: center; justify-content: center;
  font-size: 20px; color: var(--ink-muted); border: 1px dashed var(--ink-faint); border-radius: 3px;
}
.tcat-info { min-width: 0; }
.tcat-name { font-weight: 700; color: var(--ink); }
.tcat-meta { margin-top: 2px; font-family: var(--font-mono); font-size: 10px; color: var(--ink-muted); }
.tcat-badge {
  display: inline-block; padding: 0 5px; border-radius: 3px; font-weight: 700;
  font-size: 9px; letter-spacing: .04em; text-transform: uppercase;
}
.tcat-badge.on { background: #1f7a3d; color: #fff; }
.tcat-badge.off { background: #8a8175; color: #fff; }
.tcat-note { margin-top: 3px; color: var(--ink-muted); font-size: 11px; line-height: 1.3; }

/* Click-to-identify highlight on the sheet (in the grid SVG, which is pointer-events:none). The
   outline marks the selected entry's full frame; the tint marks its exact `used` generator cells. */
.necro-sheet-stage { cursor: crosshair; }
.tcat-hilite { fill: none; stroke: #ffd000; paint-order: stroke; }
.tcat-tint { fill: #ffd000; opacity: .18; }
}
