input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

input[type="number"] {
  -moz-appearance: textfield;
}

body {
  padding: 0;
  margin: 0;
}

#autoSwitch {
  color: blue;
}

#saveFont {
  color: blue;
}

.vt323-regular {
  font-family: "VT323", monospace;
  font-weight: 400;
  font-style: normal;
}

#container1 {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

#container2 {
  display: flex;
  overflow: auto;
  flex: 1;
}

#header {
  height: 28px;
  background-color: rgb(255, 255, 255);
  border-style: solid;
  border-width: 2px;
}

#header-text,
.header-text {
  color: rgb(0, 0, 0);
  text-align: center;
  margin-top: 5px;
  font-size: 18px;
  font-family: 'VT323';
}

#bottom {
  height: 28px;
  /* Footer uses white background with black text */
  background-color: rgb(255, 255, 255);
  border-style: solid;
  border-width: 2px;
}

#middleBox {
  flex: 1;
  overflow: scroll;
}

#sideBox,
.sideBox {
  width: 16vw;
  background-color: rgb(255, 255, 255);
  display: flex;
  flex-direction: column;
  border-right-style: solid;
  border-left-style: solid;
  border-width: 2px;
}

#introduction,
.introduction {
  font-family: 'VT323';
  font-size: 200%;
  line-height: 80%;
  text-align: center;
  margin: 30px 5px 10px 5px;
  color: rgb(0, 0, 0);
}

#controlPanel,
.controlPanel {
  background-color: white;
  margin: 20px 28px;
  height: 20vh;
  flex: 1;
  display: flex;
  flex-direction: column;
  box-sizing: border-box;
}

select {
  -webkit-appearance: none;
  /* Chrome, Safari, Edge, Opera */
  -moz-appearance: none;
  /* Firefox */
  appearance: none;
  border: none;
  background: transparent;
  color: blue;
  outline: none;
  font-family: 'VT323';
  font-size: 18px;
  flex: 1;
  box-sizing: border-box;
  width: 1px;
  /* Keep value aligned to the right like number inputs */
  text-align: right;
  /* Chrome needs this to align the selected option text */
  text-align-last: right;
  /* Avoid extra inset that prevents true right alignment */
  padding: 0;
  /* Match row height and keep vertical centering consistent */
  height: 20px;
  line-height: 20px;
  cursor: pointer;
}

input {
  border: none;
  background: transparent;
  color: blue;
  outline: none;
  font-family: 'VT323';
  font-size: 18px;
  flex: 1;
  box-sizing: border-box;
  width: 1px;
  text-align: right;
}

label {
  font-family: 'VT323';
  font-size: 18px;
  /* Align with 20px control row */
  line-height: 20px;
}

textarea {
  border: none;
  background: transparent;
  color: blue;
  outline: none;
  font-family: 'VT323';
  font-size: 18px;
  height: 36px;
  width: 100%;
  padding: 0px;
}

pre {
  margin: 5px 27px;
  border: none;
  background: transparent;
  color: rgb(0, 0, 0);
  outline: none;
  font-family: 'VT323';
  font-size: 18px;
  height: 80px;
  width: 260px;
}

#fontData {
  border: none;
  background: transparent;
  color: blue;
  outline: none;
  font-family: 'VT323';
  font-size: 18px;
  margin: 20px 0px;
  height: 100%;
  width: 100%;
}

#output-matrix {
  margin: 5px 27px;
  border: none;
  background: transparent;
  color: blue;
  outline: none;
  font-family: 'VT323';
  font-size: 18px;
  height: 90%;
  width: 260px;
}

#inputText {
  margin: 5px 0px;
  border: none;
  background: transparent;
  color: blue;
  outline: none;
  font-family: 'VT323';
  font-size: 18px;
  height: 100%;
  width: 100%;
}

#inputBlock,
.inputBlock {
  display: flex;
  height: 20px;
  /* Vertically center label and control for consistent alignment in Chrome/Safari */
  align-items: center;
}

input[type='color'] {
  padding: 5px 2px 7px 10px;
  border: none;
  height: 20px;
  cursor: pointer;
}

input[type="color"]::-webkit-color-swatch-wrapper {
  padding: 0;
}

input[type="color"]::-webkit-color-swatch {
  border: none;
}

a {
  color: white;
}

a:visited {
  color: rgb(0, 0, 0);
}

/* Footer links should be black on white footer */
#bottom a,
#bottom a:visited {
  color: rgb(0, 0, 0);
}

#buttonContainer,
.buttonContainer {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  margin-bottom: 20px;
}

#buttonContainer button,
.buttonContainer button {
  border: none;
  background: transparent;
  font-family: 'VT323';
  font-size: 18px;
  color: blue;
  margin: 8px;
  cursor: pointer;
}

/* Modal Styles */
.modal {
  display: none;
  /* Hidden by default */
  position: fixed;
  z-index: 1000;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.4);
  align-items: center;
  justify-content: center;
}

