/* ========== Base ========== */
* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0; height: 100%;
  font-family: 'Inter', 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', 'Noto Sans SC', system-ui, -apple-system, sans-serif;
  font-size: 13.5px;
  color: #e2e8f0;
  background: #0c1220;
  user-select: none;
  -webkit-user-select: none;
  overflow: hidden;
}
button { font: inherit; color: inherit; cursor: pointer; border: none; }
input, select { font: inherit; }

/* ========== App Layout ========== */
.app {
  --left-w: 330px;
  --right-w: 230px;
  display: grid;
  grid-template-columns: var(--left-w) 8px minmax(0,1fr);
  height: 100vh;
  gap: 0;
  padding: 8px;
  background: linear-gradient(175deg, #11182a 0%, #0b1020 100%);
}

.sidebar, .main, .layers { display: flex; flex-direction: column; gap: 8px; min-width: 0; min-height: 0; overflow: hidden; }
.sidebar { padding-right: 2px; }
.layers { padding-left: 2px; }
.main { display: grid; grid-template-columns: minmax(0,1fr) 8px var(--right-w); grid-template-rows: minmax(0,1fr); gap: 0; min-height: 0; height: 100%; }
#centerPanel { padding: 0 2px; }

/* ========== Resizers ========== */
.resizer {
  position: relative;
  cursor: col-resize;
  background: transparent;
  z-index: 30;
  min-width: 8px;
  max-width: 8px;
  width: 8px;
  align-self: stretch;
}
.resizer::before {
  content: '';
  position: absolute;
  top: 0; bottom: 0;
  left: 2px; width: 4px;
  border-radius: 3px;
  background: #25304a;
  transition: background .15s;
}
.resizer::after {
  content: '';
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  width: 2px; height: 28px;
  border-radius: 2px;
  background: #4360a0;
  transition: background .15s;
}
.resizer:hover::before, .resizer.dragging::before { background: #5888ff; }
.resizer:hover::after, .resizer.dragging::after { background: #fff; }
.canvas-wrap { display: flex; flex-direction: column; gap: 8px; min-width: 0; min-height: 0; overflow: hidden; height: 100%; position: relative; }

.panel {
  background: #151d30;
  border: 1px solid #243050;
  border-radius: 10px;
  padding: 10px;
  box-shadow: 0 2px 8px rgba(0,0,0,.25);
}

/* ========== Map Config Panel ========== */
.map-config { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.map-type-wrap { display: flex; align-items: center; gap: 6px; flex: 1 1 140px; }
.map-type-swatch {
  width: 28px; height: 22px; border-radius: 5px;
  background: #2d8a3d; border: 1px solid #1f5e2a;
  flex: 0 0 28px;
}
.map-type-select {
  background: #0d1425; color: #cbd5e1; border: 1px solid #243050;
  border-radius: 6px; padding: 5px 8px; flex: 1; min-width: 0;
  transition: border-color .15s;
}
.map-type-select:focus { border-color: #5888ff; outline: none; }
.map-size { display: flex; align-items: center; gap: 6px; }
.map-size label { display: flex; align-items: center; gap: 4px; color: #94a3b8; font-size: 12px; }
.map-size .lbl-icon { color: #ff7a59; font-weight: 700; }
.map-size input {
  width: 44px; background: #0d1425; color: #cbd5e1;
  border: 1px solid #243050; border-radius: 6px; padding: 4px 6px; text-align: center;
  font-size: 12px; transition: border-color .15s;
}
.map-size input:focus { border-color: #5888ff; outline: none; }
.btn-apply-size {
  background: #2563eb; color: #fff; border: 1px solid #3b82f6;
  padding: 4px 12px; font-size: 12px; border-radius: 6px;
  font-weight: 500; transition: all .15s;
}
.btn-apply-size:hover { background: #3b82f6; transform: translateY(-1px); }

/* ========== File Action Buttons ========== */
.file-actions {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

/* File buttons — 2-col grid, responsive to 1-col on narrow sidebar */
.file-buttons {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 5px;
}

/* Save Map dropdown container */
.save-map-dropdown {
  position: relative;
  display: flex;
  min-width: 0;
}
.save-map-dropdown .btn-action {
  width: 100%;
}

/* Save JSON + Compress grouped inline */
.save-json-group {
  display: flex;
  border: 1px solid #243050;
  border-radius: 7px;
  overflow: hidden;
  gap: 0;
}
.save-json-group .btn-action {
  flex: 1;
  border: none;
  border-radius: 0;
  border-right: 1px solid #243050;
}
.save-json-group .btn-action:hover {
  border-right: 1px solid #344060;
}
.compress-label {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 7px 10px; font-size: 11.5px; white-space: nowrap;
  color: #94a3b8; cursor: pointer; transition: all .15s;
  background: #0d1425; min-width: 0; user-select: none;
}
.compress-label:hover { background: #1a2540; color: #fff; }
.compress-label input { margin: 0; cursor: pointer; accent-color: #5888ff; width: 14px; height: 14px; }

.dropdown-caret { font-size: 8px; margin-left: 1px; opacity: .6; }

/* Save map dropdown menu */
.dropdown-menu {
  display: none;
  position: absolute;
  top: calc(100% + 3px);
  left: 0;
  min-width: 190px;
  background: #0d1425;
  border: 1px solid #344060;
  border-radius: 8px;
  box-shadow: 0 6px 16px rgba(0,0,0,.45);
  z-index: 100;
  flex-direction: column;
  padding: 6px 0;
  overflow: hidden;
}
.dropdown-menu.open { display: flex; }
.dropdown-item {
  background: transparent; border: none; color: #cbd5e1;
  padding: 7px 14px; font-size: 12px; cursor: pointer;
  text-align: left; display: flex; align-items: center; gap: 8px;
  white-space: nowrap; transition: all .12s;
}
.dropdown-item:hover { background: #1a2540; color: #7ba8ff; }
.dropdown-item .item-icon { font-size: 14px; }

/* Base button */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 4px;
  background: #0d1425;
  color: #cbd5e1;
  border: 1px solid #243050;
  border-radius: 7px;
  padding: 7px 10px;
  font-size: 12px;
  font-weight: 500;
  transition: all .15s;
  white-space: nowrap;
  cursor: pointer;
  min-width: 0;
}
.btn:hover {
  background: #1a2540;
  border-color: #344060;
  color: #fff;
  transform: translateY(-1px);
}
.btn:active { transform: translateY(0); }
.btn.primary {
  background: #c2410c; color: #fff; border-color: #ea580c;
  font-weight: 600;
}
.btn.primary:hover { background: #ea580c; border-color: #f97316; }
.btn .btn-icon { font-size: 13px; line-height: 1; }

.btn-action {
  padding: 7px 8px; font-size: 11.5px;
}

/* Old btn-action-opt — kept for backward compatibility, hidden */
.btn-action-opt { display: none; }

/* ========== Tabs ========== */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid #243050; margin-bottom: 10px; }
.tab {
  background: transparent; border: none; color: #7b8ba8;
  padding: 8px 14px; font-size: 13px; border-radius: 8px 8px 0 0;
  position: relative; font-weight: 500;
  transition: color .15s, background .15s;
  cursor: pointer;
}
.tab:hover { color: #cbd5e1; background: rgba(255,255,255,.03); }
.tab.active { color: #7ba8ff; }
.tab.active::after {
  content: ''; position: absolute; left: 8px; right: 8px; bottom: -1px;
  height: 2px; background: #7ba8ff; border-radius: 2px;
}
.tab-icon { margin-left: 3px; font-size: 13px; }
.tab .check { color: #5888ff; margin-left: 2px; }
.tab .tab-check {
  color: #5888ff; margin-left: 2px; cursor: pointer;
  pointer-events: auto; user-select: none; -webkit-user-select: none;
  padding: 0 2px; border-radius: 3px;
  transition: background .12s;
}
.tab .tab-check:hover { background: rgba(88,136,255,0.15); }
.tab-content { min-height: 0; flex: 1; }
.tab-pane { display: none; height: 100%; flex-direction: column; }
.tab-pane.active { display: flex; }

/* ========== Tile Grid ========== */
.tile-categories {
  display: grid; grid-template-columns: repeat(8, 1fr);
  gap: 4px; padding-bottom: 6px; border-bottom: 1px solid #243050; margin-bottom: 6px;
}
.cat-tile {
  aspect-ratio: 1; background: #0d1425; border: 1px solid #243050;
  border-radius: 5px; display: flex; align-items: center; justify-content: center;
  cursor: pointer; padding: 0; transition: all .12s;
}
.cat-tile:hover { background: #1a2540; border-color: #344060; }
.cat-tile.active { border-color: #a78bfa; box-shadow: 0 0 0 1px #a78bfa inset; }
.cat-tile canvas { width: 100%; height: 100%; image-rendering: pixelated; }

.tile-grid {
  display: grid; grid-template-columns: repeat(6, 1fr);
  gap: 3px; overflow-y: auto; max-height: 60vh;
  padding: 2px;
}
.tile-cell {
  aspect-ratio: 1; background: #0d1425; border: 1px solid #243050;
  border-radius: 4px; cursor: pointer; padding: 1px;
  position: relative; transition: all .12s;
}
.tile-cell:hover { border-color: #5888ff; }
.tile-cell.selected { border-color: #a78bfa; box-shadow: 0 0 0 2px #a78bfa inset; }
.tile-cell canvas { width: 100%; height: 100%; image-rendering: pixelated; }

/* ========== Objects Panel ========== */
.objects-panel { display: flex; flex-direction: column; gap: 8px; }
.objects-header {
  display: flex; align-items: center; gap: 6px;
  padding-bottom: 6px; border-bottom: 1px solid #243050;
}
.objects-title { font-weight: 600; color: #cbd5e1; font-size: 12px; flex: 1; }
.btn-add-object {
  background: #2563eb; color: #fff; border: 1px solid #3b82f6;
  padding: 4px 10px; font-size: 11px; border-radius: 6px;
  font-weight: 500; transition: all .15s;
}
.btn-add-object:hover { background: #3b82f6; transform: translateY(-1px); }

/* Object type selector bar */
.object-type-bar {
  display: flex; align-items: center; gap: 6px; flex-wrap: wrap;
  padding: 7px 6px; background: #0d1425;
  border: 1px solid #243050; border-radius: 7px;
}
.object-type-label { font-size: 11px; color: #94a3b8; min-width: 64px; flex: 0 0 auto; }
.object-type-btns { display: flex; gap: 4px; flex: 1; min-width: 0; }
.obj-type-btn {
  flex: 1; min-width: 0;
  background: #0d1425; color: #cbd5e1;
  border: 1px solid #243050; border-radius: 6px;
  padding: 6px 5px; font-size: 11px; cursor: pointer;
  transition: all .15s; white-space: nowrap; font-weight: 500;
}
.obj-type-btn:hover { background: #1a2540; border-color: #344060; }
.obj-type-btn.active {
  background: #2563eb; color: #fff; border-color: #3b82f6;
  box-shadow: 0 0 0 1px rgba(88,136,255,.4);
}

/* Direction selector bar */
.direction-bar {
  display: flex; align-items: center; gap: 6px; flex-wrap: wrap;
  padding: 7px 6px; background: #0d1425;
  border: 1px solid #243050; border-radius: 7px;
}
.direction-label { font-size: 11px; color: #94a3b8; min-width: 64px; flex: 0 0 auto; }
.direction-btns { display: flex; gap: 4px; flex: 1; min-width: 0; }
.dir-btn {
  flex: 1; min-width: 0;
  background: #0d1425; color: #cbd5e1;
  border: 1px solid #243050; border-radius: 6px;
  padding: 6px 5px; font-size: 11px; cursor: pointer;
  transition: all .15s; white-space: nowrap; font-weight: 500;
}
.dir-btn:hover { background: #1a2540; border-color: #344060; }
.dir-btn.active {
  background: #c2410c; color: #fff; border-color: #ea580c;
  box-shadow: 0 0 0 1px rgba(249,115,22,.4);
}

.objects-list {
  display: flex; flex-direction: column; gap: 4px;
  overflow-y: auto; max-height: 55vh; padding: 2px;
}
.object-item {
  display: flex; align-items: center; gap: 6px;
  background: #0d1425; border: 1px solid #243050;
  border-radius: 6px; padding: 6px 8px; font-size: 12px;
  cursor: pointer; transition: all .15s;
}
.object-item:hover { background: #1a2540; border-color: #344060; }
.object-item.selected {
  border-color: #a78bfa; box-shadow: 0 0 0 1px #a78bfa inset;
  background: #181a30;
}
.object-item .obj-preview {
  width: 24px; height: 24px; flex: 0 0 24px;
  display: flex; align-items: center; justify-content: center;
}
.object-item .obj-preview canvas { width: 100%; height: 100%; }
.object-item .obj-name {
  flex: 1; min-width: 0; color: #cbd5e1;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.object-item .obj-name input {
  background: transparent; color: inherit; border: none; width: 100%;
  padding: 0; font-size: 12px;
}
.object-item .obj-name input:focus { outline: 1px dashed #5888ff; }
.object-item .obj-style-badge {
  font-size: 10px; padding: 2px 5px; border-radius: 4px;
  background: #1a2540; color: #94a3b8; border: 1px solid #243050;
}
.object-item .obj-edit, .object-item .obj-del {
  background: transparent; border: none; padding: 0 3px; font-size: 13px;
  color: #94a3b8; cursor: pointer; transition: color .12s;
}
.object-item .obj-edit:hover { color: #5888ff; }
.object-item .obj-del:hover { color: #f87171; }
.objects-empty {
  color: #64748b; font-size: 12px; text-align: center; padding: 14px 4px;
}

/* ========== Add/Edit Object Dialog ========== */
.obj-dialog-overlay {
  position: fixed; inset: 0; z-index: 2000;
  background: rgba(0,0,0,.55);
  display: flex; align-items: center; justify-content: center;
}
.obj-dialog {
  background: #151d30; border: 1px solid #344060; border-radius: 12px;
  padding: 18px; width: 350px; max-width: 90vw;
  box-shadow: 0 10px 40px rgba(0,0,0,.5);
  display: flex; flex-direction: column; gap: 14px;
}
.obj-dialog h3 { margin: 0; font-size: 15px; color: #cbd5e1; font-weight: 600; }
.obj-dialog .form-row { display: flex; flex-direction: column; gap: 4px; }
.obj-dialog .form-row label { font-size: 11px; color: #94a3b8; }
.obj-dialog .form-row input[type="text"] {
  background: #0d1425; color: #cbd5e1; border: 1px solid #243050;
  border-radius: 6px; padding: 7px 10px; font-size: 13px;
  transition: border-color .15s;
}
.obj-dialog .form-row input[type="text"]:focus { outline: none; border-color: #5888ff; }
.obj-dialog .style-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 7px; }
.obj-dialog .dialog-type-row { display: flex; gap: 6px; }
.obj-dialog .dialog-type-row .obj-type-btn { flex: 1; padding: 7px 5px; font-size: 12px; }
.obj-dialog .style-option {
  aspect-ratio: 1; background: #0d1425; border: 2px solid #243050;
  border-radius: 7px; cursor: pointer; padding: 5px;
  display: flex; align-items: center; justify-content: center;
  transition: all .15s;
}
.obj-dialog .style-option:hover { border-color: #344060; background: #1a2540; }
.obj-dialog .style-option.selected { border-color: #a78bfa; box-shadow: 0 0 0 1px #a78bfa; }
.obj-dialog .style-option canvas { width: 100%; height: 100%; }
.obj-dialog .dialog-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 4px; }
.obj-dialog .btn-cancel {
  background: #0d1425; border: 1px solid #243050; color: #cbd5e1;
  padding: 7px 16px; border-radius: 6px; font-size: 12px; cursor: pointer;
  transition: all .15s;
}
.obj-dialog .btn-cancel:hover { background: #1a2540; }
.obj-dialog .btn-save {
  background: #2563eb; border: 1px solid #3b82f6; color: #fff;
  padding: 7px 16px; border-radius: 6px; font-size: 12px; cursor: pointer;
  font-weight: 500; transition: all .15s;
}
.obj-dialog .btn-save:hover { background: #3b82f6; }

/* ========== Tileset Sprite-sheet Viewer ========== */
.tileset-viewer { display: flex; flex-direction: column; gap: 8px; padding: 4px 0; }
.tileset-viewer[hidden] { display: none; }
.tileset-header {
  display: flex; align-items: center; gap: 6px; flex-wrap: wrap;
  font-size: 11px; color: #94a3b8;
}
.tileset-title { font-weight: 600; color: #cbd5e1; }

.tileset-zoom-ctrl {
  display: inline-flex; align-items: center; gap: 1px;
  background: #0d1425; border: 1px solid #243050; border-radius: 6px;
  overflow: hidden;
}
.tileset-zoom-btn {
  background: transparent; border: none; color: #cbd5e1;
  width: 22px; height: 24px; font-size: 14px; line-height: 1; cursor: pointer;
  transition: background .12s;
}
.tileset-zoom-btn:hover { background: #1a2540; }
.tileset-zoom-btn:active { background: #243050; }
.tileset-del-btn {
  background: #2a1515; border: 1px solid #5a2a2a; color: #fca5a5;
  width: 24px; height: 24px; font-size: 12px; line-height: 1; cursor: pointer;
  border-radius: 5px; transition: all .12s;
  flex: 0 0 auto;
}
.tileset-del-btn:hover { background: #3a1e1e; border-color: #7a3a3a; color: #fff; }
.tileset-del-btn:active { transform: scale(.94); }
.tileset-zoom-label {
  min-width: 32px; text-align: center; font-size: 10px; color: #94a3b8;
  padding: 0 3px; user-select: none;
}
.tileset-zoom-reset { font-size: 12px; }

.tileset-select {
  flex: 1; min-width: 0;
  background: #0d1425; color: #cbd5e1;
  border: 1px solid #243050; border-radius: 6px; padding: 4px 6px;
  font-size: 11px;
}
.tileset-cell-size { display: flex; align-items: center; gap: 4px; }
.tileset-cell-size select {
  background: #0d1425; color: #cbd5e1;
  border: 1px solid #243050; border-radius: 6px; padding: 3px 5px;
  font-size: 11px;
}
.tileset-canvas-wrap {
  position: relative; max-height: 50vh; overflow: auto;
  background: #090d18; border: 1px solid #243050; border-radius: 8px;
  padding: 0;
  display: flex; align-items: flex-start; justify-content: flex-start;
  min-width: 0;
}
.tileset-canvas-wrap canvas {
  image-rendering: pixelated; image-rendering: crisp-edges;
  display: block; cursor: crosshair;
  -webkit-user-drag: none; user-drag: none;
  flex-shrink: 0;
}
.tileset-info { font-size: 11px; color: #64748b; text-align: center; }
.passability-bar {
  position: fixed; bottom: 8px; left: 8px;
  width: var(--left-w); z-index: 200;
  display: flex; align-items: center; gap: 4px; flex-wrap: wrap;
  margin-top: 0; padding: 7px; background: #151d30;
  border: 1px solid #344060; border-radius: 8px;
  box-shadow: 0 -2px 12px rgba(0,0,0,.4);
  max-height: 38vh; overflow-y: auto;
}
.passability-bar[hidden] { display: none; }
.passability-label { font-size: 11px; color: #94a3b8; margin-right: 2px; flex: 0 0 auto; }
.passability-btns { display: flex; gap: 3px; flex-wrap: wrap; flex: 1; min-width: 0; }
.tileset-viewer { padding-bottom: 96px; }
.pass-btn {
  background: #0d1425; color: #cbd5e1; border: 1px solid #243050;
  border-radius: 5px; padding: 3px 8px; font-size: 11px; cursor: pointer;
  line-height: 1.5; transition: all .12s;
}
.pass-btn:hover { background: #1a2540; border-color: #5888ff; }
.pass-btn.active { background: #2563eb; color: #fff; border-color: #5888ff; }

/* ========== Toolbar ========== */
.toolbar { display: flex; flex-wrap: wrap; gap: 5px; align-items: center; }
.tool {
  background: #0d1425; color: #cbd5e1; border: 1px solid #243050;
  border-radius: 6px; padding: 6px 11px; font-size: 12px;
  transition: all .15s; font-weight: 500;
}
.tool:hover { background: #1a2540; border-color: #344060; color: #fff; }
.tool.active { background: #2563eb; color: #fff; border-color: #5888ff; box-shadow: 0 0 0 1px rgba(88,136,255,.35); }
.tool.move { background: #2563eb; color: #fff; border-color: #5888ff; }
.tool.move.active { background: #1d4ed8; }
.spacer { flex: 1; }
.zoom-label { color: #94a3b8; min-width: 44px; text-align: center; font-size: 12px; font-weight: 500; }
.lang-btn { background: #4a3a82; border-color: #6350b0; font-weight: 600; }
.lang-btn:hover { background: #5b48a0; border-color: #7c63d0; }

/* ========== Canvas ========== */
.canvas-host {
  position: relative; flex: 1; min-height: 0; min-width: 0;
  background-color: #0d1425;
  background-image:
    linear-gradient(45deg, #151d30 25%, transparent 25%),
    linear-gradient(-45deg, #151d30 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #151d30 75%),
    linear-gradient(-45deg, transparent 75%, #151d30 75%);
  background-size: 16px 16px;
  background-position: 0 0, 0 8px, 8px -8px, -8px 0px;
  border: 1px solid #243050;
  border-radius: 10px;
  overflow: auto;
  display: flex;
  align-items: flex-start;
  justify-content: flex-start;
  padding: 16px;
}
#mapCanvas {
  display: block; flex-shrink: 0;
  image-rendering: pixelated; image-rendering: crisp-edges;
  background: transparent; border-radius: 4px;
}
.canvas-host.dragging,
.canvas-host.panning { cursor: grabbing !important; }
.canvas-host.tool-move { cursor: grab; }
.canvas-host.tool-move:active { cursor: grabbing; }
.canvas-host.tool-draw { cursor: crosshair; }
.canvas-host.tool-erase { cursor: cell; }
.canvas-empty {
  position: absolute; inset: 0; display: flex; align-items: center;
  justify-content: center; color: #fff; font-size: 18px;
  pointer-events: none;
}
.canvas-empty[hidden] { display: none; }

/* Tool cursor variations */
.canvas-host.tool-fill { cursor: copy; }
.canvas-host.tool-select { cursor: crosshair; }
.canvas-host.tool-pick { cursor: help; }
.canvas-host.tool-rect { cursor: crosshair; }
.canvas-host.tool-line { cursor: crosshair; }
.canvas-host.right-copying { cursor: crosshair !important; }
.canvas-host.right-copy-ready { cursor: copy !important; }

/* ========== Layers ========== */
.btn-new-layer {
  width: 100%; background: #2563eb; color: #fff; border: 1px solid #3b82f6;
  margin-bottom: 8px; padding: 8px; border-radius: 7px; font-weight: 500;
  transition: all .15s;
}
.btn-new-layer:hover { background: #3b82f6; transform: translateY(-1px); }

.layer-list { list-style: none; margin: 0 0 8px 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.layer-item {
  display: flex; align-items: center; gap: 6px;
  background: #0d1425; border: 1px solid #243050;
  border-radius: 6px; padding: 5px 7px; font-size: 12px;
  cursor: pointer; flex-wrap: wrap; transition: all .15s;
}
.layer-item:hover { background: #1a2540; }
.layer-item.active { border-color: #5888ff; box-shadow: 0 0 0 1px #5888ff; }
.layer-item.object-layer { background: #181a30; border-color: #343060; }
.layer-item.object-layer.active { border-color: #7c5cd0; box-shadow: 0 0 0 1px #7c5cd0; }
.layer-item.object-layer:hover { background: #242040; }
.layer-icon { color: #f87171; }
.layer-name { flex: 1; min-width: 0; }
.layer-name input {
  background: transparent; color: inherit; border: none; width: 100%; padding: 0; font-size: 12px;
}
.layer-name input:focus { outline: 1px dashed #5888ff; }
.layer-vis, .layer-del,
.layer-rename, .layer-clear {
  background: transparent; border: none; padding: 0 3px; font-size: 13px;
  color: #94a3b8; cursor: pointer; transition: color .12s;
}
.layer-vis:hover { color: #fff; }
.layer-del:hover { color: #f87171; }
.layer-rename:hover { color: #5888ff; }
.layer-clear:hover { color: #fb923c; }
.btn-erase-all {
  width: 100%; background: #2a1515; border: 1px solid #5a2a2a; color: #fca5a5;
  margin-bottom: 6px; border-radius: 7px; padding: 8px;
  font-weight: 500; transition: all .15s;
}
.btn-erase-all:hover { background: #3a1e1e; border-color: #7a3a3a; }
.btn-music {
  width: 100%; background: #0d1425; border: 1px solid #243050;
  border-radius: 7px; padding: 8px; font-weight: 500; transition: all .15s;
}
.btn-music:hover { background: #1a2540; }

/* ========== Maps Pane ========== */
.maps-pane { padding: 6px; }
.hint { color: #64748b; font-size: 12px; margin: 4px 0; }
.saved-maps { display: flex; flex-direction: column; gap: 6px; }
.saved-map {
  background: #0d1425; border: 1px solid #243050; border-radius: 6px;
  padding: 6px; display: flex; gap: 8px; align-items: center;
  transition: all .12s;
}
.saved-map:hover { background: #1a2540; }
.saved-map canvas { width: 64px; height: 48px; image-rendering: pixelated; background: #0d1425; border-radius: 3px; }
.saved-map .name { flex: 1; font-size: 12px; }
.saved-map button {
  background: #1a2540; border: 1px solid #243050; color: #cbd5e1;
  padding: 4px 8px; border-radius: 5px; font-size: 11px;
  transition: all .12s;
}
.saved-map button:hover { background: #243050; }

/* ========== Grid Pane ========== */
.grid-pane { padding: 6px; display: flex; flex-direction: column; gap: 10px; }
.grid-pane .row { display: flex; align-items: center; gap: 8px; font-size: 12px; color: #cbd5e1; }
.grid-pane input[type="number"] {
  width: 60px; background: #0d1425; color: #cbd5e1;
  border: 1px solid #243050; padding: 4px 6px; border-radius: 5px;
}
.grid-pane input[type="range"] { flex: 1; accent-color: #5888ff; }
.grid-sep { border: none; border-top: 1px solid #243050; margin: 8px 0; }

/* ========== Toast ========== */
.toast {
  position: fixed; bottom: 28px; left: 50%; transform: translateX(-50%);
  background: rgba(15,20,36,.95); color: #fff; border: 1px solid #344060;
  padding: 10px 20px; border-radius: 8px; font-size: 13px; z-index: 1000;
  opacity: 0; transition: opacity .2s; pointer-events: none;
  font-weight: 500; box-shadow: 0 4px 16px rgba(0,0,0,.4);
}
.toast.show { opacity: 1; }

/* ========== Scrollbar ========== */
::-webkit-scrollbar { width: 7px; height: 7px; }
::-webkit-scrollbar-track { background: #0d1425; }
::-webkit-scrollbar-thumb { background: #243050; border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: #344060; }

/* ========== Responsive ========== */
@media (max-width: 1100px) {
  .app { --left-w: 290px; --right-w: 210px; }
  .file-buttons { grid-template-columns: 1fr; }
}

/* ========== Tiled-style additions ========== */
.opacity-slider { width: 100%; margin: 4px 0 2px; accent-color: #5888ff; }
.layer-offset-row {
  display: flex; gap: 4px; align-items: center; margin-top: 2px;
  font-size: 11px; color: #94a3b8;
}
.layer-offset {
  width: 42px; background: #0d1425; color: #cbd5e1;
  border: 1px solid #243050; border-radius: 4px; padding: 3px 5px;
  text-align: center; font-size: 11px;
}
.layer-type-badge {
  display: inline-block; font-size: 10px; padding: 2px 6px;
  border-radius: 4px; margin-left: 4px; vertical-align: middle;
}
.layer-type-badge.tile { background: #1a2540; color: #94a3b8; border: 1px solid #243050; }
.layer-type-badge.object { background: #302050; color: #c4b5fd; border: 1px solid #503a70; }

.layer-item .layer-controls {
  width: 100%; display: flex; flex-direction: column; gap: 2px;
  margin-top: 4px; padding-top: 4px; border-top: 1px dashed #243050;
}
.drag-handle {
  cursor: grab; color: #64748b; padding: 0 3px; font-size: 14px;
}
.drag-handle:active { cursor: grabbing; }
.layer-item.dragging-over { border-top: 2px solid #5888ff; }

.layer-type-chooser { display: flex; gap: 4px; margin-top: 4px; }
.layer-type-chooser .btn { flex: 1; font-size: 11px; padding: 5px; }

.layer-object-id-row {
  display: flex; gap: 4px; align-items: center;
  font-size: 11px; color: #94a3b8; margin-top: 2px;
}
.layer-object-id-row .obj-id-label { color: #fb923c; font-weight: 700; min-width: 18px; }
.layer-object-id-row .obj-id-from-lib {
  flex: 1; min-width: 0; color: #a78bfa; font-size: 11px;
  padding: 4px 7px; background: #181a30;
  border: 1px solid #302050; border-radius: 4px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.layer-obj-affix-row {
  display: flex; gap: 4px; align-items: center; margin-top: 2px;
}
.layer-obj-affix-row label {
  display: flex; flex: 1; gap: 2px; align-items: center;
  font-size: 10px; color: #64748b;
}
.layer-obj-affix-row input {
  flex: 1; min-width: 0; background: #0d1425; color: #cbd5e1;
  border: 1px solid #243050; border-radius: 4px;
  padding: 3px 6px; font-size: 11px;
}
.layer-obj-affix-row input:focus { outline: none; border-color: #5888ff; }
.layer-obj-idx-row {
  display: flex; gap: 4px; align-items: center; margin-top: 2px;
}
.layer-obj-idx-row label {
  display: flex; gap: 4px; align-items: center;
  font-size: 10px; color: #64748b; cursor: pointer;
}
.layer-obj-idx-row input[type="checkbox"] { accent-color: #5888ff; }

.object-marker { pointer-events: none; }

/* Minimap — stays fixed in canvas-wrap, draggable by title bar, snaps to edges */
.minimap-container {
  position: absolute;
  right: 12px; bottom: 12px; top: auto; left: auto;
  background: rgba(13,20,37,.92);
  border: 1px solid #344060; border-radius: 8px;
  padding: 6px; z-index: 50;
  box-shadow: 0 4px 12px rgba(0,0,0,.45);
  transition: none;
  user-select: none;
  -webkit-user-select: none;
}
.minimap-container.snapping {
  transition: left .25s ease, top .25s ease, right .25s ease, bottom .25s ease;
}
.minimap-container .mini-title {
  font-size: 10px; color: #94a3b8; margin-bottom: 3px; text-align: center;
  cursor: grab; user-select: none;
}
.minimap-container .mini-title:active { cursor: grabbing; }
.minimap-container.dragging .mini-title { cursor: grabbing; }
.minimap-canvas {
  display: block; image-rendering: pixelated;
  cursor: pointer; background: #0d1425;
  border: 1px solid #243050; border-radius: 4px;
}

/* Status bar */
.status-bar {
  display: flex; gap: 14px; align-items: center;
  background: #0d1425; border: 1px solid #243050;
  border-radius: 7px; padding: 5px 10px;
  font-size: 11px; color: #94a3b8; flex-wrap: wrap;
}
.status-bar .status-item { display: flex; gap: 5px; align-items: center; }
.status-bar .status-label { color: #64748b; }
.status-bar .status-value { color: #cbd5e1; font-weight: 500; }
.status-bar .status-sep { color: #243050; }

.selection-preview { pointer-events: none; }

/* ========== Help Button + Export JSON Help Dialog ========== */
.help-btn {
  background: #4a3a82 !important;
  border-color: #6350b0 !important;
  color: #fff !important;
  font-weight: 700;
  flex: 0 0 auto;
}
.help-btn:hover { background: #5b48a0 !important; }

.help-overlay {
  position: fixed; inset: 0; z-index: 2000;
  background: rgba(0,0,0,.55);
  display: flex; align-items: center; justify-content: center;
}
.help-overlay[hidden] { display: none; }
.help-dialog {
  background: #151d30; border: 1px solid #344060; border-radius: 12px;
  width: 780px; max-width: 92vw; max-height: 86vh;
  display: flex; flex-direction: column;
  box-shadow: 0 10px 40px rgba(0,0,0,.5);
}
.help-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px; border-bottom: 1px solid #243050;
  flex: 0 0 auto;
}
.help-title { font-size: 16px; font-weight: 600; color: #cbd5e1; }
.help-close {
  background: transparent; border: none; color: #94a3b8;
  font-size: 24px; line-height: 1; cursor: pointer; padding: 0 4px;
}
.help-close:hover { color: #f87171; }
.help-body { padding: 18px; overflow-y: auto; flex: 1; min-height: 0; }
.help-section { margin-bottom: 22px; }
.help-section:last-child { margin-bottom: 0; }
.help-h {
  margin: 0 0 8px; font-size: 13px; color: #fb923c; font-weight: 600;
}
.help-h code { color: #5888ff; font-size: 13px; }
.help-table {
  width: 100%; border-collapse: collapse; font-size: 12px;
}
.help-table th, .help-table td {
  text-align: left; padding: 6px 10px;
  border-bottom: 1px solid #243050; vertical-align: top;
}
.help-table th {
  color: #64748b; font-weight: 600; background: #0d1425;
}
.help-table td { color: #cbd5e1; }
.help-table code {
  background: #0d1425; color: #5888ff; padding: 1px 6px;
  border-radius: 4px; font-size: 11px; white-space: nowrap;
}
.help-note { margin: 0 0 8px; font-size: 11px; color: #94a3b8; font-style: italic; }
.help-example { margin-top: 6px; font-size: 11px; color: #94a3b8; }
.help-example code { margin-right: 8px; display: inline-block; }

/* ========== Help Center tabs ========== */
.help-tabs {
  display: flex; flex-wrap: wrap; gap: 4px;
  padding: 10px 18px 0; border-bottom: 1px solid #243050;
  background: #101a30; flex: 0 0 auto;
}
.help-tab {
  background: transparent; border: 1px solid transparent; color: #94a3b8;
  font-size: 12px; padding: 7px 13px; border-radius: 8px 8px 0 0;
  cursor: pointer; font-weight: 600;
}
.help-tab:hover { color: #cbd5e1; background: #182240; }
.help-tab.active {
  color: #fff; background: #1e2b4a; border-color: #344060;
  border-bottom-color: #1e2b4a;
}
.help-pane { display: none; }
.help-pane.active { display: block; }
.help-lead {
  margin: 0 0 16px; font-size: 12.5px; line-height: 1.6; color: #cbd5e1;
  background: #101a30; border: 1px solid #243050; border-radius: 8px;
  padding: 10px 12px;
}
.help-list { margin: 0 0 4px; padding-left: 20px; font-size: 12.5px; color: #cbd5e1; }
.help-list li { margin-bottom: 6px; line-height: 1.55; }
.help-list b { color: #fb923c; font-weight: 600; }
.help-list code {
  background: #0d1425; color: #5888ff; padding: 1px 6px;
  border-radius: 4px; font-size: 11px;
}
.help-kbd {
  display: inline-block; background: #0d1425; border: 1px solid #344060;
  border-bottom-width: 2px; color: #a5b4fc; font-size: 10.5px;
  padding: 1px 6px; border-radius: 4px; font-family: inherit; margin-left: 4px;
  white-space: nowrap;
}
.help-code {
  margin: 0 0 10px; padding: 10px 12px; background: #0d1425;
  border: 1px solid #243050; border-radius: 8px; color: #a5e8a5;
  font-size: 11px; line-height: 1.5; overflow-x: auto;
  white-space: pre; font-family: "Consolas", "SF Mono", Menlo, monospace;
}
.help-table td .help-kbd { margin-left: 0; }
