@font-face {
  font-family: 'Roboto Mono';
  src: url('../fonts/roboto-mono/RobotoMono-Regular.woff2') format('woff2');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: 'Roboto Mono';
  src: url('../fonts/roboto-mono/RobotoMono-Bold.woff2') format('woff2');
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}

:root {
  --bg: #12141c;
  --panel: #1c2030;
  --panel-2: #262c40;
  --line: #333a52;
  --text: #e8ecf5;
  --muted: #9aa3bd;
  --accent: #ffb300;
  --accent-2: #4caf50;
  --danger: #e53935;
  --pink: #ff4081;
  --topbar-gap: 20px;
  --topbar-height: 0px;
  --dev-panel-width: 320px;
  --dev-panel-gap: 12px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: 'Roboto Mono', ui-monospace, Menlo, monospace;
  overflow: hidden;
}

/* ---------- Top bar ---------- */
.topbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 8px 14px;
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  flex-wrap: wrap;
}
.brand {
  display: inline-grid;
  font-family: 'Doto', 'Roboto Mono', ui-monospace, Menlo, monospace;
  font-weight: 700;
  font-size: 16px;
  letter-spacing: 0.5px;
  white-space: nowrap;
}
.brand-measure,
.brand-reveal {
  grid-area: 1 / 1;
}
.brand-measure {
  visibility: hidden;
  pointer-events: none;
  user-select: none;
}
.brand-char {
  opacity: 1;
}
.tb-group { display: flex; align-items: center; gap: 8px; }
.tb-group label { display: flex; align-items: center; gap: 5px; font-size: 13px; color: var(--muted); }

.topbar button {
  padding: 3px 6px;
  font-size: 11px;
  line-height: 1.3;
  width: 16ch;
  min-width: 16ch;
  text-align: center;
  white-space: nowrap;
  text-transform: uppercase;
}

