/* ===== 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 ===== */
#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;
}

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

/* ===== Section Panels ===== */
.section-panel {
  width: 100%;
  max-width: 920px;
  background: #cccccc;
  border: 1.5px solid #999999;
  border-radius: 10px;
  padding: 10px 14px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.section-header {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  border-bottom: 1.5px solid #aaaaaa;
  padding-bottom: 6px;
  margin-bottom: 2px;
}
.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;
}
.section-panel.collapsed .section-collapse-btn .fa-chevron-down {
  transform: rotate(-90deg);
}
.section-panel.collapsed .section-header {
  border-bottom-color: transparent;
  margin-bottom: 0;
  padding-bottom: 4px;
}
.section-body {
  overflow: hidden;
}
.section-panel.collapsed .section-body {
  display: none;
}

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

/* ===== Output Tabs ===== */
.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; border-color: #3a3a3a; }
.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; }

/* ===== Buttons ===== */
.tool-btn, .action-btn, .zoom-btn, .edit-mode-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, .action-btn:hover:not(:disabled), .zoom-btn:hover:not(.active), .edit-mode-btn:hover:not(.active) { background: #d5d5d5; }
.tool-btn.active, .zoom-btn.active, .edit-mode-btn.active { background: #5a5a5a; color: #fff; border-color: #3a3a3a; }
.action-btn:disabled { opacity: 0.4; cursor: default; }
#tile-edit-mode-bar {
  display: flex;
  gap: 4px;
  align-items: center;
  margin: 0 auto;
}

/* ===== Tile Name Bar ===== */
#tile-name-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-left: auto;
}
#tile-name-bar label { font-size: 12px; color: #456; }
#tile-name-input {
  padding: 3px 8px;
  border: 1.5px solid #aaaaaa;
  border-radius: 5px;
  font-size: 13px;
  font-weight: 600;
  background: #f5f5f5;
  width: 150px;
}

/* ===== Color Bar + Canvas Scale Bar ===== */
#color-bar, #canvas-scale-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  background: #eeeeee;
  border: 1.5px solid #aaaaaa;
  border-radius: 7px;
  padding: 6px 12px;
}
#color-bar label, #canvas-scale-bar label { font-weight: 600; font-size: 12px; margin-right: 4px; }
#canvas-scale-bar { flex-wrap: wrap; align-items: center; }
#color-bar { flex-wrap: wrap; }
.color-group { display: flex; align-items: center; gap: 6px; }
.color-label { font-size: 12px; font-weight: 600; color: #333; }
.color-swatch {
  display: inline-block;
  width: 24px;
  height: 24px;
  border-radius: 4px;
  border: 2px solid rgba(0,0,0,0.3);
  cursor: pointer;
  flex-shrink: 0;
  transition: transform 0.1s, border-color 0.1s;
}
.color-swatch:hover { transform: scale(1.15); border-color: #1a1a1a; }
.color-swatch.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 0;
  background-color: #fff;
}
.color-name { font-size: 12px; color: #234; font-weight: 600; cursor: pointer; }
.color-name:hover { color: #000; text-decoration: underline; }

/* ===== Tools Bar ===== */
#tools-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  background: #eeeeee;
  border: 1.5px solid #aaaaaa;
  border-radius: 7px;
  padding: 6px 10px;
  flex-wrap: wrap;
}
.nudge-label { font-weight: 600; font-size: 12px; color: #333; margin-right: 2px; }

#tile-nudge-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 4px 0 2px;
  padding-left: 28px; /* offset by vert bar + gap so content centres over canvas */
}
.nudge-btn {
  padding: 4px 7px;
  border: 1.5px solid #5a5a5a;
  border-radius: 5px;
  background: #eeeeee;
  color: #1a1a1a;
  font-size: 12px;
  cursor: pointer;
  transition: background 0.15s;
}
.nudge-btn:hover  { background: #d5d5d5; }
.nudge-btn:active { background: #5a5a5a; color: #fff; }
.nudge-wrap-label {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  font-weight: 600;
  color: #333;
  margin-left: 4px;
  cursor: pointer;
  user-select: none;
}
.nudge-wrap-label input { accent-color: #5a5a5a; cursor: pointer; }
.tools-bar-sep {
  width: 1px;
  height: 24px;
  background: #999;
  margin: 0 2px;
}

/* ===== Palette Bar ===== */
#palette-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  background: #eeeeee;
  border: 1.5px solid #aaaaaa;
  border-radius: 7px;
  padding: 6px 10px;
  flex-wrap: wrap;
}
#palette-bar label { font-weight: 600; font-size: 12px; }
#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.fg-active { border-color: #ffffff; box-shadow: 0 0 0 2px #000; }
.palette-swatch.bg-active { border-color: #333333; box-shadow: 0 0 0 2px #888; }

.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 0;
  background-color: #fff;
}
.swatch-label { font-size: 9px; color: #456; font-weight: 600; }

/* ===== Tile Editor Main (canvas left + controls right) ===== */
#tile-editor-main {
  display: flex;
  align-items: flex-start;
  gap: 12px;
}

/* Canvas area: symmetry bars + canvas */
#tile-canvas-area {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 2px;
  flex-shrink: 0;
}

#tile-sym-top-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 3px;
  padding-left: 28px; /* offset by vert bar + gap so buttons centre over canvas */
}

#tile-canvas-row {
  display: flex;
  align-items: center;
  gap: 2px;
}

#tile-sym-vert-bar {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  width: 26px;
}

