/* ===== Reset & Base ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'Segoe UI', system-ui, sans-serif;
  font-size: 13px;
  color: #1a1a1a;
  min-height: 100vh;
  padding-bottom: 40px;
}

#top-bar {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 12px 16px 6px;
  gap: 8px;
}

h1 {
  text-align: center;
  font-size: 18px;
  font-weight: 700;
  color: #1a1a1a;
  letter-spacing: 1px;
  text-transform: uppercase;
}

#top-actions {
  display: flex;
  gap: 6px;
}

#top-output-tabs {
  display: flex;
  gap: 6px;
}

.top-action-btn {
  padding: 6px 14px;
  border: 1.5px solid #5a5a5a;
  border-radius: 6px;
  background: #eeeeee;
  color: #1a1a1a;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s;
  white-space: nowrap;
}
.top-action-btn:hover { background: #d5d5d5; border-color: #4a4a4a; }

#save-format-note {
  font-size: 11px;
  color: #789;
  font-style: italic;
  align-self: center;
}

/* ===== Layout ===== */
#app {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 0 16px;
}

/* ===== Layer Bar ===== */
#layer-bar {
  width: 100%;
  padding: 8px 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.layer-bar-top {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.layer-bar-top label {
  font-weight: 600;
  color: #1a1a1a;
}

#layer-switch-tip {
  position: fixed;
  background: #666666;
  color: #fff;
  font-size: 12px;
  padding: 7px 11px;
  border-radius: 7px;
  box-shadow: 0 3px 12px rgba(0,0,0,0.25);
  pointer-events: none;
  z-index: 600;
  max-width: 200px;
  line-height: 1.4;
  opacity: 1;
  transition: opacity 0.4s;
}
#layer-switch-tip::before {
  content: '';
  position: absolute;
  top: 50%;
  right: -7px;
  transform: translateY(-50%);
  border: 7px solid transparent;
  border-left-color: #666666;
  border-right: none;
}

.layer-count-group {
  display: flex;
  border: 1.5px solid #5a5a5a;
  border-radius: 6px;
  overflow: hidden;
}

.layer-count-btn {
  padding: 4px 12px;
  border: none;
  background: #eeeeee;
  color: #1a1a1a;
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
  transition: background 0.15s;
}

.layer-count-btn + .layer-count-btn { border-left: 1.5px solid #5a5a5a; }
.layer-count-btn.active { background: #5a5a5a; color: #fff; }
.layer-count-btn:hover:not(.active) { background: #d5d5d5; }

.layer-row {
  display: flex;
  align-items: center;
  gap: 8px;
  background: #eeeeee;
  border: 1.5px solid #A8C4E0;
  border-radius: 6px;
  padding: 5px 10px;
  cursor: pointer;
  transition: border-color 0.15s;
}

.layer-row.layer-active {
  border-color: #5a5a5a;
  border-left: 4px solid #5a5a5a;
  background: #e2e2e2;
}

.layer-row:not(.layer-active) { border-left: 4px solid transparent; }

.layer-select-btn {
  background: none;
  border: none;
  font-weight: 700;
  color: #1a1a1a;
  cursor: pointer;
  font-size: 13px;
  width: 90px;
  flex-shrink: 0;
  text-align: left;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.layer-row.layer-active .layer-select-btn { color: #3a3a3a; }

.layer-vis-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 15px;
  padding: 0 2px;
  line-height: 1;
}

.layer-opacity,
#ref-opacity-slider {
  width: 90px;
  accent-color: #5a5a5a;
  cursor: pointer;
}

/* Layer number badge — circle with number */
.layer-num-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #cccccc;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  flex-shrink: 0;
}

/* Reference image layer row — inherits .layer-row; these are the only overrides */
#ref-layer-row { cursor: default; background: #ececec; border-color: #c8c8c8; }

#layer-color-picker {
  display: none;
  position: fixed;
  z-index: 500;
  background: #eeeeee;
  border: 1.5px solid #5a5a5a;
  border-radius: 7px;
  padding: 6px;
  flex-wrap: wrap;
  gap: 4px;
  width: 168px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.2);
}

