/* ════════════════════════════════════════════════════════════════════
   TileMap Studio — "light table"
   The map is the lit object on a quiet graphite workbench. Chrome recedes;
   colour only ever means state:
     blue   = selected / active       green  = terrain (autotile)
     yellow = SpriteLab               pink   = destructive
   Type: IBM Plex Sans (UI, sentence case) · JetBrains Mono (key chips)
         Press Start 2P (wordmark only — the one pixel-font moment)
   ════════════════════════════════════════════════════════════════════ */

:root {
  --ground: #0d0d14;      /* canvas surround */
  --chrome: #13131c;      /* docks, bars */
  --raised: #1a1a26;      /* controls */
  --raised-2: #222232;    /* hover */
  --line: #232333;        /* hairlines */
  --line-2: #30304a;      /* control borders */
  --text: #dde2f3;
  --text-2: #a3a9c6;
  --text-3: #6d7294;
  --blue: #89b4fa;
  --blue-ink: #0f1a33;
  --green: #a6e3a1;
  --yellow: #f9e2af;
  --pink: #f38ba8;
  --teal: #94e2d5;
  --lavender: #b4befe;
  --sans: 'IBM Plex Sans', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
  --px: 'Press Start 2P', monospace;
  --r: 5px;
  --r-lg: 8px;
  --shadow-pop: 0 12px 32px rgba(0, 0, 0, 0.55), 0 2px 6px rgba(0, 0, 0, 0.35);
  --ease: cubic-bezier(0.2, 0.7, 0.2, 1);
  color-scheme: dark;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }
html, body { height: 100%; overflow: hidden; }

body {
  font-family: var(--sans);
  font-size: 13px;
  line-height: 1.4;
  color: var(--text);
  background: var(--ground);
  display: flex;
  flex-direction: column;
  user-select: none;
  -webkit-font-smoothing: antialiased;
}

svg.i { width: 16px; height: 16px; display: block; flex-shrink: 0; }

/* ── base controls ─────────────────────────────────────────────────── */
button {
  font: inherit;
  font-size: 12.5px;
  color: var(--text-2);
  background: var(--raised);
  border: 1px solid var(--line-2);
  border-radius: var(--r);
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
}
button:hover:not(:disabled) { background: var(--raised-2); color: var(--text); border-color: #3c3c5a; }
button:active:not(:disabled) { transform: translateY(1px); }
button:disabled { opacity: 0.35; cursor: default; }
:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }
button:focus:not(:focus-visible) { outline: none; }