.modal.modal-open {
  display: flex;
}


.modal-content {
  background-color: rgb(255, 255, 255);
  /* Match sideBox background */
  color: rgb(0, 0, 0);
  /* Match text color */
  padding: 20px;
  border: 2px solid rgb(0, 0, 0);
  /* Match border style */
  width: 80%;
  /* Could be more or less, depending on screen size */
  max-width: 500px;
  text-align: center;
  font-family: 'VT323', monospace;
  max-height: 90vh;
  overflow-y: auto;
  position: relative;
}

.modal-content p {
  font-size: 18px;
  margin: 4px;
}

.modal-content label {
  display: block;
  margin-bottom: 10px;
  font-size: 18px;
  margin-left: 0;
  /* Override general label margin */
  padding-top: 0;
  /* Override general label padding */
}

.modal-content input[type="text"] {
  width: calc(100% - 22px);
  /* Adjust width considering padding */
  padding: 10px;
  margin-bottom: 20px;
  border: 1px solid rgb(0, 0, 0);
  background-color: white;
  /* Match controlPanel background */
  color: rgb(0, 0, 0);
  font-family: 'VT323', monospace;
  font-size: 18px;
  text-align: left;
  /* Override general input text-align */
}

.modal-content button {
  background-color: white;
  /* Match controlPanel background */
  color: rgb(0, 0, 0);
  padding: 10px 20px;
  border: 1px solid rgb(0, 0, 0);
  cursor: pointer;
  margin: 5px;
  font-family: 'VT323', monospace;
  font-size: 18px;
}

.modal-content button:hover {
  background-color: #eee;
  /* Lighter hover */
}

.close {
  color: #aaa;
  float: right;
  font-size: 28px;
  font-weight: bold;
}

.close:hover,
.close:focus {
  color: black;
  text-decoration: none;
  cursor: pointer;
}

#modal-cancel {
  background-color: #ccc;
  /* Slightly different background for cancel */
}

#modal-cancel:hover {
  background-color: #bbb;
}

#single-char-matrix-preview {
  overflow: auto;
  height: auto;
  min-height: 80px;
}

#output-matrix {
  overflow: auto;
  color: blue;
}

/* Canvas cursor helpers used by INTR-PIXEL-WIZARD */
.canvas-grab {
  cursor: grab;
}

.canvas-grabbing {
  cursor: grabbing;
}

.canvas-resize-ew {
  cursor: ew-resize;
}

.canvas-resize-ns {
  cursor: ns-resize;
}

.canvas-resize-nwse {
  cursor: nwse-resize;
}

.canvas-resize-nesw {
  cursor: nesw-resize;
}

/* INTR-PIXEL-WIZARD specific sizing */
#chars-to-process {
  height: 140px;
}

#status-brief {
  font-family: 'VT323';
  font-size: 18px;
  color: blue;
}

/* Header right-side navigation (tool switcher) */
#header {
  position: relative;
}

.header-nav {
  position: absolute;
  right: 8px;
  top: 2px;
  display: flex;
  gap: 8px;
}

.header-nav button {
  border: none;
  background: transparent;
  font-family: 'VT323';
  font-size: 18px;
  color: blue;
  cursor: pointer;
  padding: 0;
}

.header-nav button[disabled] {
  color: rgb(0, 0, 0);
  cursor: default;
}

.home-middle {
  flex: 1;
  background-color: white;
  display: flex;
  justify-content: center;
  /* horizontal center of content block */
  align-items: center;
  /* vertical center of content block */
}

.home-content {
  max-width: 960px;
  width: 100%;
  margin: 0 auto;
  /* center content block so cards group is centered */
  padding: 36px 48px;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  gap: 28px;
  color: black;
}

.home-tagline {
  margin: 0;
  font-family: 'VT323';
  font-size: 22px;
  line-height: 1.2;
  letter-spacing: 1px;
}

.home-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 24px;
  justify-content: center;
  /* center tracks when there is extra space */
}

.home-card {
  border: 2px solid rgb(0, 0, 0);
  background-color: rgb(255, 255, 255);
  padding: 24px;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-height: 220px;
}

.home-card h2 {
  margin: 0;
  font-family: 'VT323';
  font-size: 28px;
  color: rgb(0, 0, 0);
}

.home-card p {
  margin: 0;
  font-family: 'VT323';
  font-size: 18px;
  line-height: 1.28;
  color: rgb(0, 0, 0);
}

.home-launch {
  border: none;
  background: transparent;
  font-family: 'VT323';
  font-size: 18px;
  color: blue;
  cursor: pointer;
  padding: 0;
  align-self: flex-start;
}

.home-launch:hover {
  text-decoration: underline;
}

.home-side-note {
  margin: 0 24px 24px;
  font-family: 'VT323';
  font-size: 16px;
  line-height: 1.2;
  color: rgb(0, 0, 0);
}

