/* ── Editor panel ── */
#editor-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  justify-content: center;
  padding: 0;
  overflow: hidden; /* container handles scrolling via grid-container */
  min-height: 0; /* allow children to stretch
  */
}

/* editor header removed to eliminate top gap */

#grid-container {
  position: relative;
  line-height: 0;
  user-select: none;
  flex: 1; min-width: 0; min-height: 0;
  display: flex; align-items: flex-start; justify-content: flex-start;
  overflow: hidden; padding: 0; background: #1a1a1a; /* full-height dark bg */
}

/* panning cursor */
#grid-container.panning, #grid-container.panning canvas { cursor: grabbing !important; }

#grid-canvas {
  display: block;
  border: 1px solid #333;
  box-sizing: content-box; /* JS sets the drawing-area size; the border sits outside it */
}
/* what's drawn: the visible part of the canvas, at the screen's resolution (render.js); the pointer goes through to #grid-canvas */
#view-canvas { position: absolute; left: 0; top: 0; width: 100%; height: 100%; pointer-events: none; }

/* ── Preview panel ── */
#preview-panel {
  width: 220px;
  min-width: 180px;
  background: #111;
  border-left: 1px solid #2e2e2e;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  padding: 1rem 0.9rem;
  gap: 0.8rem;
}

/* inspector tabs */
#inspector-tabs { display:flex; gap:6px; width:100%; align-items: center; }
.tab-btn {
  padding: 0.35rem 0.6rem; cursor: pointer; border-radius:0px;
  background: transparent; color: #999; border:none; border-bottom: 2px solid transparent; font-size:0.82rem;
  transition: color 0.15s, border-color 0.15s;
}
.tab-btn:hover { color: #ccc; }
.tab-btn.active { background:transparent; border-color:#888; border-bottom: 2px solid #888; color:#ddd; }

#inspector-collapse-btn {
  background: #111; border: 1px solid #2e2e2e; color: #888; cursor: pointer;
  padding: 0; width: 24px; height: 32px; display: flex; align-items: center; justify-content: center;
  transition: color 0.15s;
  flex-shrink: 0;
  position: absolute;
  right: calc(220px + var(--dock-right-w, 0px));
  top: 1rem;
  z-index: 14;
  border-radius: 8px 0 0 8px;
  border-right: none;
}
#inspector-collapse-btn:hover { color: #ccc; }
#inspector-collapse-btn svg { width: 14px; height: 14px; }

#inspector-collapse-btn:not(.collapsed) svg {
  transform: none;
}

#inspector-collapse-btn.collapsed {
  right: var(--dock-right-w, 0px);
  border-radius: 8px 0 0 8px;
}

.tab-content { display:none; width:100%; }
.tab-content.active { display:block; }

#preview-panel.collapsed {
  display: none;
}

#preview-panel { overflow-y: auto; }

#preview-panel .panel-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  opacity: 0.4;
  align-self: flex-start;
  display: none;
}

.preview-bg.checker {
  background-image:
    linear-gradient(45deg, #333 25%, transparent 25%),
    linear-gradient(-45deg, #333 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #333 75%),
    linear-gradient(-45deg, transparent 75%, #333 75%);
  background-size: 8px 8px;
  background-position: 0 0, 0 4px, 4px -4px, -4px 0px;
}

/* ── Preview widget (floats beside inspector) ── */
#main { position: relative; }

/* same window frame as Layers / tool settings; placed by JS, draggable and dockable */
#preview-widget {
  position: fixed;
  z-index: 16;
  width: 220px;
  background: #161616;
  border: 1px solid #2e2e2e;
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.4);
  font-size: 0.78rem;
  display: flex;
  flex-direction: column;
}
#preview-win-header {
  display: flex; align-items: center; gap: 0.45rem;
  padding: 0.4rem 0.5rem 0.4rem 0.75rem;
  cursor: grab; user-select: none; touch-action: none;
  border-bottom: 1px solid #2e2e2e;
  border-radius: 8px 8px 0 0;
}
#preview-win-header > svg { color: #e0e0e0; opacity: 0.5; flex-shrink: 0; }
#preview-win-header:hover { background: #1e1e1e; }
#preview-widget.dragging #preview-win-header { cursor: grabbing; }
#preview-body {
  display: flex; flex-direction: column; align-items: center;
  gap: 0.5rem; padding: 0.55rem 0.75rem 0.75rem;
}
#preview-widget.minimized #preview-body { display: none; }
#preview-widget.minimized #preview-win-header { border-bottom: none; border-radius: 8px; }
#preview-widget.minimized .panel-min-btn[aria-expanded] svg { transform: rotate(180deg); }

/* ── Dock columns (windows snapped to the left/right edge) ── */
.dock {
  width: 290px; /* (DOCK_W in docking.js — Layers' Opacity, Lock alpha and blend mode in one row) */
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 8px;
  background: #111;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: #3a3a3a transparent;
}
.dock.empty { display: none; }
/* narrow rails at the outer edges: where the tools strip docks */
.rail {
  width: 64px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  background: #161616; /* the tools strip's own grey, running the full height */
}
.rail.empty { display: none; }
#rail-left { border-right: 1px solid #2e2e2e; }
#rail-right { border-left: 1px solid #2e2e2e; }
.rail > .docked {
  position: static !important;
  left: auto !important; top: auto !important; right: auto !important; bottom: auto !important;
  z-index: auto !important;
}
/* the docked tools strip blends into the rail: no card look (id selector to beat #tools-sidebar's own styles) */
.rail > #tools-sidebar.docked {
  box-shadow: none;
  border: none;
  border-radius: 0;
  background: transparent;
}
.rail > #tools-sidebar.docked #tools-sidebar-header { border-radius: 0; }
#tools-sidebar.dragging { z-index: 1000; }
#dock-left { border-right: 1px solid #2e2e2e; }
#dock-right { border-left: 1px solid #2e2e2e; }
/* a docked window becomes a section of the column */
.dock > .docked {
  position: static !important;
  left: auto !important; top: auto !important;
  width: auto !important; height: auto !important; max-height: none !important;
  min-width: 0 !important;
  z-index: auto !important; /* flex items honour z-index: don't sit above windows being dragged */
  flex-shrink: 0;
  box-shadow: none;
}
/* a window being dragged is always on top */
#layers-panel.dragging, #tool-settings.dragging, #preview-widget.dragging, #palette-panel.dragging, #colors-panel.dragging, #history-panel.dragging, #tileset-panel.dragging { z-index: 1000; }