input, select, textarea {
  font: inherit;
  font-size: 12.5px;
  color: var(--text);
  background: var(--ground);
  border: 1px solid var(--line-2);
  border-radius: var(--r);
  padding: 6px 8px;
  user-select: text;
}
input:hover, select:hover, textarea:hover { border-color: #3c3c5a; }
input:focus, select:focus, textarea:focus { border-color: var(--blue); outline: none; box-shadow: 0 0 0 3px rgba(137, 180, 250, 0.15); }
textarea { resize: vertical; line-height: 1.5; }
select {
  appearance: none;
  padding-right: 26px;
  background: var(--ground) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='none' stroke='%23a3a9c6' stroke-width='2' stroke-linecap='round' stroke-linejoin='round' d='M6 9l6 6 6-6'/%3E%3C/svg%3E") no-repeat right 7px center / 13px;
  cursor: pointer;
}
::placeholder { color: var(--text-3); }

/* checkboxes: small square with a drawn tick */
input[type='checkbox'] {
  appearance: none;
  width: 14px;
  height: 14px;
  padding: 0;
  border: 1.5px solid var(--line-2);
  border-radius: 3px;
  background: var(--ground);
  display: inline-grid;
  place-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.12s, border-color 0.12s;
}
input[type='checkbox']::after {
  content: '';
  width: 8px;
  height: 5px;
  border: solid var(--blue-ink);
  border-width: 0 0 2px 2px;
  transform: rotate(-45deg) translate(1px, -1px);
  opacity: 0;
}
input[type='checkbox']:checked { background: var(--blue); border-color: var(--blue); }
input[type='checkbox']:checked::after { opacity: 1; }
input[type='checkbox']:focus { box-shadow: none; }

/* range sliders: thin track, filled to the value via --fill */
input[type='range'] {
  appearance: none;
  background: transparent;
  border: none;
  padding: 0;
  height: 18px;
  cursor: pointer;
  --fill: 100%;
}
input[type='range']:focus { box-shadow: none; }
input[type='range']::-webkit-slider-runnable-track {
  height: 4px;
  border-radius: 2px;
  background: linear-gradient(to right, var(--blue) var(--fill), var(--line-2) var(--fill));
}
input[type='range']::-webkit-slider-thumb {
  appearance: none;
  width: 12px;
  height: 12px;
  margin-top: -4px;
  border-radius: 50%;
  background: var(--text);
  border: 2px solid var(--chrome);
  box-shadow: 0 0 0 1px var(--line-2);
}
input[type='range']::-moz-range-track { height: 4px; border-radius: 2px; background: var(--line-2); }
input[type='range']::-moz-range-progress { height: 4px; border-radius: 2px; background: var(--blue); }
input[type='range']::-moz-range-thumb { width: 10px; height: 10px; border-radius: 50%; background: var(--text); border: 2px solid var(--chrome); }

kbd {
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 500;
  color: var(--text-3);
  background: var(--ground);
  border: 1px solid var(--line-2);
  border-bottom-width: 2px;
  border-radius: 3px;
  padding: 0 4px;
  line-height: 15px;
  display: inline-block;
}
hr { border: none; border-top: 1px solid var(--line); margin: 4px 2px; }
a { color: var(--blue); text-decoration-thickness: 1px; text-underline-offset: 2px; }
strong { font-weight: 600; color: var(--text); }

.icon-btn {
  width: 30px;
  height: 30px;
  padding: 0;
  display: inline-grid;
  place-items: center;
  background: transparent;
  border-color: transparent;
  color: var(--text-2);
}
.icon-btn:hover:not(:disabled) { background: var(--raised-2); border-color: transparent; }
.icon-btn.sm { width: 26px; height: 26px; }
.icon-btn.sm svg.i { width: 15px; height: 15px; }
.icon-btn.xs { width: 22px; height: 22px; }
.icon-btn.xs svg.i { width: 13px; height: 13px; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 7px 12px;
  font-weight: 500;
  color: var(--text);
}
.btn-block { width: 100%; }
.btn svg.i { width: 15px; height: 15px; }

/* ── title bar ──────────────────────────────────────────────────────── */
.titlebar {
  position: relative;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 6px;
  height: 44px;
  padding: 0 8px 0 14px;
  background: var(--chrome);
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}
.brand { display: flex; align-items: center; gap: 9px; margin-right: 10px; }
.brand-mark { display: grid; grid-template-columns: 6px 6px; gap: 2px; }
.brand-mark i { width: 6px; height: 6px; display: block; }
.brand-mark i:nth-child(1) { background: var(--blue); }
.brand-mark i:nth-child(2) { background: var(--pink); }
.brand-mark i:nth-child(3) { background: var(--green); }
.brand-mark i:nth-child(4) { background: var(--yellow); }
.brand h1 {
  font-family: var(--px);
  font-size: 10px;
  white-space: nowrap;
  font-weight: 400;
  letter-spacing: 0.5px;
  color: #fff;
  padding-top: 2px;
}
.brand-ver { font-size: 11px; color: var(--text-3); font-variant-numeric: tabular-nums; }

.menus { display: flex; gap: 1px; }
.menu { position: relative; }
.menu-btn {
  background: none;
  border-color: transparent;
  padding: 5px 10px;
  font-size: 13px;
  color: var(--text-2);
}
.menu-btn:hover:not(:disabled), .menu.open .menu-btn { color: var(--text); background: var(--raised-2); border-color: transparent; }
.menu-drop {
  display: none;
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  min-width: 232px;
  background: var(--raised);
  border: 1px solid var(--line-2);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-pop);
  padding: 5px;
  z-index: 40;
}
.menu.open .menu-drop { display: block; animation: pop 0.12s var(--ease); }
@keyframes pop { from { opacity: 0; transform: translateY(-3px); } }
.menu-drop button {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  border-radius: 4px;
  padding: 6px 9px;
  color: var(--text);
  font-size: 13px;
}
.menu-drop button:hover:not(:disabled), .menu-drop button:focus-visible { background: rgba(137, 180, 250, 0.14); outline: none; }
.menu-group { display: block; padding: 6px 9px 3px; font-size: 11px; color: var(--text-3); }
.menu-check { width: 14px; height: 14px; color: var(--blue); }
.menu-check.on::before { content: '✓'; font-weight: 600; }

.titlebar-spacer { flex: 1; display: flex; justify-content: center; min-width: 60px; }
.map-name {
  background: none;
  border: 1px solid transparent;
  text-align: center;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-2);
  width: min(300px, 100%);
  padding: 5px 8px;
}
.map-name:hover { border-color: var(--line-2); color: var(--text); }
.map-name:focus { color: #fff; background: var(--ground); }

.titlebar-actions { display: flex; gap: 1px; align-items: center; }
.tb-sep { width: 1px; height: 18px; background: var(--line-2); margin: 0 5px; }
#btnSwapQuick.on { color: var(--yellow); background: rgba(249, 226, 175, 0.1); }
.tb-danger:hover:not(:disabled) { color: var(--pink) !important; background: rgba(243, 139, 168, 0.1) !important; }

.spritelab-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-left: 8px;
  font-size: 12px;
  color: var(--text-2);
  text-decoration: none;
  border: 1px solid rgba(249, 226, 175, 0.22);
  border-radius: 999px;
  padding: 4px 11px 4px 8px;
  white-space: nowrap;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
}
.spritelab-badge svg.i { width: 13px; height: 13px; color: var(--yellow); }
.spritelab-badge strong { color: var(--yellow); font-weight: 600; }
.spritelab-badge:hover { color: var(--text); border-color: var(--yellow); background: rgba(249, 226, 175, 0.07); }

/* ── workspace ──────────────────────────────────────────────────────── */
.workspace {
  position: relative;
  z-index: 1;
  flex: 1;
  display: grid;
  grid-template-columns: auto 1fr auto;
  min-height: 0;
}
.dock {
  position: relative;
  display: flex;
  flex-direction: column;
  background: var(--chrome);
  overflow-y: auto;
  overflow-x: hidden;
  min-height: 0;
}
.dock-left { width: 236px; border-right: 1px solid var(--line); }
.dock-right { width: 288px; border-left: 1px solid var(--line); }

.panel { padding: 12px 12px 14px; border-bottom: 1px solid var(--line); }
.panel:last-child { border-bottom: none; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 6px; margin-bottom: 8px; min-height: 26px; }
.panel-head .panel-title { margin-bottom: 0; }
.panel-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-2);
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 18px;
}