.home-side-note p {
  margin: 0;
}

/* Pattern Editor Styles */
.editor-modal {
  max-width: 90vw;
  width: 1200px;
  height: 80vh;
  max-height: none;
  display: flex;
  flex-direction: column;
}

.editor-modal h2 {
  font-family: 'VT323';
  font-size: 24px;
  margin: 0 0 20px 0;
  text-align: left;
}

.editor-container {
  display: flex;
  gap: 20px;
  flex: 1;
  overflow: hidden;
}

.editor-left-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0px;
  overflow-y: auto;
  border-right: 2px solid rgb(0, 0, 0);
  padding-right: 15px;
}

.editor-right-panel {
  flex: 1;
  overflow: auto;
  display: flex;
  flex-direction: column;
}

.editor-section {
  border: 1px solid rgb(0, 0, 0);
  padding: 10px;
  background-color: white;
}

.editor-section h4 {
  font-family: 'VT323';
  font-size: 20px;
  margin: 0 0 10px 0;
}

/* Component Previews */
.component-grid {
  display: grid;
  grid-template-columns: repeat(10, 1fr);
  gap: 4px;
}

.component-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 4px;
  border: 1px solid rgb(200, 200, 200);
  cursor: pointer;
  background-color: white;
  box-sizing: border-box;
}

.component-item:hover {
  background-color: #f0f0f0;
}

.component-item.selected {
  border: 2px solid blue;
  background-color: #e6f0ff;
}

.component-preview {
  width: 25px;
  height: 25px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.component-preview svg {
  max-width: 100%;
  max-height: 100%;
}

.component-preview .empty-preview,
.component-preview .undefined-preview {
  font-family: 'VT323';
  font-size: 12px;
  color: #999;
}

.component-label {
  font-family: 'VT323';
  font-size: 10px;
  text-align: center;
  word-break: break-word;
  line-height: 1;
}

/* Matrix Settings */
.matrix-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

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

.matrix-input-group label {
  font-family: 'VT323';
  font-size: 20px;
  margin: 0;
}

.matrix-input-group input {
  width: 60px;
  border: 1px solid rgb(0, 0, 0);
  padding: 4px 6px;
  font-family: 'VT323';
  font-size: 20px;
  text-align: center;
}

.matrix-controls button {
  font-family: 'VT323';
  font-size: 20px;
  padding: 6px 10px;
  border: 1px solid rgb(0, 0, 0);
  background-color: white;
  cursor: pointer;
  white-space: nowrap;
}

.matrix-controls button:hover {
  background-color: #f0f0f0;
}

/* Old matrix settings styles - kept for backwards compatibility */
.setting-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.setting-row label {
  font-family: 'VT323';
  font-size: 16px;
}

.setting-row input {
  width: 80px;
  border: 1px solid rgb(0, 0, 0);
  padding: 4px;
  font-family: 'VT323';
  font-size: 16px;
  text-align: center;
}

.setting-buttons {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 10px;
}

.setting-buttons button {
  font-family: 'VT323';
  font-size: 16px;
  padding: 6px;
  border: 1px solid rgb(0, 0, 0);
  background-color: white;
  cursor: pointer;
}

.setting-buttons button:hover {
  background-color: #f0f0f0;
}

/* Character List */
.char-toolbar {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
}

.char-toolbar button {
  flex: 1;
  font-family: 'VT323';
  font-size: 20px;
  padding: 8px;
  border: 1px solid rgb(0, 0, 0);
  background-color: white;
  cursor: pointer;
}

.char-toolbar button:hover {
  background-color: #f0f0f0;
}

.char-list-container {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(50px, 1fr));
  gap: 6px;
  max-height: 400px;
  overflow-y: auto;
  border: none;
  padding: 8px;
}

.char-item {
  padding: 10px;
  font-family: 'VT323';
  font-size: 20px;
  cursor: pointer;
  border: none;
  background-color: white;
  text-align: center;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
}

.char-item:hover {
  background-color: #f0f0f0;
}

.char-item.selected {
  background-color: #e6f0ff;
  border: 2px solid blue;
}

/* Character Preview SVG */
.char-preview-svg {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 5px;
}

.char-preview-svg svg {
  display: block;
}

/* Grid Editor */
#gridEditor h4 {
  font-family: 'VT323';
  font-size: 22px;
  margin: 0 0 15px 0;
}

.pattern-grid {
  display: grid;
  gap: 2px;
  background-color: rgb(200, 200, 200);
  border: 2px solid rgb(0, 0, 0);
  padding: 2px;
  margin: 0 auto 20px auto;
  width: fit-content;
}

.pattern-grid>* {
  width: 30px;
  height: 30px;
}

.grid-cell {
  border: 1px solid rgb(200, 200, 200);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-family: 'VT323';
  font-size: 20px;
  background-color: white;
  position: relative;
  padding: 2px;
}