#layer-color-picker span {
  display: inline-block;
  width: 20px;
  height: 20px;
  border-radius: 3px;
  border: 2px solid transparent;
  cursor: pointer;
  transition: border-color 0.1s, transform 0.1s;
}
#layer-color-picker span:hover { border-color: #1a1a1a; transform: scale(1.15); }
#layer-color-picker span.swatch-disabled { opacity: 0.25; cursor: not-allowed; pointer-events: none; }

#ref-color-picker {
  display: none;
  position: fixed;
  z-index: 500;
  background: #eeeeee;
  border: 1.5px solid #5a5a5a;
  border-radius: 7px;
  padding: 6px;
  flex-wrap: wrap;
  gap: 4px;
  width: 168px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.2);
}

#ref-color-picker span {
  display: inline-block;
  width: 20px;
  height: 20px;
  border-radius: 3px;
  border: 2px solid transparent;
  cursor: pointer;
  transition: border-color 0.1s, transform 0.1s;
}
#ref-color-picker span:hover { border-color: #1a1a1a; transform: scale(1.15); }

.layer-import-cvbasic-btn {
  padding: 3px 8px;
  border: 1.5px solid #5a5a5a;
  border-radius: 5px;
  background: #eeeeee;
  color: #3a3a3a;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  margin-left: auto;
  white-space: nowrap;
  transition: background 0.15s;
}

.layer-import-cvbasic-btn:hover:not(:disabled) { background: #d5d5d5; border-color: #4a4a4a; }
.layer-import-cvbasic-btn:disabled { opacity: 0.4; cursor: default; }

#auto-trace-btn .fa-bolt {
  color: #f5c800;
  -webkit-text-stroke: 0.5px #222222;
  text-shadow: 0 0 1px #222222;
}