.dock-toggle {
  position: absolute;
  top: 10px;
  z-index: 6;
  width: 22px;
  height: 22px;
  padding: 0;
  display: grid;
  place-items: center;
  background: transparent;
  border-color: transparent;
  color: var(--text-3);
}
.dock-toggle svg.i { width: 14px; height: 14px; }
.dock-left .dock-toggle { right: 8px; }
.dock-right .dock-toggle { right: 8px; }
.dock-right .panel-tilesets .panel-head { padding-right: 26px; }
.dock.collapsed { width: 36px !important; overflow: hidden; }
.dock.collapsed .panel { display: none; }
.dock.collapsed .dock-toggle { right: 7px; }

/* ── tools ──────────────────────────────────────────────────────────── */
.toolgrid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; }
.tool {
  position: relative;
  height: 50px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 4px 2px 3px;
  background: transparent;
  border-color: transparent;
  color: var(--text-2);
}
.tool svg { width: 18px; height: 18px; display: block; }
.tool span { font-size: 11px; line-height: 1; }
.tool kbd {
  position: absolute;
  top: 3px;
  right: 3px;
  border: none;
  background: none;
  padding: 0;
  font-size: 8.5px;
  line-height: 1;
  color: var(--text-3);
  opacity: 0;
  transition: opacity 0.12s;
}
.tool:hover kbd, .tool.active kbd { opacity: 1; }
.tool:hover:not(:disabled) { background: var(--raised); border-color: transparent; }
.tool.active {
  background: rgba(137, 180, 250, 0.15);
  border-color: rgba(137, 180, 250, 0.45);
  color: #fff;
}
.tool.active svg { color: var(--blue); }
.tool.active kbd { color: var(--blue); }
.tool-terrain.active { background: rgba(166, 227, 161, 0.13); border-color: rgba(166, 227, 161, 0.45); }
.tool-terrain.active svg, .tool-terrain.active kbd { color: var(--green); }

.tool-extras { margin-top: 12px; display: flex; flex-direction: column; gap: 10px; }
.tool-option { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--text-2); }
.eraser-size input { flex: 1; min-width: 0; }
.eraser-size output { width: 14px; text-align: right; font-variant-numeric: tabular-nums; color: var(--text); }
.terrain-atlas { flex-direction: column; align-items: stretch; gap: 5px; }
.terrain-atlas label { font-size: 12px; color: var(--green); }
.terrain-atlas select { width: 100%; }

.hand-box {
  display: grid;
  grid-template-columns: 64px 1fr;
  gap: 10px;
  align-items: center;
  padding: 8px;
  background: var(--ground);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
}
#handPreview {
  width: 64px;
  height: 64px;
  border-radius: 4px;
  background: repeating-conic-gradient(#1b1b27 0% 25%, #15151f 0% 50%) 0 0 / 12px 12px;
  image-rendering: pixelated;
}
.hand-info { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.hand-label { font-size: 12px; font-weight: 600; color: var(--text); }
.hand-meta { font-size: 11.5px; color: var(--text-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hand-actions { display: flex; gap: 2px; margin-top: 4px; margin-left: -4px; }

/* ── layers ─────────────────────────────────────────────────────────── */
.panel-layers { flex: 1; display: flex; flex-direction: column; min-height: 180px; }
.layer-toolbar { display: flex; gap: 0; margin-right: -4px; }
.layer-list {
  list-style: none;
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-height: 60px;
}
.layer-row {
  display: flex;
  align-items: center;
  gap: 2px;
  height: 32px;
  padding: 0 8px 0 4px;
  border-radius: var(--r);
  border: 1px solid transparent;
  cursor: pointer;
  color: var(--text-2);
}
.layer-row:hover { background: var(--raised); }
.layer-row.active { background: rgba(137, 180, 250, 0.13); border-color: rgba(137, 180, 250, 0.35); color: #fff; }
.layer-row.terrain-layer .layer-name::before {
  content: '';
  display: inline-block;
  width: 7px;
  height: 7px;
  margin-right: 7px;
  vertical-align: 1px;
  background: var(--green);
  border-radius: 1px;
}
.layer-row .layer-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; padding-left: 4px; }
.layer-row.hidden-layer .layer-name { color: var(--text-3); text-decoration: line-through; }
.layer-row button {
  width: 24px;
  height: 24px;
  padding: 0;
  display: grid;
  place-items: center;
  background: none;
  border: none;
  color: var(--text-3);
  flex-shrink: 0;
}
.layer-row button svg { width: 14px; height: 14px; display: block; }
.layer-row button:hover:not(:disabled) { color: var(--text); background: rgba(255, 255, 255, 0.06); }
.layer-row button.on { color: var(--text-2); }
.layer-row .lock-btn:not(.on) { opacity: 0; }
.layer-row:hover .lock-btn, .layer-row .lock-btn:focus-visible { opacity: 1; }
.layer-row .lock-btn.on { color: var(--yellow); opacity: 1; }
.layer-row input.rename { width: 100%; font-size: 13px; padding: 2px 5px; }
.layer-opacity { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--text-2); margin-top: 10px; }
.layer-opacity input { flex: 1; min-width: 0; }
.layer-opacity output { width: 36px; text-align: right; font-variant-numeric: tabular-nums; color: var(--text); }

/* ── viewport ───────────────────────────────────────────────────────── */
.viewport-wrap { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.viewport {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow: hidden;
  background:
    radial-gradient(120% 90% at 50% 45%, transparent 55%, rgba(0, 0, 0, 0.35)),
    radial-gradient(rgba(163, 169, 198, 0.07) 1px, transparent 1.2px) 0 0 / 16px 16px,
    var(--ground);
}
.viewport canvas { position: absolute; top: 0; left: 0; }
#mapCanvas { z-index: 1; }
#overlayCanvas { z-index: 2; cursor: crosshair; }

#minimap {
  position: absolute !important;
  right: 12px;
  bottom: 12px;
  top: auto !important;
  left: auto !important;
  z-index: 5;
  width: 132px;
  height: 132px;
  background: rgba(19, 19, 28, 0.92);
  border: 1px solid var(--line-2);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-pop);
  cursor: pointer;
  image-rendering: pixelated;
  transition: opacity 0.2s, transform 0.2s var(--ease);
}
#minimap.idle { opacity: 0; transform: translateY(6px); pointer-events: none; }

.statusbar {
  display: flex;
  align-items: center;
  gap: 14px;
  height: 30px;
  padding: 0 10px;
  font-size: 12px;
  color: var(--text-3);
  background: var(--chrome);
  border-top: 1px solid var(--line);
  white-space: nowrap;
  overflow: hidden;
  flex-shrink: 0;
}
.status-item { flex-shrink: 0; font-variant-numeric: tabular-nums; }
.status-coords { min-width: 48px; color: var(--text-2); }
.status-zoom { display: inline-flex; align-items: center; gap: 1px; }
.status-zoom .icon-btn { color: var(--text-3); }
#statusZoom {
  min-width: 48px;
  height: 22px;
  padding: 0 4px;
  background: none;
  border-color: transparent;
  color: var(--text-2);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}