.grid-cell img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.grid-cell:hover {
  background-color: #f0f0f0;
}

.grid-cell.empty {
  background-color: #f9f9f9;
}

.grid-cell.multi-selected {
  background-color: #fff3cd;
  border: 2px solid orange;
}

/* Component colors for visual feedback */
.grid-cell.component-0 {
  background-color: #e8e8e8;
}

.grid-cell.component-1 {
  background-color: #ffe6e6;
  color: #cc0000;
}

.grid-cell.component-2 {
  background-color: #e6f0ff;
  color: #0066cc;
}

.grid-cell.component-3 {
  background-color: #e6ffe6;
  color: #00cc00;
}

.grid-cell.component-4 {
  background-color: #fff0e6;
  color: #cc6600;
}

.grid-cell.component-5 {
  background-color: #ffe6ff;
  color: #cc00cc;
}

.grid-cell.component-6 {
  background-color: #ffffe6;
  color: #cccc00;
}

.grid-cell.component-7 {
  background-color: #f0f0f0;
  color: #666666;
}

.grid-cell.component-8 {
  background-color: #fff0f0;
  color: #996666;
}

.current-component-indicator {
  font-family: 'VT323';
  font-size: 18px;
  color: blue;
  margin-top: 10px;
  padding: 10px;
  border: 1px solid rgb(0, 0, 0);
  background-color: #f9f9f9;
}

/* Custom Dialog Styles */
.custom-dialog-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10000;
}

.custom-dialog {
  background-color: white;
  border: 2px solid rgb(0, 0, 0);
  padding: 20px;
  min-width: 300px;
  max-width: 500px;
  font-family: 'VT323';
}

.custom-dialog-message {
  font-family: 'VT323';
  font-size: 18px;
  margin: 0 0 20px 0;
  color: rgb(0, 0, 0);
}

.custom-dialog-input {
  width: 100%;
  border: 1px solid rgb(0, 0, 0);
  padding: 8px;
  margin-bottom: 20px;
  font-family: 'VT323';
  font-size: 16px;
  box-sizing: border-box;
  background-color: white;
  color: rgb(0, 0, 0);
}

.custom-dialog-buttons {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

.custom-dialog-btn {
  font-family: 'VT323';
  font-size: 16px;
  padding: 8px 16px;
  border: 1px solid rgb(0, 0, 0);
  background-color: white;
  cursor: pointer;
  min-width: 80px;
}

.custom-dialog-btn:hover {
  background-color: #f0f0f0;
}

.custom-dialog-btn-confirm {
  background-color: white;
}

.custom-dialog-btn-cancel {
  background-color: #eee;
}

/* ===========================
   MODERN UI
   =========================== */

/* Hide classic panel in modern mode */
body.modern-ui .classic-control-panel,
body.modern-ui .action-button-container {
  display: none !important;
}

/* modernPanel hidden by default, shown in modern mode */
#modernPanel {
  display: none;
  flex-direction: column;
  flex: 1;
  overflow-y: auto;
  padding: 0 14px 14px 14px;
  box-sizing: border-box;
  gap: 0;
}

body.modern-ui #modernPanel {
  display: flex;
}

body.modern-ui #container1 {
  height: 100vh;
}

body.modern-ui #header,
body.modern-ui #bottom {
  display: none;
}

body.modern-ui #container2 {
  position: relative;
  height: 100vh;
  overflow: hidden;
}

body.modern-ui #middleBox {
  flex: 1;
  overflow: auto;
  display: flex;
  justify-content: center;
  align-items: flex-start;
}

body.modern-ui .glyph-data-panel {
  display: none;
}

body.modern-ui .intr-pixel-controls {
  width: 0;
  min-width: 0;
  flex: 0 0 0;
  border: 0;
  background: transparent;
  overflow: visible;
  z-index: 20;
}

body.modern-ui .intr-pixel-controls::before {
  content: '';
  position: fixed;
  left: 16px;
  top: 16px;
  width: min(320px, calc(100vw - 32px));
  height: 138px;
  border: 2px solid #000;
  background: #fff;
  box-sizing: border-box;
  z-index: 30;
  pointer-events: none;
}

body.modern-ui .intr-pixel-controls > .introduction {
  position: fixed;
  left: 28px;
  top: 28px;
  width: min(296px, calc(100vw - 56px));
  margin: 0;
  text-align: left;
  font-size: 28px;
  line-height: 1;
  z-index: 31;
}

body.modern-ui .top-btn-container {
  position: fixed;
  left: 24px;
  top: 58px;
  width: min(304px, calc(100vw - 48px));
  margin: 0 !important;
  justify-content: flex-start;
  z-index: 31;
}

body.modern-ui .top-btn-container button {
  margin: 4px;
}

body.modern-ui #modernPanel {
  display: block;
  position: static;
  padding: 0;
  overflow: visible;
  flex: none;
}