.sym-btn {
  padding: 3px 5px;
  border: 1.5px solid #5a5a5a;
  border-radius: 4px;
  background: #eeeeee;
  color: #3a3a3a;
  font-size: 11px;
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
  line-height: 1;
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.sym-btn:hover { background: #d5d5d5; }
.sym-btn.active { background: #1A6AAF; color: #fff; border-color: #0e4a80; }

.sym-sep {
  color: #999;
  font-size: 14px;
  padding: 0 2px;
}
.sym-sep-v {
  width: 16px;
  height: 1.5px;
  background: #aaa;
  margin: 1px 0;
}

#canvas-wrapper {
  border: 2px solid #5a5a5a;
  border-radius: 4px;
  overflow: hidden;
  line-height: 0;
  flex-shrink: 0;
}

#tile-canvas {
  display: block;
  cursor: crosshair;
  image-rendering: pixelated;
}

/* Controls column to the right of the canvas */
#tile-editor-controls {
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1;
  min-width: 0;
}

/* Color bar, tools bar, palette bar — full width inside the controls column */
#color-bar, #tools-bar, #palette-bar, #canvas-scale-bar {
  width: 100%;
}
.scale-btn {
  padding: 3px 10px;
  border: 1.5px solid #5a5a5a;
  border-radius: 5px;
  background: #eeeeee;
  color: #1a1a1a;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}
.scale-btn:hover:not(:disabled) { background: #d5d5d5; }
.scale-btn.active { background: #5a5a5a; color: #fff; border-color: #3a3a3a; }
.scale-btn:disabled { opacity: 0.35; cursor: default; }

/* Transform buttons — horizontal wrapping row */
#tile-editor-sidebar {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  background: #eeeeee;
  border: 1.5px solid #aaaaaa;
  border-radius: 7px;
  padding: 6px 8px;
}

.rot-btn {
  padding: 5px 8px;
  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;
  min-width: 52px;
}
.rot-btn:hover { background: #d5d5d5; }
.rot-sep {
  border: none;
  border-top: 1.5px solid #999;
  margin: 2px 0;
  width: 100%;
}
.coll-btn[data-coll="0"].active { background: #5a5a5a; color: #fff; border-color: #3a3a3a; }
.coll-btn[data-coll="1"].active { background: #c03030; color: #fff; border-color: #901010; }
.coll-btn[data-coll="2"].active { background: #2a8a2a; color: #fff; border-color: #1a6a1a; }

/* ===== Tile Status Bar ===== */
#tile-status-bar {
  font-size: 11px;
  color: #567;
  padding: 3px 6px;
  background: #e0e0e0;
  border-radius: 4px;
  border: 1px solid #bbb;
}

/* ===== Tileset Section ===== */
#tileset-section .section-header { margin-bottom: 4px; }

/* ===== Tile Import Bar ===== */
#tile-import-bar {
  padding-top: 4px;
  border-top: 1.5px solid #cccccc;
}

/* ===== Tile Import Modal ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}
.modal-dialog {
  background: #f0f0f0;
  border: 1.5px solid #888;
  border-radius: 8px;
  padding: 16px 18px;
  width: 480px;
  max-width: 95vw;
  display: flex;
  flex-direction: column;
  gap: 10px;
  box-shadow: 0 6px 24px rgba(0,0,0,0.25);
}
.modal-header {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 14px;
  color: #1a1a1a;
}
.modal-close-btn {
  margin-left: auto;
  background: none;
  border: none;
  cursor: pointer;
  font-size: 16px;
  color: #666;
  padding: 2px 4px;
  line-height: 1;
}
.modal-close-btn:hover { color: #111; }
.modal-hint {
  margin: 0;
  font-size: 11px;
  line-height: 1.7;
  color: #567;
  font-style: italic;
}
.modal-hint code {
  font-family: 'Cascadia Code', 'Consolas', monospace;
  font-size: 10.5px;
  background: #e2e2e2;
  padding: 1px 4px;
  border-radius: 3px;
  color: #1a1a1a;
}

#tile-import-textarea {
  width: 100%;
  box-sizing: border-box;
  font-family: 'Cascadia Code', 'Consolas', monospace;
  font-size: 12px;
  padding: 8px;
  border: 1.5px solid #aaaaaa;
  border-radius: 5px;
  background: #fafafa;
  resize: vertical;
  color: #1a1a1a;
}
#tile-import-textarea:focus { outline: none; border-color: #5a5a5a; }
.modal-footer {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

.tileset-controls { display: flex; align-items: center; gap: 8px; margin-left: auto; }

/* Swap bar */
#tileset-swap-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 8px;
  margin-bottom: 6px;
  background: #eeeeee;
  border: 1.5px solid #aaaaaa;
  border-radius: 6px;
  flex-wrap: wrap;
}
.swap-label {
  font-size: 12px;
  font-weight: 700;
  color: #333;
}
.swap-target-group {
  display: flex;
  border: 1.5px solid #5a5a5a;
  border-radius: 4px;
  overflow: hidden;
}
.swap-target-btn {
  padding: 2px 9px;
  font-size: 11px;
  font-weight: 700;
  border: none;
  background: #eeeeee;
  cursor: pointer;
  color: #333;
}
.swap-target-btn.active { background: #5a5a5a; color: #fff; }
.swap-target-btn:hover:not(.active) { background: #d5d5d5; }
.swap-color-label {
  font-size: 11px;
  color: #555;
}
.swap-color-swatch {
  display: inline-block;
  width: 20px;
  height: 20px;
  border: 1.5px solid #5a5a5a;
  border-radius: 3px;
  cursor: pointer;
  flex-shrink: 0;
  vertical-align: middle;
}
.swap-color-swatch:hover { border-color: #1a1a1a; }
.swap-select-links {
  font-size: 11px;
  color: #555;
  margin-left: auto;
}
.swap-select-links a {
  color: #333;
  cursor: pointer;
  text-decoration: underline;
}
.swap-select-links a:hover { color: #000; }

/* Group swap checkbox */
.group-swap-cb {
  width: 14px;
  height: 14px;
  cursor: pointer;
  flex-shrink: 0;
  accent-color: #4a7aaa;
}

#tileset-groups-container {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 320px;
  overflow-y: auto;
  padding-right: 4px;
}

.tile-group {
  background: #eeeeee;
  border: 1.5px solid #aaaaaa;
  border-radius: 7px;
  padding: 6px 10px 8px;
}

.tile-group-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}

.group-name-input {
  padding: 3px 7px;
  border: 1.5px solid #aaaaaa;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 700;
  background: #f5f5f5;
  width: 140px;
}
.group-name-input:focus { outline: 2px solid #5a5a5a; border-color: #5a5a5a; }

.group-info {
  font-size: 11px;
  color: #678;
  font-style: italic;
}

.group-color-pair {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
  margin-right: 8px;
  padding: 2px 8px;
  background: #e4e4e4;
  border: 1px solid #bbb;
  border-radius: 5px;
}

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

.group-color-label {
  font-size: 11px;
  font-weight: 700;
  color: #444;
}

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

.group-delete-btn {
  padding: 3px 7px;
  font-size: 11px;
}

.tile-thumbs-row {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.tile-thumb-wrapper {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  cursor: pointer;
  border-radius: 5px;
  padding: 3px;
  border: 2px solid transparent;
  transition: border-color 0.1s, background 0.1s, box-shadow 0.1s;
}
.tile-thumb-wrapper:hover {
  background: rgba(0,0,0,0.08);
  border-color: #aaaaaa;
}
.tile-thumb-wrapper.tile-thumb-selected {
  border-color: #33ff33;
  box-shadow: 0 0 6px rgba(51,255,51,0.7), 0 0 12px rgba(51,255,51,0.3);
  background: rgba(51,255,51,0.06);
}

.tile-thumb-canvas {
  display: block;
  image-rendering: pixelated;
  border: 1px solid #999;
  border-radius: 2px;
}

.tile-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: 11px;
  cursor: pointer;
  display: none;
  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);
}
.tile-clone-btn:hover { background: #d5d5d5; border-color: #4a4a4a; }
.tile-thumb-wrapper:hover .tile-clone-btn { display: flex; }

.tile-thumb-label {
  font-size: 9px;
  color: #567;
  font-weight: 600;
}

/* ===== Screen Section ===== */
.screen-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-left: auto;
}
.screen-controls label { font-weight: 600; font-size: 12px; }

.zoom-group {
  display: flex;
  border: 1.5px solid #5a5a5a;
  border-radius: 5px;
  overflow: hidden;
}
.zoom-btn {
  padding: 4px 10px;
  border: none;
  border-radius: 0;
  font-size: 12px;
}
.zoom-btn + .zoom-btn { border-left: 1.5px solid #5a5a5a; }

.screen-sep { color: #999; font-size: 16px; }

/* Screen canvas layout */
#screen-canvas-layout {
  display: flex;
  align-items: flex-start;
  gap: 10px;
}
#screen-canvas-col {
  flex-shrink: 0;
}
#screen-canvas-sidebar {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 110px;
  flex-shrink: 0;
  overflow-wrap: break-word;
  word-break: break-word;
  overflow: visible;
}

/* Status bar — stacked */
#screen-status-bar {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 11px;
  color: #567;
  padding: 6px 8px;
  background: #e0e0e0;
  border-radius: 4px;
  height: 180px;
  box-sizing: border-box;
  border: 1px solid #bbb;
  word-break: break-word;
  overflow: hidden;
}
#screen-status-title {
  font-weight: 700;
  font-size: 11px;
  color: #444;
  flex-shrink: 0;
  border-bottom: 1px solid #bbb;
  padding-bottom: 3px;
  margin-bottom: 1px;
}
#screen-status-text {
  flex-shrink: 1;
  overflow: hidden;
}
#screen-tile-thumb {
  flex-shrink: 0;
  width: 48px;
  height: 48px;
  border-radius: 3px;
  image-rendering: pixelated;
}
#screen-tile-attr,
#screen-coords {
  flex-shrink: 0;
}

