/* ═══════════════════════════════ Level Maker ═══════════════════════════════
   Editor, library, dialogs, toasts and results. Builds on the pixel UI kit in style.css
   (--panel, --ink, --gold, --notch, fonts). */

:root {
  --lm-bg: #120a1e;
  --lm-line: rgba(255, 243, 220, 0.12);
  --lm-good: #7be07b;
  --lm-bad: #ff5a6e;
  --lm-warn: #ffb02e;
  --lm-info: #6ec8ff;
}

.px-icon { display: block; image-rendering: pixelated; }
.px-icon-wrap { display: inline-flex; align-items: center; }
.px-icon-wrap .px-icon { display: block; }

.lm-icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 36px;
  height: 36px;
  padding: 0 8px;
  font-family: var(--font-display);
  font-size: 14px;
  color: var(--cream);
  background: var(--panel-2);
  border: 3px solid var(--ink);
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.14), inset 0 -3px 0 rgba(0, 0, 0, 0.3);
  clip-path: var(--notch-3);
  cursor: pointer;
  transition: filter 0.1s, transform 0.06s;
}
.lm-icon-btn:hover { filter: brightness(1.2); }
.lm-icon-btn:active { transform: translateY(1px); }
.lm-icon-btn:disabled { opacity: 0.4; cursor: default; filter: none; }
.lm-icon-btn[aria-pressed="true"] { background: var(--panel-hi); color: var(--gold); }
.lm-icon-btn:focus-visible, .le-tool:focus-visible, .le-pal-tile:focus-visible, .le-theme:focus-visible { outline: 2px solid var(--gold); outline-offset: 1px; }