body.modern-ui #modernPanel > .modern-section {
  position: fixed;
  margin: 0;
  box-sizing: border-box;
  padding: 10px;
  z-index: 30;
  overflow: visible;
}

body.modern-ui #modernPanel > .modern-section:nth-child(1) {
  left: 24px;
  top: 96px;
  width: min(304px, calc(100vw - 48px));
  border: 0;
  padding: 0 4px;
  background: transparent;
  z-index: 31;
}

body.modern-ui #modernPanel > .modern-section:nth-child(2) {
  left: 16px;
  bottom: 16px;
  width: min(340px, calc(100vw - 32px));
  padding-bottom: 16px;
}

body.modern-ui #modernPanel > .modern-section:nth-child(3) {
  right: 16px;
  top: 16px;
  width: min(340px, calc(100vw - 32px));
  max-height: calc(50vh - 24px);
  overflow-y: auto;
}

body.modern-ui #modernPanel > .modern-section:nth-child(4) {
  right: 16px;
  bottom: 16px;
  width: min(340px, calc(100vw - 32px));
  --text-panel-inner-width: calc(min(340px, calc(100vw - 32px)) - 20px);
}

body.modern-ui #modernPanel > .modern-section:nth-child(1) .modern-section-header {
  display: none;
}

body.modern-ui .modern-mode-row {
  margin: 0;
}

body.modern-ui #modernInputText {
  min-height: 0;
  resize: none;
}

@media (max-width: 760px) {
  body.modern-ui #container2 {
    overflow: auto;
  }

  body.modern-ui #modernPanel > .modern-section,
  body.modern-ui .intr-pixel-controls::before,
  body.modern-ui .intr-pixel-controls > .introduction,
  body.modern-ui .top-btn-container {
    position: absolute;
  }

  body.modern-ui .intr-pixel-controls::before {
    left: 12px;
    top: 12px;
  }

  body.modern-ui .intr-pixel-controls > .introduction {
    left: 24px;
    top: 24px;
  }

  body.modern-ui .top-btn-container {
    left: 20px;
    top: 54px;
  }

  body.modern-ui #modernPanel > .modern-section:nth-child(1) {
    left: 20px;
    top: 92px;
  }

  body.modern-ui #modernPanel > .modern-section:nth-child(2) {
    left: 12px;
    top: 170px;
    bottom: auto;
  }

  body.modern-ui #modernPanel > .modern-section:nth-child(3) {
    left: 12px;
    right: auto;
    top: 540px;
    max-height: none;
  }

body.modern-ui #modernPanel > .modern-section:nth-child(4) {
    left: 12px;
    right: auto;
    top: 700px;
    bottom: auto;
  }
}

/* Section header: — label — */
.modern-section {
  margin-top: 8px;
}

.modern-section-header {
  display: flex;
  align-items: center;
  margin-bottom: 6px;
  font-family: 'VT323';
  font-size: 16px;
  color: #000;
}

.modern-section-header::before,
.modern-section-header::after {
  content: '';
  flex: 1;
  height: 1px;
  background: #000;
}

.modern-section-header span {
  padding: 0 8px;
}

/* Mode icon button row */
.modern-mode-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 4px;
}

.mode-btn-group {
  display: flex;
}

.mode-icon-btn {
  width: 32px;
  height: 32px;
  border: 2px solid #000;
  background: #fff;
  cursor: pointer;
  padding: 3px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
  color: #000;
  flex-shrink: 0;
  position: relative;
}

.mode-btn-group .mode-icon-btn + .mode-icon-btn {
  margin-left: -2px;
}

.mode-icon-btn svg,
.mode-icon-btn img {
  width: 100%;
  height: 100%;
  display: block;
}

.mode-icon-btn.active {
  background: #000;
  color: #fff;
  z-index: 1;
}

.mode-icon-btn.active img {
  filter: invert(1);
}

.mode-icon-btn:hover:not(.active) {
  background: #eee;
  z-index: 1;
}

/* Dots 2x2 grid */
.modern-dots-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0;
}

.dot-cell {
  position: relative;
  aspect-ratio: 1 / 1;
  overflow: visible;
  box-sizing: border-box;
  border-right:  2px solid #000;
  border-bottom: 2px solid #000;
}

#positionCell {
  order: 3;
}

#intervalCell {
  order: 4;
}
#dotUsedCell,
#positionCell {
  border-left: 2px solid #000;
}

#dotUsedCell,
#dotUnusedCell {
  border-top: 2px solid #000;
}

.dot-cell canvas {
  width: 100%;
  height: 100%;
  display: block;
}

/* ── Position widget (BR cell) ─────────────────────────────── */