/* Background box */
#screen-bg-bar {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 11px;
  color: #567;
  padding: 6px 8px;
  background: #e0e0e0;
  border-radius: 4px;
  border: 1px solid #bbb;
  box-sizing: border-box;
}
#screen-bg-title {
  font-weight: 700;
  font-size: 11px;
  color: #444;
  flex-shrink: 0;
  border-bottom: 1px solid #bbb;
  padding-bottom: 3px;
  margin-bottom: 1px;
}
#screen-bg-swatches {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 3px;
}

#screen-import-bar {
  width: 100%;
  box-sizing: border-box;
}
#png-import-btn {
  width: 100%;
  box-sizing: border-box;
  font-size: 11px;
  padding: 5px 6px;
}
#screen-flip-bar {
  width: 100%;
  box-sizing: border-box;
  margin-top: 25px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
#screen-flip-bar .action-btn {
  width: 100%;
  box-sizing: border-box;
  font-size: 11px;
  padding: 5px 6px;
}

.screen-bg-swatch {
  display: block;
  width: 100%;
  aspect-ratio: 1;
  border-radius: 3px;
  border: 2px solid transparent;
  cursor: pointer;
  transition: transform 0.1s, border-color 0.1s;
  box-sizing: border-box;
}
.screen-bg-swatch:hover { transform: scale(1.18); border-color: #555; }
.screen-bg-swatch.screen-bg-active {
  border-color: #1a1a1a;
  box-shadow: 0 0 0 2px #5a5a5a;
  transform: scale(1.1);
}

/* Screen mode bar */
#screen-mode-bar {
  display: flex;
  align-items: stretch;
  justify-content: center;
  gap: 12px;
  flex-wrap: wrap;
}