#statusZoom:hover { background: var(--raised-2); }
.status-toggles { display: flex; gap: 12px; }
.status-toggles label { display: inline-flex; align-items: center; gap: 5px; cursor: pointer; color: var(--text-2); }
.status-toggles label:hover { color: var(--text); }
.status-toggles input[type='checkbox'] { width: 13px; height: 13px; }
.status-hint { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; color: var(--text-3); }
.status-hint strong { color: var(--text-2); font-weight: 500; }
.status-save { margin-left: auto; display: inline-flex; align-items: center; gap: 6px; }
.status-save::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: var(--text-3); }
.status-save:empty { display: none; }
.status-save.saved::before { background: var(--green); }
.status-save.dirty::before { background: var(--yellow); }
.status-save.failed { color: var(--pink); }
.status-save.failed::before { background: var(--pink); }

/* ── tilesets ───────────────────────────────────────────────────────── */
.panel-tilesets { flex: 1; display: flex; flex-direction: column; min-height: 240px; }
.recent-strip {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  padding: 6px;
  margin-top: 8px;
  background: var(--ground);
  border: 1px solid var(--line);
  border-radius: var(--r);
}
.recent-strip canvas { image-rendering: pixelated; border-radius: 3px; outline: 1px solid var(--line-2); cursor: pointer; }
.recent-strip canvas:hover { outline: 2px solid var(--blue); }
.recent-empty { font-size: 12px; color: var(--text-3); padding: 2px 2px; }
#btnRecent.on { color: var(--blue); background: rgba(137, 180, 250, 0.12); }

.tileset-list { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 10px; margin-top: 10px; }
.tileset-empty {
  text-align: center;
  padding: 26px 14px;
  color: var(--text-2);
  font-size: 13px;
  line-height: 1.55;
  border: 1px dashed var(--line-2);
  border-radius: var(--r-lg);
}
.tileset-empty .dim { color: var(--text-3); font-size: 12px; margin: 4px 0 14px; }

.tileset-card {
  flex-shrink: 0;
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  background: var(--ground);
  overflow: hidden;
  transition: border-color 0.12s;
}
.tileset-card.active { border-color: rgba(137, 180, 250, 0.5); }
.tileset-card.autotile.active { border-color: rgba(166, 227, 161, 0.5); }
.tileset-head {
  position: relative;
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 4px 4px 4px 10px;
  background: var(--raised);
  border-bottom: 1px solid var(--line);
  min-height: 34px;
}
.tileset-name {
  flex: 1;
  min-width: 0;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: pointer;
}
.tileset-sub { display: block; font-size: 11px; font-weight: 400; color: var(--text-3); }
.tileset-head .icon-btn { width: 24px; height: 24px; color: var(--text-3); }
.tileset-head .icon-btn svg.i { width: 14px; height: 14px; }
.tileset-head .icon-btn:hover:not(:disabled) { color: var(--text); }
/* view/remove controls float over the header's right end on hover so the
   name gets the full width the rest of the time */