.pos-widget {
  width: 100%; height: 100%;
  position: relative; overflow: hidden;
  user-select: none; touch-action: none;
  background-color: #fff;

}
.pos-widget::before, .pos-widget::after {
  content: ''; position: absolute;
  background: rgba(0,0,0,0.26); pointer-events: none; z-index: 1;
}
.pos-widget::before { left: 50%; top: 0; width: 1px; height: 100%; transform: translateX(-0.5px); }
.pos-widget::after  { left: 0; top: 50%; width: 100%; height: 1px; transform: translateY(-0.5px); }

.pos-block {
  position: absolute;
  width: 40%; height: 40%;
  border: 2px solid #000;
  background: transparent;
  transition: left 180ms ease, top 180ms ease;
  z-index: 2;
}

.pos-point {
  position: absolute;
  width: 18px; height: 18px;
  border: none;
  border-radius: 0;
  background: transparent;
  transform: translate(-50%, -50%);
  cursor: pointer;
  z-index: 4;
  padding: 0;
  appearance: none;
}

.pos-point::after {
  content: '';
  position: absolute;
  left: 50%;
  top: 50%;
  width: 6px;
  height: 6px;
  background: #0000ff;
  transform: translate(-50%, -50%);
}

.pos-point:hover::after,
.pos-point.active::after {
  background: #000;
}

.pos-point[data-x="0"]   { left: 0%; }
.pos-point[data-x="0.5"] { left: 50%; }
.pos-point[data-x="1"]   { left: 100%; }
.pos-point[data-y="0"]   { top: 0%; }
.pos-point[data-y="0.5"] { top: 50%; }
.pos-point[data-y="1"]   { top: 100%; }

.pos-center-mark {
  position: absolute; left: 50%; top: 50%;
  transform: translate(-50%, -50%);
  z-index: 3; pointer-events: none;
}
.pos-center-mark::before, .pos-center-mark::after {
  content: ''; position: absolute;
  background: #000; left: 50%; top: 50%;
  transform: translate(-50%, -50%);
}
.pos-center-mark::before { width: 14px; height: 1px; }
.pos-center-mark::after  { width: 1px; height: 14px; }

/* ── Interval widget (BL cell) ─────────────────────────────── */

.int-widget {
  width: 100%;
  height: 100%;
  position: relative;
  overflow: hidden;
  user-select: none;
  touch-action: none;
  background-color: #fff;
}

.int-widget::before,
.int-widget::after {
  content: '';
  position: absolute;
  background: rgba(0,0,0,0.26);
  pointer-events: none;
  z-index: 1;
}
.int-widget::before { left: 50%; top: 0; width: 1px; height: 100%; transform: translateX(-0.5px); }
.int-widget::after  { left: 0; top: 50%; width: 100%; height: 1px; transform: translateY(-0.5px); }

/* dashed bounding cell — always centered */
.int-spacing-box {
  position: absolute;
  left: 50%; top: 50%;
  transform: translate(-50%, -50%);
  border: none;
  border-top: 1.5px dashed rgba(0,0,0,0.7);
  border-right: 1.5px dashed rgba(0,0,0,0.7);
  z-index: 2;
  min-width: 6px;
  min-height: 6px;
  pointer-events: none;
  box-sizing: border-box;
  transition: width 180ms ease, height 180ms ease;
}

/* inner draggable fill (center handle) */
.int-fill {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 18px;
  height: 18px;
  transform: translate(-50%, -50%);
  cursor: move;
  pointer-events: auto;
  z-index: 4;
  background: transparent;
  display: flex;
  align-items: center;
  justify-content: center;
}

.int-fill::after,
.int-metric-handle::after {
  content: '';
  width: 6px;
  height: 6px;
  background: #000;
  display: block;
}

.int-metric-handle {
  position: absolute;
  z-index: 4;
  width: 18px;
  height: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  background: transparent;
}

.int-metric-handle.int-mid-left,
.int-metric-handle.int-mid-right {
  top: 50%;
  transform: translate(-50%, -50%);
}

.int-metric-handle.int-mid-left { left: 0; }
.int-metric-handle.int-mid-right { left: 100%; }

.int-metric-handle.int-mid-top,
.int-metric-handle.int-mid-bottom {
  left: 50%;
  transform: translate(-50%, -50%);
}

.int-metric-handle.int-mid-top { top: 0; }
.int-metric-handle.int-mid-bottom { top: 100%; }

/* ── Dot block widget (TL / TR cells) ──────────────────────── */

.dot-widget {
  width: 100%;
  height: 100%;
  position: relative;
  background-color: #fff;
  overflow: hidden;
  user-select: none;
  touch-action: none;
  box-sizing: border-box;
}

.dot-widget::before,
.dot-widget::after {
  content: '';
  position: absolute;
  background: rgba(0,0,0,0.26);
  pointer-events: none;
  z-index: 1;
}

.dot-widget::before {
  left: 50%;
  top: 0;
  width: 1px;
  height: 100%;
  transform: translateX(-0.5px);
}