.screen-mode-group {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border: 2px solid #aaaaaa;
  border-radius: 8px;
  background: #e0e0e0;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.screen-mode-group.active {
  border-color: #5a9e6f;
  background: #d4edda;
}

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

#screen-attr-options {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-left: 6px;
  padding-left: 10px;
  border-left: 1.5px solid #aaa;
}

.screen-attr-btn {
  padding: 5px 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, color 0.15s;
  white-space: nowrap;
}
.screen-attr-btn:hover:not(.active) { background: #d5d5d5; }
.screen-attr-btn[data-attr="none"].active     { background: #5a5a5a; color: #fff; border-color: #3a3a3a; }
.screen-attr-btn[data-attr="solid"].active    { background: #c03030; color: #fff; border-color: #901010; }
.screen-attr-btn[data-attr="passthru"].active { background: #2a8a2a; color: #fff; border-color: #1a6a1a; }

#screen-canvas-wrapper {
  overflow: visible;
  line-height: 0;
  display: flex;
  justify-content: center;
}
#screen-canvas-wrapper.scrollable {
  overflow: auto;
  justify-content: flex-start;
  max-width: 100%;
  max-height: 70vh;
  border: 1px solid #aaa;
  border-radius: 4px;
}

#screen-canvas {
  display: block;
  cursor: crosshair;
  image-rendering: pixelated;
  flex-shrink: 0;
}


/* Screen layouts strip */
#screen-layouts-section {
  margin-top: 10px;
  border-top: 1px solid #aaa;
  padding-top: 8px;
}
#screen-layouts-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}
#screen-layouts-header .section-label {
  font-size: 12px;
  font-weight: bold;
  color: #445;
}
#screen-thumbs-container {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.screen-thumb-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  cursor: pointer;
  padding: 4px;
  border: 2px solid #aaa;
  border-radius: 4px;
  background: #bbb;
  position: relative;
  user-select: none;
}
.screen-thumb-wrapper:hover {
  border-color: #789;
  background: #c8c8cc;
}
.screen-thumb-wrapper.active {
  border-color: #3a7ab5;
  background: #c4d8ef;
}
.screen-thumb-wrapper canvas {
  display: block;
  image-rendering: pixelated;
}
.screen-thumb-name-row {
  display: flex;
  align-items: center;
  gap: 3px;
  max-width: 128px;
}
.screen-thumb-name {
  font-size: 10px;
  color: #333;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  flex: 1;
  text-align: center;
}
.screen-thumb-edit-btn {
  flex-shrink: 0;
  padding: 1px 3px;
  border: 1px solid #999;
  border-radius: 3px;
  background: #ddd;
  color: #444;
  font-size: 9px;
  cursor: pointer;
  line-height: 1;
  opacity: 0.5;
  transition: opacity 0.15s, background 0.15s;
}
.screen-thumb-wrapper:hover .screen-thumb-edit-btn { opacity: 1; }
.screen-thumb-edit-btn:hover { background: #c8c8c8; }
.screen-thumb-name-input {
  font-size: 10px;
  width: 100px;
  padding: 1px 3px;
  border: 1px solid #888;
  border-radius: 2px;
}
.screen-thumb-del {
  position: absolute;
  top: -6px;
  right: -6px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 1px solid #a03030;
  background: #e05050;
  color: #fff;
  font-size: 10px;
  line-height: 14px;
  text-align: center;
  cursor: pointer;
  display: none;
  padding: 0;
}
.screen-thumb-wrapper:hover .screen-thumb-del {
  display: block;
}
.screen-thumb-clone {
  position: absolute;
  bottom: -8px;
  right: -8px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 1.5px solid #5a5a5a;
  background: #eeeeee;
  color: #3a3a3a;
  font-size: 11px;
  cursor: pointer;
  display: none;
  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);
}
.screen-thumb-clone:hover { background: #d5d5d5; border-color: #4a4a4a; }
.screen-thumb-wrapper:hover .screen-thumb-clone { display: flex; }
.screen-arrow-row {
  display: flex;
  gap: 4px;
  justify-content: center;
  min-height: 18px;
  width: 100%;
}
.screen-arrow-btn {
  padding: 1px 7px;
  border: 1.5px solid #5a5a5a;
  border-radius: 3px;
  background: #eeeeee;
  color: #3a3a3a;
  font-size: 11px;
  cursor: pointer;
  line-height: 1;
  transition: background 0.15s;
}
.screen-arrow-btn:hover { background: #d5d5d5; }

/* ===== Output Panel ===== */
#output-panel-header {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  padding-bottom: 6px;
  border-bottom: 1.5px solid #aaaaaa;
  margin-bottom: 4px;
}
#output-panel-header > span {
  font-weight: 700;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

#output-filter-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-left: 6px;
}
.output-filter-label {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  color: #445;
  cursor: pointer;
  user-select: none;
}
.output-filter-cb { cursor: pointer; accent-color: #1A6AAF; }

#output-pre {
  background: #1a1a2e;
  color: #c8e6c9;
  font-family: 'Consolas', 'Courier New', monospace;
  font-size: 12px;
  line-height: 1.5;
  padding: 10px 12px;
  border-radius: 6px;
  overflow: auto;
  max-height: 360px;
  white-space: pre;
  tab-size: 4;
}

