:root {
  --bg: #0f172a;
  --panel: #111827;
  --panel-2: #0b1220;
  --text: #e5e7eb;
  --muted: #9ca3af;
  --accent: #22c55e;
  --primary: #3b82f6;
  --grid: #1f2937;
  --chip-wall: #64748b;
  --chip-coin: #fbbf24;
  --chip-hazard: #ef4444;
  --chip-goal: #10b981;
  --chip-boost: #a78bfa;
  --chip-start: #60a5fa;
  --chip-checkpoint: #f59e0b;
  --chip-finish: #e5e7eb;
  --chip-slow: #22c55e;
  --chip-crate: #38bdf8;
  --chip-enemy: #ef476f;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, "Noto Sans", "Apple Color Emoji", "Segoe UI Emoji";
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  background: var(--panel);
  border-bottom: 1px solid #1f2937;
}
.brand { display: flex; align-items: center; gap: 8px; }
.logo { font-size: 20px; }
.title { font-weight: 600; letter-spacing: 0.5px; }
.controls { display: flex; align-items: center; gap: 8px; }
.controls label { display: inline-flex; align-items: center; gap: 6px; }
button, select, input[type=number] {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid #1f2937;
  border-radius: 8px;
  padding: 6px 10px;
}
button.primary { background: var(--primary); border-color: transparent; }
button:disabled { opacity: 0.5; }
.import-label { position: relative; }
.import-label::after { content: "Choose file"; padding: 6px 10px; background: var(--panel-2); border: 1px solid #1f2937; border-radius: 8px; margin-left: 6px; }

.workspace {
  display: grid;
  grid-template-columns: 300px 1fr 280px;
  height: calc(100vh - 54px);
}
.sidebar {
  background: var(--panel);
  border-right: 1px solid #1f2937;
  padding: 12px;
  overflow: auto;
}
.sidebar.right { border-right: none; border-left: 1px solid #1f2937; }
.sidebar h3 { margin: 6px 0 10px; }
.section { margin-top: 18px; }
.section h4 { margin: 0 0 8px 0; font-weight: 600; color: var(--muted); }

.palette { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.palette .item {
  display: flex; align-items: center; gap: 8px;
  padding: 8px; border: 1px solid #1f2937; border-radius: 8px; cursor: pointer;
  background: var(--panel-2);
  min-width: 0; /* allow shrink inside grid to avoid overflow */
}
.palette .item span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: normal; }

/* ensure left sidebar sits on top if any overlap occurs in some browsers */
.sidebar.left { position: relative; z-index: 2; }
.palette .item.active { outline: 2px solid var(--primary); }
.chip { display: inline-block; width: 18px; height: 18px; border-radius: 4px; }
.chip.wall { background: var(--chip-wall); }
.chip.coin { background: var(--chip-coin); }
.chip.hazard { background: var(--chip-hazard); }
.chip.goal { background: var(--chip-goal); }
.chip.boost { background: var(--chip-boost); }
.chip.start { background: var(--chip-start); }
.chip.door { background: #06b6d4; }
.chip.switch { background: #f472b6; }
.chip.checkpoint { background: var(--chip-checkpoint); }
.chip.finish { background: var(--chip-finish); }
.chip.slow { background: var(--chip-slow); }
.chip.crate { background: var(--chip-crate); }
.chip.enemy { background: var(--chip-enemy); }

/* Floating Jump button (touch friendly) */
.floating-jump {
  position: absolute;
  right: 14px;
  bottom: 14px;
  padding: 10px 14px;
  font-weight: 600;
  border-radius: 999px;
  background: rgba(59,130,246,0.95);
  color: #fff;
  border: none;
  box-shadow: 0 6px 18px rgba(0,0,0,0.35);
  cursor: pointer;
  display: none; /* shown during Play */
}
.floating-jump:active { transform: translateY(1px); }

canvas:focus { outline: 2px solid rgba(59,130,246,0.6); }

.hint { color: var(--muted); margin-top: 8px; font-size: 12px; }
.hint strong { color: #fff; }

.center { display: flex; flex-direction: column; }
.canvas-wrap { flex: 1; display: flex; align-items: center; justify-content: center; background: #0b1020; position: relative; }
.timeline { padding: 8px; background: var(--panel); border-top: 1px solid #1f2937; }
#editScroll { width: 100%; }

canvas { background: #0a0f1c; border: 1px solid #1f2937; border-radius: 10px; image-rendering: pixelated; }

.alert { margin: 8px; padding: 8px 12px; border: 1px solid rgba(245, 158, 11, 0.5); background: rgba(245, 158, 11, 0.12); color: #facc15; border-radius: 10px; }
.hidden { display: none !important; }
.alert .ignore {
  float: right;
  background: transparent;
  border: 1px solid rgba(245, 158, 11, 0.6);
  color: #fde68a;
  border-radius: 8px;
  padding: 2px 8px;
  cursor: pointer;
}

.legend { padding-left: 18px; margin: 8px 0; }
.legend li { margin: 4px 0; color: var(--muted); }
.param-group.hidden { display: none; }
.keys { color: var(--muted); font-size: 13px; display: grid; gap: 2px; }

.overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.6); display: flex; align-items: center; justify-content: center; }
.overlay.hidden { display: none; }
.modal { background: var(--panel); padding: 16px; border-radius: 12px; width: min(620px, 92vw); border: 1px solid #1f2937; }
.modal h2 { margin-top: 0; }
.modal ol { margin-left: 16px; }

/* Rules layout tidy */
.rules-list { display: flex; flex-direction: column; gap: 8px; margin-top: 6px; }
.rules-list label { display: flex; align-items: center; gap: 8px; }
.rules-list input[type=number] { width: 90px; }
.rules-list button { align-self: flex-start; }

/* Mobile tweaks */
@media (max-width: 900px) {
  .workspace { grid-template-columns: 1fr; }
  .sidebar.left, .sidebar.right { display: none; }
  .canvas-wrap { padding: 8px; }
}