.save-status {
  font-size: 12px;
  color: var(--muted);
  min-width: 5.5em;
  user-select: none;
  pointer-events: none;
}
.save-status.pending { color: #ffd54f; }
.save-status.saving { color: #90caf9; }
.save-status.error { color: #ef9a9a; }

button {
  font-family: inherit;
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 6px 11px;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s;
}
button:hover { background: #313850; }
button.primary { background: var(--accent-2); border-color: var(--accent-2); color: #06210b; font-weight: 700; }
button.primary:hover { background: #5dbf61; }
button.danger { background: #3a1f22; border-color: #6a2a2e; color: #ff9a9a; }
button.danger:hover { background: #52272b; }
button.active { outline: 2px solid var(--accent); }
#btnDev.active { color: var(--accent); }

input, select {
  font-family: inherit;
  background: #10121a;
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 5px 8px;
  font-size: 13px;
}
input[type="number"] { width: 74px; }
input[type="color"] { padding: 2px; width: 34px; height: 28px; }
#levelName { width: 130px; }

/* ---------- Stage ---------- */
.stage {
  position: relative;
  height: 100vh;
}
.canvas-wrap {
  position: relative;
  width: 100%;
  height: 100%;
}
#game {
  height: 100%;
  width: 100%;
  background: #7ec8ff;
  image-rendering: pixelated;
  display: block;
  min-width: 0;
}
#game.panning { cursor: grabbing; }

/* ---------- Minimap / overview ---------- */
.minimap-box {
  position: absolute;
  top: calc(var(--topbar-height) + var(--topbar-gap));
  right: calc(var(--dev-panel-width) + var(--dev-panel-gap));
  background: rgba(28, 32, 48, 0.85);
  border: 1px solid rgba(51, 58, 82, 0.45);
  border-radius: 8px;
  padding: 6px;
  box-shadow: 0 6px 20px #0007;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  z-index: 10;
}
.minimap-box.hidden { display: none; }
.minimap-title {
  display: block;
  font-size: 10px;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 4px;
}
#minimap {
  display: block;
  image-rendering: pixelated;
  border-radius: 4px;
  background: #0d0f16;
  cursor: pointer;
}

/* ---------- Dev panel ---------- */
.dev-panel {
  position: absolute;
  top: calc(var(--topbar-height) + var(--topbar-gap));
  right: 0;
  width: var(--dev-panel-width);
  max-height: calc(100% - var(--topbar-height) - var(--topbar-gap));
  background: rgba(28, 32, 48, 0.85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-left: 1px solid rgba(51, 58, 82, 0.45);
  overflow-y: auto;
  padding: 10px;
  z-index: 10;
  transform: translateX(100%);
  visibility: hidden;
  pointer-events: none;
}
.dev-panel.is-open {
  transform: translateX(0);
  visibility: visible;
  pointer-events: auto;
  transition:
    transform 0.45s cubic-bezier(0.34, 1.18, 0.64, 1),
    visibility 0s;
}
.dev-panel.is-closing {
  transform: translateX(100%);
  visibility: hidden;
  pointer-events: none;
  transition:
    transform 0.38s cubic-bezier(0.36, 0, 0.66, -0.22),
    visibility 0s linear 0.38s;
}
.panel-block { margin-bottom: 16px; }
.panel-block h3 {
  margin: 0 0 8px;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: #fff;
  border-bottom: 1px solid var(--line);
  padding-bottom: 5px;
}
.panel-block h3 small { text-transform: none; letter-spacing: 0; font-weight: 400; color: #667; font-size: 10px; }

.panel-block.foldable > summary {
  list-style: none;
  cursor: pointer;
  margin: 0;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: #fff;
  border-bottom: 1px solid var(--line);
  padding-bottom: 5px;
  user-select: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.panel-block.foldable > summary::-webkit-details-marker { display: none; }
.panel-block.foldable > summary::marker { content: ''; }
.panel-block.foldable > summary::after {
  content: '+';
  font-size: 14px;
  line-height: 1;
  color: var(--muted);
  flex-shrink: 0;
}
.panel-block.foldable[open] > summary::after { content: '−'; }
.panel-block.foldable[open] > summary { margin-bottom: 8px; }
.panel-block.foldable > :not(summary) { padding-top: 2px; }
.panel-block.foldable > summary:hover { color: #fff; }
.panel-block.foldable > summary:hover::after { color: #fff; }

.library {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-auto-rows: 68px;
  gap: 6px;
  max-height: calc(4 * 68px + 3 * 6px);
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: #2a2a2a #000;
}
.library::-webkit-scrollbar {
  width: 8px;
}
.library::-webkit-scrollbar-track {
  background: #000;
  border-radius: 4px;
}
.library::-webkit-scrollbar-thumb {
  background: #2a2a2a;
  border-radius: 4px;
  border: 2px solid #000;
}
.library::-webkit-scrollbar-thumb:hover {
  background: #3a3a3a;
}
.lib-item {
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  padding: 6px 3px; font-size: 10px; line-height: 1.1;
  background: var(--panel-2);
  position: relative;
  transform-origin: center;
  transition: transform 0.12s ease, background 0.12s;
}
.lib-item:hover {
  transform: scale(1.1);
  z-index: 1;
}
.lib-item canvas { image-rendering: pixelated; background: #0d0f16; border-radius: 3px; }
.lib-item.locked { cursor: default; border-color: #3a4a6a; }
.lib-item span { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.wide { width: 100%; margin-top: 8px; }
.lib-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-top: 8px; }
.lib-actions button {
  width: 100%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  text-transform: uppercase;
}
.lib-actions button svg { flex-shrink: 0; }

/* Inspector */
.inspector { font-size: 13px; }
.ins-empty { color: var(--muted); line-height: 1.5; }
.ins-row { display: flex; align-items: center; gap: 6px; margin-bottom: 6px; }
.ins-id { margin-left: auto; font-size: 11px; color: var(--muted); text-transform: uppercase; }
.ins-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-bottom: 8px; }
.ins-grid label, .ins-enemy label, .settings label { display: flex; align-items: center; gap: 5px; color: var(--muted); font-size: 12px; }
.ins-grid input, .ins-enemy input { width: 100%; }
.ins-check { display: flex; align-items: center; gap: 6px; margin-bottom: 8px; color: var(--muted); }
.ins-enemy { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-bottom: 8px; }
.ins-portal { display: flex; flex-direction: column; gap: 4px; margin-bottom: 8px; color: var(--muted); font-size: 12px; }
.ins-portal select { width: 100%; }
.ins-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.ins-actions button {
  width: 100%;
  font-size: 11px;
  text-transform: uppercase;
}

.settings { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.settings input { width: 100%; }

.help ul { margin: 0; padding-left: 16px; color: var(--muted); font-size: 12px; line-height: 1.7; }
.help b { color: var(--text); }

/* ---------- Toast ---------- */
.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  background: #000c; color: #fff; padding: 10px 18px; border-radius: 8px;
  font-size: 14px; border: 1px solid var(--line); z-index: 50;
  transition: opacity 0.3s;
}
.toast.hidden { opacity: 0; pointer-events: none; }

/* ---------- Mobile controls ---------- */
.joystick-zone,
.jump-zone {
  display: none;
  position: fixed;
  bottom: 18px;
  width: 148px;
  height: 148px;
  z-index: 15;
  touch-action: none;
  pointer-events: auto;
}

.joystick-zone {
  left: 18px;
}

.jump-zone {
  right: 18px;
  display: none;
  align-items: center;
  justify-content: center;
}

.jump-btn {
  width: 112px;
  height: 112px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.35);
  background: rgba(255, 255, 255, 0.18);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  padding: 0;
  min-width: unset;
  transition: background 0.1s, border-color 0.1s, transform 0.1s;
}

.jump-btn:active,
.jump-btn.is-pressed {
  background: rgba(255, 255, 255, 0.35);
  border-color: rgba(255, 255, 255, 0.6);
  transform: scale(0.96);
}

@media (pointer: coarse) {
  .joystick-zone,
  .jump-zone {
    display: flex;
  }

  #game {
    touch-action: none;
  }
}

/* ---------- Sprite editor ---------- */
.se-overlay {
  position: fixed; inset: 0; background: #000a;
  display: flex; align-items: center; justify-content: center; z-index: 100;
}
.se-overlay.hidden { display: none; }
.se-modal {
  width: 900px; max-width: 96vw; max-height: 94vh;
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  display: flex; flex-direction: column; overflow: hidden;
  box-shadow: 0 20px 60px #000a;
}
.se-modal button { text-transform: uppercase; }
.se-header, .se-footer {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px; background: var(--panel-2);
}
.se-header { border-bottom: 1px solid var(--line); }
.se-footer { border-top: 1px solid var(--line); }
.se-title { font-weight: 700; }
.se-name { width: 140px; }
.se-kind { min-width: 150px; font-size: 12px; }
.se-spacer { flex: 1; }
.se-size { display: flex; align-items: center; gap: 4px; font-size: 12px; color: var(--muted); }
.se-size input { width: 54px; }
.se-hint { color: var(--muted); font-size: 12px; }

.se-body { display: flex; gap: 14px; padding: 14px; overflow: auto; }
.se-tools { width: 210px; flex-shrink: 0; display: flex; flex-direction: column; gap: 10px; }
.se-toolgroup { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.se-toolgroup button {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8px 0;
  color: #fff;
}
.se-toolgroup button svg { flex-shrink: 0; }
.se-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 4px;
  color: #fff;
  background: transparent;
  border: none;
  min-width: unset;
  width: auto;
}
.se-close svg { flex-shrink: 0; width: 26px; height: 26px; }
.se-close:hover { background: transparent; color: var(--muted); }
.se-check { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 13px; }
.se-color-row { display: flex; gap: 6px; align-items: center; }
.se-color { width: 48px; height: 34px; }
.se-palette-title { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.5px; }
.se-palette {
  display: grid;
  grid-template-columns: repeat(16, 1fr);
  gap: 0;
  max-height: 220px;
  overflow-y: auto;
  padding: 0;
  background: #0d0f16;
  border-radius: 6px;
  border: 1px solid var(--line);
}
.se-swatch {
  position: relative;
  width: 100%;
  aspect-ratio: 1;
  padding: 0;
  border: none;
  border-radius: 0;
  cursor: pointer;
  transition: transform 0.1s ease;
}
.se-swatch:hover { transform: scale(1.1); z-index: 2; }
.se-swatch.active { outline: 2px solid var(--accent); outline-offset: 0; z-index: 1; }
.se-frame-actions { display: flex; flex-direction: column; gap: 6px; margin-top: 4px; }

.se-canvas-wrap {
  flex: 1; display: flex; align-items: center; justify-content: center;
  background: #0d0f16; border-radius: 8px; padding: 10px; min-height: 300px;
}
.se-canvas { image-rendering: pixelated; cursor: crosshair; background: #eee; }

.se-side { width: 170px; flex-shrink: 0; display: flex; flex-direction: column; gap: 10px; }
.se-preview-box { background: #0d0f16; border-radius: 8px; padding: 8px; text-align: center; }
.se-preview { image-rendering: pixelated; background: #05060a; border-radius: 4px; }
.se-fps { font-size: 11px; color: var(--muted); display: flex; align-items: center; gap: 6px; justify-content: center; margin-top: 6px; }
.se-fps input { width: 80px; }
.se-frames-title { font-size: 12px; color: var(--muted); text-transform: uppercase; }
.se-frames { display: flex; flex-direction: column; gap: 6px; max-height: 240px; overflow-y: auto; }
.se-frame {
  position: relative; display: flex; align-items: center; gap: 8px;
  background: var(--panel-2); border: 2px solid transparent; border-radius: 6px; padding: 4px 6px; cursor: pointer;
}
.se-frame.active { border-color: var(--accent); }
.se-frame-thumb { image-rendering: pixelated; background: #05060a; border-radius: 3px; }
.se-frame span { color: var(--muted); font-size: 12px; }
.se-frame-del {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 2px 6px;
  background: transparent;
  border: none;
  color: #fff;
}
.se-frame-del svg { flex-shrink: 0; width: 14px; height: 14px; }
.se-frame-del:hover { color: var(--danger); background: transparent; }