.btn-small { display: inline-flex; align-items: center; gap: 6px; }
/* Level Maker buttons size to their content (the game's short-screen rule sets a min-width) */
.le-root .btn, .lm-dialog .btn, .lm-browser .btn, .lm-toast .btn { min-width: 0; }
.btn-danger { background: #9b2741; }
.btn kbd { margin-left: 6px; }

.le-spacer { flex: 1; }

/* ── Main menu entry ── */

.btn-maker {
  background: linear-gradient(180deg, #ffd93d, #ff9f2e);
  color: var(--ink);
  text-shadow: 1px 1px 0 rgba(255, 255, 255, 0.4);
}
.btn-maker .btn-new {
  position: absolute;
  top: -1px;
  right: 4px;
  padding: 2px 4px;
  font-size: 7px;
  color: #fff;
  background: var(--accent-color);
  text-shadow: none;
  animation: glow-pulse 1.1s steps(2, jump-none) infinite;
}
.menu-options-container .menu-main { grid-template-columns: repeat(3, minmax(0, 1fr)); }
#menu-screen .menu-main [data-action="start"] { grid-column: span 2; }
#menu-screen .menu-main .btn-maker { grid-column: span 1; font-size: 11px; padding: 13px 8px 15px; }
#menu-screen .menu-main [data-action="resume-saved"] { grid-column: 1 / -1; }

/* Back button on character select (it can be reached from the menu or the Level Maker) */
#character-select-screen .select-back {
  position: absolute;
  top: calc(12px + env(safe-area-inset-top));
  left: calc(12px + env(safe-area-inset-left));
  z-index: 2;
}

/* ═══════════════════════════════ Editor ═══════════════════════════════ */

#level-editor[hidden] { display: none !important; }

.le-root {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  grid-template-columns: 214px minmax(0, 1fr) 288px;
  grid-template-rows: 54px minmax(0, 1fr) 66px;
  grid-template-areas:
    "top top top"
    "left stage right"
    "left bottom right";
  background: var(--lm-bg);
  color: var(--cream);
  font-family: var(--font-body);
  user-select: none;
  -webkit-user-select: none;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

body.editor-open #game-container { visibility: hidden; }

/* Top bar */
.le-top {
  grid-area: top;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 10px;
  background: linear-gradient(180deg, var(--panel-2), var(--panel));
  border-bottom: 3px solid var(--ink);
  box-shadow: inset 0 -2px 0 var(--panel-hi);
  min-width: 0;
}
.le-title { display: flex; flex-direction: column; min-width: 120px; flex: 0 1 260px; }
.le-name {
  font-family: var(--font-display);
  font-size: 12px;
  color: var(--cream);
  background: transparent;
  border: 2px solid transparent;
  padding: 4px 6px;
  width: 100%;
  text-shadow: 2px 2px 0 var(--ink);
}
.le-name:hover { border-color: var(--lm-line); }
.le-name:focus { outline: none; border-color: var(--gold); background: rgba(0, 0, 0, 0.3); }
.le-save-state { font-size: 11px; color: var(--muted); padding-left: 8px; }
.le-save-state[data-state="saving"], .le-save-state[data-state="dirty"] { color: var(--gold); }
.le-save-state[data-state="error"] { color: var(--lm-bad); }
.le-top-group { display: flex; gap: 4px; align-items: center; }
.le-zoom-label {
  min-width: 58px;
  height: 36px;
  font-family: var(--font-display);
  font-size: 9px;
  color: var(--cream);
  background: rgba(0, 0, 0, 0.35);
  border: 2px solid var(--ink);
  cursor: pointer;
}
.le-toggles .lm-icon-btn[data-mode="full"] { color: #fff; }
.le-test-split { position: relative; display: flex; }
.le-test-split .btn { min-width: 0; margin: 0; }
.le-test-btn { padding: 10px 16px 12px; display: inline-flex; align-items: center; gap: 8px; font-size: 11px; }
.le-caret { padding: 10px 8px 12px; margin-left: -3px !important; }
.le-share-btn { font-size: 10px; }
.le-more-btn { display: none; }

.le-menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  z-index: 70;
  width: 270px;
  padding: 8px;
  background: var(--panel);
  border: 3px solid var(--ink);
  box-shadow: inset 0 0 0 2px var(--panel-hi), 0 8px 24px rgba(0, 0, 0, 0.5);
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.le-menu > button {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 10px;
  font-family: var(--font-body);
  font-size: 14px;
  color: var(--cream);
  background: transparent;
  border: 0;
  cursor: pointer;
  text-align: left;
}
.le-menu > button:hover { background: var(--panel-2); }
.le-menu hr { border: 0; border-top: 2px solid var(--lm-line); margin: 4px 0; }
.le-menu-label { font-size: 12px; color: var(--muted); padding: 2px 10px; }
.le-menu-cats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; }
.le-cat {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 6px 2px;
  font-family: var(--font-body);
  font-size: 12px;
  color: var(--cream);
  background: rgba(0, 0, 0, 0.25);
  border: 2px solid var(--ink);
  cursor: pointer;
}
.le-cat img { height: 22px; image-rendering: pixelated; }
.le-cat.on { border-color: var(--gold); background: var(--panel-2); }
.le-check { display: flex; gap: 8px; align-items: flex-start; font-size: 13px; padding: 6px 10px; color: var(--muted); cursor: pointer; }
.le-check input { margin-top: 2px; accent-color: var(--gold); }

kbd {
  font-family: var(--font-display);
  font-size: 8px;
  padding: 2px 4px;
  color: var(--cream);
  background: rgba(0, 0, 0, 0.4);
  border: 1px solid rgba(255, 243, 220, 0.25);
  border-bottom-width: 2px;
}

/* Left: tools + palette */
.le-left {
  grid-area: left;
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--panel);
  border-right: 3px solid var(--ink);
  box-shadow: inset -2px 0 0 var(--panel-hi);
}
.le-tools { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; padding: 8px 8px 6px; border-bottom: 2px solid var(--lm-line); }
.le-tool {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 7px 2px 6px;
  font-family: var(--font-body);
  font-size: 12px;
  color: var(--muted);
  background: rgba(0, 0, 0, 0.28);
  border: 2px solid var(--ink);
  cursor: pointer;
}
.le-tool:hover { color: var(--cream); background: var(--panel-2); }
.le-tool.on { color: var(--ink); background: var(--gold); }
.le-palette { overflow-y: auto; padding: 4px 8px 12px; scrollbar-width: thin; }
.le-pal-group h3 {
  font-family: var(--font-display);
  font-size: 8px;
  color: var(--gold);
  letter-spacing: 1px;
  text-transform: uppercase;
  margin: 10px 2px 6px;
  text-shadow: 1px 1px 0 var(--ink);
}
.le-pal-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; }
.le-pal-tile {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 4px 2px 3px;
  background: linear-gradient(180deg, #3a2a58, #2b1f45);
  border: 2px solid var(--ink);
  cursor: grab;
  touch-action: pan-y;
  color: var(--cream);
  transition: transform 0.08s, background 0.1s;
}
.le-pal-tile:hover { background: linear-gradient(180deg, #4b3870, #36285a); transform: translateY(-1px); }
.le-pal-tile.on { border-color: var(--gold); box-shadow: 0 0 0 2px var(--gold), inset 0 0 12px rgba(255, 217, 61, 0.25); }
.le-pal-tile canvas { width: 44px; height: 36px; image-rendering: pixelated; pointer-events: none; }
.le-pal-name { font-size: 11px; line-height: 1.05; text-align: center; color: var(--muted); max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.le-pal-tile.on .le-pal-name { color: var(--gold); }
.le-pal-tile kbd { position: absolute; top: 2px; right: 2px; font-size: 6px; padding: 1px 2px; opacity: 0.8; }

.le-drag-ghost {
  position: fixed;
  left: 0;
  top: 0;
  z-index: 200;
  pointer-events: none;
  padding: 2px;
  background: rgba(42, 29, 64, 0.85);
  border: 2px solid var(--ink);
  opacity: 0.9;
}
.le-drag-ghost.over { background: rgba(255, 217, 61, 0.35); border-color: var(--gold); }
.le-drag-ghost canvas { display: block; width: 44px; height: 36px; image-rendering: pixelated; }
.le-dragging, .le-dragging * { cursor: grabbing !important; }

/* Stage */
.le-stage { grid-area: stage; position: relative; min-width: 0; min-height: 0; overflow: hidden; background: #0c0616; }
.le-canvas { position: absolute; inset: 0; display: block; touch-action: none; outline: none; }
.le-hint {
  position: absolute;
  left: 50%;
  bottom: 10px;
  transform: translateX(-50%);
  max-width: calc(100% - 24px);
  padding: 6px 12px;
  font-size: 13px;
  color: var(--cream);
  background: rgba(14, 6, 28, 0.78);
  border: 2px solid var(--ink);
  pointer-events: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.le-result {
  position: absolute;
  top: 34px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 14px;
  max-width: calc(100% - 24px);
  padding: 10px 12px 10px 16px;
  background: var(--panel);
  border: 3px solid var(--ink);
  box-shadow: inset 0 0 0 2px var(--panel-hi), 0 10px 30px rgba(0, 0, 0, 0.5);
  animation: banner-in 0.3s ease-out;
}
.le-result[hidden] { display: none; }
.le-result > div:first-child { display: flex; flex-direction: column; gap: 4px; }
.le-result b { font-family: var(--font-display); font-size: 11px; text-shadow: 2px 2px 0 var(--ink); white-space: nowrap; }
.le-result.good b { color: var(--lm-good); }
.le-result.bad b { color: var(--lm-bad); }
.le-result span { font-size: 13px; color: var(--muted); }
.le-result-btns { display: flex; gap: 6px; flex-shrink: 0; }
.le-inspect-btn { display: none; position: absolute; top: 30px; right: 8px; z-index: 4; min-width: 0; }
.le-drop-hint {
  position: absolute;
  inset: 12px;
  display: none;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-size: 12px;
  color: var(--gold);
  background: rgba(14, 6, 28, 0.82);
  border: 3px dashed var(--gold);
  pointer-events: none;
  z-index: 6;
}
.le-dropping .le-drop-hint { display: flex; }

/* Bottom: minimap */
.le-bottom {
  grid-area: bottom;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  background: var(--panel);
  border-top: 3px solid var(--ink);
  min-width: 0;
}
.le-minimap { flex: 1 1 0; width: 0; height: 100%; min-width: 0; border: 2px solid var(--ink); cursor: pointer; touch-action: none; image-rendering: pixelated; }
.le-coords {
  position: absolute;
  right: 8px;
  bottom: 8px;
  padding: 4px 6px;
  font-family: var(--font-display);
  font-size: 8px;
  color: var(--muted);
  background: rgba(14, 6, 28, 0.7);
  pointer-events: none;
}
.le-coords:empty { display: none; }
.le-bottom .btn { flex-shrink: 0; font-size: 9px; margin: 0; }

/* Right: inspector */
.le-right {
  grid-area: right;
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--panel);
  border-left: 3px solid var(--ink);
  box-shadow: inset 2px 0 0 var(--panel-hi);
}
.le-tabs { display: flex; gap: 2px; padding: 8px 8px 0; border-bottom: 2px solid var(--ink); }
.le-tabs [role="tab"] {
  flex: 1;
  position: relative;
  padding: 9px 4px 8px;
  font-family: var(--font-display);
  font-size: 8px;
  color: var(--muted);
  background: rgba(0, 0, 0, 0.3);
  border: 2px solid var(--ink);
  border-bottom: 0;
  cursor: pointer;
}
.le-tabs [role="tab"].on { color: var(--gold); background: var(--panel-2); }
.le-badge {
  position: absolute;
  top: -6px;
  right: -2px;
  min-width: 16px;
  padding: 2px 3px;
  font-size: 7px;
  color: var(--ink);
  background: var(--lm-warn);
  border: 2px solid var(--ink);
}
.le-badge[hidden] { display: none; }
.le-sheet-close { display: none; }
.le-panel { flex: 1; overflow-y: auto; padding: 12px; scrollbar-width: thin; }
.le-panel[hidden] { display: none; }

.le-panel h3 { font-family: var(--font-display); font-size: 10px; color: var(--cream); line-height: 1.4; text-shadow: 2px 2px 0 var(--ink); margin-bottom: 6px; }
.le-panel h4 { font-family: var(--font-display); font-size: 8px; color: var(--gold); margin: 14px 0 8px; }
.le-desc { font-size: 14px; line-height: 1.3; color: var(--muted); margin: 4px 0 10px; }
.le-note { font-size: 12px; line-height: 1.3; color: #a99bc9; margin: 8px 0; }
.le-muted { color: var(--muted); font-size: 12px; }
.le-field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.le-label { font-family: var(--font-display); font-size: 7px; letter-spacing: 1px; text-transform: uppercase; color: var(--gold); }
.le-row { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.le-row > .le-input { flex: 1; min-width: 0; }
.le-input {
  width: 100%;
  font-family: var(--font-body);
  font-size: 15px;
  color: var(--cream);
  background: rgba(0, 0, 0, 0.35);
  border: 2px solid var(--ink);
  box-shadow: inset 0 2px 0 rgba(0, 0, 0, 0.3);
  padding: 7px 8px;
  resize: vertical;
  user-select: text;
  -webkit-user-select: text;
}
.le-input:focus { outline: none; border-color: var(--gold); }
select.le-input { width: auto; flex: 1; }
.le-count { font-size: 11px; color: var(--muted); align-self: flex-end; }

.le-item-head { display: flex; gap: 10px; align-items: center; margin-bottom: 4px; }
.le-item-icon { flex-shrink: 0; padding: 4px; background: rgba(0, 0, 0, 0.3); border: 2px solid var(--ink); }
.le-item-icon canvas { display: block; width: 44px; height: 36px; image-rendering: pixelated; }
.le-item-sub { font-size: 12px; color: var(--muted); }
.le-pos { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; font-size: 13px; color: var(--muted); }

.le-stepper { display: inline-flex; align-items: stretch; border: 2px solid var(--ink); background: rgba(0, 0, 0, 0.3); }
.le-stepper button {
  width: 28px;
  font-family: var(--font-display);
  font-size: 12px;
  color: var(--cream);
  background: var(--panel-2);
  border: 0;
  cursor: pointer;
}
.le-stepper button:hover:not(:disabled) { background: var(--panel-hi); }
.le-stepper button:disabled { opacity: 0.35; cursor: default; }
.le-stepper output { min-width: 40px; padding: 6px 4px; text-align: center; font-family: var(--font-display); font-size: 9px; color: var(--cream); }

.le-seg { display: flex; flex-wrap: wrap; gap: 4px; }
.le-seg button {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 6px 8px;
  font-family: var(--font-body);
  font-size: 13px;
  color: var(--muted);
  background: rgba(0, 0, 0, 0.3);
  border: 2px solid var(--ink);
  cursor: pointer;
}
.le-seg button:hover { color: var(--cream); background: var(--panel-2); }
.le-seg button.on { color: var(--ink); background: var(--gold); }
.le-seg button canvas { width: auto; height: 20px; image-rendering: pixelated; }
.le-seg-wrap button { flex: 1 1 calc(50% - 4px); justify-content: flex-start; }

.le-actions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 16px; }
.le-actions .btn { flex: 1; justify-content: center; margin: 0; }
.le-chips { display: flex; flex-wrap: wrap; gap: 4px; margin: 8px 0 12px; }
.le-chip { display: inline-flex; align-items: center; gap: 2px; padding: 2px 6px 2px 2px; background: rgba(0, 0, 0, 0.3); border: 2px solid var(--ink); font-size: 13px; }
.le-chip canvas { width: 30px; height: 24px; image-rendering: pixelated; }

.le-empty h3 { margin-bottom: 10px; }
.le-tips { list-style: none; display: flex; flex-direction: column; gap: 8px; margin-bottom: 14px; }
.le-tips li { font-size: 14px; line-height: 1.3; color: var(--muted); padding-left: 12px; position: relative; }
.le-tips li::before { content: ''; position: absolute; left: 0; top: 6px; width: 5px; height: 5px; background: var(--gold); }
.le-tips b { color: var(--cream); }

/* Level tab */
.le-themes { display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px; }
.le-theme {
  position: relative;
  display: flex;
  flex-direction: column;
  padding: 0;
  background: #000;
  border: 2px solid var(--ink);
  cursor: pointer;
  overflow: hidden;
}
.le-theme img { width: 100%; aspect-ratio: 16 / 9; object-fit: cover; image-rendering: auto; display: block; transition: transform 0.2s; }
.le-theme:hover img { transform: scale(1.05); }
.le-theme span {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 3px 4px;
  font-size: 12px;
  color: #fff;
  background: linear-gradient(transparent, rgba(10, 4, 20, 0.85));
  text-align: left;
  text-shadow: 1px 1px 0 var(--ink);
}
.le-theme.on { border-color: var(--gold); box-shadow: 0 0 0 2px var(--gold); }
.le-theme.on span { color: var(--gold); }
.le-skies { display: grid; grid-template-columns: repeat(5, 1fr); gap: 4px; }
.le-sky {
  position: relative;
  height: 38px;
  border: 2px solid var(--ink);
  cursor: pointer;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  overflow: hidden;
}
.le-sky span { font-size: 10px; color: #fff; text-shadow: 1px 1px 0 var(--ink), -1px -1px 0 var(--ink); padding-bottom: 1px; pointer-events: none; }
.le-sky.on { box-shadow: 0 0 0 2px var(--gold); border-color: var(--gold); }
.le-sky-custom { background: conic-gradient(#ff5a6e, #ffd93d, #7be07b, #6ec8ff, #b46cff, #ff5a6e); }
.le-color { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; }
.le-range { width: 100%; }
.le-readout { font-size: 13px; color: var(--muted); }
.le-presets { display: flex; gap: 4px; flex-wrap: wrap; }
.le-chip-btn { padding: 4px 8px; font-family: var(--font-body); font-size: 12px; color: var(--muted); background: rgba(0, 0, 0, 0.3); border: 2px solid var(--ink); cursor: pointer; }
.le-chip-btn:hover { color: var(--ink); background: var(--gold); }
.le-lives { display: flex; gap: 2px; flex-wrap: wrap; }
.le-heart {
  width: 24px;
  height: 24px;
  border: 0;
  cursor: pointer;
  background: url('../assets/sprites/ui/heart.png') center / 18px no-repeat;
  image-rendering: pixelated;
  filter: grayscale(1) brightness(0.45);
  transition: transform 0.08s;
}
.le-heart.on { filter: none; }
.le-heart:hover { transform: scale(1.15); }
.le-ammo { display: flex; flex-direction: column; gap: 8px; }
.le-ammo-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px; }
.le-ammo-item { display: flex; align-items: center; gap: 4px; }
.le-ammo-item img { width: 20px; height: 20px; image-rendering: pixelated; }
.le-ammo-item .le-stepper button { width: 22px; }
.le-ammo-item .le-stepper output { min-width: 26px; }

/* Doctor tab */
.le-summary { display: flex; flex-direction: column; gap: 8px; padding: 10px; background: rgba(0, 0, 0, 0.25); border: 2px solid var(--ink); }
.le-diff { display: flex; align-items: center; gap: 8px; }
.le-diff b { font-family: var(--font-display); font-size: 9px; color: var(--gold); }
.le-paws, .lm-paws { display: inline-flex; gap: 2px; }
.le-paw { color: rgba(255, 243, 220, 0.18); }
.le-paw.on { color: #ff9ff3; }
.le-facts { display: grid; grid-template-columns: repeat(2, 1fr); gap: 2px 10px; font-size: 13px; color: var(--muted); }
.le-facts b { font-family: var(--font-display); font-size: 9px; color: var(--cream); }
.le-verified { display: flex; gap: 8px; align-items: flex-start; margin-top: 10px; padding: 8px 10px; font-size: 13px; line-height: 1.25; color: var(--muted); border: 2px dashed rgba(255, 243, 220, 0.25); }
.le-verified.yes { color: var(--lm-good); border: 2px solid var(--lm-good); background: rgba(123, 224, 123, 0.08); }
.le-last-test { display: flex; flex-direction: column; gap: 3px; margin-top: 10px; padding: 8px 10px; font-size: 13px; color: var(--muted); background: rgba(0, 0, 0, 0.25); border: 2px solid var(--ink); }
.le-last-test b { color: var(--cream); }
.le-issues { list-style: none; display: flex; flex-direction: column; gap: 6px; }
.le-issue { display: grid; grid-template-columns: 18px 1fr auto; gap: 8px; align-items: start; padding: 7px 8px; font-size: 13px; line-height: 1.25; background: rgba(0, 0, 0, 0.22); border-left: 4px solid var(--lm-info); }
.le-issue.warn { border-left-color: var(--lm-warn); }
.le-issue.tip { border-left-color: var(--lm-good); }
.le-issue-icon { display: flex; align-items: center; justify-content: center; width: 18px; height: 18px; font-family: var(--font-display); font-size: 8px; color: var(--ink); background: var(--lm-info); }
.le-issue.warn .le-issue-icon { background: var(--lm-warn); }
.le-issue.tip .le-issue-icon { background: var(--lm-good); }
.le-link { font-family: var(--font-body); font-size: 13px; color: var(--gold); background: none; border: 0; text-decoration: underline; cursor: pointer; padding: 0; justify-self: start; }

/* Help */
.le-help { display: grid; grid-template-columns: 1.2fr 1fr; gap: 18px; }
.le-keys { border-collapse: collapse; width: 100%; font-size: 14px; }
.le-keys td { padding: 4px 6px; vertical-align: middle; color: var(--muted); border-bottom: 1px solid var(--lm-line); }
.le-keys td:first-child { white-space: nowrap; }
.le-keys kbd { margin-right: 3px; }
.le-help-notes p { font-size: 14px; line-height: 1.35; color: var(--muted); margin-bottom: 8px; }
.le-help-notes h4 { font-family: var(--font-display); font-size: 9px; color: var(--gold); margin-bottom: 10px; }

/* First-run tour */
.le-tour { position: fixed; inset: 0; z-index: 90; }
.le-tour-spot {
  position: fixed;
  border: 3px solid var(--gold);
  box-shadow: 0 0 0 9999px rgba(8, 2, 18, 0.72);
  transition: all 0.25s ease-out;
  pointer-events: none;
}
.le-tour-bubble {
  position: fixed;
  padding: 14px 16px;
  background: var(--panel);
  border: 3px solid var(--ink);
  box-shadow: inset 0 0 0 2px var(--gold), 0 10px 30px rgba(0, 0, 0, 0.6);
  transition: all 0.25s ease-out;
}
.le-tour-bubble h3 { font-family: var(--font-display); font-size: 11px; color: var(--gold); margin: 4px 0 8px; text-shadow: 2px 2px 0 var(--ink); }
.le-tour-bubble p { font-size: 15px; line-height: 1.35; color: var(--cream); }
.le-tour-step { font-family: var(--font-display); font-size: 7px; color: var(--muted); }
.le-tour-bubble .le-actions { margin-top: 12px; }

/* ═══════════════════════════════ Dialogs & toasts ═══════════════════════════════ */

#lm-dialogs { position: fixed; inset: 0; z-index: 120; pointer-events: none; }
.lm-backdrop {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: max(12px, env(safe-area-inset-top)) 12px max(12px, env(safe-area-inset-bottom));
  background: rgba(8, 2, 18, 0.72);
  pointer-events: auto;
  animation: screen-in 0.15s ease-out;
}
.lm-backdrop.closing { opacity: 0; transition: opacity 0.12s; }
.lm-dialog {
  display: flex;
  flex-direction: column;
  width: min(440px, 100%);
  max-height: 100%;
  background: linear-gradient(180deg, var(--panel-2) 0%, var(--panel) 30%);
  border: 4px solid var(--ink);
  box-shadow: inset 0 0 0 2px var(--panel-hi), 0 16px 40px rgba(0, 0, 0, 0.55);
  clip-path: var(--notch);
  color: var(--cream);
  font-family: var(--font-body);
  animation: drop-in 0.2s ease-out;
}
.lm-dialog-wide { width: min(640px, 100%); }
.lm-dialog-head { display: flex; align-items: center; gap: 10px; padding: 14px 14px 10px 18px; border-bottom: 2px solid var(--lm-line); }
.lm-dialog-head h2 { flex: 1; font-family: var(--font-display); font-size: 13px; line-height: 1.4; color: var(--gold); text-shadow: 3px 3px 0 var(--ink); }
.lm-dialog-x { min-width: 32px; height: 32px; font-size: 18px; }
.lm-dialog-body { padding: 14px 18px; overflow-y: auto; user-select: text; -webkit-user-select: text; }
.lm-dialog-text { font-size: 16px; line-height: 1.4; color: var(--muted); }
.lm-dialog-actions { display: flex; justify-content: flex-end; flex-wrap: wrap; gap: 8px; padding: 10px 18px 16px; border-top: 2px solid var(--lm-line); }
.lm-dialog-actions .btn { min-width: 0; margin: 0; font-size: 10px; padding: 10px 14px 12px; }
.lm-dialog .le-field { margin-bottom: 14px; }
.lm-mono { font-family: ui-monospace, Consolas, monospace; font-size: 12px; }
.lm-code { word-break: break-all; }
.lm-warn { font-size: 14px; line-height: 1.3; color: var(--lm-warn); padding: 8px 10px; margin-bottom: 12px; border: 2px dashed var(--lm-warn); }
.lm-status { min-height: 18px; font-size: 14px; color: var(--muted); margin: 8px 0; }
.lm-status.good { color: var(--lm-good); }
.lm-status.bad { color: var(--lm-bad); }
.lm-drop {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  margin-top: 10px;
  padding: 16px;
  font-size: 14px;
  color: var(--muted);
  border: 3px dashed rgba(255, 243, 220, 0.3);
  cursor: pointer;
}
.lm-drop b { font-family: var(--font-display); font-size: 9px; color: var(--cream); }
.lm-drop.over, .lm-drop:hover { border-color: var(--gold); color: var(--gold); background: rgba(255, 217, 61, 0.06); }
.lm-preview { display: flex; flex-direction: column; gap: 8px; padding: 8px; margin-bottom: 12px; background: rgba(0, 0, 0, 0.3); border: 2px solid var(--ink); }
.lm-preview-thumb canvas { display: block; width: 100% !important; height: auto !important; aspect-ratio: 300 / 84; border: 2px solid var(--ink); image-rendering: pixelated; }
.lm-preview-info { display: flex; flex-direction: column; gap: 2px; }
.lm-preview-name { font-family: var(--font-display); font-size: 11px; color: var(--cream); line-height: 1.4; }
.lm-preview-by, .lm-preview-stats { font-size: 13px; color: var(--muted); }
.lm-preview-desc { font-size: 14px; color: var(--cream); margin-top: 4px; }
.lm-new .le-themes { grid-template-columns: repeat(4, 1fr); }

.lm-toast {
  position: fixed;
  left: 50%;
  bottom: calc(18px + env(safe-area-inset-bottom));
  z-index: 140;
  display: flex;
  align-items: center;
  gap: 12px;
  max-width: calc(100% - 24px);
  padding: 9px 14px;
  font-family: var(--font-body);
  font-size: 15px;
  color: var(--cream);
  background: var(--panel);
  border: 3px solid var(--ink);
  box-shadow: inset 0 0 0 2px var(--panel-hi), 0 8px 24px rgba(0, 0, 0, 0.5);
  transform: translate(-50%, 140%);
  opacity: 0;
  transition: transform 0.2s ease-out, opacity 0.2s;
  pointer-events: none;
}
.lm-toast.show { transform: translate(-50%, 0); opacity: 1; pointer-events: auto; }
.lm-toast.good { box-shadow: inset 0 0 0 2px var(--lm-good), 0 8px 24px rgba(0, 0, 0, 0.5); }
.lm-toast.warn { box-shadow: inset 0 0 0 2px var(--lm-warn), 0 8px 24px rgba(0, 0, 0, 0.5); }
.lm-toast-btn { font-family: var(--font-display); font-size: 8px; color: var(--gold); background: none; border: 0; cursor: pointer; text-decoration: underline; }

/* ═══════════════════════════════ Library ═══════════════════════════════ */

#level-browser.screen {
  font-family: var(--font-body);
  justify-content: flex-start;
  align-items: stretch;
  padding: 0;
  overflow-y: auto;
  background: radial-gradient(ellipse at 50% 0%, #3b2b5a 0%, #1d1232 45%, #120a1e 100%);
  overscroll-behavior: contain;
}
.lm-browser.lm-dropping::after {
  content: 'Drop a level file to import it';
  position: fixed;
  inset: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-size: 13px;
  color: var(--gold);
  background: rgba(14, 6, 28, 0.85);
  border: 3px dashed var(--gold);
  z-index: 5;
  pointer-events: none;
}
.lm-head {
  position: sticky;
  top: 0;
  z-index: 3;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: calc(10px + env(safe-area-inset-top)) calc(14px + env(safe-area-inset-right)) 10px calc(14px + env(safe-area-inset-left));
  background: linear-gradient(180deg, rgba(42, 29, 64, 0.97), rgba(42, 29, 64, 0.9));
  border-bottom: 3px solid var(--ink);
  box-shadow: inset 0 -2px 0 var(--panel-hi);
}
.lm-head h1, .lm-hero-copy h2 { font-family: var(--font-display); }
.lm-head h1 { font-size: 16px !important; margin: 0 0 0 4px !important; color: var(--gold); text-shadow: 3px 3px 0 var(--ink) !important; }
.lm-head .btn { min-width: 0; margin: 0; }
.lm-head .btn-primary { font-size: 11px; padding: 10px 14px 12px; }
.lm-surprise { background: #5b3f8f; }
.lm-hero {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr);
  align-items: center;
  gap: 20px;
  width: min(1100px, calc(100% - 28px));
  margin: 16px auto 4px;
}
.lm-hero-art {
  aspect-ratio: 3 / 2;
  max-height: 260px;
  background: #120a1e url('../assets/backgrounds/level-maker.webp') center / cover no-repeat;
  border: 4px solid var(--ink);
  box-shadow: inset 0 0 0 2px var(--panel-hi), 0 10px 30px rgba(0, 0, 0, 0.45);
  clip-path: var(--notch);
  image-rendering: auto;
}
.lm-hero-copy h2 { font-size: 18px !important; line-height: 1.5 !important; text-align: left !important; margin-bottom: 10px !important; }
.lm-hero-copy p { font-size: 17px !important; line-height: 1.4 !important; color: var(--muted); }
.lm-tabs {
  display: flex;
  gap: 4px;
  width: min(1100px, calc(100% - 28px));
  margin: 14px auto 0;
  border-bottom: 3px solid var(--ink);
}
.lm-tabs button {
  padding: 10px 14px 9px;
  font-family: var(--font-display);
  font-size: 9px;
  color: var(--muted);
  background: rgba(0, 0, 0, 0.3);
  border: 3px solid var(--ink);
  border-bottom: 0;
  cursor: pointer;
}
.lm-tabs button.on { color: var(--gold); background: var(--panel); }
.lm-tab-count { color: var(--cream); }
.lm-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(270px, 1fr));
  gap: 14px;
  width: min(1100px, calc(100% - 28px));
  margin: 14px auto calc(28px + env(safe-area-inset-bottom));
}
.lm-loading { color: var(--muted); font-size: 15px; }
.lm-card {
  position: relative;
  display: flex;
  flex-direction: column;
  background: linear-gradient(180deg, var(--panel-2) 0%, var(--panel) 40%);
  border: 4px solid var(--ink);
  box-shadow: inset 0 0 0 2px var(--panel-hi), inset 0 -6px 0 2px rgba(0, 0, 0, 0.28);
  clip-path: var(--notch);
  transition: transform 0.12s;
}
.lm-card:hover { transform: translateY(-2px); }
.lm-card-thumb {
  position: relative;
  padding: 6px;
  background-size: cover;
  background-position: center;
  border-bottom: 3px solid var(--ink);
}
.lm-card-thumb canvas { display: block; width: 100% !important; height: auto !important; aspect-ratio: 268 / 74; border: 2px solid var(--ink); box-shadow: 0 4px 10px rgba(0, 0, 0, 0.4); image-rendering: pixelated; }
.lm-badge {
  position: absolute;
  top: 10px;
  right: 10px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 6px;
  font-family: var(--font-display);
  font-size: 7px;
  color: var(--ink);
  background: var(--gold);
  border: 2px solid var(--ink);
}
.lm-verified { background: var(--lm-good); }
.lm-wave-badge { left: 10px; right: auto; }
.lm-card-body { display: flex; flex-direction: column; gap: 4px; padding: 10px 12px 4px; flex: 1; }
.lm-card-body h3 { font-family: var(--font-display); font-size: 11px; line-height: 1.4; color: var(--cream); text-shadow: 2px 2px 0 var(--ink); overflow-wrap: anywhere; }
.lm-card-meta { font-size: 13px; color: var(--muted); }
.lm-card-stats { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; font-size: 13px; color: var(--muted); }
.lm-best { display: inline-flex; align-items: center; gap: 3px; color: var(--gold); }
.lm-best img { width: 14px; height: 14px; }
.lm-card-desc { font-size: 14px !important; line-height: 1.3 !important; color: var(--cream) !important; margin: 4px 0 0 !important; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.lm-card-actions { display: flex; gap: 6px; padding: 10px 12px 12px; }
.lm-card-actions .btn { flex: 1; justify-content: center; margin: 0; font-size: 9px; }
.lm-more { min-width: 36px; }
.lm-menu {
  position: absolute;
  right: 12px;
  bottom: 54px;
  z-index: 4;
  display: flex;
  flex-direction: column;
  min-width: 170px;
  padding: 4px;
  background: var(--panel);
  border: 3px solid var(--ink);
  box-shadow: inset 0 0 0 2px var(--panel-hi), 0 8px 20px rgba(0, 0, 0, 0.5);
}
.lm-menu button { padding: 8px 10px; font-family: var(--font-body); font-size: 15px; text-align: left; color: var(--cream); background: none; border: 0; cursor: pointer; }
.lm-menu button:hover { background: var(--panel-2); }
.lm-menu button.danger { color: var(--lm-bad); }
.lm-empty {
  grid-column: 1 / -1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 36px 16px;
  text-align: center;
  border: 3px dashed rgba(255, 243, 220, 0.2);
}
.lm-empty h3 { font-family: var(--font-display); font-size: 13px; color: var(--gold); text-shadow: 2px 2px 0 var(--ink); }
.lm-empty p { max-width: 460px; }
.lm-empty .btn { min-width: 0; }

/* ═══════════════════════════════ In-game extras ═══════════════════════════════ */

#ui-overlay > #level-toast {
  position: absolute;
  top: calc(64px + env(safe-area-inset-top));
  left: 50%;
  z-index: 15;
  max-width: min(520px, calc(100% - 24px));
  padding: 10px 16px 10px 44px;
  font-family: var(--font-display);
  font-size: 11px;
  line-height: 1.5;
  color: var(--ink);
  background: #fff3dc url('../assets/sprites/obstacles/sign.png') 10px center / 22px auto no-repeat;
  border: 3px solid var(--ink);
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.35);
  image-rendering: pixelated;
  pointer-events: none;
  transform: translateX(-50%);
  animation: sign-in 0.25s ease-out;
}
#ui-overlay > #level-toast.hidden { display: none; }
@keyframes sign-in { from { transform: translate(-50%, -10px) scale(0.9); opacity: 0; } to { transform: translate(-50%, 0); opacity: 1; } }

#ui-overlay > #test-badge {
  position: absolute;
  left: 50%;
  bottom: calc(10px + env(safe-area-inset-bottom));
  z-index: 12;
  padding: 5px 10px;
  font-family: var(--font-display);
  font-size: 8px;
  color: var(--ink);
  background: var(--gold);
  border: 2px solid var(--ink);
  transform: translateX(-50%);
  pointer-events: none;
}
#ui-overlay > #test-badge[hidden] { display: none; }

.heart[hidden] { display: none !important; }

/* Results */
#level-result-screen.screen { background: radial-gradient(ellipse at center, rgba(34, 18, 60, 0.85), rgba(10, 4, 20, 0.96)); }
.lr-main { display: flex; flex-direction: column; align-items: center; gap: 12px; padding: 22px 26px; width: min(520px, 100%); }
.lr-main .lr-title { margin-bottom: 0; }
.victory .lr-title { color: var(--gold); }
.lr-level { font-family: var(--font-display) !important; font-size: 10px !important; color: var(--cream) !important; margin: 0 !important; text-align: center; }
.lr-level span { color: var(--muted); }
.lr-ribbon { padding: 6px 14px; font-family: var(--font-display); font-size: 10px; color: var(--ink); background: var(--gold); border: 3px solid var(--ink); animation: pop 0.4s ease-out, glow-pulse 1.1s steps(2, jump-none) infinite; }
.lr-progress { position: relative; width: 100%; height: 22px; background: rgba(0, 0, 0, 0.45); border: 3px solid var(--ink); }
.lr-progress span { position: absolute; inset: 0 auto 0 0; background: repeating-linear-gradient(90deg, var(--accent-color) 0 8px, #c7334f 8px 16px); }
.lr-progress b { position: relative; display: block; text-align: center; font-family: var(--font-display); font-size: 8px; line-height: 16px; color: #fff; text-shadow: 1px 1px 0 var(--ink); }
.lr-hearts { display: flex; gap: 3px; }
.lr-best { font-size: 14px !important; margin: 0 !important; }

/* ═══════════════════════════════ Responsive ═══════════════════════════════ */

@media (max-width: 1100px) {
  .le-root { grid-template-columns: 184px minmax(0, 1fr) 256px; }
  .le-pal-grid { grid-template-columns: repeat(3, 1fr); }
  .le-pal-tile canvas { width: 38px; height: 31px; }
  .le-title { flex-basis: 200px; }
}

@media (max-width: 900px) {
  .le-root { grid-template-columns: 150px minmax(0, 1fr) 236px; }
  .le-pal-grid { grid-template-columns: repeat(2, 1fr); }
  .le-toggles [data-cmd="help"] { display: none; }
  .le-share-btn span { display: none; }
  .lm-hero { grid-template-columns: 1fr; }
  .lm-hero-art { max-height: 200px; width: 100%; }
}

/* Phones and narrow windows: palette strip at the bottom, inspector as a sheet */
@media (max-width: 760px), (max-height: 520px) and (orientation: landscape) {
  .le-root {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: 48px minmax(0, 1fr) 34px auto;
    grid-template-areas: "top" "stage" "bottom" "left";
  }
  .le-top { gap: 4px; padding: 0 6px; overflow-x: auto; scrollbar-width: none; }
  .le-top::-webkit-scrollbar { display: none; }
  .le-title { min-width: 96px; flex: 1 1 120px; }
  .le-save-state { display: none; }
  .le-zoom, .le-toggles { display: none; }
  .le-more-btn { display: inline-flex; font-size: 16px; }
  .le-spacer { display: none; }
  .le-share-btn { min-width: 0; padding: 9px 10px 10px; }
  .le-share-btn span, .le-test-btn span { display: none; }
  .le-test-btn { padding: 9px 12px 11px; }
  .lm-icon-btn { min-width: 34px; height: 34px; }
  .le-left {
    flex-direction: row;
    border-right: 0;
    border-top: 3px solid var(--ink);
    box-shadow: inset 0 2px 0 var(--panel-hi);
    padding-bottom: env(safe-area-inset-bottom);
  }
  .le-tools { display: grid; grid-template-columns: repeat(2, 34px); grid-auto-rows: 30px; gap: 3px; align-content: center; padding: 6px; border-bottom: 0; border-right: 2px solid var(--lm-line); }
  .le-tool { flex-direction: row; justify-content: center; padding: 0; font-size: 11px; }
  .le-tool span { display: none; }
  .le-palette { display: flex; gap: 10px; overflow-x: auto; overflow-y: hidden; padding: 4px 8px 6px; scrollbar-width: thin; }
  .le-pal-group { flex-shrink: 0; }
  .le-pal-group h3 { margin: 2px 2px 4px; font-size: 7px; }
  .le-pal-grid { display: flex; gap: 4px; }
  .le-pal-tile { width: 56px; touch-action: pan-x; }
  .le-pal-tile kbd { display: none; }
  .le-bottom { padding: 4px 6px; border-top: 2px solid var(--ink); }
  .le-bottom .btn span { display: none; }
  .le-bottom .btn { padding: 6px 10px 8px; }
  .le-hint { display: none; }
  .le-inspect-btn { display: inline-flex; }
  .le-right {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 75;
    max-height: 62vh;
    border-left: 0;
    border-top: 4px solid var(--ink);
    box-shadow: inset 0 2px 0 var(--panel-hi), 0 -12px 30px rgba(0, 0, 0, 0.55);
    transform: translateY(105%);
    transition: transform 0.22s ease-out;
    padding-bottom: env(safe-area-inset-bottom);
  }
  .inspector-open .le-right { transform: none; }
  .le-sheet-close { display: inline-flex; flex: 0 0 auto; min-width: 32px; height: 30px; margin-left: 4px; }
  .le-result { top: 8px; flex-direction: column; align-items: stretch; gap: 8px; }
  .lm-head h1 { font-size: 12px !important; }
  .lm-head .btn { font-size: 9px; padding: 9px 9px 11px; }
  .lm-hero { display: none; }
  .le-help { grid-template-columns: 1fr; }
  .lm-new .le-themes { grid-template-columns: repeat(3, 1fr); }
}

@media (max-height: 520px) and (orientation: landscape) {
  .le-root { grid-template-rows: 44px minmax(0, 1fr) 30px auto; }
  .le-pal-tile canvas { width: 34px; height: 28px; }
  .le-pal-name { font-size: 10px; }
  .le-right { left: auto; top: 0; width: min(320px, 60vw); max-height: none; border-top: 0; border-left: 4px solid var(--ink); transform: translateX(105%); }
}

@media (max-width: 480px) {
  .lm-head .lm-surprise { display: none; }
  .lm-grid { grid-template-columns: 1fr; }
  #menu-screen .menu-main .btn-maker { font-size: 9px; }
}

@media (prefers-reduced-motion: reduce) {
  .le-tour-spot, .le-tour-bubble, .le-right, .lm-toast { transition: none; }
  .btn-maker .btn-new, .lr-ribbon { animation: none; }
}