/* Syntax Highlighting */
.hl-key         { color: #80cbc4; font-weight: 700; }   /* JSON keys           */
.hl-str         { color: #a5d6a7; }                      /* JSON strings        */
.hl-num         { color: #ffab91; font-weight: 600; }    /* numbers             */
.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; }    /* $XX hex literals    */
.hl-pixel       { color: #ffffff; font-weight: 900; }    /* BITMAP X on-pixels  */
.hl-transparent { color: #37474f; }                      /* BITMAP . off-pixels */

/* ===== Color Picker Popup ===== */
#color-picker-popup {
  display: none;
  position: fixed;
  z-index: 800;
  background: #eeeeee;
  border: 1.5px solid #5a5a5a;
  border-radius: 8px;
  padding: 8px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.3);
  flex-wrap: wrap;
  gap: 4px;
  width: 180px;
}
#color-picker-popup.visible { display: flex; }
#color-picker-popup .cp-swatch {
  display: inline-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;
}
#color-picker-popup .cp-swatch:hover { transform: scale(1.1); border-color: #1a1a1a; }
#color-picker-popup .cp-swatch.cp-active { border-color: #1a1a1a; box-shadow: 0 0 0 2px #5a5a5a; }
#color-picker-popup .cp-color {
  width: 22px;
  height: 22px;
  border-radius: 3px;
  border: 1px solid rgba(0,0,0,0.2);
}
#color-picker-popup .cp-label { font-size: 9px; color: #456; font-weight: 600; }
#color-picker-title {
  width: 100%;
  font-size: 11px;
  font-weight: 700;
  color: #333;
  margin-bottom: 2px;
  text-align: center;
}