.layer-export-cvbasic-btn {
  padding: 3px 8px;
  border: 1.5px solid #5a5a5a;
  border-radius: 5px;
  background: #eeeeee;
  color: #3a3a3a;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s;
}
.layer-export-cvbasic-btn:hover { background: #d5d5d5; border-color: #4a4a4a; }

.layer-clear-btn {
  padding: 3px 8px;
  border: 1.5px solid #c07070;
  border-radius: 5px;
  background: #fef0f0;
  color: #a03030;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s;
}

.layer-clear-btn:hover { background: #fcd0d0; border-color: #a03030; }

.layer-delete-btn {
  padding: 3px 6px;
  border: 1.5px solid #c07070;
  border-radius: 5px;
  background: #fef0f0;
  color: #a03030;
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s;
  margin-left: 4px;
}
.layer-delete-btn:hover { background: #fcd0d0; border-color: #a03030; }

.layer-color-swatch {
  display: inline-block;
  width: 20px;
  height: 20px;
  border-radius: 4px;
  border: 2px solid rgba(0,0,0,0.25);
  flex-shrink: 0;
  cursor: pointer;
  transition: border-color 0.1s, transform 0.1s;
}
.layer-color-swatch:hover { border-color: #1a1a1a; transform: scale(1.15); }

.layer-opacity-label {
  min-width: 34px;
  font-size: 11px;
  color: #456;
}

/* ===== Toolbar ===== */
#toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  background: #cccccc;
  border: 1.5px solid #999999;
  border-radius: 8px;
  padding: 7px 12px;
  width: 100%;
  max-width: 860px;
}

.toolbar-group {
  display: flex;
  align-items: center;
  gap: 4px;
}

.toolbar-sep {
  width: 1px;
  height: 28px;
  background: #999999;
  margin: 0 4px;
}

.tool-btn, .zoom-btn, .action-btn {
  padding: 5px 10px;
  border: 1.5px solid #5a5a5a;
  border-radius: 5px;
  background: #eeeeee;
  color: #1a1a1a;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  white-space: nowrap;
}

.tool-btn:hover, .zoom-btn:hover, .action-btn:hover:not(:disabled) { background: #d5d5d5; }
.action-btn:disabled { opacity: 0.4; cursor: default; }
.tool-btn.active, .zoom-btn.active { background: #5a5a5a; color: #fff; border-color: #3a3a3a; }

#grid-toggle { font-size: 12px; }
#grid-toggle.active { background: #5a5a5a; color: #fff; }

#active-color-display {
  padding: 4px 10px;
  border-radius: 5px;
  border: 1.5px solid #5a5a5a;
  font-weight: 700;
  font-size: 12px;
  min-width: 130px;
  text-align: center;
  margin-left: auto;
}

/* ===== Palette ===== */
#palette-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 0;
  width: 100%;
  flex-wrap: wrap;
}

#palette-bar label {
  font-weight: 600;
  color: #1a1a1a;
  font-size: 12px;
  margin-right: 4px;
}

#palette-container {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.palette-swatch {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  cursor: pointer;
  border-radius: 4px;
  padding: 2px;
  border: 2px solid transparent;
  transition: border-color 0.1s, transform 0.1s;
}

.palette-swatch:hover { transform: scale(1.15); border-color: #5a5a5a; }
.palette-swatch.active { border-color: #1a1a1a; box-shadow: 0 0 0 2px #5a5a5a; }
.palette-swatch.swatch-disabled { opacity: 0.25; cursor: not-allowed; pointer-events: none; }

.swatch-color {
  width: 22px;
  height: 22px;
  border-radius: 3px;
  border: 1px solid rgba(0,0,0,0.2);
}

.swatch-transparent {
  background-image:
    linear-gradient(45deg, #ccc 25%, transparent 25%),
    linear-gradient(-45deg, #ccc 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #ccc 75%),
    linear-gradient(-45deg, transparent 75%, #ccc 75%);
  background-size: 8px 8px;
  background-position: 0 0, 0 4px, 4px -4px, -4px 0px;
  background-color: #fff;
}

.swatch-label {
  font-size: 9px;
  color: #456;
  font-weight: 600;
}

/* ===== Mode Tabs ===== */
#mode-tabs {
  display: flex;
  gap: 0;
  border: 1.5px solid #999999;
  border-radius: 8px;
  overflow: hidden;
  width: 100%;
  max-width: 860px;
}

.mode-tab {
  flex: 1;
  padding: 7px 0;
  border: none;
  background: #cccccc;
  color: #1a1a1a;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
  text-align: center;
}

.mode-tab + .mode-tab { border-left: 1.5px solid #999999; }
.mode-tab.active { background: #5a5a5a; color: #fff; }
.mode-tab:hover:not(.active) { background: #d5d5d5; }

/* ===== Sprite Canvas Section Panel ===== */
#sprite-canvas-panel {
  background: #cccccc;
  border: 1.5px solid #999999;
  border-radius: 8px;
  padding: 10px 12px;
  width: 100%;
  max-width: 860px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

#sprite-canvas-body {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

#sprite-canvas-panel.collapsed #sprite-canvas-body { display: none; }

#sprite-canvas-panel.collapsed #sprite-name-bar { border-bottom-color: transparent; margin-bottom: 0; padding-bottom: 0; }

.section-collapse-btn {
  background: none;
  border: none;
  cursor: pointer;
  padding: 2px 4px;
  color: #555;
  font-size: 13px;
  line-height: 1;
  flex-shrink: 0;
  transition: color 0.15s;
}
.section-collapse-btn:hover { color: #111; }
.section-collapse-btn .fa-chevron-down {
  display: inline-block;
  transition: transform 0.2s ease;
}
#sprite-canvas-panel.collapsed .section-collapse-btn .fa-chevron-down {
  transform: rotate(-90deg);
}

/* ===== Sprite Name Bar ===== */
.section-title {
  font-size: 14px;
  font-weight: 700;
  color: #1a1a1a;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

#sprite-name-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  border-bottom: 1.5px solid #aaaaaa;
  padding-bottom: 6px;
  margin-bottom: 2px;
  width: 100%;
  max-width: 860px;
}

#sprite-name-bar label {
  font-size: 12px;
  color: #456;
  white-space: nowrap;
}

#sprite-name-input {
  padding: 4px 8px;
  border: 1.5px solid #5a5a5a;
  border-radius: 5px;
  background: #f8f8f8;
  color: #1a1a1a;
  font-family: 'Cascadia Code', 'Consolas', monospace;
  font-size: 13px;
  font-weight: 700;
  width: 180px;
}

#sprite-name-input:focus {
  outline: none;
  border-color: #4a4a4a;
  box-shadow: 0 0 0 2px rgba(80,80,80,0.2);
}

#sprite-name-preview {
  font-family: 'Cascadia Code', 'Consolas', monospace;
  font-size: 12px;
  color: #456;
}

/* ===== Drawing Tools Bar ===== */
#tools-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 0;
  width: 100%;
}

.tools-bar-sep {
  width: 1.5px;
  align-self: stretch;
  background: #999999;
  margin: 0 4px;
}

/* ===== Symmetry Bar ===== */
#canvas-center-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

#symmetry-bar {
  display: flex;
  gap: 6px;
}

.sym-btn {
  padding: 5px 14px;
  border: 1.5px solid #5a5a5a;
  border-radius: 5px;
  background: #eeeeee;
  color: #1a1a1a;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  white-space: nowrap;
}
.sym-btn:hover { background: #d5d5d5; }
.sym-sep { color: #999999; font-size: 18px; line-height: 1; align-self: center; }
.sym-btn.active { background: #5a5a5a; color: #fff; border-color: #3a3a3a; }

/* ===== Canvas Area ===== */
#canvas-area {
  display: flex;
  align-items: flex-end;
  gap: 8px;
}

#sym-vert-bar {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 6px;
  align-items: stretch;
}

#sym-vert-bar .sym-btn {
  writing-mode: vertical-rl;
  transform: rotate(180deg);
  padding: 12px 5px;
  min-height: 80px;
}

#rot-bar {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 6px;
  align-items: stretch;
}

.rot-btn {
  padding: 5px 10px;
  border: 1.5px solid #5a5a5a;
  border-radius: 5px;
  background: #eeeeee;
  color: #1a1a1a;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
  white-space: nowrap;
}
.rot-btn:hover { background: #d5d5d5; }
.rot-btn:active { background: #5a5a5a; color: #fff; }

.rot-color-hint {
  display: none;
  text-align: center;
  font-size: 10px;
  font-weight: 700;
  color: #888;
  background: #e8e8e8;
  border: 1.5px solid #bbb;
  border-radius: 4px;
  padding: 1px 0;
  letter-spacing: 1px;
  cursor: default;
}

.rot-swatch-row {
  display: flex;
  align-items: center;
  gap: 4px;
}

.rot-color-swatch {
  flex: 1;
  min-width: 0;
  height: 22px;
  border-radius: 5px;
  border: 2px solid #5a5a5a;
  cursor: pointer;
  box-sizing: border-box;
  transition: border-color 0.15s, transform 0.1s;
}
.rot-color-swatch:hover { border-color: #1a1a1a; transform: scale(1.06); }
.rot-color-swatch.rot-swatch-active { border-color: #1a1a1a; box-shadow: 0 0 0 2px #5a5a5a; }

.rot-swatch-edit-btn {
  flex-shrink: 0;
  width: 22px;
  height: 22px;
  border: 1.5px solid #5a5a5a;
  border-radius: 4px;
  background: #eeeeee;
  color: #3a3a3a;
  font-size: 10px;
  cursor: pointer;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, border-color 0.15s;
}
.rot-swatch-edit-btn:hover { background: #d5d5d5; border-color: #4a4a4a; }

.sym-sep-v {
  display: block;
  height: 1.5px;
  background: #999999;
  margin: 2px 0;
}

#canvas-wrapper {
  display: flex;
  justify-content: center;
  background: #c0c0c0;
  border: 2px solid #999999;
  border-radius: 10px;
  padding: 16px;
  box-shadow: inset 0 2px 8px rgba(0,0,0,0.08);
}

#nudge-bar {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 6px;
  padding: 4px 0;
}

.nudge-label {
  font-size: 12px;
  font-weight: 600;
  color: #222;
  margin-right: 2px;
}

.nudge-btn {
  padding: 5px 10px;
  border: 1.5px solid #5a5a5a;
  border-radius: 5px;
  background: #eeeeee;
  color: #1a1a1a;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
  white-space: nowrap;
}
.nudge-btn:hover  { background: #d5d5d5; }
.nudge-btn:active { background: #5a5a5a; color: #fff; }

#nudge-all-label, #nudge-wrap-label {
  font-size: 12px;
  font-weight: 600;
  color: #222;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 4px;
  margin-left: 4px;
}
#nudge-all-colors, #nudge-wrap {
  accent-color: #5a5a5a;
  cursor: pointer;
}

#main-canvas {
  display: block;
  cursor: crosshair;
  image-rendering: pixelated;
  border: 1px solid #5a5a5a;
}

/* ===== Status Bar ===== */
#status-bar {
  width: 100%;
  max-width: 860px;
  background: #cccccc;
  border: 1.5px solid #999999;
  border-radius: 6px;
  padding: 4px 12px;
  font-family: monospace;
  font-size: 12px;
  color: #1a1a1a;
  letter-spacing: 0.5px;
}

/* ===== Frame Bar ===== */
#frame-bar {
  width: 100%;
  max-width: 860px;
  background: #cccccc;
  border: 1.5px solid #999999;
  border-radius: 8px;
  padding: 8px 12px;
  display: flex;
  flex-direction: row;
  align-items: flex-start;
  gap: 12px;
}

.frame-bar-collapsed #frame-strip,
.frame-bar-collapsed #anim-preview-group { display: none; }
.frame-bar-collapsed #frame-bar-left { gap: 0; }

.frame-bar-toggle-btn {
  background: none;
  border: none;
  color: #5a5a5a;
  font-size: 12px;
  cursor: pointer;
  padding: 0 4px 0 0;
  line-height: 1;
  flex-shrink: 0;
  transition: color 0.15s;
}
.frame-bar-toggle-btn:hover { color: #1a1a1a; }
.frame-bar-toggle-btn i { transition: transform 0.2s; }
#frame-bar:not(.frame-bar-collapsed) .frame-bar-toggle-btn i { transform: rotate(90deg); }

#frame-bar-left {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 18px;
  min-width: 0;
}

#frame-bar-header {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

#frame-bar-header > span {
  font-weight: 700;
  color: #1a1a1a;
  font-size: 13px;
}

