* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: #000;
  color: #efefef;
  font-family: "Trebuchet MS", sans-serif;
}

.editor-app {
  width: min(1380px, 97vw);
  margin: 12px auto;
}

.topbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-bottom: 10px;
}

.top-field {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 0 2px;
  color: #d5d5d5;
  font-size: 0.85rem;
}

.top-field input {
  width: 118px;
  border: 1px solid #575757;
  background: #171717;
  color: #efefef;
  border-radius: 8px;
  padding: 6px 8px;
  font: inherit;
}

.back-link,
button,
select {
  border: 1px solid #575757;
  background: #171717;
  color: #efefef;
  text-decoration: none;
  border-radius: 8px;
  padding: 7px 10px;
  font: inherit;
}

button {
  cursor: pointer;
}

.status {
  margin: 0 0 0 auto;
  border: 1px solid #474747;
  border-radius: 8px;
  padding: 7px 10px;
  background: #101010;
  min-width: 320px;
  max-width: 700px;
}

.status[data-type="error"] {
  border-color: #8f3a3a;
  color: #ffd2d2;
}

.status[data-type="ok"] {
  border-color: #356535;
  color: #d5ffd5;
}

.workspace {
  display: grid;
  grid-template-columns: 250px minmax(0, 1fr);
  gap: 10px;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.panel {
  border: 1px solid #444;
  border-radius: 10px;
  background: #111;
  padding: 10px;
}

.panel h2 {
  margin: 0 0 10px;
  font-size: 1rem;
}

.tools-panel {
  padding: 8px;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.selector-panel.is-hidden {
  display: none;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
  margin-bottom: 8px;
}

.tool-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px;
}

.tool-btn {
  min-height: 34px;
  padding: 0;
  font-size: 1rem;
  font-weight: bold;
}

.tool-btn.is-active {
  border-color: #7dff7d;
  color: #d8ffd8;
  background: #143114;
}

.special-tool-panel {
  margin-top: 8px;
  border: 1px solid #3f3f3f;
  border-radius: 8px;
  padding: 8px;
  background: #0f0f0f;
}

.special-tool-panel.is-disabled {
  opacity: 0.72;
}

.compact-field {
  margin-bottom: 6px;
}

.compact-field input,
.compact-field select {
  border: 1px solid #575757;
  background: #171717;
  color: #efefef;
  border-radius: 6px;
  padding: 6px 7px;
  font: inherit;
}

#specialEraseToggleBtn {
  width: 100%;
  margin-top: 2px;
}

#specialEraseToggleBtn.is-active {
  border-color: #ff8a80;
  color: #ffd8d4;
  background: #361919;
}

.special-hint {
  margin: 6px 0 0;
  color: #c8c8c8;
  font-size: 0.78rem;
  line-height: 1.3;
}

.void-box {
  margin-top: 8px;
}

.map-size-box {
  margin-top: 8px;
}

.map-size-row {
  display: flex;
  align-items: flex-end;
  gap: 6px;
}

.size-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.75rem;
  color: #d5d5d5;
}

.size-field input {
  width: 58px;
  padding: 5px 6px;
  border: 1px solid #575757;
  background: #171717;
  color: #efefef;
  border-radius: 6px;
  font: inherit;
}

#applyMapSizeBtn {
  min-height: 31px;
  padding: 4px 8px;
}

.layer-box {
  margin-top: 8px;
}

.layer-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
}

.layer-btn {
  min-height: 30px;
  padding: 0;
  font-size: 0.85rem;
  font-weight: bold;
}

.layer-btn.is-active {
  border-color: #6ea0ff;
  color: #e0ebff;
  background: #172742;
}

.void-label {
  margin: 0 0 6px;
  font-size: 0.85rem;
  color: #c9c9c9;
}

.void-picker {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 8px;
  justify-content: flex-start;
  padding: 6px 8px;
}

#voidPreviewCanvas {
  width: 32px;
  height: 32px;
  border: 1px solid #555;
  border-radius: 4px;
  background: #060606;
  image-rendering: pixelated;
}

.selected-label {
  margin: 8px 0;
  font-family: monospace;
}

.palette-shell {
  border: 1px solid #464646;
  border-radius: 8px;
  max-height: 420px;
  overflow: auto;
  background: #0d0d0d;
}

#tilePaletteCanvas {
  display: block;
  width: 100%;
  height: auto;
  image-rendering: pixelated;
}

.canvas-wrap {
  display: flex;
  justify-content: center;
  align-items: flex-start;
  width: fit-content;
  max-width: 100%;
  margin: 0 auto;
  border: 1px solid #4e4e4e;
  border-radius: 12px;
  overflow: auto;
}

#editorCanvas {
  display: block;
  width: 960px;
  height: 540px;
  flex: 0 0 auto;
  background: #0b0b0b;
  image-rendering: pixelated;
  cursor: crosshair;
}

.modal {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
}

.modal.is-hidden {
  display: none;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
}

.modal-card {
  position: relative;
  width: min(640px, 92vw);
  max-height: 82vh;
  border: 1px solid #4d4d4d;
  border-radius: 12px;
  background: #111;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-head h3 {
  margin: 0;
  font-size: 1rem;
}

.modal-close {
  min-width: 34px;
  min-height: 30px;
  padding: 0;
}

.modal-help {
  margin: 0;
  color: #cdcdcd;
  font-size: 0.85rem;
}

.modal-palette-shell {
  border: 1px solid #4a4a4a;
  border-radius: 8px;
  max-height: 60vh;
  overflow: auto;
  background: #0d0d0d;
}

#voidModalCanvas {
  display: block;
  width: 100%;
  height: auto;
  image-rendering: pixelated;
}

@media (max-width: 1160px) {
  .workspace {
    grid-template-columns: 1fr;
  }
}