.dot-widget::after {
  left: 0;
  top: 50%;
  width: 100%;
  height: 1px;
  transform: translateY(-0.5px);
}

.dot-block {
  position: absolute;
  /* left/top set dynamically by JS based on position value */
  background: #000;
  border: 2px solid #000;
  min-width: 4px;
  min-height: 4px;
  box-sizing: border-box;
  transition: left 180ms ease, top 180ms ease, width 180ms ease, height 180ms ease;
}

.dot-cell.is-resizing .dot-block,
.dot-cell.is-resizing .dot-label-top,
.dot-cell.is-resizing .dot-label-right {
  transition: none;
}

.dot-cell.is-resizing .int-spacing-box {
  transition: none;
}

/* hidden proxy color picker — sits in the cell, clicked programmatically */
.dot-proxy-picker {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
  left: 0;
  top: 0;
  pointer-events: none;
  border: 0;
  padding: 0;
}

/* Resize handles */
.d-handle {
  position: absolute;
  z-index: 3;
  background: transparent;
  pointer-events: auto;   /* override any pointer-events:none from parent */
}
.d-handle.d-left,
.d-handle.d-right {
  top: 6px; bottom: 6px; width: 12px; cursor: ew-resize;
}
.d-handle.d-left  { left: -7px; }
.d-handle.d-right { right: -7px; }
.d-handle.d-top,
.d-handle.d-bottom {
  left: 6px; right: 6px; height: 12px; cursor: ns-resize;
}
.d-handle.d-top    { top: -7px; }
.d-handle.d-bottom { bottom: -7px; }
.d-handle.d-tl, .d-handle.d-tr,
.d-handle.d-bl, .d-handle.d-br {
  width: 16px; height: 16px;
}
.d-handle.d-tl { left: -8px;  top: -8px;    cursor: nwse-resize; }
.d-handle.d-tr { right: -8px; top: -8px;    cursor: nesw-resize; }
.d-handle.d-bl { left: -8px;  bottom: -8px; cursor: nesw-resize; }
.d-handle.d-br { right: -8px; bottom: -8px; cursor: nwse-resize; }

.dot-block > .d-handle.disabled {
  cursor: default !important;
}

.int-spacing-box > .d-handle.d-tl::after,
.int-spacing-box > .d-handle.d-tr::after,
.int-spacing-box > .d-handle.d-bl::after,
.int-spacing-box > .d-handle.d-br::after {
  content: '';
  position: absolute;
  left: 50%;
  right: auto;
  top: 50%;
  bottom: auto;
  width: 6px;
  height: 6px;
  background: #000;
  display: block;
  pointer-events: none;
  transform: translate(-50%, -50%);
}

/* Value labels — position is set dynamically in JS to track block edges */
.dot-label-top,
.dot-label-right {
  position: absolute;
  font-family: 'VT323';
  font-size: 18px;
  color: #0000ff;
  cursor: text;
  user-select: none;
  line-height: 1;
  white-space: nowrap;
  pointer-events: auto;
  z-index: 4;
  transition: left 180ms ease, top 180ms ease;
}

.dot-label-top.editing,
.dot-label-right.editing {
  background: #fff;
  border: 1px solid #00f;
  padding: 0 2px;
}

.dot-label-top input,
.dot-label-right input {
  font-family: 'VT323';
  font-size: 13px;
  color: #0000ff;
  border: none;
  background: transparent;
  outline: none;
  width: 36px;
  padding: 0;
  text-align: left;
}

/* Visuals thumbnail grid */
.modern-thumb-grid {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 0;
  margin-bottom: 0;
}

.thumb-cell {
  aspect-ratio: 1 / 1;
  border-right: 2px solid #000;
  border-bottom: 2px solid #000;
  cursor: pointer;
  overflow: hidden;
  box-sizing: border-box;
}

.modern-thumb-grid .thumb-cell:nth-child(8n+1) {
  border-left: 2px solid #000;
}

#modernPresetGrid .thumb-cell:nth-child(-n+8) {
  border-top: 2px solid #000;
}

#modernFontGrid {
  margin-top: -2px;
}

#modernFontGrid .thumb-cell:nth-child(-n+8) {
  border-top: 2px solid #000;
}

.thumb-cell canvas {
  width: 100%;
  height: 100%;
  display: block;
}

.thumb-cell.active {
  border: 2px solid #0000ff;
  box-shadow: 0 0 0 2px #0000ff;
  position: relative;
  z-index: 1;
}

.thumb-cell:hover:not(.active) {
  opacity: 0.7;
}

/* Text controls */
.modern-text-controls {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-bottom: 0;
}

.modern-text-layout-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0;
  margin-bottom: 0;
}

.text-widget-cell {
  position: relative;
  aspect-ratio: 1 / 1;
  border-top: 2px solid #000;
  border-right: 2px solid #000;
  border-bottom: 2px solid #000;
  box-sizing: border-box;
  overflow: visible;
  min-width: 0;
}