.anim-sep {
  color: #999999;
  font-size: 16px;
  line-height: 1;
  margin: 0 2px;
}

.anim-label {
  font-size: 12px;
  font-weight: 600;
  color: #1a1a1a;
  white-space: nowrap;
}

.anim-speed-group {
  display: inline-flex;
  gap: 3px;
  align-items: center;
}

.anim-speed-btn {
  width: 22px;
  height: 22px;
  border: 1.5px solid #5a5a5a;
  border-radius: 4px;
  background: #eeeeee;
  color: #1a1a1a;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  line-height: 1;
  transition: background 0.15s;
}
.anim-speed-btn:hover:not(:disabled) { background: #d5d5d5; }
.anim-speed-btn:disabled { opacity: 0.4; cursor: default; }

#anim-fps-display {
  font-size: 11px;
  font-weight: 600;
  color: #1a1a1a;
  min-width: 110px;
  text-align: center;
  font-family: 'Cascadia Code', 'Consolas', monospace;
  white-space: nowrap;
}

#anim-preview-group {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

#anim-play-controls {
  display: flex;
  gap: 4px;
}

#anim-mode-controls {
  display: flex;
  gap: 4px;
  width: 100%;
}

.anim-mode-btn {
  flex: 1;
  padding: 3px 0;
  border: 1.5px solid #5a5a5a;
  border-radius: 4px;
  background: #eeeeee;
  color: #1a1a1a;
  font-size: 10px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  white-space: nowrap;
}
.anim-mode-btn:hover:not(.active):not(:disabled) { background: #d5d5d5; }
.anim-mode-btn.active { background: #5a5a5a; color: #fff; border-color: #3a3a3a; }
.anim-mode-btn:disabled { opacity: 0.35; cursor: default; }

#anim-preview-canvas {
  display: block;
  image-rendering: pixelated;
  border: 1.5px solid #5a5a5a;
  border-radius: 4px;
  background: #fff;
  width: 80px;
  height: 80px;
}

#anim-bg-picker {
  display: flex;
  flex-wrap: wrap;
  gap: 3px;
  justify-content: center;
  width: 80px;
}