/* ── Document colors window (same frame as History) ── */
#colors-panel {
  position: fixed; z-index: 16; width: 220px;
  background: #161616; border: 1px solid #2e2e2e; border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.4);
  font-size: 0.78rem;
  display: flex; flex-direction: column;
}
#colors-header {
  display: flex; align-items: center; gap: 0.45rem;
  padding: 0.4rem 0.5rem 0.4rem 0.75rem;
  cursor: grab; user-select: none; touch-action: none;
  border-bottom: 1px solid #2e2e2e; border-radius: 8px 8px 0 0;
}
#colors-header > svg { color: #e0e0e0; opacity: 0.5; flex-shrink: 0; }
#colors-header { gap: 0.35rem; }
#colors-header .ts-title { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
#colors-header .panel-min-btn { width: 22px; }
#colors-header:hover { background: #1e1e1e; }
#colors-panel.dragging #colors-header { cursor: grabbing; }
#colors-panel.minimized #colors-body { display: none; }
#colors-panel.minimized #colors-header { border-bottom: none; border-radius: 8px; }
#colors-panel.minimized .panel-min-btn[aria-expanded] svg { transform: rotate(180deg); }
#colors-body { display: flex; flex-direction: column; }
.pal-swatches {
  display: flex; flex-wrap: wrap; gap: 4px; padding: 10px;
  max-height: 220px; overflow-y: auto; scrollbar-width: thin; scrollbar-color: #3a3a3a transparent;
}
.pal-swatches:empty { display: none; }
.pal-sw {
  position: relative; width: 20px; height: 20px; padding: 0; border: 1px solid #0e0e0e; border-radius: 3px;
  cursor: pointer; font: inherit; font-size: 10px; font-weight: 700; line-height: 18px; text-align: center;
}
.pal-sw.is-fg { box-shadow: 0 0 0 1px #161616, 0 0 0 3px #fff; z-index: 1; }
.pal-sw.is-bg { outline: 2px solid #000; outline-offset: -3px; }
/* a color that isn't in the palette the drawing keeps to: a corner cut off it (palette.js) */
.pal-sw.off-pal::after { content: ''; position: absolute; top: -1px; right: -1px; width: 0; height: 0; border-top: 8px solid #ffc45a; border-left: 8px solid transparent; border-top-right-radius: 3px; pointer-events: none; }
/* the note (amber), and under it its two buttons: Remap, Add to palette */
.colors-remap { display: flex; flex-direction: column; gap: 6px; margin: 0 10px 10px; }
.colors-remap[hidden] { display: none; }
.colors-remap-note { padding: 6px 10px; border-radius: 6px; background: #2a2416; border: 1px solid #4a3d22; font-size: 0.74rem; color: #e8d3a6; }
.colors-remap-acts { display: flex; gap: 6px; }
.colors-remap-acts .btn { flex: 1; height: 26px; padding: 0 10px; }
/* hidden key numbers (header # button): the keys still work */
#colors-panel.hide-keys .pal-sw span { display: none; }
/* reordering: the dragged swatch is lifted, the rest make room */
.pal-swatches.reordering, .pal-swatches.reordering .pal-sw { cursor: grabbing; }
.pal-sw.dragging { transform: scale(1.18); box-shadow: 0 0 0 2px #4a7fcb, 0 4px 10px rgba(0,0,0,0.5); z-index: 2; }
/* header: # shows / hides the key numbers */
.colors-keys-btn { width: 24px; font: 700 12px/1 ui-monospace, Consolas, monospace; color: #777; }
.colors-keys-btn.active { color: #e0e0e0; border-color: #4a7fcb; background: #1a3558; }
.colors-keys-btn + .panel-min-btn { margin-left: 0; }

/* ── History window ── */
#history-panel {
  position: fixed; z-index: 16; width: 220px;
  background: #161616; border: 1px solid #2e2e2e; border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.4);
  font-size: 0.78rem;
  display: flex; flex-direction: column;
}
#history-header {
  display: flex; align-items: center; gap: 0.45rem;
  padding: 0.4rem 0.5rem 0.4rem 0.75rem;
  cursor: grab; user-select: none; touch-action: none;
  border-bottom: 1px solid #2e2e2e; border-radius: 8px 8px 0 0;
}
#history-header > svg { color: #e0e0e0; opacity: 0.5; flex-shrink: 0; }
#history-header:hover { background: #1e1e1e; }
#history-panel.dragging #history-header { cursor: grabbing; }
#history-panel.minimized #history-body { display: none; }
#history-panel.minimized #history-header { border-bottom: none; border-radius: 8px; }
#history-panel.minimized .panel-min-btn[aria-expanded] svg { transform: rotate(180deg); }
.hist-count { margin-left: auto; font-size: 0.68rem; opacity: 0.45; font-variant-numeric: tabular-nums; }
.hist-count + .panel-min-btn { margin-left: 0; }
#history-list {
  max-height: 260px; overflow-y: auto; padding: 4px;
  scrollbar-width: thin; scrollbar-color: #3a3a3a transparent;
}
.hist-row {
  display: flex; align-items: center; gap: 8px;
  padding: 4px 8px; border-radius: 5px; border: 1px solid transparent;
  cursor: pointer; user-select: none; white-space: nowrap;
}
.hist-row:hover { background: #1f1f1f; }
.hist-row.current { background: #1a3558; border-color: #4a7fcb; color: #fff; }
.hist-row.future { opacity: 0.4; font-style: italic; } /* undone steps (redo-able until a new edit) */
.hist-row svg { width: 14px; height: 14px; flex-shrink: 0; opacity: 0.8; }
.hist-label { overflow: hidden; text-overflow: ellipsis; }
#history-actions { display: flex; align-items: center; gap: 4px; padding: 6px 8px 8px; border-top: 1px solid #2a2a2a; }

/* ── Tileset window (tile layers — tilemap.js) ── */
#tileset-panel {
  position: fixed; z-index: 16; width: 220px;
  background: #161616; border: 1px solid #2e2e2e; border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.4);
  font-size: 0.78rem;
  display: flex; flex-direction: column;
}
#tileset-header {
  display: flex; align-items: center; gap: 0.45rem;
  padding: 0.4rem 0.5rem 0.4rem 0.75rem;
  cursor: grab; user-select: none; touch-action: none;
  border-bottom: 1px solid #2e2e2e; border-radius: 8px 8px 0 0;
}
#tileset-header > svg { color: #e0e0e0; opacity: 0.5; flex-shrink: 0; }
#tileset-header:hover { background: #1e1e1e; }
#tileset-panel.dragging #tileset-header { cursor: grabbing; }
#tileset-panel.minimized #tileset-body { display: none; }
#tileset-panel.minimized #tileset-header { border-bottom: none; border-radius: 8px; }
#tileset-panel.minimized .panel-min-btn[aria-expanded] svg { transform: rotate(180deg); }
#tileset-count + .panel-min-btn, #tileset-numbers + .panel-min-btn { margin-left: 0; }
#tileset-body { padding: 8px; display: flex; flex-direction: column; gap: 8px; }
.tileset-row { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.tileset-hint { color: #8a8a8a; line-height: 1.4; font-size: 0.74rem; }
#tileset-panel .seg .btn { padding: 3px 10px; border: none; border-radius: 0; background: transparent; color: #bbb; font-size: 0.74rem; cursor: pointer; }
#tileset-panel .seg .btn + .btn { border-left: 1px solid #3a3a3a; }
#tileset-panel .seg .btn:hover { background: #2a2a2a; color: #fff; }
#tileset-panel .seg .btn.active { background: #4a7fcb; color: #fff; }
#tileset-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(40px, 1fr)); gap: 4px;
  max-height: 220px; overflow-y: auto; scrollbar-width: thin; scrollbar-color: #3a3a3a transparent;
}
#tileset-grid .tileset-hint { grid-column: 1 / -1; }
.tileset-tile {
  position: relative; aspect-ratio: 1; padding: 3px; border: 1px solid #2e2e2e; border-radius: 4px; cursor: pointer;
  background: repeating-conic-gradient(#2a2a2a 0 25%, #222 0 50%) 0 0 / 8px 8px;
}
.tileset-tile:hover { border-color: #5a5a5a; }
.tileset-tile.active { border-color: #ffc45a; box-shadow: 0 0 0 1px #ffc45a; }
.tileset-tile canvas { width: 100%; height: 100%; image-rendering: pixelated; display: block; object-fit: contain; }
/* the options bar's Tile group (Tiles mode): the tile to place, as it's turned — Flip / Rotate, Upright */
#tileset-turn-pic { width: 26px; height: 26px; flex-shrink: 0; image-rendering: pixelated; border: 1px solid #3a3a3a; border-radius: 4px; background: repeating-conic-gradient(#2a2a2a 0 25%, #222 0 50%) 0 0 / 8px 8px; box-sizing: border-box; }
#tileset-turn-pic.turned { border-color: #ffc45a; }
#tileset-turn-pic[hidden], #tileset-cells[hidden] { display: none; }
#tileset-on .ts-icon-btn[hidden], #tileset-restyle[hidden], #tileset-restyle-color[hidden] { display: none; }
/* the color Restyle uses (the foreground), beside it — click: the color chooser */
.tileset-color { width: 26px; height: 26px; padding: 0; border: 1px solid #555; border-radius: 4px; cursor: pointer; flex-shrink: 0; box-shadow: inset 0 0 0 1px rgba(0,0,0,0.35); }
.tileset-color:hover { border-color: #888; }
.tileset-color.is-transparent { background: repeating-conic-gradient(#3a3a3a 0 25%, #262626 0 50%) 0 0 / 8px 8px; }
/* a terrain's tiles: each labelled by its corners (▘ top-left…), bigger to read */
#tileset-grid.terrain .tileset-n { font-size: 0.8rem; line-height: 1; padding: 1px 2px; letter-spacing: 0; }
#tileset-turns .btn:disabled { opacity: 0.35; cursor: default; }
#tileset-turn-reset:disabled { opacity: 0.4; cursor: default; }
/* a new tile map or terrain layer: its tile size, then the two kinds side by side (marked as in Layers) */
.tileset-new:not([hidden]) { display: flex; flex-direction: column; gap: 8px; }
#tileset-on:not([hidden]) + .tileset-new, #tileset-none:not([hidden]) ~ .tileset-new { padding-top: 10px; border-top: 1px solid #2a2a2a; }
.tileset-new-head { display: flex; align-items: baseline; justify-content: space-between; }
.tileset-new-label { font-size: 0.66rem; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: #8a8a8a; }
.tileset-new-note { font-size: 0.7rem; color: #666; }
.tileset-size { display: flex; align-items: center; gap: 6px; }
.tileset-size .num-field { flex: 1; min-width: 0; }
.tileset-size .num-field input { width: 100%; min-width: 0; text-align: center; }
.tileset-x { color: #777; font-size: 0.74rem; }
/* the chain between W and H: linked (the same value), or broken (each its own) */
.tileset-link { display: flex; align-items: center; justify-content: center; width: 24px; height: 24px; flex-shrink: 0; padding: 0; border: 1px solid transparent; border-radius: 4px; background: transparent; color: #777; cursor: pointer; }
.tileset-link:hover { color: #e0e0e0; background: #2a2a2a; }
.tileset-link:focus-visible { outline: none; border-color: #4a7fcb; }
.tileset-link.on { color: #8fb4f0; }
.tileset-link .tl-off, .tileset-link.on .tl-on { display: block; }
.tileset-link .tl-on, .tileset-link.on .tl-off { display: none; }
.tileset-makes { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
#tileset-panel .tileset-make { display: flex; align-items: center; justify-content: center; gap: 6px; height: 30px; padding: 0 6px; white-space: nowrap; }
.tileset-make .tm-mark { color: #ffc45a; flex-shrink: 0; }
.tileset-make .tr-mark { color: #7cc46a; flex-shrink: 0; }
#tileset-help { min-height: 2.8em; }
#tileset-pick { width: 100%; }
#tileset-pick[hidden] { display: none; }
.tmc-anim { color: #d8c49a; }
#tm-convert .tileset-row { flex-direction: row; flex-wrap: nowrap; gap: 10px; }
.tiles-menu { z-index: 1130; max-height: min(70vh, 480px); overflow-y: auto; }
.tiles-menu button.active b { color: #8fb4e8; }
.tiles-menu hr { width: 100%; margin: 3px 0; border: none; border-top: 1px solid #2e2e2e; }
.tileset-n { position: absolute; right: 2px; bottom: 1px; font-size: 0.6rem; color: #ddd; text-shadow: 0 0 2px #000, 0 0 2px #000; pointer-events: none; }

/* ── Tile window (tile-editor.js): a canvas of its own ── */
#tile-editor {
  position: fixed; z-index: 16; width: 260px;
  background: #161616; border: 1px solid #2e2e2e; border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.4);
  font-size: 0.78rem;
  display: flex; flex-direction: column;
}
#tile-editor-header {
  display: flex; align-items: center; gap: 0.45rem;
  padding: 0.4rem 0.5rem 0.4rem 0.75rem;
  cursor: grab; user-select: none; touch-action: none;
  border-bottom: 1px solid #2e2e2e; border-radius: 8px 8px 0 0;
}
#tile-editor-header > svg { color: #e0e0e0; opacity: 0.5; flex-shrink: 0; }
#tile-editor-header:hover { background: #1e1e1e; }
#tile-editor.dragging { z-index: 1000; }
#tile-editor-header .seg { margin-left: auto; }
#tile-editor-header .seg .btn { padding: 2px 8px; border: none; border-radius: 0; background: transparent; color: #bbb; font-size: 0.72rem; cursor: pointer; }
#tile-editor-header .seg .btn + .btn { border-left: 1px solid #3a3a3a; }
#tile-editor-header .seg .btn.active { background: #4a7fcb; color: #fff; }
#tile-ed-close { margin-left: 0; }
#tile-editor { height: 280px; min-height: 160px; } /* resized from any edge (docking.js makeResizable) */
#tile-editor.docked { height: 280px !important; }
#tile-area {
  position: relative; flex: 1 1 auto; min-height: 0; overflow: hidden; line-height: 0; user-select: none; touch-action: none;
  display: flex; align-items: flex-start; justify-content: flex-start; background: #1a1a1a; border-radius: 0 0 8px 8px;
}
#tile-grid-canvas { display: block; border: 1px solid #333; box-sizing: content-box; }
#tile-view-canvas { position: absolute; left: 0; top: 0; width: 100%; height: 100%; pointer-events: none; }

/* ── Palette window (same frame as Preview / Layers) ── */
#palette-panel {
  position: fixed; z-index: 16;
  background: #161616; border: 1px solid #2e2e2e; border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.4);
  font-size: 0.78rem;
  display: flex; flex-direction: column;
}
#palette-header {
  display: flex; align-items: center; gap: 0.45rem;
  padding: 0.4rem 0.5rem 0.4rem 0.75rem;
  cursor: grab; user-select: none; touch-action: none;
  border-bottom: 1px solid #2e2e2e; border-radius: 8px 8px 0 0;
}
#palette-header > svg { color: #e0e0e0; opacity: 0.5; flex-shrink: 0; }
#palette-header:hover { background: #1e1e1e; }
#palette-panel.dragging #palette-header { cursor: grabbing; }
#palette-panel.minimized #palette-body { display: none; }
#palette-panel.minimized #palette-header { border-bottom: none; border-radius: 8px; }
#palette-panel.minimized .panel-min-btn[aria-expanded] svg { transform: rotate(180deg); }
#palette-body { padding: 8px 8px 10px; display: flex; flex-direction: column; gap: 8px; align-items: center; }
/* shade cube */
.pal-cube-row { display: flex; flex-direction: column; align-items: center; gap: 6px; align-self: stretch; padding: 4px 0 8px; } /* (room under the hex row, above the colors) */
#pal-cube { flex-shrink: 0; overflow: visible; }
.pal-hex-row { display: flex; align-items: center; gap: 8px; align-self: stretch; }
.pal-fgbg { position: relative; width: 32px; height: 32px; flex-shrink: 0; }
.pal-fgbg .color-sq { width: 20px; height: 20px; cursor: default; }
.pal-fgbg .color-sq:hover { border-color: #d8d8d8; transform: none; }
/* Transparent chip shows when it is the foreground (white ring) or background (black ring) */
#pal-transparent.is-fg { box-shadow: 0 0 0 2px #161616, 0 0 0 4px #fff; }
#pal-transparent.is-bg { outline: 2px solid #000; outline-offset: -2px; }
.pal-fgbg .color-sq.fg { left: 1px; top: 1px; }
.pal-fgbg .color-sq.bg { right: 1px; bottom: 1px; }
#pal-transparent { width: 26px; height: 26px; }
#pal-hex {
  flex: 1; min-width: 0; height: 26px; padding: 0 8px; text-align: center;
  background: #1e1e1e; border: 1px solid #3a3a3a; border-radius: 4px;
  color: #e0e0e0; font: inherit; font-size: 0.78rem; font-family: ui-monospace, Consolas, monospace; outline: none;
}
#pal-hex:focus { border-color: #4a7fcb; }
#pal-hex.invalid { border-color: #e5484d; }
/* palette dropdown (src/palettes.js) */
/* a dropdown button (the palette's, Export's tag): .dd-select is the same look for other dropdowns */
.pal-select, .dd-select {
  align-self: stretch; display: flex; align-items: center; gap: 8px;
  height: 28px; padding: 0 8px 0 10px;
  background: #1e1e1e; border: 1px solid #3a3a3a; border-radius: 6px;
  color: #e0e0e0; font: inherit; font-size: 0.78rem; cursor: pointer; text-align: left;
}
.pal-select:hover, .dd-select:hover { border-color: #555; background: #232323; }
.pal-select[aria-expanded="true"], .dd-select[aria-expanded="true"] { border-color: #4a7fcb; }
/* focused (a mode just picked: ↑ ↓ go on from it) — lit, so it's clear where the keys go */
.dd-select:focus { outline: none; border-color: #4a7fcb; box-shadow: 0 0 0 2px #4a7fcb59; }
.pal-select-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.pal-select-count { color: #777; font-size: 0.7rem; font-variant-numeric: tabular-nums; }
.pal-select svg, .dd-select svg { color: #999; flex-shrink: 0; transition: transform 0.15s; }
.pal-select[aria-expanded="true"] svg, .dd-select[aria-expanded="true"] svg { transform: rotate(180deg); }
/* the dropdown and the pencil (edit this palette) */
.pal-select-row { display: flex; gap: 6px; align-self: stretch; }
.pal-select-row .pal-select { flex: 1; min-width: 0; }
.pal-edit-btn {
  width: 28px; height: 28px; flex-shrink: 0; padding: 0; display: flex; align-items: center; justify-content: center;
  background: #1e1e1e; border: 1px solid #3a3a3a; border-radius: 6px; color: #aaa; cursor: pointer;
}
.pal-edit-btn:hover { border-color: #555; color: #e0e0e0; }
.pal-edit-btn[aria-pressed="true"] { background: #1a3558; border-color: #4a7fcb; color: #fff; }
/* the edit bar, above the grid */
.pal-edit-bar { align-self: stretch; display: flex; flex-direction: column; gap: 6px; padding: 8px; background: #1b1b1b; border: 1px solid #2e2e2e; border-radius: 6px; }
.pal-edit-bar[hidden] { display: none; }
#pal-edit-name {
  height: 26px; padding: 0 8px; background: #121212; border: 1px solid #3a3a3a; border-radius: 5px;
  color: #e0e0e0; font: inherit; font-weight: 600; outline: none;
}
#pal-edit-name:focus { border-color: #4a7fcb; }
.pal-edit-tools { display: flex; gap: 4px; }
.pal-edit-tools button {
  height: 26px; min-width: 26px; padding: 0 7px; display: flex; align-items: center; justify-content: center; gap: 5px;
  background: #232323; border: 1px solid #333; border-radius: 5px; color: #ddd; font: inherit; cursor: pointer;
}
.pal-edit-tools button:hover:not(:disabled) { background: #2c2c2c; border-color: #4a4a4a; }
.pal-edit-tools button:disabled { opacity: 0.4; cursor: default; }
.pal-edit-tools .pal-edit-done { margin-left: auto; background: #4a7fcb; border-color: #4a7fcb; color: #fff; font-weight: 600; }
.pal-edit-tools .pal-edit-done:hover:not(:disabled) { background: #5b8fdb; border-color: #5b8fdb; }
.pal-edit-note { font-size: 0.68rem; color: #8a8a8a; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; } /* one line: the grid below doesn't move */
#pal-grid:focus { outline: none; }
#palette-panel.pal-editing #pal-grid { cursor: grab; }
#pal-grid.reordering { cursor: grabbing !important; }
.pal-export-menu { width: 230px; padding: 4px; }
.pal-export-menu .pal-menu-file { border: none; border-radius: 5px; flex-direction: column; align-items: flex-start; gap: 1px; padding: 6px 8px; }
.pal-export-menu .pal-menu-file span { color: #8a8a8a; font-size: 0.7rem; }
.pal-menu {
  position: fixed; z-index: 2700; max-height: 320px; display: flex; flex-direction: column; /* above the color picker (it has the dropdown too) */
  background: #1c1c1c; border: 1px solid #3a3a3a; border-radius: 8px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.55); font-size: 0.78rem; color: #e0e0e0; overflow: hidden;
}
.pal-menu[hidden] { display: none; }
.pal-menu-list { flex: 1 1 auto; min-height: 0; overflow-y: auto; padding: 4px; scrollbar-width: thin; scrollbar-color: #3a3a3a transparent; }
.pal-menu-head { padding: 7px 8px 3px; font-size: 0.66rem; color: #8a8a8a; text-transform: uppercase; letter-spacing: 0.05em; }
.pal-menu-item { display: flex; flex-direction: column; gap: 4px; padding: 6px 8px 7px; border-radius: 5px; cursor: pointer; }
.pal-menu-top { display: flex; align-items: center; gap: 8px; min-height: 18px; }
.pal-menu-item:hover { background: #262626; }
.pal-menu-item.selected { background: #1a3558; }
.pal-menu-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pal-menu-count { color: #777; font-size: 0.7rem; font-variant-numeric: tabular-nums; }
.pal-strip { display: flex; width: 100%; height: 12px; border-radius: 3px; overflow: hidden; box-shadow: 0 0 0 1px #0e0e0e; }
.pal-strip i { flex: 1; min-width: 0; }
.pal-menu-del {
  width: 18px; height: 18px; margin-left: -4px; padding: 0; display: none; align-items: center; justify-content: center;
  background: none; border: none; border-radius: 4px; color: #888; cursor: pointer; flex-shrink: 0;
}
.pal-menu-item:hover .pal-menu-del { display: flex; }
.pal-menu-item:hover .pal-menu-count:has(+ .pal-menu-del) { display: none; }
.pal-menu-del:hover { background: #4a2020; color: #ff8a8a; }
.pal-menu-file {
  flex-shrink: 0; display: flex; align-items: center; gap: 8px; width: 100%; padding: 8px 10px;
  border: none; border-top: 1px solid #2e2e2e; background: #1c1c1c; color: #e0e0e0; font: inherit; text-align: left; cursor: pointer;
}
.pal-menu-file:hover { background: #262626; }
.pal-menu-file svg { color: #aaa; flex-shrink: 0; }
.pal-menu-add { flex-shrink: 0; display: flex; border-top: 1px solid #2e2e2e; }
.pal-menu-add .pal-menu-file { flex: 1; min-width: 0; border-top: none; white-space: nowrap; }
.pal-menu-add .pal-menu-file + .pal-menu-file { border-left: 1px solid #2e2e2e; }
/* Add palette from Lospec, opened: the field in the row's place */
.pal-lospec { flex-shrink: 0; padding: 7px 8px 7px; border-top: 1px solid #242424; background: #1c1c1c; }
.pal-lospec-row { display: flex; align-items: center; gap: 5px; }
.pal-lospec input {
  flex: 1; min-width: 0; height: 26px; padding: 0 8px; background: #121212; border: 1px solid #3a3a3a; border-radius: 5px;
  color: #e0e0e0; font: inherit; outline: none;
}
.pal-lospec input:focus { border-color: #4a7fcb; }
.pal-lospec input:disabled { opacity: 0.6; }
.pal-lospec-go {
  height: 26px; padding: 0 10px; border: none; border-radius: 5px; background: #4a7fcb; color: #fff; font: inherit; font-weight: 600; cursor: pointer;
}
.pal-lospec-go:hover:not(:disabled) { background: #5b8fdb; }
.pal-lospec-go:disabled { opacity: 0.7; cursor: default; }
.pal-lospec-x {
  width: 22px; height: 26px; padding: 0; display: flex; align-items: center; justify-content: center;
  background: none; border: none; border-radius: 4px; color: #888; cursor: pointer;
}
.pal-lospec-x:hover { background: #262626; color: #e0e0e0; }
.pal-lospec-note { margin: 5px 2px 0; font-size: 0.7rem; color: #8a8a8a; }
.pal-lospec-note a { color: #8fb4e8; text-decoration: none; }
.pal-lospec-note a:hover { text-decoration: underline; }
.pal-lospec-note.error { color: #ff8a8a; }
/* in the color picker: smaller, over the grid */
.pal-select-sm { width: 100%; height: 24px; margin: 0 0 6px; padding: 0 6px 0 8px; font-size: 0.72rem; }
.cube-face { stroke: #0e0e0e; stroke-width: 1; stroke-linejoin: round; cursor: pointer; }
/* over a dock: see-through, so the dock and the drop line show beneath it */
.dock-hover { opacity: 0.6; transition: opacity 0.12s; }
.dock > .docked .rz { display: none; }
/* snap preview while dragging a window near an edge */
#dock-preview { position: fixed; z-index: 1001; pointer-events: none; } /* above the dragged window */
#dock-preview.zone { background: #4a7fcb22; border: 2px dashed #4a7fcb; border-radius: 8px; }
#dock-preview.line { height: 3px; background: #4a7fcb; border-radius: 2px; box-shadow: 0 0 8px #4a7fcbaa; }

#preview-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  width: 100%;
}

/* preview window rows */
.pv-row { display: flex; align-items: center; gap: 6px; width: 100%; }
.pv-btn { width: 24px; height: 24px; flex-shrink: 0; }
#preview-zoom-label {
  width: 38px; flex-shrink: 0;
  text-align: right;
  font-size: 0.72rem;
  font-variant-numeric: tabular-nums;
  opacity: 0.7;
  white-space: nowrap;
}
#preview-zoom-slider {
  flex: 1; min-width: 0; width: auto; margin: 0;
  accent-color: #4a7fcb;
  cursor: pointer;
}
.pv-seg { position: relative; display: flex; align-items: center; gap: 4px; margin-left: auto; }

#preview-viewport {
  width: 100%;
  aspect-ratio: 1;
  overflow: hidden;
  border-radius: 4px;
  border: 1px solid #2e2e2e;
  display: flex;
  align-items: center;
  justify-content: center;
  background-image:
    linear-gradient(45deg, #999 25%, transparent 25%),
    linear-gradient(-45deg, #999 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #999 75%),
    linear-gradient(-45deg, transparent 75%, #999 75%);
  background-size: 8px 8px;
  background-position: 0 0, 0 4px, 4px -4px, -4px 0px;
  background-color: #bbb;
}
/* solid background: just the artwork on a plain color */
#preview-viewport.solid { background-image: none; background-color: var(--pv-bg, #161616); }

#preview-canvas { display: block; image-rendering: pixelated; }

#ts-minimize { display: none; }

/* ── The timeline: the animation's frames, under the canvas (src/timeline.js) ── */
#timeline { position: relative; height: 200px; flex-shrink: 0; display: flex; flex-direction: column; background: #161616; border-top: 1px solid #2e2e2e; font-size: 0.75rem; color: #ccc; }
.tl-bar { grid-column: -2; grid-row: 1; display: flex; align-items: center; gap: 10px; padding: 5px 10px; min-height: 34px; flex-wrap: wrap; min-width: 0; border-bottom: 1px solid #2a2a2a; }
.tl-title { font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.06em; color: #8a8a8a; }
.tl-group { display: inline-flex; border: 1px solid #333; border-radius: 6px; overflow: hidden; }
.tl-group .tl-btn { border: none; border-radius: 0; }
.tl-group .tl-btn + .tl-btn { border-left: 1px solid #333; }
.tl-btn {
  height: 26px; min-width: 28px; padding: 0 6px; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  background: #1e1e1e; border: 1px solid #333; border-radius: 6px; color: #bbb; font: inherit; cursor: pointer;
}
.tl-btn:hover:not(:disabled) { background: #262626; color: #fff; }
.tl-btn:disabled { opacity: 0.35; cursor: default; }
.tl-play .ic-stop, .tl-play.on .ic-play { display: none; }
.tl-play.on .ic-stop { display: block; }
.tl-play.on { background: #4a7fcb; color: #fff; }
.tl-toggle[aria-pressed="true"] { background: #1a3558; border-color: #4a7fcb; color: #fff; }
/* Onion skin and its ▾ (settings): one split button */
.tl-onion-more { min-width: 20px; padding: 0 4px; color: #999; }
.tl-onion-more[aria-expanded="true"] { background: #ffffff14; color: #fff; }
.tl-onion-more[aria-expanded="true"] svg { transform: rotate(180deg); }
.tl-dur { display: inline-flex; align-items: center; gap: 5px; color: #8a8a8a; }
.tl-dur input {
  width: 52px; height: 24px; padding: 0 6px; background: #121212; border: 1px solid #3a3a3a; border-radius: 5px;
  color: #e0e0e0; font: inherit; text-align: right; font-variant-numeric: tabular-nums; outline: none;
}
.tl-dur input:focus { border-color: #4a7fcb; }
.tl-link { background: none; border: none; color: #8fb4e8; font: inherit; cursor: pointer; padding: 0; }
.tl-link:hover { text-decoration: underline; }
.tl-count { margin-left: auto; color: #8a8a8a; font-variant-numeric: tabular-nums; }
.tl-fold svg { transition: transform 0.15s; }
#timeline.folded .tl-fold svg { transform: rotate(180deg); }
#timeline.folded { height: auto !important; }
#timeline.folded .tl-grid, #timeline.folded .tl-layers, #timeline.folded .tl-layers-title, #timeline.folded .tl-resize,
#timeline.folded.with-layers .tl-layers, #timeline.folded.with-layers .tl-layers-title { display: none; }
#timeline.folded .tl-body, #timeline.folded.with-layers .tl-body { grid-template-columns: minmax(0, 1fr); }
#timeline.folded .tl-bar { border-bottom: none; }
/* drag the top edge to resize */
.tl-resize { position: absolute; left: 0; right: 0; top: -4px; height: 8px; z-index: 5; cursor: ns-resize; touch-action: none; }
.tl-resize:hover, html.resizing-s .tl-resize { background: linear-gradient(transparent 3px, #4a7fcb 3px 5px, transparent 5px); }
.tl-time { color: #8a8a8a; font-variant-numeric: tabular-nums; }
/* the body: Layers (left: its title beside the bar, its rows beside the frames) and the timeline (right: its
   bar over the frames grid); a layer's row in both lines up. Without Layers in it: the timeline alone */
.tl-body { --tl-tags: 20px; --tl-ruler: 30px; --tl-row: 38px; flex: 1 1 auto; min-height: 0; display: grid; grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr); }
#timeline.with-layers .tl-body { grid-template-columns: 290px minmax(0, 1fr); }
.tl-layers-title, .tl-layers { display: none; }
#timeline.with-layers .tl-layers-title { display: flex; grid-column: 1; grid-row: 1; align-items: center; padding: 0 10px; font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.06em; color: #8a8a8a; border-right: 1px solid #2e2e2e; border-bottom: 1px solid #2a2a2a; }
#timeline.with-layers .tl-layers { display: flex; grid-column: 1; grid-row: 2; min-height: 0; border-right: 1px solid #2e2e2e; }
.tl-grid { grid-column: -2; grid-row: 2; min-width: 0; min-height: 0; overflow: auto; position: relative; scrollbar-width: thin; scrollbar-color: #3a3a3a transparent; }
.tl-inner { position: relative; min-height: 100%; min-width: 100%; box-sizing: border-box; }
.tl-ruler { position: sticky; top: var(--tl-tags); z-index: 3; display: flex; height: var(--tl-ruler); box-sizing: border-box; background: #161616; border-bottom: 1px solid #2a2a2a; }
.tl-slot {
  flex: 0 0 34px; display: flex; align-items: center; justify-content: center; box-sizing: border-box;
  border-right: 1px solid #222; color: #8a8a8a; font-size: 0.66rem; font-variant-numeric: tabular-nums; cursor: pointer; user-select: none;
}
.tl-slot:hover { color: #fff; }
.tl-slot.spare { color: #444; cursor: default; }
.tl-slot.current { color: #fff; background: #4a7fcb; }
.tl-slot.in-frame { color: #cfe0f7; background: #1a3558; }
.tl-slot.sel:not(.current) { box-shadow: inset 0 -3px #8fb4e8; }
.tl-ruler { cursor: ew-resize; }
/* the selected slots (and rows): a see-through blue over the frames */
.tl-sel { position: absolute; z-index: 2; pointer-events: none; box-sizing: border-box; border: 2px solid #8fb4e8; border-radius: 4px; background: #8fb4e859; }
/* the selection's left and right edges: grab one to slide the frames selected together */
.tl-sel-edge { position: absolute; top: -2px; bottom: -2px; width: 8px; pointer-events: auto; cursor: ew-resize; touch-action: none; z-index: 3; }
.tl-sel-edge.left { left: -11px; } /* (just outside the box: the blocks inside stay clickable) */
.tl-sel-edge.right { right: -11px; }
.tl-sel-edge::after { content: ''; position: absolute; left: 2px; top: 50%; height: 18px; margin-top: -9px; width: 4px; border-radius: 2px; background: #8fb4e8; box-shadow: 0 0 0 1px #0006; }
.tl-sel-edge:hover::after { background: #cfe0f7; }
/* where moved frames will land */
.tl-drop { position: absolute; z-index: 4; top: 0; bottom: 0; width: 3px; margin-left: -1px; background: #4a7fcb; border-radius: 2px; box-shadow: 0 0 6px #4a7fcbaa; pointer-events: none; }
.tl-playhead { position: absolute; top: calc(var(--tl-tags) + var(--tl-ruler)); bottom: 0; z-index: 2; pointer-events: none; background: #4a7fcb40; box-shadow: inset 1px 0 #4a7fcb99, inset -1px 0 #4a7fcb99; }
.tl-row { position: relative; height: var(--tl-row); box-sizing: border-box; border-bottom: 1px solid #1d1d1d; }
/* a group's row (over its layers'): a bar where any of them has a picture; a closed group's layers' rows hidden */
.tl-grow { position: relative; height: var(--tl-row); box-sizing: border-box; border-bottom: 1px solid #1d1d1d; background: #1b1b1b; }
.tl-gbar { position: absolute; top: 50%; height: 8px; margin-top: -4px; border-radius: 4px; background: #4a7fcb55; border: 1px solid #4a7fcb88; box-sizing: border-box; }
.tl-grow.hidden-layer .tl-gbar { opacity: 0.4; }
.tl-row.tl-collapsed { display: none; }
.tl-row.active { background: #ffffff07; }
.tl-cel {
  position: absolute; top: 3px; bottom: 3px; box-sizing: border-box; display: flex; align-items: center; padding-left: 2px;
  background: #1f1f1f; border: 1px solid #333; border-radius: 4px; cursor: pointer; touch-action: none; user-select: none;
}
.tl-cel:hover { border-color: #555; }
.tl-cel.empty { background: transparent; border-style: dashed; border-color: #2c2c2c; }
.tl-cel.cur-frame { border-color: #3e5f8e; }
.tl-cel.current { border-color: #4a7fcb; background: #1a3558; box-shadow: 0 0 0 1px #4a7fcb; }
.tl-cel.drop { box-shadow: -3px 0 0 #4a7fcb; }
/* linked keys: a chain in the corner; those linked to the key the playhead's on, outlined */
.tl-link { position: absolute; top: 1px; right: 3px; display: flex; color: #8fb4e8; pointer-events: none; }
.tl-cel.link-hl { border-color: #8fb4e8; border-style: dashed; }
#tl-menu [hidden], #layer-menu [hidden], #eye-menu [hidden] { display: none; }
/* Layer properties (layer-props.js): name, blend mode, opacity */
#layer-props { width: 260px; }
#layer-props .dd-select { width: 100%; flex-direction: row; align-items: center; gap: 8px; height: 28px; padding: 0 8px 0 10px; border: 1px solid #3a3a3a; border-radius: 6px; background: #1e1e1e; font-size: 0.78rem; }
#layer-props .dd-select:hover { border-color: #555; background: #232323; }
#layer-props .dd-select[aria-expanded="true"] { border-color: #4a7fcb; }
#layer-props .tag-pop-foot .btn:not(.crop-apply) { background: #2a2a2a; border: 1px solid #3a3a3a; border-radius: 4px; }
#layer-props .tag-pop-foot .btn:not(.crop-apply):hover { background: #383838; border-color: #555; }
#lp-blend-menu { z-index: 1130; min-width: 0; width: max-content; max-height: min(70vh, 520px); overflow-y: auto; } /* (as wide as its longest name) */
#lp-blend-menu button { padding: 5px 10px; }
#lp-blend-menu button.active b { color: #8fb4e8; }
#lp-blend-menu hr { width: 100%; margin: 3px 0; border: none; border-top: 1px solid #2e2e2e; }
/* a layer not in Normal: its blend mode beside its name */
.layer-blend { flex-shrink: 0; font-size: 0.66rem; color: #8fb4e8; opacity: 0.85; }
/* Paste › and Duplicate ›: an arrow on their item; the submenu beside it */
.tlm-has-sub { display: flex; flex-direction: column; }
.tlm-has-sub > button { position: relative; padding-right: 26px; }
.tlm-has-sub > button::after { content: ''; position: absolute; right: 11px; top: 50%; width: 6px; height: 6px; margin-top: -4px; border: solid #888; border-width: 1.6px 1.6px 0 0; transform: rotate(45deg); }
.tlm-has-sub > button[aria-expanded="true"] { background: #ffffff12; }
.tlm-sub { z-index: 1110; min-width: 220px; }
/* the onion skin's reach over the numbers: red before, blue after; a handle at each outer end to pull */
.tl-onion { position: absolute; top: 0; bottom: 0; z-index: 1; pointer-events: none; }
.tl-onion.before { background: #e5484d2e; box-shadow: inset 0 2px #e5484d; }
.tl-onion.after { background: #4a9eff2e; box-shadow: inset 0 2px #4a9eff; }
.tl-onion-handle { position: absolute; top: 0; bottom: 0; width: 10px; pointer-events: auto; cursor: ew-resize; touch-action: none; }
.tl-onion.before .tl-onion-handle { left: -5px; }
.tl-onion.after .tl-onion-handle { right: -5px; }
.tl-onion-handle::after { content: ''; position: absolute; left: 3px; top: 4px; bottom: 4px; width: 4px; border-radius: 2px; }
.tl-onion.before .tl-onion-handle::after { background: #e5484d; }
.tl-onion.after .tl-onion-handle::after { background: #4a9eff; }
.tl-onion-handle:hover::after { box-shadow: 0 0 0 2px #ffffff40; }
/* a key not fully opaque: its percent in the corner */
.tl-op.fade { color: #cfe0f7; }
/* a fading key: its opacity across the block, a see-through area (high = solid) */
.tl-curve { position: absolute; left: 1px; top: 3px; width: calc(100% - 3px); height: calc(100% - 4px); overflow: visible; pointer-events: none; z-index: 1; }
.tl-curve polygon { fill: #ffffff52; stroke: none; }
.tl-op { position: absolute; left: 3px; bottom: 1px; z-index: 2; max-width: calc(100% - 8px); overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font-size: 0.56rem; line-height: 1.2; color: #ddd; background: #000a; padding: 0 2px; border-radius: 2px; pointer-events: none; }
/* small windows by the timeline: key opacity, onion skin settings */
.tl-pop { width: 240px; padding: 12px; gap: 6px; z-index: 1110; }
.tl-pop .xd-label { margin: 4px 0 0; }
.tl-pop-row { display: flex; align-items: center; gap: 10px; }
.tl-pop-row input[type=range] { flex: 1; min-width: 0; }
.tl-pop-val { min-width: 34px; text-align: right; color: #ccc; font-variant-numeric: tabular-nums; }
.tl-pop .seg button, .tl-pop .tag-pop-foot button { flex-direction: row; align-items: center; justify-content: center; font-size: 0.8rem; }
.tl-pop [hidden] { display: none; }
/* key opacity: its curve — opacity (up) over the frames (across), two handles, a dot a frame */
#key-op-pop { width: 290px; }
#key-op-custom { display: flex; flex-direction: column; gap: 6px; }
#key-op-custom[hidden] { display: none; }
.kop-head { display: flex; align-items: baseline; justify-content: space-between; }
.kop-end { color: #999; font-size: 0.72rem; }
/* Solid's and Fade's parts, spaced out */
#key-op-solid, #key-op-fade { display: flex; flex-direction: column; gap: 8px; margin-top: 2px; }
#key-op-fade[hidden], #key-op-solid[hidden] { display: none; }
#key-op-fade .xd-label { margin: 2px 0 -4px; }
/* From and To on one line, each a number box with the app's ▲▼ */
.kop-ends { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 10px; }
.kop-ends .xd-num { display: flex; align-items: center; gap: 6px; min-width: 0; }
.kop-ends .num-field { flex: 1; min-width: 0; }
.kop-ends input { width: 0; flex: 1; min-width: 0; }
/* (the window is a .pop-menu, whose buttons stack their lines: the dropdown keeps its own row) */
#key-op-pop .dd-select { width: 100%; flex-direction: row; align-items: center; gap: 8px; height: 28px; padding: 0 8px 0 10px; border: 1px solid #3a3a3a; border-radius: 6px; background: #1e1e1e; font-size: 0.78rem; }
#key-op-pop .dd-select:hover { border-color: #555; background: #232323; }
#key-op-pop .dd-select[aria-expanded="true"] { border-color: #4a7fcb; }
#key-ease-menu button.active b { color: #8fb4e8; }
#key-ease-menu { z-index: 1130; min-width: 0; }
#key-op-curve { width: 100%; height: auto; display: block; margin-top: 4px; background: #141414; border: 1px solid #2c2c2c; border-radius: 6px; touch-action: none; }
.kop-box { fill: none; stroke: #2e2e2e; }
.kop-grid { stroke: #242424; stroke-dasharray: 3 3; }
.kop-arm { stroke: #8fb4e8; stroke-width: 1; opacity: 0.7; }
.kop-path { fill: none; stroke: #4a7fcb; stroke-width: 2.5; }
.kop-dots circle { fill: #e0e0e0; }
.kop-handle { fill: #1a1a1a; stroke: #8fb4e8; stroke-width: 2; cursor: grab; }
.kop-handle:hover { fill: #8fb4e8; }
#key-op-curve.flat .kop-handle, #key-op-curve.flat .kop-arm { display: none; } /* (From = To: nothing to shape) */
/* no tags yet: no lane for them */
.tl-body.no-tags { --tl-tags: 0px; }
.tl-pic {
  width: 28px; height: 28px; flex-shrink: 0; display: flex; align-items: center; justify-content: center; border-radius: 2px;
  background: repeating-conic-gradient(#303030 0 25%, #262626 0 50%) 0 0 / 6px 6px;
}
.tl-pic canvas { display: block; width: 100%; height: 100%; object-fit: contain; image-rendering: pixelated; }
.tl-cel.empty .tl-pic { background: none; }
.tl-cel.empty .tl-pic::after { content: ''; width: 6px; height: 6px; border: 1.5px solid #4a4a4a; border-radius: 50%; }
.tl-row.hidden-layer .tl-pic { opacity: 0.4; }
/* held for several slots: a line to its end */
.tl-hold { flex: 1; height: 2px; margin: 0 9px 0 5px; border-radius: 1px; background: #4a4a4a; }
.tl-cel.cur-frame .tl-hold { background: #4a7fcb; }
/* an empty key held: its line dashed (nothing drawn there — a block to fill, move or delete) */
.tl-cel.empty .tl-hold { height: 0; border-radius: 0; background: none; border-top: 2px dashed #4a4a4a; }
.tl-cel.empty.cur-frame .tl-hold { background: none; border-top-color: #4a7fcb; }
/* the right edge: drag to hold it longer / shorter */
.tl-grip { position: absolute; right: -4px; top: -3px; bottom: -3px; width: 9px; z-index: 2; cursor: ew-resize; }
.tl-grip-l { right: auto; left: -4px; } /* (its left edge: over the key before's right one — they act as one) */
.tl-cel:hover .tl-grip::after, html.resizing-e .tl-cel.cur-frame .tl-grip::after { content: ''; position: absolute; left: 2px; top: 6px; bottom: 6px; width: 3px; border-radius: 2px; background: #8fb4e8; }
.tl-grid.dragging, .tl-grid.dragging * { cursor: grabbing; }
/* the Layers window inside the timeline (a computer): no header, its rows the grid's height */
#layers-panel.in-timeline {
  position: relative; z-index: auto; left: auto !important; top: auto !important; flex: 1; width: auto !important; height: auto !important; min-width: 0; max-height: none;
  background: transparent; border: none; border-radius: 0; box-shadow: none;
}
.in-timeline #layers-header, .in-timeline .rz { display: none; }
/* as in its own window: Opacity (and Lock alpha on the right) over the rows — level with the frame numbers — and
   the buttons (new, duplicate … delete on the right) under them */
.in-timeline #layers-body { display: grid; grid-template-columns: minmax(0, 1fr); grid-template-rows: calc(var(--tl-tags) + var(--tl-ruler)) minmax(0, 1fr) auto; height: 100%; }
.in-timeline #layers-opacity-row { grid-row: 1; align-self: end; height: var(--tl-ruler); box-sizing: border-box; padding: 0 8px 0 10px; border-bottom: 1px solid #2a2a2a; }
.in-timeline #layer-lock-alpha { height: 22px; width: 26px; }
.in-timeline #layers-blend { height: 22px; }
.in-timeline #layers-actions { grid-row: 3; align-items: center; }
.in-timeline #layers-list { grid-row: 2; min-height: 0; padding: 0; scrollbar-width: none; }
.in-timeline #layers-list::-webkit-scrollbar { display: none; }
.in-timeline .layer-row { height: var(--tl-row); box-sizing: border-box; padding: 0 8px; border-radius: 0; border-width: 0 0 1px; border-color: #1d1d1d; }
.in-timeline .layer-row.active { border-color: #1d1d1d; box-shadow: inset 3px 0 #4a7fcb; }
.in-timeline .layer-row.selected { border-color: #1d1d1d; box-shadow: inset 3px 0 #4a7fcb88; }
.in-timeline .layer-group-row { height: var(--tl-row); box-sizing: border-box; padding: 0 8px; border-radius: 0; border-width: 0 0 1px; border-color: #1d1d1d; background: #1b1b1b; }
.in-timeline .layer-row.in-group { margin-left: 0; padding-left: 22px; }
.in-timeline .layer-group-row.active { background: #1a3558; box-shadow: inset 3px 0 #4a7fcb; }
.in-timeline .layer-thumb { width: 28px; height: 28px; }

/* tags: a lane above the frame numbers, each tag a colored bar over its frames */
.tl-tags { position: sticky; top: 0; z-index: 3; height: var(--tl-tags); background: #161616; }
.tl-tags-hint { position: absolute; left: 8px; top: 0; line-height: var(--tl-tags); color: #555; font-size: 0.68rem; white-space: nowrap; pointer-events: none; }
.tl-tag {
  position: absolute; top: 3px; height: calc(var(--tl-tags) - 5px); box-sizing: border-box; padding: 0 7px;
  border-radius: 4px; background: color-mix(in srgb, var(--tag) 30%, #1a1a1a); border: 1px solid var(--tag);
  color: #f0f0f0; font-size: 0.66rem; font-weight: 600; line-height: calc(var(--tl-tags) - 7px);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; cursor: pointer; user-select: none; touch-action: none;
}
.tl-tag:hover { background: color-mix(in srgb, var(--tag) 45%, #1a1a1a); }
.tl-tag.on { background: color-mix(in srgb, var(--tag) 60%, #1a1a1a); }
.tl-tag-end { position: absolute; top: 0; bottom: 0; width: 6px; cursor: ew-resize; }
.tl-tag-end.l { left: -1px; } .tl-tag-end.r { right: -1px; }
/* a tag's editor */
#tag-pop { width: 268px; padding: 12px; gap: 6px; }
#tag-pop .xd-label { margin: 4px 0 0; }
.tag-name { height: 26px; padding: 0 8px; background: #121212; border: 1px solid #3a3a3a; border-radius: 5px; color: #e0e0e0; font: inherit; font-weight: 600; outline: none; }
.tag-name:focus { border-color: #4a7fcb; }
.tag-colors { display: flex; gap: 6px; flex-wrap: wrap; }
#tag-pop .tag-colors button { width: 22px; height: 22px; padding: 0; border-radius: 50%; border: 2px solid transparent; cursor: pointer; }
#tag-pop .tag-colors button.active { border-color: #fff; }
#tag-rep-field[hidden] { display: none; }
.tag-pop-foot { display: flex; justify-content: space-between; margin-top: 8px; }
.tag-pop-foot .btn { height: 28px; padding: 0 12px; }
#tag-pop .seg button, #tag-pop .tag-pop-foot button, #tag-pop .num-steps button { flex-direction: row; align-items: center; justify-content: center; font-size: 0.8rem; }
/* (.pop-menu's plain buttons would hide the button look) */
#tag-pop .tag-pop-foot .btn:not(.crop-apply) { background: #2a2a2a; border: 1px solid #3a3a3a; border-radius: 4px; }
#tag-pop .tag-pop-foot .btn:not(.crop-apply):hover { background: #383838; border-color: #555; }
#tag-pop .xd-seg .btn { padding: 0 9px; }
#tag-pop .num-steps button { padding: 0; border-radius: 0; }

/* ── The Palette window, as one: the palette (a dark bar), its colors touching, Opacity, Document colors ── */
#palette-body { padding: 10px 10px 12px; gap: 10px; }
#palette-panel .pal-select, #palette-panel .pal-edit-btn { height: 32px; background: #262626; border-color: #262626; border-radius: 8px; }
#palette-panel .pal-edit-btn { width: 32px; }
#palette-panel .pal-select:hover, #palette-panel .pal-edit-btn:hover { background: #2e2e2e; border-color: #2e2e2e; }
#palette-panel .pal-select[aria-expanded="true"] { border-color: #4a7fcb; }
#palette-panel .pal-edit-btn[aria-pressed="true"] { background: #1a3558; border-color: #4a7fcb; }
/* the eyedropper, in the header (lit while picking) */
#palette-header .ts-title { flex: 1; }
#palette-header .panel-min-btn { margin-left: 0; }
#palette-header .pal-eye-btn[aria-pressed="true"] { background: #1a3558; color: #fff; border-color: #4a7fcb; }
/* a section: its small heading (OPACITY, DOCUMENT COLORS), then what it holds */
.pal-sec { align-self: stretch; display: flex; flex-direction: column; gap: 6px; padding-top: 2px; }
.pal-sec-h {
  display: flex; align-items: center; justify-content: space-between; gap: 6px; min-height: 22px;
  font-size: 0.66rem; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: #8a8a8a;
}
.pal-sec-btns { display: flex; gap: 4px; }
.pal-sec-btns .panel-min-btn { width: 22px; height: 22px; text-transform: none; letter-spacing: 0; }
/* Opacity: a pill — the color fading in over a checkerboard — its round knob, and the % beside it */
.pal-op-row { display: flex; align-items: center; gap: 8px; }
.pal-op-track {
  --knob: 24px; position: relative; flex: 1; height: 28px; border-radius: 14px; cursor: pointer; touch-action: none;
  background: repeating-conic-gradient(#3a3a3a 0 25%, #262626 0 50%) 0 0 / 10px 10px;
}
.pal-op-fill { position: absolute; inset: 0; border-radius: inherit; box-shadow: inset 0 0 0 1px #ffffff10; }
.pal-op-knob {
  position: absolute; top: 2px; width: var(--knob); height: var(--knob); box-sizing: border-box; border-radius: 50%;
  border: 3px solid #fff; box-shadow: 0 1px 4px rgba(0, 0, 0, 0.6);
  background: linear-gradient(var(--knob-color, #fff), var(--knob-color, #fff)), repeating-conic-gradient(#bbb 0 25%, #fff 0 50%) 0 0 / 8px 8px;
}
.pal-op-track:focus-visible { outline: 2px solid #4a7fcb; outline-offset: 2px; }
.pal-op-track.off { opacity: 0.4; cursor: default; }
.pal-op-num { /* (as the app's other fields: the hex's) */
  width: 56px; height: 26px; flex-shrink: 0; padding: 0 6px; box-sizing: border-box; text-align: center;
  background: #1e1e1e; border: 1px solid #3a3a3a; border-radius: 4px; color: #e0e0e0; font: inherit; font-size: 0.78rem; outline: none;
}
.pal-op-num:focus { border-color: #4a7fcb; }
.pal-op-num:disabled { opacity: 0.4; }
/* Document colors: squares as the palette's, touching, as wide as its grid; the color picked: a white ring */
#palette-panel .pal-swatches {
  align-self: center; display: grid; grid-template-columns: repeat(var(--pal-cols, 16), var(--pal-cell, 15px)); grid-auto-rows: var(--pal-cell, 15px);
  gap: 0; padding: 0; border-radius: 4px; max-height: calc(var(--pal-cell, 15px) * 8);
}
#palette-panel .pal-swatches:empty { display: block; align-self: stretch; max-height: none; border-radius: 0; }
#palette-panel .pal-swatches:empty::after { content: 'The colors you draw with show here.'; font-size: 0.72rem; color: #6a6a6a; }
#palette-panel .pal-sw { width: auto; height: auto; border: 0; border-radius: 0; font-size: 9px; line-height: var(--pal-cell, 15px); }
#palette-panel .pal-sw.is-fg { box-shadow: inset 0 0 0 2px #fff, 0 0 0 1px rgba(0, 0, 0, 0.6); border-radius: 3px; z-index: 1; }
#palette-panel .pal-sw.is-bg { outline: none; box-shadow: inset 0 0 0 2px #000, 0 0 0 1px rgba(255, 255, 255, 0.45); border-radius: 3px; z-index: 1; }
#palette-panel .pal-sw.off-pal::after { top: 0; right: 0; border-top-width: 6px; border-left-width: 6px; border-top-right-radius: 0; }
#palette-panel.hide-keys .pal-sw span { display: none; }
#palette-panel .colors-remap { margin: 2px 0 0; }
/* the Color preview heading (the shade cube's section) — as Opacity's and Document colors' */
/* the palette's name: a click renames it (the arrow opens the list) — a hint of a field on hover */
#pal-select .pal-select-name { margin: -3px 0 -3px -6px; padding: 3px 6px; border-radius: 5px; cursor: text; }
#pal-select .pal-select-name:hover { background: #ffffff10; box-shadow: inset 0 0 0 1px #3a3a3a; }
#pal-select[hidden] { display: none; }
.pal-rename {
  flex: 1; min-width: 0; height: 32px; padding: 0 10px; box-sizing: border-box;
  background: #121212; border: 1px solid #4a7fcb; border-radius: 8px; color: #e0e0e0; font: inherit; font-size: 0.78rem; font-weight: 600; outline: none;
}
.pal-rename[hidden] { display: none; }
.pal-menu-export { width: 100%; justify-content: flex-start; border-top: 1px solid #2e2e2e; border-radius: 0 0 6px 6px; }
#pal-select .pal-select-name { flex: 0 1 auto; } /* (only the name renames: the rest of the bar opens the list) */
#pal-select .pal-select-count { margin-left: auto; }

/* ── Color preview window (the shade cube, foreground / background, hex) — the same frame as History ── */
#color-preview-panel {
  position: fixed; z-index: 16; width: 250px;
  background: #161616; border: 1px solid #2e2e2e; border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.4);
  font-size: 0.78rem;
  display: flex; flex-direction: column;
}
#color-preview-header {
  display: flex; align-items: center; gap: 0.45rem;
  padding: 0.4rem 0.5rem 0.4rem 0.75rem;
  cursor: grab; user-select: none; touch-action: none;
  border-bottom: 1px solid #2e2e2e; border-radius: 8px 8px 0 0;
}
#color-preview-header > svg { color: #e0e0e0; opacity: 0.5; flex-shrink: 0; }
#color-preview-header:hover { background: #1e1e1e; }
#color-preview-header .ts-title { flex: 1; }
#color-preview-panel.dragging { z-index: 1000; }
#color-preview-panel.dragging #color-preview-header { cursor: grabbing; }
#color-preview-panel.minimized #color-preview-body { display: none; }
#color-preview-panel.minimized #color-preview-header { border-bottom: none; border-radius: 8px; }
#color-preview-panel.minimized .panel-min-btn[aria-expanded] svg { transform: rotate(180deg); }
#color-preview-body { padding: 10px 10px 12px; display: flex; flex-direction: column; align-items: center; }
#color-preview-body .pal-cube-row { padding: 0; }

/* the lock (after the eyedropper): open — any color; shut and lit — the drawing kept to this palette */
.pal-lock-btn .lk-shut, .pal-lock-btn.on .lk-open { display: none; }
.pal-lock-btn.on .lk-shut { display: block; }
#palette-header .pal-lock-btn.on { background: #1a3558; color: #fff; border-color: #4a7fcb; }

/* Locking the palette (src/palette.js): Remap or Add to palette — two cards, one picked */
#lock-dlg .lk-panel { width: min(440px, 100%); gap: 12px; }
.lk-choices { display: flex; flex-direction: column; gap: 8px; }
.lk-choice {
  display: flex; flex-direction: column; align-items: flex-start; gap: 3px; padding: 10px 12px; text-align: left; cursor: pointer;
  background: #1e1e1e; border: 1px solid #3a3a3a; border-radius: 8px; color: #e0e0e0; font: inherit; font-size: 0.82rem;
}
.lk-choice span { color: #9a9a9a; font-size: 0.74rem; line-height: 1.45; }
.lk-choice:hover { border-color: #555; }
.lk-choice[aria-checked="true"] { border-color: #4a7fcb; background: #1b2230; box-shadow: 0 0 0 1px #4a7fcb; }
#lock-dlg .lk-dither { font-size: 0.78rem; white-space: normal; align-items: flex-start; line-height: 1.45; }
#lock-dlg .lk-dither input { margin-top: 2px; flex-shrink: 0; }
.lk-dither[hidden] { display: none; }
.lk-acts { display: flex; justify-content: flex-end; gap: 8px; }
.lk-acts .btn { height: 30px; padding: 0 16px; }