.tileset-tools {
  position: absolute;
  right: 4px;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  padding-left: 18px;
  background: linear-gradient(to right, transparent, var(--raised) 18px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.12s;
}
.tileset-card:hover .tileset-tools, .tileset-head:focus-within .tileset-tools { opacity: 1; pointer-events: auto; }
.tileset-body { overflow: auto; max-height: 320px; padding: 6px; }
.tileset-body canvas { image-rendering: pixelated; display: block; cursor: crosshair; }
.tileset-card.minimized .tileset-head { border-bottom: none; }
.tileset-card.minimized .chev { transform: rotate(-90deg); }
.chev { transition: transform 0.15s var(--ease); }

.autotile-badge {
  flex-shrink: 0;
  font-size: 10.5px;
  font-weight: 600;
  color: var(--green);
  background: rgba(166, 227, 161, 0.12);
  border-radius: 999px;
  padding: 1px 7px;
  margin: 0 4px;
  white-space: nowrap;
}
.autotile-actions { display: flex; gap: 6px; padding: 0 6px 6px; }
.autotile-cta {
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 6px 8px;
  font-size: 12px;
  font-weight: 500;
  color: var(--green);
  background: rgba(166, 227, 161, 0.09);
  border-color: rgba(166, 227, 161, 0.25);
}
.autotile-cta svg.i { width: 14px; height: 14px; }
.autotile-cta:hover:not(:disabled) { background: rgba(166, 227, 161, 0.18); color: #dcf6d8; border-color: rgba(166, 227, 161, 0.5); }
.autotile-cta-base { flex: 0 0 auto; color: var(--text-2); background: transparent; border-color: var(--line-2); }
.autotile-cta-base:hover:not(:disabled) { color: var(--text); background: var(--raised-2); border-color: #3c3c5a; }

/* ── AI panel (SpriteLab) ───────────────────────────────────────────── */
.panel-ai { flex-shrink: 0; }
.panel-title-ai { color: var(--yellow); }
.panel-title-ai svg.i { width: 13px; height: 13px; }
.ai-teaser { display: flex; flex-direction: column; gap: 10px; }
.ai-teaser-art { display: grid; grid-template-columns: repeat(6, 1fr); gap: 3px; height: 8px; }
.ai-teaser-art span { background: var(--c); border-radius: 1px; opacity: 0.85; }
.ai-teaser-title { font-size: 14px; font-weight: 600; color: var(--text); }
.ai-teaser-copy { font-size: 12.5px; line-height: 1.55; color: var(--text-2); }
.ai-teaser-foot { font-size: 11.5px; color: var(--text-3); }
.ai-teaser-foot a { color: var(--text-2); }

.btn-spritelab {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  width: 100%;
  padding: 8px 12px;
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
  color: #1d1706;
  background: var(--yellow);
  border: 1px solid var(--yellow);
  border-radius: var(--r);
  transition: background 0.12s, transform 0.08s;
}
.btn-spritelab svg.i { width: 14px; height: 14px; }
.btn-spritelab:hover:not(:disabled) { background: #fcecc7; color: #000; border-color: #fcecc7; }
.btn-spritelab:disabled { opacity: 0.6; }

.ai-gen { display: flex; flex-direction: column; gap: 8px; }
.ai-gen-modes { display: grid; grid-template-columns: repeat(3, 1fr); padding: 2px; gap: 2px; background: var(--ground); border: 1px solid var(--line); border-radius: var(--r); }
.ai-mode { font-size: 12px; padding: 5px 2px; border-color: transparent; background: none; border-radius: 3px; }
.ai-mode.active { background: var(--raised-2); color: var(--yellow); border-color: var(--line-2); }
.ai-mode-hint { font-size: 11.5px; color: var(--text-3); line-height: 1.45; min-height: 17px; }
.ai-gen textarea { width: 100%; }
.ai-gen-row { display: flex; align-items: center; justify-content: space-between; font-size: 12px; color: var(--text-2); }
.ai-gen-row label { display: flex; align-items: center; gap: 7px; }
.ai-gen-row select { padding-top: 4px; padding-bottom: 4px; }
.ai-credits { color: var(--teal); font-variant-numeric: tabular-nums; }
.ai-result { display: flex; flex-direction: column; gap: 8px; align-items: center; padding-top: 4px; }
#aiResultCanvas {
  image-rendering: pixelated;
  background: repeating-conic-gradient(#1b1b27 0% 25%, #15151f 0% 50%) 0 0 / 12px 12px;
  border: 1px solid var(--line-2);
  border-radius: var(--r);
}
.ai-result .btn { width: 100%; }
.ai-error { font-size: 12px; color: var(--pink); line-height: 1.5; }

/* ── modals ─────────────────────────────────────────────────────────── */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(6, 6, 12, 0.66);
  backdrop-filter: blur(2px);
  display: grid;
  place-items: center;
  padding: 16px;
  animation: fadein 0.14s ease-out;
}
@keyframes fadein { from { opacity: 0; } }
.modal {
  position: relative;
  width: min(460px, 100%);
  max-height: 88vh;
  overflow-y: auto;
  background: var(--chrome);
  border: 1px solid var(--line-2);
  border-radius: 10px;
  padding: 20px 20px 18px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.6);
  animation: rise 0.18s var(--ease);
  user-select: text;
}
@keyframes rise { from { opacity: 0; transform: translateY(8px) scale(0.99); } }
.modal h3 { font-size: 16px; font-weight: 600; color: #fff; margin-bottom: 10px; padding-right: 28px; }
.modal .modal-close { position: absolute; top: 12px; right: 12px; width: 28px; height: 28px; padding: 0; display: grid; place-items: center; background: none; border-color: transparent; color: var(--text-3); }
.modal .modal-close:hover:not(:disabled) { background: var(--raised-2); color: var(--text); }
.modal p { font-size: 13px; line-height: 1.6; color: var(--text-2); margin-bottom: 10px; }
.modal label { display: block; font-size: 12px; font-weight: 500; color: var(--text-2); margin: 14px 0 5px; }
.modal label > input, .modal label > select, .modal label > textarea { margin-top: 5px; }
.modal input[type='text'], .modal input[type='number'], .modal input[type='email'], .modal textarea, .modal select { width: 100%; }
.modal .row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; align-items: center; margin-top: 20px; flex-wrap: wrap; }
.modal-actions button, .modal-actions .btn { padding: 7px 14px; font-weight: 500; color: var(--text); }
.modal-actions .primary { background: var(--blue); border-color: var(--blue); color: var(--blue-ink); }
.modal-actions .primary:hover:not(:disabled) { background: #a4c5fb; border-color: #a4c5fb; color: var(--blue-ink); }
.modal-actions .danger { background: rgba(243, 139, 168, 0.12); border-color: rgba(243, 139, 168, 0.5); color: var(--pink); }
.modal-actions .danger:hover:not(:disabled) { background: var(--pink); border-color: var(--pink); color: #2a0d16; }
.modal-actions .btn-spritelab { width: auto; color: #1d1706; }
.modal-actions .spacer { flex: 1; }
.modal .hint { font-size: 12px; color: var(--text-3); margin-top: 6px; }

.size-presets { display: flex; gap: 5px; flex-wrap: wrap; align-items: center; margin-top: 5px; }
.size-presets button { padding: 5px 10px; font-size: 12px; font-variant-numeric: tabular-nums; }
.size-presets button.active { border-color: var(--blue); color: var(--blue); background: rgba(137, 180, 250, 0.12); }
.size-presets .custom-size { display: inline-flex; align-items: center; gap: 4px; margin-left: 4px; color: var(--text-3); font-size: 12px; }
.size-presets input { width: 58px; padding: 4px 6px; }

.import-preview-wrap {
  max-height: 260px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: var(--r);
  margin-top: 12px;
  background: repeating-conic-gradient(#1b1b27 0% 25%, #15151f 0% 50%) 0 0 / 12px 12px;
}
#importPreview { image-rendering: pixelated; display: block; }
.import-meta { font-size: 12px !important; color: var(--text-3) !important; margin: 6px 0 0 !important; font-variant-numeric: tabular-nums; }
.import-autotile {
  display: flex !important;
  gap: 9px;
  align-items: flex-start;
  font-weight: 400 !important;
  font-size: 12.5px !important;
  line-height: 1.5;
  color: var(--text-2) !important;
  cursor: pointer;
  margin: 12px 0 0 !important;
}
.import-autotile input { margin-top: 2px; }
.import-autotile strong { display: block; font-weight: 500; }

.swatches { display: grid; grid-template-columns: repeat(9, 1fr); gap: 6px; margin-top: 12px; }
.swatches button { aspect-ratio: 1; border: 1px solid rgba(255, 255, 255, 0.12); border-radius: 4px; padding: 0; }
.swatches button:hover:not(:disabled) { border-color: #fff; }
.swatches button.active { box-shadow: 0 0 0 2px var(--chrome), 0 0 0 4px var(--blue); }
input[type='color'] { width: 100%; height: 38px; padding: 3px; cursor: pointer; }

.modal-wide { width: min(640px, 100%); }
.shortcut-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 18px 32px; align-items: start; }
@media (max-width: 560px) { .shortcut-cols { grid-template-columns: 1fr; } }
.shortcut-grid { display: grid; grid-template-columns: 104px 1fr; gap: 7px 16px; font-size: 13px; align-items: center; color: var(--text-2); }
.shortcut-grid .keys { display: flex; gap: 3px; flex-wrap: wrap; }
.shortcut-grid kbd { font-size: 11px; color: var(--text); }
.shortcut-grid h4 { grid-column: 1 / -1; font-size: 12px; font-weight: 600; color: var(--text-3); }

/* ── tooltips ───────────────────────────────────────────────────────── */
.tip-bubble {
  position: fixed;
  z-index: 90;
  max-width: 260px;
  padding: 6px 9px;
  background: #26263a;
  border: 1px solid #3a3a56;
  border-radius: 6px;
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.5);
  font-size: 12px;
  line-height: 1.45;
  pointer-events: none;
  animation: tipin 0.1s ease-out;
}
@keyframes tipin { from { opacity: 0; transform: translateY(2px); } }
.tip-label { display: block; color: #fff; font-weight: 500; }
.tip-label kbd { margin-left: 5px; color: var(--text); background: #1a1a28; border-color: #43435f; }
.tip-detail { display: block; color: var(--text-2); margin-top: 2px; }

/* ── toasts ─────────────────────────────────────────────────────────── */
.toast-root {
  position: fixed;
  bottom: 44px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 60;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: 10px;
  background: #22222f;
  border: 1px solid var(--line-2);
  border-radius: var(--r-lg);
  padding: 8px 8px 8px 12px;
  font-size: 13px;
  color: var(--text);
  max-width: min(460px, calc(100vw - 32px));
  box-shadow: var(--shadow-pop);
  animation: toastin 0.2s var(--ease);
}
.toast::before { content: ''; width: 8px; height: 8px; border-radius: 2px; background: var(--green); flex-shrink: 0; }
.toast.warn::before { background: var(--yellow); }
.toast.error::before { background: var(--pink); }
.toast.spritelab::before { background: var(--yellow); border-radius: 50%; }
.toast span { line-height: 1.45; }
.toast a { color: var(--yellow); }
.toast button { width: 22px; height: 22px; padding: 0; display: grid; place-items: center; background: none; border-color: transparent; color: var(--text-3); flex-shrink: 0; font-size: 12px; }
.toast button:hover:not(:disabled) { background: rgba(255, 255, 255, 0.07); }
.toast.leaving { animation: toastout 0.18s ease-in forwards; }
@keyframes toastin { from { opacity: 0; transform: translateY(8px); } }
@keyframes toastout { to { opacity: 0; transform: translateY(4px); } }

/* ── tutorial ───────────────────────────────────────────────────────── */
.tut-highlight {
  position: relative;
  z-index: 71 !important;
  box-shadow: 0 0 0 2px var(--blue), 0 0 0 6px rgba(137, 180, 250, 0.2) !important;
  border-radius: var(--r);
}
.tut-tip {
  position: fixed;
  z-index: 72;
  width: 300px;
  background: var(--chrome);
  border: 1px solid var(--line-2);
  border-radius: 10px;
  padding: 16px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.6);
  animation: rise 0.18s var(--ease);
}
.tut-step { font-size: 11.5px; color: var(--text-3); margin-bottom: 4px; font-variant-numeric: tabular-nums; }
.tut-tip h4 { font-size: 15px; font-weight: 600; color: #fff; margin-bottom: 6px; }
.tut-tip p { font-size: 13px; line-height: 1.55; color: var(--text-2); margin-bottom: 14px; }
.tut-foot { display: flex; align-items: center; gap: 8px; }
.tut-dots { display: flex; gap: 4px; flex: 1; }
.tut-dots i { width: 6px; height: 6px; border-radius: 50%; background: var(--line-2); }
.tut-dots i.on { background: var(--blue); width: 16px; border-radius: 3px; }
.tut-tip .modal-actions { margin-top: 0; }

/* ── drop overlay ───────────────────────────────────────────────────── */
.drop-overlay {
  position: fixed;
  inset: 0;
  z-index: 80;
  background: rgba(6, 6, 12, 0.75);
  display: grid;
  place-items: center;
  pointer-events: none;
}
.drop-box {
  border: 2px dashed var(--blue);
  border-radius: 14px;
  padding: 36px 52px;
  text-align: center;
  background: var(--chrome);
}
.drop-title { font-family: var(--px); font-size: 12px; color: #fff; margin-bottom: 12px; }
.drop-box p:last-child { font-size: 13px; color: var(--text-2); }

.hand-size { color: var(--text-3); }

/* scrollbars */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--line-2); border: 3px solid var(--chrome); border-radius: 6px; }
::-webkit-scrollbar-thumb:hover { background: #45456a; }
::-webkit-scrollbar-corner { background: transparent; }

/* ── responsive ─────────────────────────────────────────────────────── */
@media (max-width: 1280px) {
  .badge-text { display: none; }
  .spritelab-badge { padding: 6px; }
}
@media (max-width: 1100px) {
  .dock-left { width: 212px; }
  .dock-right { width: 252px; }
  .brand-ver { display: none; }
  .status-toggles label[title^='Coordinates'] { display: none; }
}
@media (max-width: 900px) {
  .map-name { display: none; }
  .status-hint { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ── terrain mode ───────────────────────────────────────────────────── */
/* tools that place regular tiles don't act on terrain: greyed, still
   clickable (clicking leaves terrain mode) */
.tool.dimmed { opacity: 0.32; }
.tool.dimmed:hover:not(:disabled) { opacity: 0.75; }
.terrain-mode-note {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  margin-top: 10px;
  padding: 8px 10px;
  font-size: 12px;
  line-height: 1.45;
  color: var(--text-2);
  background: rgba(166, 227, 161, 0.07);
  border: 1px solid rgba(166, 227, 161, 0.22);
  border-radius: var(--r);
}
.terrain-mode-note svg.i { width: 14px; height: 14px; color: var(--green); margin-top: 2px; }
.terrain-mode-note strong { color: var(--green); font-weight: 600; }

.hand-box.terrain { border-color: rgba(166, 227, 161, 0.3); }
.hand-box.terrain .hand-label { color: var(--green); }
.hand-box.terrain .hand-actions { display: none; }

/* tileset groups: terrain atlases vs regular sheets */
.tileset-group-head { display: flex; flex-direction: column; gap: 1px; padding: 2px 2px 0; }
.tileset-group-head + .tileset-card { margin-top: -4px; }
.tileset-group-head:not(:first-child) { margin-top: 6px; }
.tileset-group-title { font-size: 12px; font-weight: 600; display: flex; align-items: center; gap: 6px; }
.tileset-group-title::before { content: ''; width: 8px; height: 8px; border-radius: 2px; }
.tileset-group-head.terrain .tileset-group-title { color: var(--green); }
.tileset-group-head.terrain .tileset-group-title::before { background: var(--green); }
.tileset-group-head.sheets .tileset-group-title { color: var(--text-2); }
.tileset-group-head.sheets .tileset-group-title::before { background: var(--text-3); }
.tileset-group-detail { font-size: 11.5px; color: var(--text-3); padding-left: 14px; }

/* terrain cards always read as terrain: green edge + tinted header */
.tileset-card.autotile { border-color: rgba(166, 227, 161, 0.28); box-shadow: inset 3px 0 0 var(--green); }
.tileset-card.autotile .tileset-head { background: linear-gradient(90deg, rgba(166, 227, 161, 0.1), var(--raised) 60%); }
.tileset-card.autotile .tileset-tools { background: linear-gradient(to right, transparent, #1f2a24 18px); }
/* an atlas isn't for picking tiles — say so on hover */
.tileset-card.autotile .tileset-body { position: relative; }
.tileset-card.autotile .tileset-body::after {
  content: 'Click to paint terrain with this';
  position: absolute;
  left: 6px;
  right: 6px;
  bottom: 6px;
  padding: 6px 8px;
  font-size: 11.5px;
  text-align: center;
  color: #0f1d0e;
  background: rgba(166, 227, 161, 0.92);
  border-radius: 4px;
  opacity: 0;
  transform: translateY(3px);
  transition: opacity 0.12s, transform 0.12s;
  pointer-events: none;
}
.tileset-card.autotile .tileset-body:hover::after { opacity: 1; transform: none; }
/* in terrain mode regular sheets step back (clicking a tile still works) */
.terrain-mode .tileset-card:not(.autotile) { opacity: 0.55; transition: opacity 0.15s; }
.terrain-mode .tileset-card:not(.autotile):hover { opacity: 1; }
.tileset-card.autotile.active { border-color: rgba(166, 227, 161, 0.65); }

/* ── segmented control ──────────────────────────────────────────────── */
.seg {
  display: inline-grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 2px;
  padding: 2px;
  background: var(--ground);
  border: 1px solid var(--line);
  border-radius: var(--r);
}
.seg button { padding: 4px 10px; font-size: 12px; background: none; border-color: transparent; border-radius: 3px; }
.seg button.active { background: var(--raised-2); border-color: var(--line-2); color: #fff; }
.tool-option.seg { display: grid; width: 100%; }

/* switch-style option row */
.tool-option.switch { cursor: pointer; color: var(--text-2); }
.tool-option.switch:hover { color: var(--text); }
.tool-option.switch span { flex: 1; }
.tool-option.switch kbd { font-size: 9.5px; }

/* ── recent tiles ───────────────────────────────────────────────────── */
.recent-item {
  position: relative;
  width: 28px;
  height: 28px;
  padding: 1px;
  display: grid;
  place-items: center;
  background: var(--raised);
  border-color: var(--line-2);
  border-radius: 4px;
}
.recent-item canvas { width: 24px; height: 24px; image-rendering: pixelated; border-radius: 2px; outline: none !important; }
.recent-item:hover:not(:disabled) { border-color: var(--blue); }
.recent-n {
  position: absolute;
  right: -4px;
  bottom: -4px;
  min-width: 13px;
  height: 13px;
  padding: 0 3px;
  font: 600 9px/13px var(--mono);
  color: var(--text);
  background: var(--raised-2);
  border: 1px solid var(--line-2);
  border-radius: 7px;
  text-align: center;
  pointer-events: none;
}

/* ── layer thumbnails + drag reorder ────────────────────────────────── */
.layer-row { height: 38px; }
.layer-thumb {
  width: 28px;
  height: 28px;
  flex-shrink: 0;
  margin-left: 2px;
  border-radius: 3px;
  image-rendering: pixelated;
  background: repeating-conic-gradient(#1b1b27 0% 25%, #15151f 0% 50%) 0 0 / 8px 8px;
  outline: 1px solid var(--line);
}
.layer-row.hidden-layer .layer-thumb { opacity: 0.35; }
.layer-row.dragging { opacity: 0.45; }
.layer-row.drop-above { box-shadow: inset 0 2px 0 var(--blue); }
.layer-row.drop-below { box-shadow: inset 0 -2px 0 var(--blue); }
.layer-row[draggable='true'] { cursor: grab; }
.layer-row.terrain-layer .layer-thumb { outline-color: rgba(166, 227, 161, 0.45); }

/* ── command palette ────────────────────────────────────────────────── */
.palette-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 28px;
  margin-left: 6px;
  padding: 0 6px 0 9px;
  font-size: 12.5px;
  color: var(--text-3);
  background: var(--ground);
  border-color: var(--line);
  border-radius: 6px;
  min-width: 150px;
}
.palette-btn span { flex: 1; text-align: left; }
.palette-btn svg.i { width: 14px; height: 14px; }
.palette-btn kbd { font-size: 10px; }
.palette-btn:hover:not(:disabled) { color: var(--text-2); background: var(--ground); border-color: var(--line-2); }

.palette-backdrop {
  position: fixed;
  inset: 0;
  z-index: 55;
  background: rgba(6, 6, 12, 0.5);
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 12vh 16px 16px;
  animation: fadein 0.1s ease-out;
}
.palette {
  width: min(560px, 100%);
  background: var(--chrome);
  border: 1px solid var(--line-2);
  border-radius: 12px;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.6);
  overflow: hidden;
  animation: rise 0.14s var(--ease);
}
.palette-search { display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.palette-search svg.i { color: var(--text-3); }
.palette-search input {
  flex: 1;
  font-size: 15px;
  padding: 2px 0;
  background: none;
  border: none;
  box-shadow: none !important;
}
.palette-list { list-style: none; max-height: min(52vh, 420px); overflow-y: auto; padding: 6px; }
.palette-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 10px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13.5px;
  color: var(--text);
}
.palette-item.sel { background: rgba(137, 180, 250, 0.16); }
.palette-group { width: 58px; flex-shrink: 0; font-size: 11.5px; color: var(--text-3); }
.palette-label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.palette-item.current .palette-label::after { content: ' · current'; color: var(--text-3); }
.palette-empty { padding: 18px 10px; color: var(--text-3); text-align: center; font-size: 13px; }

/* ── new map / export dialogs ───────────────────────────────────────── */
.preset-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.preset-grid button { display: flex; flex-direction: column; gap: 1px; padding: 8px 4px; font-size: 12px; }
.preset-grid button strong { font-weight: 500; color: var(--text); }
.preset-grid button span { font-size: 11px; color: var(--text-3); font-variant-numeric: tabular-nums; }
.preset-grid button.active { border-color: var(--blue); background: rgba(137, 180, 250, 0.12); }
@media (max-width: 520px) { .preset-grid { grid-template-columns: repeat(3, 1fr); } }
.export-preview {
  display: grid;
  place-items: center;
  min-height: 120px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--r);
  background: repeating-conic-gradient(#1b1b27 0% 25%, #15151f 0% 50%) 0 0 / 12px 12px;
}
.export-preview canvas { image-rendering: pixelated; max-width: 100%; box-shadow: 0 6px 18px rgba(0, 0, 0, 0.45); }
.modal .seg { display: inline-grid; }
@media (max-width: 1100px) { .palette-btn { min-width: 0; } .palette-btn span, .palette-btn kbd { display: none; } }

.brand-home { display: flex; align-items: center; gap: 9px; text-decoration: none; }
.brand-home:hover h1 { color: var(--blue); }
