:root {
  color-scheme: dark;
  --black: #050607;
  --ink: #d9dcdd;
  --panel: #111416;
  --panel-2: #1a1e20;
  --steel: #777d80;
  --steel-light: #b9bec0;
  --line: #3f4549;
  --blue: #005c9e;
  --cyan: #00a7c7;
  --green: #24c856;
  --magenta: #d826c9;
  --red: #ef4e58;
  --yellow: #f2db45;
  --orange: #f89a36;
}

* { box-sizing: border-box; }

html {
  min-height: 100%;
  background: var(--black);
  touch-action: manipulation;
}

body {
  min-height: 100vh;
  margin: 0;
  overflow-x: hidden;
  background: #080a0b;
  color: var(--ink);
  font-family: "Courier New", ui-monospace, monospace;
  -webkit-tap-highlight-color: transparent;
}

button, input { color: inherit; font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
button { cursor: pointer; }
input { min-width: 0; user-select: text; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.editor-shell { width: min(100%, 1700px); margin: 0 auto; padding: 14px 16px 24px; }

.editor-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  margin: 0 0 11px;
}

.wordmark {
  display: flex;
  align-items: baseline;
  gap: .25em;
  color: inherit;
  font-family: Impact, Haettenschweiler, "Arial Narrow Bold", sans-serif;
  font-size: clamp(30px, 4vw, 50px);
  font-weight: 900;
  letter-spacing: .03em;
  line-height: .9;
  text-decoration: none;
  filter: drop-shadow(0 3px 0 #000);
}

.wordmark > span { color: var(--red); }
.wordmark > strong { color: var(--green); font-size: .73em; }
.wordmark small {
  margin-left: .55em;
  color: var(--steel-light);
  font-family: "Courier New", monospace;
  font-size: .19em;
  letter-spacing: .16em;
}

.header-actions { display: flex; align-items: center; justify-content: flex-end; gap: 8px; }
.save-state { margin-right: 7px; color: #92999c; font-size: 11px; }
.save-state.dirty { color: var(--yellow); }

.button, .icon-button, .zoom-value {
  min-height: 34px;
  padding: 6px 10px;
  border: 1px solid var(--steel);
  border-radius: 3px;
  background: #262b2e;
  box-shadow: inset 0 1px #676e71, 0 2px 0 #000;
  color: var(--yellow);
  text-decoration: none;
}

.button:hover, .icon-button:hover, .zoom-value:hover { border-color: var(--steel-light); background: #303639; }
.button:active, .icon-button:active, .zoom-value:active { transform: translateY(1px); box-shadow: inset 0 1px #08090a; }
.button:focus-visible, .icon-button:focus-visible, .zoom-value:focus-visible, input:focus-visible, .tool:focus-visible, .tile-option:focus-visible { outline: 2px solid var(--cyan); outline-offset: 2px; }
.button:disabled { cursor: default; opacity: .38; transform: none; }
.button.primary { border-color: #31d865; background: #135926; color: #efff9f; font-weight: 700; }
.button.warning { color: #ffc56f; }
.button.subtle { color: #c8cdcf; }

.editor-console {
  position: relative;
  overflow: hidden;
  border: 1px solid #696f72;
  border-radius: 7px;
  background: #202528;
  box-shadow: inset 0 0 0 2px #0b0d0e, inset 0 0 0 4px #444a4d, 0 18px 55px #000;
}

.console-label {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 13px 7px;
  color: #c9cdcf;
  font-size: 10px;
  letter-spacing: .12em;
}
.console-label i { height: 2px; flex: 1; background: var(--red); border-right: 80px solid var(--yellow); border-left: 80px solid var(--cyan); }

.command-bar {
  display: flex;
  align-items: end;
  gap: 12px;
  padding: 9px 12px;
  border-block: 1px solid #080a0b;
  background: #141719;
}

.level-name { display: grid; flex: 1 1 260px; gap: 4px; }
.level-name span { color: #8f9699; font-size: 9px; letter-spacing: .12em; text-transform: uppercase; }
.level-name input, .search-label input {
  width: 100%;
  height: 34px;
  border: 1px solid #4b5154;
  border-radius: 2px;
  background: #050607;
  color: #e5e8e9;
}
.level-name input { padding: 5px 8px; }
.command-group { display: flex; flex: 0 0 auto; gap: 6px; }

.workspace {
  display: grid;
  grid-template-columns: 286px minmax(430px, 1fr) 258px;
  gap: 8px;
  min-height: min(720px, calc(100vh - 190px));
  padding: 8px;
}

.panel {
  min-width: 0;
  border: 1px solid #42484b;
  border-radius: 3px;
  background: var(--panel);
  box-shadow: inset 0 0 0 1px #070809;
}

.tool-panel, .info-panel { padding: 12px; }
.tool-panel { overflow: hidden; }
.info-panel { overflow: auto; }

.panel-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.eyebrow { display: block; margin-bottom: 3px; color: var(--green); font-size: 9px; letter-spacing: .14em; }
.panel-heading h2, .map-toolbar h1 { margin: 0; font-size: 16px; line-height: 1.1; }
.panel-heading kbd, .count-badge {
  padding: 3px 5px;
  border: 1px solid #474d50;
  border-bottom-width: 2px;
  border-radius: 2px;
  background: #202427;
  color: #a8afb1;
  font-size: 10px;
}

.tool-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.tool {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 42px;
  padding: 5px 7px;
  border: 1px solid #444b4e;
  border-radius: 2px;
  background: #1a1e20;
  color: #bfc4c6;
  text-align: left;
}
.tool b { display: grid; width: 24px; height: 24px; place-items: center; border: 1px solid #62696c; color: var(--yellow); }
.tool span { font-size: 11px; }
.tool:hover { border-color: #7f8689; }
.tool.active { border-color: var(--cyan); background: #082c35; color: #fff; }
.tool.start b { color: var(--green); }
.tool.exit b { color: var(--red); }
.tip { margin: 10px 1px 15px; color: #92999c; font-size: 10px; line-height: 1.45; }

.palette-heading { margin-top: 4px; }
.search-label input { padding: 5px 8px; }
.palette-filters { display: flex; gap: 4px; margin: 7px 0; }
.palette-filters button {
  flex: 1;
  padding: 5px 3px;
  border: 1px solid #3f4548;
  border-radius: 2px;
  background: #171a1c;
  color: #9da3a5;
  font-size: 9px;
}
.palette-filters button.active { border-color: var(--yellow); color: var(--yellow); }

.tile-palette {
  display: grid;
  grid-template-columns: repeat(5, minmax(42px, 1fr));
  align-content: start;
  gap: 4px;
  height: calc(min(720px, 100vh - 190px) - 323px);
  min-height: 220px;
  overflow: auto;
  padding: 2px 3px 8px 2px;
  scrollbar-color: #4b5255 #0b0d0e;
}

.tile-option {
  position: relative;
  display: grid;
  min-width: 0;
  min-height: 49px;
  padding: 3px;
  place-items: center;
  border: 1px solid #343a3d;
  border-radius: 2px;
  background: #050607;
}
.tile-option:hover { border-color: #8b9295; }
.tile-option.selected { border-color: var(--yellow); box-shadow: inset 0 0 0 1px var(--yellow); }
.tile-option canvas { width: 36px; height: 36px; image-rendering: pixelated; }
.tile-option small { position: absolute; right: 2px; bottom: 1px; padding: 0 2px; background: #050607; color: #92999c; font-size: 8px; }
.palette-empty { grid-column: 1 / -1; color: #9da3a5; font-size: 11px; line-height: 1.5; }

.map-panel { display: flex; flex-direction: column; overflow: hidden; }
.map-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 62px; padding: 10px 12px; border-bottom: 1px solid #343a3d; }
.map-toolbar h1 { color: var(--yellow); }
.view-controls { display: flex; align-items: center; gap: 5px; }
.icon-button { width: 34px; padding: 0; font-size: 20px; }
.zoom-value { min-width: 58px; padding-inline: 6px; color: #d7dcde; font-size: 11px; }
.toggle { display: flex; align-items: center; gap: 5px; margin-left: 5px; color: #abb1b3; font-size: 10px; }
.toggle input { accent-color: var(--cyan); }

.map-viewport {
  position: relative;
  flex: 1;
  min-height: 420px;
  overflow: auto;
  background: #000;
  box-shadow: inset 0 0 24px #000;
  cursor: crosshair;
  overscroll-behavior: contain;
  touch-action: none;
  scrollbar-color: #596063 #090b0c;
}
.map-viewport.pan-mode, .map-viewport.space-pan { cursor: grab; }
.map-viewport.panning { cursor: grabbing; }
#level-canvas { display: block; image-rendering: pixelated; image-rendering: crisp-edges; transform-origin: top left; }
.map-status { display: flex; justify-content: space-between; gap: 12px; min-height: 29px; padding: 7px 10px; border-top: 1px solid #343a3d; color: #91989a; font-size: 10px; }
#selected-status { color: var(--yellow); text-align: right; }

.selected-preview { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
#selected-tile { width: 58px; height: 58px; border: 1px solid #555c5f; background: #050607; image-rendering: pixelated; }
.selected-preview div { display: grid; gap: 4px; }
.selected-preview strong { color: var(--yellow); font-size: 13px; }
.selected-preview span { color: #939a9d; font-size: 10px; }
.tile-details { display: grid; gap: 0; margin: 0; border-block: 1px solid #343a3d; }
.tile-details div { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; padding: 8px 0; border-bottom: 1px solid #24292b; }
.tile-details div:last-child { border: 0; }
.tile-details dt { color: #8f9698; font-size: 10px; }
.tile-details dd { margin: 0; color: #d4d8da; font-size: 10px; text-align: right; }
.validation-heading { margin-top: 18px; }

.mission-summary { display: grid; grid-template-columns: 1fr 1fr; gap: 5px; }
.summary-cell { padding: 7px; border: 1px solid #353b3e; background: #181b1d; }
.summary-cell strong { display: block; color: var(--cyan); font-size: 17px; }
.summary-cell span { color: #9aa1a3; font-size: 9px; text-transform: uppercase; }
.validation-list { display: grid; gap: 6px; margin: 10px 0 0; padding: 0; list-style: none; }
.validation-list li { padding: 7px 8px; border-left: 3px solid #596063; background: #181b1d; color: #b9bfc1; font-size: 10px; line-height: 1.4; }
.validation-list li.error { border-color: var(--red); color: #ffc1c4; }
.validation-list li.warning { border-color: var(--orange); color: #ffd59e; }
.validation-list li.ok { border-color: var(--green); color: #aef8be; }
.validation-list li.note { border-color: var(--cyan); }

.help-box { margin-top: 15px; border-top: 1px solid #343a3d; color: #9fa6a8; font-size: 10px; line-height: 1.55; }
.help-box summary { padding: 10px 0 4px; color: var(--yellow); cursor: pointer; }
.help-box p { margin: 7px 0; }

.editor-footer { display: flex; justify-content: space-between; gap: 15px; padding: 8px 13px 10px; color: #92999c; font-size: 10px; }
#footer-message { color: var(--yellow); }

.toast {
  position: fixed;
  z-index: 20;
  left: 50%;
  bottom: 24px;
  max-width: min(92vw, 620px);
  padding: 9px 13px;
  border: 1px solid var(--steel);
  border-radius: 3px;
  background: #171a1c;
  box-shadow: 0 8px 35px #000;
  color: #f3f5f5;
  font-size: 11px;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 8px);
  transition: opacity .14s, transform .14s;
}
.toast.visible { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 1180px) {
  .workspace { grid-template-columns: 250px minmax(390px, 1fr); }
  .info-panel { grid-column: 1 / -1; display: grid; grid-template-columns: 1fr 1fr 2fr; gap: 14px; align-items: start; }
  .info-panel > .panel-heading:first-child { grid-column: 1; }
  .selected-preview { grid-column: 1; }
  .tile-details { grid-column: 2; grid-row: 1 / span 2; }
  .validation-heading { grid-column: 3; grid-row: 1; margin: 0; }
  .mission-summary { grid-column: 3; grid-row: 2; }
  .validation-list { grid-column: 3; grid-row: 3; }
  .help-box { grid-column: 1 / 3; }
}

@media (max-width: 860px) {
  .editor-shell { padding: 8px; }
  .editor-header { align-items: flex-start; }
  .save-state { display: none; }
  .wordmark small { display: none; }
  .command-bar { flex-wrap: wrap; }
  .level-name { flex-basis: 100%; }
  .command-group { flex: 1 1 auto; }
  .command-group .button { flex: 1; }
  .workspace { display: flex; min-height: 0; flex-direction: column; }
  .map-panel { min-height: 72vh; order: 1; }
  .tool-panel { order: 2; }
  .info-panel { order: 3; display: block; }
  .tile-palette { grid-template-columns: repeat(9, minmax(48px, 1fr)); height: 300px; }
  .mission-summary { margin-top: 8px; }
}

@media (max-width: 560px) {
  .editor-header { align-items: center; }
  .wordmark { font-size: 28px; }
  .header-actions .subtle { display: none; }
  .button { padding-inline: 7px; font-size: 10px; }
  .command-group { width: 100%; }
  .command-group .button { padding-inline: 3px; }
  .console-label { font-size: 7px; }
  .workspace { padding: 5px; }
  .map-toolbar { align-items: flex-start; }
  .map-toolbar h1 { max-width: 42vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .toggle { display: none; }
  .map-viewport { min-height: 65vh; }
  .tool-grid { grid-template-columns: repeat(2, 1fr); }
  .tile-palette { grid-template-columns: repeat(6, minmax(44px, 1fr)); }
  .editor-footer { flex-direction: column; gap: 3px; }
}

@media (prefers-reduced-motion: reduce) { .toast { transition: none; } }