.anim-bg-swatch {
  width: 12px;
  height: 12px;
  border-radius: 2px;
  border: 1.5px solid transparent;
  cursor: pointer;
  flex-shrink: 0;
  transition: border-color 0.1s, transform 0.1s;
}
.anim-bg-swatch:hover { transform: scale(1.2); border-color: #333; }
.anim-bg-swatch.active { border-color: #333; box-shadow: 0 0 0 1px #fff; }

#frame-strip {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: flex-end;
}

.frame-thumb-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  cursor: pointer;
  padding: 4px;
  border-radius: 6px;
  border: 2px solid transparent;
  background: #eeeeee;
  position: relative;
  transition: border-color 0.15s;
}
.frame-thumb-wrap:hover { border-color: #5a5a5a; }
.frame-thumb-wrap.active { border-color: #1a1a1a; box-shadow: 0 0 0 2px #5a5a5a; }

.frame-thumb {
  display: block;
  image-rendering: pixelated;
  border: 1px solid #999999;
  border-radius: 2px;
}

.frame-label {
  font-size: 10px;
  font-weight: 600;
  color: #789;
}
.frame-thumb-wrap.active .frame-label { color: #1a1a1a; }

.frame-arrow-row {
  display: flex;
  gap: 4px;
  justify-content: center;
  min-height: 18px;
  width: 100%;
}

.frame-arrow-btn {
  padding: 1px 7px;
  border: 1.5px solid #5a5a5a;
  border-radius: 3px;
  background: #eeeeee;
  color: #3a3a3a;
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
  line-height: 1;
  transition: background 0.15s;
}
.frame-arrow-btn:hover { background: #d5d5d5; }

.frame-thumb-wrap.anim-playing {
  border-color: #d07020;
  box-shadow: 0 0 0 2px #f09030;
}

.frame-delete-btn {
  position: absolute;
  top: -8px;
  right: -8px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 1.5px solid #c07070;
  background: #fef0f0;
  color: #a03030;
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  line-height: 1;
  transition: background 0.15s;
  box-shadow: 0 1px 4px rgba(0,0,0,0.15);
}
.frame-delete-btn:hover { background: #fcd0d0; }

.frame-clone-btn {
  position: absolute;
  bottom: -8px;
  right: -8px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 1.5px solid #5a5a5a;
  background: #eeeeee;
  color: #3a3a3a;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  line-height: 1;
  transition: background 0.15s;
  box-shadow: 0 1px 4px rgba(0,0,0,0.15);
}
.frame-clone-btn:hover:not(:disabled) { background: #d5d5d5; border-color: #4a4a4a; }
.frame-clone-btn:disabled { opacity: 0.4; cursor: default; }

/* ===== Section Panel (shared with tile editor) ===== */
.section-panel {
  width: 100%;
  max-width: 860px;
  background: #cccccc;
  border: 1.5px solid #999999;
  border-radius: 8px;
  padding: 8px 12px 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

/* ===== Output Panel ===== */
#output-panel-header {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  padding-bottom: 6px;
  border-bottom: 1.5px solid #aaaaaa;
}

#output-panel-header > span {
  font-weight: 700;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* Base tabs (top bar — stays light) */
.output-tab {
  padding: 4px 12px;
  border: 1.5px solid #5a5a5a;
  border-radius: 5px;
  background: #eeeeee;
  color: #1a1a1a;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}
.output-tab.active { background: #5a5a5a; color: #fff; }
.output-tab:hover:not(.active) { background: #d5d5d5; }
#output-panel-header .output-tab { cursor: default; pointer-events: none; }
#output-panel-header .output-tab:not(.active) { display: none; }
.asm-fmt-btn {
  padding: 4px 10px;
  border: 1.5px solid #5a5a5a;
  border-radius: 5px;
  background: #eeeeee;
  color: #1a1a1a;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}
.asm-fmt-btn.active { background: #5a5a5a; color: #fff; }
.asm-fmt-btn:hover:not(.active) { background: #d5d5d5; }

#output-copy-btn {
  margin-left: auto;
  padding: 4px 12px;
  border: 1.5px solid #5a5a5a;
  border-radius: 5px;
  background: #eeeeee;
  color: #1a1a1a;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}
#output-copy-btn:hover  { background: #d5d5d5; }
#output-copy-btn.copied { background: #5a5a5a; color: #fff; }

.output-action-btn {
  padding: 4px 12px;
  border: 1.5px solid #5a5a5a;
  border-radius: 5px;
  background: #eeeeee;
  color: #1a1a1a;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  margin-left: auto;
  transition: background 0.15s;
}

.output-action-btn:hover { background: #d5d5d5; }
.output-action-btn + .output-action-btn { margin-left: 4px; }

#output-pre {
  display: block;
  padding: 12px 16px;
  font-family: 'Cascadia Code', 'Consolas', 'Courier New', monospace;
  font-size: 11.5px;
  line-height: 1.55;
  color: #c8e6c9;
  background: #1a1a2e;
  border-radius: 6px;
  max-height: 600px;
  overflow-y: auto;
  white-space: pre;
}

/* Syntax Highlighting — shared classes across all three formats */
.hl-key         { color: #80cbc4; font-weight: 700; }   /* JSON keys           */
.hl-str         { color: #a5d6a7; }                      /* JSON / table strings */
.hl-num         { color: #ffab91; font-weight: 600; }    /* numbers everywhere   */
.hl-kw          { color: #ce93d8; font-weight: 700; }    /* keywords/directives  */
.hl-comment     { color: #546e7a; font-style: italic; }  /* ' CVBasic  ; ASM     */
.hl-label       { color: #ffcc80; font-weight: 700; }    /* labels ending in :   */
.hl-hex         { color: #ffd54f; font-weight: 600; }    /* ASM 0x.. hex literals*/
.hl-pixel       { color: #ffffff; font-weight: 900; }    /* BITMAP "1" on-pixels */
.hl-transparent { color: #37474f; }                      /* BITMAP "_" off/transparent */

/* ===== Tile mode legend ===== */
#tile-legend {
  display: none;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
  background: #cccccc;
  border: 1.5px solid #999999;
  border-radius: 8px;
  padding: 6px 12px;
  width: 100%;
  max-width: 860px;
  font-size: 12px;
  font-weight: 600;
  color: #1a1a1a;
}

#tile-legend span { margin-right: 3px; }
.tile-swatch { display: inline-block; width: 14px; height: 14px; border-radius: 3px; border: 1px solid rgba(0,0,0,0.2); vertical-align: middle; margin-right: 3px; }

/* ===== CVBasic Layer Export Modal ===== */
#cvbasic-export-modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

#cvbasic-export-box {
  background: #eeeeee;
  border: 2px solid #5a5a5a;
  border-radius: 10px;
  padding: 18px 20px 14px;
  width: 540px;
  max-width: 95vw;
  display: flex;
  flex-direction: column;
  gap: 10px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.25);
}

#cvbasic-export-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-weight: 700;
  font-size: 13px;
  color: #1a1a1a;
}

#cvbasic-export-close {
  background: none;
  border: none;
  font-size: 15px;
  cursor: pointer;
  color: #456;
  padding: 0 2px;
  line-height: 1;
}
#cvbasic-export-close:hover { color: #a03030; }

#cvbasic-export-pre {
  background: #f8f8f8;
  border: 1.5px solid #5a5a5a;
  border-radius: 6px;
  padding: 10px 12px;
  font-family: 'Cascadia Code', 'Consolas', monospace;
  font-size: 11.5px;
  line-height: 1.55;
  color: #1a1a1a;
  max-height: 400px;
  overflow-y: auto;
  white-space: pre;
  user-select: all;
}

#cvbasic-export-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

#cvbasic-export-copy, #cvbasic-export-cancel {
  padding: 5px 14px;
  border-radius: 5px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  border: 1.5px solid #5a5a5a;
  transition: background 0.15s;
}
#cvbasic-export-copy { background: #5a5a5a; color: #fff; border-color: #3a3a3a; }
#cvbasic-export-copy:hover { background: #3a3a3a; }
#cvbasic-export-cancel { background: #eeeeee; color: #1a1a1a; }
#cvbasic-export-cancel:hover { background: #d5d5d5; }

/* ===== CVBasic Import Modal ===== */
#cvbasic-import-modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

#cvbasic-import-box {
  background: #eeeeee;
  border: 2px solid #5a5a5a;
  border-radius: 10px;
  padding: 18px 20px 14px;
  width: 480px;
  max-width: 95vw;
  display: flex;
  flex-direction: column;
  gap: 10px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.25);
}

#cvbasic-import-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-weight: 700;
  font-size: 13px;
  color: #1a1a1a;
}

#cvbasic-import-close {
  background: none;
  border: none;
  font-size: 15px;
  cursor: pointer;
  color: #456;
  padding: 0 2px;
  line-height: 1;
}
#cvbasic-import-close:hover { color: #a03030; }

#cvbasic-import-hint {
  font-size: 11px;
  color: #456;
  margin: 0;
}

#cvbasic-import-textarea {
  width: 100%;
  font-family: 'Cascadia Code', 'Consolas', monospace;
  font-size: 11.5px;
  padding: 8px 10px;
  border: 1.5px solid #5a5a5a;
  border-radius: 6px;
  background: #f8f8f8;
  color: #1a1a1a;
  resize: vertical;
  line-height: 1.5;
}
#cvbasic-import-textarea:focus { outline: none; border-color: #4a4a4a; box-shadow: 0 0 0 2px rgba(80,80,80,0.2); }

#cvbasic-import-footer {
  display: flex;
  align-items: center;
  gap: 8px;
}

#cvbasic-import-status {
  flex: 1;
  font-size: 11px;
  color: #456;
}

#cvbasic-import-cancel, #cvbasic-import-ok {
  padding: 5px 14px;
  border-radius: 5px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  border: 1.5px solid #5a5a5a;
  transition: background 0.15s;
}
#cvbasic-import-cancel { background: #eeeeee; color: #1a1a1a; }
#cvbasic-import-cancel:hover { background: #d5d5d5; }
#cvbasic-import-ok { background: #5a5a5a; color: #fff; border-color: #3a3a3a; }
#cvbasic-import-ok:hover { background: #3a3a3a; }