#textAlignCell {
  border-left: 2px solid #000;
}

.text-align-widget,
.text-metrics-widget {
  width: 100%;
  height: 100%;
  position: relative;
  overflow: hidden;
  user-select: none;
  touch-action: none;
  background-color: #fff;
  --text-metric-font-size: 18px;
}

.text-align-widget::before,
.text-align-widget::after,
.text-metrics-widget::before,
.text-metrics-widget::after {
  content: '';
  position: absolute;
  background: rgba(0,0,0,0.26);
  pointer-events: none;
  z-index: 1;
}

.text-align-widget::before,
.text-metrics-widget::before {
  left: 50%;
  top: 0;
  width: 1px;
  height: 100%;
  transform: translateX(-0.5px);
}

.text-align-widget::after,
.text-metrics-widget::after {
  left: 0;
  top: 50%;
  width: 100%;
  height: 1px;
  transform: translateY(-0.5px);
}

.text-align-block {
  background: transparent;
}

.text-metrics-box {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  border: none;
  border-top: 1.5px dashed rgba(0,0,0,0.7);
  border-right: 1.5px dashed rgba(0,0,0,0.7);
  z-index: 2;
  min-width: 8px;
  min-height: 8px;
  pointer-events: none;
  box-sizing: border-box;
  transition: width 180ms ease, height 180ms ease;
}

.text-metrics-fill {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 22px;
  height: 22px;
  transform: translate(-50%, -50%);
  cursor: move;
  pointer-events: auto;
  z-index: 4;
  background: transparent;
}

.text-metric-handle {
  position: absolute;
  z-index: 3;
  width: max(22px, calc(var(--text-metric-font-size) + 4px));
  height: max(22px, calc(var(--text-metric-font-size) + 4px));
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'VT323';
  font-size: var(--text-metric-font-size);
  line-height: 1;
  color: #000;
  pointer-events: auto;
  background: transparent;
}

.text-metric-handle.metric-tl {
  left: 0;
  top: 0;
  transform: translate(-50%, -50%);
  cursor: nwse-resize;
}

.text-metric-handle.metric-tr {
  left: 100%;
  top: 0;
  transform: translate(-50%, -50%);
  cursor: nesw-resize;
}

.text-metric-handle.metric-bl {
  left: 0;
  top: 100%;
  transform: translate(-50%, -50%);
  cursor: nesw-resize;
}

.text-metric-handle.metric-br {
  left: 100%;
  top: 100%;
  transform: translate(-50%, -50%);
  cursor: nwse-resize;
}

.text-metric-handle.metric-center {
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  cursor: move;
}

.text-metric-handle.metric-left,
.text-metric-handle.metric-right {
  top: 50%;
  transform: translate(-50%, -50%);
  cursor: ew-resize;
}

.text-metric-handle.metric-left { left: 0; }
.text-metric-handle.metric-right { left: 100%; }

.text-metric-handle.metric-top,
.text-metric-handle.metric-bottom {
  left: 50%;
  transform: translate(-50%, -50%);
  cursor: ns-resize;
}

.text-metric-handle.metric-top { top: 0; }
.text-metric-handle.metric-bottom { top: 100%; }

.text-fontsize-slider {
  position: absolute;
  right: 8px;
  bottom: 8px;
  z-index: 6;
  display: block;
  padding: 4px;
  background: #fff;
  border-top: 1px solid rgba(0,0,0,0.35);
  box-sizing: border-box;
}

.text-fontsize-slider input[type="number"] {
  width: 38px;
  flex: none;
  font-family: 'VT323';
  font-size: 16px;
  color: #0000ff;
  text-align: right;
}

.text-widget-cell.is-resizing .text-metrics-box,
.text-widget-cell.is-resizing .dot-label-top,
.text-widget-cell.is-resizing .dot-label-right {
  transition: none;
}

.modern-text-controls {
  display: none;
}

.modern-text-controls .text-icon:nth-of-type(2),
.modern-text-controls .text-icon:nth-of-type(3),
#modernLineHeight,
#modernSpacing {
  display: none;
}

.text-icon {
  width: 18px;
  height: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.text-icon img {
  width: 100%;
  height: 100%;
}

.modern-text-controls input[type="number"] {
  width: 32px;
  font-family: 'VT323';
  font-size: 16px;
  color: #0000ff;
  border: none;
  background: transparent;
  outline: none;
  text-align: right;
  padding: 0;
}

#modernInputText {
  display: block;
  width: 100%;
  box-sizing: border-box;
  font-family: 'VT323';
  font-size: 14px;
  color: #0000ff;
  border: 2px solid #000;
  border-bottom: none;
  background: transparent;
  outline: none;
  resize: none;
  margin: 0;
  min-height: 0;
  height: calc(var(--text-panel-inner-width) / 2);
  padding: 6px 8px;
}
